@lakitu/sdk 0.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 (111) hide show
  1. package/README.md +166 -0
  2. package/convex/_generated/api.d.ts +45 -0
  3. package/convex/_generated/api.js +23 -0
  4. package/convex/_generated/dataModel.d.ts +58 -0
  5. package/convex/_generated/server.d.ts +143 -0
  6. package/convex/_generated/server.js +93 -0
  7. package/convex/cloud/CLAUDE.md +238 -0
  8. package/convex/cloud/_generated/api.ts +84 -0
  9. package/convex/cloud/_generated/component.ts +861 -0
  10. package/convex/cloud/_generated/dataModel.ts +60 -0
  11. package/convex/cloud/_generated/server.ts +156 -0
  12. package/convex/cloud/convex.config.ts +16 -0
  13. package/convex/cloud/index.ts +29 -0
  14. package/convex/cloud/intentSchema/generate.ts +447 -0
  15. package/convex/cloud/intentSchema/index.ts +16 -0
  16. package/convex/cloud/intentSchema/types.ts +418 -0
  17. package/convex/cloud/ksaPolicy.ts +554 -0
  18. package/convex/cloud/mail.ts +92 -0
  19. package/convex/cloud/schema.ts +322 -0
  20. package/convex/cloud/utils/kanbanContext.ts +229 -0
  21. package/convex/cloud/workflows/agentBoard.ts +451 -0
  22. package/convex/cloud/workflows/agentPrompt.ts +272 -0
  23. package/convex/cloud/workflows/agentThread.ts +374 -0
  24. package/convex/cloud/workflows/compileSandbox.ts +146 -0
  25. package/convex/cloud/workflows/crudBoard.ts +217 -0
  26. package/convex/cloud/workflows/crudKSAs.ts +262 -0
  27. package/convex/cloud/workflows/crudLorobeads.ts +371 -0
  28. package/convex/cloud/workflows/crudSkills.ts +205 -0
  29. package/convex/cloud/workflows/crudThreads.ts +708 -0
  30. package/convex/cloud/workflows/lifecycleSandbox.ts +1396 -0
  31. package/convex/cloud/workflows/sandboxConvex.ts +1046 -0
  32. package/convex/sandbox/README.md +90 -0
  33. package/convex/sandbox/_generated/api.d.ts +2934 -0
  34. package/convex/sandbox/_generated/api.js +23 -0
  35. package/convex/sandbox/_generated/dataModel.d.ts +60 -0
  36. package/convex/sandbox/_generated/server.d.ts +143 -0
  37. package/convex/sandbox/_generated/server.js +93 -0
  38. package/convex/sandbox/actions/bash.ts +130 -0
  39. package/convex/sandbox/actions/browser.ts +282 -0
  40. package/convex/sandbox/actions/file.ts +336 -0
  41. package/convex/sandbox/actions/lsp.ts +325 -0
  42. package/convex/sandbox/actions/pdf.ts +119 -0
  43. package/convex/sandbox/agent/codeExecLoop.ts +535 -0
  44. package/convex/sandbox/agent/decisions.ts +284 -0
  45. package/convex/sandbox/agent/index.ts +515 -0
  46. package/convex/sandbox/agent/subagents.ts +651 -0
  47. package/convex/sandbox/brandResearch/index.ts +417 -0
  48. package/convex/sandbox/context/index.ts +7 -0
  49. package/convex/sandbox/context/session.ts +402 -0
  50. package/convex/sandbox/convex.config.ts +17 -0
  51. package/convex/sandbox/index.ts +51 -0
  52. package/convex/sandbox/nodeActions/codeExec.ts +130 -0
  53. package/convex/sandbox/planning/beads.ts +187 -0
  54. package/convex/sandbox/planning/index.ts +8 -0
  55. package/convex/sandbox/planning/sync.ts +194 -0
  56. package/convex/sandbox/prompts/codeExec.ts +852 -0
  57. package/convex/sandbox/prompts/modes.ts +231 -0
  58. package/convex/sandbox/prompts/system.ts +142 -0
  59. package/convex/sandbox/schema.ts +510 -0
  60. package/convex/sandbox/state/artifacts.ts +99 -0
  61. package/convex/sandbox/state/checkpoints.ts +341 -0
  62. package/convex/sandbox/state/files.ts +383 -0
  63. package/convex/sandbox/state/index.ts +10 -0
  64. package/convex/sandbox/state/verification.actions.ts +268 -0
  65. package/convex/sandbox/state/verification.ts +101 -0
  66. package/convex/sandbox/tsconfig.json +25 -0
  67. package/convex/sandbox/utils/codeExecHelpers.ts +52 -0
  68. package/dist/cli/commands/build.d.ts +19 -0
  69. package/dist/cli/commands/build.d.ts.map +1 -0
  70. package/dist/cli/commands/build.js +223 -0
  71. package/dist/cli/commands/init.d.ts +16 -0
  72. package/dist/cli/commands/init.d.ts.map +1 -0
  73. package/dist/cli/commands/init.js +148 -0
  74. package/dist/cli/commands/publish.d.ts +12 -0
  75. package/dist/cli/commands/publish.d.ts.map +1 -0
  76. package/dist/cli/commands/publish.js +33 -0
  77. package/dist/cli/index.d.ts +14 -0
  78. package/dist/cli/index.d.ts.map +1 -0
  79. package/dist/cli/index.js +40 -0
  80. package/dist/sdk/builders.d.ts +104 -0
  81. package/dist/sdk/builders.d.ts.map +1 -0
  82. package/dist/sdk/builders.js +214 -0
  83. package/dist/sdk/index.d.ts +29 -0
  84. package/dist/sdk/index.d.ts.map +1 -0
  85. package/dist/sdk/index.js +38 -0
  86. package/dist/sdk/types.d.ts +107 -0
  87. package/dist/sdk/types.d.ts.map +1 -0
  88. package/dist/sdk/types.js +6 -0
  89. package/ksa/README.md +263 -0
  90. package/ksa/_generated/REFERENCE.md +2954 -0
  91. package/ksa/_generated/registry.ts +257 -0
  92. package/ksa/_shared/configReader.ts +302 -0
  93. package/ksa/_shared/configSchemas.ts +649 -0
  94. package/ksa/_shared/gateway.ts +175 -0
  95. package/ksa/_shared/ksaBehaviors.ts +411 -0
  96. package/ksa/_shared/ksaProxy.ts +248 -0
  97. package/ksa/_shared/localDb.ts +302 -0
  98. package/ksa/index.ts +134 -0
  99. package/package.json +93 -0
  100. package/runtime/browser/agent-browser.ts +330 -0
  101. package/runtime/entrypoint.ts +194 -0
  102. package/runtime/lsp/manager.ts +366 -0
  103. package/runtime/pdf/pdf-generator.ts +50 -0
  104. package/runtime/pdf/renderer.ts +357 -0
  105. package/runtime/pdf/schema.ts +97 -0
  106. package/runtime/services/file-watcher.ts +191 -0
  107. package/template/build.ts +307 -0
  108. package/template/e2b/Dockerfile +69 -0
  109. package/template/e2b/e2b.toml +13 -0
  110. package/template/e2b/prebuild.sh +68 -0
  111. package/template/e2b/start.sh +14 -0
@@ -0,0 +1,238 @@
1
+ # Agent Orchestration System
2
+
3
+ This folder contains the agent orchestration layer that coordinates AI agents running in E2B sandboxes. It bridges the Jibe frontend with the Lakitu agent runtime.
4
+
5
+ ## Architecture Overview
6
+
7
+ ```
8
+ Frontend Request
9
+
10
+ ┌──────────────────────────────────────────────────┐
11
+ │ convex/agent/ │
12
+ │ │
13
+ │ ┌─────────────────┐ ┌─────────────────────┐ │
14
+ │ │ agentThread.ts │ │ agentPrompt.ts │ │
15
+ │ │ (Chat UI) │ │ (Simple prompts) │ │
16
+ │ └────────┬────────┘ └──────────┬──────────┘ │
17
+ │ │ │ │
18
+ │ └────────┬───────────────┘ │
19
+ │ ↓ │
20
+ │ ┌────────────────┐ │
21
+ │ │ agentBoard.ts │ ← Durable Workflow │
22
+ │ │ (Card Pipeline)│ │
23
+ │ └───────┬────────┘ │
24
+ │ ↓ │
25
+ │ ┌────────────────────────────────────────────┐ │
26
+ │ │ sandboxConvex.ts / lifecycleSandbox.ts │ │
27
+ │ │ (Sandbox Lifecycle Management) │ │
28
+ │ └────────────────────────────────────────────┘ │
29
+ └───────────────────────┬──────────────────────────┘
30
+
31
+ ┌─────────────────────┐
32
+ │ E2B Sandbox │
33
+ │ (Lakitu Runtime) │
34
+ └─────────────────────┘
35
+ ```
36
+
37
+ ## File Reference
38
+
39
+ | File | Purpose |
40
+ |------|---------|
41
+ | `index.ts` | Main exports - re-exports all CRUD modules and workflows |
42
+ | `mail.ts` | Inter-agent async messaging system |
43
+ | `workflows/agentBoard.ts` | **Core** - Durable workflow for card execution pipeline |
44
+ | `workflows/agentThread.ts` | Multi-turn chat interface with agents |
45
+ | `workflows/agentPrompt.ts` | One-off prompt execution (board planning, research) |
46
+ | `workflows/sandboxConvex.ts` | E2B sandbox + self-hosted Convex (current approach) |
47
+ | `workflows/lifecycleSandbox.ts` | E2B sandbox + OpenCode (legacy) |
48
+ | `workflows/crudThreads.ts` | Thread/conversation CRUD operations |
49
+ | `workflows/crudSkills.ts` | Skill definitions (tool bundles + prompts) |
50
+ | `workflows/crudBoard.ts` | AI-assisted board creation workflow |
51
+ | `workflows/crudLorobeads.ts` | Loro CRDT state sync and Beads issue tracking |
52
+ | `workflows/compileSandbox.ts` | Compilation manifest management |
53
+
54
+ ## Key Workflows
55
+
56
+ ### Card Execution (`agentBoard.ts`)
57
+
58
+ The main 5-step durable workflow for executing kanban cards:
59
+
60
+ 1. **Setup** - Load card, board, task; validate stage type
61
+ 2. **Run Agent** - Execute in Lakitu sandbox (poll for completion)
62
+ 3. **Save Artifacts** - Persist files to Convex storage
63
+ 4. **QA Check** - Verify deliverables are met
64
+ 5. **Advance/Block** - Move card to next stage or handle errors
65
+
66
+ ```typescript
67
+ // Entry point
68
+ agentBoard.startCardExecution({ cardId, userId })
69
+
70
+ // Cancel running workflow
71
+ agentBoard.stopCardExecution({ cardId, userId })
72
+ ```
73
+
74
+ ### Chat Threads (`agentThread.ts`)
75
+
76
+ Multi-turn conversations outside board workflows:
77
+
78
+ ```typescript
79
+ // Start new chat
80
+ agentThread.startThread({ prompt, userId })
81
+
82
+ // Continue conversation
83
+ agentThread.continueThread({ threadId, prompt })
84
+ ```
85
+
86
+ ### Simple Prompts (`agentPrompt.ts`)
87
+
88
+ One-off executions for quick tasks:
89
+
90
+ ```typescript
91
+ // Run any prompt
92
+ agentPrompt.runPrompt({ prompt, systemPrompt?, tools? })
93
+
94
+ // Board planning
95
+ agentPrompt.generateBoardPlan({ description })
96
+ agentPrompt.executeBoardPlan({ plan })
97
+
98
+ // Research queries
99
+ agentPrompt.runResearch({ query, depth: 'quick' | 'thorough' })
100
+ ```
101
+
102
+ ## Sandbox Management
103
+
104
+ ### Current: `sandboxConvex.ts`
105
+
106
+ Spawns E2B sandbox running self-hosted Convex backend:
107
+
108
+ 1. Creates session record in cloud Convex
109
+ 2. Spawns E2B sandbox with Lakitu template
110
+ 3. Deploys agent functions to sandbox Convex
111
+ 4. Starts agent thread via Convex client
112
+ 5. Polls stream deltas for real-time updates
113
+ 6. JWT auth for sandbox → cloud communication
114
+
115
+ ### Legacy: `lifecycleSandbox.ts`
116
+
117
+ Uses OpenCode HTTP API instead of self-hosted Convex. Kept for reference.
118
+
119
+ ## State Synchronization
120
+
121
+ ### Loro CRDT (`crudLorobeads.ts`)
122
+
123
+ Multi-agent state sync using Loro (conflict-free replicated data type):
124
+
125
+ - **Updates**: Incremental changes (push/get)
126
+ - **Snapshots**: Compacted state checkpoints
127
+ - **VFS Manifest**: Track sandbox file state
128
+
129
+ ### Beads Integration
130
+
131
+ Issue tracking synced between sandbox and cloud:
132
+
133
+ ```typescript
134
+ // Sync issue from sandbox
135
+ lorobeads.syncIssue({ cardId, issue })
136
+
137
+ // Get all issues for a card
138
+ lorobeads.getCardIssues({ cardId })
139
+ ```
140
+
141
+ ## Skills (`crudSkills.ts`)
142
+
143
+ Bundles of tools + prompts for specific capabilities:
144
+
145
+ - Custom skills per user/org stored in database
146
+ - Skills determine which tools an agent can use
147
+
148
+ ## Database Tables
149
+
150
+ | Table | Purpose |
151
+ |-------|---------|
152
+ | `cards` | Work items with context |
153
+ | `cardRuns` | Execution history per card |
154
+ | `boards` | Kanban boards |
155
+ | `boardTasks` | Workflow stages (agent/human) |
156
+ | `convexSandboxSessions` | Session records (sandboxConvex) |
157
+ | `convexSandboxLogs` | Real-time logs |
158
+ | `agentSessions` | Session records (legacy) |
159
+ | `agentSessionLogs` | Activity logs (legacy) |
160
+ | `threads` | Chat sessions per user |
161
+ | `threadMessages` | Message history |
162
+ | `agentConversations` | Project-level conversations |
163
+ | `skills` | Skill definitions |
164
+ | `customTools` | Custom tool implementations |
165
+ | `beadsLoroUpdates` | CRDT incremental updates |
166
+ | `beadsSnapshots` | Compacted state |
167
+ | `beadsIssues` | Synced issues |
168
+ | `compiledSandbox` | Compilation manifests |
169
+ | `agentMail` | Inter-agent messages |
170
+
171
+ ## Common Patterns
172
+
173
+ ### Polling for Completion
174
+
175
+ Sandboxes run async; we poll for completion:
176
+
177
+ ```typescript
178
+ // sandboxConvex.ts pattern
179
+ for (let i = 0; i < MAX_POLLS; i++) {
180
+ const session = await ctx.runQuery(internal.sessions.get, { sessionId })
181
+ if (session.status === 'completed') return session
182
+ if (session.status === 'failed') throw new Error(session.error)
183
+ await sleep(POLL_INTERVAL)
184
+ }
185
+ ```
186
+
187
+ ### Durable Workflows
188
+
189
+ Uses Convex Workflow for failure recovery:
190
+
191
+ ```typescript
192
+ // agentBoard.ts
193
+ export const cardExecutionWorkflow = workflow.define({
194
+ args: { cardId, userId },
195
+ handler: async (step, args) => {
196
+ // Step 1: Setup
197
+ const card = await step.runQuery(...)
198
+
199
+ // Step 2: Run Agent (survives function restarts)
200
+ const result = await step.runAction(...)
201
+
202
+ // Step 3: Save Artifacts
203
+ await step.runMutation(...)
204
+ }
205
+ })
206
+ ```
207
+
208
+ ### JWT Authentication
209
+
210
+ Sandbox authenticates to cloud via JWT:
211
+
212
+ ```typescript
213
+ // Generate JWT for sandbox
214
+ const jwt = signJwt({ sessionId, userId }, SANDBOX_JWT_SECRET)
215
+
216
+ // Sandbox includes JWT in requests to cloud gateway
217
+ fetch(`${CLOUD_URL}/agent/call`, {
218
+ headers: { Authorization: `Bearer ${jwt}` }
219
+ })
220
+ ```
221
+
222
+ ## Entry Points
223
+
224
+ **From Frontend** (via Convex API):
225
+ - `agentThread.sendMessage()` - Chat interface
226
+ - `agentPrompt.runPrompt()` - Direct execution
227
+ - `agentBoard.startCardExecution()` - Card workflows
228
+ - `crudBoard.generatePlan()` - Board planning
229
+
230
+ **From Gateway** (`convex/gateway.ts`):
231
+ - HTTP callbacks from sandboxes
232
+ - Stream delta forwarding
233
+ - LLM call proxying
234
+
235
+ ## Related Packages
236
+
237
+ - **packages/lakitu** - The agent runtime that runs inside E2B sandboxes
238
+ - **packages/primitives/agent** - Tool/skill metadata and sandbox template builder
@@ -0,0 +1,84 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as index from "../index.js";
12
+ import type * as intentSchema_generate from "../intentSchema/generate.js";
13
+ import type * as intentSchema_index from "../intentSchema/index.js";
14
+ import type * as intentSchema_types from "../intentSchema/types.js";
15
+ import type * as ksaPolicy from "../ksaPolicy.js";
16
+ import type * as mail from "../mail.js";
17
+ import type * as utils_kanbanContext from "../utils/kanbanContext.js";
18
+ import type * as workflows_agentBoard from "../workflows/agentBoard.js";
19
+ import type * as workflows_agentPrompt from "../workflows/agentPrompt.js";
20
+ import type * as workflows_agentThread from "../workflows/agentThread.js";
21
+ import type * as workflows_compileSandbox from "../workflows/compileSandbox.js";
22
+ import type * as workflows_crudBoard from "../workflows/crudBoard.js";
23
+ import type * as workflows_crudKSAs from "../workflows/crudKSAs.js";
24
+ import type * as workflows_crudLorobeads from "../workflows/crudLorobeads.js";
25
+ import type * as workflows_crudSkills from "../workflows/crudSkills.js";
26
+ import type * as workflows_crudThreads from "../workflows/crudThreads.js";
27
+ import type * as workflows_lifecycleSandbox from "../workflows/lifecycleSandbox.js";
28
+ import type * as workflows_sandboxConvex from "../workflows/sandboxConvex.js";
29
+
30
+ import type {
31
+ ApiFromModules,
32
+ FilterApi,
33
+ FunctionReference,
34
+ } from "convex/server";
35
+ import { anyApi, componentsGeneric } from "convex/server";
36
+
37
+ const fullApi: ApiFromModules<{
38
+ index: typeof index;
39
+ "intentSchema/generate": typeof intentSchema_generate;
40
+ "intentSchema/index": typeof intentSchema_index;
41
+ "intentSchema/types": typeof intentSchema_types;
42
+ ksaPolicy: typeof ksaPolicy;
43
+ mail: typeof mail;
44
+ "utils/kanbanContext": typeof utils_kanbanContext;
45
+ "workflows/agentBoard": typeof workflows_agentBoard;
46
+ "workflows/agentPrompt": typeof workflows_agentPrompt;
47
+ "workflows/agentThread": typeof workflows_agentThread;
48
+ "workflows/compileSandbox": typeof workflows_compileSandbox;
49
+ "workflows/crudBoard": typeof workflows_crudBoard;
50
+ "workflows/crudKSAs": typeof workflows_crudKSAs;
51
+ "workflows/crudLorobeads": typeof workflows_crudLorobeads;
52
+ "workflows/crudSkills": typeof workflows_crudSkills;
53
+ "workflows/crudThreads": typeof workflows_crudThreads;
54
+ "workflows/lifecycleSandbox": typeof workflows_lifecycleSandbox;
55
+ "workflows/sandboxConvex": typeof workflows_sandboxConvex;
56
+ }> = anyApi as any;
57
+
58
+ /**
59
+ * A utility for referencing Convex functions in your app's public API.
60
+ *
61
+ * Usage:
62
+ * ```js
63
+ * const myFunctionReference = api.myModule.myFunction;
64
+ * ```
65
+ */
66
+ export const api: FilterApi<
67
+ typeof fullApi,
68
+ FunctionReference<any, "public">
69
+ > = anyApi as any;
70
+
71
+ /**
72
+ * A utility for referencing Convex functions in your app's internal API.
73
+ *
74
+ * Usage:
75
+ * ```js
76
+ * const myFunctionReference = internal.myModule.myFunction;
77
+ * ```
78
+ */
79
+ export const internal: FilterApi<
80
+ typeof fullApi,
81
+ FunctionReference<any, "internal">
82
+ > = anyApi as any;
83
+
84
+ export const components = componentsGeneric() as unknown as {};