Merge feature/m10-client-tools into main
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
modified
.tickets/issues/0090-proposer-des-outils-aux-agents-en-tant-que-clien.yaml +55 -11 | @@ -1,12 +1,12 @@ | ||
| 1 | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | 2 | id: 90 |
| 3 | 3 | title: "Proposer des outils aux agents en tant que client ACP (extensions org.mini-me/tools)" |
| 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-10T23:22:37.000Z |
| 9 | -updatedAt: 2026-11-10T23:22:37.000Z | |
| 9 | +updatedAt: 2026-11-10T23:41:07.000Z | |
| 10 | 10 | labels: |
| 11 | 11 | - "kind::feature" |
| 12 | 12 | - "area::acp" |
| @@ -73,66 +73,110 @@ body: | | ||
| 73 | 73 | tasks: |
| 74 | 74 | - id: 1 |
| 75 | 75 | title: "Annoncer la liste dans initialize (_meta org.mini-me/tools) et répondre aux méthodes d'extension" |
| 76 | - state: open | |
| 76 | + state: closed | |
| 77 | 77 | priority: high |
| 78 | 78 | author: |
| 79 | 79 | name: k33g |
| 80 | 80 | email: ph.charriere@gmail.com |
| 81 | 81 | createdAt: 2026-11-10T23:22:37.000Z |
| 82 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 83 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 82 | 84 | - id: 2 |
| 83 | 85 | title: "Registre d'outils et correspondance sessionId → channel" |
| 84 | - state: open | |
| 86 | + state: closed | |
| 85 | 87 | priority: high |
| 86 | 88 | author: |
| 87 | 89 | name: k33g |
| 88 | 90 | email: ph.charriere@gmail.com |
| 89 | 91 | createdAt: 2026-11-10T23:22:37.000Z |
| 92 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 93 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 90 | 94 | - id: 3 |
| 91 | 95 | title: "Outil memory_pressure" |
| 92 | - state: open | |
| 96 | + state: closed | |
| 93 | 97 | priority: medium |
| 94 | 98 | author: |
| 95 | 99 | name: k33g |
| 96 | 100 | email: ph.charriere@gmail.com |
| 97 | 101 | createdAt: 2026-11-10T23:22:37.000Z |
| 102 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 103 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 98 | 104 | - id: 4 |
| 99 | 105 | title: "Outil about_sidekicks (version injectée au build, ClientInfo.Version)" |
| 100 | - state: open | |
| 106 | + state: closed | |
| 101 | 107 | priority: medium |
| 102 | 108 | author: |
| 103 | 109 | name: k33g |
| 104 | 110 | email: ph.charriere@gmail.com |
| 105 | 111 | createdAt: 2026-11-10T23:22:37.000Z |
| 112 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 113 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 106 | 114 | - id: 5 |
| 107 | 115 | title: "Outil current_channel" |
| 108 | - state: open | |
| 116 | + state: closed | |
| 109 | 117 | priority: medium |
| 110 | 118 | author: |
| 111 | 119 | name: k33g |
| 112 | 120 | email: ph.charriere@gmail.com |
| 113 | 121 | createdAt: 2026-11-10T23:22:37.000Z |
| 122 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 123 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 114 | 124 | - id: 6 |
| 115 | 125 | title: "Mode de découverte request : décider et implémenter _org.mini-me/tools/list" |
| 116 | - state: open | |
| 126 | + state: closed | |
| 117 | 127 | priority: medium |
| 118 | 128 | author: |
| 119 | 129 | name: k33g |
| 120 | 130 | email: ph.charriere@gmail.com |
| 121 | 131 | createdAt: 2026-11-10T23:22:37.000Z |
| 132 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 133 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 122 | 134 | - id: 7 |
| 123 | 135 | title: "Tests avec un faux agent qui appelle les méthodes ; essai avec Riker" |
| 124 | - state: open | |
| 136 | + state: closed | |
| 125 | 137 | priority: high |
| 126 | 138 | author: |
| 127 | 139 | name: k33g |
| 128 | 140 | email: ph.charriere@gmail.com |
| 129 | 141 | createdAt: 2026-11-10T23:22:37.000Z |
| 142 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 143 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 130 | 144 | - id: 8 |
| 131 | 145 | title: "Documentation EN + FR" |
| 132 | - state: open | |
| 146 | + state: closed | |
| 133 | 147 | priority: medium |
| 134 | 148 | author: |
| 135 | 149 | name: k33g |
| 136 | 150 | email: ph.charriere@gmail.com |
| 137 | 151 | createdAt: 2026-11-10T23:22:37.000Z |
| 138 | -comments: [] | |
| 152 | + updatedAt: 2026-11-10T23:28:58.000Z | |
| 153 | + closedAt: 2026-11-10T23:28:58.000Z | |
| 154 | +comments: | |
| 155 | + - id: 1 | |
| 156 | + author: | |
| 157 | + name: k33g | |
| 158 | + email: ph.charriere@gmail.com | |
| 159 | + createdAt: 2026-11-10T23:28:58.000Z | |
| 160 | + body: | | |
| 161 | + Fait. | |
| 162 | + - [internal/acp/tools.go](internal/acp/tools.go) : `acp.Tool`, la liste dans `clientCapabilities._meta["org.mini-me/tools"]` | |
| 163 | + (ou `true` en mode `request`), `HandleExtensionMethod` répond à `_org.mini-me/tools/list`, aux méthodes des | |
| 164 | + outils (résultat au format MCP, `isError` en cas d'échec) et `-32601` au reste. `clientInfo.version` est la vraie version. | |
| 165 | + - Mode de découverte : **lu dans le fichier de l'agent** (`--config <fichier>`, `acp.clientTools.discovery`), | |
| 166 | + [internal/agents/discovery.go](internal/agents/discovery.go) ; `meta` par défaut. | |
| 167 | + - Outils : [internal/app/clienttools.go](internal/app/clienttools.go) ; `current_channel` retrouve le channel par | |
| 168 | + `channels.Manager.SessionChannel(agent, sessionId)`. Version : `build/config.yml` embarqué dans `main.go`. | |
| 169 | + - Tests : faux agent ACP qui appelle la liste, un outil, un outil en échec et une méthode inconnue | |
| 170 | + ([internal/acp/tools_test.go](internal/acp/tools_test.go)) ; découverte ; channel d'une session ; textes des outils. | |
| 171 | + - Docs EN + FR : guide « Laisser un agent utiliser les outils de Sidekicks », référence « Outils proposés aux agents », | |
| 172 | + explication dans « Pourquoi ACP ». | |
| 173 | + - Reste à faire sur le Mac : l'essai avec Riker (`mm` n'est pas dans la sandbox de développement). | |
| 174 | + - id: 2 | |
| 175 | + author: | |
| 176 | + name: k33g | |
| 177 | + email: ph.charriere@gmail.com | |
| 178 | + createdAt: 2026-11-10T23:41:07.000Z | |
| 179 | + body: | | |
| 180 | + Essayé sur le Mac avec Riker : les trois outils fonctionnent. La documentation explique en plus que peu | |
| 181 | + d'agents ACP savent découvrir les outils d'un client, et que mini-me le sait (explication « Pourquoi ACP », | |
| 182 | + référence, guide). | |
| @@ -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: 90 | 2 | id: 90 |
| 3 | title: "Proposer des outils aux agents en tant que client ACP (extensions org.mini-me/tools)" | 3 | title: "Proposer des outils aux agents en tant que client ACP (extensions org.mini-me/tools)" |
| 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-10T23:22:37.000Z | 8 | createdAt: 2026-11-10T23:22:37.000Z |
| 9 | -updatedAt: 2026-11-10T23:22:37.000Z | 9 | +updatedAt: 2026-11-10T23:41:07.000Z |
| 10 | labels: | 10 | labels: |
| 11 | - "kind::feature" | 11 | - "kind::feature" |
| 12 | - "area::acp" | 12 | - "area::acp" |
| @@ -73,66 +73,110 @@ body: | | |||
| 73 | tasks: | 73 | tasks: |
| 74 | - id: 1 | 74 | - id: 1 |
| 75 | title: "Annoncer la liste dans initialize (_meta org.mini-me/tools) et répondre aux méthodes d'extension" | 75 | title: "Annoncer la liste dans initialize (_meta org.mini-me/tools) et répondre aux méthodes d'extension" |
| 76 | - state: open | 76 | + state: closed |
| 77 | priority: high | 77 | priority: high |
| 78 | author: | 78 | author: |
| 79 | name: k33g | 79 | name: k33g |
| 80 | email: ph.charriere@gmail.com | 80 | email: ph.charriere@gmail.com |
| 81 | createdAt: 2026-11-10T23:22:37.000Z | 81 | createdAt: 2026-11-10T23:22:37.000Z |
| 82 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 83 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 82 | - id: 2 | 84 | - id: 2 |
| 83 | title: "Registre d'outils et correspondance sessionId → channel" | 85 | title: "Registre d'outils et correspondance sessionId → channel" |
| 84 | - state: open | 86 | + state: closed |
| 85 | priority: high | 87 | priority: high |
| 86 | author: | 88 | author: |
| 87 | name: k33g | 89 | name: k33g |
| 88 | email: ph.charriere@gmail.com | 90 | email: ph.charriere@gmail.com |
| 89 | createdAt: 2026-11-10T23:22:37.000Z | 91 | createdAt: 2026-11-10T23:22:37.000Z |
| 92 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 93 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 90 | - id: 3 | 94 | - id: 3 |
| 91 | title: "Outil memory_pressure" | 95 | title: "Outil memory_pressure" |
| 92 | - state: open | 96 | + state: closed |
| 93 | priority: medium | 97 | priority: medium |
| 94 | author: | 98 | author: |
| 95 | name: k33g | 99 | name: k33g |
| 96 | email: ph.charriere@gmail.com | 100 | email: ph.charriere@gmail.com |
| 97 | createdAt: 2026-11-10T23:22:37.000Z | 101 | createdAt: 2026-11-10T23:22:37.000Z |
| 102 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 103 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 98 | - id: 4 | 104 | - id: 4 |
| 99 | title: "Outil about_sidekicks (version injectée au build, ClientInfo.Version)" | 105 | title: "Outil about_sidekicks (version injectée au build, ClientInfo.Version)" |
| 100 | - state: open | 106 | + state: closed |
| 101 | priority: medium | 107 | priority: medium |
| 102 | author: | 108 | author: |
| 103 | name: k33g | 109 | name: k33g |
| 104 | email: ph.charriere@gmail.com | 110 | email: ph.charriere@gmail.com |
| 105 | createdAt: 2026-11-10T23:22:37.000Z | 111 | createdAt: 2026-11-10T23:22:37.000Z |
| 112 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 113 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 106 | - id: 5 | 114 | - id: 5 |
| 107 | title: "Outil current_channel" | 115 | title: "Outil current_channel" |
| 108 | - state: open | 116 | + state: closed |
| 109 | priority: medium | 117 | priority: medium |
| 110 | author: | 118 | author: |
| 111 | name: k33g | 119 | name: k33g |
| 112 | email: ph.charriere@gmail.com | 120 | email: ph.charriere@gmail.com |
| 113 | createdAt: 2026-11-10T23:22:37.000Z | 121 | createdAt: 2026-11-10T23:22:37.000Z |
| 122 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 123 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 114 | - id: 6 | 124 | - id: 6 |
| 115 | title: "Mode de découverte request : décider et implémenter _org.mini-me/tools/list" | 125 | title: "Mode de découverte request : décider et implémenter _org.mini-me/tools/list" |
| 116 | - state: open | 126 | + state: closed |
| 117 | priority: medium | 127 | priority: medium |
| 118 | author: | 128 | author: |
| 119 | name: k33g | 129 | name: k33g |
| 120 | email: ph.charriere@gmail.com | 130 | email: ph.charriere@gmail.com |
| 121 | createdAt: 2026-11-10T23:22:37.000Z | 131 | createdAt: 2026-11-10T23:22:37.000Z |
| 132 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 133 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 122 | - id: 7 | 134 | - id: 7 |
| 123 | title: "Tests avec un faux agent qui appelle les méthodes ; essai avec Riker" | 135 | title: "Tests avec un faux agent qui appelle les méthodes ; essai avec Riker" |
| 124 | - state: open | 136 | + state: closed |
| 125 | priority: high | 137 | priority: high |
| 126 | author: | 138 | author: |
| 127 | name: k33g | 139 | name: k33g |
| 128 | email: ph.charriere@gmail.com | 140 | email: ph.charriere@gmail.com |
| 129 | createdAt: 2026-11-10T23:22:37.000Z | 141 | createdAt: 2026-11-10T23:22:37.000Z |
| 142 | + updatedAt: 2026-11-10T23:28:58.000Z | ||
| 143 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 130 | - id: 8 | 144 | - id: 8 |
| 131 | title: "Documentation EN + FR" | 145 | title: "Documentation EN + FR" |
| 132 | - state: open | 146 | + state: closed |
| 133 | priority: medium | 147 | priority: medium |
| 134 | author: | 148 | author: |
| 135 | name: k33g | 149 | name: k33g |
| 136 | email: ph.charriere@gmail.com | 150 | email: ph.charriere@gmail.com |
| 137 | createdAt: 2026-11-10T23:22:37.000Z | 151 | createdAt: 2026-11-10T23:22:37.000Z |
| 138 | -comments: [] | 152 | + updatedAt: 2026-11-10T23:28:58.000Z |
| 153 | + closedAt: 2026-11-10T23:28:58.000Z | ||
| 154 | +comments: | ||
| 155 | + - id: 1 | ||
| 156 | + author: | ||
| 157 | + name: k33g | ||
| 158 | + email: ph.charriere@gmail.com | ||
| 159 | + createdAt: 2026-11-10T23:28:58.000Z | ||
| 160 | + body: | | ||
| 161 | + Fait. | ||
| 162 | + - [internal/acp/tools.go](internal/acp/tools.go) : `acp.Tool`, la liste dans `clientCapabilities._meta["org.mini-me/tools"]` | ||
| 163 | + (ou `true` en mode `request`), `HandleExtensionMethod` répond à `_org.mini-me/tools/list`, aux méthodes des | ||
| 164 | + outils (résultat au format MCP, `isError` en cas d'échec) et `-32601` au reste. `clientInfo.version` est la vraie version. | ||
| 165 | + - Mode de découverte : **lu dans le fichier de l'agent** (`--config <fichier>`, `acp.clientTools.discovery`), | ||
| 166 | + [internal/agents/discovery.go](internal/agents/discovery.go) ; `meta` par défaut. | ||
| 167 | + - Outils : [internal/app/clienttools.go](internal/app/clienttools.go) ; `current_channel` retrouve le channel par | ||
| 168 | + `channels.Manager.SessionChannel(agent, sessionId)`. Version : `build/config.yml` embarqué dans `main.go`. | ||
| 169 | + - Tests : faux agent ACP qui appelle la liste, un outil, un outil en échec et une méthode inconnue | ||
| 170 | + ([internal/acp/tools_test.go](internal/acp/tools_test.go)) ; découverte ; channel d'une session ; textes des outils. | ||
| 171 | + - Docs EN + FR : guide « Laisser un agent utiliser les outils de Sidekicks », référence « Outils proposés aux agents », | ||
| 172 | + explication dans « Pourquoi ACP ». | ||
| 173 | + - Reste à faire sur le Mac : l'essai avec Riker (`mm` n'est pas dans la sandbox de développement). | ||
| 174 | + - id: 2 | ||
| 175 | + author: | ||
| 176 | + name: k33g | ||
| 177 | + email: ph.charriere@gmail.com | ||
| 178 | + createdAt: 2026-11-10T23:41:07.000Z | ||
| 179 | + body: | | ||
| 180 | + Essayé sur le Mac avec Riker : les trois outils fonctionnent. La documentation explique en plus que peu | ||
| 181 | + d'agents ACP savent découvrir les outils d'un client, et que mini-me le sait (explication « Pourquoi ACP », | ||
| 182 | + référence, guide). | ||
added
.tickets/issues/0091-outils-pour-les-agents-chercher-dans-l-historiqu.yaml +202 -0 | new file mode 100644 | ||
| @@ -0,0 +1,202 @@ | ||
| 1 | +# Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | |
| 2 | +id: 91 | |
| 3 | +title: "Outils pour les agents : chercher dans l'historique d'un channel, lister les channels et les agents ; réglage pour les désactiver ou les filtrer" | |
| 4 | +state: closed | |
| 5 | +author: | |
| 6 | + name: k33g | |
| 7 | + email: ph.charriere@gmail.com | |
| 8 | +createdAt: 2026-11-10T23:41:38.000Z | |
| 9 | +updatedAt: 2026-11-11T00:23:22.000Z | |
| 10 | +labels: | |
| 11 | + - "kind::feature" | |
| 12 | + - "area::acp" | |
| 13 | + - "area::config" | |
| 14 | + - "real-agents" | |
| 15 | + - "size::M" | |
| 16 | +milestone: "M10 · Outils client ACP" | |
| 17 | +epic: "Client ACP" | |
| 18 | +related: | |
| 19 | + - 90 | |
| 20 | +body: | | |
| 21 | + ## Contexte | |
| 22 | + [#90 — Proposer des outils aux agents en tant que client ACP](.tickets/issues/0090-proposer-des-outils-aux-agents-en-tant-que-clien.yaml) | |
| 23 | + propose trois outils aux agents (`memory_pressure`, `about_sidekicks`, `current_channel`) par les méthodes | |
| 24 | + d'extension ACP, avec le protocole `org.mini-me/tools` de mini-me | |
| 25 | + ([internal/app/clienttools.go](internal/app/clienttools.go)). Ce ticket ajoute des outils qui lisent ce que | |
| 26 | + Sidekicks sait — son historique, ses channels, ses agents — et un réglage pour tout désactiver ou choisir | |
| 27 | + les outils proposés. | |
| 28 | + | |
| 29 | + **Peu d'agents ACP savent découvrir ces extensions** : ACP dit comment répondre à une méthode d'extension, pas | |
| 30 | + comment un agent les découvre. mini-me le sait (`acp.clientTools`) ; Claude, Codex, Gemini et docker-agent non : | |
| 31 | + ils les ignorent et fonctionnent comme avant. La documentation doit le redire. | |
| 32 | + | |
| 33 | + ## Nouveaux outils | |
| 34 | + | `name` (le modèle voit) | `method` | Paramètres | Renvoie | | |
| 35 | + | --- | --- | --- | --- | | |
| 36 | + | `list_channels` (`client_list_channels`) | `_com.rickub.sidekicks/channels/list` | aucun | Les channels et les conversations directes : nom (ou « direct avec @agent »), description, membres, nombre de messages, date du dernier. | | |
| 37 | + | `list_agents` (`client_list_agents`) | `_com.rickub.sidekicks/agents/list` | aucun | Les agents de la configuration : nom (@nom), titre, description, où il tourne (local, Docker, sbx), état (arrêté, prêt, occupé…). | | |
| 38 | + | `search_messages` (`client_search_messages`) | `_com.rickub.sidekicks/messages/search` | `query` (obligatoire), `channel` (nom, sans `#` ; absent : le channel de la session), `limit` (défaut 10, max 50) | Les messages du channel qui contiennent `query`, les plus récents d'abord : date, auteur (utilisateur ou @agent), extrait autour du texte trouvé. Toute l'histoire du channel, pas seulement les messages chargés. | | |
| 39 | + | |
| 40 | + `search_messages` a un `inputSchema` (`type: object`, `required: [query]`). Recherche sans index : le | |
| 41 | + store (Pebble) n'a pas de recherche plein texte ; parcourir les messages du channel, comparaison sans casse | |
| 42 | + ni accents. Un channel inconnu est une erreur qui liste les channels existants. | |
| 43 | + | |
| 44 | + **Portée (décidée)** : un agent lit déjà l'historique des channels dont il est membre. Quand les outils sont | |
| 45 | + activés, il peut **lister et chercher dans tous les channels**, conversations directes comprises. Pour le | |
| 46 | + restreindre, l'utilisateur retire `search_messages` ou `list_channels` des outils proposés (ci-dessous). | |
| 47 | + Les descriptions des outils et la documentation le disent. | |
| 48 | + | |
| 49 | + ## Réglage : activé par défaut, désactivable et filtrable dans Settings | |
| 50 | + Une clé dans la configuration de Sidekicks, modifiable depuis le panneau **Settings** : | |
| 51 | + | |
| 52 | + ```yaml | |
| 53 | + agentTools: | |
| 54 | + enabled: true # défaut ; false : aucun outil n'est proposé aux agents | |
| 55 | + offer: # facultatif : seulement ces outils ; absent : tous | |
| 56 | + - memory_pressure | |
| 57 | + - current_channel | |
| 58 | + - list_agents | |
| 59 | + ``` | |
| 60 | + | |
| 61 | + - `enabled: false` : rien dans le `_meta` d'`initialize`, `_org.mini-me/tools/list` et les méthodes des outils | |
| 62 | + répondent `-32601`. Vaut pour **tous** les outils, ceux de #90 compris. | |
| 63 | + - `offer` : la liste des noms des outils proposés (`memory_pressure`, `about_sidekicks`, `current_channel`, | |
| 64 | + `list_channels`, `list_agents`, `search_messages`). Absente : tous. Un outil retiré n'est ni annoncé ni | |
| 65 | + répondu (`-32601`). Un nom inconnu est un avertissement de la configuration (« outil inconnu, outils connus : … »). | |
| 66 | + Liste vide : aucun outil, comme `enabled: false`. | |
| 67 | + - Lu au démarrage d'un agent : un agent en marche garde ses outils jusqu'à son redémarrage (le marquer | |
| 68 | + « à redémarrer » comme pour un changement de sa configuration, si c'est simple). | |
| 69 | + - Schéma JSON de la configuration (booléen, liste de noms avec `enum`), validation, valeurs par défaut, | |
| 70 | + configuration par défaut écrite. | |
| 71 | + - Plus tard, si le besoin vient : un `agentTools.offer` par agent, qui remplace la liste globale. | |
| 72 | + | |
| 73 | + ## Critères d'acceptation | |
| 74 | + - Avec Riker : « liste les channels », « quels agents y a-t-il ? », « cherche ce qu'on a dit sur Lyon dans #general » | |
| 75 | + font appeler les bons outils, avec des réponses justes. | |
| 76 | + - `agentTools.enabled: false` puis redémarrage de Riker : il n'a plus d'outil `client_…` (journal `[acp] client tools` absent). | |
| 77 | + - `agentTools.offer: [memory_pressure]` puis redémarrage : Riker n'a que `client_memory_pressure`. | |
| 78 | + - Tests : chaque outil (recherche : casse, accents, limite, channel par défaut, channel inconnu, channel dont | |
| 79 | + l'agent n'est pas membre, conversation directe), le réglage (rien d'annoncé, filtre, `-32601`), la validation | |
| 80 | + de la configuration (nom inconnu). | |
| 81 | + - Documentation EN + FR : référence de la configuration (`agentTools`), référence des outils, guide « Laisser un | |
| 82 | + agent utiliser les outils de Sidekicks » (désactiver ou filtrer les outils, portée de la recherche), explication (peu d'agents ACP découvrent ces | |
| 83 | + extensions, mini-me le peut ; pourquoi tout l'historique et un filtre global). | |
| 84 | +tasks: | |
| 85 | + - id: 1 | |
| 86 | + title: "Réglage agentTools (enabled, défaut true ; offer, filtre des outils) : config, schéma, validation, Settings" | |
| 87 | + state: closed | |
| 88 | + priority: high | |
| 89 | + author: | |
| 90 | + name: k33g | |
| 91 | + email: ph.charriere@gmail.com | |
| 92 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 93 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 94 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 95 | + - id: 2 | |
| 96 | + title: "Désactivé ou filtré : rien d'annoncé à initialize pour les outils retirés, -32601" | |
| 97 | + state: closed | |
| 98 | + priority: high | |
| 99 | + author: | |
| 100 | + name: k33g | |
| 101 | + email: ph.charriere@gmail.com | |
| 102 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 103 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 104 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 105 | + - id: 3 | |
| 106 | + title: "Outil list_channels" | |
| 107 | + state: closed | |
| 108 | + priority: medium | |
| 109 | + author: | |
| 110 | + name: k33g | |
| 111 | + email: ph.charriere@gmail.com | |
| 112 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 113 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 114 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 115 | + - id: 4 | |
| 116 | + title: "Outil list_agents" | |
| 117 | + state: closed | |
| 118 | + priority: medium | |
| 119 | + author: | |
| 120 | + name: k33g | |
| 121 | + email: ph.charriere@gmail.com | |
| 122 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 123 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 124 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 125 | + - id: 5 | |
| 126 | + title: "Outil search_messages (store : parcours des messages d'un channel, sans casse ni accents)" | |
| 127 | + state: closed | |
| 128 | + priority: high | |
| 129 | + author: | |
| 130 | + name: k33g | |
| 131 | + email: ph.charriere@gmail.com | |
| 132 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 133 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 134 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 135 | + - id: 6 | |
| 136 | + title: "Décider la portée : channels dont l'agent est membre ou tous" | |
| 137 | + state: closed | |
| 138 | + priority: medium | |
| 139 | + author: | |
| 140 | + name: k33g | |
| 141 | + email: ph.charriere@gmail.com | |
| 142 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 143 | + updatedAt: 2026-11-10T23:46:12.000Z | |
| 144 | + closedAt: 2026-11-10T23:46:12.000Z | |
| 145 | + - id: 7 | |
| 146 | + title: "Tests ; essai avec Riker" | |
| 147 | + state: closed | |
| 148 | + priority: high | |
| 149 | + author: | |
| 150 | + name: k33g | |
| 151 | + email: ph.charriere@gmail.com | |
| 152 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 153 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 154 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 155 | + - id: 8 | |
| 156 | + title: "Documentation EN + FR (config, référence, guide, explication)" | |
| 157 | + state: closed | |
| 158 | + priority: medium | |
| 159 | + author: | |
| 160 | + name: k33g | |
| 161 | + email: ph.charriere@gmail.com | |
| 162 | + createdAt: 2026-11-10T23:41:38.000Z | |
| 163 | + updatedAt: 2026-11-10T23:54:34.000Z | |
| 164 | + closedAt: 2026-11-10T23:54:34.000Z | |
| 165 | +comments: | |
| 166 | + - id: 1 | |
| 167 | + author: | |
| 168 | + name: k33g | |
| 169 | + email: ph.charriere@gmail.com | |
| 170 | + createdAt: 2026-11-10T23:46:12.000Z | |
| 171 | + body: | | |
| 172 | + Décidé : un agent lit déjà l'historique des channels dont il est membre ; outils activés, il peut lister et | |
| 173 | + chercher dans **tous** les channels. Pour restreindre, on filtre les outils proposés avec `agentTools.offer`. | |
| 174 | + - id: 2 | |
| 175 | + author: | |
| 176 | + name: k33g | |
| 177 | + email: ph.charriere@gmail.com | |
| 178 | + createdAt: 2026-11-10T23:54:34.000Z | |
| 179 | + body: | | |
| 180 | + Fait. | |
| 181 | + - Réglage `agentTools` ([internal/config/config.go](internal/config/config.go)) : `enabled` (défaut `true`) et | |
| 182 | + `offer` (liste, absente : tous) ; `config.AgentToolNames` ; un nom inconnu est un avertissement ; schéma JSON | |
| 183 | + (`examples` : l'éditeur Settings propose les noms après `- `) ; configuration par défaut. | |
| 184 | + - Recherche et résumés : [internal/channels/search.go](internal/channels/search.go) (`Summaries`, `ChannelNamed`, | |
| 185 | + `Search` : tout l'historique enregistré, sans casse ni accents, extrait de 80 caractères de chaque côté). | |
| 186 | + - Outils `list_channels`, `list_agents`, `search_messages` : [internal/app/historytools.go](internal/app/historytools.go) ; | |
| 187 | + filtre des six outils dans `clientTools`. Un outil retiré n'est ni annoncé ni répondu (`-32601`). | |
| 188 | + - Tests : config (défaut, désactivé, filtre, liste vide, nom inconnu), recherche, résumés, outils, filtre. | |
| 189 | + - Docs EN + FR : référence de la configuration (`agentTools`), référence des outils, guide, explication « Pourquoi ACP ». | |
| 190 | + - Reste : l'essai avec Riker sur le Mac. | |
| 191 | + - id: 3 | |
| 192 | + author: | |
| 193 | + name: k33g | |
| 194 | + email: ph.charriere@gmail.com | |
| 195 | + createdAt: 2026-11-11T00:23:22.000Z | |
| 196 | + body: | | |
| 197 | + Essayé avec Riker sur le Mac ; corrections après l'essai : | |
| 198 | + - un agent en marche dont les outils proposés changent est marqué « à redémarrer » ; | |
| 199 | + - le journal de l'agent dit au démarrage quels outils Sidekicks lui propose (`sidekicks: tools offered (meta): …`) ; | |
| 200 | + - `list_channels` ne liste que les channels, pas les conversations directes ; | |
| 201 | + - descriptions : rappeler les outils à chaque fois, chercher des messages et non des fichiers, préférer à bash ; | |
| 202 | + - le texte en cours de saisie est gardé par conversation quand on change de channel. | |
| new file mode 100644 | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | +# Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | ||
| 2 | +id: 91 | ||
| 3 | +title: "Outils pour les agents : chercher dans l'historique d'un channel, lister les channels et les agents ; réglage pour les désactiver ou les filtrer" | ||
| 4 | +state: closed | ||
| 5 | +author: | ||
| 6 | + name: k33g | ||
| 7 | + email: ph.charriere@gmail.com | ||
| 8 | +createdAt: 2026-11-10T23:41:38.000Z | ||
| 9 | +updatedAt: 2026-11-11T00:23:22.000Z | ||
| 10 | +labels: | ||
| 11 | + - "kind::feature" | ||
| 12 | + - "area::acp" | ||
| 13 | + - "area::config" | ||
| 14 | + - "real-agents" | ||
| 15 | + - "size::M" | ||
| 16 | +milestone: "M10 · Outils client ACP" | ||
| 17 | +epic: "Client ACP" | ||
| 18 | +related: | ||
| 19 | + - 90 | ||
| 20 | +body: | | ||
| 21 | + ## Contexte | ||
| 22 | + [#90 — Proposer des outils aux agents en tant que client ACP](.tickets/issues/0090-proposer-des-outils-aux-agents-en-tant-que-clien.yaml) | ||
| 23 | + propose trois outils aux agents (`memory_pressure`, `about_sidekicks`, `current_channel`) par les méthodes | ||
| 24 | + d'extension ACP, avec le protocole `org.mini-me/tools` de mini-me | ||
| 25 | + ([internal/app/clienttools.go](internal/app/clienttools.go)). Ce ticket ajoute des outils qui lisent ce que | ||
| 26 | + Sidekicks sait — son historique, ses channels, ses agents — et un réglage pour tout désactiver ou choisir | ||
| 27 | + les outils proposés. | ||
| 28 | + | ||
| 29 | + **Peu d'agents ACP savent découvrir ces extensions** : ACP dit comment répondre à une méthode d'extension, pas | ||
| 30 | + comment un agent les découvre. mini-me le sait (`acp.clientTools`) ; Claude, Codex, Gemini et docker-agent non : | ||
| 31 | + ils les ignorent et fonctionnent comme avant. La documentation doit le redire. | ||
| 32 | + | ||
| 33 | + ## Nouveaux outils | ||
| 34 | + | `name` (le modèle voit) | `method` | Paramètres | Renvoie | | ||
| 35 | + | --- | --- | --- | --- | | ||
| 36 | + | `list_channels` (`client_list_channels`) | `_com.rickub.sidekicks/channels/list` | aucun | Les channels et les conversations directes : nom (ou « direct avec @agent »), description, membres, nombre de messages, date du dernier. | | ||
| 37 | + | `list_agents` (`client_list_agents`) | `_com.rickub.sidekicks/agents/list` | aucun | Les agents de la configuration : nom (@nom), titre, description, où il tourne (local, Docker, sbx), état (arrêté, prêt, occupé…). | | ||
| 38 | + | `search_messages` (`client_search_messages`) | `_com.rickub.sidekicks/messages/search` | `query` (obligatoire), `channel` (nom, sans `#` ; absent : le channel de la session), `limit` (défaut 10, max 50) | Les messages du channel qui contiennent `query`, les plus récents d'abord : date, auteur (utilisateur ou @agent), extrait autour du texte trouvé. Toute l'histoire du channel, pas seulement les messages chargés. | | ||
| 39 | + | ||
| 40 | + `search_messages` a un `inputSchema` (`type: object`, `required: [query]`). Recherche sans index : le | ||
| 41 | + store (Pebble) n'a pas de recherche plein texte ; parcourir les messages du channel, comparaison sans casse | ||
| 42 | + ni accents. Un channel inconnu est une erreur qui liste les channels existants. | ||
| 43 | + | ||
| 44 | + **Portée (décidée)** : un agent lit déjà l'historique des channels dont il est membre. Quand les outils sont | ||
| 45 | + activés, il peut **lister et chercher dans tous les channels**, conversations directes comprises. Pour le | ||
| 46 | + restreindre, l'utilisateur retire `search_messages` ou `list_channels` des outils proposés (ci-dessous). | ||
| 47 | + Les descriptions des outils et la documentation le disent. | ||
| 48 | + | ||
| 49 | + ## Réglage : activé par défaut, désactivable et filtrable dans Settings | ||
| 50 | + Une clé dans la configuration de Sidekicks, modifiable depuis le panneau **Settings** : | ||
| 51 | + | ||
| 52 | + ```yaml | ||
| 53 | + agentTools: | ||
| 54 | + enabled: true # défaut ; false : aucun outil n'est proposé aux agents | ||
| 55 | + offer: # facultatif : seulement ces outils ; absent : tous | ||
| 56 | + - memory_pressure | ||
| 57 | + - current_channel | ||
| 58 | + - list_agents | ||
| 59 | + ``` | ||
| 60 | + | ||
| 61 | + - `enabled: false` : rien dans le `_meta` d'`initialize`, `_org.mini-me/tools/list` et les méthodes des outils | ||
| 62 | + répondent `-32601`. Vaut pour **tous** les outils, ceux de #90 compris. | ||
| 63 | + - `offer` : la liste des noms des outils proposés (`memory_pressure`, `about_sidekicks`, `current_channel`, | ||
| 64 | + `list_channels`, `list_agents`, `search_messages`). Absente : tous. Un outil retiré n'est ni annoncé ni | ||
| 65 | + répondu (`-32601`). Un nom inconnu est un avertissement de la configuration (« outil inconnu, outils connus : … »). | ||
| 66 | + Liste vide : aucun outil, comme `enabled: false`. | ||
| 67 | + - Lu au démarrage d'un agent : un agent en marche garde ses outils jusqu'à son redémarrage (le marquer | ||
| 68 | + « à redémarrer » comme pour un changement de sa configuration, si c'est simple). | ||
| 69 | + - Schéma JSON de la configuration (booléen, liste de noms avec `enum`), validation, valeurs par défaut, | ||
| 70 | + configuration par défaut écrite. | ||
| 71 | + - Plus tard, si le besoin vient : un `agentTools.offer` par agent, qui remplace la liste globale. | ||
| 72 | + | ||
| 73 | + ## Critères d'acceptation | ||
| 74 | + - Avec Riker : « liste les channels », « quels agents y a-t-il ? », « cherche ce qu'on a dit sur Lyon dans #general » | ||
| 75 | + font appeler les bons outils, avec des réponses justes. | ||
| 76 | + - `agentTools.enabled: false` puis redémarrage de Riker : il n'a plus d'outil `client_…` (journal `[acp] client tools` absent). | ||
| 77 | + - `agentTools.offer: [memory_pressure]` puis redémarrage : Riker n'a que `client_memory_pressure`. | ||
| 78 | + - Tests : chaque outil (recherche : casse, accents, limite, channel par défaut, channel inconnu, channel dont | ||
| 79 | + l'agent n'est pas membre, conversation directe), le réglage (rien d'annoncé, filtre, `-32601`), la validation | ||
| 80 | + de la configuration (nom inconnu). | ||
| 81 | + - Documentation EN + FR : référence de la configuration (`agentTools`), référence des outils, guide « Laisser un | ||
| 82 | + agent utiliser les outils de Sidekicks » (désactiver ou filtrer les outils, portée de la recherche), explication (peu d'agents ACP découvrent ces | ||
| 83 | + extensions, mini-me le peut ; pourquoi tout l'historique et un filtre global). | ||
| 84 | +tasks: | ||
| 85 | + - id: 1 | ||
| 86 | + title: "Réglage agentTools (enabled, défaut true ; offer, filtre des outils) : config, schéma, validation, Settings" | ||
| 87 | + state: closed | ||
| 88 | + priority: high | ||
| 89 | + author: | ||
| 90 | + name: k33g | ||
| 91 | + email: ph.charriere@gmail.com | ||
| 92 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 93 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 94 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 95 | + - id: 2 | ||
| 96 | + title: "Désactivé ou filtré : rien d'annoncé à initialize pour les outils retirés, -32601" | ||
| 97 | + state: closed | ||
| 98 | + priority: high | ||
| 99 | + author: | ||
| 100 | + name: k33g | ||
| 101 | + email: ph.charriere@gmail.com | ||
| 102 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 103 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 104 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 105 | + - id: 3 | ||
| 106 | + title: "Outil list_channels" | ||
| 107 | + state: closed | ||
| 108 | + priority: medium | ||
| 109 | + author: | ||
| 110 | + name: k33g | ||
| 111 | + email: ph.charriere@gmail.com | ||
| 112 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 113 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 114 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 115 | + - id: 4 | ||
| 116 | + title: "Outil list_agents" | ||
| 117 | + state: closed | ||
| 118 | + priority: medium | ||
| 119 | + author: | ||
| 120 | + name: k33g | ||
| 121 | + email: ph.charriere@gmail.com | ||
| 122 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 123 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 124 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 125 | + - id: 5 | ||
| 126 | + title: "Outil search_messages (store : parcours des messages d'un channel, sans casse ni accents)" | ||
| 127 | + state: closed | ||
| 128 | + priority: high | ||
| 129 | + author: | ||
| 130 | + name: k33g | ||
| 131 | + email: ph.charriere@gmail.com | ||
| 132 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 133 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 134 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 135 | + - id: 6 | ||
| 136 | + title: "Décider la portée : channels dont l'agent est membre ou tous" | ||
| 137 | + state: closed | ||
| 138 | + priority: medium | ||
| 139 | + author: | ||
| 140 | + name: k33g | ||
| 141 | + email: ph.charriere@gmail.com | ||
| 142 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 143 | + updatedAt: 2026-11-10T23:46:12.000Z | ||
| 144 | + closedAt: 2026-11-10T23:46:12.000Z | ||
| 145 | + - id: 7 | ||
| 146 | + title: "Tests ; essai avec Riker" | ||
| 147 | + state: closed | ||
| 148 | + priority: high | ||
| 149 | + author: | ||
| 150 | + name: k33g | ||
| 151 | + email: ph.charriere@gmail.com | ||
| 152 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 153 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 154 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 155 | + - id: 8 | ||
| 156 | + title: "Documentation EN + FR (config, référence, guide, explication)" | ||
| 157 | + state: closed | ||
| 158 | + priority: medium | ||
| 159 | + author: | ||
| 160 | + name: k33g | ||
| 161 | + email: ph.charriere@gmail.com | ||
| 162 | + createdAt: 2026-11-10T23:41:38.000Z | ||
| 163 | + updatedAt: 2026-11-10T23:54:34.000Z | ||
| 164 | + closedAt: 2026-11-10T23:54:34.000Z | ||
| 165 | +comments: | ||
| 166 | + - id: 1 | ||
| 167 | + author: | ||
| 168 | + name: k33g | ||
| 169 | + email: ph.charriere@gmail.com | ||
| 170 | + createdAt: 2026-11-10T23:46:12.000Z | ||
| 171 | + body: | | ||
| 172 | + Décidé : un agent lit déjà l'historique des channels dont il est membre ; outils activés, il peut lister et | ||
| 173 | + chercher dans **tous** les channels. Pour restreindre, on filtre les outils proposés avec `agentTools.offer`. | ||
| 174 | + - id: 2 | ||
| 175 | + author: | ||
| 176 | + name: k33g | ||
| 177 | + email: ph.charriere@gmail.com | ||
| 178 | + createdAt: 2026-11-10T23:54:34.000Z | ||
| 179 | + body: | | ||
| 180 | + Fait. | ||
| 181 | + - Réglage `agentTools` ([internal/config/config.go](internal/config/config.go)) : `enabled` (défaut `true`) et | ||
| 182 | + `offer` (liste, absente : tous) ; `config.AgentToolNames` ; un nom inconnu est un avertissement ; schéma JSON | ||
| 183 | + (`examples` : l'éditeur Settings propose les noms après `- `) ; configuration par défaut. | ||
| 184 | + - Recherche et résumés : [internal/channels/search.go](internal/channels/search.go) (`Summaries`, `ChannelNamed`, | ||
| 185 | + `Search` : tout l'historique enregistré, sans casse ni accents, extrait de 80 caractères de chaque côté). | ||
| 186 | + - Outils `list_channels`, `list_agents`, `search_messages` : [internal/app/historytools.go](internal/app/historytools.go) ; | ||
| 187 | + filtre des six outils dans `clientTools`. Un outil retiré n'est ni annoncé ni répondu (`-32601`). | ||
| 188 | + - Tests : config (défaut, désactivé, filtre, liste vide, nom inconnu), recherche, résumés, outils, filtre. | ||
| 189 | + - Docs EN + FR : référence de la configuration (`agentTools`), référence des outils, guide, explication « Pourquoi ACP ». | ||
| 190 | + - Reste : l'essai avec Riker sur le Mac. | ||
| 191 | + - id: 3 | ||
| 192 | + author: | ||
| 193 | + name: k33g | ||
| 194 | + email: ph.charriere@gmail.com | ||
| 195 | + createdAt: 2026-11-11T00:23:22.000Z | ||
| 196 | + body: | | ||
| 197 | + Essayé avec Riker sur le Mac ; corrections après l'essai : | ||
| 198 | + - un agent en marche dont les outils proposés changent est marqué « à redémarrer » ; | ||
| 199 | + - le journal de l'agent dit au démarrage quels outils Sidekicks lui propose (`sidekicks: tools offered (meta): …`) ; | ||
| 200 | + - `list_channels` ne liste que les channels, pas les conversations directes ; | ||
| 201 | + - descriptions : rappeler les outils à chaque fois, chercher des messages et non des fichiers, préférer à bash ; | ||
| 202 | + - le texte en cours de saisie est gardé par conversation quand on change de channel. | ||
modified
.tickets/milestones.yaml +1 -1 | @@ -55,5 +55,5 @@ milestones: | ||
| 55 | 55 | state: open |
| 56 | 56 | description: "Faire répondre plusieurs agents en même temps dans un même channel : étude des options, puis implémentation de celle retenue." |
| 57 | 57 | - title: "M10 · Outils client ACP" |
| 58 | - state: open | |
| 58 | + state: closed | |
| 59 | 59 | description: "Sidekicks propose ses propres outils aux agents, en tant que client ACP, par les méthodes d'extension (protocole org.mini-me/tools de mini-me) : pression mémoire, à propos de Sidekicks, channel courant." |
| @@ -55,5 +55,5 @@ milestones: | |||
| 55 | state: open | 55 | state: open |
| 56 | description: "Faire répondre plusieurs agents en même temps dans un même channel : étude des options, puis implémentation de celle retenue." | 56 | description: "Faire répondre plusieurs agents en même temps dans un même channel : étude des options, puis implémentation de celle retenue." |
| 57 | - title: "M10 · Outils client ACP" | 57 | - title: "M10 · Outils client ACP" |
| 58 | - state: open | 58 | + state: closed |
| 59 | description: "Sidekicks propose ses propres outils aux agents, en tant que client ACP, par les méthodes d'extension (protocole org.mini-me/tools de mini-me) : pression mémoire, à propos de Sidekicks, channel courant." | 59 | description: "Sidekicks propose ses propres outils aux agents, en tant que client ACP, par les méthodes d'extension (protocole org.mini-me/tools de mini-me) : pression mémoire, à propos de Sidekicks, channel courant." |
modified
docs/en/README.md +1 -1 | @@ -7,7 +7,7 @@ This documentation follows [Diátaxis](https://diataxis.fr): pick the section th | ||
| 7 | 7 | | You want to… | Section | Pages | |
| 8 | 8 | | --- | --- | --- | |
| 9 | 9 | | **learn** by doing | Tutorials | [Your first agent, without writing any configuration](tutorials/your-first-agent.md) · [A channel with two agents](tutorials/first-channel.md) · [Your first conversation with an agent](tutorials/first-conversation.md) · [Your first launch of Sidekicks](tutorials/first-launch.md) · [Your first ACP exchange with a test agent](tutorials/first-acp-exchange.md) | |
| 10 | -| **do** a specific task | How-to guides | [Install Sidekicks](how-to/install-sidekicks.md) · [Add an agent](how-to/add-an-agent.md) · [Work with an agent's files and terminal](how-to/work-with-an-agents-files.md) · [Run an agent in a Docker container](how-to/run-an-agent-in-docker.md) · [Run an agent in an sbx sandbox](how-to/run-an-agent-in-a-sandbox.md) · [Add a Claude agent in an sbx sandbox](how-to/add-a-claude-agent-in-a-sandbox.md) · [Add a Codex agent in an sbx sandbox](how-to/add-a-codex-agent-in-a-sandbox.md) · [Add a Gemini agent in an sbx sandbox](how-to/add-a-gemini-agent-in-a-sandbox.md) · [Join files to a message](how-to/join-files-to-a-message.md) · [Manage channels and their agents](how-to/manage-channels.md) · [Edit or switch the configuration](how-to/edit-or-switch-the-configuration.md) · [Reset Sidekicks](how-to/reset-sidekicks.md) · [Watch the memory pressure](how-to/watch-the-memory-pressure.md) · [Develop the application](how-to/develop-the-application.md) · [Run the tests](how-to/run-the-tests.md) · [Check a change before merging it](how-to/check-before-merging.md) · [Run a test agent](how-to/run-a-test-agent.md) · [Run the end-to-end scenarios (v0.1)](how-to/run-the-end-to-end-scenarios.md) · [Set the version](how-to/set-the-version.md) · [Publish a release](how-to/publish-a-release.md) · [Sign and notarize for macOS](how-to/sign-and-notarize-on-macos.md) · [Test issue #52 on macOS](how-to/test-issue-52-on-macos.md) · [Test issues #49 and #50 on macOS](how-to/test-issues-49-and-50-on-macos.md) · [Test issue #47 on macOS](how-to/test-issue-47-on-macos.md) · [Test milestone M4 on macOS](how-to/test-milestone-m4-on-macos.md) · [Test milestone M3 on macOS](how-to/test-milestone-m3-on-macos.md) · [Test milestone M2 on macOS](how-to/test-milestone-m2-on-macos.md) · [Test milestone M1 on macOS](how-to/test-milestone-m1-on-macos.md) · [Test milestone Initialize on macOS](how-to/test-milestone-initialize-on-macos.md) | | |
| 10 | +| **do** a specific task | How-to guides | [Install Sidekicks](how-to/install-sidekicks.md) · [Add an agent](how-to/add-an-agent.md) · [Work with an agent's files and terminal](how-to/work-with-an-agents-files.md) · [Run an agent in a Docker container](how-to/run-an-agent-in-docker.md) · [Run an agent in an sbx sandbox](how-to/run-an-agent-in-a-sandbox.md) · [Add a Claude agent in an sbx sandbox](how-to/add-a-claude-agent-in-a-sandbox.md) · [Add a Codex agent in an sbx sandbox](how-to/add-a-codex-agent-in-a-sandbox.md) · [Add a Gemini agent in an sbx sandbox](how-to/add-a-gemini-agent-in-a-sandbox.md) · [Join files to a message](how-to/join-files-to-a-message.md) · [Manage channels and their agents](how-to/manage-channels.md) · [Edit or switch the configuration](how-to/edit-or-switch-the-configuration.md) · [Reset Sidekicks](how-to/reset-sidekicks.md) · [Watch the memory pressure](how-to/watch-the-memory-pressure.md) · [Let an agent use Sidekicks' tools](how-to/use-sidekicks-tools-from-an-agent.md) · [Develop the application](how-to/develop-the-application.md) · [Run the tests](how-to/run-the-tests.md) · [Check a change before merging it](how-to/check-before-merging.md) · [Run a test agent](how-to/run-a-test-agent.md) · [Run the end-to-end scenarios (v0.1)](how-to/run-the-end-to-end-scenarios.md) · [Set the version](how-to/set-the-version.md) · [Publish a release](how-to/publish-a-release.md) · [Sign and notarize for macOS](how-to/sign-and-notarize-on-macos.md) · [Test issue #52 on macOS](how-to/test-issue-52-on-macos.md) · [Test issues #49 and #50 on macOS](how-to/test-issues-49-and-50-on-macos.md) · [Test issue #47 on macOS](how-to/test-issue-47-on-macos.md) · [Test milestone M4 on macOS](how-to/test-milestone-m4-on-macos.md) · [Test milestone M3 on macOS](how-to/test-milestone-m3-on-macos.md) · [Test milestone M2 on macOS](how-to/test-milestone-m2-on-macos.md) · [Test milestone M1 on macOS](how-to/test-milestone-m1-on-macos.md) · [Test milestone Initialize on macOS](how-to/test-milestone-initialize-on-macos.md) | | |
| 11 | 11 | | **look up** an exact detail | Reference | [The configuration file](reference/configuration.md) · [Keyboard shortcuts](reference/keyboard-shortcuts.md) · [Agents, channels and events](reference/agents-and-events.md) · [Commands](reference/commands.md) · [scripts/agents.sh](reference/agents-script.md) | |
| 12 | 12 | | **understand** why | Explanation | [Workspaces and terminals](explanation/workspaces-and-terminals.md) · [Channels and what each agent knows](explanation/channels-and-context.md) · [Permissions and trust](explanation/permissions.md) · [Why ACP](explanation/why-acp.md) · [The interface stack](explanation/ui-stack.md) · [Architecture](explanation/architecture.md) · [Memory and local models](explanation/memory-and-local-models.md) | |
| 13 | 13 | |
| @@ -7,7 +7,7 @@ This documentation follows [Diátaxis](https://diataxis.fr): pick the section th | |||
| 7 | | You want to… | Section | Pages | | 7 | | You want to… | Section | Pages | |
| 8 | | --- | --- | --- | | 8 | | --- | --- | --- | |
| 9 | | **learn** by doing | Tutorials | [Your first agent, without writing any configuration](tutorials/your-first-agent.md) · [A channel with two agents](tutorials/first-channel.md) · [Your first conversation with an agent](tutorials/first-conversation.md) · [Your first launch of Sidekicks](tutorials/first-launch.md) · [Your first ACP exchange with a test agent](tutorials/first-acp-exchange.md) | | 9 | | **learn** by doing | Tutorials | [Your first agent, without writing any configuration](tutorials/your-first-agent.md) · [A channel with two agents](tutorials/first-channel.md) · [Your first conversation with an agent](tutorials/first-conversation.md) · [Your first launch of Sidekicks](tutorials/first-launch.md) · [Your first ACP exchange with a test agent](tutorials/first-acp-exchange.md) | |
| 10 | -| **do** a specific task | How-to guides | [Install Sidekicks](how-to/install-sidekicks.md) · [Add an agent](how-to/add-an-agent.md) · [Work with an agent's files and terminal](how-to/work-with-an-agents-files.md) · [Run an agent in a Docker container](how-to/run-an-agent-in-docker.md) · [Run an agent in an sbx sandbox](how-to/run-an-agent-in-a-sandbox.md) · [Add a Claude agent in an sbx sandbox](how-to/add-a-claude-agent-in-a-sandbox.md) · [Add a Codex agent in an sbx sandbox](how-to/add-a-codex-agent-in-a-sandbox.md) · [Add a Gemini agent in an sbx sandbox](how-to/add-a-gemini-agent-in-a-sandbox.md) · [Join files to a message](how-to/join-files-to-a-message.md) · [Manage channels and their agents](how-to/manage-channels.md) · [Edit or switch the configuration](how-to/edit-or-switch-the-configuration.md) · [Reset Sidekicks](how-to/reset-sidekicks.md) · [Watch the memory pressure](how-to/watch-the-memory-pressure.md) · [Develop the application](how-to/develop-the-application.md) · [Run the tests](how-to/run-the-tests.md) · [Check a change before merging it](how-to/check-before-merging.md) · [Run a test agent](how-to/run-a-test-agent.md) · [Run the end-to-end scenarios (v0.1)](how-to/run-the-end-to-end-scenarios.md) · [Set the version](how-to/set-the-version.md) · [Publish a release](how-to/publish-a-release.md) · [Sign and notarize for macOS](how-to/sign-and-notarize-on-macos.md) · [Test issue #52 on macOS](how-to/test-issue-52-on-macos.md) · [Test issues #49 and #50 on macOS](how-to/test-issues-49-and-50-on-macos.md) · [Test issue #47 on macOS](how-to/test-issue-47-on-macos.md) · [Test milestone M4 on macOS](how-to/test-milestone-m4-on-macos.md) · [Test milestone M3 on macOS](how-to/test-milestone-m3-on-macos.md) · [Test milestone M2 on macOS](how-to/test-milestone-m2-on-macos.md) · [Test milestone M1 on macOS](how-to/test-milestone-m1-on-macos.md) · [Test milestone Initialize on macOS](how-to/test-milestone-initialize-on-macos.md) | | 10 | +| **do** a specific task | How-to guides | [Install Sidekicks](how-to/install-sidekicks.md) · [Add an agent](how-to/add-an-agent.md) · [Work with an agent's files and terminal](how-to/work-with-an-agents-files.md) · [Run an agent in a Docker container](how-to/run-an-agent-in-docker.md) · [Run an agent in an sbx sandbox](how-to/run-an-agent-in-a-sandbox.md) · [Add a Claude agent in an sbx sandbox](how-to/add-a-claude-agent-in-a-sandbox.md) · [Add a Codex agent in an sbx sandbox](how-to/add-a-codex-agent-in-a-sandbox.md) · [Add a Gemini agent in an sbx sandbox](how-to/add-a-gemini-agent-in-a-sandbox.md) · [Join files to a message](how-to/join-files-to-a-message.md) · [Manage channels and their agents](how-to/manage-channels.md) · [Edit or switch the configuration](how-to/edit-or-switch-the-configuration.md) · [Reset Sidekicks](how-to/reset-sidekicks.md) · [Watch the memory pressure](how-to/watch-the-memory-pressure.md) · [Let an agent use Sidekicks' tools](how-to/use-sidekicks-tools-from-an-agent.md) · [Develop the application](how-to/develop-the-application.md) · [Run the tests](how-to/run-the-tests.md) · [Check a change before merging it](how-to/check-before-merging.md) · [Run a test agent](how-to/run-a-test-agent.md) · [Run the end-to-end scenarios (v0.1)](how-to/run-the-end-to-end-scenarios.md) · [Set the version](how-to/set-the-version.md) · [Publish a release](how-to/publish-a-release.md) · [Sign and notarize for macOS](how-to/sign-and-notarize-on-macos.md) · [Test issue #52 on macOS](how-to/test-issue-52-on-macos.md) · [Test issues #49 and #50 on macOS](how-to/test-issues-49-and-50-on-macos.md) · [Test issue #47 on macOS](how-to/test-issue-47-on-macos.md) · [Test milestone M4 on macOS](how-to/test-milestone-m4-on-macos.md) · [Test milestone M3 on macOS](how-to/test-milestone-m3-on-macos.md) · [Test milestone M2 on macOS](how-to/test-milestone-m2-on-macos.md) · [Test milestone M1 on macOS](how-to/test-milestone-m1-on-macos.md) · [Test milestone Initialize on macOS](how-to/test-milestone-initialize-on-macos.md) | |
| 11 | | **look up** an exact detail | Reference | [The configuration file](reference/configuration.md) · [Keyboard shortcuts](reference/keyboard-shortcuts.md) · [Agents, channels and events](reference/agents-and-events.md) · [Commands](reference/commands.md) · [scripts/agents.sh](reference/agents-script.md) | | 11 | | **look up** an exact detail | Reference | [The configuration file](reference/configuration.md) · [Keyboard shortcuts](reference/keyboard-shortcuts.md) · [Agents, channels and events](reference/agents-and-events.md) · [Commands](reference/commands.md) · [scripts/agents.sh](reference/agents-script.md) | |
| 12 | | **understand** why | Explanation | [Workspaces and terminals](explanation/workspaces-and-terminals.md) · [Channels and what each agent knows](explanation/channels-and-context.md) · [Permissions and trust](explanation/permissions.md) · [Why ACP](explanation/why-acp.md) · [The interface stack](explanation/ui-stack.md) · [Architecture](explanation/architecture.md) · [Memory and local models](explanation/memory-and-local-models.md) | | 12 | | **understand** why | Explanation | [Workspaces and terminals](explanation/workspaces-and-terminals.md) · [Channels and what each agent knows](explanation/channels-and-context.md) · [Permissions and trust](explanation/permissions.md) · [Why ACP](explanation/why-acp.md) · [The interface stack](explanation/ui-stack.md) · [Architecture](explanation/architecture.md) · [Memory and local models](explanation/memory-and-local-models.md) | |
| 13 | 13 | ||
modified
docs/en/explanation/why-acp.md +8 -0 | @@ -17,6 +17,14 @@ Reading a specification is not the same as watching an agent. The spike drove th | ||
| 17 | 17 | - **Skills are slash commands.** Garfield's skills arrive as commands, and `/idioms Il pleut des cordes.` sent as plain text runs the skill. In a channel with several agents, `/garfield:idioms …` only needs Sidekicks to strip the agent's name and send the rest to Garfield. |
| 18 | 18 | - **A small model does not take no for an answer.** Refused once, Riker retried the same action forty times in different forms until mm gave up with an error. A permission dialog that only offers "allow" and "reject" leaves a non-technical user facing forty dialogs; hence "never in this conversation" and "stop the agent" (see the [wireframe](../../design/04-permission.png)). |
| 19 | 19 | |
| 20 | +## Offering tools to the agents | |
| 21 | + | |
| 22 | +ACP lets a client answer methods of its own (names starting with `_`), but says nothing about how an agent learns them, nor how a model calls them. mini-me fills that gap with a small protocol, `org.mini-me/tools`: the client lists its tools, and mm turns each one into a tool of its model, `client_<name>`. Sidekicks speaks it (issue #90) because only Sidekicks knows some things an agent is asked about: the memory pressure of the computer it shares with the agents, the version of the application, the channel a conversation happens in and who else is there. Offering a tool costs an agent nothing when it does not know the protocol: the list travels in `_meta`, which ACP tells every agent to ignore when it does not understand it. Sidekicks follows the agent's choice of discovery, read in its file, rather than a setting of its own: the agent's file already says it, and two places to keep in step would drift apart. | |
| 23 | + | |
| 24 | +Few ACP agents can use these tools. ACP defines how a client answers an extension method, not how an agent finds out which ones exist: discovering a client's tools and handing them to a model is a convention between the two sides, and each agent would need its own. mini-me has one, `acp.clientTools`, and its documentation describes it as a specification any client can implement; that is the one Sidekicks follows. Claude (`claude-agent-acp`), Codex (`codex-acp`), Gemini (`gemini --acp`) and docker-agent do not discover client tools today: they start and answer as before, without them. If another agent adopts a discovery convention, Sidekicks can answer it with the same tools, since only the way the list is announced differs. | |
| 25 | + | |
| 26 | +Some tools read Sidekicks' history (issue #91): the list of channels and a search in any of them. An agent already reads the history of the channels it is a member of, since it is told what it has not seen; these tools open the others too. That is deliberate: asking an agent "what did we decide about Lyon last week?" is useful precisely when the decision was taken elsewhere. The user keeps the choice with one setting, `agentTools`, on by default: off, or a list of the tools offered. It is global rather than per agent because a per-agent list would have to be kept in step with every agent added, for a need nobody has yet; it can come later. The search reads the stored messages one by one, since the store has no text index: a channel's history is small enough for it. | |
| 27 | + | |
| 20 | 28 | ## Rejected alternatives |
| 21 | 29 | |
| 22 | 30 | - **Writing the JSON-RPC layer by hand**: possible, but the Go SDK by Coder is generated from the official schema, covers every v1 message, and has no dependencies. Owning that code would be cost without benefit. |
| @@ -17,6 +17,14 @@ Reading a specification is not the same as watching an agent. The spike drove th | |||
| 17 | - **Skills are slash commands.** Garfield's skills arrive as commands, and `/idioms Il pleut des cordes.` sent as plain text runs the skill. In a channel with several agents, `/garfield:idioms …` only needs Sidekicks to strip the agent's name and send the rest to Garfield. | 17 | - **Skills are slash commands.** Garfield's skills arrive as commands, and `/idioms Il pleut des cordes.` sent as plain text runs the skill. In a channel with several agents, `/garfield:idioms …` only needs Sidekicks to strip the agent's name and send the rest to Garfield. |
| 18 | - **A small model does not take no for an answer.** Refused once, Riker retried the same action forty times in different forms until mm gave up with an error. A permission dialog that only offers "allow" and "reject" leaves a non-technical user facing forty dialogs; hence "never in this conversation" and "stop the agent" (see the [wireframe](../../design/04-permission.png)). | 18 | - **A small model does not take no for an answer.** Refused once, Riker retried the same action forty times in different forms until mm gave up with an error. A permission dialog that only offers "allow" and "reject" leaves a non-technical user facing forty dialogs; hence "never in this conversation" and "stop the agent" (see the [wireframe](../../design/04-permission.png)). |
| 19 | 19 | ||
| 20 | +## Offering tools to the agents | ||
| 21 | + | ||
| 22 | +ACP lets a client answer methods of its own (names starting with `_`), but says nothing about how an agent learns them, nor how a model calls them. mini-me fills that gap with a small protocol, `org.mini-me/tools`: the client lists its tools, and mm turns each one into a tool of its model, `client_<name>`. Sidekicks speaks it (issue #90) because only Sidekicks knows some things an agent is asked about: the memory pressure of the computer it shares with the agents, the version of the application, the channel a conversation happens in and who else is there. Offering a tool costs an agent nothing when it does not know the protocol: the list travels in `_meta`, which ACP tells every agent to ignore when it does not understand it. Sidekicks follows the agent's choice of discovery, read in its file, rather than a setting of its own: the agent's file already says it, and two places to keep in step would drift apart. | ||
| 23 | + | ||
| 24 | +Few ACP agents can use these tools. ACP defines how a client answers an extension method, not how an agent finds out which ones exist: discovering a client's tools and handing them to a model is a convention between the two sides, and each agent would need its own. mini-me has one, `acp.clientTools`, and its documentation describes it as a specification any client can implement; that is the one Sidekicks follows. Claude (`claude-agent-acp`), Codex (`codex-acp`), Gemini (`gemini --acp`) and docker-agent do not discover client tools today: they start and answer as before, without them. If another agent adopts a discovery convention, Sidekicks can answer it with the same tools, since only the way the list is announced differs. | ||
| 25 | + | ||
| 26 | +Some tools read Sidekicks' history (issue #91): the list of channels and a search in any of them. An agent already reads the history of the channels it is a member of, since it is told what it has not seen; these tools open the others too. That is deliberate: asking an agent "what did we decide about Lyon last week?" is useful precisely when the decision was taken elsewhere. The user keeps the choice with one setting, `agentTools`, on by default: off, or a list of the tools offered. It is global rather than per agent because a per-agent list would have to be kept in step with every agent added, for a need nobody has yet; it can come later. The search reads the stored messages one by one, since the store has no text index: a channel's history is small enough for it. | ||
| 27 | + | ||
| 20 | ## Rejected alternatives | 28 | ## Rejected alternatives |
| 21 | 29 | ||
| 22 | - **Writing the JSON-RPC layer by hand**: possible, but the Go SDK by Coder is generated from the official schema, covers every v1 message, and has no dependencies. Owning that code would be cost without benefit. | 30 | - **Writing the JSON-RPC layer by hand**: possible, but the Go SDK by Coder is generated from the official schema, covers every v1 message, and has no dependencies. Owning that code would be cost without benefit. |
modified
docs/en/how-to/manage-channels.md +1 -0 | @@ -74,6 +74,7 @@ An agent does not call itself, an agent that answers your message anyway is not | ||
| 74 | 74 | |
| 75 | 75 | ## Variants |
| 76 | 76 | |
| 77 | +- **Leave a message half written**: switch to another channel or conversation; when you come back, the text you were writing is still there, until you send it. Drafts are kept while Sidekicks runs, not after quitting. | |
| 77 | 78 | - **Fold the lists of the left panel**: click the heading **AGENTS** or **CHANNELS** to fold the list under it, again to unfold it. Folded, the heading still shows how many agents or channels there are and, in blue, the answers you have not read yet. Sidekicks remembers it at the next launch. ⌘N unfolds the channels to create one; **Add an agent** stays in the command palette (⌘K) and on ⇧⌘N. |
| 78 | 79 | - **Channels from the configuration file**: channels declared under `channels:` are created at startup if they do not exist yet, with their agents; afterwards they are ordinary channels. Removing them from the file deletes nothing ([configuration reference](../reference/configuration.md)). |
| 79 | 80 | - **Start again from an empty history, for every channel at once**: use the **Danger zone** ([Reset Sidekicks](reset-sidekicks.md)), or quit Sidekicks and delete the folder `sidekicks/data/<…>` of your configuration (its location is in the [reference](../reference/agents-and-events.md#history)). The channels declared in the file come back at the next launch, empty. |
| @@ -74,6 +74,7 @@ An agent does not call itself, an agent that answers your message anyway is not | |||
| 74 | 74 | ||
| 75 | ## Variants | 75 | ## Variants |
| 76 | 76 | ||
| 77 | +- **Leave a message half written**: switch to another channel or conversation; when you come back, the text you were writing is still there, until you send it. Drafts are kept while Sidekicks runs, not after quitting. | ||
| 77 | - **Fold the lists of the left panel**: click the heading **AGENTS** or **CHANNELS** to fold the list under it, again to unfold it. Folded, the heading still shows how many agents or channels there are and, in blue, the answers you have not read yet. Sidekicks remembers it at the next launch. ⌘N unfolds the channels to create one; **Add an agent** stays in the command palette (⌘K) and on ⇧⌘N. | 78 | - **Fold the lists of the left panel**: click the heading **AGENTS** or **CHANNELS** to fold the list under it, again to unfold it. Folded, the heading still shows how many agents or channels there are and, in blue, the answers you have not read yet. Sidekicks remembers it at the next launch. ⌘N unfolds the channels to create one; **Add an agent** stays in the command palette (⌘K) and on ⇧⌘N. |
| 78 | - **Channels from the configuration file**: channels declared under `channels:` are created at startup if they do not exist yet, with their agents; afterwards they are ordinary channels. Removing them from the file deletes nothing ([configuration reference](../reference/configuration.md)). | 79 | - **Channels from the configuration file**: channels declared under `channels:` are created at startup if they do not exist yet, with their agents; afterwards they are ordinary channels. Removing them from the file deletes nothing ([configuration reference](../reference/configuration.md)). |
| 79 | - **Start again from an empty history, for every channel at once**: use the **Danger zone** ([Reset Sidekicks](reset-sidekicks.md)), or quit Sidekicks and delete the folder `sidekicks/data/<…>` of your configuration (its location is in the [reference](../reference/agents-and-events.md#history)). The channels declared in the file come back at the next launch, empty. | 80 | - **Start again from an empty history, for every channel at once**: use the **Danger zone** ([Reset Sidekicks](reset-sidekicks.md)), or quit Sidekicks and delete the folder `sidekicks/data/<…>` of your configuration (its location is in the [reference](../reference/agents-and-events.md#history)). The channels declared in the file come back at the next launch, empty. |
added
docs/en/how-to/use-sidekicks-tools-from-an-agent.md +56 -0 | new file mode 100644 | ||
| @@ -0,0 +1,56 @@ | ||
| 1 | +# How to let an agent use Sidekicks' tools | |
| 2 | + | |
| 3 | +This guide shows how to let a mini-me agent (`mm`) call the tools Sidekicks offers it: the memory pressure of the computer, what Sidekicks is, the channel it is talking in, the list of channels and of agents, and a search in the history of any channel. Few ACP agents can discover the tools of their client; mini-me can, which is why this guide uses it. It assumes the agent is already added (see [Add an agent](add-an-agent.md)) and started with `--acp --config <file>`. | |
| 4 | + | |
| 5 | +## Steps | |
| 6 | + | |
| 7 | +1. Open the agent's file (`agent.yaml`) and add, under `acp:`: | |
| 8 | + | |
| 9 | + ```yaml | |
| 10 | + acp: | |
| 11 | + clientTools: | |
| 12 | + enabled: true | |
| 13 | + discovery: meta # or request | |
| 14 | + permissions: auto # ask: the user allows each call | |
| 15 | + timeout: 30s | |
| 16 | + ``` | |
| 17 | + | |
| 18 | +2. Restart the agent: in Sidekicks, **Stop** then send it a message, or quit and relaunch Sidekicks. The tools are offered when the agent starts. | |
| 19 | +3. Ask it, for instance in `#general`: | |
| 20 | + - `@riker what is the memory pressure?` — it calls `client_memory_pressure`; | |
| 21 | + - `@riker what is Sidekicks?` — it calls `client_about_sidekicks`; | |
| 22 | + - `@riker which channel are we in, and who is here?` — it calls `client_current_channel`; | |
| 23 | + - `@riker list the channels` — it calls `client_list_channels`; | |
| 24 | + - `@riker which agents are there?` — it calls `client_list_agents`; | |
| 25 | + - `@riker what did we say about Lyon in #general?` — it calls `client_search_messages` with `query: Lyon` and `channel: general`. | |
| 26 | + | |
| 27 | + The call shows in its answer like any tool call (`client: memory_pressure`), and in its log (`[acp] client tools (meta): …` at start). | |
| 28 | + | |
| 29 | +A model may answer a question it was already asked from its earlier answer instead of calling the tool again; the descriptions of the tools whose result changes (memory, channels, agents, search) tell it to call again each time, and a small model follows that better when its instructions say it too. A small model also calls a tool more readily when its instructions name it: add to its `system:` a line such as "Call client_current_channel to know where you are and who is there." | |
| 30 | + | |
| 31 | +## Variants | |
| 32 | + | |
| 33 | +- **Choose the tools offered, or turn them off**: in **Settings**, add to the configuration of Sidekicks | |
| 34 | + | |
| 35 | + ```yaml | |
| 36 | + agentTools: | |
| 37 | + enabled: true # false: no tool at all | |
| 38 | + offer: # only these; without "offer", all of them | |
| 39 | + - memory_pressure | |
| 40 | + - current_channel | |
| 41 | + - list_agents | |
| 42 | + ``` | |
| 43 | + | |
| 44 | + then save. The tools are read when an agent starts: a running agent whose tools change shows "restart to apply changes"; restart it. The editor suggests the names after `- `. An unknown name is shown as a warning. | |
| 45 | +- **The agent says it has no such tool**: open its log (**Log** in the status bar). At start, Sidekicks writes `sidekicks: tools offered (meta): about_sidekicks, current_channel, …`, then mm writes `[acp] client tools (meta): client_…` with the tools it took. A tool missing from the first line is left out by `agentTools`; from the second only, mm refused it (its stderr says why). If an older log lacks it, the agent was started before the change: restart it. If the log shows it and the agent still denies it, the model overlooked it: name the tool in its `system:` instructions. | |
| 46 | +- **The agent searches files with bash instead**: a channel named like a folder (`documentation`) can make a coding agent look for files. Name the channel with `#` and say "messages": `@riker search the messages of #documentation about Kotlin`. For a coding agent, add to its `system:` a line such as "To find what was said in a Sidekicks channel, call client_search_messages, never bash." | |
| 47 | +- **Keep an agent to its own channels**: `list_channels` lists every channel (the direct conversations are not listed), and `search_messages` reads every channel and direct conversation (`channel: @alice`), not only the agent's. Leave them out of `offer` if that is not wanted. | |
| 48 | + | |
| 49 | +- **`discovery: request`**: Sidekicks reads the agent's file (the one after `--config`) to know it, announces the tools only, and gives the list each time the agent opens a session. The file is read on this computer: an agent in a sandbox or a container must have it at the same path, which the assistant's sbx and Docker variants already require. | |
| 50 | +- **`permissions: ask`**, or `auto` without `yolo: true`: each call asks the user first, with the usual permission card (`client: <name>`). | |
| 51 | +- **Another agent** (Claude, Codex, Gemini, docker-agent): the tools are offered too, but these agents do not discover a client's tools and ignore them; they work as before. Few ACP agents can discover them today: mini-me can ([why](../explanation/why-acp.md#offering-tools-to-the-agents)). | |
| 52 | + | |
| 53 | +## See also | |
| 54 | + | |
| 55 | +- What each tool returns, and the protocol: [Tools offered to the agents](../reference/agents-and-events.md#tools-offered-to-the-agents) | |
| 56 | +- [Why Sidekicks speaks ACP](../explanation/why-acp.md#offering-tools-to-the-agents) | |
| new file mode 100644 | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | +# How to let an agent use Sidekicks' tools | ||
| 2 | + | ||
| 3 | +This guide shows how to let a mini-me agent (`mm`) call the tools Sidekicks offers it: the memory pressure of the computer, what Sidekicks is, the channel it is talking in, the list of channels and of agents, and a search in the history of any channel. Few ACP agents can discover the tools of their client; mini-me can, which is why this guide uses it. It assumes the agent is already added (see [Add an agent](add-an-agent.md)) and started with `--acp --config <file>`. | ||
| 4 | + | ||
| 5 | +## Steps | ||
| 6 | + | ||
| 7 | +1. Open the agent's file (`agent.yaml`) and add, under `acp:`: | ||
| 8 | + | ||
| 9 | + ```yaml | ||
| 10 | + acp: | ||
| 11 | + clientTools: | ||
| 12 | + enabled: true | ||
| 13 | + discovery: meta # or request | ||
| 14 | + permissions: auto # ask: the user allows each call | ||
| 15 | + timeout: 30s | ||
| 16 | + ``` | ||
| 17 | + | ||
| 18 | +2. Restart the agent: in Sidekicks, **Stop** then send it a message, or quit and relaunch Sidekicks. The tools are offered when the agent starts. | ||
| 19 | +3. Ask it, for instance in `#general`: | ||
| 20 | + - `@riker what is the memory pressure?` — it calls `client_memory_pressure`; | ||
| 21 | + - `@riker what is Sidekicks?` — it calls `client_about_sidekicks`; | ||
| 22 | + - `@riker which channel are we in, and who is here?` — it calls `client_current_channel`; | ||
| 23 | + - `@riker list the channels` — it calls `client_list_channels`; | ||
| 24 | + - `@riker which agents are there?` — it calls `client_list_agents`; | ||
| 25 | + - `@riker what did we say about Lyon in #general?` — it calls `client_search_messages` with `query: Lyon` and `channel: general`. | ||
| 26 | + | ||
| 27 | + The call shows in its answer like any tool call (`client: memory_pressure`), and in its log (`[acp] client tools (meta): …` at start). | ||
| 28 | + | ||
| 29 | +A model may answer a question it was already asked from its earlier answer instead of calling the tool again; the descriptions of the tools whose result changes (memory, channels, agents, search) tell it to call again each time, and a small model follows that better when its instructions say it too. A small model also calls a tool more readily when its instructions name it: add to its `system:` a line such as "Call client_current_channel to know where you are and who is there." | ||
| 30 | + | ||
| 31 | +## Variants | ||
| 32 | + | ||
| 33 | +- **Choose the tools offered, or turn them off**: in **Settings**, add to the configuration of Sidekicks | ||
| 34 | + | ||
| 35 | + ```yaml | ||
| 36 | + agentTools: | ||
| 37 | + enabled: true # false: no tool at all | ||
| 38 | + offer: # only these; without "offer", all of them | ||
| 39 | + - memory_pressure | ||
| 40 | + - current_channel | ||
| 41 | + - list_agents | ||
| 42 | + ``` | ||
| 43 | + | ||
| 44 | + then save. The tools are read when an agent starts: a running agent whose tools change shows "restart to apply changes"; restart it. The editor suggests the names after `- `. An unknown name is shown as a warning. | ||
| 45 | +- **The agent says it has no such tool**: open its log (**Log** in the status bar). At start, Sidekicks writes `sidekicks: tools offered (meta): about_sidekicks, current_channel, …`, then mm writes `[acp] client tools (meta): client_…` with the tools it took. A tool missing from the first line is left out by `agentTools`; from the second only, mm refused it (its stderr says why). If an older log lacks it, the agent was started before the change: restart it. If the log shows it and the agent still denies it, the model overlooked it: name the tool in its `system:` instructions. | ||
| 46 | +- **The agent searches files with bash instead**: a channel named like a folder (`documentation`) can make a coding agent look for files. Name the channel with `#` and say "messages": `@riker search the messages of #documentation about Kotlin`. For a coding agent, add to its `system:` a line such as "To find what was said in a Sidekicks channel, call client_search_messages, never bash." | ||
| 47 | +- **Keep an agent to its own channels**: `list_channels` lists every channel (the direct conversations are not listed), and `search_messages` reads every channel and direct conversation (`channel: @alice`), not only the agent's. Leave them out of `offer` if that is not wanted. | ||
| 48 | + | ||
| 49 | +- **`discovery: request`**: Sidekicks reads the agent's file (the one after `--config`) to know it, announces the tools only, and gives the list each time the agent opens a session. The file is read on this computer: an agent in a sandbox or a container must have it at the same path, which the assistant's sbx and Docker variants already require. | ||
| 50 | +- **`permissions: ask`**, or `auto` without `yolo: true`: each call asks the user first, with the usual permission card (`client: <name>`). | ||
| 51 | +- **Another agent** (Claude, Codex, Gemini, docker-agent): the tools are offered too, but these agents do not discover a client's tools and ignore them; they work as before. Few ACP agents can discover them today: mini-me can ([why](../explanation/why-acp.md#offering-tools-to-the-agents)). | ||
| 52 | + | ||
| 53 | +## See also | ||
| 54 | + | ||
| 55 | +- What each tool returns, and the protocol: [Tools offered to the agents](../reference/agents-and-events.md#tools-offered-to-the-agents) | ||
| 56 | +- [Why Sidekicks speaks ACP](../explanation/why-acp.md#offering-tools-to-the-agents) | ||
modified
docs/en/reference/agents-and-events.md +24 -0 | @@ -235,6 +235,30 @@ A file opened for editing has `path, content, version`; `version` identifies the | ||
| 235 | 235 | | `ChooseCompose()` | The native file dialog, for a Compose file. | |
| 236 | 236 | | `Reset(choice)` | The Danger zone: `settings` (default configuration, preferences forgotten), `history` (this configuration's), `allHistory` (every configuration's) or `everything`. Each thing reset is first kept as a dated copy; returns `{copies[]}`. The history is reopened empty and the declared channels created again; then `config:changed` is sent. | |
| 237 | 237 | |
| 238 | +## Tools offered to the agents | |
| 239 | + | |
| 240 | +Issues #90 and #91. Sidekicks offers every agent six tools, as [`agentTools`](configuration.md#agenttools) allows (all by default), with mini-me's protocol (`org.mini-me/tools`, ACP extension methods). An agent that knows it (`acp.clientTools` in an `mm` file) gives them to its model as `client_<name>`; the others ignore them. Few ACP agents discover a client's tools: among the agents Sidekicks documents, only mini-me does (not Claude, Codex, Gemini nor docker-agent). | |
| 241 | + | |
| 242 | +| Tool (the model sees) | Method | Returns | | |
| 243 | +| --- | --- | --- | | |
| 244 | +| `memory_pressure` (`client_memory_pressure`) | `_com.rickub.sidekicks/system/memory` | `Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %).`, as the **Log** panel shows it ([Watch the memory pressure](../how-to/watch-the-memory-pressure.md)); `The memory cannot be measured on this computer.` where it cannot be | | |
| 245 | +| `about_sidekicks` (`client_about_sidekicks`) | `_com.rickub.sidekicks/about` | Sidekicks' version (`info.version` of `build/config.yml`, `dev` for a development build), the system and architecture, what Sidekicks is, the agent's name in it, the releases page | | |
| 246 | +| `list_channels` (`client_list_channels`) | `_com.rickub.sidekicks/channels/list` | Every channel, oldest first, without the direct conversations: `#name: description. Members: @a (you), @b. 12 messages, the last on 2026-11-10 14:05.` | | |
| 247 | +| `list_agents` (`client_list_agents`) | `_com.rickub.sidekicks/agents/list` | Every agent of the configuration: `@name (you), title: description. Runs on the user's computer` (or `in a Docker container`, `in an sbx sandbox`) `; ready.` (its state: `stopped`, `starting`, `ready`, `busy`, `error`) | | |
| 248 | +| `search_messages` (`client_search_messages`) | `_com.rickub.sidekicks/messages/search` | The user and agent messages of a channel that contain `query`, case and accents ignored, the most recent first: `- 2026-11-10 14:05, @alice: …excerpt around the match…` (80 characters on each side). Parameters: `query` (required), `channel` (`general`, `#general`, or `@alice` for a direct conversation; default: the channel of the call's session), `limit` (default 10, at most 50). The whole stored history is read, not only the messages shown. An unknown channel is an error that lists the channels (a direct conversation is searched with `@agent`, it is not listed) | | |
| 249 | +| `current_channel` (`client_current_channel`) | `_com.rickub.sidekicks/channel/current` | `Channel #<name>.`, its description and its members (`you (@agent), @other, and the user.`), or `A direct conversation between the user and you (<agent>)…`. The channel is the one whose session (`_meta["org.mini-me/sessionId"]` of the call) the agent holds; a session of no channel is an error | | |
| 250 | + | |
| 251 | +Only `search_messages` takes parameters; its `inputSchema` says `query` is required. `list_channels` and `search_messages` read **every** channel, not only the ones the agent is a member of (it already reads those): leave them out of `agentTools.offer` when that is not wanted. A tool left out, or every tool with `enabled: false`, is not announced, and its method answers `-32601`. The protocol: | |
| 252 | + | |
| 253 | +| Step | What Sidekicks does | | |
| 254 | +| --- | --- | | |
| 255 | +| `initialize` | `clientCapabilities._meta["org.mini-me/tools"]` holds the list (`name, description, method`), or `true` when the agent's file says `acp.clientTools.discovery: request`. The file is the one after `--config` (or `-config`) in the agent's arguments, relative to its folder; without it, or unreadable, `meta`. `clientInfo.version` is Sidekicks' version | | |
| 256 | +| `_org.mini-me/tools/list` | answered with `{"tools": [...]}` | | |
| 257 | +| a tool's method | answered with `{"content":[{"type":"text","text":"…"}],"isError":false}`; a failure has `isError: true` and says why | | |
| 258 | +| any other `_…` method | JSON-RPC error `-32601` (Method not found) | | |
| 259 | + | |
| 260 | +When an agent starts, its log gets `sidekicks: tools offered (meta|request): <names>`, or `sidekicks: no tool offered (agentTools)`. With `acp.clientTools.permissions: ask` (or `auto` without `yolo`), mm asks before each call: the permission card shows `client: <name>`. | |
| 261 | + | |
| 238 | 262 | ## Stopping an agent |
| 239 | 263 | |
| 240 | 264 | The agent's stdin is closed; after 5 s the agent and its children get SIGTERM (time for `scripts/agents.sh` to unload the model); after 3 more seconds, SIGKILL. |
| @@ -235,6 +235,30 @@ A file opened for editing has `path, content, version`; `version` identifies the | |||
| 235 | | `ChooseCompose()` | The native file dialog, for a Compose file. | | 235 | | `ChooseCompose()` | The native file dialog, for a Compose file. | |
| 236 | | `Reset(choice)` | The Danger zone: `settings` (default configuration, preferences forgotten), `history` (this configuration's), `allHistory` (every configuration's) or `everything`. Each thing reset is first kept as a dated copy; returns `{copies[]}`. The history is reopened empty and the declared channels created again; then `config:changed` is sent. | | 236 | | `Reset(choice)` | The Danger zone: `settings` (default configuration, preferences forgotten), `history` (this configuration's), `allHistory` (every configuration's) or `everything`. Each thing reset is first kept as a dated copy; returns `{copies[]}`. The history is reopened empty and the declared channels created again; then `config:changed` is sent. | |
| 237 | 237 | ||
| 238 | +## Tools offered to the agents | ||
| 239 | + | ||
| 240 | +Issues #90 and #91. Sidekicks offers every agent six tools, as [`agentTools`](configuration.md#agenttools) allows (all by default), with mini-me's protocol (`org.mini-me/tools`, ACP extension methods). An agent that knows it (`acp.clientTools` in an `mm` file) gives them to its model as `client_<name>`; the others ignore them. Few ACP agents discover a client's tools: among the agents Sidekicks documents, only mini-me does (not Claude, Codex, Gemini nor docker-agent). | ||
| 241 | + | ||
| 242 | +| Tool (the model sees) | Method | Returns | | ||
| 243 | +| --- | --- | --- | | ||
| 244 | +| `memory_pressure` (`client_memory_pressure`) | `_com.rickub.sidekicks/system/memory` | `Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %).`, as the **Log** panel shows it ([Watch the memory pressure](../how-to/watch-the-memory-pressure.md)); `The memory cannot be measured on this computer.` where it cannot be | | ||
| 245 | +| `about_sidekicks` (`client_about_sidekicks`) | `_com.rickub.sidekicks/about` | Sidekicks' version (`info.version` of `build/config.yml`, `dev` for a development build), the system and architecture, what Sidekicks is, the agent's name in it, the releases page | | ||
| 246 | +| `list_channels` (`client_list_channels`) | `_com.rickub.sidekicks/channels/list` | Every channel, oldest first, without the direct conversations: `#name: description. Members: @a (you), @b. 12 messages, the last on 2026-11-10 14:05.` | | ||
| 247 | +| `list_agents` (`client_list_agents`) | `_com.rickub.sidekicks/agents/list` | Every agent of the configuration: `@name (you), title: description. Runs on the user's computer` (or `in a Docker container`, `in an sbx sandbox`) `; ready.` (its state: `stopped`, `starting`, `ready`, `busy`, `error`) | | ||
| 248 | +| `search_messages` (`client_search_messages`) | `_com.rickub.sidekicks/messages/search` | The user and agent messages of a channel that contain `query`, case and accents ignored, the most recent first: `- 2026-11-10 14:05, @alice: …excerpt around the match…` (80 characters on each side). Parameters: `query` (required), `channel` (`general`, `#general`, or `@alice` for a direct conversation; default: the channel of the call's session), `limit` (default 10, at most 50). The whole stored history is read, not only the messages shown. An unknown channel is an error that lists the channels (a direct conversation is searched with `@agent`, it is not listed) | | ||
| 249 | +| `current_channel` (`client_current_channel`) | `_com.rickub.sidekicks/channel/current` | `Channel #<name>.`, its description and its members (`you (@agent), @other, and the user.`), or `A direct conversation between the user and you (<agent>)…`. The channel is the one whose session (`_meta["org.mini-me/sessionId"]` of the call) the agent holds; a session of no channel is an error | | ||
| 250 | + | ||
| 251 | +Only `search_messages` takes parameters; its `inputSchema` says `query` is required. `list_channels` and `search_messages` read **every** channel, not only the ones the agent is a member of (it already reads those): leave them out of `agentTools.offer` when that is not wanted. A tool left out, or every tool with `enabled: false`, is not announced, and its method answers `-32601`. The protocol: | ||
| 252 | + | ||
| 253 | +| Step | What Sidekicks does | | ||
| 254 | +| --- | --- | | ||
| 255 | +| `initialize` | `clientCapabilities._meta["org.mini-me/tools"]` holds the list (`name, description, method`), or `true` when the agent's file says `acp.clientTools.discovery: request`. The file is the one after `--config` (or `-config`) in the agent's arguments, relative to its folder; without it, or unreadable, `meta`. `clientInfo.version` is Sidekicks' version | | ||
| 256 | +| `_org.mini-me/tools/list` | answered with `{"tools": [...]}` | | ||
| 257 | +| a tool's method | answered with `{"content":[{"type":"text","text":"…"}],"isError":false}`; a failure has `isError: true` and says why | | ||
| 258 | +| any other `_…` method | JSON-RPC error `-32601` (Method not found) | | ||
| 259 | + | ||
| 260 | +When an agent starts, its log gets `sidekicks: tools offered (meta|request): <names>`, or `sidekicks: no tool offered (agentTools)`. With `acp.clientTools.permissions: ask` (or `auto` without `yolo`), mm asks before each call: the permission card shows `client: <name>`. | ||
| 261 | + | ||
| 238 | ## Stopping an agent | 262 | ## Stopping an agent |
| 239 | 263 | ||
| 240 | The agent's stdin is closed; after 5 s the agent and its children get SIGTERM (time for `scripts/agents.sh` to unload the model); after 3 more seconds, SIGKILL. | 264 | The agent's stdin is closed; after 5 s the agent and its children get SIGTERM (time for `scripts/agents.sh` to unload the model); after 3 more seconds, SIGKILL. |
modified
docs/en/reference/configuration.md +20 -1 | @@ -38,6 +38,7 @@ The file is looked up in this order; the first one that applies wins: | ||
| 38 | 38 | | `version` | integer | yes | — | Format version; only `1` exists. A later format increments it, so Sidekicks can migrate or refuse an old file explicitly. | |
| 39 | 39 | | `ui` | object | no | | Interface preferences. | |
| 40 | 40 | | `limits` | object | no | | Resource limits. | |
| 41 | +| `agentTools` | object | no | | The tools Sidekicks offers the agents ([below](#agenttools)). | | |
| 41 | 42 | | `agents` | list of agents | yes | | The agents available with `@name`. May be empty. | |
| 42 | 43 | | `channels` | list of channels | no | `[]` | Channels created at startup when they do not exist yet. | |
| 43 | 44 | |
| @@ -58,6 +59,23 @@ Unknown keys are **errors**, at every level: a misspelt `comand:` must be report | ||
| 58 | 59 | | `stopIdleAgentsAfter` | Go duration (`30s`, `10m`, `1h30m`), or `0` (number or text) | `10m` | Stops an agent unused for this long, to free its memory. `0` never stops it. | |
| 59 | 60 | | `maxAgentHandoffs` | integer, 0 to 10 | `3` | In a channel, how many times one message may be handed from agent to agent: an agent whose answer mentions another member with `@name` gives it the floor ([Manage channels](../how-to/manage-channels.md#let-the-agents-call-each-other)). Once the limit is reached the chain stops, and says so. `0` turns it off. | |
| 60 | 61 | |
| 62 | +### `agentTools` | |
| 63 | + | |
| 64 | +The tools Sidekicks offers the agents that can discover them: today, mini-me agents whose file has `acp.clientTools` ([Let an agent use Sidekicks' tools](../how-to/use-sidekicks-tools-from-an-agent.md)). Few ACP agents discover a client's tools; the others ignore them. Read when an agent starts: after a change, a running agent whose tools differ shows "restart to apply changes" next to its name; restart it to apply. | |
| 65 | + | |
| 66 | +| Key | Type | Default | Meaning | | |
| 67 | +| --- | --- | --- | --- | | |
| 68 | +| `enabled` | boolean | `true` | `false`: no tool is offered; an agent that calls one anyway gets "Method not found". | | |
| 69 | +| `offer` | list of tool names | all | Only these tools are offered. The names: `memory_pressure`, `about_sidekicks`, `current_channel`, `list_channels`, `list_agents`, `search_messages` ([what each returns](agents-and-events.md#tools-offered-to-the-agents)). An unknown name is a warning; an empty list offers none. | | |
| 70 | + | |
| 71 | +`list_channels` lists **every** channel (not the direct conversations) and `search_messages` reads every channel and direct conversation, not only those of the agent: leave them out of `offer` to keep an agent to its own channels. | |
| 72 | + | |
| 73 | +```yaml | |
| 74 | +agentTools: | |
| 75 | + enabled: true | |
| 76 | + offer: [memory_pressure, about_sidekicks, current_channel, list_agents] | |
| 77 | +``` | |
| 78 | + | |
| 61 | 79 | ### An agent |
| 62 | 80 | |
| 63 | 81 | | Key | Type | Required | Default | Meaning | |
| @@ -168,7 +186,8 @@ JSON Schema cannot express them; the configuration loader (issue #9) checks them | ||
| 168 | 186 | 1. agent names are unique; |
| 169 | 187 | 2. channel names are unique; |
| 170 | 188 | 3. every name in a channel's `agents` is the name of an agent; |
| 171 | -4. `command` exists (in `PATH`, or as a file) — reported as a warning, since an agent may be installed later. | |
| 189 | +4. `command` exists (in `PATH`, or as a file) — reported as a warning, since an agent may be installed later; | |
| 190 | +5. every name of `agentTools.offer` is a tool — reported as a warning (`no tool is called "memory"; the tools are: …`): the other names still work. | |
| 172 | 191 | |
| 173 | 192 | ## Error messages |
| 174 | 193 | |
| @@ -38,6 +38,7 @@ The file is looked up in this order; the first one that applies wins: | |||
| 38 | | `version` | integer | yes | — | Format version; only `1` exists. A later format increments it, so Sidekicks can migrate or refuse an old file explicitly. | | 38 | | `version` | integer | yes | — | Format version; only `1` exists. A later format increments it, so Sidekicks can migrate or refuse an old file explicitly. | |
| 39 | | `ui` | object | no | | Interface preferences. | | 39 | | `ui` | object | no | | Interface preferences. | |
| 40 | | `limits` | object | no | | Resource limits. | | 40 | | `limits` | object | no | | Resource limits. | |
| 41 | +| `agentTools` | object | no | | The tools Sidekicks offers the agents ([below](#agenttools)). | | ||
| 41 | | `agents` | list of agents | yes | | The agents available with `@name`. May be empty. | | 42 | | `agents` | list of agents | yes | | The agents available with `@name`. May be empty. | |
| 42 | | `channels` | list of channels | no | `[]` | Channels created at startup when they do not exist yet. | | 43 | | `channels` | list of channels | no | `[]` | Channels created at startup when they do not exist yet. | |
| 43 | 44 | ||
| @@ -58,6 +59,23 @@ Unknown keys are **errors**, at every level: a misspelt `comand:` must be report | |||
| 58 | | `stopIdleAgentsAfter` | Go duration (`30s`, `10m`, `1h30m`), or `0` (number or text) | `10m` | Stops an agent unused for this long, to free its memory. `0` never stops it. | | 59 | | `stopIdleAgentsAfter` | Go duration (`30s`, `10m`, `1h30m`), or `0` (number or text) | `10m` | Stops an agent unused for this long, to free its memory. `0` never stops it. | |
| 59 | | `maxAgentHandoffs` | integer, 0 to 10 | `3` | In a channel, how many times one message may be handed from agent to agent: an agent whose answer mentions another member with `@name` gives it the floor ([Manage channels](../how-to/manage-channels.md#let-the-agents-call-each-other)). Once the limit is reached the chain stops, and says so. `0` turns it off. | | 60 | | `maxAgentHandoffs` | integer, 0 to 10 | `3` | In a channel, how many times one message may be handed from agent to agent: an agent whose answer mentions another member with `@name` gives it the floor ([Manage channels](../how-to/manage-channels.md#let-the-agents-call-each-other)). Once the limit is reached the chain stops, and says so. `0` turns it off. | |
| 60 | 61 | ||
| 62 | +### `agentTools` | ||
| 63 | + | ||
| 64 | +The tools Sidekicks offers the agents that can discover them: today, mini-me agents whose file has `acp.clientTools` ([Let an agent use Sidekicks' tools](../how-to/use-sidekicks-tools-from-an-agent.md)). Few ACP agents discover a client's tools; the others ignore them. Read when an agent starts: after a change, a running agent whose tools differ shows "restart to apply changes" next to its name; restart it to apply. | ||
| 65 | + | ||
| 66 | +| Key | Type | Default | Meaning | | ||
| 67 | +| --- | --- | --- | --- | | ||
| 68 | +| `enabled` | boolean | `true` | `false`: no tool is offered; an agent that calls one anyway gets "Method not found". | | ||
| 69 | +| `offer` | list of tool names | all | Only these tools are offered. The names: `memory_pressure`, `about_sidekicks`, `current_channel`, `list_channels`, `list_agents`, `search_messages` ([what each returns](agents-and-events.md#tools-offered-to-the-agents)). An unknown name is a warning; an empty list offers none. | | ||
| 70 | + | ||
| 71 | +`list_channels` lists **every** channel (not the direct conversations) and `search_messages` reads every channel and direct conversation, not only those of the agent: leave them out of `offer` to keep an agent to its own channels. | ||
| 72 | + | ||
| 73 | +```yaml | ||
| 74 | +agentTools: | ||
| 75 | + enabled: true | ||
| 76 | + offer: [memory_pressure, about_sidekicks, current_channel, list_agents] | ||
| 77 | +``` | ||
| 78 | + | ||
| 61 | ### An agent | 79 | ### An agent |
| 62 | 80 | ||
| 63 | | Key | Type | Required | Default | Meaning | | 81 | | Key | Type | Required | Default | Meaning | |
| @@ -168,7 +186,8 @@ JSON Schema cannot express them; the configuration loader (issue #9) checks them | |||
| 168 | 1. agent names are unique; | 186 | 1. agent names are unique; |
| 169 | 2. channel names are unique; | 187 | 2. channel names are unique; |
| 170 | 3. every name in a channel's `agents` is the name of an agent; | 188 | 3. every name in a channel's `agents` is the name of an agent; |
| 171 | -4. `command` exists (in `PATH`, or as a file) — reported as a warning, since an agent may be installed later. | 189 | +4. `command` exists (in `PATH`, or as a file) — reported as a warning, since an agent may be installed later; |
| 190 | +5. every name of `agentTools.offer` is a tool — reported as a warning (`no tool is called "memory"; the tools are: …`): the other names still work. | ||
| 172 | 191 | ||
| 173 | ## Error messages | 192 | ## Error messages |
| 174 | 193 | ||
modified
docs/fr/README.md +1 -1 | @@ -7,7 +7,7 @@ Cette documentation suit la méthode [Diátaxis](https://diataxis.fr) : choisiss | ||
| 7 | 7 | | Vous voulez… | Section | Pages | |
| 8 | 8 | | --- | --- | --- | |
| 9 | 9 | | **apprendre** en pratiquant | Tutoriels | [Votre premier agent, sans écrire de configuration](tutorials/premier-agent.md) · [Un channel avec deux agents](tutorials/premier-channel.md) · [Votre première conversation avec un agent](tutorials/premiere-conversation.md) · [Votre premier lancement de Sidekicks](tutorials/premier-lancement.md) · [Votre premier échange ACP avec un agent de test](tutorials/premier-echange-acp.md) | |
| 10 | -| **réaliser** une tâche précise | Guides pratiques | [Installer Sidekicks](how-to/installer-sidekicks.md) · [Ajouter un agent](how-to/ajouter-un-agent.md) · [Travailler avec les fichiers et le terminal d'un agent](how-to/fichiers-et-terminal-d-un-agent.md) · [Lancer un agent dans un conteneur Docker](how-to/lancer-un-agent-dans-docker.md) · [Lancer un agent dans une sandbox sbx](how-to/lancer-un-agent-dans-une-sandbox.md) · [Ajouter un agent Claude dans une sandbox sbx](how-to/ajouter-un-agent-claude-dans-une-sandbox.md) · [Ajouter un agent Codex dans une sandbox sbx](how-to/ajouter-un-agent-codex-dans-une-sandbox.md) · [Ajouter un agent Gemini dans une sandbox sbx](how-to/ajouter-un-agent-gemini-dans-une-sandbox.md) · [Joindre des fichiers à un message](how-to/joindre-des-fichiers-a-un-message.md) · [Gérer les channels et leurs agents](how-to/gerer-les-channels.md) · [Modifier ou changer la configuration](how-to/modifier-ou-changer-la-configuration.md) · [Repartir de zéro](how-to/repartir-de-zero.md) · [Surveiller la pression mémoire](how-to/surveiller-la-pression-memoire.md) · [Développer l'application](how-to/developper-l-application.md) · [Lancer les tests](how-to/lancer-les-tests.md) · [Vérifier une modification avant de la fusionner](how-to/verifier-avant-de-fusionner.md) · [Lancer un agent de test](how-to/lancer-un-agent-de-test.md) · [Dérouler les scénarios de bout en bout (v0.1)](how-to/derouler-les-scenarios-de-bout-en-bout.md) · [Définir la version](how-to/definir-la-version.md) · [Tester la CI locale (temporaire)](how-to/tester-la-ci-locale.md) · [Publier une release](how-to/publier-une-release.md) · [Signer et notariser pour macOS](how-to/signer-et-notariser-sous-macos.md) · [Tester l'issue #52 sous macOS](how-to/tester-l-issue-52-sous-macos.md) · [Tester les issues #49 et #50 sous macOS](how-to/tester-les-issues-49-et-50-sous-macos.md) · [Tester l'issue #47 sous macOS](how-to/tester-l-issue-47-sous-macos.md) · [Tester la milestone M4 sous macOS](how-to/tester-la-milestone-m4-sous-macos.md) · [Tester la milestone M3 sous macOS](how-to/tester-la-milestone-m3-sous-macos.md) · [Tester la milestone M2 sous macOS](how-to/tester-la-milestone-m2-sous-macos.md) · [Tester la milestone M1 sous macOS](how-to/tester-la-milestone-m1-sous-macos.md) · [Tester la milestone Initialize sous macOS](how-to/tester-la-milestone-initialize-sous-macos.md) | | |
| 10 | +| **réaliser** une tâche précise | Guides pratiques | [Installer Sidekicks](how-to/installer-sidekicks.md) · [Ajouter un agent](how-to/ajouter-un-agent.md) · [Travailler avec les fichiers et le terminal d'un agent](how-to/fichiers-et-terminal-d-un-agent.md) · [Lancer un agent dans un conteneur Docker](how-to/lancer-un-agent-dans-docker.md) · [Lancer un agent dans une sandbox sbx](how-to/lancer-un-agent-dans-une-sandbox.md) · [Ajouter un agent Claude dans une sandbox sbx](how-to/ajouter-un-agent-claude-dans-une-sandbox.md) · [Ajouter un agent Codex dans une sandbox sbx](how-to/ajouter-un-agent-codex-dans-une-sandbox.md) · [Ajouter un agent Gemini dans une sandbox sbx](how-to/ajouter-un-agent-gemini-dans-une-sandbox.md) · [Joindre des fichiers à un message](how-to/joindre-des-fichiers-a-un-message.md) · [Gérer les channels et leurs agents](how-to/gerer-les-channels.md) · [Modifier ou changer la configuration](how-to/modifier-ou-changer-la-configuration.md) · [Repartir de zéro](how-to/repartir-de-zero.md) · [Surveiller la pression mémoire](how-to/surveiller-la-pression-memoire.md) · [Laisser un agent utiliser les outils de Sidekicks](how-to/utiliser-les-outils-de-sidekicks-depuis-un-agent.md) · [Développer l'application](how-to/developper-l-application.md) · [Lancer les tests](how-to/lancer-les-tests.md) · [Vérifier une modification avant de la fusionner](how-to/verifier-avant-de-fusionner.md) · [Lancer un agent de test](how-to/lancer-un-agent-de-test.md) · [Dérouler les scénarios de bout en bout (v0.1)](how-to/derouler-les-scenarios-de-bout-en-bout.md) · [Définir la version](how-to/definir-la-version.md) · [Tester la CI locale (temporaire)](how-to/tester-la-ci-locale.md) · [Publier une release](how-to/publier-une-release.md) · [Signer et notariser pour macOS](how-to/signer-et-notariser-sous-macos.md) · [Tester l'issue #52 sous macOS](how-to/tester-l-issue-52-sous-macos.md) · [Tester les issues #49 et #50 sous macOS](how-to/tester-les-issues-49-et-50-sous-macos.md) · [Tester l'issue #47 sous macOS](how-to/tester-l-issue-47-sous-macos.md) · [Tester la milestone M4 sous macOS](how-to/tester-la-milestone-m4-sous-macos.md) · [Tester la milestone M3 sous macOS](how-to/tester-la-milestone-m3-sous-macos.md) · [Tester la milestone M2 sous macOS](how-to/tester-la-milestone-m2-sous-macos.md) · [Tester la milestone M1 sous macOS](how-to/tester-la-milestone-m1-sous-macos.md) · [Tester la milestone Initialize sous macOS](how-to/tester-la-milestone-initialize-sous-macos.md) | | |
| 11 | 11 | | **consulter** un détail exact | Référence | [Le fichier de configuration](reference/configuration.md) · [Raccourcis clavier](reference/raccourcis-clavier.md) · [Agents, channels et événements](reference/agents-et-evenements.md) · [Commandes](reference/commandes.md) · [scripts/agents.sh](reference/script-agents.md) | |
| 12 | 12 | | **comprendre** le pourquoi | Explications | [Workspaces et terminaux](explanation/workspaces-et-terminaux.md) · [Les channels et ce que sait chaque agent](explanation/channels-et-contexte.md) · [Permissions et confiance](explanation/permissions-et-confiance.md) · [Pourquoi ACP](explanation/pourquoi-acp.md) · [La stack de l'interface](explanation/stack-interface.md) · [Architecture](explanation/architecture.md) · [Mémoire et modèles locaux](explanation/memoire-et-modeles-locaux.md) | |
| 13 | 13 | |
| @@ -7,7 +7,7 @@ Cette documentation suit la méthode [Diátaxis](https://diataxis.fr) : choisiss | |||
| 7 | | Vous voulez… | Section | Pages | | 7 | | Vous voulez… | Section | Pages | |
| 8 | | --- | --- | --- | | 8 | | --- | --- | --- | |
| 9 | | **apprendre** en pratiquant | Tutoriels | [Votre premier agent, sans écrire de configuration](tutorials/premier-agent.md) · [Un channel avec deux agents](tutorials/premier-channel.md) · [Votre première conversation avec un agent](tutorials/premiere-conversation.md) · [Votre premier lancement de Sidekicks](tutorials/premier-lancement.md) · [Votre premier échange ACP avec un agent de test](tutorials/premier-echange-acp.md) | | 9 | | **apprendre** en pratiquant | Tutoriels | [Votre premier agent, sans écrire de configuration](tutorials/premier-agent.md) · [Un channel avec deux agents](tutorials/premier-channel.md) · [Votre première conversation avec un agent](tutorials/premiere-conversation.md) · [Votre premier lancement de Sidekicks](tutorials/premier-lancement.md) · [Votre premier échange ACP avec un agent de test](tutorials/premier-echange-acp.md) | |
| 10 | -| **réaliser** une tâche précise | Guides pratiques | [Installer Sidekicks](how-to/installer-sidekicks.md) · [Ajouter un agent](how-to/ajouter-un-agent.md) · [Travailler avec les fichiers et le terminal d'un agent](how-to/fichiers-et-terminal-d-un-agent.md) · [Lancer un agent dans un conteneur Docker](how-to/lancer-un-agent-dans-docker.md) · [Lancer un agent dans une sandbox sbx](how-to/lancer-un-agent-dans-une-sandbox.md) · [Ajouter un agent Claude dans une sandbox sbx](how-to/ajouter-un-agent-claude-dans-une-sandbox.md) · [Ajouter un agent Codex dans une sandbox sbx](how-to/ajouter-un-agent-codex-dans-une-sandbox.md) · [Ajouter un agent Gemini dans une sandbox sbx](how-to/ajouter-un-agent-gemini-dans-une-sandbox.md) · [Joindre des fichiers à un message](how-to/joindre-des-fichiers-a-un-message.md) · [Gérer les channels et leurs agents](how-to/gerer-les-channels.md) · [Modifier ou changer la configuration](how-to/modifier-ou-changer-la-configuration.md) · [Repartir de zéro](how-to/repartir-de-zero.md) · [Surveiller la pression mémoire](how-to/surveiller-la-pression-memoire.md) · [Développer l'application](how-to/developper-l-application.md) · [Lancer les tests](how-to/lancer-les-tests.md) · [Vérifier une modification avant de la fusionner](how-to/verifier-avant-de-fusionner.md) · [Lancer un agent de test](how-to/lancer-un-agent-de-test.md) · [Dérouler les scénarios de bout en bout (v0.1)](how-to/derouler-les-scenarios-de-bout-en-bout.md) · [Définir la version](how-to/definir-la-version.md) · [Tester la CI locale (temporaire)](how-to/tester-la-ci-locale.md) · [Publier une release](how-to/publier-une-release.md) · [Signer et notariser pour macOS](how-to/signer-et-notariser-sous-macos.md) · [Tester l'issue #52 sous macOS](how-to/tester-l-issue-52-sous-macos.md) · [Tester les issues #49 et #50 sous macOS](how-to/tester-les-issues-49-et-50-sous-macos.md) · [Tester l'issue #47 sous macOS](how-to/tester-l-issue-47-sous-macos.md) · [Tester la milestone M4 sous macOS](how-to/tester-la-milestone-m4-sous-macos.md) · [Tester la milestone M3 sous macOS](how-to/tester-la-milestone-m3-sous-macos.md) · [Tester la milestone M2 sous macOS](how-to/tester-la-milestone-m2-sous-macos.md) · [Tester la milestone M1 sous macOS](how-to/tester-la-milestone-m1-sous-macos.md) · [Tester la milestone Initialize sous macOS](how-to/tester-la-milestone-initialize-sous-macos.md) | | 10 | +| **réaliser** une tâche précise | Guides pratiques | [Installer Sidekicks](how-to/installer-sidekicks.md) · [Ajouter un agent](how-to/ajouter-un-agent.md) · [Travailler avec les fichiers et le terminal d'un agent](how-to/fichiers-et-terminal-d-un-agent.md) · [Lancer un agent dans un conteneur Docker](how-to/lancer-un-agent-dans-docker.md) · [Lancer un agent dans une sandbox sbx](how-to/lancer-un-agent-dans-une-sandbox.md) · [Ajouter un agent Claude dans une sandbox sbx](how-to/ajouter-un-agent-claude-dans-une-sandbox.md) · [Ajouter un agent Codex dans une sandbox sbx](how-to/ajouter-un-agent-codex-dans-une-sandbox.md) · [Ajouter un agent Gemini dans une sandbox sbx](how-to/ajouter-un-agent-gemini-dans-une-sandbox.md) · [Joindre des fichiers à un message](how-to/joindre-des-fichiers-a-un-message.md) · [Gérer les channels et leurs agents](how-to/gerer-les-channels.md) · [Modifier ou changer la configuration](how-to/modifier-ou-changer-la-configuration.md) · [Repartir de zéro](how-to/repartir-de-zero.md) · [Surveiller la pression mémoire](how-to/surveiller-la-pression-memoire.md) · [Laisser un agent utiliser les outils de Sidekicks](how-to/utiliser-les-outils-de-sidekicks-depuis-un-agent.md) · [Développer l'application](how-to/developper-l-application.md) · [Lancer les tests](how-to/lancer-les-tests.md) · [Vérifier une modification avant de la fusionner](how-to/verifier-avant-de-fusionner.md) · [Lancer un agent de test](how-to/lancer-un-agent-de-test.md) · [Dérouler les scénarios de bout en bout (v0.1)](how-to/derouler-les-scenarios-de-bout-en-bout.md) · [Définir la version](how-to/definir-la-version.md) · [Tester la CI locale (temporaire)](how-to/tester-la-ci-locale.md) · [Publier une release](how-to/publier-une-release.md) · [Signer et notariser pour macOS](how-to/signer-et-notariser-sous-macos.md) · [Tester l'issue #52 sous macOS](how-to/tester-l-issue-52-sous-macos.md) · [Tester les issues #49 et #50 sous macOS](how-to/tester-les-issues-49-et-50-sous-macos.md) · [Tester l'issue #47 sous macOS](how-to/tester-l-issue-47-sous-macos.md) · [Tester la milestone M4 sous macOS](how-to/tester-la-milestone-m4-sous-macos.md) · [Tester la milestone M3 sous macOS](how-to/tester-la-milestone-m3-sous-macos.md) · [Tester la milestone M2 sous macOS](how-to/tester-la-milestone-m2-sous-macos.md) · [Tester la milestone M1 sous macOS](how-to/tester-la-milestone-m1-sous-macos.md) · [Tester la milestone Initialize sous macOS](how-to/tester-la-milestone-initialize-sous-macos.md) | |
| 11 | | **consulter** un détail exact | Référence | [Le fichier de configuration](reference/configuration.md) · [Raccourcis clavier](reference/raccourcis-clavier.md) · [Agents, channels et événements](reference/agents-et-evenements.md) · [Commandes](reference/commandes.md) · [scripts/agents.sh](reference/script-agents.md) | | 11 | | **consulter** un détail exact | Référence | [Le fichier de configuration](reference/configuration.md) · [Raccourcis clavier](reference/raccourcis-clavier.md) · [Agents, channels et événements](reference/agents-et-evenements.md) · [Commandes](reference/commandes.md) · [scripts/agents.sh](reference/script-agents.md) | |
| 12 | | **comprendre** le pourquoi | Explications | [Workspaces et terminaux](explanation/workspaces-et-terminaux.md) · [Les channels et ce que sait chaque agent](explanation/channels-et-contexte.md) · [Permissions et confiance](explanation/permissions-et-confiance.md) · [Pourquoi ACP](explanation/pourquoi-acp.md) · [La stack de l'interface](explanation/stack-interface.md) · [Architecture](explanation/architecture.md) · [Mémoire et modèles locaux](explanation/memoire-et-modeles-locaux.md) | | 12 | | **comprendre** le pourquoi | Explications | [Workspaces et terminaux](explanation/workspaces-et-terminaux.md) · [Les channels et ce que sait chaque agent](explanation/channels-et-contexte.md) · [Permissions et confiance](explanation/permissions-et-confiance.md) · [Pourquoi ACP](explanation/pourquoi-acp.md) · [La stack de l'interface](explanation/stack-interface.md) · [Architecture](explanation/architecture.md) · [Mémoire et modèles locaux](explanation/memoire-et-modeles-locaux.md) | |
| 13 | 13 | ||
modified
docs/fr/explanation/pourquoi-acp.md +8 -0 | @@ -17,6 +17,14 @@ Lire une spécification n'est pas observer un agent. Le spike a piloté les agen | ||
| 17 | 17 | - **Les skills sont des commandes slash.** Les skills de Garfield arrivent comme des commandes, et `/idioms Il pleut des cordes.` envoyé comme simple texte lance le skill. Dans un channel à plusieurs agents, `/garfield:idioms …` demande seulement à Sidekicks de retirer le nom de l'agent et d'envoyer le reste à Garfield. |
| 18 | 18 | - **Un petit modèle n'accepte pas un refus.** Refusé une fois, Riker a retenté la même action quarante fois sous des formes différentes, jusqu'à ce que mm abandonne sur une erreur. Un dialogue de permission qui ne propose que « autoriser » et « refuser » mettrait un utilisateur non technique face à quarante dialogues ; d'où « jamais dans cette conversation » et « arrêter l'agent » (voir la [maquette](../../design/04-permission.png)). |
| 19 | 19 | |
| 20 | +## Proposer des outils aux agents | |
| 21 | + | |
| 22 | +ACP permet à un client de répondre à ses propres méthodes (dont le nom commence par `_`), mais ne dit ni comment un agent les découvre, ni comment un modèle les appelle. mini-me comble ce manque avec un petit protocole, `org.mini-me/tools` : le client liste ses outils, et mm fait de chacun un outil de son modèle, `client_<nom>`. Sidekicks le parle (ticket #90) parce que lui seul sait certaines choses qu'on demande à un agent : la pression mémoire de l'ordinateur qu'il partage avec les agents, la version de l'application, le channel où se passe une conversation et qui d'autre y est. Proposer un outil ne coûte rien à un agent qui ne connaît pas le protocole : la liste voyage dans `_meta`, qu'ACP demande à tout agent d'ignorer quand il ne le comprend pas. Sidekicks suit le mode de découverte choisi par l'agent, lu dans son fichier, plutôt qu'un réglage à lui : le fichier de l'agent le dit déjà, et deux endroits à garder d'accord finiraient par diverger. | |
| 23 | + | |
| 24 | +Peu d'agents ACP savent utiliser ces outils. ACP définit comment un client répond à une méthode d'extension, pas comment un agent apprend lesquelles existent : découvrir les outils d'un client et les donner à un modèle est une convention entre les deux côtés, et chaque agent aurait la sienne. mini-me en a une, `acp.clientTools`, que sa documentation décrit comme une spécification que tout client peut implémenter ; c'est celle que suit Sidekicks. Claude (`claude-agent-acp`), Codex (`codex-acp`), Gemini (`gemini --acp`) et docker-agent ne découvrent pas aujourd'hui les outils d'un client : ils démarrent et répondent comme avant, sans eux. Si un autre agent adopte une convention de découverte, Sidekicks pourra lui répondre avec les mêmes outils : seule la façon d'annoncer la liste change. | |
| 25 | + | |
| 26 | +Certains outils lisent l'historique de Sidekicks (ticket #91) : la liste des channels et une recherche dans n'importe lequel. Un agent lit déjà l'historique des channels dont il est membre, puisqu'on lui transmet ce qu'il n'a pas vu ; ces outils lui ouvrent aussi les autres. C'est voulu : demander à un agent « qu'avait-on décidé pour Lyon la semaine dernière ? » est utile justement quand la décision a été prise ailleurs. L'utilisateur garde le choix avec un seul réglage, `agentTools`, activé par défaut : désactivé, ou une liste des outils proposés. Il est global plutôt que par agent, car une liste par agent devrait être tenue à jour à chaque agent ajouté, pour un besoin que personne n'a encore ; elle pourra venir plus tard. La recherche lit les messages enregistrés un à un, faute d'index de texte dans le store : l'historique d'un channel est assez petit pour cela. | |
| 27 | + | |
| 20 | 28 | ## Alternatives écartées |
| 21 | 29 | |
| 22 | 30 | - **Écrire la couche JSON-RPC à la main** : possible, mais le SDK Go de Coder est généré depuis le schéma officiel, couvre tous les messages v1 et n'a aucune dépendance. Maintenir ce code nous-mêmes coûterait sans rien apporter. |
| @@ -17,6 +17,14 @@ Lire une spécification n'est pas observer un agent. Le spike a piloté les agen | |||
| 17 | - **Les skills sont des commandes slash.** Les skills de Garfield arrivent comme des commandes, et `/idioms Il pleut des cordes.` envoyé comme simple texte lance le skill. Dans un channel à plusieurs agents, `/garfield:idioms …` demande seulement à Sidekicks de retirer le nom de l'agent et d'envoyer le reste à Garfield. | 17 | - **Les skills sont des commandes slash.** Les skills de Garfield arrivent comme des commandes, et `/idioms Il pleut des cordes.` envoyé comme simple texte lance le skill. Dans un channel à plusieurs agents, `/garfield:idioms …` demande seulement à Sidekicks de retirer le nom de l'agent et d'envoyer le reste à Garfield. |
| 18 | - **Un petit modèle n'accepte pas un refus.** Refusé une fois, Riker a retenté la même action quarante fois sous des formes différentes, jusqu'à ce que mm abandonne sur une erreur. Un dialogue de permission qui ne propose que « autoriser » et « refuser » mettrait un utilisateur non technique face à quarante dialogues ; d'où « jamais dans cette conversation » et « arrêter l'agent » (voir la [maquette](../../design/04-permission.png)). | 18 | - **Un petit modèle n'accepte pas un refus.** Refusé une fois, Riker a retenté la même action quarante fois sous des formes différentes, jusqu'à ce que mm abandonne sur une erreur. Un dialogue de permission qui ne propose que « autoriser » et « refuser » mettrait un utilisateur non technique face à quarante dialogues ; d'où « jamais dans cette conversation » et « arrêter l'agent » (voir la [maquette](../../design/04-permission.png)). |
| 19 | 19 | ||
| 20 | +## Proposer des outils aux agents | ||
| 21 | + | ||
| 22 | +ACP permet à un client de répondre à ses propres méthodes (dont le nom commence par `_`), mais ne dit ni comment un agent les découvre, ni comment un modèle les appelle. mini-me comble ce manque avec un petit protocole, `org.mini-me/tools` : le client liste ses outils, et mm fait de chacun un outil de son modèle, `client_<nom>`. Sidekicks le parle (ticket #90) parce que lui seul sait certaines choses qu'on demande à un agent : la pression mémoire de l'ordinateur qu'il partage avec les agents, la version de l'application, le channel où se passe une conversation et qui d'autre y est. Proposer un outil ne coûte rien à un agent qui ne connaît pas le protocole : la liste voyage dans `_meta`, qu'ACP demande à tout agent d'ignorer quand il ne le comprend pas. Sidekicks suit le mode de découverte choisi par l'agent, lu dans son fichier, plutôt qu'un réglage à lui : le fichier de l'agent le dit déjà, et deux endroits à garder d'accord finiraient par diverger. | ||
| 23 | + | ||
| 24 | +Peu d'agents ACP savent utiliser ces outils. ACP définit comment un client répond à une méthode d'extension, pas comment un agent apprend lesquelles existent : découvrir les outils d'un client et les donner à un modèle est une convention entre les deux côtés, et chaque agent aurait la sienne. mini-me en a une, `acp.clientTools`, que sa documentation décrit comme une spécification que tout client peut implémenter ; c'est celle que suit Sidekicks. Claude (`claude-agent-acp`), Codex (`codex-acp`), Gemini (`gemini --acp`) et docker-agent ne découvrent pas aujourd'hui les outils d'un client : ils démarrent et répondent comme avant, sans eux. Si un autre agent adopte une convention de découverte, Sidekicks pourra lui répondre avec les mêmes outils : seule la façon d'annoncer la liste change. | ||
| 25 | + | ||
| 26 | +Certains outils lisent l'historique de Sidekicks (ticket #91) : la liste des channels et une recherche dans n'importe lequel. Un agent lit déjà l'historique des channels dont il est membre, puisqu'on lui transmet ce qu'il n'a pas vu ; ces outils lui ouvrent aussi les autres. C'est voulu : demander à un agent « qu'avait-on décidé pour Lyon la semaine dernière ? » est utile justement quand la décision a été prise ailleurs. L'utilisateur garde le choix avec un seul réglage, `agentTools`, activé par défaut : désactivé, ou une liste des outils proposés. Il est global plutôt que par agent, car une liste par agent devrait être tenue à jour à chaque agent ajouté, pour un besoin que personne n'a encore ; elle pourra venir plus tard. La recherche lit les messages enregistrés un à un, faute d'index de texte dans le store : l'historique d'un channel est assez petit pour cela. | ||
| 27 | + | ||
| 20 | ## Alternatives écartées | 28 | ## Alternatives écartées |
| 21 | 29 | ||
| 22 | - **Écrire la couche JSON-RPC à la main** : possible, mais le SDK Go de Coder est généré depuis le schéma officiel, couvre tous les messages v1 et n'a aucune dépendance. Maintenir ce code nous-mêmes coûterait sans rien apporter. | 30 | - **Écrire la couche JSON-RPC à la main** : possible, mais le SDK Go de Coder est généré depuis le schéma officiel, couvre tous les messages v1 et n'a aucune dépendance. Maintenir ce code nous-mêmes coûterait sans rien apporter. |
modified
docs/fr/how-to/gerer-les-channels.md +1 -0 | @@ -74,6 +74,7 @@ Un agent ne s'appelle pas lui-même, un agent qui répond de toute façon à vot | ||
| 74 | 74 | |
| 75 | 75 | ## Variantes |
| 76 | 76 | |
| 77 | +- **Laisser un message à moitié écrit** : passez à un autre channel ou à une autre conversation ; quand vous revenez, le texte en cours est toujours là, jusqu'à ce que vous l'envoyiez. Les brouillons sont gardés tant que Sidekicks tourne, pas après l'avoir quitté. | |
| 77 | 78 | - **Replier les listes du panneau de gauche** : cliquez sur le titre **AGENTS** ou **CHANNELS** pour replier la liste, à nouveau pour la déplier. Repliée, le titre indique toujours combien il y a d'agents ou de channels et, en bleu, les réponses pas encore lues. Sidekicks s'en souvient au lancement suivant. ⌘N déplie les channels pour en créer un ; **Ajouter un agent** reste dans la palette de commandes (⌘K) et sur ⇧⌘N. |
| 78 | 79 | - **Channels du fichier de configuration** : les channels déclarés sous `channels:` sont créés au démarrage s'ils n'existent pas encore, avec leurs agents ; ensuite ce sont des channels ordinaires. Les retirer du fichier ne supprime rien ([référence de la configuration](../reference/configuration.md)). |
| 79 | 80 | - **Repartir d'un historique vide, pour tous les channels d'un coup** : utilisez la **Danger zone** ([Repartir de zéro](repartir-de-zero.md)), ou quittez Sidekicks et supprimez le dossier `sidekicks/data/<…>` de votre configuration (son emplacement est dans la [référence](../reference/agents-et-evenements.md#historique)). Les channels déclarés dans le fichier reviennent, vides, au lancement suivant. |
| @@ -74,6 +74,7 @@ Un agent ne s'appelle pas lui-même, un agent qui répond de toute façon à vot | |||
| 74 | 74 | ||
| 75 | ## Variantes | 75 | ## Variantes |
| 76 | 76 | ||
| 77 | +- **Laisser un message à moitié écrit** : passez à un autre channel ou à une autre conversation ; quand vous revenez, le texte en cours est toujours là, jusqu'à ce que vous l'envoyiez. Les brouillons sont gardés tant que Sidekicks tourne, pas après l'avoir quitté. | ||
| 77 | - **Replier les listes du panneau de gauche** : cliquez sur le titre **AGENTS** ou **CHANNELS** pour replier la liste, à nouveau pour la déplier. Repliée, le titre indique toujours combien il y a d'agents ou de channels et, en bleu, les réponses pas encore lues. Sidekicks s'en souvient au lancement suivant. ⌘N déplie les channels pour en créer un ; **Ajouter un agent** reste dans la palette de commandes (⌘K) et sur ⇧⌘N. | 78 | - **Replier les listes du panneau de gauche** : cliquez sur le titre **AGENTS** ou **CHANNELS** pour replier la liste, à nouveau pour la déplier. Repliée, le titre indique toujours combien il y a d'agents ou de channels et, en bleu, les réponses pas encore lues. Sidekicks s'en souvient au lancement suivant. ⌘N déplie les channels pour en créer un ; **Ajouter un agent** reste dans la palette de commandes (⌘K) et sur ⇧⌘N. |
| 78 | - **Channels du fichier de configuration** : les channels déclarés sous `channels:` sont créés au démarrage s'ils n'existent pas encore, avec leurs agents ; ensuite ce sont des channels ordinaires. Les retirer du fichier ne supprime rien ([référence de la configuration](../reference/configuration.md)). | 79 | - **Channels du fichier de configuration** : les channels déclarés sous `channels:` sont créés au démarrage s'ils n'existent pas encore, avec leurs agents ; ensuite ce sont des channels ordinaires. Les retirer du fichier ne supprime rien ([référence de la configuration](../reference/configuration.md)). |
| 79 | - **Repartir d'un historique vide, pour tous les channels d'un coup** : utilisez la **Danger zone** ([Repartir de zéro](repartir-de-zero.md)), ou quittez Sidekicks et supprimez le dossier `sidekicks/data/<…>` de votre configuration (son emplacement est dans la [référence](../reference/agents-et-evenements.md#historique)). Les channels déclarés dans le fichier reviennent, vides, au lancement suivant. | 80 | - **Repartir d'un historique vide, pour tous les channels d'un coup** : utilisez la **Danger zone** ([Repartir de zéro](repartir-de-zero.md)), ou quittez Sidekicks et supprimez le dossier `sidekicks/data/<…>` de votre configuration (son emplacement est dans la [référence](../reference/agents-et-evenements.md#historique)). Les channels déclarés dans le fichier reviennent, vides, au lancement suivant. |
added
docs/fr/how-to/utiliser-les-outils-de-sidekicks-depuis-un-agent.md +56 -0 | new file mode 100644 | ||
| @@ -0,0 +1,56 @@ | ||
| 1 | +# Laisser un agent utiliser les outils de Sidekicks | |
| 2 | + | |
| 3 | +Ce guide montre comment laisser un agent mini-me (`mm`) appeler les outils que Sidekicks lui propose : la pression mémoire de l'ordinateur, ce qu'est Sidekicks, le channel où il parle, la liste des channels et des agents, et une recherche dans l'historique de n'importe quel channel. Peu d'agents ACP savent découvrir les outils de leur client ; mini-me le sait, c'est pourquoi ce guide l'utilise. Il suppose l'agent déjà ajouté (voir [Ajouter un agent](ajouter-un-agent.md)) et démarré avec `--acp --config <fichier>`. | |
| 4 | + | |
| 5 | +## Étapes | |
| 6 | + | |
| 7 | +1. Ouvrez le fichier de l'agent (`agent.yaml`) et ajoutez, sous `acp:` : | |
| 8 | + | |
| 9 | + ```yaml | |
| 10 | + acp: | |
| 11 | + clientTools: | |
| 12 | + enabled: true | |
| 13 | + discovery: meta # ou request | |
| 14 | + permissions: auto # ask : l'utilisateur autorise chaque appel | |
| 15 | + timeout: 30s | |
| 16 | + ``` | |
| 17 | + | |
| 18 | +2. Redémarrez l'agent : dans Sidekicks, **Stop** puis envoyez-lui un message, ou quittez et relancez Sidekicks. Les outils sont proposés au démarrage de l'agent. | |
| 19 | +3. Demandez-lui, par exemple dans `#general` : | |
| 20 | + - `@riker quelle est la pression mémoire ?` — il appelle `client_memory_pressure` ; | |
| 21 | + - `@riker qu'est-ce que Sidekicks ?` — il appelle `client_about_sidekicks` ; | |
| 22 | + - `@riker dans quel channel sommes-nous, et qui est là ?` — il appelle `client_current_channel` ; | |
| 23 | + - `@riker liste les channels` — il appelle `client_list_channels` ; | |
| 24 | + - `@riker quels agents y a-t-il ?` — il appelle `client_list_agents` ; | |
| 25 | + - `@riker qu'a-t-on dit sur Lyon dans #general ?` — il appelle `client_search_messages` avec `query: Lyon` et `channel: general`. | |
| 26 | + | |
| 27 | + L'appel s'affiche dans sa réponse comme tout appel d'outil (`client: memory_pressure`), et dans son journal (`[acp] client tools (meta): …` au démarrage). | |
| 28 | + | |
| 29 | +Un modèle peut répondre à une question déjà posée avec sa réponse précédente au lieu de rappeler l'outil ; les descriptions des outils dont le résultat change (mémoire, channels, agents, recherche) lui demandent de le rappeler à chaque fois, et un petit modèle le fait mieux quand ses instructions le disent aussi. Un petit modèle appelle aussi plus volontiers un outil que ses instructions nomment : ajoutez à son `system:` une ligne comme « Call client_current_channel to know where you are and who is there. » | |
| 30 | + | |
| 31 | +## Variantes | |
| 32 | + | |
| 33 | +- **Choisir les outils proposés, ou les désactiver** : dans **Settings**, ajoutez à la configuration de Sidekicks | |
| 34 | + | |
| 35 | + ```yaml | |
| 36 | + agentTools: | |
| 37 | + enabled: true # false : aucun outil | |
| 38 | + offer: # seulement ceux-ci ; sans « offer », tous | |
| 39 | + - memory_pressure | |
| 40 | + - current_channel | |
| 41 | + - list_agents | |
| 42 | + ``` | |
| 43 | + | |
| 44 | + puis enregistrez. Les outils sont lus au démarrage d'un agent : un agent en marche dont les outils changent affiche « à redémarrer » ; redémarrez-le. L'éditeur propose les noms après `- `. Un nom inconnu s'affiche en avertissement. | |
| 45 | +- **L'agent dit qu'il n'a pas cet outil** : ouvrez son journal (**Log** dans la barre d'état). Au démarrage, Sidekicks écrit `sidekicks: tools offered (meta): about_sidekicks, current_channel, …`, puis mm écrit `[acp] client tools (meta): client_…` avec les outils qu'il a pris. Un outil absent de la première ligne est retiré par `agentTools` ; absent de la seconde seulement, mm l'a refusé (son stderr dit pourquoi). Si l'outil manque dans un journal plus ancien, l'agent a été démarré avant le changement : redémarrez-le. Si le journal le montre et que l'agent le nie quand même, le modèle l'a ignoré : nommez l'outil dans ses instructions `system:`. | |
| 46 | +- **L'agent cherche des fichiers avec bash à la place** : un channel nommé comme un dossier (`documentation`) peut pousser un agent de code à chercher des fichiers. Nommez le channel avec `#` et dites « messages » : `@riker cherche les messages de #documentation sur Kotlin`. Pour un agent de code, ajoutez à son `system:` une ligne comme « To find what was said in a Sidekicks channel, call client_search_messages, never bash. » | |
| 47 | +- **Cantonner un agent à ses propres channels** : `list_channels` liste tous les channels (les conversations directes n'y sont pas), et `search_messages` lit tous les channels et conversations directes (`channel: @alice`), pas seulement ceux de l'agent. Retirez-les d'`offer` si ce n'est pas souhaité. | |
| 48 | + | |
| 49 | +- **`discovery: request`** : Sidekicks lit le fichier de l'agent (celui qui suit `--config`) pour le savoir, annonce seulement les outils, et donne la liste à chaque ouverture de session. Le fichier est lu sur cet ordinateur : un agent dans une sandbox ou un conteneur doit l'avoir au même chemin, ce que demandent déjà les variantes sbx et Docker de l'assistant. | |
| 50 | +- **`permissions: ask`**, ou `auto` sans `yolo: true` : chaque appel demande d'abord à l'utilisateur, avec la carte de permission habituelle (`client: <nom>`). | |
| 51 | +- **Un autre agent** (Claude, Codex, Gemini, docker-agent) : les outils lui sont proposés aussi, mais ces agents ne découvrent pas les outils d'un client et les ignorent ; ils fonctionnent comme avant. Peu d'agents ACP savent les découvrir aujourd'hui : mini-me le sait ([pourquoi](../explanation/pourquoi-acp.md#proposer-des-outils-aux-agents)). | |
| 52 | + | |
| 53 | +## Voir aussi | |
| 54 | + | |
| 55 | +- Ce que renvoie chaque outil, et le protocole : [Outils proposés aux agents](../reference/agents-et-evenements.md#outils-proposés-aux-agents) | |
| 56 | +- [Pourquoi Sidekicks parle ACP](../explanation/pourquoi-acp.md#proposer-des-outils-aux-agents) | |
| new file mode 100644 | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | +# Laisser un agent utiliser les outils de Sidekicks | ||
| 2 | + | ||
| 3 | +Ce guide montre comment laisser un agent mini-me (`mm`) appeler les outils que Sidekicks lui propose : la pression mémoire de l'ordinateur, ce qu'est Sidekicks, le channel où il parle, la liste des channels et des agents, et une recherche dans l'historique de n'importe quel channel. Peu d'agents ACP savent découvrir les outils de leur client ; mini-me le sait, c'est pourquoi ce guide l'utilise. Il suppose l'agent déjà ajouté (voir [Ajouter un agent](ajouter-un-agent.md)) et démarré avec `--acp --config <fichier>`. | ||
| 4 | + | ||
| 5 | +## Étapes | ||
| 6 | + | ||
| 7 | +1. Ouvrez le fichier de l'agent (`agent.yaml`) et ajoutez, sous `acp:` : | ||
| 8 | + | ||
| 9 | + ```yaml | ||
| 10 | + acp: | ||
| 11 | + clientTools: | ||
| 12 | + enabled: true | ||
| 13 | + discovery: meta # ou request | ||
| 14 | + permissions: auto # ask : l'utilisateur autorise chaque appel | ||
| 15 | + timeout: 30s | ||
| 16 | + ``` | ||
| 17 | + | ||
| 18 | +2. Redémarrez l'agent : dans Sidekicks, **Stop** puis envoyez-lui un message, ou quittez et relancez Sidekicks. Les outils sont proposés au démarrage de l'agent. | ||
| 19 | +3. Demandez-lui, par exemple dans `#general` : | ||
| 20 | + - `@riker quelle est la pression mémoire ?` — il appelle `client_memory_pressure` ; | ||
| 21 | + - `@riker qu'est-ce que Sidekicks ?` — il appelle `client_about_sidekicks` ; | ||
| 22 | + - `@riker dans quel channel sommes-nous, et qui est là ?` — il appelle `client_current_channel` ; | ||
| 23 | + - `@riker liste les channels` — il appelle `client_list_channels` ; | ||
| 24 | + - `@riker quels agents y a-t-il ?` — il appelle `client_list_agents` ; | ||
| 25 | + - `@riker qu'a-t-on dit sur Lyon dans #general ?` — il appelle `client_search_messages` avec `query: Lyon` et `channel: general`. | ||
| 26 | + | ||
| 27 | + L'appel s'affiche dans sa réponse comme tout appel d'outil (`client: memory_pressure`), et dans son journal (`[acp] client tools (meta): …` au démarrage). | ||
| 28 | + | ||
| 29 | +Un modèle peut répondre à une question déjà posée avec sa réponse précédente au lieu de rappeler l'outil ; les descriptions des outils dont le résultat change (mémoire, channels, agents, recherche) lui demandent de le rappeler à chaque fois, et un petit modèle le fait mieux quand ses instructions le disent aussi. Un petit modèle appelle aussi plus volontiers un outil que ses instructions nomment : ajoutez à son `system:` une ligne comme « Call client_current_channel to know where you are and who is there. » | ||
| 30 | + | ||
| 31 | +## Variantes | ||
| 32 | + | ||
| 33 | +- **Choisir les outils proposés, ou les désactiver** : dans **Settings**, ajoutez à la configuration de Sidekicks | ||
| 34 | + | ||
| 35 | + ```yaml | ||
| 36 | + agentTools: | ||
| 37 | + enabled: true # false : aucun outil | ||
| 38 | + offer: # seulement ceux-ci ; sans « offer », tous | ||
| 39 | + - memory_pressure | ||
| 40 | + - current_channel | ||
| 41 | + - list_agents | ||
| 42 | + ``` | ||
| 43 | + | ||
| 44 | + puis enregistrez. Les outils sont lus au démarrage d'un agent : un agent en marche dont les outils changent affiche « à redémarrer » ; redémarrez-le. L'éditeur propose les noms après `- `. Un nom inconnu s'affiche en avertissement. | ||
| 45 | +- **L'agent dit qu'il n'a pas cet outil** : ouvrez son journal (**Log** dans la barre d'état). Au démarrage, Sidekicks écrit `sidekicks: tools offered (meta): about_sidekicks, current_channel, …`, puis mm écrit `[acp] client tools (meta): client_…` avec les outils qu'il a pris. Un outil absent de la première ligne est retiré par `agentTools` ; absent de la seconde seulement, mm l'a refusé (son stderr dit pourquoi). Si l'outil manque dans un journal plus ancien, l'agent a été démarré avant le changement : redémarrez-le. Si le journal le montre et que l'agent le nie quand même, le modèle l'a ignoré : nommez l'outil dans ses instructions `system:`. | ||
| 46 | +- **L'agent cherche des fichiers avec bash à la place** : un channel nommé comme un dossier (`documentation`) peut pousser un agent de code à chercher des fichiers. Nommez le channel avec `#` et dites « messages » : `@riker cherche les messages de #documentation sur Kotlin`. Pour un agent de code, ajoutez à son `system:` une ligne comme « To find what was said in a Sidekicks channel, call client_search_messages, never bash. » | ||
| 47 | +- **Cantonner un agent à ses propres channels** : `list_channels` liste tous les channels (les conversations directes n'y sont pas), et `search_messages` lit tous les channels et conversations directes (`channel: @alice`), pas seulement ceux de l'agent. Retirez-les d'`offer` si ce n'est pas souhaité. | ||
| 48 | + | ||
| 49 | +- **`discovery: request`** : Sidekicks lit le fichier de l'agent (celui qui suit `--config`) pour le savoir, annonce seulement les outils, et donne la liste à chaque ouverture de session. Le fichier est lu sur cet ordinateur : un agent dans une sandbox ou un conteneur doit l'avoir au même chemin, ce que demandent déjà les variantes sbx et Docker de l'assistant. | ||
| 50 | +- **`permissions: ask`**, ou `auto` sans `yolo: true` : chaque appel demande d'abord à l'utilisateur, avec la carte de permission habituelle (`client: <nom>`). | ||
| 51 | +- **Un autre agent** (Claude, Codex, Gemini, docker-agent) : les outils lui sont proposés aussi, mais ces agents ne découvrent pas les outils d'un client et les ignorent ; ils fonctionnent comme avant. Peu d'agents ACP savent les découvrir aujourd'hui : mini-me le sait ([pourquoi](../explanation/pourquoi-acp.md#proposer-des-outils-aux-agents)). | ||
| 52 | + | ||
| 53 | +## Voir aussi | ||
| 54 | + | ||
| 55 | +- Ce que renvoie chaque outil, et le protocole : [Outils proposés aux agents](../reference/agents-et-evenements.md#outils-proposés-aux-agents) | ||
| 56 | +- [Pourquoi Sidekicks parle ACP](../explanation/pourquoi-acp.md#proposer-des-outils-aux-agents) | ||
modified
docs/fr/reference/agents-et-evenements.md +24 -0 | @@ -235,6 +235,30 @@ Un fichier ouvert pour modification a `path, content, version` ; `version` ident | ||
| 235 | 235 | | `ChooseCompose()` | Le sélecteur de fichier natif, pour un fichier Compose. | |
| 236 | 236 | | `Reset(choice)` | La Danger zone : `settings` (configuration par défaut, préférences oubliées), `history` (celui de cette configuration), `allHistory` (celui de toutes les configurations) ou `everything`. Chaque élément réinitialisé est d'abord gardé en copie datée ; renvoie `{copies[]}`. L'historique est rouvert vide et les channels déclarés sont recréés ; puis `config:changed` est envoyé. | |
| 237 | 237 | |
| 238 | +## Outils proposés aux agents | |
| 239 | + | |
| 240 | +Tickets #90 et #91. Sidekicks propose six outils à chaque agent, dans la limite de [`agentTools`](configuration.md#agenttools) (tous par défaut), avec le protocole de mini-me (`org.mini-me/tools`, méthodes d'extension ACP). Un agent qui le connaît (`acp.clientTools` dans un fichier `mm`) les donne à son modèle sous le nom `client_<nom>` ; les autres les ignorent. Peu d'agents ACP découvrent les outils d'un client : parmi les agents que documente Sidekicks, seul mini-me le fait (ni Claude, ni Codex, ni Gemini, ni docker-agent). | |
| 241 | + | |
| 242 | +| Outil (le modèle voit) | Méthode | Renvoie | | |
| 243 | +| --- | --- | --- | | |
| 244 | +| `memory_pressure` (`client_memory_pressure`) | `_com.rickub.sidekicks/system/memory` | `Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %).`, comme l'affiche le panneau **Log** ([Surveiller la pression mémoire](../how-to/surveiller-la-pression-memoire.md)) ; `The memory cannot be measured on this computer.` là où elle ne se mesure pas | | |
| 245 | +| `about_sidekicks` (`client_about_sidekicks`) | `_com.rickub.sidekicks/about` | la version de Sidekicks (`info.version` de `build/config.yml`, `dev` pour une version de développement), le système et l'architecture, ce qu'est Sidekicks, le nom de l'agent dans Sidekicks, la page des releases | | |
| 246 | +| `list_channels` (`client_list_channels`) | `_com.rickub.sidekicks/channels/list` | Tous les channels, du plus ancien au plus récent, sans les conversations directes : `#nom: description. Members: @a (you), @b. 12 messages, the last on 2026-11-10 14:05.` | | |
| 247 | +| `list_agents` (`client_list_agents`) | `_com.rickub.sidekicks/agents/list` | Tous les agents de la configuration : `@nom (you), titre: description. Runs on the user's computer` (ou `in a Docker container`, `in an sbx sandbox`) `; ready.` (son état : `stopped`, `starting`, `ready`, `busy`, `error`) | | |
| 248 | +| `search_messages` (`client_search_messages`) | `_com.rickub.sidekicks/messages/search` | Les messages de l'utilisateur et des agents d'un channel qui contiennent `query`, sans tenir compte de la casse ni des accents, du plus récent au plus ancien : `- 2026-11-10 14:05, @alice: …extrait autour du texte trouvé…` (80 caractères de chaque côté). Paramètres : `query` (obligatoire), `channel` (`general`, `#general`, ou `@alice` pour une conversation directe ; par défaut, le channel de la session de l'appel), `limit` (10 par défaut, 50 au plus). Tout l'historique enregistré est lu, pas seulement les messages affichés. Un channel inconnu est une erreur qui liste les channels (une conversation directe se cherche avec `@agent`, elle n'est pas listée) | | |
| 249 | +| `current_channel` (`client_current_channel`) | `_com.rickub.sidekicks/channel/current` | `Channel #<nom>.`, sa description et ses membres (`you (@agent), @autre, and the user.`), ou `A direct conversation between the user and you (<agent>)…`. Le channel est celui dont l'agent tient la session (`_meta["org.mini-me/sessionId"]` de l'appel) ; une session d'aucun channel est une erreur | | |
| 250 | + | |
| 251 | +Seul `search_messages` a des paramètres ; son `inputSchema` indique que `query` est obligatoire. `list_channels` et `search_messages` lisent **tous** les channels, pas seulement ceux dont l'agent est membre (il lit déjà ceux-là) : retirez-les d'`agentTools.offer` si ce n'est pas souhaité. Un outil retiré, ou tous les outils avec `enabled: false`, n'est pas annoncé, et sa méthode répond `-32601`. Le protocole : | |
| 252 | + | |
| 253 | +| Étape | Ce que fait Sidekicks | | |
| 254 | +| --- | --- | | |
| 255 | +| `initialize` | `clientCapabilities._meta["org.mini-me/tools"]` contient la liste (`name, description, method`), ou `true` quand le fichier de l'agent indique `acp.clientTools.discovery: request`. Le fichier est celui qui suit `--config` (ou `-config`) dans les arguments de l'agent, relatif à son dossier ; sans lui, ou illisible : `meta`. `clientInfo.version` est la version de Sidekicks | | |
| 256 | +| `_org.mini-me/tools/list` | répond `{"tools": [...]}` | | |
| 257 | +| la méthode d'un outil | répond `{"content":[{"type":"text","text":"…"}],"isError":false}` ; un échec a `isError: true` et dit pourquoi | | |
| 258 | +| toute autre méthode `_…` | erreur JSON-RPC `-32601` (Method not found) | | |
| 259 | + | |
| 260 | +Au démarrage d'un agent, son journal reçoit `sidekicks: tools offered (meta|request): <noms>`, ou `sidekicks: no tool offered (agentTools)`. Avec `acp.clientTools.permissions: ask` (ou `auto` sans `yolo`), mm demande avant chaque appel : la carte de permission affiche `client: <nom>`. | |
| 261 | + | |
| 238 | 262 | ## Arrêt d'un agent |
| 239 | 263 | |
| 240 | 264 | L'entrée standard de l'agent est fermée ; après 5 s, l'agent et ses enfants reçoivent SIGTERM (le temps pour `scripts/agents.sh` de décharger le modèle) ; 3 s plus tard, SIGKILL. |
| @@ -235,6 +235,30 @@ Un fichier ouvert pour modification a `path, content, version` ; `version` ident | |||
| 235 | | `ChooseCompose()` | Le sélecteur de fichier natif, pour un fichier Compose. | | 235 | | `ChooseCompose()` | Le sélecteur de fichier natif, pour un fichier Compose. | |
| 236 | | `Reset(choice)` | La Danger zone : `settings` (configuration par défaut, préférences oubliées), `history` (celui de cette configuration), `allHistory` (celui de toutes les configurations) ou `everything`. Chaque élément réinitialisé est d'abord gardé en copie datée ; renvoie `{copies[]}`. L'historique est rouvert vide et les channels déclarés sont recréés ; puis `config:changed` est envoyé. | | 236 | | `Reset(choice)` | La Danger zone : `settings` (configuration par défaut, préférences oubliées), `history` (celui de cette configuration), `allHistory` (celui de toutes les configurations) ou `everything`. Chaque élément réinitialisé est d'abord gardé en copie datée ; renvoie `{copies[]}`. L'historique est rouvert vide et les channels déclarés sont recréés ; puis `config:changed` est envoyé. | |
| 237 | 237 | ||
| 238 | +## Outils proposés aux agents | ||
| 239 | + | ||
| 240 | +Tickets #90 et #91. Sidekicks propose six outils à chaque agent, dans la limite de [`agentTools`](configuration.md#agenttools) (tous par défaut), avec le protocole de mini-me (`org.mini-me/tools`, méthodes d'extension ACP). Un agent qui le connaît (`acp.clientTools` dans un fichier `mm`) les donne à son modèle sous le nom `client_<nom>` ; les autres les ignorent. Peu d'agents ACP découvrent les outils d'un client : parmi les agents que documente Sidekicks, seul mini-me le fait (ni Claude, ni Codex, ni Gemini, ni docker-agent). | ||
| 241 | + | ||
| 242 | +| Outil (le modèle voit) | Méthode | Renvoie | | ||
| 243 | +| --- | --- | --- | | ||
| 244 | +| `memory_pressure` (`client_memory_pressure`) | `_com.rickub.sidekicks/system/memory` | `Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %).`, comme l'affiche le panneau **Log** ([Surveiller la pression mémoire](../how-to/surveiller-la-pression-memoire.md)) ; `The memory cannot be measured on this computer.` là où elle ne se mesure pas | | ||
| 245 | +| `about_sidekicks` (`client_about_sidekicks`) | `_com.rickub.sidekicks/about` | la version de Sidekicks (`info.version` de `build/config.yml`, `dev` pour une version de développement), le système et l'architecture, ce qu'est Sidekicks, le nom de l'agent dans Sidekicks, la page des releases | | ||
| 246 | +| `list_channels` (`client_list_channels`) | `_com.rickub.sidekicks/channels/list` | Tous les channels, du plus ancien au plus récent, sans les conversations directes : `#nom: description. Members: @a (you), @b. 12 messages, the last on 2026-11-10 14:05.` | | ||
| 247 | +| `list_agents` (`client_list_agents`) | `_com.rickub.sidekicks/agents/list` | Tous les agents de la configuration : `@nom (you), titre: description. Runs on the user's computer` (ou `in a Docker container`, `in an sbx sandbox`) `; ready.` (son état : `stopped`, `starting`, `ready`, `busy`, `error`) | | ||
| 248 | +| `search_messages` (`client_search_messages`) | `_com.rickub.sidekicks/messages/search` | Les messages de l'utilisateur et des agents d'un channel qui contiennent `query`, sans tenir compte de la casse ni des accents, du plus récent au plus ancien : `- 2026-11-10 14:05, @alice: …extrait autour du texte trouvé…` (80 caractères de chaque côté). Paramètres : `query` (obligatoire), `channel` (`general`, `#general`, ou `@alice` pour une conversation directe ; par défaut, le channel de la session de l'appel), `limit` (10 par défaut, 50 au plus). Tout l'historique enregistré est lu, pas seulement les messages affichés. Un channel inconnu est une erreur qui liste les channels (une conversation directe se cherche avec `@agent`, elle n'est pas listée) | | ||
| 249 | +| `current_channel` (`client_current_channel`) | `_com.rickub.sidekicks/channel/current` | `Channel #<nom>.`, sa description et ses membres (`you (@agent), @autre, and the user.`), ou `A direct conversation between the user and you (<agent>)…`. Le channel est celui dont l'agent tient la session (`_meta["org.mini-me/sessionId"]` de l'appel) ; une session d'aucun channel est une erreur | | ||
| 250 | + | ||
| 251 | +Seul `search_messages` a des paramètres ; son `inputSchema` indique que `query` est obligatoire. `list_channels` et `search_messages` lisent **tous** les channels, pas seulement ceux dont l'agent est membre (il lit déjà ceux-là) : retirez-les d'`agentTools.offer` si ce n'est pas souhaité. Un outil retiré, ou tous les outils avec `enabled: false`, n'est pas annoncé, et sa méthode répond `-32601`. Le protocole : | ||
| 252 | + | ||
| 253 | +| Étape | Ce que fait Sidekicks | | ||
| 254 | +| --- | --- | | ||
| 255 | +| `initialize` | `clientCapabilities._meta["org.mini-me/tools"]` contient la liste (`name, description, method`), ou `true` quand le fichier de l'agent indique `acp.clientTools.discovery: request`. Le fichier est celui qui suit `--config` (ou `-config`) dans les arguments de l'agent, relatif à son dossier ; sans lui, ou illisible : `meta`. `clientInfo.version` est la version de Sidekicks | | ||
| 256 | +| `_org.mini-me/tools/list` | répond `{"tools": [...]}` | | ||
| 257 | +| la méthode d'un outil | répond `{"content":[{"type":"text","text":"…"}],"isError":false}` ; un échec a `isError: true` et dit pourquoi | | ||
| 258 | +| toute autre méthode `_…` | erreur JSON-RPC `-32601` (Method not found) | | ||
| 259 | + | ||
| 260 | +Au démarrage d'un agent, son journal reçoit `sidekicks: tools offered (meta|request): <noms>`, ou `sidekicks: no tool offered (agentTools)`. Avec `acp.clientTools.permissions: ask` (ou `auto` sans `yolo`), mm demande avant chaque appel : la carte de permission affiche `client: <nom>`. | ||
| 261 | + | ||
| 238 | ## Arrêt d'un agent | 262 | ## Arrêt d'un agent |
| 239 | 263 | ||
| 240 | L'entrée standard de l'agent est fermée ; après 5 s, l'agent et ses enfants reçoivent SIGTERM (le temps pour `scripts/agents.sh` de décharger le modèle) ; 3 s plus tard, SIGKILL. | 264 | L'entrée standard de l'agent est fermée ; après 5 s, l'agent et ses enfants reçoivent SIGTERM (le temps pour `scripts/agents.sh` de décharger le modèle) ; 3 s plus tard, SIGKILL. |
modified
docs/fr/reference/configuration.md +20 -1 | @@ -38,6 +38,7 @@ Le fichier est cherché dans cet ordre ; la première source applicable l'emport | ||
| 38 | 38 | | `version` | entier | oui | — | Version du format ; seule `1` existe. Un format ultérieur l'incrémente, pour que Sidekicks puisse migrer ou refuser explicitement un ancien fichier. | |
| 39 | 39 | | `ui` | objet | non | | Préférences d'interface. | |
| 40 | 40 | | `limits` | objet | non | | Limites de ressources. | |
| 41 | +| `agentTools` | objet | non | | Les outils que Sidekicks propose aux agents ([plus bas](#agenttools)). | | |
| 41 | 42 | | `agents` | liste d'agents | oui | | Les agents disponibles avec `@nom`. Peut être vide. | |
| 42 | 43 | | `channels` | liste de channels | non | `[]` | Channels créés au démarrage s'ils n'existent pas encore. | |
| 43 | 44 | |
| @@ -58,6 +59,23 @@ Les clés inconnues sont des **erreurs**, à tous les niveaux : une faute de fra | ||
| 58 | 59 | | `stopIdleAgentsAfter` | durée Go (`30s`, `10m`, `1h30m`), ou `0` (nombre ou texte) | `10m` | Arrête un agent inutilisé depuis ce délai pour libérer sa mémoire. `0` ne l'arrête jamais. | |
| 59 | 60 | | `maxAgentHandoffs` | entier, de 0 à 10 | `3` | Dans un channel, combien de fois un même message peut passer d'agent en agent : un agent dont la réponse mentionne un autre membre avec `@nom` lui passe la parole ([Gérer les channels](../how-to/gerer-les-channels.md#laisser-les-agents-sappeler-entre-eux)). La limite atteinte, la chaîne s'arrête et le dit. `0` désactive. | |
| 60 | 61 | |
| 62 | +### `agentTools` | |
| 63 | + | |
| 64 | +Les outils que Sidekicks propose aux agents capables de les découvrir : aujourd'hui, les agents mini-me dont le fichier contient `acp.clientTools` ([Laisser un agent utiliser les outils de Sidekicks](../how-to/utiliser-les-outils-de-sidekicks-depuis-un-agent.md)). Peu d'agents ACP découvrent les outils d'un client ; les autres les ignorent. Lu au démarrage d'un agent : après un changement, un agent en marche dont les outils diffèrent affiche « à redémarrer » à côté de son nom ; redémarrez-le pour appliquer. | |
| 65 | + | |
| 66 | +| Clé | Type | Défaut | Signification | | |
| 67 | +| --- | --- | --- | --- | | |
| 68 | +| `enabled` | booléen | `true` | `false` : aucun outil n'est proposé ; un agent qui en appelle un quand même reçoit « Method not found ». | | |
| 69 | +| `offer` | liste de noms d'outils | tous | Seulement ces outils sont proposés. Les noms : `memory_pressure`, `about_sidekicks`, `current_channel`, `list_channels`, `list_agents`, `search_messages` ([ce que renvoie chacun](agents-et-evenements.md#outils-proposés-aux-agents)). Un nom inconnu est un avertissement ; une liste vide n'en propose aucun. | | |
| 70 | + | |
| 71 | +`list_channels` liste **tous** les channels (pas les conversations directes) et `search_messages` lit tous les channels et conversations directes, pas seulement ceux de l'agent : retirez-les d'`offer` pour cantonner un agent à ses propres channels. | |
| 72 | + | |
| 73 | +```yaml | |
| 74 | +agentTools: | |
| 75 | + enabled: true | |
| 76 | + offer: [memory_pressure, about_sidekicks, current_channel, list_agents] | |
| 77 | +``` | |
| 78 | + | |
| 61 | 79 | ### Un agent |
| 62 | 80 | |
| 63 | 81 | | Clé | Type | Obligatoire | Défaut | Signification | |
| @@ -168,7 +186,8 @@ JSON Schema ne sait pas les exprimer ; le chargeur de configuration (issue #9) l | ||
| 168 | 186 | 1. les noms d'agents sont uniques ; |
| 169 | 187 | 2. les noms de channels sont uniques ; |
| 170 | 188 | 3. chaque nom de la liste `agents` d'un channel est le nom d'un agent ; |
| 171 | -4. `command` existe (dans le `PATH`, ou comme fichier) — signalé comme avertissement, car un agent peut être installé plus tard. | |
| 189 | +4. `command` existe (dans le `PATH`, ou comme fichier) — signalé comme avertissement, car un agent peut être installé plus tard ; | |
| 190 | +5. chaque nom d'`agentTools.offer` est un outil — signalé comme avertissement (`aucun outil ne s'appelle « memory » ; outils connus : …`) : les autres noms fonctionnent. | |
| 172 | 191 | |
| 173 | 192 | ## Messages d'erreur |
| 174 | 193 | |
| @@ -38,6 +38,7 @@ Le fichier est cherché dans cet ordre ; la première source applicable l'emport | |||
| 38 | | `version` | entier | oui | — | Version du format ; seule `1` existe. Un format ultérieur l'incrémente, pour que Sidekicks puisse migrer ou refuser explicitement un ancien fichier. | | 38 | | `version` | entier | oui | — | Version du format ; seule `1` existe. Un format ultérieur l'incrémente, pour que Sidekicks puisse migrer ou refuser explicitement un ancien fichier. | |
| 39 | | `ui` | objet | non | | Préférences d'interface. | | 39 | | `ui` | objet | non | | Préférences d'interface. | |
| 40 | | `limits` | objet | non | | Limites de ressources. | | 40 | | `limits` | objet | non | | Limites de ressources. | |
| 41 | +| `agentTools` | objet | non | | Les outils que Sidekicks propose aux agents ([plus bas](#agenttools)). | | ||
| 41 | | `agents` | liste d'agents | oui | | Les agents disponibles avec `@nom`. Peut être vide. | | 42 | | `agents` | liste d'agents | oui | | Les agents disponibles avec `@nom`. Peut être vide. | |
| 42 | | `channels` | liste de channels | non | `[]` | Channels créés au démarrage s'ils n'existent pas encore. | | 43 | | `channels` | liste de channels | non | `[]` | Channels créés au démarrage s'ils n'existent pas encore. | |
| 43 | 44 | ||
| @@ -58,6 +59,23 @@ Les clés inconnues sont des **erreurs**, à tous les niveaux : une faute de fra | |||
| 58 | | `stopIdleAgentsAfter` | durée Go (`30s`, `10m`, `1h30m`), ou `0` (nombre ou texte) | `10m` | Arrête un agent inutilisé depuis ce délai pour libérer sa mémoire. `0` ne l'arrête jamais. | | 59 | | `stopIdleAgentsAfter` | durée Go (`30s`, `10m`, `1h30m`), ou `0` (nombre ou texte) | `10m` | Arrête un agent inutilisé depuis ce délai pour libérer sa mémoire. `0` ne l'arrête jamais. | |
| 59 | | `maxAgentHandoffs` | entier, de 0 à 10 | `3` | Dans un channel, combien de fois un même message peut passer d'agent en agent : un agent dont la réponse mentionne un autre membre avec `@nom` lui passe la parole ([Gérer les channels](../how-to/gerer-les-channels.md#laisser-les-agents-sappeler-entre-eux)). La limite atteinte, la chaîne s'arrête et le dit. `0` désactive. | | 60 | | `maxAgentHandoffs` | entier, de 0 à 10 | `3` | Dans un channel, combien de fois un même message peut passer d'agent en agent : un agent dont la réponse mentionne un autre membre avec `@nom` lui passe la parole ([Gérer les channels](../how-to/gerer-les-channels.md#laisser-les-agents-sappeler-entre-eux)). La limite atteinte, la chaîne s'arrête et le dit. `0` désactive. | |
| 60 | 61 | ||
| 62 | +### `agentTools` | ||
| 63 | + | ||
| 64 | +Les outils que Sidekicks propose aux agents capables de les découvrir : aujourd'hui, les agents mini-me dont le fichier contient `acp.clientTools` ([Laisser un agent utiliser les outils de Sidekicks](../how-to/utiliser-les-outils-de-sidekicks-depuis-un-agent.md)). Peu d'agents ACP découvrent les outils d'un client ; les autres les ignorent. Lu au démarrage d'un agent : après un changement, un agent en marche dont les outils diffèrent affiche « à redémarrer » à côté de son nom ; redémarrez-le pour appliquer. | ||
| 65 | + | ||
| 66 | +| Clé | Type | Défaut | Signification | | ||
| 67 | +| --- | --- | --- | --- | | ||
| 68 | +| `enabled` | booléen | `true` | `false` : aucun outil n'est proposé ; un agent qui en appelle un quand même reçoit « Method not found ». | | ||
| 69 | +| `offer` | liste de noms d'outils | tous | Seulement ces outils sont proposés. Les noms : `memory_pressure`, `about_sidekicks`, `current_channel`, `list_channels`, `list_agents`, `search_messages` ([ce que renvoie chacun](agents-et-evenements.md#outils-proposés-aux-agents)). Un nom inconnu est un avertissement ; une liste vide n'en propose aucun. | | ||
| 70 | + | ||
| 71 | +`list_channels` liste **tous** les channels (pas les conversations directes) et `search_messages` lit tous les channels et conversations directes, pas seulement ceux de l'agent : retirez-les d'`offer` pour cantonner un agent à ses propres channels. | ||
| 72 | + | ||
| 73 | +```yaml | ||
| 74 | +agentTools: | ||
| 75 | + enabled: true | ||
| 76 | + offer: [memory_pressure, about_sidekicks, current_channel, list_agents] | ||
| 77 | +``` | ||
| 78 | + | ||
| 61 | ### Un agent | 79 | ### Un agent |
| 62 | 80 | ||
| 63 | | Clé | Type | Obligatoire | Défaut | Signification | | 81 | | Clé | Type | Obligatoire | Défaut | Signification | |
| @@ -168,7 +186,8 @@ JSON Schema ne sait pas les exprimer ; le chargeur de configuration (issue #9) l | |||
| 168 | 1. les noms d'agents sont uniques ; | 186 | 1. les noms d'agents sont uniques ; |
| 169 | 2. les noms de channels sont uniques ; | 187 | 2. les noms de channels sont uniques ; |
| 170 | 3. chaque nom de la liste `agents` d'un channel est le nom d'un agent ; | 188 | 3. chaque nom de la liste `agents` d'un channel est le nom d'un agent ; |
| 171 | -4. `command` existe (dans le `PATH`, ou comme fichier) — signalé comme avertissement, car un agent peut être installé plus tard. | 189 | +4. `command` existe (dans le `PATH`, ou comme fichier) — signalé comme avertissement, car un agent peut être installé plus tard ; |
| 190 | +5. chaque nom d'`agentTools.offer` est un outil — signalé comme avertissement (`aucun outil ne s'appelle « memory » ; outils connus : …`) : les autres noms fonctionnent. | ||
| 172 | 191 | ||
| 173 | ## Messages d'erreur | 192 | ## Messages d'erreur |
| 174 | 193 | ||
modified
frontend/src/lib/chat/Composer.svelte +9 -1 | @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <!-- Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE --> |
| 2 | 2 | <script lang="ts"> |
| 3 | + import { untrack } from 'svelte' | |
| 3 | 4 | import { t } from '../i18n/index.svelte' |
| 4 | 5 | import { completeTrigger, createHistory, findTrigger, insertAt, type Trigger } from '../composer' |
| 5 | 6 | import type { Suggestion, Suggestions } from '../suggestions' |
| @@ -16,6 +17,8 @@ | ||
| 16 | 17 | onStop, |
| 17 | 18 | onAttach, |
| 18 | 19 | dropTarget, |
| 20 | + draft = '', | |
| 21 | + onDraft = () => {}, | |
| 19 | 22 | }: { |
| 20 | 23 | placeholder: string |
| 21 | 24 | busy?: boolean |
| @@ -32,9 +35,14 @@ | ||
| 32 | 35 | onAttach?: () => void |
| 33 | 36 | /** The id of the composer as a drop target for files (Wails files:dropped). */ |
| 34 | 37 | dropTarget?: string |
| 38 | + /** The text being written when the composer was left, given back. */ | |
| 39 | + draft?: string | |
| 40 | + /** Called with the text as it changes, to keep it as the draft. */ | |
| 41 | + onDraft?: (text: string) => void | |
| 35 | 42 | } = $props() |
| 36 | 43 | |
| 37 | - let text = $state('') | |
| 44 | + let text = $state(untrack(() => draft)) | |
| 45 | + $effect(() => onDraft(text)) | |
| 38 | 46 | let textarea: HTMLTextAreaElement |
| 39 | 47 | const history = createHistory() |
| 40 | 48 | |
| @@ -1,5 +1,6 @@ | |||
| 1 | <!-- Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE --> | 1 | <!-- Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE --> |
| 2 | <script lang="ts"> | 2 | <script lang="ts"> |
| 3 | + import { untrack } from 'svelte' | ||
| 3 | import { t } from '../i18n/index.svelte' | 4 | import { t } from '../i18n/index.svelte' |
| 4 | import { completeTrigger, createHistory, findTrigger, insertAt, type Trigger } from '../composer' | 5 | import { completeTrigger, createHistory, findTrigger, insertAt, type Trigger } from '../composer' |
| 5 | import type { Suggestion, Suggestions } from '../suggestions' | 6 | import type { Suggestion, Suggestions } from '../suggestions' |
| @@ -16,6 +17,8 @@ | |||
| 16 | onStop, | 17 | onStop, |
| 17 | onAttach, | 18 | onAttach, |
| 18 | dropTarget, | 19 | dropTarget, |
| 20 | + draft = '', | ||
| 21 | + onDraft = () => {}, | ||
| 19 | }: { | 22 | }: { |
| 20 | placeholder: string | 23 | placeholder: string |
| 21 | busy?: boolean | 24 | busy?: boolean |
| @@ -32,9 +35,14 @@ | |||
| 32 | onAttach?: () => void | 35 | onAttach?: () => void |
| 33 | /** The id of the composer as a drop target for files (Wails files:dropped). */ | 36 | /** The id of the composer as a drop target for files (Wails files:dropped). */ |
| 34 | dropTarget?: string | 37 | dropTarget?: string |
| 38 | + /** The text being written when the composer was left, given back. */ | ||
| 39 | + draft?: string | ||
| 40 | + /** Called with the text as it changes, to keep it as the draft. */ | ||
| 41 | + onDraft?: (text: string) => void | ||
| 35 | } = $props() | 42 | } = $props() |
| 36 | 43 | ||
| 37 | - let text = $state('') | 44 | + let text = $state(untrack(() => draft)) |
| 45 | + $effect(() => onDraft(text)) | ||
| 38 | let textarea: HTMLTextAreaElement | 46 | let textarea: HTMLTextAreaElement |
| 39 | const history = createHistory() | 47 | const history = createHistory() |
| 40 | 48 | ||
modified
frontend/src/lib/composer.test.ts +14 -1 | @@ -1,7 +1,7 @@ | ||
| 1 | 1 | // Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE |
| 2 | 2 | |
| 3 | 3 | import { describe, expect, it } from 'vitest' |
| 4 | -import { completeTrigger, createHistory, findTrigger, isNearBottom } from './composer' | |
| 4 | +import { completeTrigger, createDrafts, createHistory, findTrigger, isNearBottom } from './composer' | |
| 5 | 5 | |
| 6 | 6 | describe('findTrigger', () => { |
| 7 | 7 | it('finds a trigger at the start or after a space', () => { |
| @@ -49,3 +49,16 @@ describe('isNearBottom', () => { | ||
| 49 | 49 | expect(isNearBottom(500, 100, 1000)).toBe(false) |
| 50 | 50 | }) |
| 51 | 51 | }) |
| 52 | + | |
| 53 | +describe('drafts', () => { | |
| 54 | + it('gives back the text of each conversation, and forgets an empty one', () => { | |
| 55 | + const drafts = createDrafts() | |
| 56 | + drafts.keep('c1', 'Hello @ali') | |
| 57 | + drafts.keep('c2', 'other') | |
| 58 | + expect(drafts.of('c1')).toBe('Hello @ali') | |
| 59 | + expect(drafts.of('c3')).toBe('') | |
| 60 | + drafts.keep('c1', ' ') | |
| 61 | + expect(drafts.of('c1')).toBe('') | |
| 62 | + expect(drafts.of('c2')).toBe('other') | |
| 63 | + }) | |
| 64 | +}) | |
| @@ -1,7 +1,7 @@ | |||
| 1 | // Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | 1 | // Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE |
| 2 | 2 | ||
| 3 | import { describe, expect, it } from 'vitest' | 3 | import { describe, expect, it } from 'vitest' |
| 4 | -import { completeTrigger, createHistory, findTrigger, isNearBottom } from './composer' | 4 | +import { completeTrigger, createDrafts, createHistory, findTrigger, isNearBottom } from './composer' |
| 5 | 5 | ||
| 6 | describe('findTrigger', () => { | 6 | describe('findTrigger', () => { |
| 7 | it('finds a trigger at the start or after a space', () => { | 7 | it('finds a trigger at the start or after a space', () => { |
| @@ -49,3 +49,16 @@ describe('isNearBottom', () => { | |||
| 49 | expect(isNearBottom(500, 100, 1000)).toBe(false) | 49 | expect(isNearBottom(500, 100, 1000)).toBe(false) |
| 50 | }) | 50 | }) |
| 51 | }) | 51 | }) |
| 52 | + | ||
| 53 | +describe('drafts', () => { | ||
| 54 | + it('gives back the text of each conversation, and forgets an empty one', () => { | ||
| 55 | + const drafts = createDrafts() | ||
| 56 | + drafts.keep('c1', 'Hello @ali') | ||
| 57 | + drafts.keep('c2', 'other') | ||
| 58 | + expect(drafts.of('c1')).toBe('Hello @ali') | ||
| 59 | + expect(drafts.of('c3')).toBe('') | ||
| 60 | + drafts.keep('c1', ' ') | ||
| 61 | + expect(drafts.of('c1')).toBe('') | ||
| 62 | + expect(drafts.of('c2')).toBe('other') | ||
| 63 | + }) | ||
| 64 | +}) | ||
modified
frontend/src/lib/composer.ts +22 -0 | @@ -89,3 +89,25 @@ export function createHistory() { | ||
| 89 | 89 | export function isNearBottom(scrollTop: number, clientHeight: number, scrollHeight: number, margin = 48): boolean { |
| 90 | 90 | return scrollHeight - (scrollTop + clientHeight) <= margin |
| 91 | 91 | } |
| 92 | + | |
| 93 | +/** | |
| 94 | + * The messages being written, by conversation: switching to another channel | |
| 95 | + * and back gives the text back. Kept while Sidekicks runs. | |
| 96 | + * | |
| 97 | + * @example | |
| 98 | + * drafts.keep('c1', 'Hello @ali') | |
| 99 | + * drafts.of('c1') // 'Hello @ali' | |
| 100 | + */ | |
| 101 | +export function createDrafts() { | |
| 102 | + const texts = new Map<string, string>() | |
| 103 | + return { | |
| 104 | + of: (id: string): string => texts.get(id) ?? '', | |
| 105 | + keep(id: string, text: string) { | |
| 106 | + if (text.trim() === '') texts.delete(id) | |
| 107 | + else texts.set(id, text) | |
| 108 | + }, | |
| 109 | + } | |
| 110 | +} | |
| 111 | + | |
| 112 | +/** The drafts of every conversation of the window. */ | |
| 113 | +export const drafts = createDrafts() | |
| @@ -89,3 +89,25 @@ export function createHistory() { | |||
| 89 | export function isNearBottom(scrollTop: number, clientHeight: number, scrollHeight: number, margin = 48): boolean { | 89 | export function isNearBottom(scrollTop: number, clientHeight: number, scrollHeight: number, margin = 48): boolean { |
| 90 | return scrollHeight - (scrollTop + clientHeight) <= margin | 90 | return scrollHeight - (scrollTop + clientHeight) <= margin |
| 91 | } | 91 | } |
| 92 | + | ||
| 93 | +/** | ||
| 94 | + * The messages being written, by conversation: switching to another channel | ||
| 95 | + * and back gives the text back. Kept while Sidekicks runs. | ||
| 96 | + * | ||
| 97 | + * @example | ||
| 98 | + * drafts.keep('c1', 'Hello @ali') | ||
| 99 | + * drafts.of('c1') // 'Hello @ali' | ||
| 100 | + */ | ||
| 101 | +export function createDrafts() { | ||
| 102 | + const texts = new Map<string, string>() | ||
| 103 | + return { | ||
| 104 | + of: (id: string): string => texts.get(id) ?? '', | ||
| 105 | + keep(id: string, text: string) { | ||
| 106 | + if (text.trim() === '') texts.delete(id) | ||
| 107 | + else texts.set(id, text) | ||
| 108 | + }, | ||
| 109 | + } | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +/** The drafts of every conversation of the window. */ | ||
| 113 | +export const drafts = createDrafts() | ||
modified
frontend/src/lib/panels/ConversationPanel.svelte +3 -1 | @@ -14,7 +14,7 @@ | ||
| 14 | 14 | import { textIcon } from '../avatar' |
| 15 | 15 | import ActionError from '../chat/ActionError.svelte' |
| 16 | 16 | import Logo from '../layout/Logo.svelte' |
| 17 | - import { isNearBottom, type Trigger } from '../composer' | |
| 17 | + import { drafts, isNearBottom, type Trigger } from '../composer' | |
| 18 | 18 | import { notStreaming, usagePercent } from '../conversation' |
| 19 | 19 | import { act, addMember, agentTitle, appState, cancel, channelOf, clearHistory, loadOlder, openAssistant, prepareCommands, removeMember, send } from '../state.svelte' |
| 20 | 20 | import { ConfigService, WorkspaceService } from '../../../bindings/git.rickub.com/bots-garden/sidekicks/internal/app' |
| @@ -308,6 +308,8 @@ | ||
| 308 | 308 | dropTarget={composerTarget} |
| 309 | 309 | onSend={(text) => send(channel.id, text)} |
| 310 | 310 | onStop={() => cancel(channel.id)} |
| 311 | + draft={drafts.of(channel.id)} | |
| 312 | + onDraft={(text) => drafts.keep(channel.id, text)} | |
| 311 | 313 | /> |
| 312 | 314 | {/key} |
| 313 | 315 | </div> |
| @@ -14,7 +14,7 @@ | |||
| 14 | import { textIcon } from '../avatar' | 14 | import { textIcon } from '../avatar' |
| 15 | import ActionError from '../chat/ActionError.svelte' | 15 | import ActionError from '../chat/ActionError.svelte' |
| 16 | import Logo from '../layout/Logo.svelte' | 16 | import Logo from '../layout/Logo.svelte' |
| 17 | - import { isNearBottom, type Trigger } from '../composer' | 17 | + import { drafts, isNearBottom, type Trigger } from '../composer' |
| 18 | import { notStreaming, usagePercent } from '../conversation' | 18 | import { notStreaming, usagePercent } from '../conversation' |
| 19 | import { act, addMember, agentTitle, appState, cancel, channelOf, clearHistory, loadOlder, openAssistant, prepareCommands, removeMember, send } from '../state.svelte' | 19 | import { act, addMember, agentTitle, appState, cancel, channelOf, clearHistory, loadOlder, openAssistant, prepareCommands, removeMember, send } from '../state.svelte' |
| 20 | import { ConfigService, WorkspaceService } from '../../../bindings/git.rickub.com/bots-garden/sidekicks/internal/app' | 20 | import { ConfigService, WorkspaceService } from '../../../bindings/git.rickub.com/bots-garden/sidekicks/internal/app' |
| @@ -308,6 +308,8 @@ | |||
| 308 | dropTarget={composerTarget} | 308 | dropTarget={composerTarget} |
| 309 | onSend={(text) => send(channel.id, text)} | 309 | onSend={(text) => send(channel.id, text)} |
| 310 | onStop={() => cancel(channel.id)} | 310 | onStop={() => cancel(channel.id)} |
| 311 | + draft={drafts.of(channel.id)} | ||
| 312 | + onDraft={(text) => drafts.keep(channel.id, text)} | ||
| 311 | /> | 313 | /> |
| 312 | {/key} | 314 | {/key} |
| 313 | </div> | 315 | </div> |
modified
frontend/src/lib/yamlSchema.test.ts +10 -1 | @@ -11,7 +11,8 @@ const labels = (suggestions: Array<{ label: string }>) => suggestions.map((sugge | ||
| 11 | 11 | |
| 12 | 12 | describe('createSchemaIndex', () => { |
| 13 | 13 | it('lists the keys of the schema, following $ref and list items', () => { |
| 14 | - expect(labels(schema.keysAt([]))).toEqual(['version', 'ui', 'limits', 'agents', 'channels']) | |
| 14 | + expect(labels(schema.keysAt([]))).toEqual(['version', 'ui', 'limits', 'agentTools', 'agents', 'channels']) | |
| 15 | + expect(labels(schema.keysAt(['agentTools']))).toEqual(['enabled', 'offer']) | |
| 15 | 16 | expect(labels(schema.keysAt(['agents', item]))).toContain('workspace') |
| 16 | 17 | expect(labels(schema.keysAt(['agents', item, 'runtime']))).toEqual(['type', 'container', 'sandbox', 'workspacePath', 'lifecycle']) |
| 17 | 18 | expect(labels(schema.keysAt(['agents', item, 'runtime', 'lifecycle']))).toEqual(['folder', 'create', 'stop', 'remove']) |
| @@ -71,6 +72,14 @@ describe('suggestionsAt', () => { | ||
| 71 | 72 | expect(labels(result.options)).toEqual(['system', 'light', 'dark']) |
| 72 | 73 | }) |
| 73 | 74 | |
| 75 | + it('suggests the tools in the list of agentTools.offer', () => { | |
| 76 | + const result = suggestionsAt(schema, ['agentTools:', ' offer:', ' - mem'], 2, 9)! | |
| 77 | + expect(result.kind).toBe('value') | |
| 78 | + expect(result.word).toBe('mem') | |
| 79 | + expect(labels(result.options)).toContain('memory_pressure') | |
| 80 | + expect(labels(result.options)).toContain('search_messages') | |
| 81 | + }) | |
| 82 | + | |
| 74 | 83 | it('suggests nothing in the middle of a value', () => { |
| 75 | 84 | expect(suggestionsAt(schema, ['agents:', ' - name: alice smith'], 1, 20)).toBeNull() |
| 76 | 85 | }) |
| @@ -11,7 +11,8 @@ const labels = (suggestions: Array<{ label: string }>) => suggestions.map((sugge | |||
| 11 | 11 | ||
| 12 | describe('createSchemaIndex', () => { | 12 | describe('createSchemaIndex', () => { |
| 13 | it('lists the keys of the schema, following $ref and list items', () => { | 13 | it('lists the keys of the schema, following $ref and list items', () => { |
| 14 | - expect(labels(schema.keysAt([]))).toEqual(['version', 'ui', 'limits', 'agents', 'channels']) | 14 | + expect(labels(schema.keysAt([]))).toEqual(['version', 'ui', 'limits', 'agentTools', 'agents', 'channels']) |
| 15 | + expect(labels(schema.keysAt(['agentTools']))).toEqual(['enabled', 'offer']) | ||
| 15 | expect(labels(schema.keysAt(['agents', item]))).toContain('workspace') | 16 | expect(labels(schema.keysAt(['agents', item]))).toContain('workspace') |
| 16 | expect(labels(schema.keysAt(['agents', item, 'runtime']))).toEqual(['type', 'container', 'sandbox', 'workspacePath', 'lifecycle']) | 17 | expect(labels(schema.keysAt(['agents', item, 'runtime']))).toEqual(['type', 'container', 'sandbox', 'workspacePath', 'lifecycle']) |
| 17 | expect(labels(schema.keysAt(['agents', item, 'runtime', 'lifecycle']))).toEqual(['folder', 'create', 'stop', 'remove']) | 18 | expect(labels(schema.keysAt(['agents', item, 'runtime', 'lifecycle']))).toEqual(['folder', 'create', 'stop', 'remove']) |
| @@ -71,6 +72,14 @@ describe('suggestionsAt', () => { | |||
| 71 | expect(labels(result.options)).toEqual(['system', 'light', 'dark']) | 72 | expect(labels(result.options)).toEqual(['system', 'light', 'dark']) |
| 72 | }) | 73 | }) |
| 73 | 74 | ||
| 75 | + it('suggests the tools in the list of agentTools.offer', () => { | ||
| 76 | + const result = suggestionsAt(schema, ['agentTools:', ' offer:', ' - mem'], 2, 9)! | ||
| 77 | + expect(result.kind).toBe('value') | ||
| 78 | + expect(result.word).toBe('mem') | ||
| 79 | + expect(labels(result.options)).toContain('memory_pressure') | ||
| 80 | + expect(labels(result.options)).toContain('search_messages') | ||
| 81 | + }) | ||
| 82 | + | ||
| 74 | it('suggests nothing in the middle of a value', () => { | 83 | it('suggests nothing in the middle of a value', () => { |
| 75 | expect(suggestionsAt(schema, ['agents:', ' - name: alice smith'], 1, 20)).toBeNull() | 84 | expect(suggestionsAt(schema, ['agents:', ' - name: alice smith'], 1, 20)).toBeNull() |
| 76 | }) | 85 | }) |
modified
frontend/src/lib/yamlSchema.ts +11 -3 | @@ -12,6 +12,8 @@ interface SchemaNode { | ||
| 12 | 12 | items?: SchemaNode |
| 13 | 13 | enum?: unknown[] |
| 14 | 14 | const?: unknown |
| 15 | + /** Values worth suggesting without forbidding others (agentTools.offer). */ | |
| 16 | + examples?: unknown[] | |
| 15 | 17 | $defs?: Record<string, SchemaNode> |
| 16 | 18 | } |
| 17 | 19 | |
| @@ -55,7 +57,7 @@ export function createSchemaIndex(root: SchemaNode) { | ||
| 55 | 57 | }, |
| 56 | 58 | valuesAt(path: string[]): Suggestion[] { |
| 57 | 59 | const node = nodeAt(path) |
| 58 | - const values = node?.enum ?? (node?.const !== undefined ? [node.const] : []) | |
| 60 | + const values = node?.enum ?? (node?.const !== undefined ? [node.const] : (node?.examples ?? [])) | |
| 59 | 61 | return values.map((value) => ({ label: String(value) })) |
| 60 | 62 | }, |
| 61 | 63 | } |
| @@ -107,7 +109,8 @@ export function contextPath(lines: string[], lineIndex: number): string[] { | ||
| 107 | 109 | |
| 108 | 110 | /** |
| 109 | 111 | * What to suggest at the caret: keys at the start of a line (possibly after |
| 110 | - * "- "), or the values of the key on the left of "key: ". | |
| 112 | + * "- "), the values of a list of plain values after "- ", or the values of | |
| 113 | + * the key on the left of "key: ". | |
| 111 | 114 | */ |
| 112 | 115 | export function suggestionsAt(index: ReturnType<typeof createSchemaIndex>, lines: string[], lineIndex: number, column: number) { |
| 113 | 116 | const before = (lines[lineIndex] ?? '').slice(0, column) |
| @@ -118,7 +121,12 @@ export function suggestionsAt(index: ReturnType<typeof createSchemaIndex>, lines | ||
| 118 | 121 | } |
| 119 | 122 | const key = /^\s*(?:-\s+)?([A-Za-z_][\w-]*)?$/.exec(before) |
| 120 | 123 | if (key) { |
| 121 | - return { kind: 'key' as const, word: key[1] ?? '', options: index.keysAt(contextPath([...lines.slice(0, lineIndex), before], lineIndex)) } | |
| 124 | + const path = contextPath([...lines.slice(0, lineIndex), before], lineIndex) | |
| 125 | + const keys = index.keysAt(path) | |
| 126 | + if (keys.length === 0 && /^\s*-\s+/.test(before)) { | |
| 127 | + return { kind: 'value' as const, word: key[1] ?? '', options: index.valuesAt(path) } | |
| 128 | + } | |
| 129 | + return { kind: 'key' as const, word: key[1] ?? '', options: keys } | |
| 122 | 130 | } |
| 123 | 131 | return null |
| 124 | 132 | } |
| @@ -12,6 +12,8 @@ interface SchemaNode { | |||
| 12 | items?: SchemaNode | 12 | items?: SchemaNode |
| 13 | enum?: unknown[] | 13 | enum?: unknown[] |
| 14 | const?: unknown | 14 | const?: unknown |
| 15 | + /** Values worth suggesting without forbidding others (agentTools.offer). */ | ||
| 16 | + examples?: unknown[] | ||
| 15 | $defs?: Record<string, SchemaNode> | 17 | $defs?: Record<string, SchemaNode> |
| 16 | } | 18 | } |
| 17 | 19 | ||
| @@ -55,7 +57,7 @@ export function createSchemaIndex(root: SchemaNode) { | |||
| 55 | }, | 57 | }, |
| 56 | valuesAt(path: string[]): Suggestion[] { | 58 | valuesAt(path: string[]): Suggestion[] { |
| 57 | const node = nodeAt(path) | 59 | const node = nodeAt(path) |
| 58 | - const values = node?.enum ?? (node?.const !== undefined ? [node.const] : []) | 60 | + const values = node?.enum ?? (node?.const !== undefined ? [node.const] : (node?.examples ?? [])) |
| 59 | return values.map((value) => ({ label: String(value) })) | 61 | return values.map((value) => ({ label: String(value) })) |
| 60 | }, | 62 | }, |
| 61 | } | 63 | } |
| @@ -107,7 +109,8 @@ export function contextPath(lines: string[], lineIndex: number): string[] { | |||
| 107 | 109 | ||
| 108 | /** | 110 | /** |
| 109 | * What to suggest at the caret: keys at the start of a line (possibly after | 111 | * What to suggest at the caret: keys at the start of a line (possibly after |
| 110 | - * "- "), or the values of the key on the left of "key: ". | 112 | + * "- "), the values of a list of plain values after "- ", or the values of |
| 113 | + * the key on the left of "key: ". | ||
| 111 | */ | 114 | */ |
| 112 | export function suggestionsAt(index: ReturnType<typeof createSchemaIndex>, lines: string[], lineIndex: number, column: number) { | 115 | export function suggestionsAt(index: ReturnType<typeof createSchemaIndex>, lines: string[], lineIndex: number, column: number) { |
| 113 | const before = (lines[lineIndex] ?? '').slice(0, column) | 116 | const before = (lines[lineIndex] ?? '').slice(0, column) |
| @@ -118,7 +121,12 @@ export function suggestionsAt(index: ReturnType<typeof createSchemaIndex>, lines | |||
| 118 | } | 121 | } |
| 119 | const key = /^\s*(?:-\s+)?([A-Za-z_][\w-]*)?$/.exec(before) | 122 | const key = /^\s*(?:-\s+)?([A-Za-z_][\w-]*)?$/.exec(before) |
| 120 | if (key) { | 123 | if (key) { |
| 121 | - return { kind: 'key' as const, word: key[1] ?? '', options: index.keysAt(contextPath([...lines.slice(0, lineIndex), before], lineIndex)) } | 124 | + const path = contextPath([...lines.slice(0, lineIndex), before], lineIndex) |
| 125 | + const keys = index.keysAt(path) | ||
| 126 | + if (keys.length === 0 && /^\s*-\s+/.test(before)) { | ||
| 127 | + return { kind: 'value' as const, word: key[1] ?? '', options: index.valuesAt(path) } | ||
| 128 | + } | ||
| 129 | + return { kind: 'key' as const, word: key[1] ?? '', options: keys } | ||
| 122 | } | 130 | } |
| 123 | return null | 131 | return null |
| 124 | } | 132 | } |
modified
internal/acp/client.go +4 -3 | @@ -9,11 +9,12 @@ import ( | ||
| 9 | 9 | ) |
| 10 | 10 | |
| 11 | 11 | // client answers the requests an agent sends to Sidekicks: session updates |
| 12 | -// and permission requests go to the handler of their session; file and | |
| 13 | -// terminal access — which Sidekicks does not advertise (ADR 0001, decision 5) | |
| 14 | -// — is refused. | |
| 12 | +// and permission requests go to the handler of their session; the tools | |
| 13 | +// Sidekicks offers are answered (tools.go); file and terminal access — which | |
| 14 | +// Sidekicks does not advertise (ADR 0001, decision 5) — is refused. | |
| 15 | 15 | type client struct { |
| 16 | 16 | sessions *sessions |
| 17 | + tools []Tool | |
| 17 | 18 | } |
| 18 | 19 | |
| 19 | 20 | func (c *client) SessionUpdate(_ context.Context, notification sdk.SessionNotification) error { |
| @@ -9,11 +9,12 @@ import ( | |||
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | // client answers the requests an agent sends to Sidekicks: session updates | 11 | // client answers the requests an agent sends to Sidekicks: session updates |
| 12 | -// and permission requests go to the handler of their session; file and | 12 | +// and permission requests go to the handler of their session; the tools |
| 13 | -// terminal access — which Sidekicks does not advertise (ADR 0001, decision 5) | 13 | +// Sidekicks offers are answered (tools.go); file and terminal access — which |
| 14 | -// — is refused. | 14 | +// Sidekicks does not advertise (ADR 0001, decision 5) — is refused. |
| 15 | type client struct { | 15 | type client struct { |
| 16 | sessions *sessions | 16 | sessions *sessions |
| 17 | + tools []Tool | ||
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | func (c *client) SessionUpdate(_ context.Context, notification sdk.SessionNotification) error { | 20 | func (c *client) SessionUpdate(_ context.Context, notification sdk.SessionNotification) error { |
modified
internal/acp/conn.go +16 -3 | @@ -58,6 +58,12 @@ type Spec struct { | ||
| 58 | 58 | Env map[string]string |
| 59 | 59 | // Dir is the working directory of the process: the agent's workspace. |
| 60 | 60 | Dir string |
| 61 | + // Tools are offered to the agent (issue #90), the way ToolDiscovery | |
| 62 | + // says: DiscoveryMeta ("" too) or DiscoveryRequest. | |
| 63 | + Tools []Tool | |
| 64 | + ToolDiscovery string | |
| 65 | + // ClientVersion is Sidekicks' version, told in initialize. | |
| 66 | + ClientVersion string | |
| 61 | 67 | } |
| 62 | 68 | |
| 63 | 69 | // Options tunes Start. The zero value is usable. |
| @@ -153,7 +159,7 @@ func (c *Conn) launch(onStderr func(string)) error { | ||
| 153 | 159 | stderrDone := make(chan struct{}) |
| 154 | 160 | go c.readStderr(stderr, onStderr, stderrDone) |
| 155 | 161 | go c.wait(stderrDone) |
| 156 | - c.connection = sdk.NewClientSideConnection(&client{sessions: c.sessions}, stdin, stdout) | |
| 162 | + c.connection = sdk.NewClientSideConnection(&client{sessions: c.sessions, tools: c.spec.Tools}, stdin, stdout) | |
| 157 | 163 | // The SDK logs its own diagnostics ("connection closed"…); the agent's |
| 158 | 164 | // stderr already tells what matters. |
| 159 | 165 | c.connection.SetLogger(slog.New(slog.NewTextHandler(io.Discard, nil))) |
| @@ -201,8 +207,8 @@ func (c *Conn) initialize(ctx context.Context) error { | ||
| 201 | 207 | go func() { |
| 202 | 208 | response, err := c.connection.Initialize(ctx, sdk.InitializeRequest{ |
| 203 | 209 | ProtocolVersion: sdk.ProtocolVersion(ProtocolVersion), |
| 204 | - ClientCapabilities: sdk.ClientCapabilities{}, | |
| 205 | - ClientInfo: &sdk.Implementation{Name: "sidekicks", Version: "0.0.1"}, | |
| 210 | + ClientCapabilities: sdk.ClientCapabilities{Meta: toolsMeta(c.spec.Tools, c.spec.ToolDiscovery)}, | |
| 211 | + ClientInfo: &sdk.Implementation{Name: "sidekicks", Version: clientVersion(c.spec.ClientVersion)}, | |
| 206 | 212 | }) |
| 207 | 213 | answer <- result{response, err} |
| 208 | 214 | }() |
| @@ -226,6 +232,13 @@ func (c *Conn) initialize(ctx context.Context) error { | ||
| 226 | 232 | // handshakeError explains a failed initialize. An agent that exits right |
| 227 | 233 | // away makes the SDK report "peer disconnected before response": the exit |
| 228 | 234 | // status (with the stderr lines added by startError) says more. |
| 235 | +func clientVersion(version string) string { | |
| 236 | + if version == "" { | |
| 237 | + return "dev" | |
| 238 | + } | |
| 239 | + return version | |
| 240 | +} | |
| 241 | + | |
| 229 | 242 | func (c *Conn) handshakeError(err error) error { |
| 230 | 243 | select { |
| 231 | 244 | case <-c.done: |
| @@ -58,6 +58,12 @@ type Spec struct { | |||
| 58 | Env map[string]string | 58 | Env map[string]string |
| 59 | // Dir is the working directory of the process: the agent's workspace. | 59 | // Dir is the working directory of the process: the agent's workspace. |
| 60 | Dir string | 60 | Dir string |
| 61 | + // Tools are offered to the agent (issue #90), the way ToolDiscovery | ||
| 62 | + // says: DiscoveryMeta ("" too) or DiscoveryRequest. | ||
| 63 | + Tools []Tool | ||
| 64 | + ToolDiscovery string | ||
| 65 | + // ClientVersion is Sidekicks' version, told in initialize. | ||
| 66 | + ClientVersion string | ||
| 61 | } | 67 | } |
| 62 | 68 | ||
| 63 | // Options tunes Start. The zero value is usable. | 69 | // Options tunes Start. The zero value is usable. |
| @@ -153,7 +159,7 @@ func (c *Conn) launch(onStderr func(string)) error { | |||
| 153 | stderrDone := make(chan struct{}) | 159 | stderrDone := make(chan struct{}) |
| 154 | go c.readStderr(stderr, onStderr, stderrDone) | 160 | go c.readStderr(stderr, onStderr, stderrDone) |
| 155 | go c.wait(stderrDone) | 161 | go c.wait(stderrDone) |
| 156 | - c.connection = sdk.NewClientSideConnection(&client{sessions: c.sessions}, stdin, stdout) | 162 | + c.connection = sdk.NewClientSideConnection(&client{sessions: c.sessions, tools: c.spec.Tools}, stdin, stdout) |
| 157 | // The SDK logs its own diagnostics ("connection closed"…); the agent's | 163 | // The SDK logs its own diagnostics ("connection closed"…); the agent's |
| 158 | // stderr already tells what matters. | 164 | // stderr already tells what matters. |
| 159 | c.connection.SetLogger(slog.New(slog.NewTextHandler(io.Discard, nil))) | 165 | c.connection.SetLogger(slog.New(slog.NewTextHandler(io.Discard, nil))) |
| @@ -201,8 +207,8 @@ func (c *Conn) initialize(ctx context.Context) error { | |||
| 201 | go func() { | 207 | go func() { |
| 202 | response, err := c.connection.Initialize(ctx, sdk.InitializeRequest{ | 208 | response, err := c.connection.Initialize(ctx, sdk.InitializeRequest{ |
| 203 | ProtocolVersion: sdk.ProtocolVersion(ProtocolVersion), | 209 | ProtocolVersion: sdk.ProtocolVersion(ProtocolVersion), |
| 204 | - ClientCapabilities: sdk.ClientCapabilities{}, | 210 | + ClientCapabilities: sdk.ClientCapabilities{Meta: toolsMeta(c.spec.Tools, c.spec.ToolDiscovery)}, |
| 205 | - ClientInfo: &sdk.Implementation{Name: "sidekicks", Version: "0.0.1"}, | 211 | + ClientInfo: &sdk.Implementation{Name: "sidekicks", Version: clientVersion(c.spec.ClientVersion)}, |
| 206 | }) | 212 | }) |
| 207 | answer <- result{response, err} | 213 | answer <- result{response, err} |
| 208 | }() | 214 | }() |
| @@ -226,6 +232,13 @@ func (c *Conn) initialize(ctx context.Context) error { | |||
| 226 | // handshakeError explains a failed initialize. An agent that exits right | 232 | // handshakeError explains a failed initialize. An agent that exits right |
| 227 | // away makes the SDK report "peer disconnected before response": the exit | 233 | // away makes the SDK report "peer disconnected before response": the exit |
| 228 | // status (with the stderr lines added by startError) says more. | 234 | // status (with the stderr lines added by startError) says more. |
| 235 | +func clientVersion(version string) string { | ||
| 236 | + if version == "" { | ||
| 237 | + return "dev" | ||
| 238 | + } | ||
| 239 | + return version | ||
| 240 | +} | ||
| 241 | + | ||
| 229 | func (c *Conn) handshakeError(err error) error { | 242 | func (c *Conn) handshakeError(err error) error { |
| 230 | select { | 243 | select { |
| 231 | case <-c.done: | 244 | case <-c.done: |
modified
internal/acp/conn_test.go +19 -1 | @@ -4,6 +4,7 @@ package acp_test | ||
| 4 | 4 | |
| 5 | 5 | import ( |
| 6 | 6 | "context" |
| 7 | + "encoding/json" | |
| 7 | 8 | "errors" |
| 8 | 9 | "fmt" |
| 9 | 10 | "os" |
| @@ -242,9 +243,12 @@ func runFakeAgent(mode string) int { | ||
| 242 | 243 | type fakeAgent struct { |
| 243 | 244 | mode string |
| 244 | 245 | conn *sdk.AgentSideConnection |
| 246 | + // client is what Sidekicks said about itself in initialize. | |
| 247 | + client sdk.InitializeRequest | |
| 245 | 248 | } |
| 246 | 249 | |
| 247 | -func (a *fakeAgent) Initialize(context.Context, sdk.InitializeRequest) (sdk.InitializeResponse, error) { | |
| 250 | +func (a *fakeAgent) Initialize(_ context.Context, request sdk.InitializeRequest) (sdk.InitializeResponse, error) { | |
| 251 | + a.client = request | |
| 248 | 252 | version := 1 |
| 249 | 253 | if a.mode == "version-2" { |
| 250 | 254 | version = 2 |
| @@ -322,6 +326,20 @@ func (a *fakeAgent) Prompt(ctx context.Context, request sdk.PromptRequest) (sdk. | ||
| 322 | 326 | send(sdk.UpdateToolCall("call_1", sdk.WithUpdateStatus(sdk.ToolCallStatusCompleted), |
| 323 | 327 | sdk.WithUpdateContent([]sdk.ToolCallContent{sdk.ToolContent(sdk.TextBlock("written")), sdk.ToolDiffContent("/w/notes.txt", "hello")}))) |
| 324 | 328 | return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn}, nil |
| 329 | + case "client-tools": | |
| 330 | + // Like mm with acp.clientTools: report what initialize offered, ask | |
| 331 | + // for the list, call a tool, then a method nobody answers. | |
| 332 | + meta, _ := json.Marshal(a.client.ClientCapabilities.Meta) | |
| 333 | + send(sdk.UpdateAgentMessageText("meta=" + string(meta) + " version=" + a.client.ClientInfo.Version + "\n")) | |
| 334 | + list, err := a.conn.CallExtension(ctx, "_org.mini-me/tools/list", map[string]any{"sessionId": "s-1", "cwd": "/w"}) | |
| 335 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("list=%s %v\n", list, err))) | |
| 336 | + call, err := a.conn.CallExtension(ctx, "_test/echo", map[string]any{"word": "hi", "_meta": map[string]any{"org.mini-me/sessionId": "s-1"}}) | |
| 337 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("call=%s %v\n", call, err))) | |
| 338 | + failing, err := a.conn.CallExtension(ctx, "_test/fail", nil) | |
| 339 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("fail=%s %v\n", failing, err))) | |
| 340 | + _, err = a.conn.CallExtension(ctx, "_test/missing", nil) | |
| 341 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("missing=%v", err))) | |
| 342 | + return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn}, nil | |
| 325 | 343 | case "long": |
| 326 | 344 | for { |
| 327 | 345 | select { |
| @@ -4,6 +4,7 @@ package acp_test | |||
| 4 | 4 | ||
| 5 | import ( | 5 | import ( |
| 6 | "context" | 6 | "context" |
| 7 | + "encoding/json" | ||
| 7 | "errors" | 8 | "errors" |
| 8 | "fmt" | 9 | "fmt" |
| 9 | "os" | 10 | "os" |
| @@ -242,9 +243,12 @@ func runFakeAgent(mode string) int { | |||
| 242 | type fakeAgent struct { | 243 | type fakeAgent struct { |
| 243 | mode string | 244 | mode string |
| 244 | conn *sdk.AgentSideConnection | 245 | conn *sdk.AgentSideConnection |
| 246 | + // client is what Sidekicks said about itself in initialize. | ||
| 247 | + client sdk.InitializeRequest | ||
| 245 | } | 248 | } |
| 246 | 249 | ||
| 247 | -func (a *fakeAgent) Initialize(context.Context, sdk.InitializeRequest) (sdk.InitializeResponse, error) { | 250 | +func (a *fakeAgent) Initialize(_ context.Context, request sdk.InitializeRequest) (sdk.InitializeResponse, error) { |
| 251 | + a.client = request | ||
| 248 | version := 1 | 252 | version := 1 |
| 249 | if a.mode == "version-2" { | 253 | if a.mode == "version-2" { |
| 250 | version = 2 | 254 | version = 2 |
| @@ -322,6 +326,20 @@ func (a *fakeAgent) Prompt(ctx context.Context, request sdk.PromptRequest) (sdk. | |||
| 322 | send(sdk.UpdateToolCall("call_1", sdk.WithUpdateStatus(sdk.ToolCallStatusCompleted), | 326 | send(sdk.UpdateToolCall("call_1", sdk.WithUpdateStatus(sdk.ToolCallStatusCompleted), |
| 323 | sdk.WithUpdateContent([]sdk.ToolCallContent{sdk.ToolContent(sdk.TextBlock("written")), sdk.ToolDiffContent("/w/notes.txt", "hello")}))) | 327 | sdk.WithUpdateContent([]sdk.ToolCallContent{sdk.ToolContent(sdk.TextBlock("written")), sdk.ToolDiffContent("/w/notes.txt", "hello")}))) |
| 324 | return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn}, nil | 328 | return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn}, nil |
| 329 | + case "client-tools": | ||
| 330 | + // Like mm with acp.clientTools: report what initialize offered, ask | ||
| 331 | + // for the list, call a tool, then a method nobody answers. | ||
| 332 | + meta, _ := json.Marshal(a.client.ClientCapabilities.Meta) | ||
| 333 | + send(sdk.UpdateAgentMessageText("meta=" + string(meta) + " version=" + a.client.ClientInfo.Version + "\n")) | ||
| 334 | + list, err := a.conn.CallExtension(ctx, "_org.mini-me/tools/list", map[string]any{"sessionId": "s-1", "cwd": "/w"}) | ||
| 335 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("list=%s %v\n", list, err))) | ||
| 336 | + call, err := a.conn.CallExtension(ctx, "_test/echo", map[string]any{"word": "hi", "_meta": map[string]any{"org.mini-me/sessionId": "s-1"}}) | ||
| 337 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("call=%s %v\n", call, err))) | ||
| 338 | + failing, err := a.conn.CallExtension(ctx, "_test/fail", nil) | ||
| 339 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("fail=%s %v\n", failing, err))) | ||
| 340 | + _, err = a.conn.CallExtension(ctx, "_test/missing", nil) | ||
| 341 | + send(sdk.UpdateAgentMessageText(fmt.Sprintf("missing=%v", err))) | ||
| 342 | + return sdk.PromptResponse{StopReason: sdk.StopReasonEndTurn}, nil | ||
| 325 | case "long": | 343 | case "long": |
| 326 | for { | 344 | for { |
| 327 | select { | 345 | select { |
added
internal/acp/tools.go +110 -0 | new file mode 100644 | ||
| @@ -0,0 +1,110 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package acp | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "context" | |
| 7 | + "encoding/json" | |
| 8 | + | |
| 9 | + sdk "github.com/coder/acp-go-sdk" | |
| 10 | +) | |
| 11 | + | |
| 12 | +// The tools Sidekicks offers an agent (issue #90), with the protocol of | |
| 13 | +// mini-me ("org.mini-me/tools"): ACP extension methods, whose names start | |
| 14 | +// with "_", that the agent calls when its model calls client_<name>. | |
| 15 | +// | |
| 16 | +// Discovery "meta" puts the list in the _meta of the initialize request; | |
| 17 | +// "request" announces the capability only (true) and answers the agent's | |
| 18 | +// _org.mini-me/tools/list when it opens a session. A call carries the | |
| 19 | +// model's arguments at the top of its params, and the session in | |
| 20 | +// _meta["org.mini-me/sessionId"]; the answer has the shape of an MCP | |
| 21 | +// tools/call result. | |
| 22 | +const ( | |
| 23 | + // ToolsMetaKey is the key of clientCapabilities._meta that offers the tools. | |
| 24 | + ToolsMetaKey = "org.mini-me/tools" | |
| 25 | + // ToolsListMethod is the request with which the agent asks for the tools. | |
| 26 | + ToolsListMethod = "_org.mini-me/tools/list" | |
| 27 | + // SessionMetaKey is the key of a call's params._meta that names its session. | |
| 28 | + SessionMetaKey = "org.mini-me/sessionId" | |
| 29 | + // DiscoveryMeta and DiscoveryRequest are the two ways to offer the tools | |
| 30 | + // (acp.clientTools.discovery in a mini-me agent's file). | |
| 31 | + DiscoveryMeta = "meta" | |
| 32 | + DiscoveryRequest = "request" | |
| 33 | +) | |
| 34 | + | |
| 35 | +// Tool is a tool Sidekicks offers the agent. The model sees it as | |
| 36 | +// client_<Name>; the agent calls Method, which starts with "_". | |
| 37 | +type Tool struct { | |
| 38 | + Name string `json:"name"` | |
| 39 | + Description string `json:"description,omitempty"` | |
| 40 | + Method string `json:"method"` | |
| 41 | + // InputSchema is the JSON schema of the arguments; nil: no parameter. | |
| 42 | + InputSchema map[string]any `json:"inputSchema,omitempty"` | |
| 43 | + // Call answers a call: sessionID is the session it belongs to ("" when | |
| 44 | + // the agent does not say), arguments are the model's. An error is given | |
| 45 | + // to the model as a failed call. | |
| 46 | + Call func(ctx context.Context, sessionID string, arguments map[string]any) (string, error) `json:"-"` | |
| 47 | +} | |
| 48 | + | |
| 49 | +// toolsMeta is the _meta of the initialize request that offers tools with | |
| 50 | +// discovery; nil without tools. | |
| 51 | +func toolsMeta(tools []Tool, discovery string) map[string]any { | |
| 52 | + if len(tools) == 0 { | |
| 53 | + return nil | |
| 54 | + } | |
| 55 | + if discovery == DiscoveryRequest { | |
| 56 | + return map[string]any{ToolsMetaKey: true} | |
| 57 | + } | |
| 58 | + return map[string]any{ToolsMetaKey: tools} | |
| 59 | +} | |
| 60 | + | |
| 61 | +// toolText is one block of a tool result. | |
| 62 | +type toolText struct { | |
| 63 | + Type string `json:"type"` | |
| 64 | + Text string `json:"text"` | |
| 65 | +} | |
| 66 | + | |
| 67 | +// toolResult is the answer to a call: an MCP tools/call result. | |
| 68 | +type toolResult struct { | |
| 69 | + Content []toolText `json:"content"` | |
| 70 | + IsError bool `json:"isError"` | |
| 71 | +} | |
| 72 | + | |
| 73 | +// HandleExtensionMethod answers the agent's extension requests: the list of | |
| 74 | +// tools, and the calls of each tool. Any other method is not found. | |
| 75 | +func (c *client) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error) { | |
| 76 | + if method == ToolsListMethod && len(c.tools) > 0 { | |
| 77 | + return map[string]any{"tools": c.tools}, nil | |
| 78 | + } | |
| 79 | + for _, tool := range c.tools { | |
| 80 | + if tool.Method == method { | |
| 81 | + return callTool(ctx, tool, params), nil | |
| 82 | + } | |
| 83 | + } | |
| 84 | + return nil, sdk.NewMethodNotFound(method) | |
| 85 | +} | |
| 86 | + | |
| 87 | +// callTool runs tool with the arguments of params, apart from _meta, which | |
| 88 | +// names the session. | |
| 89 | +func callTool(ctx context.Context, tool Tool, params json.RawMessage) toolResult { | |
| 90 | + arguments := map[string]any{} | |
| 91 | + if len(params) > 0 && string(params) != "null" { | |
| 92 | + if err := json.Unmarshal(params, &arguments); err != nil { | |
| 93 | + return failed("the arguments are not a JSON object: " + err.Error()) | |
| 94 | + } | |
| 95 | + } | |
| 96 | + sessionID := "" | |
| 97 | + if meta, ok := arguments["_meta"].(map[string]any); ok { | |
| 98 | + sessionID, _ = meta[SessionMetaKey].(string) | |
| 99 | + } | |
| 100 | + delete(arguments, "_meta") | |
| 101 | + text, err := tool.Call(ctx, sessionID, arguments) | |
| 102 | + if err != nil { | |
| 103 | + return failed(err.Error()) | |
| 104 | + } | |
| 105 | + return toolResult{Content: []toolText{{Type: "text", Text: text}}} | |
| 106 | +} | |
| 107 | + | |
| 108 | +func failed(text string) toolResult { | |
| 109 | + return toolResult{Content: []toolText{{Type: "text", Text: text}}, IsError: true} | |
| 110 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package acp | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "context" | ||
| 7 | + "encoding/json" | ||
| 8 | + | ||
| 9 | + sdk "github.com/coder/acp-go-sdk" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// The tools Sidekicks offers an agent (issue #90), with the protocol of | ||
| 13 | +// mini-me ("org.mini-me/tools"): ACP extension methods, whose names start | ||
| 14 | +// with "_", that the agent calls when its model calls client_<name>. | ||
| 15 | +// | ||
| 16 | +// Discovery "meta" puts the list in the _meta of the initialize request; | ||
| 17 | +// "request" announces the capability only (true) and answers the agent's | ||
| 18 | +// _org.mini-me/tools/list when it opens a session. A call carries the | ||
| 19 | +// model's arguments at the top of its params, and the session in | ||
| 20 | +// _meta["org.mini-me/sessionId"]; the answer has the shape of an MCP | ||
| 21 | +// tools/call result. | ||
| 22 | +const ( | ||
| 23 | + // ToolsMetaKey is the key of clientCapabilities._meta that offers the tools. | ||
| 24 | + ToolsMetaKey = "org.mini-me/tools" | ||
| 25 | + // ToolsListMethod is the request with which the agent asks for the tools. | ||
| 26 | + ToolsListMethod = "_org.mini-me/tools/list" | ||
| 27 | + // SessionMetaKey is the key of a call's params._meta that names its session. | ||
| 28 | + SessionMetaKey = "org.mini-me/sessionId" | ||
| 29 | + // DiscoveryMeta and DiscoveryRequest are the two ways to offer the tools | ||
| 30 | + // (acp.clientTools.discovery in a mini-me agent's file). | ||
| 31 | + DiscoveryMeta = "meta" | ||
| 32 | + DiscoveryRequest = "request" | ||
| 33 | +) | ||
| 34 | + | ||
| 35 | +// Tool is a tool Sidekicks offers the agent. The model sees it as | ||
| 36 | +// client_<Name>; the agent calls Method, which starts with "_". | ||
| 37 | +type Tool struct { | ||
| 38 | + Name string `json:"name"` | ||
| 39 | + Description string `json:"description,omitempty"` | ||
| 40 | + Method string `json:"method"` | ||
| 41 | + // InputSchema is the JSON schema of the arguments; nil: no parameter. | ||
| 42 | + InputSchema map[string]any `json:"inputSchema,omitempty"` | ||
| 43 | + // Call answers a call: sessionID is the session it belongs to ("" when | ||
| 44 | + // the agent does not say), arguments are the model's. An error is given | ||
| 45 | + // to the model as a failed call. | ||
| 46 | + Call func(ctx context.Context, sessionID string, arguments map[string]any) (string, error) `json:"-"` | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +// toolsMeta is the _meta of the initialize request that offers tools with | ||
| 50 | +// discovery; nil without tools. | ||
| 51 | +func toolsMeta(tools []Tool, discovery string) map[string]any { | ||
| 52 | + if len(tools) == 0 { | ||
| 53 | + return nil | ||
| 54 | + } | ||
| 55 | + if discovery == DiscoveryRequest { | ||
| 56 | + return map[string]any{ToolsMetaKey: true} | ||
| 57 | + } | ||
| 58 | + return map[string]any{ToolsMetaKey: tools} | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +// toolText is one block of a tool result. | ||
| 62 | +type toolText struct { | ||
| 63 | + Type string `json:"type"` | ||
| 64 | + Text string `json:"text"` | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +// toolResult is the answer to a call: an MCP tools/call result. | ||
| 68 | +type toolResult struct { | ||
| 69 | + Content []toolText `json:"content"` | ||
| 70 | + IsError bool `json:"isError"` | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +// HandleExtensionMethod answers the agent's extension requests: the list of | ||
| 74 | +// tools, and the calls of each tool. Any other method is not found. | ||
| 75 | +func (c *client) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error) { | ||
| 76 | + if method == ToolsListMethod && len(c.tools) > 0 { | ||
| 77 | + return map[string]any{"tools": c.tools}, nil | ||
| 78 | + } | ||
| 79 | + for _, tool := range c.tools { | ||
| 80 | + if tool.Method == method { | ||
| 81 | + return callTool(ctx, tool, params), nil | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + return nil, sdk.NewMethodNotFound(method) | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +// callTool runs tool with the arguments of params, apart from _meta, which | ||
| 88 | +// names the session. | ||
| 89 | +func callTool(ctx context.Context, tool Tool, params json.RawMessage) toolResult { | ||
| 90 | + arguments := map[string]any{} | ||
| 91 | + if len(params) > 0 && string(params) != "null" { | ||
| 92 | + if err := json.Unmarshal(params, &arguments); err != nil { | ||
| 93 | + return failed("the arguments are not a JSON object: " + err.Error()) | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + sessionID := "" | ||
| 97 | + if meta, ok := arguments["_meta"].(map[string]any); ok { | ||
| 98 | + sessionID, _ = meta[SessionMetaKey].(string) | ||
| 99 | + } | ||
| 100 | + delete(arguments, "_meta") | ||
| 101 | + text, err := tool.Call(ctx, sessionID, arguments) | ||
| 102 | + if err != nil { | ||
| 103 | + return failed(err.Error()) | ||
| 104 | + } | ||
| 105 | + return toolResult{Content: []toolText{{Type: "text", Text: text}}} | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +func failed(text string) toolResult { | ||
| 109 | + return toolResult{Content: []toolText{{Type: "text", Text: text}}, IsError: true} | ||
| 110 | +} | ||
added
internal/acp/tools_test.go +111 -0 | new file mode 100644 | ||
| @@ -0,0 +1,111 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package acp_test | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "context" | |
| 7 | + "errors" | |
| 8 | + "fmt" | |
| 9 | + "strings" | |
| 10 | + "testing" | |
| 11 | + | |
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | |
| 13 | +) | |
| 14 | + | |
| 15 | +// Issue #90: Sidekicks offers tools to the agent with the protocol of mini-me. | |
| 16 | + | |
| 17 | +func testTools() []acp.Tool { | |
| 18 | + return []acp.Tool{ | |
| 19 | + {Name: "echo", Description: "Say the word back.", Method: "_test/echo", | |
| 20 | + InputSchema: map[string]any{"type": "object", "properties": map[string]any{"word": map[string]any{"type": "string"}}}, | |
| 21 | + Call: func(_ context.Context, sessionID string, arguments map[string]any) (string, error) { | |
| 22 | + return fmt.Sprintf("%v in %s (%d argument)", arguments["word"], sessionID, len(arguments)), nil | |
| 23 | + }}, | |
| 24 | + {Name: "fail", Method: "_test/fail", Call: func(context.Context, string, map[string]any) (string, error) { | |
| 25 | + return "", errors.New("no memory status here") | |
| 26 | + }}, | |
| 27 | + } | |
| 28 | +} | |
| 29 | + | |
| 30 | +// toolsTurn has the fake agent call the tools offered with discovery and | |
| 31 | +// returns what it reports, one line per step. | |
| 32 | +func toolsTurn(t *testing.T, discovery string) map[string]string { | |
| 33 | + t.Helper() | |
| 34 | + spec := fakeSpec(t, "ready") | |
| 35 | + spec.Tools, spec.ToolDiscovery, spec.ClientVersion = testTools(), discovery, "1.4.0" | |
| 36 | + conn, err := acp.Start(context.Background(), spec, acp.Options{}) | |
| 37 | + if err != nil { | |
| 38 | + t.Fatal(err) | |
| 39 | + } | |
| 40 | + t.Cleanup(func() { _ = conn.Close(context.Background()) }) | |
| 41 | + handler := &recordingHandler{} | |
| 42 | + id, err := conn.NewSession(context.Background(), t.TempDir(), handler) | |
| 43 | + if err != nil { | |
| 44 | + t.Fatal(err) | |
| 45 | + } | |
| 46 | + if _, err := conn.Prompt(context.Background(), id, "client-tools"); err != nil { | |
| 47 | + t.Fatal(err) | |
| 48 | + } | |
| 49 | + var text strings.Builder | |
| 50 | + for _, update := range handler.ofKind(acp.UpdateMessage) { | |
| 51 | + text.WriteString(update.Text) | |
| 52 | + } | |
| 53 | + steps := map[string]string{} | |
| 54 | + for _, line := range strings.Split(text.String(), "\n") { | |
| 55 | + key, value, _ := strings.Cut(line, "=") | |
| 56 | + steps[key] = value | |
| 57 | + } | |
| 58 | + return steps | |
| 59 | +} | |
| 60 | + | |
| 61 | +func TestTheToolsAreOfferedInInitialize(t *testing.T) { | |
| 62 | + steps := toolsTurn(t, acp.DiscoveryMeta) | |
| 63 | + for _, want := range []string{`"org.mini-me/tools":[`, `"name":"echo"`, `"method":"_test/echo"`, `"description":"Say the word back."`, `"inputSchema":{`, `{"method":"_test/fail","name":"fail"}`, `version=1.4.0`} { | |
| 64 | + if !strings.Contains(steps["meta"], want) { | |
| 65 | + t.Fatalf("initialize lacks %s: %s", want, steps["meta"]) | |
| 66 | + } | |
| 67 | + } | |
| 68 | +} | |
| 69 | + | |
| 70 | +func TestDiscoveryRequestAnnouncesTheCapabilityAndAnswersTheList(t *testing.T) { | |
| 71 | + steps := toolsTurn(t, acp.DiscoveryRequest) | |
| 72 | + if !strings.HasPrefix(steps["meta"], `{"org.mini-me/tools":true}`) { | |
| 73 | + t.Fatalf("only the capability: %s", steps["meta"]) | |
| 74 | + } | |
| 75 | + if !strings.HasPrefix(steps["list"], `{"tools":[{"name":"echo"`) || !strings.HasSuffix(steps["list"], "<nil>") { | |
| 76 | + t.Fatalf("list: %s", steps["list"]) | |
| 77 | + } | |
| 78 | +} | |
| 79 | + | |
| 80 | +func TestAToolCallGetsItsArgumentsAndSession(t *testing.T) { | |
| 81 | + steps := toolsTurn(t, acp.DiscoveryMeta) | |
| 82 | + if steps["call"] != `{"content":[{"type":"text","text":"hi in s-1 (1 argument)"}],"isError":false} <nil>` { | |
| 83 | + t.Fatalf("call: %s", steps["call"]) | |
| 84 | + } | |
| 85 | + if steps["fail"] != `{"content":[{"type":"text","text":"no memory status here"}],"isError":true} <nil>` { | |
| 86 | + t.Fatalf("a failing tool is a failed call: %s", steps["fail"]) | |
| 87 | + } | |
| 88 | + if !strings.Contains(steps["missing"], "Method not found") { | |
| 89 | + t.Fatalf("an unknown method is not found: %s", steps["missing"]) | |
| 90 | + } | |
| 91 | +} | |
| 92 | + | |
| 93 | +func TestAnAgentWithoutToolsIsOfferedNothing(t *testing.T) { | |
| 94 | + conn, err := acp.Start(context.Background(), fakeSpec(t, "ready"), acp.Options{}) | |
| 95 | + if err != nil { | |
| 96 | + t.Fatal(err) | |
| 97 | + } | |
| 98 | + t.Cleanup(func() { _ = conn.Close(context.Background()) }) | |
| 99 | + handler := &recordingHandler{} | |
| 100 | + id, _ := conn.NewSession(context.Background(), t.TempDir(), handler) | |
| 101 | + if _, err := conn.Prompt(context.Background(), id, "client-tools"); err != nil { | |
| 102 | + t.Fatal(err) | |
| 103 | + } | |
| 104 | + var text strings.Builder | |
| 105 | + for _, update := range handler.ofKind(acp.UpdateMessage) { | |
| 106 | + text.WriteString(update.Text) | |
| 107 | + } | |
| 108 | + if !strings.HasPrefix(text.String(), "meta=null version=dev") || !strings.Contains(text.String(), `list=null {"code":-32601`) { | |
| 109 | + t.Fatalf("no tools, no list: %s", text.String()) | |
| 110 | + } | |
| 111 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package acp_test | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "context" | ||
| 7 | + "errors" | ||
| 8 | + "fmt" | ||
| 9 | + "strings" | ||
| 10 | + "testing" | ||
| 11 | + | ||
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +// Issue #90: Sidekicks offers tools to the agent with the protocol of mini-me. | ||
| 16 | + | ||
| 17 | +func testTools() []acp.Tool { | ||
| 18 | + return []acp.Tool{ | ||
| 19 | + {Name: "echo", Description: "Say the word back.", Method: "_test/echo", | ||
| 20 | + InputSchema: map[string]any{"type": "object", "properties": map[string]any{"word": map[string]any{"type": "string"}}}, | ||
| 21 | + Call: func(_ context.Context, sessionID string, arguments map[string]any) (string, error) { | ||
| 22 | + return fmt.Sprintf("%v in %s (%d argument)", arguments["word"], sessionID, len(arguments)), nil | ||
| 23 | + }}, | ||
| 24 | + {Name: "fail", Method: "_test/fail", Call: func(context.Context, string, map[string]any) (string, error) { | ||
| 25 | + return "", errors.New("no memory status here") | ||
| 26 | + }}, | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +// toolsTurn has the fake agent call the tools offered with discovery and | ||
| 31 | +// returns what it reports, one line per step. | ||
| 32 | +func toolsTurn(t *testing.T, discovery string) map[string]string { | ||
| 33 | + t.Helper() | ||
| 34 | + spec := fakeSpec(t, "ready") | ||
| 35 | + spec.Tools, spec.ToolDiscovery, spec.ClientVersion = testTools(), discovery, "1.4.0" | ||
| 36 | + conn, err := acp.Start(context.Background(), spec, acp.Options{}) | ||
| 37 | + if err != nil { | ||
| 38 | + t.Fatal(err) | ||
| 39 | + } | ||
| 40 | + t.Cleanup(func() { _ = conn.Close(context.Background()) }) | ||
| 41 | + handler := &recordingHandler{} | ||
| 42 | + id, err := conn.NewSession(context.Background(), t.TempDir(), handler) | ||
| 43 | + if err != nil { | ||
| 44 | + t.Fatal(err) | ||
| 45 | + } | ||
| 46 | + if _, err := conn.Prompt(context.Background(), id, "client-tools"); err != nil { | ||
| 47 | + t.Fatal(err) | ||
| 48 | + } | ||
| 49 | + var text strings.Builder | ||
| 50 | + for _, update := range handler.ofKind(acp.UpdateMessage) { | ||
| 51 | + text.WriteString(update.Text) | ||
| 52 | + } | ||
| 53 | + steps := map[string]string{} | ||
| 54 | + for _, line := range strings.Split(text.String(), "\n") { | ||
| 55 | + key, value, _ := strings.Cut(line, "=") | ||
| 56 | + steps[key] = value | ||
| 57 | + } | ||
| 58 | + return steps | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +func TestTheToolsAreOfferedInInitialize(t *testing.T) { | ||
| 62 | + steps := toolsTurn(t, acp.DiscoveryMeta) | ||
| 63 | + for _, want := range []string{`"org.mini-me/tools":[`, `"name":"echo"`, `"method":"_test/echo"`, `"description":"Say the word back."`, `"inputSchema":{`, `{"method":"_test/fail","name":"fail"}`, `version=1.4.0`} { | ||
| 64 | + if !strings.Contains(steps["meta"], want) { | ||
| 65 | + t.Fatalf("initialize lacks %s: %s", want, steps["meta"]) | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +func TestDiscoveryRequestAnnouncesTheCapabilityAndAnswersTheList(t *testing.T) { | ||
| 71 | + steps := toolsTurn(t, acp.DiscoveryRequest) | ||
| 72 | + if !strings.HasPrefix(steps["meta"], `{"org.mini-me/tools":true}`) { | ||
| 73 | + t.Fatalf("only the capability: %s", steps["meta"]) | ||
| 74 | + } | ||
| 75 | + if !strings.HasPrefix(steps["list"], `{"tools":[{"name":"echo"`) || !strings.HasSuffix(steps["list"], "<nil>") { | ||
| 76 | + t.Fatalf("list: %s", steps["list"]) | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +func TestAToolCallGetsItsArgumentsAndSession(t *testing.T) { | ||
| 81 | + steps := toolsTurn(t, acp.DiscoveryMeta) | ||
| 82 | + if steps["call"] != `{"content":[{"type":"text","text":"hi in s-1 (1 argument)"}],"isError":false} <nil>` { | ||
| 83 | + t.Fatalf("call: %s", steps["call"]) | ||
| 84 | + } | ||
| 85 | + if steps["fail"] != `{"content":[{"type":"text","text":"no memory status here"}],"isError":true} <nil>` { | ||
| 86 | + t.Fatalf("a failing tool is a failed call: %s", steps["fail"]) | ||
| 87 | + } | ||
| 88 | + if !strings.Contains(steps["missing"], "Method not found") { | ||
| 89 | + t.Fatalf("an unknown method is not found: %s", steps["missing"]) | ||
| 90 | + } | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +func TestAnAgentWithoutToolsIsOfferedNothing(t *testing.T) { | ||
| 94 | + conn, err := acp.Start(context.Background(), fakeSpec(t, "ready"), acp.Options{}) | ||
| 95 | + if err != nil { | ||
| 96 | + t.Fatal(err) | ||
| 97 | + } | ||
| 98 | + t.Cleanup(func() { _ = conn.Close(context.Background()) }) | ||
| 99 | + handler := &recordingHandler{} | ||
| 100 | + id, _ := conn.NewSession(context.Background(), t.TempDir(), handler) | ||
| 101 | + if _, err := conn.Prompt(context.Background(), id, "client-tools"); err != nil { | ||
| 102 | + t.Fatal(err) | ||
| 103 | + } | ||
| 104 | + var text strings.Builder | ||
| 105 | + for _, update := range handler.ofKind(acp.UpdateMessage) { | ||
| 106 | + text.WriteString(update.Text) | ||
| 107 | + } | ||
| 108 | + if !strings.HasPrefix(text.String(), "meta=null version=dev") || !strings.Contains(text.String(), `list=null {"code":-32601`) { | ||
| 109 | + t.Fatalf("no tools, no list: %s", text.String()) | ||
| 110 | + } | ||
| 111 | +} | ||
added
internal/agents/discovery.go +62 -0 | new file mode 100644 | ||
| @@ -0,0 +1,62 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package agents | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "os" | |
| 7 | + "path/filepath" | |
| 8 | + "strings" | |
| 9 | + | |
| 10 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | |
| 11 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | |
| 12 | + "go.yaml.in/yaml/v3" | |
| 13 | +) | |
| 14 | + | |
| 15 | +// ToolDiscovery is how the agent of definition wants the tools Sidekicks | |
| 16 | +// offers (issue #90): acp.DiscoveryRequest when the file it is started with | |
| 17 | +// (--config <file>, as mm is) says acp.clientTools.discovery: request; | |
| 18 | +// acp.DiscoveryMeta otherwise, mini-me's default. The file is read on this | |
| 19 | +// computer: an agent in a sandbox or a container has it at the same path. | |
| 20 | +// | |
| 21 | +// ToolDiscovery(config.Agent{Command: "mm", Args: []string{"--acp", "--config", "agent.yaml"}, Workspace: "/agents/riker"}) | |
| 22 | +func ToolDiscovery(definition config.Agent) string { | |
| 23 | + path := configFileOf(definition.Args) | |
| 24 | + if path == "" { | |
| 25 | + return acp.DiscoveryMeta | |
| 26 | + } | |
| 27 | + if !filepath.IsAbs(path) { | |
| 28 | + path = filepath.Join(definition.Workspace, path) | |
| 29 | + } | |
| 30 | + data, err := os.ReadFile(path) | |
| 31 | + if err != nil { | |
| 32 | + return acp.DiscoveryMeta | |
| 33 | + } | |
| 34 | + var file struct { | |
| 35 | + ACP struct { | |
| 36 | + ClientTools struct { | |
| 37 | + Discovery string `yaml:"discovery"` | |
| 38 | + } `yaml:"clientTools"` | |
| 39 | + } `yaml:"acp"` | |
| 40 | + } | |
| 41 | + if yaml.Unmarshal(data, &file) != nil || file.ACP.ClientTools.Discovery != acp.DiscoveryRequest { | |
| 42 | + return acp.DiscoveryMeta | |
| 43 | + } | |
| 44 | + return acp.DiscoveryRequest | |
| 45 | +} | |
| 46 | + | |
| 47 | +// configFileOf is the file given with --config or -config in args, "" without. | |
| 48 | +func configFileOf(args []string) string { | |
| 49 | + for i, arg := range args { | |
| 50 | + name, value, joined := strings.Cut(strings.TrimLeft(arg, "-"), "=") | |
| 51 | + if !strings.HasPrefix(arg, "-") || name != "config" { | |
| 52 | + continue | |
| 53 | + } | |
| 54 | + if joined { | |
| 55 | + return value | |
| 56 | + } | |
| 57 | + if i+1 < len(args) { | |
| 58 | + return args[i+1] | |
| 59 | + } | |
| 60 | + } | |
| 61 | + return "" | |
| 62 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package agents | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "os" | ||
| 7 | + "path/filepath" | ||
| 8 | + "strings" | ||
| 9 | + | ||
| 10 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | ||
| 11 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | ||
| 12 | + "go.yaml.in/yaml/v3" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +// ToolDiscovery is how the agent of definition wants the tools Sidekicks | ||
| 16 | +// offers (issue #90): acp.DiscoveryRequest when the file it is started with | ||
| 17 | +// (--config <file>, as mm is) says acp.clientTools.discovery: request; | ||
| 18 | +// acp.DiscoveryMeta otherwise, mini-me's default. The file is read on this | ||
| 19 | +// computer: an agent in a sandbox or a container has it at the same path. | ||
| 20 | +// | ||
| 21 | +// ToolDiscovery(config.Agent{Command: "mm", Args: []string{"--acp", "--config", "agent.yaml"}, Workspace: "/agents/riker"}) | ||
| 22 | +func ToolDiscovery(definition config.Agent) string { | ||
| 23 | + path := configFileOf(definition.Args) | ||
| 24 | + if path == "" { | ||
| 25 | + return acp.DiscoveryMeta | ||
| 26 | + } | ||
| 27 | + if !filepath.IsAbs(path) { | ||
| 28 | + path = filepath.Join(definition.Workspace, path) | ||
| 29 | + } | ||
| 30 | + data, err := os.ReadFile(path) | ||
| 31 | + if err != nil { | ||
| 32 | + return acp.DiscoveryMeta | ||
| 33 | + } | ||
| 34 | + var file struct { | ||
| 35 | + ACP struct { | ||
| 36 | + ClientTools struct { | ||
| 37 | + Discovery string `yaml:"discovery"` | ||
| 38 | + } `yaml:"clientTools"` | ||
| 39 | + } `yaml:"acp"` | ||
| 40 | + } | ||
| 41 | + if yaml.Unmarshal(data, &file) != nil || file.ACP.ClientTools.Discovery != acp.DiscoveryRequest { | ||
| 42 | + return acp.DiscoveryMeta | ||
| 43 | + } | ||
| 44 | + return acp.DiscoveryRequest | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +// configFileOf is the file given with --config or -config in args, "" without. | ||
| 48 | +func configFileOf(args []string) string { | ||
| 49 | + for i, arg := range args { | ||
| 50 | + name, value, joined := strings.Cut(strings.TrimLeft(arg, "-"), "=") | ||
| 51 | + if !strings.HasPrefix(arg, "-") || name != "config" { | ||
| 52 | + continue | ||
| 53 | + } | ||
| 54 | + if joined { | ||
| 55 | + return value | ||
| 56 | + } | ||
| 57 | + if i+1 < len(args) { | ||
| 58 | + return args[i+1] | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + return "" | ||
| 62 | +} | ||
added
internal/agents/discovery_test.go +44 -0 | new file mode 100644 | ||
| @@ -0,0 +1,44 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package agents_test | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "os" | |
| 7 | + "path/filepath" | |
| 8 | + "testing" | |
| 9 | + | |
| 10 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | |
| 11 | + "git.rickub.com/bots-garden/sidekicks/internal/agents" | |
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | |
| 13 | +) | |
| 14 | + | |
| 15 | +func TestToolDiscoveryFollowsTheAgentsFile(t *testing.T) { | |
| 16 | + dir := t.TempDir() | |
| 17 | + write := func(name, content string) { | |
| 18 | + if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil { | |
| 19 | + t.Fatal(err) | |
| 20 | + } | |
| 21 | + } | |
| 22 | + write("request.yaml", "acp:\n clientTools:\n enabled: true\n discovery: request\n") | |
| 23 | + write("meta.yaml", "acp:\n clientTools:\n discovery: meta\n") | |
| 24 | + write("none.yaml", "model: x\n") | |
| 25 | + cases := []struct { | |
| 26 | + args []string | |
| 27 | + want string | |
| 28 | + }{ | |
| 29 | + {[]string{"--acp", "--config", "request.yaml"}, acp.DiscoveryRequest}, | |
| 30 | + {[]string{"-acp", "-config", filepath.Join(dir, "request.yaml")}, acp.DiscoveryRequest}, | |
| 31 | + {[]string{"--acp", "--config=request.yaml"}, acp.DiscoveryRequest}, | |
| 32 | + {[]string{"exec", "-i", "box", "mm", "--acp", "--config", "request.yaml"}, acp.DiscoveryRequest}, | |
| 33 | + {[]string{"--acp", "--config", "meta.yaml"}, acp.DiscoveryMeta}, | |
| 34 | + {[]string{"--acp", "--config", "none.yaml"}, acp.DiscoveryMeta}, | |
| 35 | + {[]string{"--acp", "--config", "missing.yaml"}, acp.DiscoveryMeta}, | |
| 36 | + {[]string{"serve", "acp", "agent.yaml"}, acp.DiscoveryMeta}, | |
| 37 | + {nil, acp.DiscoveryMeta}, | |
| 38 | + } | |
| 39 | + for _, c := range cases { | |
| 40 | + if got := agents.ToolDiscovery(config.Agent{Command: "mm", Args: c.args, Workspace: dir}); got != c.want { | |
| 41 | + t.Errorf("%q: got %s, want %s", c.args, got, c.want) | |
| 42 | + } | |
| 43 | + } | |
| 44 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package agents_test | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "os" | ||
| 7 | + "path/filepath" | ||
| 8 | + "testing" | ||
| 9 | + | ||
| 10 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | ||
| 11 | + "git.rickub.com/bots-garden/sidekicks/internal/agents" | ||
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +func TestToolDiscoveryFollowsTheAgentsFile(t *testing.T) { | ||
| 16 | + dir := t.TempDir() | ||
| 17 | + write := func(name, content string) { | ||
| 18 | + if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil { | ||
| 19 | + t.Fatal(err) | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + write("request.yaml", "acp:\n clientTools:\n enabled: true\n discovery: request\n") | ||
| 23 | + write("meta.yaml", "acp:\n clientTools:\n discovery: meta\n") | ||
| 24 | + write("none.yaml", "model: x\n") | ||
| 25 | + cases := []struct { | ||
| 26 | + args []string | ||
| 27 | + want string | ||
| 28 | + }{ | ||
| 29 | + {[]string{"--acp", "--config", "request.yaml"}, acp.DiscoveryRequest}, | ||
| 30 | + {[]string{"-acp", "-config", filepath.Join(dir, "request.yaml")}, acp.DiscoveryRequest}, | ||
| 31 | + {[]string{"--acp", "--config=request.yaml"}, acp.DiscoveryRequest}, | ||
| 32 | + {[]string{"exec", "-i", "box", "mm", "--acp", "--config", "request.yaml"}, acp.DiscoveryRequest}, | ||
| 33 | + {[]string{"--acp", "--config", "meta.yaml"}, acp.DiscoveryMeta}, | ||
| 34 | + {[]string{"--acp", "--config", "none.yaml"}, acp.DiscoveryMeta}, | ||
| 35 | + {[]string{"--acp", "--config", "missing.yaml"}, acp.DiscoveryMeta}, | ||
| 36 | + {[]string{"serve", "acp", "agent.yaml"}, acp.DiscoveryMeta}, | ||
| 37 | + {nil, acp.DiscoveryMeta}, | ||
| 38 | + } | ||
| 39 | + for _, c := range cases { | ||
| 40 | + if got := agents.ToolDiscovery(config.Agent{Command: "mm", Args: c.args, Workspace: dir}); got != c.want { | ||
| 41 | + t.Errorf("%q: got %s, want %s", c.args, got, c.want) | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | +} | ||
modified
internal/agents/manager.go +58 -8 | @@ -20,6 +20,7 @@ import ( | ||
| 20 | 20 | "os" |
| 21 | 21 | "os/exec" |
| 22 | 22 | "reflect" |
| 23 | + "slices" | |
| 23 | 24 | "strings" |
| 24 | 25 | "sync" |
| 25 | 26 | "time" |
| @@ -98,6 +99,10 @@ type Options struct { | ||
| 98 | 99 | Prepare Preparer |
| 99 | 100 | // Now defaults to time.Now; tests control the clock with it. |
| 100 | 101 | Now func() time.Time |
| 102 | + // Tools, when set, gives the tools Sidekicks offers an agent (issue #90). | |
| 103 | + Tools func(definition config.Agent) []acp.Tool | |
| 104 | + // ClientVersion is Sidekicks' version, told to the agents. | |
| 105 | + ClientVersion string | |
| 101 | 106 | } |
| 102 | 107 | |
| 103 | 108 | // Status is the public view of an agent. |
| @@ -140,6 +145,8 @@ type agent struct { | ||
| 140 | 145 | // starting is closed when the current start attempt ends. |
| 141 | 146 | starting chan struct{} |
| 142 | 147 | outdated bool |
| 148 | + // tools are the names of the tools offered when the agent started. | |
| 149 | + tools []string | |
| 143 | 150 | // stopRequested: Stop was called while the agent was starting. |
| 144 | 151 | stopRequested bool |
| 145 | 152 | logs []string |
| @@ -301,9 +308,13 @@ func (m *Manager) ensureStarted(ctx context.Context, name string) (*agent, error | ||
| 301 | 308 | _ = conn.Close(ctx) |
| 302 | 309 | } |
| 303 | 310 | var conn Conn |
| 311 | + spec := m.specFor(definition) | |
| 304 | 312 | startErr := m.prepare(ctx, a, definition) |
| 305 | 313 | if startErr == nil { |
| 306 | - conn, startErr = m.options.Starter(ctx, specFor(definition), func(line string) { m.log(a, line) }) | |
| 314 | + if m.options.Tools != nil { | |
| 315 | + m.log(a, toolsLine(spec)) | |
| 316 | + } | |
| 317 | + conn, startErr = m.options.Starter(ctx, spec, func(line string) { m.log(a, line) }) | |
| 307 | 318 | } |
| 308 | 319 | |
| 309 | 320 | m.mu.Lock() |
| @@ -320,7 +331,7 @@ func (m *Manager) ensureStarted(ctx context.Context, name string) (*agent, error | ||
| 320 | 331 | go func() { _ = conn.Close(context.Background()) }() |
| 321 | 332 | return nil, fmt.Errorf("agent %s was stopped while starting", a.definition.Name) |
| 322 | 333 | } |
| 323 | - a.conn, a.users, a.outdated = conn, 0, false | |
| 334 | + a.conn, a.users, a.outdated, a.tools = conn, 0, false, toolNames(spec.Tools) | |
| 324 | 335 | a.lastUsed = m.options.Now() |
| 325 | 336 | m.setState(a, StateReady, "") |
| 326 | 337 | m.watchers.Add(1) |
| @@ -527,9 +538,17 @@ func (m *Manager) Run(ctx context.Context) { | ||
| 527 | 538 | } |
| 528 | 539 | |
| 529 | 540 | // Reconfigure applies a new configuration: new agents appear stopped, removed |
| 530 | -// agents are stopped and forgotten, and running agents whose definition | |
| 531 | -// changed keep running but are marked Outdated until restarted. | |
| 541 | +// agents are stopped and forgotten, and running agents whose definition, or | |
| 542 | +// the tools offered to them (agentTools, issue #91), changed keep running | |
| 543 | +// but are marked Outdated until restarted. | |
| 532 | 544 | func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, maxRunning int, idleTimeout time.Duration) { |
| 545 | + // Options.Tools reads the new configuration: outside the lock. | |
| 546 | + tools := map[string][]string{} | |
| 547 | + if m.options.Tools != nil { | |
| 548 | + for _, definition := range definitions { | |
| 549 | + tools[definition.Name] = toolNames(m.options.Tools(definition)) | |
| 550 | + } | |
| 551 | + } | |
| 533 | 552 | m.mu.Lock() |
| 534 | 553 | if maxRunning > 0 { |
| 535 | 554 | m.options.MaxRunning = maxRunning |
| @@ -546,7 +565,8 @@ func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, m | ||
| 546 | 565 | m.emitState(m.agents[definition.Name]) |
| 547 | 566 | continue |
| 548 | 567 | } |
| 549 | - if !reflect.DeepEqual(a.definition, definition) { | |
| 568 | + toolsChanged := m.options.Tools != nil && a.conn != nil && !slices.Equal(a.tools, tools[definition.Name]) | |
| 569 | + if !reflect.DeepEqual(a.definition, definition) || toolsChanged { | |
| 550 | 570 | a.outdated = a.conn != nil |
| 551 | 571 | a.definition = definition |
| 552 | 572 | m.emitState(a) |
| @@ -569,11 +589,41 @@ func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, m | ||
| 569 | 589 | } |
| 570 | 590 | } |
| 571 | 591 | |
| 572 | -func specFor(definition config.Agent) acp.Spec { | |
| 573 | - return acp.Spec{ | |
| 592 | +// toolsLine says in the agent's log which tools Sidekicks offers it, and | |
| 593 | +// how (issue #91): the agent's own log line, when it knows the protocol, | |
| 594 | +// says which ones it took. | |
| 595 | +func toolsLine(spec acp.Spec) string { | |
| 596 | + if len(spec.Tools) == 0 { | |
| 597 | + return "sidekicks: no tool offered (agentTools)" | |
| 598 | + } | |
| 599 | + discovery := spec.ToolDiscovery | |
| 600 | + if discovery == "" { | |
| 601 | + discovery = acp.DiscoveryMeta | |
| 602 | + } | |
| 603 | + return fmt.Sprintf("sidekicks: tools offered (%s): %s", discovery, strings.Join(toolNames(spec.Tools), ", ")) | |
| 604 | +} | |
| 605 | + | |
| 606 | +// toolNames are the names of tools, in order. | |
| 607 | +func toolNames(tools []acp.Tool) []string { | |
| 608 | + names := []string{} | |
| 609 | + for _, tool := range tools { | |
| 610 | + names = append(names, tool.Name) | |
| 611 | + } | |
| 612 | + return names | |
| 613 | +} | |
| 614 | + | |
| 615 | +// specFor is how to start the agent of definition, with the tools offered | |
| 616 | +// to it, the way its file asks for them (ToolDiscovery). | |
| 617 | +func (m *Manager) specFor(definition config.Agent) acp.Spec { | |
| 618 | + spec := acp.Spec{ | |
| 574 | 619 | Name: definition.Name, Command: definition.Command, Args: definition.Args, |
| 575 | - Env: definition.Env, Dir: definition.Workspace, | |
| 620 | + Env: definition.Env, Dir: definition.Workspace, ClientVersion: m.options.ClientVersion, | |
| 621 | + } | |
| 622 | + if m.options.Tools != nil { | |
| 623 | + spec.Tools = m.options.Tools(definition) | |
| 624 | + spec.ToolDiscovery = ToolDiscovery(definition) | |
| 576 | 625 | } |
| 626 | + return spec | |
| 577 | 627 | } |
| 578 | 628 | |
| 579 | 629 | func (m *Manager) log(a *agent, line string) { |
| @@ -20,6 +20,7 @@ import ( | |||
| 20 | "os" | 20 | "os" |
| 21 | "os/exec" | 21 | "os/exec" |
| 22 | "reflect" | 22 | "reflect" |
| 23 | + "slices" | ||
| 23 | "strings" | 24 | "strings" |
| 24 | "sync" | 25 | "sync" |
| 25 | "time" | 26 | "time" |
| @@ -98,6 +99,10 @@ type Options struct { | |||
| 98 | Prepare Preparer | 99 | Prepare Preparer |
| 99 | // Now defaults to time.Now; tests control the clock with it. | 100 | // Now defaults to time.Now; tests control the clock with it. |
| 100 | Now func() time.Time | 101 | Now func() time.Time |
| 102 | + // Tools, when set, gives the tools Sidekicks offers an agent (issue #90). | ||
| 103 | + Tools func(definition config.Agent) []acp.Tool | ||
| 104 | + // ClientVersion is Sidekicks' version, told to the agents. | ||
| 105 | + ClientVersion string | ||
| 101 | } | 106 | } |
| 102 | 107 | ||
| 103 | // Status is the public view of an agent. | 108 | // Status is the public view of an agent. |
| @@ -140,6 +145,8 @@ type agent struct { | |||
| 140 | // starting is closed when the current start attempt ends. | 145 | // starting is closed when the current start attempt ends. |
| 141 | starting chan struct{} | 146 | starting chan struct{} |
| 142 | outdated bool | 147 | outdated bool |
| 148 | + // tools are the names of the tools offered when the agent started. | ||
| 149 | + tools []string | ||
| 143 | // stopRequested: Stop was called while the agent was starting. | 150 | // stopRequested: Stop was called while the agent was starting. |
| 144 | stopRequested bool | 151 | stopRequested bool |
| 145 | logs []string | 152 | logs []string |
| @@ -301,9 +308,13 @@ func (m *Manager) ensureStarted(ctx context.Context, name string) (*agent, error | |||
| 301 | _ = conn.Close(ctx) | 308 | _ = conn.Close(ctx) |
| 302 | } | 309 | } |
| 303 | var conn Conn | 310 | var conn Conn |
| 311 | + spec := m.specFor(definition) | ||
| 304 | startErr := m.prepare(ctx, a, definition) | 312 | startErr := m.prepare(ctx, a, definition) |
| 305 | if startErr == nil { | 313 | if startErr == nil { |
| 306 | - conn, startErr = m.options.Starter(ctx, specFor(definition), func(line string) { m.log(a, line) }) | 314 | + if m.options.Tools != nil { |
| 315 | + m.log(a, toolsLine(spec)) | ||
| 316 | + } | ||
| 317 | + conn, startErr = m.options.Starter(ctx, spec, func(line string) { m.log(a, line) }) | ||
| 307 | } | 318 | } |
| 308 | 319 | ||
| 309 | m.mu.Lock() | 320 | m.mu.Lock() |
| @@ -320,7 +331,7 @@ func (m *Manager) ensureStarted(ctx context.Context, name string) (*agent, error | |||
| 320 | go func() { _ = conn.Close(context.Background()) }() | 331 | go func() { _ = conn.Close(context.Background()) }() |
| 321 | return nil, fmt.Errorf("agent %s was stopped while starting", a.definition.Name) | 332 | return nil, fmt.Errorf("agent %s was stopped while starting", a.definition.Name) |
| 322 | } | 333 | } |
| 323 | - a.conn, a.users, a.outdated = conn, 0, false | 334 | + a.conn, a.users, a.outdated, a.tools = conn, 0, false, toolNames(spec.Tools) |
| 324 | a.lastUsed = m.options.Now() | 335 | a.lastUsed = m.options.Now() |
| 325 | m.setState(a, StateReady, "") | 336 | m.setState(a, StateReady, "") |
| 326 | m.watchers.Add(1) | 337 | m.watchers.Add(1) |
| @@ -527,9 +538,17 @@ func (m *Manager) Run(ctx context.Context) { | |||
| 527 | } | 538 | } |
| 528 | 539 | ||
| 529 | // Reconfigure applies a new configuration: new agents appear stopped, removed | 540 | // Reconfigure applies a new configuration: new agents appear stopped, removed |
| 530 | -// agents are stopped and forgotten, and running agents whose definition | 541 | +// agents are stopped and forgotten, and running agents whose definition, or |
| 531 | -// changed keep running but are marked Outdated until restarted. | 542 | +// the tools offered to them (agentTools, issue #91), changed keep running |
| 543 | +// but are marked Outdated until restarted. | ||
| 532 | func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, maxRunning int, idleTimeout time.Duration) { | 544 | func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, maxRunning int, idleTimeout time.Duration) { |
| 545 | + // Options.Tools reads the new configuration: outside the lock. | ||
| 546 | + tools := map[string][]string{} | ||
| 547 | + if m.options.Tools != nil { | ||
| 548 | + for _, definition := range definitions { | ||
| 549 | + tools[definition.Name] = toolNames(m.options.Tools(definition)) | ||
| 550 | + } | ||
| 551 | + } | ||
| 533 | m.mu.Lock() | 552 | m.mu.Lock() |
| 534 | if maxRunning > 0 { | 553 | if maxRunning > 0 { |
| 535 | m.options.MaxRunning = maxRunning | 554 | m.options.MaxRunning = maxRunning |
| @@ -546,7 +565,8 @@ func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, m | |||
| 546 | m.emitState(m.agents[definition.Name]) | 565 | m.emitState(m.agents[definition.Name]) |
| 547 | continue | 566 | continue |
| 548 | } | 567 | } |
| 549 | - if !reflect.DeepEqual(a.definition, definition) { | 568 | + toolsChanged := m.options.Tools != nil && a.conn != nil && !slices.Equal(a.tools, tools[definition.Name]) |
| 569 | + if !reflect.DeepEqual(a.definition, definition) || toolsChanged { | ||
| 550 | a.outdated = a.conn != nil | 570 | a.outdated = a.conn != nil |
| 551 | a.definition = definition | 571 | a.definition = definition |
| 552 | m.emitState(a) | 572 | m.emitState(a) |
| @@ -569,11 +589,41 @@ func (m *Manager) Reconfigure(ctx context.Context, definitions []config.Agent, m | |||
| 569 | } | 589 | } |
| 570 | } | 590 | } |
| 571 | 591 | ||
| 572 | -func specFor(definition config.Agent) acp.Spec { | 592 | +// toolsLine says in the agent's log which tools Sidekicks offers it, and |
| 573 | - return acp.Spec{ | 593 | +// how (issue #91): the agent's own log line, when it knows the protocol, |
| 594 | +// says which ones it took. | ||
| 595 | +func toolsLine(spec acp.Spec) string { | ||
| 596 | + if len(spec.Tools) == 0 { | ||
| 597 | + return "sidekicks: no tool offered (agentTools)" | ||
| 598 | + } | ||
| 599 | + discovery := spec.ToolDiscovery | ||
| 600 | + if discovery == "" { | ||
| 601 | + discovery = acp.DiscoveryMeta | ||
| 602 | + } | ||
| 603 | + return fmt.Sprintf("sidekicks: tools offered (%s): %s", discovery, strings.Join(toolNames(spec.Tools), ", ")) | ||
| 604 | +} | ||
| 605 | + | ||
| 606 | +// toolNames are the names of tools, in order. | ||
| 607 | +func toolNames(tools []acp.Tool) []string { | ||
| 608 | + names := []string{} | ||
| 609 | + for _, tool := range tools { | ||
| 610 | + names = append(names, tool.Name) | ||
| 611 | + } | ||
| 612 | + return names | ||
| 613 | +} | ||
| 614 | + | ||
| 615 | +// specFor is how to start the agent of definition, with the tools offered | ||
| 616 | +// to it, the way its file asks for them (ToolDiscovery). | ||
| 617 | +func (m *Manager) specFor(definition config.Agent) acp.Spec { | ||
| 618 | + spec := acp.Spec{ | ||
| 574 | Name: definition.Name, Command: definition.Command, Args: definition.Args, | 619 | Name: definition.Name, Command: definition.Command, Args: definition.Args, |
| 575 | - Env: definition.Env, Dir: definition.Workspace, | 620 | + Env: definition.Env, Dir: definition.Workspace, ClientVersion: m.options.ClientVersion, |
| 621 | + } | ||
| 622 | + if m.options.Tools != nil { | ||
| 623 | + spec.Tools = m.options.Tools(definition) | ||
| 624 | + spec.ToolDiscovery = ToolDiscovery(definition) | ||
| 576 | } | 625 | } |
| 626 | + return spec | ||
| 577 | } | 627 | } |
| 578 | 628 | ||
| 579 | func (m *Manager) log(a *agent, line string) { | 629 | func (m *Manager) log(a *agent, line string) { |
modified
internal/agents/manager_test.go +27 -0 | @@ -461,6 +461,33 @@ func TestReconfigure(t *testing.T) { | ||
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | +func TestChangingTheToolsOfferedMakesARunningAgentOutdated(t *testing.T) { | |
| 465 | + offered := []acp.Tool{{Name: "memory_pressure", Method: "_m"}} | |
| 466 | + f := &fixture{starter: newFakeStarter(), recorder: &events.Recorder{}, clock: &clock{now: time.Now()}} | |
| 467 | + f.manager = agents.NewManager(definitions("alice", "bob"), agents.Options{ | |
| 468 | + MaxRunning: maxRunning, Emitter: f.recorder, Starter: f.starter.start, Now: f.clock.Now, | |
| 469 | + Tools: func(config.Agent) []acp.Tool { return offered }, | |
| 470 | + }) | |
| 471 | + _ = f.manager.Start(ctx, "alice") | |
| 472 | + if logs, _ := f.manager.Logs("alice"); len(logs) == 0 || logs[0] != "sidekicks: tools offered (meta): memory_pressure" { | |
| 473 | + t.Fatalf("the log says which tools are offered: %q", logs) | |
| 474 | + } | |
| 475 | + f.manager.Reconfigure(ctx, definitions("alice", "bob"), maxRunning, 0) | |
| 476 | + if f.manager.Statuses()[0].Outdated { | |
| 477 | + t.Fatal("the same tools: nothing to restart") | |
| 478 | + } | |
| 479 | + offered = append(offered, acp.Tool{Name: "search_messages", Method: "_s"}) | |
| 480 | + f.manager.Reconfigure(ctx, definitions("alice", "bob"), maxRunning, 0) | |
| 481 | + statuses := f.manager.Statuses() | |
| 482 | + if !statuses[0].Outdated || statuses[1].Outdated { | |
| 483 | + t.Fatalf("alice runs with the old tools, bob is stopped: %+v", statuses) | |
| 484 | + } | |
| 485 | + _ = f.manager.Restart(ctx, "alice") | |
| 486 | + if f.manager.Statuses()[0].Outdated { | |
| 487 | + t.Fatal("a restart offers the new tools") | |
| 488 | + } | |
| 489 | +} | |
| 490 | + | |
| 464 | 491 | func ExampleManager_Acquire() { |
| 465 | 492 | manager := agents.NewManager(definitions("alice"), agents.Options{ |
| 466 | 493 | Starter: func(context.Context, acp.Spec, func(string)) (agents.Conn, error) { return newFakeConn("alice"), nil }, |
| @@ -461,6 +461,33 @@ func TestReconfigure(t *testing.T) { | |||
| 461 | } | 461 | } |
| 462 | } | 462 | } |
| 463 | 463 | ||
| 464 | +func TestChangingTheToolsOfferedMakesARunningAgentOutdated(t *testing.T) { | ||
| 465 | + offered := []acp.Tool{{Name: "memory_pressure", Method: "_m"}} | ||
| 466 | + f := &fixture{starter: newFakeStarter(), recorder: &events.Recorder{}, clock: &clock{now: time.Now()}} | ||
| 467 | + f.manager = agents.NewManager(definitions("alice", "bob"), agents.Options{ | ||
| 468 | + MaxRunning: maxRunning, Emitter: f.recorder, Starter: f.starter.start, Now: f.clock.Now, | ||
| 469 | + Tools: func(config.Agent) []acp.Tool { return offered }, | ||
| 470 | + }) | ||
| 471 | + _ = f.manager.Start(ctx, "alice") | ||
| 472 | + if logs, _ := f.manager.Logs("alice"); len(logs) == 0 || logs[0] != "sidekicks: tools offered (meta): memory_pressure" { | ||
| 473 | + t.Fatalf("the log says which tools are offered: %q", logs) | ||
| 474 | + } | ||
| 475 | + f.manager.Reconfigure(ctx, definitions("alice", "bob"), maxRunning, 0) | ||
| 476 | + if f.manager.Statuses()[0].Outdated { | ||
| 477 | + t.Fatal("the same tools: nothing to restart") | ||
| 478 | + } | ||
| 479 | + offered = append(offered, acp.Tool{Name: "search_messages", Method: "_s"}) | ||
| 480 | + f.manager.Reconfigure(ctx, definitions("alice", "bob"), maxRunning, 0) | ||
| 481 | + statuses := f.manager.Statuses() | ||
| 482 | + if !statuses[0].Outdated || statuses[1].Outdated { | ||
| 483 | + t.Fatalf("alice runs with the old tools, bob is stopped: %+v", statuses) | ||
| 484 | + } | ||
| 485 | + _ = f.manager.Restart(ctx, "alice") | ||
| 486 | + if f.manager.Statuses()[0].Outdated { | ||
| 487 | + t.Fatal("a restart offers the new tools") | ||
| 488 | + } | ||
| 489 | +} | ||
| 490 | + | ||
| 464 | func ExampleManager_Acquire() { | 491 | func ExampleManager_Acquire() { |
| 465 | manager := agents.NewManager(definitions("alice"), agents.Options{ | 492 | manager := agents.NewManager(definitions("alice"), agents.Options{ |
| 466 | Starter: func(context.Context, acp.Spec, func(string)) (agents.Conn, error) { return newFakeConn("alice"), nil }, | 493 | Starter: func(context.Context, acp.Spec, func(string)) (agents.Conn, error) { return newFakeConn("alice"), nil }, |
modified
internal/app/app.go +4 -0 | @@ -55,6 +55,9 @@ type Options struct { | ||
| 55 | 55 | // Sbx is the sbx command used to list, create, stop and remove the |
| 56 | 56 | // agents' sandboxes; "" looks it up. Tests pass a fake. |
| 57 | 57 | Sbx string |
| 58 | + // Version is Sidekicks' version (info.version of build/config.yml), told | |
| 59 | + // to the agents; "" for a development build. | |
| 60 | + Version string | |
| 58 | 61 | // OpenStore opens the history of the configuration file at path; nil |
| 59 | 62 | // opens it in the user's configuration folder (store.DirFor). |
| 60 | 63 | OpenStore func(configPath string) (*store.Store, error) |
| @@ -97,6 +100,7 @@ func New(location config.Location, options Options) *Core { | ||
| 97 | 100 | core.manager = agents.NewManager(cfg.Agents, agents.Options{ |
| 98 | 101 | MaxRunning: cfg.Limits.MaxRunningAgents, IdleTimeout: cfg.Limits.StopIdleAgentsAfter, |
| 99 | 102 | Emitter: options.Emitter, Starter: options.Starter, Prepare: core.sandboxes.Ensure, |
| 103 | + Tools: core.clientTools, ClientVersion: options.Version, | |
| 100 | 104 | }) |
| 101 | 105 | core.workspaces = newWorkspaces(options.Emitter) |
| 102 | 106 | core.workspaces.options.Sbx = options.Sbx |
| @@ -55,6 +55,9 @@ type Options struct { | |||
| 55 | // Sbx is the sbx command used to list, create, stop and remove the | 55 | // Sbx is the sbx command used to list, create, stop and remove the |
| 56 | // agents' sandboxes; "" looks it up. Tests pass a fake. | 56 | // agents' sandboxes; "" looks it up. Tests pass a fake. |
| 57 | Sbx string | 57 | Sbx string |
| 58 | + // Version is Sidekicks' version (info.version of build/config.yml), told | ||
| 59 | + // to the agents; "" for a development build. | ||
| 60 | + Version string | ||
| 58 | // OpenStore opens the history of the configuration file at path; nil | 61 | // OpenStore opens the history of the configuration file at path; nil |
| 59 | // opens it in the user's configuration folder (store.DirFor). | 62 | // opens it in the user's configuration folder (store.DirFor). |
| 60 | OpenStore func(configPath string) (*store.Store, error) | 63 | OpenStore func(configPath string) (*store.Store, error) |
| @@ -97,6 +100,7 @@ func New(location config.Location, options Options) *Core { | |||
| 97 | core.manager = agents.NewManager(cfg.Agents, agents.Options{ | 100 | core.manager = agents.NewManager(cfg.Agents, agents.Options{ |
| 98 | MaxRunning: cfg.Limits.MaxRunningAgents, IdleTimeout: cfg.Limits.StopIdleAgentsAfter, | 101 | MaxRunning: cfg.Limits.MaxRunningAgents, IdleTimeout: cfg.Limits.StopIdleAgentsAfter, |
| 99 | Emitter: options.Emitter, Starter: options.Starter, Prepare: core.sandboxes.Ensure, | 102 | Emitter: options.Emitter, Starter: options.Starter, Prepare: core.sandboxes.Ensure, |
| 103 | + Tools: core.clientTools, ClientVersion: options.Version, | ||
| 100 | }) | 104 | }) |
| 101 | core.workspaces = newWorkspaces(options.Emitter) | 105 | core.workspaces = newWorkspaces(options.Emitter) |
| 102 | core.workspaces.options.Sbx = options.Sbx | 106 | core.workspaces.options.Sbx = options.Sbx |
added
internal/app/clienttools.go +171 -0 | new file mode 100644 | ||
| @@ -0,0 +1,171 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package app | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "context" | |
| 7 | + "errors" | |
| 8 | + "fmt" | |
| 9 | + "runtime" | |
| 10 | + "strings" | |
| 11 | + | |
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | |
| 13 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | |
| 14 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | |
| 15 | + "git.rickub.com/bots-garden/sidekicks/internal/memory" | |
| 16 | + "go.yaml.in/yaml/v3" | |
| 17 | +) | |
| 18 | + | |
| 19 | +// The tools Sidekicks offers every agent (issues #90 and #91), as | |
| 20 | +// agentTools in the configuration allows. An agent that knows the protocol | |
| 21 | +// of mini-me (acp.clientTools in its file) gives them to its model as | |
| 22 | +// client_<name>; the others ignore them. | |
| 23 | + | |
| 24 | +// ReleasesURL is where Sidekicks is published. | |
| 25 | +const ReleasesURL = "https://rickub.com/bots-garden/sidekicks/releases" | |
| 26 | + | |
| 27 | +// The methods of the tools, under Sidekicks' reverse domain name. | |
| 28 | +const ( | |
| 29 | + MemoryMethod = "_com.rickub.sidekicks/system/memory" | |
| 30 | + AboutMethod = "_com.rickub.sidekicks/about" | |
| 31 | + ChannelMethod = "_com.rickub.sidekicks/channel/current" | |
| 32 | +) | |
| 33 | + | |
| 34 | +// clientTools are the tools offered to the agent of definition: the ones | |
| 35 | +// agentTools of the current configuration offers, read when it starts. | |
| 36 | +func (c *Core) clientTools(definition config.Agent) []acp.Tool { | |
| 37 | + c.mu.Lock() | |
| 38 | + settings := config.AgentTools{Enabled: true} | |
| 39 | + if c.cfg != nil { | |
| 40 | + settings = c.cfg.AgentTools | |
| 41 | + } | |
| 42 | + c.mu.Unlock() | |
| 43 | + var offered []acp.Tool | |
| 44 | + for _, tool := range append(c.systemTools(definition.Name), c.historyTools(definition.Name)...) { | |
| 45 | + if settings.Offers(tool.Name) { | |
| 46 | + offered = append(offered, tool) | |
| 47 | + } | |
| 48 | + } | |
| 49 | + return offered | |
| 50 | +} | |
| 51 | + | |
| 52 | +// channelManager is the channels' manager, nil before it is open. | |
| 53 | +func (c *Core) channelManager() (*channels.Manager, error) { | |
| 54 | + c.mu.Lock() | |
| 55 | + defer c.mu.Unlock() | |
| 56 | + if c.channels == nil { | |
| 57 | + return nil, errors.New("no channel is open in Sidekicks") | |
| 58 | + } | |
| 59 | + return c.channels, nil | |
| 60 | +} | |
| 61 | + | |
| 62 | +// systemTools tell about the computer, Sidekicks and the current channel (issue #90). | |
| 63 | +func (c *Core) systemTools(agent string) []acp.Tool { | |
| 64 | + return []acp.Tool{ | |
| 65 | + { | |
| 66 | + Name: "memory_pressure", | |
| 67 | + Description: "Tell how much the memory of the user's computer is under pressure (normal, warning or critical) and how much is used. Call it before a heavy task, or when the user asks about memory or slowness. The memory changes from moment to moment: call it again each time, never reuse an earlier result.", | |
| 68 | + Method: MemoryMethod, | |
| 69 | + Call: func(context.Context, string, map[string]any) (string, error) { | |
| 70 | + status, err := memory.Read() | |
| 71 | + if err != nil { | |
| 72 | + return "", err | |
| 73 | + } | |
| 74 | + return MemoryText(status), nil | |
| 75 | + }, | |
| 76 | + }, | |
| 77 | + { | |
| 78 | + Name: "about_sidekicks", | |
| 79 | + Description: "Tell what Sidekicks is: the application the user talks to you through, its version and the computer it runs on. Call it when the user asks about Sidekicks or about where you run.", | |
| 80 | + Method: AboutMethod, | |
| 81 | + Call: func(context.Context, string, map[string]any) (string, error) { | |
| 82 | + return AboutText(c.options.Version, runtime.GOOS, runtime.GOARCH, agent), nil | |
| 83 | + }, | |
| 84 | + }, | |
| 85 | + { | |
| 86 | + Name: "current_channel", | |
| 87 | + Description: "Tell which Sidekicks channel this conversation is in: its name, its description and its members, or that it is a direct conversation with you. Call it when the user mentions the channel, or to know who else is there.", | |
| 88 | + Method: ChannelMethod, | |
| 89 | + Call: func(_ context.Context, sessionID string, _ map[string]any) (string, error) { | |
| 90 | + manager, err := c.channelManager() | |
| 91 | + if err != nil { | |
| 92 | + return "", err | |
| 93 | + } | |
| 94 | + channel, ok := manager.SessionChannel(agent, sessionID) | |
| 95 | + if !ok { | |
| 96 | + return "", errors.New("this session belongs to no Sidekicks channel") | |
| 97 | + } | |
| 98 | + return ChannelText(channel, agent), nil | |
| 99 | + }, | |
| 100 | + }, | |
| 101 | + } | |
| 102 | +} | |
| 103 | + | |
| 104 | +// MemoryText tells status to a model. | |
| 105 | +// | |
| 106 | +// MemoryText(memory.Status{Level: memory.Warning, Used: 24 << 30, Total: 32 << 30}) | |
| 107 | +// // "Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %)." | |
| 108 | +func MemoryText(status memory.Status) string { | |
| 109 | + if status.Total == 0 { | |
| 110 | + return "The memory cannot be measured on this computer." | |
| 111 | + } | |
| 112 | + colours := map[memory.Level]string{memory.Normal: "green", memory.Warning: "yellow", memory.Critical: "red"} | |
| 113 | + text := fmt.Sprintf("Memory pressure: %s", status.Level) | |
| 114 | + if colour, ok := colours[status.Level]; ok { | |
| 115 | + text += " (" + colour + ")" | |
| 116 | + } | |
| 117 | + return fmt.Sprintf("%s. Used: %s of %s (%d %%).", text, gigabytes(status.Used), gigabytes(status.Total), status.Used*100/status.Total) | |
| 118 | +} | |
| 119 | + | |
| 120 | +func gigabytes(bytes uint64) string { | |
| 121 | + return fmt.Sprintf("%.1f GB", float64(bytes)/(1<<30)) | |
| 122 | +} | |
| 123 | + | |
| 124 | +// AboutText tells a model what Sidekicks is; agent is the one asking. | |
| 125 | +func AboutText(version, system, architecture, agent string) string { | |
| 126 | + if version == "" { | |
| 127 | + version = "dev" | |
| 128 | + } | |
| 129 | + return strings.Join([]string{ | |
| 130 | + fmt.Sprintf("Sidekicks %s, on %s/%s.", version, system, architecture), | |
| 131 | + "Sidekicks is a desktop application to converse with AI agents, alone or several together in channels, with the Agent Client Protocol (ACP).", | |
| 132 | + fmt.Sprintf("You are the agent %q in it: the user writes to you in a channel or a direct conversation, and mentions you with @%s.", agent, agent), | |
| 133 | + "Releases: " + ReleasesURL, | |
| 134 | + }, "\n") | |
| 135 | +} | |
| 136 | + | |
| 137 | +// ChannelText tells a model where it is talking: channel, seen by agent. | |
| 138 | +func ChannelText(channel channels.Channel, agent string) string { | |
| 139 | + if channel.Direct != "" { | |
| 140 | + return fmt.Sprintf("A direct conversation between the user and you (%s): no other agent reads it.", channel.Direct) | |
| 141 | + } | |
| 142 | + text := "Channel #" + channel.Name + "." | |
| 143 | + if channel.Description != "" { | |
| 144 | + text += "\nDescription: " + channel.Description | |
| 145 | + } | |
| 146 | + var others []string | |
| 147 | + for _, member := range channel.Members { | |
| 148 | + if member != agent { | |
| 149 | + others = append(others, "@"+member) | |
| 150 | + } | |
| 151 | + } | |
| 152 | + text += "\nMembers: you (@" + agent + ")" | |
| 153 | + if len(others) > 0 { | |
| 154 | + text += ", " + strings.Join(others, ", ") | |
| 155 | + } | |
| 156 | + return text + ", and the user." | |
| 157 | +} | |
| 158 | + | |
| 159 | +// VersionOf reads info.version in the content of build/config.yml; "" when | |
| 160 | +// it has none. | |
| 161 | +func VersionOf(buildConfig []byte) string { | |
| 162 | + var file struct { | |
| 163 | + Info struct { | |
| 164 | + Version string `yaml:"version"` | |
| 165 | + } `yaml:"info"` | |
| 166 | + } | |
| 167 | + if yaml.Unmarshal(buildConfig, &file) != nil { | |
| 168 | + return "" | |
| 169 | + } | |
| 170 | + return file.Info.Version | |
| 171 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package app | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "context" | ||
| 7 | + "errors" | ||
| 8 | + "fmt" | ||
| 9 | + "runtime" | ||
| 10 | + "strings" | ||
| 11 | + | ||
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | ||
| 13 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | ||
| 14 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | ||
| 15 | + "git.rickub.com/bots-garden/sidekicks/internal/memory" | ||
| 16 | + "go.yaml.in/yaml/v3" | ||
| 17 | +) | ||
| 18 | + | ||
| 19 | +// The tools Sidekicks offers every agent (issues #90 and #91), as | ||
| 20 | +// agentTools in the configuration allows. An agent that knows the protocol | ||
| 21 | +// of mini-me (acp.clientTools in its file) gives them to its model as | ||
| 22 | +// client_<name>; the others ignore them. | ||
| 23 | + | ||
| 24 | +// ReleasesURL is where Sidekicks is published. | ||
| 25 | +const ReleasesURL = "https://rickub.com/bots-garden/sidekicks/releases" | ||
| 26 | + | ||
| 27 | +// The methods of the tools, under Sidekicks' reverse domain name. | ||
| 28 | +const ( | ||
| 29 | + MemoryMethod = "_com.rickub.sidekicks/system/memory" | ||
| 30 | + AboutMethod = "_com.rickub.sidekicks/about" | ||
| 31 | + ChannelMethod = "_com.rickub.sidekicks/channel/current" | ||
| 32 | +) | ||
| 33 | + | ||
| 34 | +// clientTools are the tools offered to the agent of definition: the ones | ||
| 35 | +// agentTools of the current configuration offers, read when it starts. | ||
| 36 | +func (c *Core) clientTools(definition config.Agent) []acp.Tool { | ||
| 37 | + c.mu.Lock() | ||
| 38 | + settings := config.AgentTools{Enabled: true} | ||
| 39 | + if c.cfg != nil { | ||
| 40 | + settings = c.cfg.AgentTools | ||
| 41 | + } | ||
| 42 | + c.mu.Unlock() | ||
| 43 | + var offered []acp.Tool | ||
| 44 | + for _, tool := range append(c.systemTools(definition.Name), c.historyTools(definition.Name)...) { | ||
| 45 | + if settings.Offers(tool.Name) { | ||
| 46 | + offered = append(offered, tool) | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + return offered | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +// channelManager is the channels' manager, nil before it is open. | ||
| 53 | +func (c *Core) channelManager() (*channels.Manager, error) { | ||
| 54 | + c.mu.Lock() | ||
| 55 | + defer c.mu.Unlock() | ||
| 56 | + if c.channels == nil { | ||
| 57 | + return nil, errors.New("no channel is open in Sidekicks") | ||
| 58 | + } | ||
| 59 | + return c.channels, nil | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +// systemTools tell about the computer, Sidekicks and the current channel (issue #90). | ||
| 63 | +func (c *Core) systemTools(agent string) []acp.Tool { | ||
| 64 | + return []acp.Tool{ | ||
| 65 | + { | ||
| 66 | + Name: "memory_pressure", | ||
| 67 | + Description: "Tell how much the memory of the user's computer is under pressure (normal, warning or critical) and how much is used. Call it before a heavy task, or when the user asks about memory or slowness. The memory changes from moment to moment: call it again each time, never reuse an earlier result.", | ||
| 68 | + Method: MemoryMethod, | ||
| 69 | + Call: func(context.Context, string, map[string]any) (string, error) { | ||
| 70 | + status, err := memory.Read() | ||
| 71 | + if err != nil { | ||
| 72 | + return "", err | ||
| 73 | + } | ||
| 74 | + return MemoryText(status), nil | ||
| 75 | + }, | ||
| 76 | + }, | ||
| 77 | + { | ||
| 78 | + Name: "about_sidekicks", | ||
| 79 | + Description: "Tell what Sidekicks is: the application the user talks to you through, its version and the computer it runs on. Call it when the user asks about Sidekicks or about where you run.", | ||
| 80 | + Method: AboutMethod, | ||
| 81 | + Call: func(context.Context, string, map[string]any) (string, error) { | ||
| 82 | + return AboutText(c.options.Version, runtime.GOOS, runtime.GOARCH, agent), nil | ||
| 83 | + }, | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + Name: "current_channel", | ||
| 87 | + Description: "Tell which Sidekicks channel this conversation is in: its name, its description and its members, or that it is a direct conversation with you. Call it when the user mentions the channel, or to know who else is there.", | ||
| 88 | + Method: ChannelMethod, | ||
| 89 | + Call: func(_ context.Context, sessionID string, _ map[string]any) (string, error) { | ||
| 90 | + manager, err := c.channelManager() | ||
| 91 | + if err != nil { | ||
| 92 | + return "", err | ||
| 93 | + } | ||
| 94 | + channel, ok := manager.SessionChannel(agent, sessionID) | ||
| 95 | + if !ok { | ||
| 96 | + return "", errors.New("this session belongs to no Sidekicks channel") | ||
| 97 | + } | ||
| 98 | + return ChannelText(channel, agent), nil | ||
| 99 | + }, | ||
| 100 | + }, | ||
| 101 | + } | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +// MemoryText tells status to a model. | ||
| 105 | +// | ||
| 106 | +// MemoryText(memory.Status{Level: memory.Warning, Used: 24 << 30, Total: 32 << 30}) | ||
| 107 | +// // "Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %)." | ||
| 108 | +func MemoryText(status memory.Status) string { | ||
| 109 | + if status.Total == 0 { | ||
| 110 | + return "The memory cannot be measured on this computer." | ||
| 111 | + } | ||
| 112 | + colours := map[memory.Level]string{memory.Normal: "green", memory.Warning: "yellow", memory.Critical: "red"} | ||
| 113 | + text := fmt.Sprintf("Memory pressure: %s", status.Level) | ||
| 114 | + if colour, ok := colours[status.Level]; ok { | ||
| 115 | + text += " (" + colour + ")" | ||
| 116 | + } | ||
| 117 | + return fmt.Sprintf("%s. Used: %s of %s (%d %%).", text, gigabytes(status.Used), gigabytes(status.Total), status.Used*100/status.Total) | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +func gigabytes(bytes uint64) string { | ||
| 121 | + return fmt.Sprintf("%.1f GB", float64(bytes)/(1<<30)) | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +// AboutText tells a model what Sidekicks is; agent is the one asking. | ||
| 125 | +func AboutText(version, system, architecture, agent string) string { | ||
| 126 | + if version == "" { | ||
| 127 | + version = "dev" | ||
| 128 | + } | ||
| 129 | + return strings.Join([]string{ | ||
| 130 | + fmt.Sprintf("Sidekicks %s, on %s/%s.", version, system, architecture), | ||
| 131 | + "Sidekicks is a desktop application to converse with AI agents, alone or several together in channels, with the Agent Client Protocol (ACP).", | ||
| 132 | + fmt.Sprintf("You are the agent %q in it: the user writes to you in a channel or a direct conversation, and mentions you with @%s.", agent, agent), | ||
| 133 | + "Releases: " + ReleasesURL, | ||
| 134 | + }, "\n") | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +// ChannelText tells a model where it is talking: channel, seen by agent. | ||
| 138 | +func ChannelText(channel channels.Channel, agent string) string { | ||
| 139 | + if channel.Direct != "" { | ||
| 140 | + return fmt.Sprintf("A direct conversation between the user and you (%s): no other agent reads it.", channel.Direct) | ||
| 141 | + } | ||
| 142 | + text := "Channel #" + channel.Name + "." | ||
| 143 | + if channel.Description != "" { | ||
| 144 | + text += "\nDescription: " + channel.Description | ||
| 145 | + } | ||
| 146 | + var others []string | ||
| 147 | + for _, member := range channel.Members { | ||
| 148 | + if member != agent { | ||
| 149 | + others = append(others, "@"+member) | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + text += "\nMembers: you (@" + agent + ")" | ||
| 153 | + if len(others) > 0 { | ||
| 154 | + text += ", " + strings.Join(others, ", ") | ||
| 155 | + } | ||
| 156 | + return text + ", and the user." | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +// VersionOf reads info.version in the content of build/config.yml; "" when | ||
| 160 | +// it has none. | ||
| 161 | +func VersionOf(buildConfig []byte) string { | ||
| 162 | + var file struct { | ||
| 163 | + Info struct { | ||
| 164 | + Version string `yaml:"version"` | ||
| 165 | + } `yaml:"info"` | ||
| 166 | + } | ||
| 167 | + if yaml.Unmarshal(buildConfig, &file) != nil { | ||
| 168 | + return "" | ||
| 169 | + } | ||
| 170 | + return file.Info.Version | ||
| 171 | +} | ||
added
internal/app/clienttools_test.go +170 -0 | new file mode 100644 | ||
| @@ -0,0 +1,170 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package app_test | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "context" | |
| 7 | + "os" | |
| 8 | + "path/filepath" | |
| 9 | + "strings" | |
| 10 | + "sync" | |
| 11 | + "testing" | |
| 12 | + "time" | |
| 13 | + | |
| 14 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | |
| 15 | + "git.rickub.com/bots-garden/sidekicks/internal/agents" | |
| 16 | + "git.rickub.com/bots-garden/sidekicks/internal/app" | |
| 17 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | |
| 18 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | |
| 19 | + "git.rickub.com/bots-garden/sidekicks/internal/memory" | |
| 20 | +) | |
| 21 | + | |
| 22 | +// Issue #90: the tools Sidekicks offers the agents. | |
| 23 | + | |
| 24 | +// offeredTools has riker answer in #general, with settings (YAML) in the | |
| 25 | +// configuration, and returns how it was started. | |
| 26 | +func offeredTools(t *testing.T, settings string) acp.Spec { | |
| 27 | + t.Helper() | |
| 28 | + directory := t.TempDir() | |
| 29 | + path := filepath.Join(directory, "config.yaml") | |
| 30 | + write(t, path, "version: 1\n"+settings+"agents:\n - name: riker\n command: mm\n args: [--acp, --config, agent.yaml]\n workspace: riker\n") | |
| 31 | + var mu sync.Mutex | |
| 32 | + var spec acp.Spec | |
| 33 | + start := func(_ context.Context, started acp.Spec, _ func(string)) (agents.Conn, error) { | |
| 34 | + mu.Lock() | |
| 35 | + spec = started | |
| 36 | + mu.Unlock() | |
| 37 | + return &conn{done: make(chan struct{})}, nil | |
| 38 | + } | |
| 39 | + core := app.New(config.Location{Path: path, Source: config.SourceFlag}, app.Options{Starter: start, Version: "1.4.0"}) | |
| 40 | + t.Cleanup(func() { core.Shutdown(context.Background()) }) | |
| 41 | + service := &app.ChannelService{Core: core} | |
| 42 | + general, err := service.Create("general", "the bridge") | |
| 43 | + if err != nil { | |
| 44 | + t.Fatal(err) | |
| 45 | + } | |
| 46 | + if _, err := service.Send(general.ID, "@riker hi"); err != nil { | |
| 47 | + t.Fatal(err) | |
| 48 | + } | |
| 49 | + deadline := time.Now().Add(3 * time.Second) | |
| 50 | + for { | |
| 51 | + view, _ := service.Conversation(general.ID) | |
| 52 | + if !view.Busy && len(view.Messages) >= 2 { | |
| 53 | + break | |
| 54 | + } | |
| 55 | + if time.Now().After(deadline) { | |
| 56 | + t.Fatal("riker never answered") | |
| 57 | + } | |
| 58 | + time.Sleep(10 * time.Millisecond) | |
| 59 | + } | |
| 60 | + mu.Lock() | |
| 61 | + defer mu.Unlock() | |
| 62 | + return spec | |
| 63 | +} | |
| 64 | + | |
| 65 | +func TestTheAgentsAreOfferedSidekicksTools(t *testing.T) { | |
| 66 | + spec := offeredTools(t, "") | |
| 67 | + if spec.ClientVersion != "1.4.0" || spec.ToolDiscovery != acp.DiscoveryMeta || len(spec.Tools) != 6 { | |
| 68 | + t.Fatalf("spec: version %q, discovery %q, %d tools", spec.ClientVersion, spec.ToolDiscovery, len(spec.Tools)) | |
| 69 | + } | |
| 70 | + for _, tool := range spec.Tools { | |
| 71 | + if !strings.HasPrefix(tool.Method, "_com.rickub.sidekicks/") || tool.Description == "" { | |
| 72 | + t.Fatalf("tool %+v", tool) | |
| 73 | + } | |
| 74 | + } | |
| 75 | +} | |
| 76 | + | |
| 77 | +func TestTheToolsAnswerForTheCallersSession(t *testing.T) { | |
| 78 | + tools := map[string]acp.Tool{} | |
| 79 | + for _, tool := range offeredTools(t, "").Tools { | |
| 80 | + tools[tool.Name] = tool | |
| 81 | + } | |
| 82 | + text, err := tools["current_channel"].Call(context.Background(), "s-1", nil) | |
| 83 | + if err != nil || !strings.Contains(text, "Channel #general.") || !strings.Contains(text, "Description: the bridge") || !strings.Contains(text, "you (@riker)") { | |
| 84 | + t.Fatalf("current_channel: %q %v", text, err) | |
| 85 | + } | |
| 86 | + if _, err := tools["current_channel"].Call(context.Background(), "s-unknown", nil); err == nil { | |
| 87 | + t.Fatal("an unknown session is an error") | |
| 88 | + } | |
| 89 | + if text, _ := tools["about_sidekicks"].Call(context.Background(), "s-1", nil); !strings.HasPrefix(text, "Sidekicks 1.4.0, on ") || !strings.Contains(text, `"riker"`) { | |
| 90 | + t.Fatalf("about_sidekicks: %q", text) | |
| 91 | + } | |
| 92 | + if text, err := tools["memory_pressure"].Call(context.Background(), "", nil); err == nil && !strings.HasPrefix(text, "Memory pressure: ") { | |
| 93 | + t.Fatalf("memory_pressure: %q", text) | |
| 94 | + } | |
| 95 | +} | |
| 96 | + | |
| 97 | +func TestToolTexts(t *testing.T) { | |
| 98 | + if got := app.MemoryText(memory.Status{Level: memory.Warning, Used: 24 << 30, Total: 32 << 30}); got != "Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %)." { | |
| 99 | + t.Fatalf("memory: %q", got) | |
| 100 | + } | |
| 101 | + if got := app.MemoryText(memory.Status{}); got != "The memory cannot be measured on this computer." { | |
| 102 | + t.Fatalf("no memory: %q", got) | |
| 103 | + } | |
| 104 | + if got := app.ChannelText(channels.Channel{Direct: "riker"}, "riker"); !strings.HasPrefix(got, "A direct conversation between the user and you (riker)") { | |
| 105 | + t.Fatalf("direct: %q", got) | |
| 106 | + } | |
| 107 | + if got := app.ChannelText(channels.Channel{Name: "general", Members: []string{"riker", "data"}}, "riker"); got != "Channel #general.\nMembers: you (@riker), @data, and the user." { | |
| 108 | + t.Fatalf("channel: %q", got) | |
| 109 | + } | |
| 110 | + if got := app.AboutText("", "darwin", "arm64", "riker"); !strings.HasPrefix(got, "Sidekicks dev, on darwin/arm64.") || !strings.Contains(got, app.ReleasesURL) { | |
| 111 | + t.Fatalf("about: %q", got) | |
| 112 | + } | |
| 113 | + if got := app.VersionOf([]byte("info:\n productName: \"Sidekicks\"\n version: \"1.3.0\" # The application version\n")); got != "1.3.0" { | |
| 114 | + t.Fatalf("version: %q", got) | |
| 115 | + } | |
| 116 | + data, err := os.ReadFile("../../build/config.yml") | |
| 117 | + if err != nil || app.VersionOf(data) == "" { | |
| 118 | + t.Fatalf("the version of build/config.yml: %v", err) | |
| 119 | + } | |
| 120 | +} | |
| 121 | + | |
| 122 | +// Issue #91: the history tools, and agentTools. | |
| 123 | + | |
| 124 | +func toolsOf(spec acp.Spec) map[string]acp.Tool { | |
| 125 | + tools := map[string]acp.Tool{} | |
| 126 | + for _, tool := range spec.Tools { | |
| 127 | + tools[tool.Name] = tool | |
| 128 | + } | |
| 129 | + return tools | |
| 130 | +} | |
| 131 | + | |
| 132 | +func TestAgentToolsChoosesTheToolsOffered(t *testing.T) { | |
| 133 | + if spec := offeredTools(t, "agentTools:\n enabled: false\n"); len(spec.Tools) != 0 { | |
| 134 | + t.Fatalf("disabled: %d tools", len(spec.Tools)) | |
| 135 | + } | |
| 136 | + spec := offeredTools(t, "agentTools:\n offer: [memory_pressure, list_agents]\n") | |
| 137 | + if tools := toolsOf(spec); len(tools) != 2 || tools["memory_pressure"].Call == nil || tools["list_agents"].Call == nil { | |
| 138 | + t.Fatalf("filtered: %+v", spec.Tools) | |
| 139 | + } | |
| 140 | +} | |
| 141 | + | |
| 142 | +func TestTheHistoryToolsReadEveryChannel(t *testing.T) { | |
| 143 | + tools := toolsOf(offeredTools(t, "")) | |
| 144 | + text, err := tools["list_channels"].Call(context.Background(), "s-1", nil) | |
| 145 | + if err != nil || !strings.Contains(text, "- #general: the bridge. Members: @riker (you). 2 messages, the last on ") { | |
| 146 | + t.Fatalf("list_channels: %q %v", text, err) | |
| 147 | + } | |
| 148 | + text, err = tools["list_agents"].Call(context.Background(), "s-1", nil) | |
| 149 | + if err != nil || !strings.Contains(text, "1 agents:\n- @riker (you). Runs on the user's computer; ") { | |
| 150 | + t.Fatalf("list_agents: %q %v", text, err) | |
| 151 | + } | |
| 152 | + search := tools["search_messages"] | |
| 153 | + if search.InputSchema["required"].([]string)[0] != "query" { | |
| 154 | + t.Fatalf("schema: %+v", search.InputSchema) | |
| 155 | + } | |
| 156 | + text, err = search.Call(context.Background(), "s-1", map[string]any{"query": "HI"}) | |
| 157 | + if err != nil || !strings.Contains(text, `1 messages of #general contain "HI", the most recent first:`) || !strings.Contains(text, ", the user: @riker hi") { | |
| 158 | + t.Fatalf("search in this channel: %q %v", text, err) | |
| 159 | + } | |
| 160 | + text, err = search.Call(context.Background(), "", map[string]any{"query": "ok", "channel": "#general", "limit": float64(5)}) | |
| 161 | + if err != nil || !strings.Contains(text, ", @riker: ok") { | |
| 162 | + t.Fatalf("search in a named channel: %q %v", text, err) | |
| 163 | + } | |
| 164 | + if _, err := search.Call(context.Background(), "", map[string]any{"query": "ok", "channel": "bridge"}); err == nil || !strings.Contains(err.Error(), "the channels are: #general") { | |
| 165 | + t.Fatalf("unknown channel: %v", err) | |
| 166 | + } | |
| 167 | + if _, err := search.Call(context.Background(), "s-1", map[string]any{}); err == nil { | |
| 168 | + t.Fatal("query is required") | |
| 169 | + } | |
| 170 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,170 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package app_test | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "context" | ||
| 7 | + "os" | ||
| 8 | + "path/filepath" | ||
| 9 | + "strings" | ||
| 10 | + "sync" | ||
| 11 | + "testing" | ||
| 12 | + "time" | ||
| 13 | + | ||
| 14 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | ||
| 15 | + "git.rickub.com/bots-garden/sidekicks/internal/agents" | ||
| 16 | + "git.rickub.com/bots-garden/sidekicks/internal/app" | ||
| 17 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | ||
| 18 | + "git.rickub.com/bots-garden/sidekicks/internal/config" | ||
| 19 | + "git.rickub.com/bots-garden/sidekicks/internal/memory" | ||
| 20 | +) | ||
| 21 | + | ||
| 22 | +// Issue #90: the tools Sidekicks offers the agents. | ||
| 23 | + | ||
| 24 | +// offeredTools has riker answer in #general, with settings (YAML) in the | ||
| 25 | +// configuration, and returns how it was started. | ||
| 26 | +func offeredTools(t *testing.T, settings string) acp.Spec { | ||
| 27 | + t.Helper() | ||
| 28 | + directory := t.TempDir() | ||
| 29 | + path := filepath.Join(directory, "config.yaml") | ||
| 30 | + write(t, path, "version: 1\n"+settings+"agents:\n - name: riker\n command: mm\n args: [--acp, --config, agent.yaml]\n workspace: riker\n") | ||
| 31 | + var mu sync.Mutex | ||
| 32 | + var spec acp.Spec | ||
| 33 | + start := func(_ context.Context, started acp.Spec, _ func(string)) (agents.Conn, error) { | ||
| 34 | + mu.Lock() | ||
| 35 | + spec = started | ||
| 36 | + mu.Unlock() | ||
| 37 | + return &conn{done: make(chan struct{})}, nil | ||
| 38 | + } | ||
| 39 | + core := app.New(config.Location{Path: path, Source: config.SourceFlag}, app.Options{Starter: start, Version: "1.4.0"}) | ||
| 40 | + t.Cleanup(func() { core.Shutdown(context.Background()) }) | ||
| 41 | + service := &app.ChannelService{Core: core} | ||
| 42 | + general, err := service.Create("general", "the bridge") | ||
| 43 | + if err != nil { | ||
| 44 | + t.Fatal(err) | ||
| 45 | + } | ||
| 46 | + if _, err := service.Send(general.ID, "@riker hi"); err != nil { | ||
| 47 | + t.Fatal(err) | ||
| 48 | + } | ||
| 49 | + deadline := time.Now().Add(3 * time.Second) | ||
| 50 | + for { | ||
| 51 | + view, _ := service.Conversation(general.ID) | ||
| 52 | + if !view.Busy && len(view.Messages) >= 2 { | ||
| 53 | + break | ||
| 54 | + } | ||
| 55 | + if time.Now().After(deadline) { | ||
| 56 | + t.Fatal("riker never answered") | ||
| 57 | + } | ||
| 58 | + time.Sleep(10 * time.Millisecond) | ||
| 59 | + } | ||
| 60 | + mu.Lock() | ||
| 61 | + defer mu.Unlock() | ||
| 62 | + return spec | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +func TestTheAgentsAreOfferedSidekicksTools(t *testing.T) { | ||
| 66 | + spec := offeredTools(t, "") | ||
| 67 | + if spec.ClientVersion != "1.4.0" || spec.ToolDiscovery != acp.DiscoveryMeta || len(spec.Tools) != 6 { | ||
| 68 | + t.Fatalf("spec: version %q, discovery %q, %d tools", spec.ClientVersion, spec.ToolDiscovery, len(spec.Tools)) | ||
| 69 | + } | ||
| 70 | + for _, tool := range spec.Tools { | ||
| 71 | + if !strings.HasPrefix(tool.Method, "_com.rickub.sidekicks/") || tool.Description == "" { | ||
| 72 | + t.Fatalf("tool %+v", tool) | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +func TestTheToolsAnswerForTheCallersSession(t *testing.T) { | ||
| 78 | + tools := map[string]acp.Tool{} | ||
| 79 | + for _, tool := range offeredTools(t, "").Tools { | ||
| 80 | + tools[tool.Name] = tool | ||
| 81 | + } | ||
| 82 | + text, err := tools["current_channel"].Call(context.Background(), "s-1", nil) | ||
| 83 | + if err != nil || !strings.Contains(text, "Channel #general.") || !strings.Contains(text, "Description: the bridge") || !strings.Contains(text, "you (@riker)") { | ||
| 84 | + t.Fatalf("current_channel: %q %v", text, err) | ||
| 85 | + } | ||
| 86 | + if _, err := tools["current_channel"].Call(context.Background(), "s-unknown", nil); err == nil { | ||
| 87 | + t.Fatal("an unknown session is an error") | ||
| 88 | + } | ||
| 89 | + if text, _ := tools["about_sidekicks"].Call(context.Background(), "s-1", nil); !strings.HasPrefix(text, "Sidekicks 1.4.0, on ") || !strings.Contains(text, `"riker"`) { | ||
| 90 | + t.Fatalf("about_sidekicks: %q", text) | ||
| 91 | + } | ||
| 92 | + if text, err := tools["memory_pressure"].Call(context.Background(), "", nil); err == nil && !strings.HasPrefix(text, "Memory pressure: ") { | ||
| 93 | + t.Fatalf("memory_pressure: %q", text) | ||
| 94 | + } | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +func TestToolTexts(t *testing.T) { | ||
| 98 | + if got := app.MemoryText(memory.Status{Level: memory.Warning, Used: 24 << 30, Total: 32 << 30}); got != "Memory pressure: warning (yellow). Used: 24.0 GB of 32.0 GB (75 %)." { | ||
| 99 | + t.Fatalf("memory: %q", got) | ||
| 100 | + } | ||
| 101 | + if got := app.MemoryText(memory.Status{}); got != "The memory cannot be measured on this computer." { | ||
| 102 | + t.Fatalf("no memory: %q", got) | ||
| 103 | + } | ||
| 104 | + if got := app.ChannelText(channels.Channel{Direct: "riker"}, "riker"); !strings.HasPrefix(got, "A direct conversation between the user and you (riker)") { | ||
| 105 | + t.Fatalf("direct: %q", got) | ||
| 106 | + } | ||
| 107 | + if got := app.ChannelText(channels.Channel{Name: "general", Members: []string{"riker", "data"}}, "riker"); got != "Channel #general.\nMembers: you (@riker), @data, and the user." { | ||
| 108 | + t.Fatalf("channel: %q", got) | ||
| 109 | + } | ||
| 110 | + if got := app.AboutText("", "darwin", "arm64", "riker"); !strings.HasPrefix(got, "Sidekicks dev, on darwin/arm64.") || !strings.Contains(got, app.ReleasesURL) { | ||
| 111 | + t.Fatalf("about: %q", got) | ||
| 112 | + } | ||
| 113 | + if got := app.VersionOf([]byte("info:\n productName: \"Sidekicks\"\n version: \"1.3.0\" # The application version\n")); got != "1.3.0" { | ||
| 114 | + t.Fatalf("version: %q", got) | ||
| 115 | + } | ||
| 116 | + data, err := os.ReadFile("../../build/config.yml") | ||
| 117 | + if err != nil || app.VersionOf(data) == "" { | ||
| 118 | + t.Fatalf("the version of build/config.yml: %v", err) | ||
| 119 | + } | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +// Issue #91: the history tools, and agentTools. | ||
| 123 | + | ||
| 124 | +func toolsOf(spec acp.Spec) map[string]acp.Tool { | ||
| 125 | + tools := map[string]acp.Tool{} | ||
| 126 | + for _, tool := range spec.Tools { | ||
| 127 | + tools[tool.Name] = tool | ||
| 128 | + } | ||
| 129 | + return tools | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +func TestAgentToolsChoosesTheToolsOffered(t *testing.T) { | ||
| 133 | + if spec := offeredTools(t, "agentTools:\n enabled: false\n"); len(spec.Tools) != 0 { | ||
| 134 | + t.Fatalf("disabled: %d tools", len(spec.Tools)) | ||
| 135 | + } | ||
| 136 | + spec := offeredTools(t, "agentTools:\n offer: [memory_pressure, list_agents]\n") | ||
| 137 | + if tools := toolsOf(spec); len(tools) != 2 || tools["memory_pressure"].Call == nil || tools["list_agents"].Call == nil { | ||
| 138 | + t.Fatalf("filtered: %+v", spec.Tools) | ||
| 139 | + } | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +func TestTheHistoryToolsReadEveryChannel(t *testing.T) { | ||
| 143 | + tools := toolsOf(offeredTools(t, "")) | ||
| 144 | + text, err := tools["list_channels"].Call(context.Background(), "s-1", nil) | ||
| 145 | + if err != nil || !strings.Contains(text, "- #general: the bridge. Members: @riker (you). 2 messages, the last on ") { | ||
| 146 | + t.Fatalf("list_channels: %q %v", text, err) | ||
| 147 | + } | ||
| 148 | + text, err = tools["list_agents"].Call(context.Background(), "s-1", nil) | ||
| 149 | + if err != nil || !strings.Contains(text, "1 agents:\n- @riker (you). Runs on the user's computer; ") { | ||
| 150 | + t.Fatalf("list_agents: %q %v", text, err) | ||
| 151 | + } | ||
| 152 | + search := tools["search_messages"] | ||
| 153 | + if search.InputSchema["required"].([]string)[0] != "query" { | ||
| 154 | + t.Fatalf("schema: %+v", search.InputSchema) | ||
| 155 | + } | ||
| 156 | + text, err = search.Call(context.Background(), "s-1", map[string]any{"query": "HI"}) | ||
| 157 | + if err != nil || !strings.Contains(text, `1 messages of #general contain "HI", the most recent first:`) || !strings.Contains(text, ", the user: @riker hi") { | ||
| 158 | + t.Fatalf("search in this channel: %q %v", text, err) | ||
| 159 | + } | ||
| 160 | + text, err = search.Call(context.Background(), "", map[string]any{"query": "ok", "channel": "#general", "limit": float64(5)}) | ||
| 161 | + if err != nil || !strings.Contains(text, ", @riker: ok") { | ||
| 162 | + t.Fatalf("search in a named channel: %q %v", text, err) | ||
| 163 | + } | ||
| 164 | + if _, err := search.Call(context.Background(), "", map[string]any{"query": "ok", "channel": "bridge"}); err == nil || !strings.Contains(err.Error(), "the channels are: #general") { | ||
| 165 | + t.Fatalf("unknown channel: %v", err) | ||
| 166 | + } | ||
| 167 | + if _, err := search.Call(context.Background(), "s-1", map[string]any{}); err == nil { | ||
| 168 | + t.Fatal("query is required") | ||
| 169 | + } | ||
| 170 | +} | ||
added
internal/app/historytools.go +219 -0 | new file mode 100644 | ||
| @@ -0,0 +1,219 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package app | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "context" | |
| 7 | + "errors" | |
| 8 | + "fmt" | |
| 9 | + "strings" | |
| 10 | + | |
| 11 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | |
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/agents" | |
| 13 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | |
| 14 | +) | |
| 15 | + | |
| 16 | +// The tools that read what Sidekicks knows (issue #91): its channels, its | |
| 17 | +// agents and the history of every channel. An agent already reads the | |
| 18 | +// history of the channels it is a member of; with these tools it reads all | |
| 19 | +// of them. agentTools.offer leaves them out when that is not wanted. | |
| 20 | + | |
| 21 | +// The methods of the history tools. | |
| 22 | +const ( | |
| 23 | + ChannelsMethod = "_com.rickub.sidekicks/channels/list" | |
| 24 | + AgentsMethod = "_com.rickub.sidekicks/agents/list" | |
| 25 | + SearchMethod = "_com.rickub.sidekicks/messages/search" | |
| 26 | +) | |
| 27 | + | |
| 28 | +// The number of messages search_messages returns: by default, and at most. | |
| 29 | +const ( | |
| 30 | + DefaultSearchLimit = 10 | |
| 31 | + MaxSearchLimit = 50 | |
| 32 | +) | |
| 33 | + | |
| 34 | +func (c *Core) historyTools(agent string) []acp.Tool { | |
| 35 | + return []acp.Tool{ | |
| 36 | + { | |
| 37 | + Name: "list_channels", | |
| 38 | + Description: "List the Sidekicks channels, the places where the user talks with agents (not files, not the direct conversations): name, description, members, number of messages and date of the last one. Call it to know where a topic was discussed before searching. Channels and messages change: call it again each time, never reuse an earlier result.", | |
| 39 | + Method: ChannelsMethod, | |
| 40 | + Call: func(context.Context, string, map[string]any) (string, error) { | |
| 41 | + manager, err := c.channelManager() | |
| 42 | + if err != nil { | |
| 43 | + return "", err | |
| 44 | + } | |
| 45 | + summaries, err := manager.Summaries() | |
| 46 | + if err != nil { | |
| 47 | + return "", err | |
| 48 | + } | |
| 49 | + return ChannelsText(summaries, agent), nil | |
| 50 | + }, | |
| 51 | + }, | |
| 52 | + { | |
| 53 | + Name: "list_agents", | |
| 54 | + Description: "List the agents of Sidekicks: the name to mention them with (@name), what they do, where they run and whether they are running. Call it to know who can help. Their state changes: call it again each time, never reuse an earlier result.", | |
| 55 | + Method: AgentsMethod, | |
| 56 | + Call: func(context.Context, string, map[string]any) (string, error) { | |
| 57 | + return AgentsText(c.manager.Statuses(), agent), nil | |
| 58 | + }, | |
| 59 | + }, | |
| 60 | + { | |
| 61 | + Name: "search_messages", | |
| 62 | + Description: "Search what was said in a Sidekicks channel: the messages the user and the agents wrote there, not files. Use it, not bash nor file tools, when the user asks what was said, discussed or decided about something in a channel (e.g. \"what was said about Kotlin in documentation\" means channel documentation, query Kotlin). It returns the messages containing the text (case and accents ignored), the most recent first. Without channel, the channel of this conversation. New messages arrive: search again each time, never reuse an earlier result.", | |
| 63 | + Method: SearchMethod, | |
| 64 | + InputSchema: map[string]any{ | |
| 65 | + "type": "object", | |
| 66 | + "properties": map[string]any{ | |
| 67 | + "query": map[string]any{"type": "string", "description": "The text to find, e.g. a word or a name."}, | |
| 68 | + "channel": map[string]any{"type": "string", "description": "The channel's name (documentation, general or #general; client_list_channels lists them), or @agent for a direct conversation with that agent. Default: this conversation's channel."}, | |
| 69 | + "limit": map[string]any{"type": "integer", "description": fmt.Sprintf("How many messages at most (default %d, at most %d).", DefaultSearchLimit, MaxSearchLimit)}, | |
| 70 | + }, | |
| 71 | + "required": []string{"query"}, | |
| 72 | + }, | |
| 73 | + Call: func(_ context.Context, sessionID string, arguments map[string]any) (string, error) { | |
| 74 | + return c.search(agent, sessionID, arguments) | |
| 75 | + }, | |
| 76 | + }, | |
| 77 | + } | |
| 78 | +} | |
| 79 | + | |
| 80 | +// search runs search_messages for agent, called in sessionID. | |
| 81 | +func (c *Core) search(agent, sessionID string, arguments map[string]any) (string, error) { | |
| 82 | + manager, err := c.channelManager() | |
| 83 | + if err != nil { | |
| 84 | + return "", err | |
| 85 | + } | |
| 86 | + query, _ := arguments["query"].(string) | |
| 87 | + if strings.TrimSpace(query) == "" { | |
| 88 | + return "", errors.New("query is missing: give the text to find") | |
| 89 | + } | |
| 90 | + limit := DefaultSearchLimit | |
| 91 | + if number, ok := arguments["limit"].(float64); ok && number >= 1 { | |
| 92 | + limit = min(int(number), MaxSearchLimit) | |
| 93 | + } | |
| 94 | + channel, err := searchedChannel(manager, agent, sessionID, arguments) | |
| 95 | + if err != nil { | |
| 96 | + return "", err | |
| 97 | + } | |
| 98 | + found, err := manager.Search(channel.ID, query, limit) | |
| 99 | + if err != nil { | |
| 100 | + return "", err | |
| 101 | + } | |
| 102 | + return SearchText(channel, query, found), nil | |
| 103 | +} | |
| 104 | + | |
| 105 | +// searchedChannel is the channel arguments name, or the one of sessionID. | |
| 106 | +func searchedChannel(manager *channels.Manager, agent, sessionID string, arguments map[string]any) (channels.Channel, error) { | |
| 107 | + name, _ := arguments["channel"].(string) | |
| 108 | + if strings.TrimSpace(name) == "" { | |
| 109 | + if channel, ok := manager.SessionChannel(agent, sessionID); ok { | |
| 110 | + return channel, nil | |
| 111 | + } | |
| 112 | + return channels.Channel{}, errors.New("this session belongs to no channel: give the channel to search") | |
| 113 | + } | |
| 114 | + channel, err := manager.ChannelNamed(name) | |
| 115 | + if err != nil { | |
| 116 | + var known []string | |
| 117 | + for _, channel := range manager.Channels() { | |
| 118 | + if channel.Direct == "" { | |
| 119 | + known = append(known, channelName(channel)) | |
| 120 | + } | |
| 121 | + } | |
| 122 | + return channels.Channel{}, fmt.Errorf("no channel is called %q; the channels are: %s (or @agent for a direct conversation with that agent)", name, strings.Join(known, ", ")) | |
| 123 | + } | |
| 124 | + return channel, nil | |
| 125 | +} | |
| 126 | + | |
| 127 | +// channelName is how the tools name a channel: #general, or @alice for a | |
| 128 | +// direct conversation. | |
| 129 | +func channelName(channel channels.Channel) string { | |
| 130 | + if channel.Direct != "" { | |
| 131 | + return "@" + channel.Direct | |
| 132 | + } | |
| 133 | + return "#" + channel.Name | |
| 134 | +} | |
| 135 | + | |
| 136 | +// ChannelsText tells summaries (channels only) to a model; agent is the one asking. | |
| 137 | +func ChannelsText(summaries []channels.Summary, agent string) string { | |
| 138 | + if len(summaries) == 0 { | |
| 139 | + return "Sidekicks has no channel yet." | |
| 140 | + } | |
| 141 | + lines := []string{fmt.Sprintf("%d channels:", len(summaries))} | |
| 142 | + for _, summary := range summaries { | |
| 143 | + channel := summary.Channel | |
| 144 | + line := "- " + channelName(channel) | |
| 145 | + if channel.Description != "" { | |
| 146 | + line += ": " + channel.Description | |
| 147 | + } | |
| 148 | + line += ". Members: " + mentions(channel.Members, agent) | |
| 149 | + line += fmt.Sprintf(". %d messages", summary.Messages) | |
| 150 | + if !summary.Last.IsZero() { | |
| 151 | + line += ", the last on " + summary.Last.Local().Format("2006-01-02 15:04") | |
| 152 | + } | |
| 153 | + lines = append(lines, line+".") | |
| 154 | + } | |
| 155 | + return strings.Join(lines, "\n") | |
| 156 | +} | |
| 157 | + | |
| 158 | +func mentions(members []string, agent string) string { | |
| 159 | + if len(members) == 0 { | |
| 160 | + return "none" | |
| 161 | + } | |
| 162 | + var names []string | |
| 163 | + for _, member := range members { | |
| 164 | + name := "@" + member | |
| 165 | + if member == agent { | |
| 166 | + name += " (you)" | |
| 167 | + } | |
| 168 | + names = append(names, name) | |
| 169 | + } | |
| 170 | + return strings.Join(names, ", ") | |
| 171 | +} | |
| 172 | + | |
| 173 | +// AgentsText tells statuses to a model; agent is the one asking. | |
| 174 | +func AgentsText(statuses []agents.Status, agent string) string { | |
| 175 | + if len(statuses) == 0 { | |
| 176 | + return "Sidekicks has no agent." | |
| 177 | + } | |
| 178 | + lines := []string{fmt.Sprintf("%d agents:", len(statuses))} | |
| 179 | + for _, status := range statuses { | |
| 180 | + line := "- @" + status.Name | |
| 181 | + if status.Name == agent { | |
| 182 | + line += " (you)" | |
| 183 | + } | |
| 184 | + if status.Title != "" && status.Title != status.Name { | |
| 185 | + line += ", " + status.Title | |
| 186 | + } | |
| 187 | + if status.Description != "" { | |
| 188 | + line += ": " + status.Description | |
| 189 | + } | |
| 190 | + lines = append(lines, fmt.Sprintf("%s. Runs %s; %s.", line, where(status.Runtime), status.State)) | |
| 191 | + } | |
| 192 | + return strings.Join(lines, "\n") | |
| 193 | +} | |
| 194 | + | |
| 195 | +func where(runtime string) string { | |
| 196 | + switch runtime { | |
| 197 | + case "container": | |
| 198 | + return "in a Docker container" | |
| 199 | + case "sbx": | |
| 200 | + return "in an sbx sandbox" | |
| 201 | + } | |
| 202 | + return "on the user's computer" | |
| 203 | +} | |
| 204 | + | |
| 205 | +// SearchText tells a model what a search for query in channel found. | |
| 206 | +func SearchText(channel channels.Channel, query string, found []channels.Found) string { | |
| 207 | + if len(found) == 0 { | |
| 208 | + return fmt.Sprintf("No message of %s contains %q.", channelName(channel), query) | |
| 209 | + } | |
| 210 | + lines := []string{fmt.Sprintf("%d messages of %s contain %q, the most recent first:", len(found), channelName(channel), query)} | |
| 211 | + for _, match := range found { | |
| 212 | + author := "the user" | |
| 213 | + if match.Message.Role == channels.RoleAgent { | |
| 214 | + author = "@" + match.Message.Agent | |
| 215 | + } | |
| 216 | + lines = append(lines, fmt.Sprintf("- %s, %s: %s", match.Message.CreatedAt.Local().Format("2006-01-02 15:04"), author, match.Excerpt)) | |
| 217 | + } | |
| 218 | + return strings.Join(lines, "\n") | |
| 219 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package app | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "context" | ||
| 7 | + "errors" | ||
| 8 | + "fmt" | ||
| 9 | + "strings" | ||
| 10 | + | ||
| 11 | + "git.rickub.com/bots-garden/sidekicks/internal/acp" | ||
| 12 | + "git.rickub.com/bots-garden/sidekicks/internal/agents" | ||
| 13 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +// The tools that read what Sidekicks knows (issue #91): its channels, its | ||
| 17 | +// agents and the history of every channel. An agent already reads the | ||
| 18 | +// history of the channels it is a member of; with these tools it reads all | ||
| 19 | +// of them. agentTools.offer leaves them out when that is not wanted. | ||
| 20 | + | ||
| 21 | +// The methods of the history tools. | ||
| 22 | +const ( | ||
| 23 | + ChannelsMethod = "_com.rickub.sidekicks/channels/list" | ||
| 24 | + AgentsMethod = "_com.rickub.sidekicks/agents/list" | ||
| 25 | + SearchMethod = "_com.rickub.sidekicks/messages/search" | ||
| 26 | +) | ||
| 27 | + | ||
| 28 | +// The number of messages search_messages returns: by default, and at most. | ||
| 29 | +const ( | ||
| 30 | + DefaultSearchLimit = 10 | ||
| 31 | + MaxSearchLimit = 50 | ||
| 32 | +) | ||
| 33 | + | ||
| 34 | +func (c *Core) historyTools(agent string) []acp.Tool { | ||
| 35 | + return []acp.Tool{ | ||
| 36 | + { | ||
| 37 | + Name: "list_channels", | ||
| 38 | + Description: "List the Sidekicks channels, the places where the user talks with agents (not files, not the direct conversations): name, description, members, number of messages and date of the last one. Call it to know where a topic was discussed before searching. Channels and messages change: call it again each time, never reuse an earlier result.", | ||
| 39 | + Method: ChannelsMethod, | ||
| 40 | + Call: func(context.Context, string, map[string]any) (string, error) { | ||
| 41 | + manager, err := c.channelManager() | ||
| 42 | + if err != nil { | ||
| 43 | + return "", err | ||
| 44 | + } | ||
| 45 | + summaries, err := manager.Summaries() | ||
| 46 | + if err != nil { | ||
| 47 | + return "", err | ||
| 48 | + } | ||
| 49 | + return ChannelsText(summaries, agent), nil | ||
| 50 | + }, | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + Name: "list_agents", | ||
| 54 | + Description: "List the agents of Sidekicks: the name to mention them with (@name), what they do, where they run and whether they are running. Call it to know who can help. Their state changes: call it again each time, never reuse an earlier result.", | ||
| 55 | + Method: AgentsMethod, | ||
| 56 | + Call: func(context.Context, string, map[string]any) (string, error) { | ||
| 57 | + return AgentsText(c.manager.Statuses(), agent), nil | ||
| 58 | + }, | ||
| 59 | + }, | ||
| 60 | + { | ||
| 61 | + Name: "search_messages", | ||
| 62 | + Description: "Search what was said in a Sidekicks channel: the messages the user and the agents wrote there, not files. Use it, not bash nor file tools, when the user asks what was said, discussed or decided about something in a channel (e.g. \"what was said about Kotlin in documentation\" means channel documentation, query Kotlin). It returns the messages containing the text (case and accents ignored), the most recent first. Without channel, the channel of this conversation. New messages arrive: search again each time, never reuse an earlier result.", | ||
| 63 | + Method: SearchMethod, | ||
| 64 | + InputSchema: map[string]any{ | ||
| 65 | + "type": "object", | ||
| 66 | + "properties": map[string]any{ | ||
| 67 | + "query": map[string]any{"type": "string", "description": "The text to find, e.g. a word or a name."}, | ||
| 68 | + "channel": map[string]any{"type": "string", "description": "The channel's name (documentation, general or #general; client_list_channels lists them), or @agent for a direct conversation with that agent. Default: this conversation's channel."}, | ||
| 69 | + "limit": map[string]any{"type": "integer", "description": fmt.Sprintf("How many messages at most (default %d, at most %d).", DefaultSearchLimit, MaxSearchLimit)}, | ||
| 70 | + }, | ||
| 71 | + "required": []string{"query"}, | ||
| 72 | + }, | ||
| 73 | + Call: func(_ context.Context, sessionID string, arguments map[string]any) (string, error) { | ||
| 74 | + return c.search(agent, sessionID, arguments) | ||
| 75 | + }, | ||
| 76 | + }, | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +// search runs search_messages for agent, called in sessionID. | ||
| 81 | +func (c *Core) search(agent, sessionID string, arguments map[string]any) (string, error) { | ||
| 82 | + manager, err := c.channelManager() | ||
| 83 | + if err != nil { | ||
| 84 | + return "", err | ||
| 85 | + } | ||
| 86 | + query, _ := arguments["query"].(string) | ||
| 87 | + if strings.TrimSpace(query) == "" { | ||
| 88 | + return "", errors.New("query is missing: give the text to find") | ||
| 89 | + } | ||
| 90 | + limit := DefaultSearchLimit | ||
| 91 | + if number, ok := arguments["limit"].(float64); ok && number >= 1 { | ||
| 92 | + limit = min(int(number), MaxSearchLimit) | ||
| 93 | + } | ||
| 94 | + channel, err := searchedChannel(manager, agent, sessionID, arguments) | ||
| 95 | + if err != nil { | ||
| 96 | + return "", err | ||
| 97 | + } | ||
| 98 | + found, err := manager.Search(channel.ID, query, limit) | ||
| 99 | + if err != nil { | ||
| 100 | + return "", err | ||
| 101 | + } | ||
| 102 | + return SearchText(channel, query, found), nil | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +// searchedChannel is the channel arguments name, or the one of sessionID. | ||
| 106 | +func searchedChannel(manager *channels.Manager, agent, sessionID string, arguments map[string]any) (channels.Channel, error) { | ||
| 107 | + name, _ := arguments["channel"].(string) | ||
| 108 | + if strings.TrimSpace(name) == "" { | ||
| 109 | + if channel, ok := manager.SessionChannel(agent, sessionID); ok { | ||
| 110 | + return channel, nil | ||
| 111 | + } | ||
| 112 | + return channels.Channel{}, errors.New("this session belongs to no channel: give the channel to search") | ||
| 113 | + } | ||
| 114 | + channel, err := manager.ChannelNamed(name) | ||
| 115 | + if err != nil { | ||
| 116 | + var known []string | ||
| 117 | + for _, channel := range manager.Channels() { | ||
| 118 | + if channel.Direct == "" { | ||
| 119 | + known = append(known, channelName(channel)) | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + return channels.Channel{}, fmt.Errorf("no channel is called %q; the channels are: %s (or @agent for a direct conversation with that agent)", name, strings.Join(known, ", ")) | ||
| 123 | + } | ||
| 124 | + return channel, nil | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +// channelName is how the tools name a channel: #general, or @alice for a | ||
| 128 | +// direct conversation. | ||
| 129 | +func channelName(channel channels.Channel) string { | ||
| 130 | + if channel.Direct != "" { | ||
| 131 | + return "@" + channel.Direct | ||
| 132 | + } | ||
| 133 | + return "#" + channel.Name | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +// ChannelsText tells summaries (channels only) to a model; agent is the one asking. | ||
| 137 | +func ChannelsText(summaries []channels.Summary, agent string) string { | ||
| 138 | + if len(summaries) == 0 { | ||
| 139 | + return "Sidekicks has no channel yet." | ||
| 140 | + } | ||
| 141 | + lines := []string{fmt.Sprintf("%d channels:", len(summaries))} | ||
| 142 | + for _, summary := range summaries { | ||
| 143 | + channel := summary.Channel | ||
| 144 | + line := "- " + channelName(channel) | ||
| 145 | + if channel.Description != "" { | ||
| 146 | + line += ": " + channel.Description | ||
| 147 | + } | ||
| 148 | + line += ". Members: " + mentions(channel.Members, agent) | ||
| 149 | + line += fmt.Sprintf(". %d messages", summary.Messages) | ||
| 150 | + if !summary.Last.IsZero() { | ||
| 151 | + line += ", the last on " + summary.Last.Local().Format("2006-01-02 15:04") | ||
| 152 | + } | ||
| 153 | + lines = append(lines, line+".") | ||
| 154 | + } | ||
| 155 | + return strings.Join(lines, "\n") | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +func mentions(members []string, agent string) string { | ||
| 159 | + if len(members) == 0 { | ||
| 160 | + return "none" | ||
| 161 | + } | ||
| 162 | + var names []string | ||
| 163 | + for _, member := range members { | ||
| 164 | + name := "@" + member | ||
| 165 | + if member == agent { | ||
| 166 | + name += " (you)" | ||
| 167 | + } | ||
| 168 | + names = append(names, name) | ||
| 169 | + } | ||
| 170 | + return strings.Join(names, ", ") | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +// AgentsText tells statuses to a model; agent is the one asking. | ||
| 174 | +func AgentsText(statuses []agents.Status, agent string) string { | ||
| 175 | + if len(statuses) == 0 { | ||
| 176 | + return "Sidekicks has no agent." | ||
| 177 | + } | ||
| 178 | + lines := []string{fmt.Sprintf("%d agents:", len(statuses))} | ||
| 179 | + for _, status := range statuses { | ||
| 180 | + line := "- @" + status.Name | ||
| 181 | + if status.Name == agent { | ||
| 182 | + line += " (you)" | ||
| 183 | + } | ||
| 184 | + if status.Title != "" && status.Title != status.Name { | ||
| 185 | + line += ", " + status.Title | ||
| 186 | + } | ||
| 187 | + if status.Description != "" { | ||
| 188 | + line += ": " + status.Description | ||
| 189 | + } | ||
| 190 | + lines = append(lines, fmt.Sprintf("%s. Runs %s; %s.", line, where(status.Runtime), status.State)) | ||
| 191 | + } | ||
| 192 | + return strings.Join(lines, "\n") | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +func where(runtime string) string { | ||
| 196 | + switch runtime { | ||
| 197 | + case "container": | ||
| 198 | + return "in a Docker container" | ||
| 199 | + case "sbx": | ||
| 200 | + return "in an sbx sandbox" | ||
| 201 | + } | ||
| 202 | + return "on the user's computer" | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +// SearchText tells a model what a search for query in channel found. | ||
| 206 | +func SearchText(channel channels.Channel, query string, found []channels.Found) string { | ||
| 207 | + if len(found) == 0 { | ||
| 208 | + return fmt.Sprintf("No message of %s contains %q.", channelName(channel), query) | ||
| 209 | + } | ||
| 210 | + lines := []string{fmt.Sprintf("%d messages of %s contain %q, the most recent first:", len(found), channelName(channel), query)} | ||
| 211 | + for _, match := range found { | ||
| 212 | + author := "the user" | ||
| 213 | + if match.Message.Role == channels.RoleAgent { | ||
| 214 | + author = "@" + match.Message.Agent | ||
| 215 | + } | ||
| 216 | + lines = append(lines, fmt.Sprintf("- %s, %s: %s", match.Message.CreatedAt.Local().Format("2006-01-02 15:04"), author, match.Excerpt)) | ||
| 217 | + } | ||
| 218 | + return strings.Join(lines, "\n") | ||
| 219 | +} | ||
modified
internal/channels/channels.go +19 -0 | @@ -372,6 +372,25 @@ func (m *Manager) Channels() []Channel { | ||
| 372 | 372 | return m.list() |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | +// SessionChannel is the channel (or direct conversation) in which agent | |
| 376 | +// holds the ACP session sessionID; false when none does, such as the session | |
| 377 | +// opened to unload a model. The tools Sidekicks offers the agents use it to | |
| 378 | +// know where a call comes from (issue #90). | |
| 379 | +func (m *Manager) SessionChannel(agent, sessionID string) (Channel, bool) { | |
| 380 | + m.mu.Lock() | |
| 381 | + defer m.mu.Unlock() | |
| 382 | + if sessionID == "" { | |
| 383 | + return Channel{}, false | |
| 384 | + } | |
| 385 | + for _, id := range m.order { | |
| 386 | + ch := m.channels[id] | |
| 387 | + if member := ch.member(agent); member != nil && member.SessionID == sessionID { | |
| 388 | + return ch.view(), true | |
| 389 | + } | |
| 390 | + } | |
| 391 | + return Channel{}, false | |
| 392 | +} | |
| 393 | + | |
| 375 | 394 | // Declare creates the channels of the configuration that do not exist yet |
| 376 | 395 | // and adds their missing members (ADR 0003: the YAML describes, the store |
| 377 | 396 | // remembers; nothing is removed). |
| @@ -372,6 +372,25 @@ func (m *Manager) Channels() []Channel { | |||
| 372 | return m.list() | 372 | return m.list() |
| 373 | } | 373 | } |
| 374 | 374 | ||
| 375 | +// SessionChannel is the channel (or direct conversation) in which agent | ||
| 376 | +// holds the ACP session sessionID; false when none does, such as the session | ||
| 377 | +// opened to unload a model. The tools Sidekicks offers the agents use it to | ||
| 378 | +// know where a call comes from (issue #90). | ||
| 379 | +func (m *Manager) SessionChannel(agent, sessionID string) (Channel, bool) { | ||
| 380 | + m.mu.Lock() | ||
| 381 | + defer m.mu.Unlock() | ||
| 382 | + if sessionID == "" { | ||
| 383 | + return Channel{}, false | ||
| 384 | + } | ||
| 385 | + for _, id := range m.order { | ||
| 386 | + ch := m.channels[id] | ||
| 387 | + if member := ch.member(agent); member != nil && member.SessionID == sessionID { | ||
| 388 | + return ch.view(), true | ||
| 389 | + } | ||
| 390 | + } | ||
| 391 | + return Channel{}, false | ||
| 392 | +} | ||
| 393 | + | ||
| 375 | // Declare creates the channels of the configuration that do not exist yet | 394 | // Declare creates the channels of the configuration that do not exist yet |
| 376 | // and adds their missing members (ADR 0003: the YAML describes, the store | 395 | // and adds their missing members (ADR 0003: the YAML describes, the store |
| 377 | // remembers; nothing is removed). | 396 | // remembers; nothing is removed). |
modified
internal/channels/channels_test.go +23 -0 | @@ -616,3 +616,26 @@ func ExampleManager_Send() { | ||
| 616 | 616 | } |
| 617 | 617 | // Output: agent:alice::alice ok | agent:bob::bob ok |
| 618 | 618 | } |
| 619 | + | |
| 620 | +func TestSessionChannelTellsWhereASessionBelongs(t *testing.T) { | |
| 621 | + f := setup(t, nil) | |
| 622 | + general := f.channel(t, "general", "alice", "bob") | |
| 623 | + random := f.channel(t, "random", "alice") | |
| 624 | + f.send(t, general.ID, "@alice hi") | |
| 625 | + f.idle(t, general.ID, 2) | |
| 626 | + f.send(t, random.ID, "@alice hello") | |
| 627 | + f.idle(t, random.ID, 2) | |
| 628 | + for _, want := range []channels.Channel{general, random} { | |
| 629 | + members, _ := f.db.Members(want.ID) | |
| 630 | + got, ok := f.manager.SessionChannel("alice", members[0].SessionID) | |
| 631 | + if !ok || got.ID != want.ID || got.Name != want.Name { | |
| 632 | + t.Fatalf("session %s: got %+v %v, want %s", members[0].SessionID, got, ok, want.Name) | |
| 633 | + } | |
| 634 | + } | |
| 635 | + if _, ok := f.manager.SessionChannel("bob", "alice-s1"); ok { | |
| 636 | + t.Fatal("a session belongs to its agent") | |
| 637 | + } | |
| 638 | + if _, ok := f.manager.SessionChannel("alice", ""); ok { | |
| 639 | + t.Fatal("no session, no channel") | |
| 640 | + } | |
| 641 | +} | |
| @@ -616,3 +616,26 @@ func ExampleManager_Send() { | |||
| 616 | } | 616 | } |
| 617 | // Output: agent:alice::alice ok | agent:bob::bob ok | 617 | // Output: agent:alice::alice ok | agent:bob::bob ok |
| 618 | } | 618 | } |
| 619 | + | ||
| 620 | +func TestSessionChannelTellsWhereASessionBelongs(t *testing.T) { | ||
| 621 | + f := setup(t, nil) | ||
| 622 | + general := f.channel(t, "general", "alice", "bob") | ||
| 623 | + random := f.channel(t, "random", "alice") | ||
| 624 | + f.send(t, general.ID, "@alice hi") | ||
| 625 | + f.idle(t, general.ID, 2) | ||
| 626 | + f.send(t, random.ID, "@alice hello") | ||
| 627 | + f.idle(t, random.ID, 2) | ||
| 628 | + for _, want := range []channels.Channel{general, random} { | ||
| 629 | + members, _ := f.db.Members(want.ID) | ||
| 630 | + got, ok := f.manager.SessionChannel("alice", members[0].SessionID) | ||
| 631 | + if !ok || got.ID != want.ID || got.Name != want.Name { | ||
| 632 | + t.Fatalf("session %s: got %+v %v, want %s", members[0].SessionID, got, ok, want.Name) | ||
| 633 | + } | ||
| 634 | + } | ||
| 635 | + if _, ok := f.manager.SessionChannel("bob", "alice-s1"); ok { | ||
| 636 | + t.Fatal("a session belongs to its agent") | ||
| 637 | + } | ||
| 638 | + if _, ok := f.manager.SessionChannel("alice", ""); ok { | ||
| 639 | + t.Fatal("no session, no channel") | ||
| 640 | + } | ||
| 641 | +} | ||
added
internal/channels/search.go +164 -0 | new file mode 100644 | ||
| @@ -0,0 +1,164 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package channels | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "encoding/json" | |
| 7 | + "errors" | |
| 8 | + "fmt" | |
| 9 | + "math" | |
| 10 | + "strings" | |
| 11 | + "time" | |
| 12 | + "unicode" | |
| 13 | + | |
| 14 | + "golang.org/x/text/unicode/norm" | |
| 15 | +) | |
| 16 | + | |
| 17 | +// What the agents' tools read in the history (issue #91): a summary of each | |
| 18 | +// channel, and a search in the whole history of one, beyond the messages | |
| 19 | +// the interface has loaded. The store has no text index: a search reads the | |
| 20 | +// channel's messages. | |
| 21 | + | |
| 22 | +// Summary is a channel with the size of its history. | |
| 23 | +type Summary struct { | |
| 24 | + Channel Channel | |
| 25 | + Messages int | |
| 26 | + // Last is when the last message was written; zero without messages. | |
| 27 | + Last time.Time | |
| 28 | +} | |
| 29 | + | |
| 30 | +// Found is a message that matches a search, with the text around the match. | |
| 31 | +type Found struct { | |
| 32 | + Message Message | |
| 33 | + Excerpt string | |
| 34 | +} | |
| 35 | + | |
| 36 | +// Summaries returns every channel, oldest first, without the direct | |
| 37 | +// conversations, with how many user and agent messages it holds and when the | |
| 38 | +// last one was written. | |
| 39 | +func (m *Manager) Summaries() ([]Summary, error) { | |
| 40 | + m.mu.Lock() | |
| 41 | + list := m.list() | |
| 42 | + m.mu.Unlock() | |
| 43 | + summaries := make([]Summary, 0, len(list)) | |
| 44 | + for _, channel := range list { | |
| 45 | + if channel.Direct != "" { | |
| 46 | + continue | |
| 47 | + } | |
| 48 | + messages, err := m.history(channel.ID) | |
| 49 | + if err != nil { | |
| 50 | + return nil, err | |
| 51 | + } | |
| 52 | + summary := Summary{Channel: channel} | |
| 53 | + for _, message := range messages { | |
| 54 | + if message.Role == RoleSystem { | |
| 55 | + continue | |
| 56 | + } | |
| 57 | + summary.Messages++ | |
| 58 | + summary.Last = message.CreatedAt | |
| 59 | + } | |
| 60 | + summaries = append(summaries, summary) | |
| 61 | + } | |
| 62 | + return summaries, nil | |
| 63 | +} | |
| 64 | + | |
| 65 | +// ChannelNamed finds a channel by its name ("general" or "#general"), or a | |
| 66 | +// direct conversation by its agent ("@alice"). | |
| 67 | +func (m *Manager) ChannelNamed(name string) (Channel, error) { | |
| 68 | + name = strings.TrimSpace(name) | |
| 69 | + m.mu.Lock() | |
| 70 | + defer m.mu.Unlock() | |
| 71 | + for _, id := range m.order { | |
| 72 | + ch := m.channels[id] | |
| 73 | + direct := ch.info.Direct != "" && name == "@"+ch.info.Direct | |
| 74 | + named := ch.info.Direct == "" && strings.EqualFold(strings.TrimSpace(ch.info.Name), strings.TrimPrefix(name, "#")) | |
| 75 | + if direct || named { | |
| 76 | + return ch.view(), nil | |
| 77 | + } | |
| 78 | + } | |
| 79 | + return Channel{}, fmt.Errorf("%w: %q", ErrUnknownChannel, name) | |
| 80 | +} | |
| 81 | + | |
| 82 | +// Search returns the user and agent messages of a channel whose text | |
| 83 | +// contains query, ignoring case and accents, the most recent first, at most | |
| 84 | +// limit of them. | |
| 85 | +// | |
| 86 | +// found, err := manager.Search(general.ID, "lyon", 10) | |
| 87 | +func (m *Manager) Search(channelID, query string, limit int) ([]Found, error) { | |
| 88 | + wanted := fold(strings.TrimSpace(query)) | |
| 89 | + if len(wanted) == 0 { | |
| 90 | + return nil, errors.New("the search is empty") | |
| 91 | + } | |
| 92 | + messages, err := m.history(channelID) | |
| 93 | + if err != nil { | |
| 94 | + return nil, err | |
| 95 | + } | |
| 96 | + var found []Found | |
| 97 | + for i := len(messages) - 1; i >= 0 && len(found) < limit; i-- { | |
| 98 | + message := messages[i] | |
| 99 | + if message.Role == RoleSystem { | |
| 100 | + continue | |
| 101 | + } | |
| 102 | + text := []rune(textOf(message)) | |
| 103 | + if at := index(fold(string(text)), wanted); at >= 0 { | |
| 104 | + found = append(found, Found{Message: *message, Excerpt: excerpt(text, at, len(wanted))}) | |
| 105 | + } | |
| 106 | + } | |
| 107 | + return found, nil | |
| 108 | +} | |
| 109 | + | |
| 110 | +// history reads every stored message of a channel, oldest first. | |
| 111 | +func (m *Manager) history(channelID string) ([]*Message, error) { | |
| 112 | + stored, _, err := m.db.Messages(channelID, "", math.MaxInt) | |
| 113 | + if err != nil { | |
| 114 | + return nil, err | |
| 115 | + } | |
| 116 | + messages := make([]*Message, 0, len(stored)) | |
| 117 | + for _, data := range stored { | |
| 118 | + message := &Message{} | |
| 119 | + if err := json.Unmarshal(data, message); err != nil { | |
| 120 | + return nil, err | |
| 121 | + } | |
| 122 | + messages = append(messages, message) | |
| 123 | + } | |
| 124 | + return messages, nil | |
| 125 | +} | |
| 126 | + | |
| 127 | +// fold lowers text and strips its accents rune by rune, so that a position | |
| 128 | +// in the result is a position in []rune(text). | |
| 129 | +func fold(text string) []rune { | |
| 130 | + runes := []rune(text) | |
| 131 | + for i, r := range runes { | |
| 132 | + base := []rune(norm.NFD.String(string(unicode.ToLower(r)))) | |
| 133 | + if len(base) > 0 { | |
| 134 | + runes[i] = base[0] | |
| 135 | + } | |
| 136 | + } | |
| 137 | + return runes | |
| 138 | +} | |
| 139 | + | |
| 140 | +// index is the position of wanted in text, -1 when absent. | |
| 141 | +func index(text, wanted []rune) int { | |
| 142 | + for i := 0; i+len(wanted) <= len(text); i++ { | |
| 143 | + if string(text[i:i+len(wanted)]) == string(wanted) { | |
| 144 | + return i | |
| 145 | + } | |
| 146 | + } | |
| 147 | + return -1 | |
| 148 | +} | |
| 149 | + | |
| 150 | +// excerptAround is how many characters an excerpt keeps on each side of a match. | |
| 151 | +const excerptAround = 80 | |
| 152 | + | |
| 153 | +// excerpt is the text around text[at:at+length], on one line. | |
| 154 | +func excerpt(text []rune, at, length int) string { | |
| 155 | + start, end := max(0, at-excerptAround), min(len(text), at+length+excerptAround) | |
| 156 | + result := strings.Join(strings.Fields(string(text[start:end])), " ") | |
| 157 | + if start > 0 { | |
| 158 | + result = "…" + result | |
| 159 | + } | |
| 160 | + if end < len(text) { | |
| 161 | + result += "…" | |
| 162 | + } | |
| 163 | + return result | |
| 164 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package channels | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "encoding/json" | ||
| 7 | + "errors" | ||
| 8 | + "fmt" | ||
| 9 | + "math" | ||
| 10 | + "strings" | ||
| 11 | + "time" | ||
| 12 | + "unicode" | ||
| 13 | + | ||
| 14 | + "golang.org/x/text/unicode/norm" | ||
| 15 | +) | ||
| 16 | + | ||
| 17 | +// What the agents' tools read in the history (issue #91): a summary of each | ||
| 18 | +// channel, and a search in the whole history of one, beyond the messages | ||
| 19 | +// the interface has loaded. The store has no text index: a search reads the | ||
| 20 | +// channel's messages. | ||
| 21 | + | ||
| 22 | +// Summary is a channel with the size of its history. | ||
| 23 | +type Summary struct { | ||
| 24 | + Channel Channel | ||
| 25 | + Messages int | ||
| 26 | + // Last is when the last message was written; zero without messages. | ||
| 27 | + Last time.Time | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +// Found is a message that matches a search, with the text around the match. | ||
| 31 | +type Found struct { | ||
| 32 | + Message Message | ||
| 33 | + Excerpt string | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +// Summaries returns every channel, oldest first, without the direct | ||
| 37 | +// conversations, with how many user and agent messages it holds and when the | ||
| 38 | +// last one was written. | ||
| 39 | +func (m *Manager) Summaries() ([]Summary, error) { | ||
| 40 | + m.mu.Lock() | ||
| 41 | + list := m.list() | ||
| 42 | + m.mu.Unlock() | ||
| 43 | + summaries := make([]Summary, 0, len(list)) | ||
| 44 | + for _, channel := range list { | ||
| 45 | + if channel.Direct != "" { | ||
| 46 | + continue | ||
| 47 | + } | ||
| 48 | + messages, err := m.history(channel.ID) | ||
| 49 | + if err != nil { | ||
| 50 | + return nil, err | ||
| 51 | + } | ||
| 52 | + summary := Summary{Channel: channel} | ||
| 53 | + for _, message := range messages { | ||
| 54 | + if message.Role == RoleSystem { | ||
| 55 | + continue | ||
| 56 | + } | ||
| 57 | + summary.Messages++ | ||
| 58 | + summary.Last = message.CreatedAt | ||
| 59 | + } | ||
| 60 | + summaries = append(summaries, summary) | ||
| 61 | + } | ||
| 62 | + return summaries, nil | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +// ChannelNamed finds a channel by its name ("general" or "#general"), or a | ||
| 66 | +// direct conversation by its agent ("@alice"). | ||
| 67 | +func (m *Manager) ChannelNamed(name string) (Channel, error) { | ||
| 68 | + name = strings.TrimSpace(name) | ||
| 69 | + m.mu.Lock() | ||
| 70 | + defer m.mu.Unlock() | ||
| 71 | + for _, id := range m.order { | ||
| 72 | + ch := m.channels[id] | ||
| 73 | + direct := ch.info.Direct != "" && name == "@"+ch.info.Direct | ||
| 74 | + named := ch.info.Direct == "" && strings.EqualFold(strings.TrimSpace(ch.info.Name), strings.TrimPrefix(name, "#")) | ||
| 75 | + if direct || named { | ||
| 76 | + return ch.view(), nil | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + return Channel{}, fmt.Errorf("%w: %q", ErrUnknownChannel, name) | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +// Search returns the user and agent messages of a channel whose text | ||
| 83 | +// contains query, ignoring case and accents, the most recent first, at most | ||
| 84 | +// limit of them. | ||
| 85 | +// | ||
| 86 | +// found, err := manager.Search(general.ID, "lyon", 10) | ||
| 87 | +func (m *Manager) Search(channelID, query string, limit int) ([]Found, error) { | ||
| 88 | + wanted := fold(strings.TrimSpace(query)) | ||
| 89 | + if len(wanted) == 0 { | ||
| 90 | + return nil, errors.New("the search is empty") | ||
| 91 | + } | ||
| 92 | + messages, err := m.history(channelID) | ||
| 93 | + if err != nil { | ||
| 94 | + return nil, err | ||
| 95 | + } | ||
| 96 | + var found []Found | ||
| 97 | + for i := len(messages) - 1; i >= 0 && len(found) < limit; i-- { | ||
| 98 | + message := messages[i] | ||
| 99 | + if message.Role == RoleSystem { | ||
| 100 | + continue | ||
| 101 | + } | ||
| 102 | + text := []rune(textOf(message)) | ||
| 103 | + if at := index(fold(string(text)), wanted); at >= 0 { | ||
| 104 | + found = append(found, Found{Message: *message, Excerpt: excerpt(text, at, len(wanted))}) | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + return found, nil | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +// history reads every stored message of a channel, oldest first. | ||
| 111 | +func (m *Manager) history(channelID string) ([]*Message, error) { | ||
| 112 | + stored, _, err := m.db.Messages(channelID, "", math.MaxInt) | ||
| 113 | + if err != nil { | ||
| 114 | + return nil, err | ||
| 115 | + } | ||
| 116 | + messages := make([]*Message, 0, len(stored)) | ||
| 117 | + for _, data := range stored { | ||
| 118 | + message := &Message{} | ||
| 119 | + if err := json.Unmarshal(data, message); err != nil { | ||
| 120 | + return nil, err | ||
| 121 | + } | ||
| 122 | + messages = append(messages, message) | ||
| 123 | + } | ||
| 124 | + return messages, nil | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +// fold lowers text and strips its accents rune by rune, so that a position | ||
| 128 | +// in the result is a position in []rune(text). | ||
| 129 | +func fold(text string) []rune { | ||
| 130 | + runes := []rune(text) | ||
| 131 | + for i, r := range runes { | ||
| 132 | + base := []rune(norm.NFD.String(string(unicode.ToLower(r)))) | ||
| 133 | + if len(base) > 0 { | ||
| 134 | + runes[i] = base[0] | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + return runes | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +// index is the position of wanted in text, -1 when absent. | ||
| 141 | +func index(text, wanted []rune) int { | ||
| 142 | + for i := 0; i+len(wanted) <= len(text); i++ { | ||
| 143 | + if string(text[i:i+len(wanted)]) == string(wanted) { | ||
| 144 | + return i | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + return -1 | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +// excerptAround is how many characters an excerpt keeps on each side of a match. | ||
| 151 | +const excerptAround = 80 | ||
| 152 | + | ||
| 153 | +// excerpt is the text around text[at:at+length], on one line. | ||
| 154 | +func excerpt(text []rune, at, length int) string { | ||
| 155 | + start, end := max(0, at-excerptAround), min(len(text), at+length+excerptAround) | ||
| 156 | + result := strings.Join(strings.Fields(string(text[start:end])), " ") | ||
| 157 | + if start > 0 { | ||
| 158 | + result = "…" + result | ||
| 159 | + } | ||
| 160 | + if end < len(text) { | ||
| 161 | + result += "…" | ||
| 162 | + } | ||
| 163 | + return result | ||
| 164 | +} | ||
added
internal/channels/search_test.go +96 -0 | new file mode 100644 | ||
| @@ -0,0 +1,96 @@ | ||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | |
| 2 | + | |
| 3 | +package channels_test | |
| 4 | + | |
| 5 | +import ( | |
| 6 | + "errors" | |
| 7 | + "strings" | |
| 8 | + "testing" | |
| 9 | + | |
| 10 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | |
| 11 | +) | |
| 12 | + | |
| 13 | +// Issue #91: what the agents' tools read in the history. | |
| 14 | + | |
| 15 | +func TestSearchFindsTheMessagesIgnoringCaseAndAccents(t *testing.T) { | |
| 16 | + f := setup(t, nil) | |
| 17 | + general := f.channel(t, "general", "alice") | |
| 18 | + f.source.conn("alice").reply = func(prompt string) string { | |
| 19 | + if strings.Contains(prompt, "train") { | |
| 20 | + return "Le TGV pour Lyon part à 8 h, gare de Lyon." | |
| 21 | + } | |
| 22 | + return "alice ok" | |
| 23 | + } | |
| 24 | + f.send(t, general.ID, "@alice quel train pour lyon ?") | |
| 25 | + f.idle(t, general.ID, 2) | |
| 26 | + f.send(t, general.ID, "@alice et le café ?") | |
| 27 | + f.idle(t, general.ID, 4) | |
| 28 | + f.send(t, general.ID, "@alice merci, Lyon c'est noté") | |
| 29 | + f.idle(t, general.ID, 6) | |
| 30 | + | |
| 31 | + found, err := f.manager.Search(general.ID, "LYÖN", 10) | |
| 32 | + if err != nil { | |
| 33 | + t.Fatal(err) | |
| 34 | + } | |
| 35 | + var got []string | |
| 36 | + for _, match := range found { | |
| 37 | + got = append(got, string(match.Message.Role)+":"+match.Excerpt) | |
| 38 | + } | |
| 39 | + want := "user:@alice merci, Lyon c'est noté | agent:Le TGV pour Lyon part à 8 h, gare de Lyon. | user:@alice quel train pour lyon ?" | |
| 40 | + if strings.Join(got, " | ") != want { | |
| 41 | + t.Fatalf("most recent first:\n got %s\nwant %s", strings.Join(got, " | "), want) | |
| 42 | + } | |
| 43 | + if found, _ := f.manager.Search(general.ID, "cafe", 10); len(found) != 1 { | |
| 44 | + t.Fatalf("café is found as cafe: %+v", found) | |
| 45 | + } | |
| 46 | + if found, _ := f.manager.Search(general.ID, "lyon", 2); len(found) != 2 { | |
| 47 | + t.Fatalf("at most the limit: %d", len(found)) | |
| 48 | + } | |
| 49 | + if _, err := f.manager.Search(general.ID, " ", 10); err == nil { | |
| 50 | + t.Fatal("an empty search is an error") | |
| 51 | + } | |
| 52 | +} | |
| 53 | + | |
| 54 | +func TestALongMessageGivesAnExcerpt(t *testing.T) { | |
| 55 | + f := setup(t, nil) | |
| 56 | + general := f.channel(t, "general", "alice") | |
| 57 | + f.send(t, general.ID, "@alice "+strings.Repeat("blah ", 40)+"needle "+strings.Repeat("bleh ", 40)) | |
| 58 | + f.idle(t, general.ID, 2) | |
| 59 | + found, _ := f.manager.Search(general.ID, "needle", 10) | |
| 60 | + if len(found) != 1 || !strings.HasPrefix(found[0].Excerpt, "…") || !strings.HasSuffix(found[0].Excerpt, "…") || | |
| 61 | + !strings.Contains(found[0].Excerpt, "needle") || len([]rune(found[0].Excerpt)) > 200 { | |
| 62 | + t.Fatalf("excerpt: %+v", found) | |
| 63 | + } | |
| 64 | +} | |
| 65 | + | |
| 66 | +func TestSummariesAndChannelNames(t *testing.T) { | |
| 67 | + f := setup(t, nil) | |
| 68 | + general := f.channel(t, "general", "alice") | |
| 69 | + f.channel(t, "random") | |
| 70 | + f.send(t, general.ID, "@alice hi") | |
| 71 | + f.idle(t, general.ID, 2) | |
| 72 | + direct, _ := f.manager.Direct("bob") | |
| 73 | + | |
| 74 | + summaries, err := f.manager.Summaries() | |
| 75 | + if err != nil { | |
| 76 | + t.Fatal(err) | |
| 77 | + } | |
| 78 | + counts := map[string]int{} | |
| 79 | + for _, summary := range summaries { | |
| 80 | + counts[summary.Channel.ID] = summary.Messages | |
| 81 | + if summary.Channel.ID == general.ID && summary.Last.IsZero() { | |
| 82 | + t.Fatal("the last message has a date") | |
| 83 | + } | |
| 84 | + } | |
| 85 | + if _, listed := counts[direct.ID]; len(summaries) != 2 || counts[general.ID] != 2 || listed { | |
| 86 | + t.Fatalf("summaries: %+v", summaries) | |
| 87 | + } | |
| 88 | + for name, want := range map[string]string{"general": general.ID, "#General": general.ID, "@bob": direct.ID} { | |
| 89 | + if got, err := f.manager.ChannelNamed(name); err != nil || got.ID != want { | |
| 90 | + t.Errorf("%s: got %+v %v", name, got, err) | |
| 91 | + } | |
| 92 | + } | |
| 93 | + if _, err := f.manager.ChannelNamed("nowhere"); !errors.Is(err, channels.ErrUnknownChannel) { | |
| 94 | + t.Fatalf("unknown: %v", err) | |
| 95 | + } | |
| 96 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | +// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE | ||
| 2 | + | ||
| 3 | +package channels_test | ||
| 4 | + | ||
| 5 | +import ( | ||
| 6 | + "errors" | ||
| 7 | + "strings" | ||
| 8 | + "testing" | ||
| 9 | + | ||
| 10 | + "git.rickub.com/bots-garden/sidekicks/internal/channels" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +// Issue #91: what the agents' tools read in the history. | ||
| 14 | + | ||
| 15 | +func TestSearchFindsTheMessagesIgnoringCaseAndAccents(t *testing.T) { | ||
| 16 | + f := setup(t, nil) | ||
| 17 | + general := f.channel(t, "general", "alice") | ||
| 18 | + f.source.conn("alice").reply = func(prompt string) string { | ||
| 19 | + if strings.Contains(prompt, "train") { | ||
| 20 | + return "Le TGV pour Lyon part à 8 h, gare de Lyon." | ||
| 21 | + } | ||
| 22 | + return "alice ok" | ||
| 23 | + } | ||
| 24 | + f.send(t, general.ID, "@alice quel train pour lyon ?") | ||
| 25 | + f.idle(t, general.ID, 2) | ||
| 26 | + f.send(t, general.ID, "@alice et le café ?") | ||
| 27 | + f.idle(t, general.ID, 4) | ||
| 28 | + f.send(t, general.ID, "@alice merci, Lyon c'est noté") | ||
| 29 | + f.idle(t, general.ID, 6) | ||
| 30 | + | ||
| 31 | + found, err := f.manager.Search(general.ID, "LYÖN", 10) | ||
| 32 | + if err != nil { | ||
| 33 | + t.Fatal(err) | ||
| 34 | + } | ||
| 35 | + var got []string | ||
| 36 | + for _, match := range found { | ||
| 37 | + got = append(got, string(match.Message.Role)+":"+match.Excerpt) | ||
| 38 | + } | ||
| 39 | + want := "user:@alice merci, Lyon c'est noté | agent:Le TGV pour Lyon part à 8 h, gare de Lyon. | user:@alice quel train pour lyon ?" | ||
| 40 | + if strings.Join(got, " | ") != want { | ||
| 41 | + t.Fatalf("most recent first:\n got %s\nwant %s", strings.Join(got, " | "), want) | ||
| 42 | + } | ||
| 43 | + if found, _ := f.manager.Search(general.ID, "cafe", 10); len(found) != 1 { | ||
| 44 | + t.Fatalf("café is found as cafe: %+v", found) | ||
| 45 | + } | ||
| 46 | + if found, _ := f.manager.Search(general.ID, "lyon", 2); len(found) != 2 { | ||
| 47 | + t.Fatalf("at most the limit: %d", len(found)) | ||
| 48 | + } | ||
| 49 | + if _, err := f.manager.Search(general.ID, " ", 10); err == nil { | ||
| 50 | + t.Fatal("an empty search is an error") | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +func TestALongMessageGivesAnExcerpt(t *testing.T) { | ||
| 55 | + f := setup(t, nil) | ||
| 56 | + general := f.channel(t, "general", "alice") | ||
| 57 | + f.send(t, general.ID, "@alice "+strings.Repeat("blah ", 40)+"needle "+strings.Repeat("bleh ", 40)) | ||
| 58 | + f.idle(t, general.ID, 2) | ||
| 59 | + found, _ := f.manager.Search(general.ID, "needle", 10) | ||
| 60 | + if len(found) != 1 || !strings.HasPrefix(found[0].Excerpt, "…") || !strings.HasSuffix(found[0].Excerpt, "…") || | ||
| 61 | + !strings.Contains(found[0].Excerpt, "needle") || len([]rune(found[0].Excerpt)) > 200 { | ||
| 62 | + t.Fatalf("excerpt: %+v", found) | ||
| 63 | + } | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +func TestSummariesAndChannelNames(t *testing.T) { | ||
| 67 | + f := setup(t, nil) | ||
| 68 | + general := f.channel(t, "general", "alice") | ||
| 69 | + f.channel(t, "random") | ||
| 70 | + f.send(t, general.ID, "@alice hi") | ||
| 71 | + f.idle(t, general.ID, 2) | ||
| 72 | + direct, _ := f.manager.Direct("bob") | ||
| 73 | + | ||
| 74 | + summaries, err := f.manager.Summaries() | ||
| 75 | + if err != nil { | ||
| 76 | + t.Fatal(err) | ||
| 77 | + } | ||
| 78 | + counts := map[string]int{} | ||
| 79 | + for _, summary := range summaries { | ||
| 80 | + counts[summary.Channel.ID] = summary.Messages | ||
| 81 | + if summary.Channel.ID == general.ID && summary.Last.IsZero() { | ||
| 82 | + t.Fatal("the last message has a date") | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + if _, listed := counts[direct.ID]; len(summaries) != 2 || counts[general.ID] != 2 || listed { | ||
| 86 | + t.Fatalf("summaries: %+v", summaries) | ||
| 87 | + } | ||
| 88 | + for name, want := range map[string]string{"general": general.ID, "#General": general.ID, "@bob": direct.ID} { | ||
| 89 | + if got, err := f.manager.ChannelNamed(name); err != nil || got.ID != want { | ||
| 90 | + t.Errorf("%s: got %+v %v", name, got, err) | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + if _, err := f.manager.ChannelNamed("nowhere"); !errors.Is(err, channels.ErrUnknownChannel) { | ||
| 94 | + t.Fatalf("unknown: %v", err) | ||
| 95 | + } | ||
| 96 | +} | ||
modified
internal/config/config.go +53 -7 | @@ -22,6 +22,7 @@ import ( | ||
| 22 | 22 | "os" |
| 23 | 23 | "os/exec" |
| 24 | 24 | "path/filepath" |
| 25 | + "slices" | |
| 25 | 26 | "strings" |
| 26 | 27 | "time" |
| 27 | 28 | |
| @@ -41,12 +42,14 @@ const ( | ||
| 41 | 42 | // Config is a loaded configuration: defaults applied and paths absolute. |
| 42 | 43 | type Config struct { |
| 43 | 44 | // Path is the absolute path of the file it was loaded from. |
| 44 | - Path string | |
| 45 | - Version int | |
| 46 | - UI UI | |
| 47 | - Limits Limits | |
| 48 | - Agents []Agent | |
| 49 | - Channels []Channel | |
| 45 | + Path string | |
| 46 | + Version int | |
| 47 | + UI UI | |
| 48 | + Limits Limits | |
| 49 | + // AgentTools says which tools Sidekicks offers the agents (issues #90 and #91). | |
| 50 | + AgentTools AgentTools | |
| 51 | + Agents []Agent | |
| 52 | + Channels []Channel | |
| 50 | 53 | // Warnings are problems that do not prevent using the configuration, |
| 51 | 54 | // such as an agent command that cannot be found yet. |
| 52 | 55 | Warnings []Problem |
| @@ -69,6 +72,23 @@ type Limits struct { | ||
| 69 | 72 | MaxAgentHandoffs int |
| 70 | 73 | } |
| 71 | 74 | |
| 75 | +// AgentToolNames are the tools Sidekicks can offer the agents, the names | |
| 76 | +// agentTools.offer accepts (issues #90 and #91). | |
| 77 | +var AgentToolNames = []string{"memory_pressure", "about_sidekicks", "current_channel", "list_channels", "list_agents", "search_messages"} | |
| 78 | + | |
| 79 | +// AgentTools says which tools Sidekicks offers the agents. | |
| 80 | +type AgentTools struct { | |
| 81 | + // Enabled is false when no tool is offered; true by default. | |
| 82 | + Enabled bool | |
| 83 | + // Offer lists the tools offered; nil offers them all. | |
| 84 | + Offer []string | |
| 85 | +} | |
| 86 | + | |
| 87 | +// Offers tells whether the tool called name is offered. | |
| 88 | +func (tools AgentTools) Offers(name string) bool { | |
| 89 | + return tools.Enabled && (tools.Offer == nil || slices.Contains(tools.Offer, name)) | |
| 90 | +} | |
| 91 | + | |
| 72 | 92 | // Agent describes one agent Sidekicks can start. |
| 73 | 93 | type Agent struct { |
| 74 | 94 | Name string |
| @@ -319,7 +339,7 @@ func Parse(content []byte, path string) (*Config, error) { | ||
| 319 | 339 | } |
| 320 | 340 | cfg := raw.toConfig(filepath.Dir(path)) |
| 321 | 341 | cfg.Path = path |
| 322 | - cfg.Warnings = withLanguage(commandWarnings(cfg, &root, language), language) | |
| 342 | + cfg.Warnings = withLanguage(append(commandWarnings(cfg, &root, language), toolWarnings(cfg, &root, language)...), language) | |
| 323 | 343 | return cfg, nil |
| 324 | 344 | } |
| 325 | 345 | |
| @@ -335,6 +355,10 @@ type rawConfig struct { | ||
| 335 | 355 | StopIdleAgentsAfter string `yaml:"stopIdleAgentsAfter"` |
| 336 | 356 | MaxAgentHandoffs *int `yaml:"maxAgentHandoffs"` |
| 337 | 357 | } `yaml:"limits"` |
| 358 | + AgentTools struct { | |
| 359 | + Enabled *bool `yaml:"enabled"` | |
| 360 | + Offer *[]string `yaml:"offer"` | |
| 361 | + } `yaml:"agentTools"` | |
| 338 | 362 | Agents []struct { |
| 339 | 363 | Name string `yaml:"name"` |
| 340 | 364 | Title string `yaml:"title"` |
| @@ -376,6 +400,10 @@ func (raw *rawConfig) toConfig(baseDir string) *Config { | ||
| 376 | 400 | MaxAgentHandoffs: DefaultMaxAgentHandoffs, |
| 377 | 401 | }, |
| 378 | 402 | } |
| 403 | + cfg.AgentTools.Enabled = raw.AgentTools.Enabled == nil || *raw.AgentTools.Enabled | |
| 404 | + if raw.AgentTools.Offer != nil { | |
| 405 | + cfg.AgentTools.Offer = append([]string{}, *raw.AgentTools.Offer...) | |
| 406 | + } | |
| 379 | 407 | if raw.Limits.MaxAgentHandoffs != nil { |
| 380 | 408 | cfg.Limits.MaxAgentHandoffs = *raw.Limits.MaxAgentHandoffs |
| 381 | 409 | } |
| @@ -493,6 +521,24 @@ func commandWarnings(cfg *Config, root *yaml.Node, language string) []Problem { | ||
| 493 | 521 | return warnings |
| 494 | 522 | } |
| 495 | 523 | |
| 524 | +// toolWarnings reports the names of agentTools.offer that are no tool: they | |
| 525 | +// offer nothing, the other names still work. | |
| 526 | +func toolWarnings(cfg *Config, root *yaml.Node, language string) []Problem { | |
| 527 | + var warnings []Problem | |
| 528 | + for index, name := range cfg.AgentTools.Offer { | |
| 529 | + if slices.Contains(AgentToolNames, name) { | |
| 530 | + continue | |
| 531 | + } | |
| 532 | + path := []string{"agentTools", "offer", fmt.Sprint(index)} | |
| 533 | + line, column := position(root, path) | |
| 534 | + warnings = append(warnings, Problem{ | |
| 535 | + Line: line, Column: column, Path: displayPath(path), Warning: true, | |
| 536 | + Message: message(language, msgUnknownTool, name, strings.Join(AgentToolNames, ", ")), | |
| 537 | + }) | |
| 538 | + } | |
| 539 | + return warnings | |
| 540 | +} | |
| 541 | + | |
| 496 | 542 | func commandExists(command string) bool { |
| 497 | 543 | if filepath.IsAbs(command) { |
| 498 | 544 | info, err := os.Stat(command) |
| @@ -22,6 +22,7 @@ import ( | |||
| 22 | "os" | 22 | "os" |
| 23 | "os/exec" | 23 | "os/exec" |
| 24 | "path/filepath" | 24 | "path/filepath" |
| 25 | + "slices" | ||
| 25 | "strings" | 26 | "strings" |
| 26 | "time" | 27 | "time" |
| 27 | 28 | ||
| @@ -41,12 +42,14 @@ const ( | |||
| 41 | // Config is a loaded configuration: defaults applied and paths absolute. | 42 | // Config is a loaded configuration: defaults applied and paths absolute. |
| 42 | type Config struct { | 43 | type Config struct { |
| 43 | // Path is the absolute path of the file it was loaded from. | 44 | // Path is the absolute path of the file it was loaded from. |
| 44 | - Path string | 45 | + Path string |
| 45 | - Version int | 46 | + Version int |
| 46 | - UI UI | 47 | + UI UI |
| 47 | - Limits Limits | 48 | + Limits Limits |
| 48 | - Agents []Agent | 49 | + // AgentTools says which tools Sidekicks offers the agents (issues #90 and #91). |
| 49 | - Channels []Channel | 50 | + AgentTools AgentTools |
| 51 | + Agents []Agent | ||
| 52 | + Channels []Channel | ||
| 50 | // Warnings are problems that do not prevent using the configuration, | 53 | // Warnings are problems that do not prevent using the configuration, |
| 51 | // such as an agent command that cannot be found yet. | 54 | // such as an agent command that cannot be found yet. |
| 52 | Warnings []Problem | 55 | Warnings []Problem |
| @@ -69,6 +72,23 @@ type Limits struct { | |||
| 69 | MaxAgentHandoffs int | 72 | MaxAgentHandoffs int |
| 70 | } | 73 | } |
| 71 | 74 | ||
| 75 | +// AgentToolNames are the tools Sidekicks can offer the agents, the names | ||
| 76 | +// agentTools.offer accepts (issues #90 and #91). | ||
| 77 | +var AgentToolNames = []string{"memory_pressure", "about_sidekicks", "current_channel", "list_channels", "list_agents", "search_messages"} | ||
| 78 | + | ||
| 79 | +// AgentTools says which tools Sidekicks offers the agents. | ||
| 80 | +type AgentTools struct { | ||
| 81 | + // Enabled is false when no tool is offered; true by default. | ||
| 82 | + Enabled bool | ||
| 83 | + // Offer lists the tools offered; nil offers them all. | ||
| 84 | + Offer []string | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +// Offers tells whether the tool called name is offered. | ||
| 88 | +func (tools AgentTools) Offers(name string) bool { | ||
| 89 | + return tools.Enabled && (tools.Offer == nil || slices.Contains(tools.Offer, name)) | ||
| 90 | +} | ||
| 91 | + | ||
| 72 | // Agent describes one agent Sidekicks can start. | 92 | // Agent describes one agent Sidekicks can start. |
| 73 | type Agent struct { | 93 | type Agent struct { |
| 74 | Name string | 94 | Name string |
| @@ -319,7 +339,7 @@ func Parse(content []byte, path string) (*Config, error) { | |||
| 319 | } | 339 | } |
| 320 | cfg := raw.toConfig(filepath.Dir(path)) | 340 | cfg := raw.toConfig(filepath.Dir(path)) |
| 321 | cfg.Path = path | 341 | cfg.Path = path |
| 322 | - cfg.Warnings = withLanguage(commandWarnings(cfg, &root, language), language) | 342 | + cfg.Warnings = withLanguage(append(commandWarnings(cfg, &root, language), toolWarnings(cfg, &root, language)...), language) |
| 323 | return cfg, nil | 343 | return cfg, nil |
| 324 | } | 344 | } |
| 325 | 345 | ||
| @@ -335,6 +355,10 @@ type rawConfig struct { | |||
| 335 | StopIdleAgentsAfter string `yaml:"stopIdleAgentsAfter"` | 355 | StopIdleAgentsAfter string `yaml:"stopIdleAgentsAfter"` |
| 336 | MaxAgentHandoffs *int `yaml:"maxAgentHandoffs"` | 356 | MaxAgentHandoffs *int `yaml:"maxAgentHandoffs"` |
| 337 | } `yaml:"limits"` | 357 | } `yaml:"limits"` |
| 358 | + AgentTools struct { | ||
| 359 | + Enabled *bool `yaml:"enabled"` | ||
| 360 | + Offer *[]string `yaml:"offer"` | ||
| 361 | + } `yaml:"agentTools"` | ||
| 338 | Agents []struct { | 362 | Agents []struct { |
| 339 | Name string `yaml:"name"` | 363 | Name string `yaml:"name"` |
| 340 | Title string `yaml:"title"` | 364 | Title string `yaml:"title"` |
| @@ -376,6 +400,10 @@ func (raw *rawConfig) toConfig(baseDir string) *Config { | |||
| 376 | MaxAgentHandoffs: DefaultMaxAgentHandoffs, | 400 | MaxAgentHandoffs: DefaultMaxAgentHandoffs, |
| 377 | }, | 401 | }, |
| 378 | } | 402 | } |
| 403 | + cfg.AgentTools.Enabled = raw.AgentTools.Enabled == nil || *raw.AgentTools.Enabled | ||
| 404 | + if raw.AgentTools.Offer != nil { | ||
| 405 | + cfg.AgentTools.Offer = append([]string{}, *raw.AgentTools.Offer...) | ||
| 406 | + } | ||
| 379 | if raw.Limits.MaxAgentHandoffs != nil { | 407 | if raw.Limits.MaxAgentHandoffs != nil { |
| 380 | cfg.Limits.MaxAgentHandoffs = *raw.Limits.MaxAgentHandoffs | 408 | cfg.Limits.MaxAgentHandoffs = *raw.Limits.MaxAgentHandoffs |
| 381 | } | 409 | } |
| @@ -493,6 +521,24 @@ func commandWarnings(cfg *Config, root *yaml.Node, language string) []Problem { | |||
| 493 | return warnings | 521 | return warnings |
| 494 | } | 522 | } |
| 495 | 523 | ||
| 524 | +// toolWarnings reports the names of agentTools.offer that are no tool: they | ||
| 525 | +// offer nothing, the other names still work. | ||
| 526 | +func toolWarnings(cfg *Config, root *yaml.Node, language string) []Problem { | ||
| 527 | + var warnings []Problem | ||
| 528 | + for index, name := range cfg.AgentTools.Offer { | ||
| 529 | + if slices.Contains(AgentToolNames, name) { | ||
| 530 | + continue | ||
| 531 | + } | ||
| 532 | + path := []string{"agentTools", "offer", fmt.Sprint(index)} | ||
| 533 | + line, column := position(root, path) | ||
| 534 | + warnings = append(warnings, Problem{ | ||
| 535 | + Line: line, Column: column, Path: displayPath(path), Warning: true, | ||
| 536 | + Message: message(language, msgUnknownTool, name, strings.Join(AgentToolNames, ", ")), | ||
| 537 | + }) | ||
| 538 | + } | ||
| 539 | + return warnings | ||
| 540 | +} | ||
| 541 | + | ||
| 496 | func commandExists(command string) bool { | 542 | func commandExists(command string) bool { |
| 497 | if filepath.IsAbs(command) { | 543 | if filepath.IsAbs(command) { |
| 498 | info, err := os.Stat(command) | 544 | info, err := os.Stat(command) |
modified
internal/config/config_test.go +42 -0 | @@ -571,3 +571,45 @@ agents: | ||
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | + | |
| 575 | +func TestAgentToolsAreOfferedByDefaultAndCanBeFiltered(t *testing.T) { | |
| 576 | + cases := []struct { | |
| 577 | + name, yaml string | |
| 578 | + offered []string | |
| 579 | + refused []string | |
| 580 | + }{ | |
| 581 | + {"absent: all", "", config.AgentToolNames, nil}, | |
| 582 | + {"disabled", "agentTools:\n enabled: false\n", nil, config.AgentToolNames}, | |
| 583 | + {"filtered", "agentTools:\n offer: [memory_pressure, list_agents]\n", []string{"memory_pressure", "list_agents"}, []string{"search_messages", "current_channel"}}, | |
| 584 | + {"empty list", "agentTools:\n offer: []\n", nil, config.AgentToolNames}, | |
| 585 | + } | |
| 586 | + for _, c := range cases { | |
| 587 | + cfg, err := parse(t, "version: 1\n"+c.yaml+"agents: []\n") | |
| 588 | + if err != nil { | |
| 589 | + t.Fatalf("%s: %v", c.name, err) | |
| 590 | + } | |
| 591 | + for _, name := range c.offered { | |
| 592 | + if !cfg.AgentTools.Offers(name) { | |
| 593 | + t.Errorf("%s: %s should be offered", c.name, name) | |
| 594 | + } | |
| 595 | + } | |
| 596 | + for _, name := range c.refused { | |
| 597 | + if cfg.AgentTools.Offers(name) { | |
| 598 | + t.Errorf("%s: %s should not be offered", c.name, name) | |
| 599 | + } | |
| 600 | + } | |
| 601 | + } | |
| 602 | +} | |
| 603 | + | |
| 604 | +func TestAnUnknownToolIsOnlyAWarning(t *testing.T) { | |
| 605 | + cfg, err := parse(t, "version: 1\nagentTools:\n offer:\n - memory_pressure\n - memory\nagents: []\n") | |
| 606 | + if err != nil { | |
| 607 | + t.Fatal(err) | |
| 608 | + } | |
| 609 | + if len(cfg.Warnings) != 1 || cfg.Warnings[0].Line != 5 || cfg.Warnings[0].Path != "agentTools.offer[1]" || !strings.Contains(cfg.Warnings[0].Message, `no tool is called "memory"; the tools are: memory_pressure, `) { | |
| 610 | + t.Fatalf("want one warning at line 5, got %+v", cfg.Warnings) | |
| 611 | + } | |
| 612 | + if _, err := parse(t, "version: 1\nagentTools:\n enabled: yes please\nagents: []\n"); err == nil { | |
| 613 | + t.Fatal("enabled is a boolean") | |
| 614 | + } | |
| 615 | +} | |
| @@ -571,3 +571,45 @@ agents: | |||
| 571 | } | 571 | } |
| 572 | } | 572 | } |
| 573 | } | 573 | } |
| 574 | + | ||
| 575 | +func TestAgentToolsAreOfferedByDefaultAndCanBeFiltered(t *testing.T) { | ||
| 576 | + cases := []struct { | ||
| 577 | + name, yaml string | ||
| 578 | + offered []string | ||
| 579 | + refused []string | ||
| 580 | + }{ | ||
| 581 | + {"absent: all", "", config.AgentToolNames, nil}, | ||
| 582 | + {"disabled", "agentTools:\n enabled: false\n", nil, config.AgentToolNames}, | ||
| 583 | + {"filtered", "agentTools:\n offer: [memory_pressure, list_agents]\n", []string{"memory_pressure", "list_agents"}, []string{"search_messages", "current_channel"}}, | ||
| 584 | + {"empty list", "agentTools:\n offer: []\n", nil, config.AgentToolNames}, | ||
| 585 | + } | ||
| 586 | + for _, c := range cases { | ||
| 587 | + cfg, err := parse(t, "version: 1\n"+c.yaml+"agents: []\n") | ||
| 588 | + if err != nil { | ||
| 589 | + t.Fatalf("%s: %v", c.name, err) | ||
| 590 | + } | ||
| 591 | + for _, name := range c.offered { | ||
| 592 | + if !cfg.AgentTools.Offers(name) { | ||
| 593 | + t.Errorf("%s: %s should be offered", c.name, name) | ||
| 594 | + } | ||
| 595 | + } | ||
| 596 | + for _, name := range c.refused { | ||
| 597 | + if cfg.AgentTools.Offers(name) { | ||
| 598 | + t.Errorf("%s: %s should not be offered", c.name, name) | ||
| 599 | + } | ||
| 600 | + } | ||
| 601 | + } | ||
| 602 | +} | ||
| 603 | + | ||
| 604 | +func TestAnUnknownToolIsOnlyAWarning(t *testing.T) { | ||
| 605 | + cfg, err := parse(t, "version: 1\nagentTools:\n offer:\n - memory_pressure\n - memory\nagents: []\n") | ||
| 606 | + if err != nil { | ||
| 607 | + t.Fatal(err) | ||
| 608 | + } | ||
| 609 | + if len(cfg.Warnings) != 1 || cfg.Warnings[0].Line != 5 || cfg.Warnings[0].Path != "agentTools.offer[1]" || !strings.Contains(cfg.Warnings[0].Message, `no tool is called "memory"; the tools are: memory_pressure, `) { | ||
| 610 | + t.Fatalf("want one warning at line 5, got %+v", cfg.Warnings) | ||
| 611 | + } | ||
| 612 | + if _, err := parse(t, "version: 1\nagentTools:\n enabled: yes please\nagents: []\n"); err == nil { | ||
| 613 | + t.Fatal("enabled is a boolean") | ||
| 614 | + } | ||
| 615 | +} | ||
modified
internal/config/default.go +6 -0 | @@ -30,6 +30,12 @@ limits: | ||
| 30 | 30 | # An agent unused for this long is stopped to free memory (e.g. 30s, 10m, 1h). |
| 31 | 31 | stopIdleAgentsAfter: 10m |
| 32 | 32 | |
| 33 | +# Tools Sidekicks offers the agents that can use them (mini-me): the memory | |
| 34 | +# pressure, the channels, the agents, a search in the history of every | |
| 35 | +# channel. false: no tool. To offer only some, list them under "offer:". | |
| 36 | +agentTools: | |
| 37 | + enabled: true | |
| 38 | + | |
| 33 | 39 | # The agents: call them in a conversation by clicking their name. |
| 34 | 40 | # The simplest way to add one is the "Add an agent" button of Sidekicks. |
| 35 | 41 | agents: [] |
| @@ -30,6 +30,12 @@ limits: | |||
| 30 | # An agent unused for this long is stopped to free memory (e.g. 30s, 10m, 1h). | 30 | # An agent unused for this long is stopped to free memory (e.g. 30s, 10m, 1h). |
| 31 | stopIdleAgentsAfter: 10m | 31 | stopIdleAgentsAfter: 10m |
| 32 | 32 | ||
| 33 | +# Tools Sidekicks offers the agents that can use them (mini-me): the memory | ||
| 34 | +# pressure, the channels, the agents, a search in the history of every | ||
| 35 | +# channel. false: no tool. To offer only some, list them under "offer:". | ||
| 36 | +agentTools: | ||
| 37 | + enabled: true | ||
| 38 | + | ||
| 33 | # The agents: call them in a conversation by clicking their name. | 39 | # The agents: call them in a conversation by clicking their name. |
| 34 | # The simplest way to add one is the "Add an agent" button of Sidekicks. | 40 | # The simplest way to add one is the "Add an agent" button of Sidekicks. |
| 35 | agents: [] | 41 | agents: [] |
modified
internal/config/problems.go +3 -0 | @@ -90,6 +90,7 @@ const ( | ||
| 90 | 90 | msgDuplicateChan = "duplicateChan" // name |
| 91 | 91 | msgUnknownMember = "unknownMember" // agent |
| 92 | 92 | msgCommandNotFound = "commandNotFound" // command, agent |
| 93 | + msgUnknownTool = "unknownTool" // name, known names | |
| 93 | 94 | msgAbsolutePath = "absolutePath" // value |
| 94 | 95 | msgTooLong = "tooLong" // maximum |
| 95 | 96 | msgEmpty = "empty" // — |
| @@ -113,6 +114,7 @@ var messages = map[string]map[string]string{ | ||
| 113 | 114 | msgDuplicateChan: "il y a déjà un channel nommé « %s » ; les noms doivent être uniques", |
| 114 | 115 | msgUnknownMember: "aucun agent ne s'appelle « %s »", |
| 115 | 116 | msgCommandNotFound: "la commande « %s » de l'agent « %s » est introuvable ; installez-la ou corrigez le chemin", |
| 117 | + msgUnknownTool: "aucun outil ne s'appelle « %s » ; outils connus : %s", | |
| 116 | 118 | msgAbsolutePath: "« %s » doit être un chemin absolu (commençant par /)", |
| 117 | 119 | msgTooLong: "texte trop long : %d caractères au maximum", |
| 118 | 120 | msgEmpty: "la valeur ne peut pas être vide", |
| @@ -134,6 +136,7 @@ var messages = map[string]map[string]string{ | ||
| 134 | 136 | msgDuplicateChan: "there is already a channel called \"%s\"; names must be unique", |
| 135 | 137 | msgUnknownMember: "no agent is called \"%s\"", |
| 136 | 138 | msgCommandNotFound: "the command \"%s\" of agent \"%s\" cannot be found; install it or fix the path", |
| 139 | + msgUnknownTool: "no tool is called \"%s\"; the tools are: %s", | |
| 137 | 140 | msgAbsolutePath: "\"%s\" must be an absolute path (starting with /)", |
| 138 | 141 | msgTooLong: "text too long: %d characters at most", |
| 139 | 142 | msgEmpty: "the value cannot be empty", |
| @@ -90,6 +90,7 @@ const ( | |||
| 90 | msgDuplicateChan = "duplicateChan" // name | 90 | msgDuplicateChan = "duplicateChan" // name |
| 91 | msgUnknownMember = "unknownMember" // agent | 91 | msgUnknownMember = "unknownMember" // agent |
| 92 | msgCommandNotFound = "commandNotFound" // command, agent | 92 | msgCommandNotFound = "commandNotFound" // command, agent |
| 93 | + msgUnknownTool = "unknownTool" // name, known names | ||
| 93 | msgAbsolutePath = "absolutePath" // value | 94 | msgAbsolutePath = "absolutePath" // value |
| 94 | msgTooLong = "tooLong" // maximum | 95 | msgTooLong = "tooLong" // maximum |
| 95 | msgEmpty = "empty" // — | 96 | msgEmpty = "empty" // — |
| @@ -113,6 +114,7 @@ var messages = map[string]map[string]string{ | |||
| 113 | msgDuplicateChan: "il y a déjà un channel nommé « %s » ; les noms doivent être uniques", | 114 | msgDuplicateChan: "il y a déjà un channel nommé « %s » ; les noms doivent être uniques", |
| 114 | msgUnknownMember: "aucun agent ne s'appelle « %s »", | 115 | msgUnknownMember: "aucun agent ne s'appelle « %s »", |
| 115 | msgCommandNotFound: "la commande « %s » de l'agent « %s » est introuvable ; installez-la ou corrigez le chemin", | 116 | msgCommandNotFound: "la commande « %s » de l'agent « %s » est introuvable ; installez-la ou corrigez le chemin", |
| 117 | + msgUnknownTool: "aucun outil ne s'appelle « %s » ; outils connus : %s", | ||
| 116 | msgAbsolutePath: "« %s » doit être un chemin absolu (commençant par /)", | 118 | msgAbsolutePath: "« %s » doit être un chemin absolu (commençant par /)", |
| 117 | msgTooLong: "texte trop long : %d caractères au maximum", | 119 | msgTooLong: "texte trop long : %d caractères au maximum", |
| 118 | msgEmpty: "la valeur ne peut pas être vide", | 120 | msgEmpty: "la valeur ne peut pas être vide", |
| @@ -134,6 +136,7 @@ var messages = map[string]map[string]string{ | |||
| 134 | msgDuplicateChan: "there is already a channel called \"%s\"; names must be unique", | 136 | msgDuplicateChan: "there is already a channel called \"%s\"; names must be unique", |
| 135 | msgUnknownMember: "no agent is called \"%s\"", | 137 | msgUnknownMember: "no agent is called \"%s\"", |
| 136 | msgCommandNotFound: "the command \"%s\" of agent \"%s\" cannot be found; install it or fix the path", | 138 | msgCommandNotFound: "the command \"%s\" of agent \"%s\" cannot be found; install it or fix the path", |
| 139 | + msgUnknownTool: "no tool is called \"%s\"; the tools are: %s", | ||
| 137 | msgAbsolutePath: "\"%s\" must be an absolute path (starting with /)", | 140 | msgAbsolutePath: "\"%s\" must be an absolute path (starting with /)", |
| 138 | msgTooLong: "text too long: %d characters at most", | 141 | msgTooLong: "text too long: %d characters at most", |
| 139 | msgEmpty: "the value cannot be empty", | 142 | msgEmpty: "the value cannot be empty", |
modified
main.go +6 -0 | @@ -31,6 +31,11 @@ import ( | ||
| 31 | 31 | //go:embed all:frontend/dist |
| 32 | 32 | var assets embed.FS |
| 33 | 33 | |
| 34 | +// buildConfig holds info.version, Sidekicks' version, told to the agents. | |
| 35 | +// | |
| 36 | +//go:embed build/config.yml | |
| 37 | +var buildConfig []byte | |
| 38 | + | |
| 34 | 39 | // titleBarInset must match --titlebar-inset in frontend/src/style.css: the |
| 35 | 40 | // height of the area covered by the macOS traffic lights. |
| 36 | 41 | const titleBarInset = 38 |
| @@ -121,6 +126,7 @@ func main() { | ||
| 121 | 126 | core := app.New(location, app.Options{ |
| 122 | 127 | Emitter: emitter, Preferences: preferences, |
| 123 | 128 | PickFile: pickFile, PickFolder: pickFolder, PickYAML: pickYAML, PickAttachment: pickAttachment, |
| 129 | + Version: app.VersionOf(buildConfig), | |
| 124 | 130 | }) |
| 125 | 131 | ctx, cancel := context.WithCancel(context.Background()) |
| 126 | 132 | |
| @@ -31,6 +31,11 @@ import ( | |||
| 31 | //go:embed all:frontend/dist | 31 | //go:embed all:frontend/dist |
| 32 | var assets embed.FS | 32 | var assets embed.FS |
| 33 | 33 | ||
| 34 | +// buildConfig holds info.version, Sidekicks' version, told to the agents. | ||
| 35 | +// | ||
| 36 | +//go:embed build/config.yml | ||
| 37 | +var buildConfig []byte | ||
| 38 | + | ||
| 34 | // titleBarInset must match --titlebar-inset in frontend/src/style.css: the | 39 | // titleBarInset must match --titlebar-inset in frontend/src/style.css: the |
| 35 | // height of the area covered by the macOS traffic lights. | 40 | // height of the area covered by the macOS traffic lights. |
| 36 | const titleBarInset = 38 | 41 | const titleBarInset = 38 |
| @@ -121,6 +126,7 @@ func main() { | |||
| 121 | core := app.New(location, app.Options{ | 126 | core := app.New(location, app.Options{ |
| 122 | Emitter: emitter, Preferences: preferences, | 127 | Emitter: emitter, Preferences: preferences, |
| 123 | PickFile: pickFile, PickFolder: pickFolder, PickYAML: pickYAML, PickAttachment: pickAttachment, | 128 | PickFile: pickFile, PickFolder: pickFolder, PickYAML: pickYAML, PickAttachment: pickAttachment, |
| 129 | + Version: app.VersionOf(buildConfig), | ||
| 124 | }) | 130 | }) |
| 125 | ctx, cancel := context.WithCancel(context.Background()) | 131 | ctx, cancel := context.WithCancel(context.Background()) |
| 126 | 132 | ||
modified
schema/config.schema.json +31 -0 | @@ -20,6 +20,9 @@ | ||
| 20 | 20 | "limits": { |
| 21 | 21 | "$ref": "#/$defs/limits" |
| 22 | 22 | }, |
| 23 | + "agentTools": { | |
| 24 | + "$ref": "#/$defs/agentTools" | |
| 25 | + }, | |
| 23 | 26 | "agents": { |
| 24 | 27 | "description": "The agents available with @name. Names must be unique.", |
| 25 | 28 | "type": "array", |
| @@ -94,6 +97,34 @@ | ||
| 94 | 97 | } |
| 95 | 98 | } |
| 96 | 99 | }, |
| 100 | + "agentTools": { | |
| 101 | + "description": "The tools Sidekicks offers the agents that can discover them (mini-me, with acp.clientTools in its file). Read when an agent starts.", | |
| 102 | + "type": "object", | |
| 103 | + "additionalProperties": false, | |
| 104 | + "properties": { | |
| 105 | + "enabled": { | |
| 106 | + "description": "false: no tool is offered to the agents.", | |
| 107 | + "type": "boolean", | |
| 108 | + "default": true | |
| 109 | + }, | |
| 110 | + "offer": { | |
| 111 | + "description": "Only these tools are offered; absent: all of them. The tools: memory_pressure, about_sidekicks, current_channel, list_channels, list_agents, search_messages (list_channels and search_messages read the history of every channel).", | |
| 112 | + "type": "array", | |
| 113 | + "uniqueItems": true, | |
| 114 | + "items": { | |
| 115 | + "type": "string", | |
| 116 | + "examples": [ | |
| 117 | + "memory_pressure", | |
| 118 | + "about_sidekicks", | |
| 119 | + "current_channel", | |
| 120 | + "list_channels", | |
| 121 | + "list_agents", | |
| 122 | + "search_messages" | |
| 123 | + ] | |
| 124 | + } | |
| 125 | + } | |
| 126 | + } | |
| 127 | + }, | |
| 97 | 128 | "agent": { |
| 98 | 129 | "type": "object", |
| 99 | 130 | "additionalProperties": false, |
| @@ -20,6 +20,9 @@ | |||
| 20 | "limits": { | 20 | "limits": { |
| 21 | "$ref": "#/$defs/limits" | 21 | "$ref": "#/$defs/limits" |
| 22 | }, | 22 | }, |
| 23 | + "agentTools": { | ||
| 24 | + "$ref": "#/$defs/agentTools" | ||
| 25 | + }, | ||
| 23 | "agents": { | 26 | "agents": { |
| 24 | "description": "The agents available with @name. Names must be unique.", | 27 | "description": "The agents available with @name. Names must be unique.", |
| 25 | "type": "array", | 28 | "type": "array", |
| @@ -94,6 +97,34 @@ | |||
| 94 | } | 97 | } |
| 95 | } | 98 | } |
| 96 | }, | 99 | }, |
| 100 | + "agentTools": { | ||
| 101 | + "description": "The tools Sidekicks offers the agents that can discover them (mini-me, with acp.clientTools in its file). Read when an agent starts.", | ||
| 102 | + "type": "object", | ||
| 103 | + "additionalProperties": false, | ||
| 104 | + "properties": { | ||
| 105 | + "enabled": { | ||
| 106 | + "description": "false: no tool is offered to the agents.", | ||
| 107 | + "type": "boolean", | ||
| 108 | + "default": true | ||
| 109 | + }, | ||
| 110 | + "offer": { | ||
| 111 | + "description": "Only these tools are offered; absent: all of them. The tools: memory_pressure, about_sidekicks, current_channel, list_channels, list_agents, search_messages (list_channels and search_messages read the history of every channel).", | ||
| 112 | + "type": "array", | ||
| 113 | + "uniqueItems": true, | ||
| 114 | + "items": { | ||
| 115 | + "type": "string", | ||
| 116 | + "examples": [ | ||
| 117 | + "memory_pressure", | ||
| 118 | + "about_sidekicks", | ||
| 119 | + "current_channel", | ||
| 120 | + "list_channels", | ||
| 121 | + "list_agents", | ||
| 122 | + "search_messages" | ||
| 123 | + ] | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + }, | ||
| 97 | "agent": { | 128 | "agent": { |
| 98 | "type": "object", | 129 | "type": "object", |
| 99 | "additionalProperties": false, | 130 | "additionalProperties": false, |