agentic-lang 0.2.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 (146) hide show
  1. package/COMMUNITY.md +220 -0
  2. package/CONTRIBUTING.md +194 -0
  3. package/FINAL_REPORT.md +398 -0
  4. package/FOR_OTHER_LLMS.md +286 -0
  5. package/IMPROVEMENTS.md +319 -0
  6. package/LAUNCH_GUIDE.md +388 -0
  7. package/LICENSE +21 -0
  8. package/NPM_PUBLISH.md +257 -0
  9. package/PROJECT_COMPLETE.md +414 -0
  10. package/PROJECT_OVERVIEW.md +265 -0
  11. package/PROJECT_TREE.txt +228 -0
  12. package/PUBLISHING_GUIDE.md +426 -0
  13. package/PUBLISH_NOW.md +337 -0
  14. package/QUICKSTART.md +207 -0
  15. package/README.md +195 -0
  16. package/README_ENHANCED.md +329 -0
  17. package/READY_TO_LAUNCH.txt +56 -0
  18. package/REFACTOR_PLAN.md +179 -0
  19. package/ROADMAP.md +201 -0
  20. package/SUMMARY.md +315 -0
  21. package/bin/agentic.js +3 -0
  22. package/blog/001-introducing-agentic.md +382 -0
  23. package/blog/002-confidence-driven-development.md +490 -0
  24. package/blog/003-formal-verification.md +427 -0
  25. package/blog/004-multi-agent-production.md +436 -0
  26. package/dist/cli.d.ts +7 -0
  27. package/dist/cli.d.ts.map +1 -0
  28. package/dist/cli.js +151 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/diagnostics/diagnostic.d.ts +115 -0
  31. package/dist/diagnostics/diagnostic.d.ts.map +1 -0
  32. package/dist/diagnostics/diagnostic.js +101 -0
  33. package/dist/diagnostics/diagnostic.js.map +1 -0
  34. package/dist/diagnostics/formatter.d.ts +36 -0
  35. package/dist/diagnostics/formatter.d.ts.map +1 -0
  36. package/dist/diagnostics/formatter.js +263 -0
  37. package/dist/diagnostics/formatter.js.map +1 -0
  38. package/dist/effects/effect-system.d.ts +64 -0
  39. package/dist/effects/effect-system.d.ts.map +1 -0
  40. package/dist/effects/effect-system.js +197 -0
  41. package/dist/effects/effect-system.js.map +1 -0
  42. package/dist/generator/typescript-generator.d.ts +31 -0
  43. package/dist/generator/typescript-generator.d.ts.map +1 -0
  44. package/dist/generator/typescript-generator.js +308 -0
  45. package/dist/generator/typescript-generator.js.map +1 -0
  46. package/dist/index.d.ts +19 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +60 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/lean4/exporter.d.ts +24 -0
  51. package/dist/lean4/exporter.d.ts.map +1 -0
  52. package/dist/lean4/exporter.js +142 -0
  53. package/dist/lean4/exporter.js.map +1 -0
  54. package/dist/lsp/server.d.ts +6 -0
  55. package/dist/lsp/server.d.ts.map +1 -0
  56. package/dist/lsp/server.js +131 -0
  57. package/dist/lsp/server.js.map +1 -0
  58. package/dist/parser/lexer.d.ts +79 -0
  59. package/dist/parser/lexer.d.ts.map +1 -0
  60. package/dist/parser/lexer.js +296 -0
  61. package/dist/parser/lexer.js.map +1 -0
  62. package/dist/parser/parser-enhanced.d.ts +12 -0
  63. package/dist/parser/parser-enhanced.d.ts.map +1 -0
  64. package/dist/parser/parser-enhanced.js +206 -0
  65. package/dist/parser/parser-enhanced.js.map +1 -0
  66. package/dist/parser/parser.d.ts +34 -0
  67. package/dist/parser/parser.d.ts.map +1 -0
  68. package/dist/parser/parser.js +507 -0
  69. package/dist/parser/parser.js.map +1 -0
  70. package/dist/property-tests/generator-enhanced.d.ts +27 -0
  71. package/dist/property-tests/generator-enhanced.d.ts.map +1 -0
  72. package/dist/property-tests/generator-enhanced.js +209 -0
  73. package/dist/property-tests/generator-enhanced.js.map +1 -0
  74. package/dist/property-tests/generator-fixed.d.ts +2 -0
  75. package/dist/property-tests/generator-fixed.d.ts.map +1 -0
  76. package/dist/property-tests/generator-fixed.js +7 -0
  77. package/dist/property-tests/generator-fixed.js.map +1 -0
  78. package/dist/property-tests/generator.d.ts +28 -0
  79. package/dist/property-tests/generator.d.ts.map +1 -0
  80. package/dist/property-tests/generator.js +284 -0
  81. package/dist/property-tests/generator.js.map +1 -0
  82. package/dist/refinements/refinement-types.d.ts +96 -0
  83. package/dist/refinements/refinement-types.d.ts.map +1 -0
  84. package/dist/refinements/refinement-types.js +234 -0
  85. package/dist/refinements/refinement-types.js.map +1 -0
  86. package/dist/repl.d.ts +21 -0
  87. package/dist/repl.d.ts.map +1 -0
  88. package/dist/repl.js +317 -0
  89. package/dist/repl.js.map +1 -0
  90. package/dist/runtime/agents.d.ts +97 -0
  91. package/dist/runtime/agents.d.ts.map +1 -0
  92. package/dist/runtime/agents.js +258 -0
  93. package/dist/runtime/agents.js.map +1 -0
  94. package/dist/runtime/index.d.ts +98 -0
  95. package/dist/runtime/index.d.ts.map +1 -0
  96. package/dist/runtime/index.js +253 -0
  97. package/dist/runtime/index.js.map +1 -0
  98. package/dist/types-extended.d.ts +197 -0
  99. package/dist/types-extended.d.ts.map +1 -0
  100. package/dist/types-extended.js +7 -0
  101. package/dist/types-extended.js.map +1 -0
  102. package/dist/types.d.ts +129 -0
  103. package/dist/types.d.ts.map +1 -0
  104. package/dist/types.js +6 -0
  105. package/dist/types.js.map +1 -0
  106. package/dist/verification/z3-engine.d.ts +75 -0
  107. package/dist/verification/z3-engine.d.ts.map +1 -0
  108. package/dist/verification/z3-engine.js +234 -0
  109. package/dist/verification/z3-engine.js.map +1 -0
  110. package/examples/advanced-features.agentic +98 -0
  111. package/examples/annotations.agentic +37 -0
  112. package/examples/auth.agentic +53 -0
  113. package/examples/enterprise-example.agentic +360 -0
  114. package/examples/minimal.agentic +3 -0
  115. package/examples/minimal.ts +7 -0
  116. package/examples/ml-pipeline.agentic +350 -0
  117. package/examples/multi-agent-example.agentic +212 -0
  118. package/examples/onboarding-tutorial.agentic +263 -0
  119. package/examples/production-api.agentic +304 -0
  120. package/examples/real-world-chatbot.agentic +351 -0
  121. package/examples/result-handling.agentic +34 -0
  122. package/examples/runtime.ts +24 -0
  123. package/examples/showcase.agentic +22 -0
  124. package/examples/showcase.ts +28 -0
  125. package/examples/simple-test.agentic +4 -0
  126. package/examples/simple-test.ts +7 -0
  127. package/examples/simple.agentic +20 -0
  128. package/examples/test2.agentic +4 -0
  129. package/examples/test2.ts +9 -0
  130. package/examples/test3.agentic +4 -0
  131. package/examples/test3.ts +9 -0
  132. package/package.json +70 -0
  133. package/playground/index.html +221 -0
  134. package/playground/playground.js +291 -0
  135. package/registry/package-registry.ts +319 -0
  136. package/scripts/build.js +50 -0
  137. package/scripts/validate-confidence-mutation.ts +112 -0
  138. package/stdlib/async/promise.agentic +216 -0
  139. package/stdlib/database/pool.agentic +235 -0
  140. package/stdlib/file/io.agentic +194 -0
  141. package/stdlib/http/client.agentic +168 -0
  142. package/video-scripts/001-agentic-in-100-seconds.md +175 -0
  143. package/vscode-extension/README.md +67 -0
  144. package/vscode-extension/language-configuration.json +31 -0
  145. package/vscode-extension/package.json +46 -0
  146. package/vscode-extension/syntaxes/agentic.tmLanguage.json +134 -0
@@ -0,0 +1,22 @@
1
+ // Agentic Language Showcase
2
+ // Demonstrates key features
3
+
4
+ @confidence(0.95)
5
+ @complete
6
+ func divide(a: number, b: number) -> number {
7
+ if b == 0 {
8
+ return 0
9
+ }
10
+ return a / b
11
+ }
12
+
13
+ @stub
14
+ func notImplemented() -> number {
15
+ return 42
16
+ }
17
+
18
+ @partial
19
+ @confidence(0.70)
20
+ func experimental(x: number) -> number {
21
+ return x * 2
22
+ }
@@ -0,0 +1,28 @@
1
+ // Auto-generated from examples/showcase.agentic
2
+ import { AgenticRuntime, Result, Ok, Err } from './runtime';
3
+
4
+ // @confidence({"arg0":0.95})
5
+ // @complete
6
+ function divide(a: number, b: number): number {
7
+ AgenticRuntime.confidence.register('divide', 0.95, 'No reason provided');
8
+ // Stage: complete
9
+ if (b == 0) {
10
+ return 0;
11
+ }
12
+ return a / b;
13
+ }
14
+
15
+ // @stub
16
+ function notImplemented(): number {
17
+ // Stage: stub
18
+ throw new Error('Function notImplemented is a stub - not yet implemented');
19
+ }
20
+
21
+ // @partial
22
+ // @confidence({"arg0":0.7})
23
+ function experimental(x: number): number {
24
+ AgenticRuntime.confidence.register('experimental', 0.7, 'No reason provided');
25
+ // Stage: partial
26
+ return x * 2;
27
+ }
28
+
@@ -0,0 +1,4 @@
1
+ // Simple test
2
+ func test(x: number) -> number {
3
+ return x
4
+ }
@@ -0,0 +1,7 @@
1
+ // Auto-generated from examples/simple-test.agentic
2
+ import { AgenticRuntime, Result, Ok, Err } from './runtime';
3
+
4
+ function test(x: number): number {
5
+ return x;
6
+ }
7
+
@@ -0,0 +1,20 @@
1
+ // Simple example demonstrating basic syntax
2
+
3
+ @confidence(0.95)
4
+ func add(a: number, b: number) -> number {
5
+ return a + b
6
+ }
7
+
8
+ @confidence(0.85)
9
+ func greet(name: string) -> string {
10
+ if name.isEmpty() {
11
+ return "Hello, stranger!"
12
+ }
13
+
14
+ return "Hello, " + name + "!"
15
+ }
16
+
17
+ @stub("Not implemented yet")
18
+ func complexCalculation(input: number) -> Result<number, Error> {
19
+ // TODO: Implement complex logic
20
+ }
@@ -0,0 +1,4 @@
1
+ @confidence(0.95)
2
+ func divide(a: number, b: number) -> number {
3
+ return a / b
4
+ }
@@ -0,0 +1,9 @@
1
+ // Auto-generated from examples/test2.agentic
2
+ import { AgenticRuntime, Result, Ok, Err } from './runtime';
3
+
4
+ // @confidence({"arg0":0.95})
5
+ function divide(a: number, b: number): number {
6
+ AgenticRuntime.confidence.register('divide', 0.95, 'No reason provided');
7
+ return a / b;
8
+ }
9
+
@@ -0,0 +1,4 @@
1
+ @confidence(0.95, "test")
2
+ func test() -> number {
3
+ return 1
4
+ }
@@ -0,0 +1,9 @@
1
+ // Auto-generated from examples/test3.agentic
2
+ import { AgenticRuntime, Result, Ok, Err } from './runtime';
3
+
4
+ // @confidence({"arg0":0.95,"arg1":"test"})
5
+ function test(): number {
6
+ AgenticRuntime.confidence.register('test', 0.95, 'test');
7
+ return 1;
8
+ }
9
+
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "agentic-lang",
3
+ "version": "0.2.0",
4
+ "description": "The world's first AI-native programming language with verified confidence, formal verification, and multi-agent primitives. Built for autonomous agents.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "agentic": "./bin/agentic.js",
9
+ "agentic-lsp": "./dist/lsp/server.js"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "watch": "tsc --watch",
14
+ "test": "vitest",
15
+ "dev": "ts-node src/cli.ts",
16
+ "example": "npm run build && node bin/agentic.js compile examples/auth.agentic --output examples/auth.ts"
17
+ },
18
+ "keywords": [
19
+ "programming-language",
20
+ "ai-native",
21
+ "formal-verification",
22
+ "multi-agent",
23
+ "confidence-tracking",
24
+ "property-based-testing",
25
+ "mutation-testing",
26
+ "z3-solver",
27
+ "session-types",
28
+ "effect-system",
29
+ "llm",
30
+ "ai-agents",
31
+ "autonomous-agents",
32
+ "typescript-compiler",
33
+ "transpiler",
34
+ "verified-code"
35
+ ],
36
+ "author": "Agentic Language Team",
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/VyasSathya/AgenticLang.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/VyasSathya/AgenticLang/issues"
44
+ },
45
+ "homepage": "https://github.com/VyasSathya/AgenticLang#readme",
46
+ "dependencies": {
47
+ "chokidar": "^3.6.0",
48
+ "commander": "^12.0.0",
49
+ "source-map": "^0.7.4",
50
+ "tree-sitter": "^0.21.0",
51
+ "tree-sitter-typescript": "^0.21.0",
52
+ "vscode-languageserver": "^9.0.1",
53
+ "vscode-languageserver-textdocument": "^1.0.12",
54
+ "z3-solver": "^4.15.4",
55
+ "zod": "^4.3.6"
56
+ },
57
+ "devDependencies": {
58
+ "@fast-check/vitest": "^0.1.0",
59
+ "@stryker-mutator/core": "^9.4.0",
60
+ "@stryker-mutator/typescript-checker": "^9.4.0",
61
+ "@types/node": "^20.11.5",
62
+ "@types/source-map": "^0.5.7",
63
+ "eslint-plugin-functional": "^9.0.2",
64
+ "fast-check": "^3.15.0",
65
+ "ts-node": "^10.9.2",
66
+ "typedoc": "^0.28.16",
67
+ "typescript": "^5.3.3",
68
+ "vitest": "^1.2.0"
69
+ }
70
+ }
@@ -0,0 +1,221 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Agentic Playground - Try AI-Native Programming in Your Browser</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
16
+ height: 100vh;
17
+ display: flex;
18
+ flex-direction: column;
19
+ background: #1e1e1e;
20
+ color: #d4d4d4;
21
+ }
22
+
23
+ .header {
24
+ background: #252526;
25
+ padding: 1rem 2rem;
26
+ border-bottom: 1px solid #3e3e42;
27
+ display: flex;
28
+ justify-content: space-between;
29
+ align-items: center;
30
+ }
31
+
32
+ .header h1 {
33
+ font-size: 1.5rem;
34
+ color: #4ec9b0;
35
+ }
36
+
37
+ .header .buttons {
38
+ display: flex;
39
+ gap: 1rem;
40
+ }
41
+
42
+ .btn {
43
+ padding: 0.5rem 1rem;
44
+ background: #0e639c;
45
+ color: white;
46
+ border: none;
47
+ border-radius: 4px;
48
+ cursor: pointer;
49
+ font-size: 0.9rem;
50
+ transition: background 0.2s;
51
+ }
52
+
53
+ .btn:hover {
54
+ background: #1177bb;
55
+ }
56
+
57
+ .btn.success {
58
+ background: #388a34;
59
+ }
60
+
61
+ .btn.success:hover {
62
+ background: #4caf50;
63
+ }
64
+
65
+ .container {
66
+ flex: 1;
67
+ display: grid;
68
+ grid-template-columns: 1fr 1fr;
69
+ gap: 0;
70
+ overflow: hidden;
71
+ }
72
+
73
+ .panel {
74
+ display: flex;
75
+ flex-direction: column;
76
+ border-right: 1px solid #3e3e42;
77
+ }
78
+
79
+ .panel:last-child {
80
+ border-right: none;
81
+ }
82
+
83
+ .panel-header {
84
+ background: #2d2d30;
85
+ padding: 0.75rem 1rem;
86
+ border-bottom: 1px solid #3e3e42;
87
+ font-weight: 600;
88
+ color: #cccccc;
89
+ }
90
+
91
+ .editor-container {
92
+ flex: 1;
93
+ position: relative;
94
+ }
95
+
96
+ #agentic-editor,
97
+ #typescript-output {
98
+ position: absolute;
99
+ top: 0;
100
+ left: 0;
101
+ right: 0;
102
+ bottom: 0;
103
+ }
104
+
105
+ .console {
106
+ background: #1e1e1e;
107
+ color: #cccccc;
108
+ padding: 1rem;
109
+ font-family: 'Consolas', 'Courier New', monospace;
110
+ font-size: 0.85rem;
111
+ overflow-y: auto;
112
+ height: 200px;
113
+ border-top: 1px solid #3e3e42;
114
+ }
115
+
116
+ .console-line {
117
+ margin-bottom: 0.5rem;
118
+ }
119
+
120
+ .console-line.error {
121
+ color: #f48771;
122
+ }
123
+
124
+ .console-line.success {
125
+ color: #4ec9b0;
126
+ }
127
+
128
+ .console-line.warning {
129
+ color: #dcdcaa;
130
+ }
131
+
132
+ .examples {
133
+ background: #252526;
134
+ padding: 0.5rem 1rem;
135
+ border-bottom: 1px solid #3e3e42;
136
+ display: flex;
137
+ gap: 0.5rem;
138
+ flex-wrap: wrap;
139
+ }
140
+
141
+ .example-btn {
142
+ padding: 0.25rem 0.75rem;
143
+ background: #3e3e42;
144
+ color: #cccccc;
145
+ border: 1px solid #555;
146
+ border-radius: 3px;
147
+ cursor: pointer;
148
+ font-size: 0.8rem;
149
+ }
150
+
151
+ .example-btn:hover {
152
+ background: #505050;
153
+ }
154
+
155
+ .footer {
156
+ background: #252526;
157
+ padding: 0.5rem 2rem;
158
+ border-top: 1px solid #3e3e42;
159
+ text-align: center;
160
+ font-size: 0.85rem;
161
+ }
162
+
163
+ .footer a {
164
+ color: #4ec9b0;
165
+ text-decoration: none;
166
+ }
167
+
168
+ .footer a:hover {
169
+ text-decoration: underline;
170
+ }
171
+ </style>
172
+ </head>
173
+ <body>
174
+ <div class="header">
175
+ <h1>⚡ Agentic Playground</h1>
176
+ <div class="buttons">
177
+ <button class="btn" id="compile-btn">▶ Compile</button>
178
+ <button class="btn success" id="share-btn">🔗 Share</button>
179
+ </div>
180
+ </div>
181
+
182
+ <div class="examples">
183
+ <button class="example-btn" data-example="hello">Hello World</button>
184
+ <button class="example-btn" data-example="confidence">Confidence Tracking</button>
185
+ <button class="example-btn" data-example="result">Result Types</button>
186
+ <button class="example-btn" data-example="stages">Incremental Stages</button>
187
+ <button class="example-btn" data-example="agents">Multi-Agent</button>
188
+ <button class="example-btn" data-example="verification">Formal Verification</button>
189
+ </div>
190
+
191
+ <div class="container">
192
+ <div class="panel">
193
+ <div class="panel-header">Agentic Code</div>
194
+ <div class="editor-container">
195
+ <div id="agentic-editor"></div>
196
+ </div>
197
+ </div>
198
+ <div class="panel">
199
+ <div class="panel-header">Generated TypeScript</div>
200
+ <div class="editor-container">
201
+ <div id="typescript-output"></div>
202
+ </div>
203
+ </div>
204
+ </div>
205
+
206
+ <div class="console" id="console">
207
+ <div class="console-line success">✓ Agentic Playground Ready</div>
208
+ <div class="console-line">Click "Compile" or press Ctrl+Enter to transpile</div>
209
+ </div>
210
+
211
+ <div class="footer">
212
+ Made with ❤️ for AI Agents |
213
+ <a href="https://github.com/agentic-lang/agentic">GitHub</a> |
214
+ <a href="https://agentic-lang.org/docs">Docs</a> |
215
+ <a href="https://discord.gg/agentic">Discord</a>
216
+ </div>
217
+
218
+ <script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs/loader.js"></script>
219
+ <script src="./playground.js"></script>
220
+ </body>
221
+ </html>
@@ -0,0 +1,291 @@
1
+ // Agentic Playground - Interactive Browser REPL
2
+
3
+ // Example code snippets
4
+ const examples = {
5
+ hello: `@confidence(0.99)
6
+ @complete
7
+ func greet(name: string) -> string {
8
+ return "Hello, " + name + "!"
9
+ }`,
10
+
11
+ confidence: `@confidence(0.95)
12
+ @complete
13
+ func safeDivide(a: number, b: number) -> Result<number, string> {
14
+ if b == 0 {
15
+ return Err("Division by zero")
16
+ }
17
+ return Ok(a / b)
18
+ }
19
+
20
+ @confidence(0.65)
21
+ @uncertain("Complex date formats not fully handled")
22
+ @partial
23
+ func parseDate(input: string) -> Result<Date, ParseError> {
24
+ // Only handles ISO format
25
+ return Date.parse(input)
26
+ }`,
27
+
28
+ result: `@confidence(0.92)
29
+ @needs(database: Database)
30
+ func findUser(id: string) -> Result<User, DatabaseError> {
31
+ user = database.users.find(id) match {
32
+ Ok(user) -> user,
33
+ Err(e) -> {
34
+ @context {
35
+ what_failed: "User lookup",
36
+ suggestions: ["Verify user exists", "Check database connection"],
37
+ recovery: { action: "create_user" }
38
+ }
39
+ return Err(DatabaseError.NOT_FOUND)
40
+ }
41
+ }
42
+
43
+ return Ok(user)
44
+ }`,
45
+
46
+ stages: `// Stage 1: Stub
47
+ @stub("Not implemented yet")
48
+ @confidence(0.00)
49
+ func authenticate(token: string) -> Result<User, AuthError>
50
+
51
+ // Stage 2: Partial
52
+ @partial("Only handles happy path")
53
+ @confidence(0.60)
54
+ func authenticate(token: string) -> Result<User, AuthError> {
55
+ decoded = jwt.decode(token)
56
+ return Ok(User.fromDict(decoded))
57
+ }
58
+
59
+ // Stage 3: Complete
60
+ @complete
61
+ @confidence(0.95)
62
+ @property("rejects empty tokens")
63
+ @property("rejects invalid tokens")
64
+ func authenticate(token: string) -> Result<User, AuthError> {
65
+ if token.isEmpty() { return Err(AuthError.MISSING_TOKEN) }
66
+ decoded = jwt.decode(token) match {
67
+ Ok(payload) -> payload,
68
+ Err(e) -> return Err(AuthError.INVALID_TOKEN)
69
+ }
70
+ return Ok(User.fromDict(decoded))
71
+ }`,
72
+
73
+ agents: `@agent(role: "planner")
74
+ agent PlannerAgent {
75
+ inbox: Channel<TaskRequest>
76
+ outbox: Channel<TaskPlan>
77
+
78
+ @handler("task_request")
79
+ @confidence(0.88)
80
+ func plan(request: TaskRequest) -> TaskPlan {
81
+ steps = analyzeAndDecompose(request)
82
+ return TaskPlan { steps: steps, estimatedTime: estimate(steps) }
83
+ }
84
+ }
85
+
86
+ @session_aware
87
+ @checkpoint_interval(5m)
88
+ func collaborativeWorkflow() -> Result<Output, Error> {
89
+ @checkpoint("planning")
90
+ plan = planner.request(task)
91
+
92
+ @checkpoint("execution")
93
+ result = executor.execute(plan)
94
+
95
+ return Ok(result)
96
+ }`,
97
+
98
+ verification: `@verify(solver: "z3")
99
+ @requires(x > 0)
100
+ @ensures(result > 0)
101
+ @confidence(0.99)
102
+ func sqrt(x: number) -> number {
103
+ return Math.sqrt(x)
104
+ }
105
+
106
+ @contract {
107
+ requires: { b: "b != 0" },
108
+ ensures: { result: "result == a / b" }
109
+ }
110
+ @property("division by zero returns error")
111
+ @complete
112
+ func divide(a: number, b: number) -> Result<number, string> {
113
+ if b == 0 { return Err("Division by zero") }
114
+ return Ok(a / b)
115
+ }`
116
+ };
117
+
118
+ // Initialize Monaco Editor
119
+ require.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs' } });
120
+
121
+ let agenticEditor;
122
+ let typescriptEditor;
123
+
124
+ require(['vs/editor/editor.main'], function () {
125
+ // Register Agentic language
126
+ monaco.languages.register({ id: 'agentic' });
127
+
128
+ // Define Agentic syntax highlighting
129
+ monaco.languages.setMonarchTokensProvider('agentic', {
130
+ keywords: [
131
+ 'func', 'return', 'if', 'else', 'match', 'or', 'error',
132
+ 'let', 'const', 'type', 'agent', 'workflow', 'session'
133
+ ],
134
+ annotations: [
135
+ 'confidence', 'stub', 'partial', 'complete', 'needs', 'uncertain',
136
+ 'property', 'verify', 'requires', 'ensures', 'contract',
137
+ 'agent', 'handler', 'session_aware', 'checkpoint', 'handoff'
138
+ ],
139
+ operators: ['->', '=>', '==', '!=', '<', '>', '<=', '>=', '+', '-', '*', '/'],
140
+ tokenizer: {
141
+ root: [
142
+ [/@[a-z_]+/, 'annotation'],
143
+ [/\b(func|return|if|else|match|or|error|let|const|type|agent|workflow|session)\b/, 'keyword'],
144
+ [/\b(Result|Ok|Err|Channel|Agent)\b/, 'type'],
145
+ [/\b[A-Z][a-zA-Z0-9]*\b/, 'type'],
146
+ [/\b\d+\.?\d*\b/, 'number'],
147
+ [/"([^"\\]|\\.)*$/, 'string.invalid'],
148
+ [/"/, 'string', '@string'],
149
+ [/\/\/.*$/, 'comment'],
150
+ ],
151
+ string: [
152
+ [/[^\\"]+/, 'string'],
153
+ [/"/, 'string', '@pop']
154
+ ]
155
+ }
156
+ });
157
+
158
+ // Create editors
159
+ agenticEditor = monaco.editor.create(document.getElementById('agentic-editor'), {
160
+ value: examples.hello,
161
+ language: 'agentic',
162
+ theme: 'vs-dark',
163
+ minimap: { enabled: false },
164
+ fontSize: 14,
165
+ lineNumbers: 'on',
166
+ roundedSelection: false,
167
+ scrollBeyondLastLine: false,
168
+ automaticLayout: true,
169
+ });
170
+
171
+ typescriptEditor = monaco.editor.create(document.getElementById('typescript-output'), {
172
+ value: '// Click "Compile" to see generated TypeScript',
173
+ language: 'typescript',
174
+ theme: 'vs-dark',
175
+ readOnly: true,
176
+ minimap: { enabled: false },
177
+ fontSize: 14,
178
+ automaticLayout: true,
179
+ });
180
+
181
+ // Compile on Ctrl+Enter
182
+ agenticEditor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, compileCode);
183
+ });
184
+
185
+ // Compile button
186
+ document.getElementById('compile-btn').addEventListener('click', compileCode);
187
+
188
+ // Example buttons
189
+ document.querySelectorAll('.example-btn').forEach(btn => {
190
+ btn.addEventListener('click', () => {
191
+ const example = btn.getAttribute('data-example');
192
+ if (examples[example]) {
193
+ agenticEditor.setValue(examples[example]);
194
+ compileCode();
195
+ }
196
+ });
197
+ });
198
+
199
+ // Share button
200
+ document.getElementById('share-btn').addEventListener('click', () => {
201
+ const code = agenticEditor.getValue();
202
+ const encoded = btoa(encodeURIComponent(code));
203
+ const url = `${window.location.origin}${window.location.pathname}?code=${encoded}`;
204
+
205
+ navigator.clipboard.writeText(url).then(() => {
206
+ log('success', '✓ Share link copied to clipboard!');
207
+ });
208
+ });
209
+
210
+ // Load from URL parameter
211
+ window.addEventListener('load', () => {
212
+ const params = new URLSearchParams(window.location.search);
213
+ const code = params.get('code');
214
+
215
+ if (code) {
216
+ try {
217
+ const decoded = decodeURIComponent(atob(code));
218
+ agenticEditor.setValue(decoded);
219
+ compileCode();
220
+ } catch (e) {
221
+ log('error', 'Failed to load code from URL');
222
+ }
223
+ }
224
+ });
225
+
226
+ function compileCode() {
227
+ const agenticCode = agenticEditor.getValue();
228
+
229
+ log('info', '⚙️ Compiling...');
230
+
231
+ try {
232
+ // Simulate compilation (in production, call actual Agentic compiler)
233
+ const tsCode = mockCompile(agenticCode);
234
+
235
+ typescriptEditor.setValue(tsCode);
236
+ log('success', '✓ Compilation successful!');
237
+
238
+ // Extract and display confidence warnings
239
+ checkConfidence(agenticCode);
240
+
241
+ } catch (error) {
242
+ log('error', `✗ Compilation failed: ${error.message}`);
243
+ typescriptEditor.setValue(`// Compilation error:\n// ${error.message}`);
244
+ }
245
+ }
246
+
247
+ function mockCompile(agenticCode) {
248
+ // This is a mock compiler for the playground
249
+ // In production, this would call the actual Agentic transpiler via WASM
250
+
251
+ let tsCode = '// Auto-generated from Agentic\n';
252
+ tsCode += "import { Result, Ok, Err } from '@agentic/runtime';\n\n";
253
+
254
+ // Extract function declarations (very basic parsing)
255
+ const funcRegex = /func\s+(\w+)\s*\(([^)]*)\)\s*->\s*([^\{]+)\{/g;
256
+ let match;
257
+
258
+ while ((match = funcRegex.exec(agenticCode)) !== null) {
259
+ const [, name, params, returnType] = match;
260
+
261
+ tsCode += `export function ${name}(${params}): ${returnType.trim()} {\n`;
262
+ tsCode += ` // Implementation\n`;
263
+ tsCode += `}\n\n`;
264
+ }
265
+
266
+ return tsCode;
267
+ }
268
+
269
+ function checkConfidence(agenticCode) {
270
+ const confidenceRegex = /@confidence\(([\d.]+)\)/g;
271
+ let match;
272
+
273
+ while ((match = confidenceRegex.exec(agenticCode)) !== null) {
274
+ const confidence = parseFloat(match[1]);
275
+
276
+ if (confidence < 0.80) {
277
+ log('warning', `⚠️ Low confidence detected: ${confidence}`);
278
+ } else if (confidence >= 0.95) {
279
+ log('success', `✓ High confidence: ${confidence}`);
280
+ }
281
+ }
282
+ }
283
+
284
+ function log(type, message) {
285
+ const consoleEl = document.getElementById('console');
286
+ const line = document.createElement('div');
287
+ line.className = `console-line ${type}`;
288
+ line.textContent = message;
289
+ consoleEl.appendChild(line);
290
+ consoleEl.scrollTop = consoleEl.scrollHeight;
291
+ }