taskmonkey-cli 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/commands/pull.js +305 -43
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskmonkey-cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "TaskMonkey CLI — Remote dev tools for tenant config editing and tool testing",
5
5
  "bin": {
6
6
  "tm": "./bin/tm.js",
@@ -55,6 +55,14 @@ export async function pull() {
55
55
  written++;
56
56
  }
57
57
 
58
+ // Create AGENTS.md (for Codex, Copilot, etc.) if it doesn't exist
59
+ const agentsMdPath = join(config._configDir, 'AGENTS.md');
60
+ if (!existsSync(agentsMdPath)) {
61
+ writeFileSync(agentsMdPath, generateAgentsMd(config.tenant));
62
+ console.log(chalk.cyan(` AGENTS.md (created)`));
63
+ written++;
64
+ }
65
+
58
66
  // Install Claude Code skills to .claude/commands/
59
67
  const skillsInstalled = installSkills(config._configDir);
60
68
  written += skillsInstalled;
@@ -90,76 +98,330 @@ function installSkills(targetDir) {
90
98
  function generateClaudeMd(tenant) {
91
99
  return `# TaskMonkey Tenant: ${tenant}
92
100
 
93
- ## Was ist das?
101
+ ## Begrüßung
102
+
103
+ Wenn der User die Konversation mit einer kurzen Nachricht beginnt (z.B. "hi", "hallo", "hey", "start", oder eine Frage zum Projekt), gib eine kurze Begrüßung aus:
104
+
105
+ > Willkommen im **${tenant}** Tenant! Ich helfe dir bei der Konfiguration deiner KI-Chatbots.
106
+ >
107
+ > **Quick Start:**
108
+ > - \`tm watch\` in separatem Terminal starten (Auto-Sync)
109
+ > - Prompt bearbeiten → wird automatisch hochgeladen → im Chat testen
110
+ >
111
+ > **Nützliche Befehle:**
112
+ > - \`/test-chat\` — Einzelne Nachricht testen
113
+ > - \`/test-conversations\` — Alle Tests ausführen
114
+ > - \`/optimize-prompt\` — Prompt automatisch verbessern
115
+ >
116
+ > Was möchtest du anpassen?
117
+
118
+ Bei allen anderen Nachrichten arbeite normal weiter ohne Begrüßung.
94
119
 
95
- Dieses Verzeichnis enthält die Konfiguration für den Tenant **${tenant}** der TaskMonkey-Plattform.
96
- Du kannst hier Prompts, Tools und Einstellungen bearbeiten und sie mit dem \`tm\` CLI auf den Server synchronisieren.
120
+ ---
121
+
122
+ Du arbeitest an der Konfiguration des **${tenant}**-Tenants auf der TaskMonkey-Plattform.
123
+ TaskMonkey ist eine KI-Chat-Plattform mit konfigurierbaren Tools, Prompts und Monkey Tasks.
124
+
125
+ ## Erste Schritte
126
+
127
+ 1. Lies \`docs/TenantConfig.md\` — die vollständige Referenz aller Config-Keys
128
+ 2. Schau dir die bestehenden Dateien an, besonders \`monkey_tasks/\` und \`prompts/\`
129
+ 3. Starte \`tm watch\` in einem separaten Terminal für Auto-Sync
130
+ 4. Teste Änderungen mit \`tm chat\` oder \`tm test-chat "deine nachricht"\`
131
+
132
+ ## CLI Befehle (\`tm\`)
133
+
134
+ | Befehl | Beschreibung |
135
+ |--------|-------------|
136
+ | \`tm pull\` | Config-Dateien vom Server herunterladen |
137
+ | \`tm sync\` | Lokale Dateien zum Server hochladen |
138
+ | \`tm watch\` | Auto-Sync bei Dateiänderung (in separatem Terminal laufen lassen) |
139
+ | \`tm chat\` | Interaktiver Chat im Terminal |
140
+ | \`tm chat --task inventur\` | Chat mit spezifischem Monkey Task |
141
+ | \`tm chat --public\` | Öffentlicher Chat (wie Endkunde) |
142
+ | \`tm test-tool <name> key=value\` | Einzelnes Tool testen |
143
+ | \`tm test-chat "nachricht"\` | Einzelne Chat-Nachricht testen |
144
+ | \`tm test-conversations\` | Alle conversation_tests ausführen |
145
+ | \`tm optimize-prompt\` | GPT-4 analysiert Test-Failures und schlägt Prompt-Verbesserungen vor |
146
+ | \`tm logs\` | Server-Logs live streamen |
97
147
 
98
148
  ## Verzeichnisstruktur
99
149
 
100
150
  \`\`\`
101
- .tmrc # Login-Daten (nicht committen!)
102
- CLAUDE.md # Diese Datei
103
- docs/ # Dokumentation (TenantConfig.md etc.)
104
- monkey_tasks/ # Monkey Task Definitionen (Name, Tools, Prompts)
105
- prompts/ # Allgemeine Prompts (System, First Message)
151
+ monkey_tasks/ # Monkey Task Definitionen
152
+ inventur.php # Name, Tools, Prompt, sheetView etc.
153
+ wareneingang.php # Jeder Task in einer Datei
154
+ prompts/ # Allgemeine Prompts
155
+ system.php # System-Prompt für öffentlichen Chat
156
+ first_message.php # Begrüßungsnachricht
106
157
  tools/ # Tool-Konfigurationen
107
- jtl/ # JTL-spezifische Tools
108
- lieferschein/ # Lieferschein/Wareneingang Tools
109
- google_sheets/ # Google Sheets Tools
110
- support/ # Support Tools
158
+ jtl/items/ # z.B. searchItems.php, updateStock.php
159
+ google_sheets/ # z.B. readFromGoogleSheet.php
111
160
  scan.php # Barcode/QR Scanner Konfiguration
112
- apis.php # API-Verbindungen (JTL etc.)
161
+ apis.php # API-Verbindungen
162
+ docs/ # Dokumentation (TenantConfig.md, ToolRunner.md)
163
+ .tmrc # Login-Daten (NICHT committen!)
113
164
  \`\`\`
114
165
 
115
- ## CLI Befehle
116
-
117
- \`\`\`bash
118
- tm login # Einloggen und Tenant wählen
119
- tm pull # Config-Dateien vom Server herunterladen
120
- tm sync # Lokale Dateien zum Server hochladen
121
- tm watch # Auto-Sync bei Dateiänderung
122
- tm test-tool <name> [key=value ...] # Tool auf dem Server testen
123
- tm test-tool <name> --dry-run # Tool im Simulationsmodus testen
124
- tm logs # Server-Logs live streamen
125
- \`\`\`
126
-
127
- ## Workflow
128
-
129
- 1. **Datei bearbeiten** — z.B. einen Prompt in \`monkey_tasks/inventur.php\` ändern
130
- 2. **Synchronisieren** — \`tm sync\` oder \`tm watch\` für Auto-Sync
131
- 3. **Testen** — Im Chat ausprobieren oder \`tm test-tool\` für direktes Tool-Testing
132
- 4. **Logs prüfen** — \`tm logs\` bei Problemen
133
-
134
166
  ## Config-Format
135
167
 
136
- Jede .php Datei gibt ein Array zurück mit Dot-Notation Keys:
168
+ Jede .php Datei gibt ein Array mit Dot-Notation Keys zurück:
137
169
 
138
170
  \`\`\`php
139
171
  <?php
140
172
  return [
141
173
  'monkey_tasks.inventur' => [
142
174
  'name' => 'Inventur',
143
- 'description' => 'Lagerbestand erfassen',
175
+ 'description' => 'Lagerbestand erfassen und aktualisieren',
144
176
  'icon' => '✅',
145
- 'tools' => ['searchItems', 'updateStock', ...],
177
+ 'tools' => ['searchItems', 'getStockBySku', 'updateStock'],
146
178
  ],
147
179
  'monkey_tasks.inventur.prompt' => <<<'PROMPT'
148
- Du bist der Inventur-Assistent...
180
+ Du bist der Inventur-Assistent.
181
+ Wenn der User eine SKU oder einen Artikelnamen nennt, suche mit searchItems.
149
182
  PROMPT,
150
183
  ];
151
184
  \`\`\`
152
185
 
153
- Siehe \`docs/TenantConfig.md\` für die vollständige Dokumentation aller Config-Keys.
186
+ ## Tool-Konfiguration
187
+
188
+ Tools können auf drei Arten definiert werden:
189
+
190
+ ### 1. API-Only (einfache API-Calls)
191
+ \`\`\`php
192
+ 'tools.getCustomer' => [
193
+ 'api' => 'jtl',
194
+ 'endpoint' => 'customers/{customerId}',
195
+ 'method' => 'GET',
196
+ 'description' => 'Holt Kundendaten',
197
+ 'parameters' => [
198
+ 'type' => 'object',
199
+ 'properties' => [
200
+ 'customerId' => ['type' => 'integer'],
201
+ ],
202
+ 'required' => ['customerId'],
203
+ ],
204
+ ],
205
+ \`\`\`
206
+
207
+ ### 2. API + Pre/Postprocess
208
+ \`\`\`php
209
+ 'tools.getOrderItems' => [
210
+ 'api' => 'jtl',
211
+ 'endpoint' => 'salesOrders/{orderId}/lineitems',
212
+ 'method' => 'GET',
213
+ 'preprocess' => function(array \\$args, array \\$ctx): array {
214
+ // Lookup oder Validierung vor dem API-Call
215
+ return ['orderId' => \\$ctx['tool']('verifyOrder', \\$args)['orderId']];
216
+ },
217
+ 'postprocess' => function(array \\$results, array \\$args, array \\$ctx): array {
218
+ // Ergebnis filtern/transformieren
219
+ return ['items' => array_filter(\\$results, fn(\\$i) => \\$i['Type'] === 1)];
220
+ },
221
+ ],
222
+ \`\`\`
223
+
224
+ ### 3. Handler (komplexe Logik)
225
+ \`\`\`php
226
+ 'tools.myCustomTool' => [
227
+ 'description' => 'Beschreibung für die KI',
228
+ 'internal' => true,
229
+ 'handler' => function(array \\$results, array \\$args, array \\$ctx): array {
230
+ \\$logger = \\$ctx['logger'];
231
+ \\$logger->info("Starte...");
232
+
233
+ // Andere Tools aufrufen
234
+ \\$item = \\$ctx['tool']('searchItems', ['searchSku' => \\$args['sku']]);
235
+
236
+ // API-Calls via Cake HTTP Client
237
+ \\$api = \\$ctx['config']['apis']['jtl'];
238
+ \\$http = new \\Cake\\Http\\Client(['timeout' => 60]);
239
+ \\$response = \\$http->get(\\$api['base_url'] . '/items', [], ['headers' => \\$api['headers']]);
240
+
241
+ \\$logger->success("Fertig");
242
+ return ['success' => true, 'data' => \\$response->getJson()];
243
+ },
244
+ 'parameters' => [
245
+ 'type' => 'object',
246
+ 'properties' => [
247
+ 'sku' => ['type' => 'string', 'description' => 'Artikel-SKU'],
248
+ ],
249
+ 'required' => ['sku'],
250
+ ],
251
+ ],
252
+ \`\`\`
253
+
254
+ ## Verfügbare Tool-Handler-Klassen
255
+
256
+ Diese PHP-Klassen stehen als Handler zur Verfügung (Referenz: \`[ClassName, 'methodName']\`):
257
+
258
+ | Klasse | Methoden | Beschreibung |
259
+ |--------|----------|-------------|
260
+ | \`JtlTools\` | searchItems, findBySku, getStockBySku, updateStock, verifyOrder, getOrderLineItems, ... | JTL Wawi API (Artikel, Bestellungen, Lager) |
261
+ | \`GoogleSheetsTools\` | readFromGoogleSheet, writeToGoogleSheet | Google Sheets lesen/schreiben |
262
+ | \`GoogleDriveTools\` | listFiles, readFile, uploadFile, createFile, searchFiles | Google Drive |
263
+ | \`BankingTools\` | getBalance, searchTransactions, listAccounts, matchInvoiceData | Banking/FinAPI |
264
+ | \`DropboxTools\` | uploadToDropbox, listDropboxFiles, readDropboxFile | Dropbox |
265
+ | \`PdfTools\` | extractInvoiceFromPdf, extractTextFromPdf | PDF-Verarbeitung |
266
+ | \`DatabaseGatewayTools\` | deployGateway, executeQuery, removeGateway | Remote-SQL via temporärem Gateway |
267
+ | \`BloomifyTools\` | getProducts, createComplaint, createSupportRequest | Bloomify-spezifisch |
268
+ | \`SuggestionsTools\` | setSuggestions | Chat-Suggestions setzen |
269
+
270
+ ## Handler-Kontext (\`\\$ctx\`)
271
+
272
+ Jeder Handler bekommt einen Kontext mit:
273
+
274
+ \`\`\`php
275
+ \\$ctx['config'] // Tenant-Konfiguration (APIs, Tools, etc.)
276
+ \\$ctx['tenant'] // Tenant-Code (z.B. "bloomify")
277
+ \\$ctx['logger'] // TaskLogger: ->info(), ->success(), ->error(), ->warning()
278
+ \\$ctx['tool'] // Funktion zum Aufrufen anderer Tools: \\$ctx['tool']('toolName', \\$args)
279
+ \\$ctx['chat_id'] // Chat-Session ID
280
+ \\$ctx['testMode'] // true wenn im Simulationsmodus
281
+ \`\`\`
282
+
283
+ ## Verfügbare Vendor-Libraries
284
+
285
+ \`\`\`php
286
+ \\Cake\\Http\\Client // HTTP-Requests (GET, POST, etc.)
287
+ \\Cake\\Cache\\Cache // Caching (read, write, delete)
288
+ \\Cake\\ORM\\TableRegistry // Datenbank-Zugriff
289
+ \\Cake\\Core\\Configure // App-Konfiguration lesen
290
+ \\Google_Service_Sheets // Google Sheets API
291
+ \\Google_Service_Drive // Google Drive API
292
+ \\GuzzleHttp\\Client // Alternative HTTP-Library
293
+ \`\`\`
294
+
295
+ ## Conversation Tests
296
+
297
+ Definiere Tests um Prompt-Änderungen automatisch zu validieren:
298
+
299
+ \`\`\`php
300
+ 'conversation_tests' => [
301
+ [
302
+ 'description' => 'Erdbeere suchen',
303
+ 'user_message' => 'welche erdbeeren habt ihr?',
304
+ 'expect_tool_calls' => ['getProducts'],
305
+ 'expect_response_contains' => ['Erdbeere', 'Preis'],
306
+ ],
307
+ [
308
+ 'description' => 'Bestand abfragen',
309
+ 'user_message' => 'wie viele Tomaten haben wir?',
310
+ 'expect_tool_calls' => ['searchItems', 'getStockBySku'],
311
+ ],
312
+ ],
313
+ \`\`\`
314
+
315
+ Ausführen: \`tm test-conversations\`
316
+ Optimieren: \`tm optimize-prompt\`
154
317
 
155
318
  ## Wichtige Regeln
156
319
 
157
- - **Nur .php Dateien** werden synchronisiert
158
- - **PHP-Syntax wird geprüft** vor dem Schreiben auf dem Server
159
- - **\`.tmrc\` nie committen** enthält Login-Token
160
- - **Prompts** definieren das Verhalten der KI im Chat
161
- - **Tools** definieren welche Aktionen die KI ausführen kann
162
- - **\`internal: true\`** bei Tools bedeutet: nur für Monkey Tasks, nicht für öffentliche Chats
320
+ - Nur \`.php\` Dateien werden synchronisiert
321
+ - PHP-Syntax wird vor dem Schreiben auf dem Server geprüft
322
+ - \`.tmrc\` nie committen (enthält Login-Token)
323
+ - \`internal: true\` bei Tools = nur für Monkey Tasks, nicht für öffentliche Chats
324
+ - Handler-Signatur: \`function(array \\$results, array \\$args, array \\$ctx): array\`
325
+ - Immer \`['success' => true/false]\` im Return-Array
326
+ - \`\\$ctx['tool']('name', \\$args)\` für verschachtelte Tool-Aufrufe
163
327
  `;
164
328
  }
165
329
 
330
+ function generateAgentsMd(tenant) {
331
+ return `# TaskMonkey Tenant: ${tenant}
332
+
333
+ This directory contains the configuration for the **${tenant}** tenant on the TaskMonkey AI platform.
334
+ Use the \`tm\` CLI to sync changes and test.
335
+
336
+ ## Setup
337
+
338
+ \`\`\`bash
339
+ npm install -g taskmonkey-cli
340
+ tm login
341
+ tm pull
342
+ \`\`\`
343
+
344
+ ## Commands
345
+
346
+ - \`tm sync\` — Upload local config files to server
347
+ - \`tm watch\` — Auto-sync on file change
348
+ - \`tm test-tool <name> key=value\` — Run a tool on the server
349
+ - \`tm test-chat "message"\` — Test a single chat message
350
+ - \`tm chat\` — Interactive chat REPL
351
+ - \`tm test-conversations\` — Run all conversation tests
352
+ - \`tm optimize-prompt\` — GPT-4 prompt optimization based on test failures
353
+ - \`tm logs\` — Stream server logs
354
+
355
+ ## File Structure
356
+
357
+ - \`monkey_tasks/*.php\` — Task definitions (name, tools, prompt)
358
+ - \`prompts/*.php\` — System prompts and greetings
359
+ - \`tools/**/*.php\` — Tool configurations (API calls, handlers)
360
+ - \`docs/TenantConfig.md\` — Full config reference
361
+
362
+ ## Config Format
363
+
364
+ Each .php file returns an array with dot-notation keys:
365
+
366
+ \`\`\`php
367
+ <?php
368
+ return [
369
+ 'monkey_tasks.myTask' => [
370
+ 'name' => 'My Task',
371
+ 'tools' => ['searchItems', 'updateStock'],
372
+ ],
373
+ 'monkey_tasks.myTask.prompt' => <<<'PROMPT'
374
+ You are an assistant that...
375
+ PROMPT,
376
+ ];
377
+ \`\`\`
378
+
379
+ ## Tool Patterns
380
+
381
+ ### API-only
382
+ \`\`\`php
383
+ 'tools.getName' => ['api' => 'myapi', 'endpoint' => 'items/{id}', 'method' => 'GET']
384
+ \`\`\`
385
+
386
+ ### Handler
387
+ \`\`\`php
388
+ 'tools.myTool' => [
389
+ 'handler' => function(array $results, array $args, array $ctx): array {
390
+ $item = $ctx['tool']('searchItems', ['searchSku' => $args['sku']]);
391
+ return ['success' => true, 'item' => $item];
392
+ },
393
+ ]
394
+ \`\`\`
395
+
396
+ ## Available Handler Classes
397
+
398
+ | Class | Key Methods |
399
+ |-------|------------|
400
+ | JtlTools | searchItems, findBySku, getStockBySku, updateStock, verifyOrder |
401
+ | GoogleSheetsTools | readFromGoogleSheet, writeToGoogleSheet |
402
+ | GoogleDriveTools | listFiles, readFile, uploadFile |
403
+ | BankingTools | getBalance, searchTransactions, matchInvoiceData |
404
+ | PdfTools | extractInvoiceFromPdf, extractTextFromPdf |
405
+ | DatabaseGatewayTools | deployGateway, executeQuery |
406
+
407
+ ## Handler Context
408
+
409
+ \`\`\`php
410
+ $ctx['config'] // Tenant config (APIs, tools)
411
+ $ctx['tenant'] // Tenant code
412
+ $ctx['logger'] // Logger: ->info(), ->success(), ->error()
413
+ $ctx['tool'] // Call other tools: $ctx['tool']('name', $args)
414
+ \`\`\`
415
+
416
+ ## Testing
417
+
418
+ Define conversation tests in config, run with \`tm test-conversations\`:
419
+
420
+ \`\`\`php
421
+ 'conversation_tests' => [
422
+ ['description' => 'Find product', 'user_message' => 'show me strawberries',
423
+ 'expect_tool_calls' => ['getProducts'], 'expect_response_contains' => ['Strawberry']],
424
+ ]
425
+ \`\`\`
426
+ `;
427
+ }