@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,284 @@
1
+ /**
2
+ * Decisions - Intentional Tool Calling & Decision Logging
3
+ *
4
+ * Log agent decisions for transparency and debugging.
5
+ * Track tool selection reasoning and expected outcomes.
6
+ */
7
+
8
+ import { mutation, query } from "../_generated/server";
9
+ import { v } from "convex/values";
10
+
11
+ // ============================================
12
+ // Mutations
13
+ // ============================================
14
+
15
+ /**
16
+ * Log a decision
17
+ */
18
+ export const log = mutation({
19
+ args: {
20
+ threadId: v.string(),
21
+ task: v.string(),
22
+ decisionType: v.union(
23
+ v.literal("tool_selection"),
24
+ v.literal("file_edit"),
25
+ v.literal("task_breakdown"),
26
+ v.literal("verification"),
27
+ v.literal("rollback"),
28
+ v.literal("checkpoint"),
29
+ v.literal("error_recovery")
30
+ ),
31
+ selectedTools: v.optional(v.array(v.string())),
32
+ reasoning: v.string(),
33
+ expectedOutcome: v.optional(v.string()),
34
+ alternatives: v.optional(
35
+ v.array(
36
+ v.object({
37
+ option: v.string(),
38
+ reason: v.string(),
39
+ })
40
+ )
41
+ ),
42
+ confidence: v.optional(v.number()), // 0-1
43
+ metadata: v.optional(v.any()),
44
+ },
45
+ handler: async (ctx, args) => {
46
+ return await ctx.db.insert("agentDecisions", {
47
+ threadId: args.threadId,
48
+ task: args.task,
49
+ decisionType: args.decisionType,
50
+ selectedTools: args.selectedTools,
51
+ reasoning: args.reasoning,
52
+ expectedOutcome: args.expectedOutcome,
53
+ alternatives: args.alternatives,
54
+ confidence: args.confidence,
55
+ metadata: args.metadata,
56
+ timestamp: Date.now(),
57
+ // Outcome tracking - use undefined instead of null
58
+ outcome: undefined,
59
+ outcomeRecordedAt: undefined,
60
+ });
61
+ },
62
+ });
63
+
64
+ /**
65
+ * Record the outcome of a decision
66
+ */
67
+ export const recordOutcome = mutation({
68
+ args: {
69
+ id: v.id("agentDecisions"),
70
+ outcome: v.union(
71
+ v.literal("success"),
72
+ v.literal("partial_success"),
73
+ v.literal("failure"),
74
+ v.literal("abandoned")
75
+ ),
76
+ actualResult: v.optional(v.string()),
77
+ notes: v.optional(v.string()),
78
+ },
79
+ handler: async (ctx, args) => {
80
+ await ctx.db.patch(args.id, {
81
+ outcome: args.outcome,
82
+ actualResult: args.actualResult,
83
+ outcomeNotes: args.notes,
84
+ outcomeRecordedAt: Date.now(),
85
+ });
86
+ },
87
+ });
88
+
89
+ /**
90
+ * Log a tool execution
91
+ */
92
+ export const logToolExecution = mutation({
93
+ args: {
94
+ decisionId: v.optional(v.id("agentDecisions")),
95
+ threadId: v.string(),
96
+ toolName: v.string(),
97
+ input: v.any(),
98
+ output: v.optional(v.any()),
99
+ success: v.boolean(),
100
+ durationMs: v.number(),
101
+ error: v.optional(v.string()),
102
+ },
103
+ handler: async (ctx, args) => {
104
+ return await ctx.db.insert("toolExecutions", {
105
+ decisionId: args.decisionId,
106
+ threadId: args.threadId,
107
+ toolName: args.toolName,
108
+ input: args.input,
109
+ output: args.output,
110
+ success: args.success,
111
+ durationMs: args.durationMs,
112
+ error: args.error,
113
+ timestamp: Date.now(),
114
+ });
115
+ },
116
+ });
117
+
118
+ // ============================================
119
+ // Queries
120
+ // ============================================
121
+
122
+ /**
123
+ * Get decisions for a thread
124
+ */
125
+ export const getByThread = query({
126
+ args: {
127
+ threadId: v.string(),
128
+ limit: v.optional(v.number()),
129
+ },
130
+ handler: async (ctx, args) => {
131
+ return await ctx.db
132
+ .query("agentDecisions")
133
+ .withIndex("by_thread", (q) => q.eq("threadId", args.threadId))
134
+ .order("desc")
135
+ .take(args.limit ?? 50);
136
+ },
137
+ });
138
+
139
+ /**
140
+ * Get recent decisions across all threads
141
+ */
142
+ export const getRecent = query({
143
+ args: { limit: v.optional(v.number()) },
144
+ handler: async (ctx, args) => {
145
+ return await ctx.db
146
+ .query("agentDecisions")
147
+ .order("desc")
148
+ .take(args.limit ?? 100);
149
+ },
150
+ });
151
+
152
+ /**
153
+ * Get tool executions for a thread
154
+ */
155
+ export const getToolExecutions = query({
156
+ args: {
157
+ threadId: v.string(),
158
+ limit: v.optional(v.number()),
159
+ },
160
+ handler: async (ctx, args) => {
161
+ return await ctx.db
162
+ .query("toolExecutions")
163
+ .withIndex("by_thread", (q) => q.eq("threadId", args.threadId))
164
+ .order("desc")
165
+ .take(args.limit ?? 100);
166
+ },
167
+ });
168
+
169
+ /**
170
+ * Get decision stats
171
+ */
172
+ export const getStats = query({
173
+ args: { threadId: v.optional(v.string()) },
174
+ handler: async (ctx, args) => {
175
+ const { threadId } = args;
176
+ const decisions = threadId
177
+ ? await ctx.db
178
+ .query("agentDecisions")
179
+ .withIndex("by_thread", (q) => q.eq("threadId", threadId))
180
+ .collect()
181
+ : await ctx.db.query("agentDecisions").collect();
182
+
183
+ const byType: Record<string, number> = {};
184
+ const byOutcome: Record<string, number> = {
185
+ success: 0,
186
+ partial_success: 0,
187
+ failure: 0,
188
+ abandoned: 0,
189
+ pending: 0,
190
+ };
191
+
192
+ let totalConfidence = 0;
193
+ let confidenceCount = 0;
194
+
195
+ for (const decision of decisions) {
196
+ byType[decision.decisionType] = (byType[decision.decisionType] || 0) + 1;
197
+
198
+ if (decision.outcome) {
199
+ byOutcome[decision.outcome]++;
200
+ } else {
201
+ byOutcome.pending++;
202
+ }
203
+
204
+ if (decision.confidence !== null && decision.confidence !== undefined) {
205
+ totalConfidence += decision.confidence;
206
+ confidenceCount++;
207
+ }
208
+ }
209
+
210
+ return {
211
+ total: decisions.length,
212
+ byType,
213
+ byOutcome,
214
+ averageConfidence:
215
+ confidenceCount > 0 ? totalConfidence / confidenceCount : null,
216
+ successRate:
217
+ decisions.length > 0
218
+ ? byOutcome.success / (decisions.length - byOutcome.pending)
219
+ : null,
220
+ };
221
+ },
222
+ });
223
+
224
+ /**
225
+ * Get tool usage stats
226
+ */
227
+ export const getToolStats = query({
228
+ args: { threadId: v.optional(v.string()) },
229
+ handler: async (ctx, args) => {
230
+ const { threadId } = args;
231
+ const executions = threadId
232
+ ? await ctx.db
233
+ .query("toolExecutions")
234
+ .withIndex("by_thread", (q) => q.eq("threadId", threadId))
235
+ .collect()
236
+ : await ctx.db.query("toolExecutions").collect();
237
+
238
+ const byTool: Record<
239
+ string,
240
+ {
241
+ count: number;
242
+ successes: number;
243
+ failures: number;
244
+ totalDurationMs: number;
245
+ }
246
+ > = {};
247
+
248
+ for (const exec of executions) {
249
+ if (!byTool[exec.toolName]) {
250
+ byTool[exec.toolName] = {
251
+ count: 0,
252
+ successes: 0,
253
+ failures: 0,
254
+ totalDurationMs: 0,
255
+ };
256
+ }
257
+
258
+ byTool[exec.toolName].count++;
259
+ if (exec.success) {
260
+ byTool[exec.toolName].successes++;
261
+ } else {
262
+ byTool[exec.toolName].failures++;
263
+ }
264
+ byTool[exec.toolName].totalDurationMs += exec.durationMs;
265
+ }
266
+
267
+ // Calculate averages
268
+ const stats = Object.entries(byTool).map(([name, data]) => ({
269
+ name,
270
+ count: data.count,
271
+ successRate: data.successes / data.count,
272
+ averageDurationMs: data.totalDurationMs / data.count,
273
+ }));
274
+
275
+ // Sort by usage count
276
+ stats.sort((a, b) => b.count - a.count);
277
+
278
+ return {
279
+ totalExecutions: executions.length,
280
+ uniqueTools: Object.keys(byTool).length,
281
+ tools: stats,
282
+ };
283
+ },
284
+ });