@koi-language/koi 1.0.5 → 1.1.0

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 (113) hide show
  1. package/README.md +4 -125
  2. package/examples/.build/agent-dialogue.ts +138 -0
  3. package/examples/.build/agent-dialogue.ts.map +1 -0
  4. package/examples/.build/chess.ts +77 -0
  5. package/examples/.build/chess.ts.map +1 -0
  6. package/examples/.build/delegation-test.ts +140 -0
  7. package/examples/.build/delegation-test.ts.map +1 -0
  8. package/examples/.build/dialog-demo.ts +77 -0
  9. package/examples/.build/dialog-demo.ts.map +1 -0
  10. package/examples/.build/hello-world.ts +77 -0
  11. package/examples/.build/hello-world.ts.map +1 -0
  12. package/examples/.build/lover-dialog-demo.ts +77 -0
  13. package/examples/.build/lover-dialog-demo.ts.map +1 -0
  14. package/examples/.build/package.json +3 -0
  15. package/examples/.build/registry-interactive-demo.ts +202 -0
  16. package/examples/.build/registry-interactive-demo.ts.map +1 -0
  17. package/examples/.build/registry-playbook-demo.ts +201 -0
  18. package/examples/.build/registry-playbook-demo.ts.map +1 -0
  19. package/examples/.build/tic-tac-toe.ts +77 -0
  20. package/examples/.build/tic-tac-toe.ts.map +1 -0
  21. package/examples/actions-demo.koi +8 -9
  22. package/examples/activists-dialogue.koi +75 -0
  23. package/examples/agent-dialogue.koi +66 -0
  24. package/examples/chess.koi +19 -0
  25. package/examples/counter.koi +20 -69
  26. package/examples/delegation-test.koi +16 -18
  27. package/examples/dialog-demo.koi +20 -0
  28. package/examples/hello-world.koi +7 -43
  29. package/examples/mcp-stdio-demo.koi +29 -0
  30. package/examples/memory-test.koi +49 -0
  31. package/examples/mobile-mcp-demo.koi +32 -0
  32. package/examples/multi-event-handler-test.koi +16 -18
  33. package/examples/pipeline.koi +15 -17
  34. package/examples/prompt-demo.koi +20 -0
  35. package/examples/{registry-playbook-email-compositor.koi → registry-interactive-demo.koi} +27 -27
  36. package/examples/registry-playbook-demo.koi +28 -28
  37. package/examples/skill-import-test.koi +7 -9
  38. package/examples/skills/.build/math-operations.ts +1656 -0
  39. package/examples/skills/.build/math-operations.ts.map +1 -0
  40. package/examples/skills/.build/package.json +3 -0
  41. package/examples/skills/.build/string-operations.ts +1643 -0
  42. package/examples/skills/.build/string-operations.ts.map +1 -0
  43. package/examples/skills/advanced/.build/index.ts +3223 -0
  44. package/examples/skills/advanced/.build/index.ts.map +1 -0
  45. package/examples/skills/advanced/.build/package.json +3 -0
  46. package/examples/skills/advanced/index.koi +3 -5
  47. package/examples/skills/math-operations.koi +1 -3
  48. package/examples/skills/string-operations.koi +1 -3
  49. package/examples/tic-tac-toe.koi +19 -0
  50. package/examples/utils/echo-mcp-server.js +141 -0
  51. package/examples/web-delegation-demo.koi +15 -17
  52. package/package.json +2 -1
  53. package/src/cli/koi.js +30 -41
  54. package/src/compiler/build-optimizer.js +204 -289
  55. package/src/compiler/cache-manager.js +1 -1
  56. package/src/compiler/import-resolver.js +5 -9
  57. package/src/compiler/parser.js +6072 -3476
  58. package/src/compiler/transpiler.js +346 -38
  59. package/src/grammar/koi.pegjs +302 -62
  60. package/src/runtime/actions/{format.js → call-llm.js} +37 -44
  61. package/src/runtime/actions/call-mcp.js +97 -0
  62. package/src/runtime/actions/if.js +179 -0
  63. package/src/runtime/actions/print.js +3 -1
  64. package/src/runtime/actions/prompt-user.js +75 -0
  65. package/src/runtime/actions/repeat.js +147 -0
  66. package/src/runtime/actions/shell.js +185 -0
  67. package/src/runtime/actions/while.js +205 -0
  68. package/src/runtime/agent.js +592 -178
  69. package/src/runtime/cli-display.js +26 -0
  70. package/src/runtime/cli-input.js +421 -0
  71. package/src/runtime/cli-logger.js +2 -5
  72. package/src/runtime/cli-markdown.js +61 -0
  73. package/src/runtime/cli-select.js +106 -0
  74. package/src/runtime/incremental-json-parser.js +51 -17
  75. package/src/runtime/index.js +1 -0
  76. package/src/runtime/llm-provider.js +1083 -572
  77. package/src/runtime/mcp-registry.js +141 -0
  78. package/src/runtime/mcp-stdio-client.js +334 -0
  79. package/src/runtime/planner.js +1 -1
  80. package/src/runtime/playbook-session.js +259 -0
  81. package/src/runtime/registry-backends/keyv-sqlite.js +1 -1
  82. package/src/runtime/registry-backends/local.js +1 -1
  83. package/src/runtime/router.js +22 -26
  84. package/src/runtime/runtime.js +7 -1
  85. package/examples/cache-test.koi +0 -29
  86. package/examples/calculator.koi +0 -61
  87. package/examples/clear-registry.js +0 -33
  88. package/examples/clear-registry.koi +0 -30
  89. package/examples/code-introspection-test.koi +0 -149
  90. package/examples/directory-import-test.koi +0 -84
  91. package/examples/hello-world-claude.koi +0 -52
  92. package/examples/hello.koi +0 -24
  93. package/examples/mcp-example.koi +0 -70
  94. package/examples/new-import-test.koi +0 -89
  95. package/examples/registry-demo.koi +0 -184
  96. package/examples/registry-playbook-email-compositor-2.koi +0 -140
  97. package/examples/sentiment.koi +0 -90
  98. package/examples/simple.koi +0 -48
  99. package/examples/task-chaining-demo.koi +0 -244
  100. package/examples/test-await.koi +0 -22
  101. package/examples/test-crypto-sha256.koi +0 -196
  102. package/examples/test-delegation.koi +0 -41
  103. package/examples/test-multi-team-routing.koi +0 -258
  104. package/examples/test-no-handler.koi +0 -35
  105. package/examples/test-npm-import.koi +0 -67
  106. package/examples/test-parse.koi +0 -10
  107. package/examples/test-peers-with-team.koi +0 -59
  108. package/examples/test-permissions-fail.koi +0 -20
  109. package/examples/test-permissions.koi +0 -36
  110. package/examples/test-simple-registry.koi +0 -31
  111. package/examples/test-typescript-import.koi +0 -64
  112. package/examples/test-uses-team-syntax.koi +0 -25
  113. package/examples/test-uses-team.koi +0 -31
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
  <img src="koi.png" alt="KOI Language Logo" width="400"/>
3
3
  </div>
4
4
 
5
- # Koi
6
-
7
- **Agent-first language. Calm orchestration.** 🌊
5
+ # Koi - Agent-first language. Calm orchestration. 🌊
8
6
 
9
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
10
8
  [![GitHub](https://img.shields.io/badge/GitHub-koi--language%2FKoi-6495ED?logo=github)](https://github.com/koi-language/Koi)
@@ -71,58 +69,6 @@ This will install KOI to `~/.koi` and add the `koi` command to your PATH.
71
69
 
72
70
  **For manual installation, development setup, and troubleshooting:** See the [Installation Guide](doc/00-installation.md).
73
71
 
74
- ## Editor Support
75
-
76
- ### VS Code
77
-
78
- ```bash
79
- # From the Koi repository root
80
- ln -s "$(pwd)/vscode-koi-extension" ~/.vscode/extensions/koi-lang
81
- # Restart VS Code
82
- ```
83
-
84
- ### Cursor
85
-
86
- ```bash
87
- # From the Koi repository root
88
- ln -s "$(pwd)/vscode-koi-extension" ~/.cursor/extensions/koi-lang
89
- # Restart Cursor
90
- ```
91
-
92
- **Features:**
93
- - ✨ Full syntax highlighting
94
- - 🎨 Custom "Koi Dark" theme
95
- - 🔤 Auto-closing brackets and quotes
96
- - 📝 Special playbook highlighting
97
- - 🔍 Go to Definition support
98
-
99
- **For more installation methods and troubleshooting:** See the [Editor Setup Guide](doc/00-editor-setup.md).
100
-
101
- ## GitHub Syntax Highlighting
102
-
103
- KOI code blocks in markdown files (README, Issues, PRs) automatically get syntax highlighting on GitHub!
104
-
105
- ````markdown
106
- ```koi
107
- Agent Hello : Worker {
108
- on greet(args: Json) {
109
- console.log("Hello from KOI!")
110
- }
111
- }
112
- ```
113
- ````
114
-
115
- **Status:**
116
- - ✅ **Current**: Using JavaScript highlighting (very similar syntax)
117
- - 🚀 **Soon**: Native KOI highlighting (PR submitted to [github/linguist](https://github.com/github/linguist))
118
-
119
- Once the PR is merged, GitHub will recognize `.koi` files with:
120
- - 🎨 Cornflower Blue (#6495ED) in language statistics
121
- - ✨ Full syntax highlighting for code blocks
122
- - 📊 Language detection in repositories
123
-
124
- See [LINGUIST.md](LINGUIST.md) for technical details and contribution status.
125
-
126
72
  ## Usage
127
73
 
128
74
  ### With Global Installation
@@ -188,8 +134,6 @@ Agent Analyzer : Worker {
188
134
 
189
135
  Look for patterns, trends, and anomalies.
190
136
  Provide actionable insights.
191
-
192
- Return JSON: { insights: [...], summary: "...", confidence: 0-1 }
193
137
  """
194
138
  }
195
139
  }
@@ -258,7 +202,7 @@ Agent Orchestrator : Worker {
258
202
  }
259
203
  ```
260
204
 
261
- See [MCP_GUIDE.md](MCP_GUIDE.md) for complete documentation.
205
+ See [MCP Integration Guide](doc/10-mcp-integration.md) for complete documentation.
262
206
 
263
207
  ### Define Skills
264
208
 
@@ -279,13 +223,6 @@ Skill SentimentAnalysis {
279
223
  - Determine overall tone (positive, neutral, negative)
280
224
  - Rate emotional intensity (0.0 to 1.0)
281
225
  - Identify key emotional indicators
282
-
283
- Return JSON: {
284
- "sentiment": "positive|neutral|negative",
285
- "score": 0.0-1.0,
286
- "keywords": ["word1", "word2", ...],
287
- "rationale": "brief explanation"
288
- }
289
226
  """
290
227
  }
291
228
  }
@@ -351,23 +288,7 @@ Example: "Translate to French and count words"
351
288
  - Action 1: Translate → `{ translated: "bonjour monde" }`
352
289
  - Action 2: Count words on `${previousResult.translated}` → `{ wordCount: 2 }`
353
290
 
354
- See [TASK_CHAINING_GUIDE.md](TASK_CHAINING_GUIDE.md) for details.
355
-
356
- ### 🆕 Automatic Routing
357
-
358
- Shows how ANY agent can automatically decompose and delegate tasks:
359
-
360
- ```bash
361
- koi run examples/auto-routing-demo.koi
362
- ```
363
-
364
- Key concepts:
365
- - Regular agents receiving complex tasks
366
- - Automatic decomposition by LLM
367
- - Cascading resolution (own handlers → skills → team routing)
368
- - Intelligent semantic matching via embeddings
369
-
370
- See [AUTO_ROUTING_GUIDE.md](AUTO_ROUTING_GUIDE.md) for explanation.
291
+ See [Task Chaining Guide](doc/08-task-chaining.md) for details.
371
292
 
372
293
  ### Simple
373
294
 
@@ -417,23 +338,7 @@ Example showing MCP (Model Context Protocol) address support:
417
338
  koi run examples/mcp-example.koi
418
339
  ```
419
340
 
420
- ### Automatic Planning
421
-
422
- Demonstrates automatic planning system where agents can decompose complex goals:
423
-
424
- ```bash
425
- koi run examples/planning-demo.koi
426
- ```
427
-
428
- ### Planning with Actions
429
-
430
- Shows how LLM can plan and generate executable actions:
431
-
432
- ```bash
433
- koi run examples/planning-with-actions.koi
434
- ```
435
-
436
- See [PLANNING_GUIDE.md](PLANNING_GUIDE.md) for detailed planning system documentation.
341
+ See [MCP Integration Guide](doc/10-mcp-integration.md) and [Planning System Guide](doc/09-planning.md) for more details on advanced features.
437
342
 
438
343
  ## Source Maps
439
344
 
@@ -491,32 +396,6 @@ Comprehensive documentation is available in the [doc/](doc/) directory:
491
396
  - **[Advanced Topics](doc/15-advanced.md)** - Debugging, performance, production
492
397
  - **[Registry](doc/16-registry.md)** - Shared data store for agent coordination
493
398
 
494
- ## Roadmap
495
-
496
- - [X] MCP (Model Context Protocol) addresses support
497
- - [X] Real LLM integration with OpenAI/Anthropic
498
- - [X] **Full MCP protocol implementation** (WebSocket/HTTP2)
499
- - [X] Real protocol support (WebSocket & HTTP/2)
500
- - [X] Authentication and authorization
501
- - [X] Server discovery
502
- - [X] Connection pooling and load balancing
503
- - [X] Retry logic and failover
504
- - [X] Streaming responses
505
- - [X] MCP tools integration
506
- - [X] Automatic planning system for agents
507
- - [X] LLM-based goal decomposition
508
- - [X] Sequential step execution
509
- - [X] Automatic re-planning on failure
510
- - [X] Context passing between steps
511
- - [X] Execution tracking and summaries
512
- - [X] TypeScript/JavaScript import support
513
- - [X] Unit testing with Jest
514
- - [X] VSCode/Cursor extension with syntax highlighting
515
- - [X] GitHub syntax highlighting support
516
- - [ ] Skills registry and marketplace
517
- - [ ] Visual debugging
518
- - [ ] Hot reload in development
519
-
520
399
  ## Contributing
521
400
 
522
401
  Contributions are welcome! Here are some ways you can help:
@@ -0,0 +1,138 @@
1
+ // Generated from agent-dialogue.koi
2
+ // Using local runtime from KOI_RUNTIME_PATH: /Users/antonioparraga/Git/Koi-lang/Koi/src/runtime
3
+ import { Agent, Team, Skill, Role, Runtime, SkillRegistry, skillSelector, registry, mcpRegistry } from 'file:///Users/antonioparraga/Git/Koi-lang/Koi/src/runtime/index.js';
4
+ import { createRequire } from 'module';
5
+ const require = createRequire(import.meta.url);
6
+
7
+ globalThis.SkillRegistry = SkillRegistry;
8
+ globalThis.skillSelector = skillSelector;
9
+ globalThis.registry = registry;
10
+ globalThis.mcpRegistry = mcpRegistry;
11
+
12
+ // ============================================================
13
+ // Pre-computed Affordances (Build-time Cache)
14
+ // Generated at: 2026-02-16T18:20:41.644Z
15
+ // Total agents: 3
16
+ // Total agent affordances: 3
17
+ // Total skills: 0
18
+ // Total skill affordances: 0
19
+ // This avoids embedding API calls at runtime
20
+ // ============================================================
21
+
22
+ const CACHED_AFFORDANCES = {
23
+ "Philosopher": {
24
+ "ask": {
25
+ "description": "Asks one brief deep philosophical question and returns it as a JSON question field.",
26
+ "confidence": 0.9,
27
+ "hasPlaybook": true
28
+ }
29
+ },
30
+ "Poet": {
31
+ "respond": {
32
+ "description": "Gives a metaphorical poetic answer in up to two sentences and returns it as JSON.",
33
+ "confidence": 0.9,
34
+ "hasPlaybook": true
35
+ }
36
+ },
37
+ "DialogueCoordinator": {
38
+ "startDialogue": {
39
+ "description": "Runs three philosopher-question and poet-answer rounds, prints the dialogue, then ends.",
40
+ "confidence": 0.9,
41
+ "hasPlaybook": true
42
+ }
43
+ }
44
+ };
45
+
46
+ const CACHED_SKILL_AFFORDANCES = {};
47
+
48
+ const Worker = new Role('Worker', ['execute']);
49
+
50
+ const Coordinator = new Role('Coordinator', ['execute', 'delegate']);
51
+
52
+ const Philosopher = new Agent({
53
+ name: 'Philosopher',
54
+ role: Worker,
55
+ llm: { provider: "openai", model: "gpt-5.2" },
56
+ handlers: {
57
+ ask: (() => {
58
+ const handler = async function(args) {
59
+ // This should not be called - playbook will be executed by LLM
60
+ throw new Error('Playbook-only handler called directly');
61
+ };
62
+ handler.__playbookOnly__ = true;
63
+ handler.__playbook__ = "You are a philosopher who asks deep questions.\n\n Context: ${args.context}\n\n Generate ONE brief philosophical question (maximum 2 sentences).\n\n Return ONLY: { \"question\": \"your question here\" }";
64
+ handler.__description__ = "Asks one brief deep philosophical question and returns it as a JSON question field.";
65
+ return handler;
66
+ })(),
67
+ }
68
+ });
69
+
70
+ const Poet = new Agent({
71
+ name: 'Poet',
72
+ role: Worker,
73
+ llm: { provider: "openai", model: "gpt-5.2" },
74
+ handlers: {
75
+ respond: (() => {
76
+ const handler = async function(args) {
77
+ // This should not be called - playbook will be executed by LLM
78
+ throw new Error('Playbook-only handler called directly');
79
+ };
80
+ handler.__playbookOnly__ = true;
81
+ handler.__playbook__ = "You are a poet who responds in a metaphorical way.\n\n Question: \"${args.question}\"\n\n Respond poetically (maximum 2 sentences).\n\n Return ONLY: { \"answer\": \"your answer here\" }";
82
+ handler.__description__ = "Gives a metaphorical poetic answer in up to two sentences and returns it as JSON.";
83
+ return handler;
84
+ })(),
85
+ }
86
+ });
87
+
88
+ const TestTeam = new Team('TestTeam', {
89
+ philosopher: Philosopher,
90
+ poet: Poet,
91
+ });
92
+
93
+ const DialogueCoordinator = new Agent({
94
+ name: 'DialogueCoordinator',
95
+ role: Coordinator,
96
+ usesTeams: [TestTeam],
97
+ peers: TestTeam, // Auto-assigned from uses Team
98
+ llm: { provider: "openai", model: "gpt-5.2" },
99
+ handlers: {
100
+ startDialogue: (() => {
101
+ const handler = async function(args) {
102
+ // This should not be called - playbook will be executed by LLM
103
+ throw new Error('Playbook-only handler called directly');
104
+ };
105
+ handler.__playbookOnly__ = true;
106
+ handler.__playbook__ = "Coordinate a dialogue between Philosopher and Poet for 3 turns.\n\n In each turn:\n First have the philosopher ask a question and then have the poet respond to that question.\n Print the dialogue like this:\n - 🤔 Philosopher: <question here>\n - 🎭 Poet: <answer here>\n\n After 3 rounds, finish by showing:\n ✨ Dialogue completed!";
107
+ handler.__description__ = "Runs three philosopher-question and poet-answer rounds, prints the dialogue, then ends.";
108
+ return handler;
109
+ })(),
110
+ }
111
+ });
112
+
113
+
114
+ // Main execution function
115
+ (async () => {
116
+ // Register agents with router
117
+ const { agentRouter } = await import('file:///Users/antonioparraga/Git/Koi-lang/Koi/src/runtime/router.js');
118
+
119
+ await agentRouter.register(Philosopher, CACHED_AFFORDANCES['Philosopher']);
120
+ await agentRouter.register(Poet, CACHED_AFFORDANCES['Poet']);
121
+ await agentRouter.register(DialogueCoordinator, CACHED_AFFORDANCES['DialogueCoordinator']);
122
+
123
+ // Execute
124
+ const result = await DialogueCoordinator.handle('startDialogue', {});
125
+ // Result handled by actions
126
+
127
+ const _gracefulShutdown = async () => { await mcpRegistry.disconnectAll(); process.exit(0); };
128
+ process.on('SIGINT', _gracefulShutdown);
129
+ process.on('SIGTERM', _gracefulShutdown);
130
+
131
+ await mcpRegistry.disconnectAll();
132
+ process.exit(0);
133
+ })().catch(err => {
134
+ console.error('Error:', err.message);
135
+ process.exit(1);
136
+ });
137
+
138
+ //# sourceMappingURL=agent-dialogue.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["agent-dialogue.koi"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAQA;;;;;;;;;;;;;;;;;;AAiBA;;;;;;;;;;;;;;;;;;AAvBA;;;;;AAwCA","file":"agent-dialogue.koi.js"}
@@ -0,0 +1,77 @@
1
+ // Generated from chess.koi
2
+ // Using local runtime from KOI_RUNTIME_PATH: /Users/antonioparraga/Git/Koi-lang/Koi/src/runtime
3
+ import { Agent, Team, Skill, Role, Runtime, SkillRegistry, skillSelector, registry, mcpRegistry } from 'file:///Users/antonioparraga/Git/Koi-lang/Koi/src/runtime/index.js';
4
+ import { createRequire } from 'module';
5
+ const require = createRequire(import.meta.url);
6
+
7
+ globalThis.SkillRegistry = SkillRegistry;
8
+ globalThis.skillSelector = skillSelector;
9
+ globalThis.registry = registry;
10
+ globalThis.mcpRegistry = mcpRegistry;
11
+
12
+ // ============================================================
13
+ // Pre-computed Affordances (Build-time Cache)
14
+ // Generated at: 2026-02-16T18:21:54.332Z
15
+ // Total agents: 1
16
+ // Total agent affordances: 1
17
+ // Total skills: 0
18
+ // Total skill affordances: 0
19
+ // This avoids embedding API calls at runtime
20
+ // ============================================================
21
+
22
+ const CACHED_AFFORDANCES = {
23
+ "Assistant": {
24
+ "test_while": {
25
+ "description": "Play chess turn-by-turn, showing the board, processing user moves, and ending on win/stop.",
26
+ "confidence": 0.9,
27
+ "hasPlaybook": true
28
+ }
29
+ }
30
+ };
31
+
32
+ const CACHED_SKILL_AFFORDANCES = {};
33
+
34
+ const Worker = new Role('Worker', ['execute']);
35
+
36
+ const Assistant = new Agent({
37
+ name: 'Assistant',
38
+ role: Worker,
39
+ llm: { provider: "openai", model: "gpt-5.2" },
40
+ handlers: {
41
+ test_while: (() => {
42
+ const handler = async function(args) {
43
+ // This should not be called - playbook will be executed by LLM
44
+ throw new Error('Playbook-only handler called directly');
45
+ };
46
+ handler.__playbookOnly__ = true;
47
+ handler.__playbook__ = "Play chess with the user.\n On each turn you show the board, and the user says where to move with a combination like A2 to A4, B3 to C3\n Then you make your move and show the board as it looks after your move.\n End the game when someone wins or if the user expresses their wish to stop.";
48
+ handler.__description__ = "Play chess turn-by-turn, showing the board, processing user moves, and ending on win/stop.";
49
+ return handler;
50
+ })(),
51
+ }
52
+ });
53
+
54
+
55
+ // Main execution function
56
+ (async () => {
57
+ // Register agents with router
58
+ const { agentRouter } = await import('file:///Users/antonioparraga/Git/Koi-lang/Koi/src/runtime/router.js');
59
+
60
+ await agentRouter.register(Assistant, CACHED_AFFORDANCES['Assistant']);
61
+
62
+ // Execute
63
+ const result = await Assistant.handle('test_while', {});
64
+ // Result handled by actions
65
+
66
+ const _gracefulShutdown = async () => { await mcpRegistry.disconnectAll(); process.exit(0); };
67
+ process.on('SIGINT', _gracefulShutdown);
68
+ process.on('SIGTERM', _gracefulShutdown);
69
+
70
+ await mcpRegistry.disconnectAll();
71
+ process.exit(0);
72
+ })().catch(err => {
73
+ console.error('Error:', err.message);
74
+ process.exit(1);
75
+ });
76
+
77
+ //# sourceMappingURL=chess.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["chess.koi"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEA","file":"chess.koi.js"}
@@ -0,0 +1,140 @@
1
+ // Generated from delegation-test.koi
2
+ // Using local runtime from KOI_RUNTIME_PATH: /Users/antonioparraga/Git/M/src/runtime
3
+ import { Agent, Team, Skill, Role, Runtime, SkillRegistry, skillSelector, registry, mcpRegistry } from 'file:///Users/antonioparraga/Git/M/src/runtime/index.js';
4
+ import { createRequire } from 'module';
5
+ const require = createRequire(import.meta.url);
6
+
7
+ globalThis.SkillRegistry = SkillRegistry;
8
+ globalThis.skillSelector = skillSelector;
9
+ globalThis.registry = registry;
10
+ globalThis.mcpRegistry = mcpRegistry;
11
+
12
+ // ============================================================
13
+ // Pre-computed Affordances (Build-time Cache)
14
+ // Generated at: 2026-02-16T17:29:50.172Z
15
+ // Total agents: 3
16
+ // Total agent affordances: 3
17
+ // Total skills: 0
18
+ // Total skill affordances: 0
19
+ // This avoids embedding API calls at runtime
20
+ // ============================================================
21
+
22
+ const CACHED_AFFORDANCES = {
23
+ "Translator": {
24
+ "translate": {
25
+ "description": "Translates text and returns the translated version in JSON format.",
26
+ "confidence": 0.9,
27
+ "hasPlaybook": true
28
+ }
29
+ },
30
+ "WordCounter": {
31
+ "count": {
32
+ "description": "Counts the number of words in the provided text and returns the count in JSON.",
33
+ "confidence": 0.9,
34
+ "hasPlaybook": true
35
+ }
36
+ },
37
+ "Orchestrator": {
38
+ "processText": {
39
+ "description": "Prompts for a sentence, translates it to Spanish, counts words, and displays results.",
40
+ "confidence": 0.9,
41
+ "hasPlaybook": true
42
+ }
43
+ }
44
+ };
45
+
46
+ const CACHED_SKILL_AFFORDANCES = {};
47
+
48
+ const Worker = new Role('Worker', ['execute']);
49
+
50
+ const Coordinator = new Role('Coordinator', ['execute', 'delegate']);
51
+
52
+ const Translator = new Agent({
53
+ name: 'Translator',
54
+ role: Worker,
55
+ llm: { provider: "openai", model: "gpt-4o-mini" },
56
+ amnesia: true,
57
+ handlers: {
58
+ translate: (() => {
59
+ const handler = async function(args) {
60
+ // This should not be called - playbook will be executed by LLM
61
+ throw new Error('Playbook-only handler called directly');
62
+ };
63
+ handler.__playbookOnly__ = true;
64
+ handler.__playbook__ = "Translate \"${args.text}\" to ${args.language}.\n Return JSON: { \"translated\": \"translated text here\" }";
65
+ handler.__description__ = "Translates text and returns the translated version in JSON format.";
66
+ return handler;
67
+ })(),
68
+ }
69
+ });
70
+
71
+ const WordCounter = new Agent({
72
+ name: 'WordCounter',
73
+ role: Worker,
74
+ llm: { provider: "openai", model: "gpt-4o-mini" },
75
+ amnesia: true,
76
+ handlers: {
77
+ count: (() => {
78
+ const handler = async function(args) {
79
+ // This should not be called - playbook will be executed by LLM
80
+ throw new Error('Playbook-only handler called directly');
81
+ };
82
+ handler.__playbookOnly__ = true;
83
+ handler.__playbook__ = "Count words in: \"${args.text}\"\n Return JSON: { \"wordCount\": number }";
84
+ handler.__description__ = "Counts the number of words in the provided text and returns the count in JSON.";
85
+ return handler;
86
+ })(),
87
+ }
88
+ });
89
+
90
+ const TestTeam = new Team('TestTeam', {
91
+ translator: Translator,
92
+ wordCounter: WordCounter,
93
+ });
94
+
95
+ const Orchestrator = new Agent({
96
+ name: 'Orchestrator',
97
+ role: Coordinator,
98
+ usesTeams: [TestTeam],
99
+ peers: TestTeam, // Auto-assigned from uses Team
100
+ llm: { provider: "openai", model: "gpt-4o-mini" },
101
+ handlers: {
102
+ processText: (() => {
103
+ const handler = async function(args) {
104
+ // This should not be called - playbook will be executed by LLM
105
+ throw new Error('Playbook-only handler called directly');
106
+ };
107
+ handler.__playbookOnly__ = true;
108
+ handler.__playbook__ = "Prompt the user to enter a sentence.\n Translate the sentence to Spanish.\n Count the words in the translation.\n Print the original sentence, the translation, and the word count.";
109
+ handler.__description__ = "Prompts for a sentence, translates it to Spanish, counts words, and displays results.";
110
+ return handler;
111
+ })(),
112
+ }
113
+ });
114
+
115
+
116
+ // Main execution function
117
+ (async () => {
118
+ // Register agents with router
119
+ const { agentRouter } = await import('file:///Users/antonioparraga/Git/M/src/runtime/router.js');
120
+
121
+ await agentRouter.register(Translator, CACHED_AFFORDANCES['Translator']);
122
+ await agentRouter.register(WordCounter, CACHED_AFFORDANCES['WordCounter']);
123
+ await agentRouter.register(Orchestrator, CACHED_AFFORDANCES['Orchestrator']);
124
+
125
+ // Execute
126
+ const result = await Orchestrator.handle('processText', { text: "hello world" });
127
+ // Result handled by actions
128
+
129
+ const _gracefulShutdown = async () => { await mcpRegistry.disconnectAll(); process.exit(0); };
130
+ process.on('SIGINT', _gracefulShutdown);
131
+ process.on('SIGTERM', _gracefulShutdown);
132
+
133
+ await mcpRegistry.disconnectAll();
134
+ process.exit(0);
135
+ })().catch(err => {
136
+ console.error('Error:', err.message);
137
+ process.exit(1);
138
+ });
139
+
140
+ //# sourceMappingURL=delegation-test.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["delegation-test.koi"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAQA;;;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;AAnBA;;;;;AAgCA","file":"delegation-test.koi.js"}
@@ -0,0 +1,77 @@
1
+ // Generated from dialog-demo.koi
2
+ // Using local runtime from KOI_RUNTIME_PATH: /Users/antonioparraga/Git/Koi-lang/Koi/src/runtime
3
+ import { Agent, Team, Skill, Role, Runtime, SkillRegistry, skillSelector, registry, mcpRegistry } from 'file:///Users/antonioparraga/Git/Koi-lang/Koi/src/runtime/index.js';
4
+ import { createRequire } from 'module';
5
+ const require = createRequire(import.meta.url);
6
+
7
+ globalThis.SkillRegistry = SkillRegistry;
8
+ globalThis.skillSelector = skillSelector;
9
+ globalThis.registry = registry;
10
+ globalThis.mcpRegistry = mcpRegistry;
11
+
12
+ // ============================================================
13
+ // Pre-computed Affordances (Build-time Cache)
14
+ // Generated at: 2026-02-16T18:35:27.515Z
15
+ // Total agents: 1
16
+ // Total agent affordances: 1
17
+ // Total skills: 0
18
+ // Total skill affordances: 0
19
+ // This avoids embedding API calls at runtime
20
+ // ============================================================
21
+
22
+ const CACHED_AFFORDANCES = {
23
+ "Assistant": {
24
+ "test_while": {
25
+ "description": "Introduce yourself as Koi, ask their name, chat freely until they say goodbye, then respond cordially.",
26
+ "confidence": 0.9,
27
+ "hasPlaybook": true
28
+ }
29
+ }
30
+ };
31
+
32
+ const CACHED_SKILL_AFFORDANCES = {};
33
+
34
+ const Worker = new Role('Worker', ['execute']);
35
+
36
+ const Assistant = new Agent({
37
+ name: 'Assistant',
38
+ role: Worker,
39
+ llm: { provider: "openai", model: "gpt-5.2" },
40
+ handlers: {
41
+ test_while: (() => {
42
+ const handler = async function(args) {
43
+ // This should not be called - playbook will be executed by LLM
44
+ throw new Error('Playbook-only handler called directly');
45
+ };
46
+ handler.__playbookOnly__ = true;
47
+ handler.__playbook__ = "Talk with the user until they say goodbye to you.\n Start the conversation by bringing up a topic of general interest, about politics, sports, science, whatever you prefer.\n Talk with the user until they express their intention to end the conversation, in which case say goodbye cordially and end the conversation.\n When you ask the user something, let them express themselves. Do not give them a set of options, instead let them express themselves freely.\n SUPER IMPORTANT, The first thing you must do is introduce yourself. Your name is Koi, so ask for their name and greet them cordially. Then start the conversation.";
48
+ handler.__description__ = "Introduce yourself as Koi, ask their name, chat freely until they say goodbye, then respond cordially.";
49
+ return handler;
50
+ })(),
51
+ }
52
+ });
53
+
54
+
55
+ // Main execution function
56
+ (async () => {
57
+ // Register agents with router
58
+ const { agentRouter } = await import('file:///Users/antonioparraga/Git/Koi-lang/Koi/src/runtime/router.js');
59
+
60
+ await agentRouter.register(Assistant, CACHED_AFFORDANCES['Assistant']);
61
+
62
+ // Execute
63
+ const result = await Assistant.handle('test_while', {});
64
+ // Result handled by actions
65
+
66
+ const _gracefulShutdown = async () => { await mcpRegistry.disconnectAll(); process.exit(0); };
67
+ process.on('SIGINT', _gracefulShutdown);
68
+ process.on('SIGTERM', _gracefulShutdown);
69
+
70
+ await mcpRegistry.disconnectAll();
71
+ process.exit(0);
72
+ })().catch(err => {
73
+ console.error('Error:', err.message);
74
+ process.exit(1);
75
+ });
76
+
77
+ //# sourceMappingURL=dialog-demo.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["dialog-demo.koi"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEA","file":"dialog-demo.koi.js"}