@lakitu/sdk 0.1.7 → 0.1.9
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.
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +4 -1
- package/package.json +2 -1
- package/shared/chain-of-thought.ts +141 -0
- package/shared/constants.ts +171 -0
- package/shared/schemas/index.ts +233 -0
- package/shared/types.ts +267 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../cli/commands/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../cli/commands/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAcH,UAAU,YAAY;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAkQD,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,iBAiBhD"}
|
|
@@ -15,7 +15,10 @@ import { join, dirname } from "path";
|
|
|
15
15
|
import { execSync, spawn } from "child_process";
|
|
16
16
|
import { fileURLToPath } from "url";
|
|
17
17
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
-
|
|
18
|
+
// Handle both TS source (cli/commands) and compiled JS (dist/cli/commands)
|
|
19
|
+
const PACKAGE_ROOT = __dirname.includes("/dist/")
|
|
20
|
+
? join(__dirname, "../../..")
|
|
21
|
+
: join(__dirname, "../..");
|
|
19
22
|
function findApiKey() {
|
|
20
23
|
// 1. Environment variable
|
|
21
24
|
if (process.env.E2B_API_KEY) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakitu/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Self-hosted AI agent framework for Convex + E2B with code execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/sdk/index.js",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"dist",
|
|
43
43
|
"convex",
|
|
44
44
|
"convex.json",
|
|
45
|
+
"shared",
|
|
45
46
|
"ksa",
|
|
46
47
|
"runtime",
|
|
47
48
|
"template",
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chain of Thought Types
|
|
3
|
+
*
|
|
4
|
+
* Structured schema for rich UI display of agent activities.
|
|
5
|
+
* Each step type maps to a specific UI component in the frontend.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ============================================
|
|
9
|
+
// Step Status
|
|
10
|
+
// ============================================
|
|
11
|
+
|
|
12
|
+
export type StepStatus = "pending" | "active" | "complete" | "error";
|
|
13
|
+
|
|
14
|
+
// ============================================
|
|
15
|
+
// Base Step
|
|
16
|
+
// ============================================
|
|
17
|
+
|
|
18
|
+
interface BaseStep {
|
|
19
|
+
id: string;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
status: StepStatus;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ============================================
|
|
25
|
+
// Step Types
|
|
26
|
+
// ============================================
|
|
27
|
+
|
|
28
|
+
/** Search with results (web_search, web_social lookups) */
|
|
29
|
+
export interface SearchStep extends BaseStep {
|
|
30
|
+
type: "search";
|
|
31
|
+
label: string;
|
|
32
|
+
results?: Array<{ url: string; title?: string }>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Image found or generated (screenshots, avatars, generated images) */
|
|
36
|
+
export interface ImageStep extends BaseStep {
|
|
37
|
+
type: "image";
|
|
38
|
+
label: string;
|
|
39
|
+
src: string;
|
|
40
|
+
caption?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Text insight or finding (summaries, extracted info) */
|
|
44
|
+
export interface TextStep extends BaseStep {
|
|
45
|
+
type: "text";
|
|
46
|
+
label: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Generic tool execution (fallback for unmapped tools) */
|
|
50
|
+
export interface ToolStep extends BaseStep {
|
|
51
|
+
type: "tool";
|
|
52
|
+
toolName: string;
|
|
53
|
+
label: string;
|
|
54
|
+
input?: Record<string, unknown>;
|
|
55
|
+
output?: unknown;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Agent thinking/reasoning */
|
|
59
|
+
export interface ThinkingStep extends BaseStep {
|
|
60
|
+
type: "thinking";
|
|
61
|
+
label: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** File operation (read, write, edit, artifact save) */
|
|
65
|
+
export interface FileStep extends BaseStep {
|
|
66
|
+
type: "file";
|
|
67
|
+
operation: "read" | "write" | "edit" | "save";
|
|
68
|
+
path: string;
|
|
69
|
+
label: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Browser automation action */
|
|
73
|
+
export interface BrowserStep extends BaseStep {
|
|
74
|
+
type: "browser";
|
|
75
|
+
action: "navigate" | "click" | "type" | "screenshot" | "scroll";
|
|
76
|
+
label: string;
|
|
77
|
+
url?: string;
|
|
78
|
+
screenshot?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ============================================
|
|
82
|
+
// Union Type
|
|
83
|
+
// ============================================
|
|
84
|
+
|
|
85
|
+
export type ChainOfThoughtStep =
|
|
86
|
+
| SearchStep
|
|
87
|
+
| ImageStep
|
|
88
|
+
| TextStep
|
|
89
|
+
| ToolStep
|
|
90
|
+
| ThinkingStep
|
|
91
|
+
| FileStep
|
|
92
|
+
| BrowserStep;
|
|
93
|
+
|
|
94
|
+
// ============================================
|
|
95
|
+
// Helpers
|
|
96
|
+
// ============================================
|
|
97
|
+
|
|
98
|
+
let stepCounter = 0;
|
|
99
|
+
|
|
100
|
+
export function createStepId(): string {
|
|
101
|
+
return `step_${Date.now()}_${++stepCounter}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createStep<T extends ChainOfThoughtStep>(
|
|
105
|
+
step: Omit<T, "id" | "timestamp" | "status"> & { status?: StepStatus }
|
|
106
|
+
): T {
|
|
107
|
+
return {
|
|
108
|
+
id: createStepId(),
|
|
109
|
+
timestamp: Date.now(),
|
|
110
|
+
status: "active",
|
|
111
|
+
...step,
|
|
112
|
+
} as T;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Map tool names to step types for automatic conversion */
|
|
116
|
+
export const TOOL_STEP_MAP: Record<string, ChainOfThoughtStep["type"]> = {
|
|
117
|
+
// Search tools
|
|
118
|
+
web_search: "search",
|
|
119
|
+
web_social: "search",
|
|
120
|
+
web_news: "search",
|
|
121
|
+
// Browser tools
|
|
122
|
+
browser_open: "browser",
|
|
123
|
+
browser_click: "browser",
|
|
124
|
+
browser_type: "browser",
|
|
125
|
+
browser_screenshot: "browser",
|
|
126
|
+
browser_scroll: "browser",
|
|
127
|
+
browser_snapshot: "browser",
|
|
128
|
+
// File tools
|
|
129
|
+
file_read: "file",
|
|
130
|
+
file_write: "file",
|
|
131
|
+
file_edit: "file",
|
|
132
|
+
artifact_save: "file",
|
|
133
|
+
automation_saveArtifact: "file",
|
|
134
|
+
pdf_create: "file",
|
|
135
|
+
// Default fallback is "tool"
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Get the step type for a tool name */
|
|
139
|
+
export function getStepTypeForTool(toolName: string): ChainOfThoughtStep["type"] {
|
|
140
|
+
return TOOL_STEP_MAP[toolName] || "tool";
|
|
141
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Constants - Paths, limits, and defaults
|
|
3
|
+
*
|
|
4
|
+
* Configuration values used across the sandbox agent.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ============================================
|
|
8
|
+
// Paths
|
|
9
|
+
// ============================================
|
|
10
|
+
|
|
11
|
+
export const PATHS = {
|
|
12
|
+
// Root directories
|
|
13
|
+
WORKSPACE: "/home/user/workspace",
|
|
14
|
+
ARTIFACTS: "/home/user/artifacts",
|
|
15
|
+
CONVEX_DATA: "/home/user/.convex",
|
|
16
|
+
SANDBOX_AGENT: "/home/user/sandbox-agent",
|
|
17
|
+
|
|
18
|
+
// Binary locations
|
|
19
|
+
BUN: "/home/user/.bun/bin/bun",
|
|
20
|
+
CONVEX_BACKEND: "/usr/local/bin/convex-backend",
|
|
21
|
+
AGENT_BROWSER: "/usr/local/bin/agent-browser",
|
|
22
|
+
|
|
23
|
+
// LSP binaries
|
|
24
|
+
TYPESCRIPT_LSP: "typescript-language-server",
|
|
25
|
+
PYTHON_LSP: "pylsp",
|
|
26
|
+
RUST_LSP: "rust-analyzer",
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
// ============================================
|
|
30
|
+
// Network
|
|
31
|
+
// ============================================
|
|
32
|
+
|
|
33
|
+
export const NETWORK = {
|
|
34
|
+
// Convex backend
|
|
35
|
+
CONVEX_PORT: 3210,
|
|
36
|
+
CONVEX_SITE_PORT: 3211,
|
|
37
|
+
CONVEX_URL: "http://localhost:3210",
|
|
38
|
+
|
|
39
|
+
// Health check endpoints
|
|
40
|
+
HEALTH_CHECK_INTERVAL_MS: 10000,
|
|
41
|
+
HEALTH_CHECK_TIMEOUT_MS: 5000,
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
// ============================================
|
|
45
|
+
// Limits
|
|
46
|
+
// ============================================
|
|
47
|
+
|
|
48
|
+
export const LIMITS = {
|
|
49
|
+
// File operations
|
|
50
|
+
MAX_FILE_SIZE_BYTES: 10 * 1024 * 1024, // 10MB
|
|
51
|
+
MAX_EDIT_SIZE_BYTES: 1 * 1024 * 1024, // 1MB
|
|
52
|
+
MAX_GLOB_RESULTS: 1000,
|
|
53
|
+
MAX_GREP_MATCHES: 500,
|
|
54
|
+
|
|
55
|
+
// Output truncation
|
|
56
|
+
MAX_STDOUT_LENGTH: 50000,
|
|
57
|
+
MAX_STDERR_LENGTH: 50000,
|
|
58
|
+
MAX_DIFF_LENGTH: 100000,
|
|
59
|
+
|
|
60
|
+
// Timeouts
|
|
61
|
+
DEFAULT_COMMAND_TIMEOUT_MS: 120000, // 2 minutes
|
|
62
|
+
MAX_COMMAND_TIMEOUT_MS: 600000, // 10 minutes
|
|
63
|
+
LSP_REQUEST_TIMEOUT_MS: 30000, // 30 seconds
|
|
64
|
+
BROWSER_ACTION_TIMEOUT_MS: 30000, // 30 seconds
|
|
65
|
+
|
|
66
|
+
// Checkpointing
|
|
67
|
+
MAX_CHECKPOINT_MESSAGE_HISTORY: 50,
|
|
68
|
+
MAX_CHECKPOINT_FILE_STATE: 1000,
|
|
69
|
+
|
|
70
|
+
// Beads
|
|
71
|
+
MAX_BEADS_PER_QUERY: 100,
|
|
72
|
+
MAX_BEAD_TITLE_LENGTH: 200,
|
|
73
|
+
MAX_BEAD_DESCRIPTION_LENGTH: 10000,
|
|
74
|
+
|
|
75
|
+
// Sync queue
|
|
76
|
+
MAX_SYNC_ATTEMPTS: 3,
|
|
77
|
+
SYNC_RETRY_DELAY_MS: 5000,
|
|
78
|
+
} as const;
|
|
79
|
+
|
|
80
|
+
// ============================================
|
|
81
|
+
// Defaults
|
|
82
|
+
// ============================================
|
|
83
|
+
|
|
84
|
+
export const DEFAULTS = {
|
|
85
|
+
// Beads
|
|
86
|
+
BEAD_PRIORITY: 2, // Medium
|
|
87
|
+
BEAD_TYPE: "task",
|
|
88
|
+
|
|
89
|
+
// Checkpoints
|
|
90
|
+
CHECKPOINT_CLEANUP_DAYS: 7,
|
|
91
|
+
|
|
92
|
+
// Context
|
|
93
|
+
CONTEXT_CACHE_TTL_MS: 3600000, // 1 hour
|
|
94
|
+
|
|
95
|
+
// Verification
|
|
96
|
+
TEST_COMMAND: "bun test",
|
|
97
|
+
LINT_COMMAND: "bun run lint",
|
|
98
|
+
TYPECHECK_COMMAND: "bunx tsc --noEmit",
|
|
99
|
+
|
|
100
|
+
// LSP
|
|
101
|
+
DEFAULT_LANGUAGE: "typescript",
|
|
102
|
+
|
|
103
|
+
// Browser
|
|
104
|
+
BROWSER_VIEWPORT_WIDTH: 1280,
|
|
105
|
+
BROWSER_VIEWPORT_HEIGHT: 720,
|
|
106
|
+
} as const;
|
|
107
|
+
|
|
108
|
+
// ============================================
|
|
109
|
+
// File Extensions
|
|
110
|
+
// ============================================
|
|
111
|
+
|
|
112
|
+
export const FILE_EXTENSIONS = {
|
|
113
|
+
TYPESCRIPT: [".ts", ".tsx", ".mts", ".cts"],
|
|
114
|
+
JAVASCRIPT: [".js", ".jsx", ".mjs", ".cjs"],
|
|
115
|
+
PYTHON: [".py", ".pyi"],
|
|
116
|
+
RUST: [".rs"],
|
|
117
|
+
JSON: [".json", ".jsonc"],
|
|
118
|
+
YAML: [".yaml", ".yml"],
|
|
119
|
+
MARKDOWN: [".md", ".mdx"],
|
|
120
|
+
HTML: [".html", ".htm"],
|
|
121
|
+
CSS: [".css", ".scss", ".sass", ".less"],
|
|
122
|
+
CONFIG: [".toml", ".ini", ".cfg", ".conf"],
|
|
123
|
+
} as const;
|
|
124
|
+
|
|
125
|
+
// Helper to get language from file path
|
|
126
|
+
export function getLanguageFromPath(path: string): "typescript" | "python" | "rust" | null {
|
|
127
|
+
const ext = path.slice(path.lastIndexOf(".")).toLowerCase();
|
|
128
|
+
|
|
129
|
+
if (FILE_EXTENSIONS.TYPESCRIPT.includes(ext as any) ||
|
|
130
|
+
FILE_EXTENSIONS.JAVASCRIPT.includes(ext as any)) {
|
|
131
|
+
return "typescript";
|
|
132
|
+
}
|
|
133
|
+
if (FILE_EXTENSIONS.PYTHON.includes(ext as any)) {
|
|
134
|
+
return "python";
|
|
135
|
+
}
|
|
136
|
+
if (FILE_EXTENSIONS.RUST.includes(ext as any)) {
|
|
137
|
+
return "rust";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ============================================
|
|
144
|
+
// Error Codes
|
|
145
|
+
// ============================================
|
|
146
|
+
|
|
147
|
+
export const ERROR_CODES = {
|
|
148
|
+
// File operations
|
|
149
|
+
FILE_NOT_FOUND: "FILE_NOT_FOUND",
|
|
150
|
+
FILE_TOO_LARGE: "FILE_TOO_LARGE",
|
|
151
|
+
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
152
|
+
EDIT_MISMATCH: "EDIT_MISMATCH",
|
|
153
|
+
|
|
154
|
+
// Command execution
|
|
155
|
+
COMMAND_TIMEOUT: "COMMAND_TIMEOUT",
|
|
156
|
+
COMMAND_FAILED: "COMMAND_FAILED",
|
|
157
|
+
DANGEROUS_COMMAND: "DANGEROUS_COMMAND",
|
|
158
|
+
|
|
159
|
+
// LSP
|
|
160
|
+
LSP_NOT_RUNNING: "LSP_NOT_RUNNING",
|
|
161
|
+
LSP_REQUEST_FAILED: "LSP_REQUEST_FAILED",
|
|
162
|
+
|
|
163
|
+
// Browser
|
|
164
|
+
BROWSER_NOT_READY: "BROWSER_NOT_READY",
|
|
165
|
+
BROWSER_NAVIGATION_FAILED: "BROWSER_NAVIGATION_FAILED",
|
|
166
|
+
|
|
167
|
+
// Agent
|
|
168
|
+
THREAD_NOT_FOUND: "THREAD_NOT_FOUND",
|
|
169
|
+
CHECKPOINT_NOT_FOUND: "CHECKPOINT_NOT_FOUND",
|
|
170
|
+
SUBAGENT_FAILED: "SUBAGENT_FAILED",
|
|
171
|
+
} as const;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Schemas - Zod validation schemas
|
|
3
|
+
*
|
|
4
|
+
* Used for runtime validation of tool inputs and API payloads.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
// ============================================
|
|
10
|
+
// File Operations
|
|
11
|
+
// ============================================
|
|
12
|
+
|
|
13
|
+
export const filePathSchema = z.string()
|
|
14
|
+
.min(1, "Path cannot be empty")
|
|
15
|
+
.refine(
|
|
16
|
+
(p) => p.startsWith("/") || p.startsWith("./"),
|
|
17
|
+
"Path must be absolute or relative"
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const fileReadArgsSchema = z.object({
|
|
21
|
+
path: filePathSchema,
|
|
22
|
+
encoding: z.enum(["utf8", "base64"]).default("utf8"),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const fileWriteArgsSchema = z.object({
|
|
26
|
+
path: filePathSchema,
|
|
27
|
+
content: z.string(),
|
|
28
|
+
createDirs: z.boolean().default(true),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const fileEditArgsSchema = z.object({
|
|
32
|
+
path: filePathSchema,
|
|
33
|
+
oldContent: z.string().min(1, "Old content cannot be empty"),
|
|
34
|
+
newContent: z.string(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const globArgsSchema = z.object({
|
|
38
|
+
pattern: z.string().min(1, "Pattern cannot be empty"),
|
|
39
|
+
cwd: z.string().default("/home/user/workspace"),
|
|
40
|
+
maxResults: z.number().int().positive().max(1000).default(100),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const grepArgsSchema = z.object({
|
|
44
|
+
pattern: z.string().min(1, "Pattern cannot be empty"),
|
|
45
|
+
path: z.string().default("/home/user/workspace"),
|
|
46
|
+
fileGlob: z.string().optional(),
|
|
47
|
+
maxMatches: z.number().int().positive().max(500).default(50),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// ============================================
|
|
51
|
+
// Bash Execution
|
|
52
|
+
// ============================================
|
|
53
|
+
|
|
54
|
+
export const bashArgsSchema = z.object({
|
|
55
|
+
command: z.string().min(1, "Command cannot be empty"),
|
|
56
|
+
cwd: z.string().optional(),
|
|
57
|
+
timeoutMs: z.number().int().positive().max(600000).default(120000),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ============================================
|
|
61
|
+
// Beads (Task Tracking)
|
|
62
|
+
// ============================================
|
|
63
|
+
|
|
64
|
+
export const beadTypeSchema = z.enum(["task", "bug", "feature", "epic", "chore"]);
|
|
65
|
+
export const beadStatusSchema = z.enum(["open", "in_progress", "blocked", "closed"]);
|
|
66
|
+
export const beadPrioritySchema = z.number().int().min(0).max(4);
|
|
67
|
+
|
|
68
|
+
export const beadCreateArgsSchema = z.object({
|
|
69
|
+
title: z.string().min(1).max(200),
|
|
70
|
+
type: beadTypeSchema.default("task"),
|
|
71
|
+
priority: beadPrioritySchema.default(2),
|
|
72
|
+
description: z.string().max(10000).optional(),
|
|
73
|
+
labels: z.array(z.string()).optional(),
|
|
74
|
+
parentId: z.string().optional(),
|
|
75
|
+
blockedBy: z.array(z.string()).optional(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const beadUpdateArgsSchema = z.object({
|
|
79
|
+
id: z.string(),
|
|
80
|
+
status: beadStatusSchema.optional(),
|
|
81
|
+
priority: beadPrioritySchema.optional(),
|
|
82
|
+
title: z.string().min(1).max(200).optional(),
|
|
83
|
+
description: z.string().max(10000).optional(),
|
|
84
|
+
labels: z.array(z.string()).optional(),
|
|
85
|
+
blockedBy: z.array(z.string()).optional(),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ============================================
|
|
89
|
+
// LSP Operations
|
|
90
|
+
// ============================================
|
|
91
|
+
|
|
92
|
+
export const languageSchema = z.enum(["typescript", "python", "rust"]);
|
|
93
|
+
|
|
94
|
+
export const lspPositionSchema = z.object({
|
|
95
|
+
line: z.number().int().min(0),
|
|
96
|
+
character: z.number().int().min(0),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export const lspDiagnosticsArgsSchema = z.object({
|
|
100
|
+
path: filePathSchema,
|
|
101
|
+
language: languageSchema.optional(),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const lspCompletionArgsSchema = z.object({
|
|
105
|
+
path: filePathSchema,
|
|
106
|
+
line: z.number().int().min(0),
|
|
107
|
+
character: z.number().int().min(0),
|
|
108
|
+
language: languageSchema.optional(),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export const lspHoverArgsSchema = z.object({
|
|
112
|
+
path: filePathSchema,
|
|
113
|
+
line: z.number().int().min(0),
|
|
114
|
+
character: z.number().int().min(0),
|
|
115
|
+
language: languageSchema.optional(),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// ============================================
|
|
119
|
+
// Browser Operations
|
|
120
|
+
// ============================================
|
|
121
|
+
|
|
122
|
+
export const browserOpenArgsSchema = z.object({
|
|
123
|
+
url: z.string().url(),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export const browserSnapshotArgsSchema = z.object({
|
|
127
|
+
interactive: z.boolean().default(true),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const browserClickArgsSchema = z.object({
|
|
131
|
+
ref: z.string().regex(/^@e\d+$/, "Ref must be in format @e1, @e2, etc."),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export const browserTypeArgsSchema = z.object({
|
|
135
|
+
text: z.string(),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const browserPressArgsSchema = z.object({
|
|
139
|
+
key: z.string(),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export const browserScrollArgsSchema = z.object({
|
|
143
|
+
direction: z.enum(["up", "down", "top", "bottom"]),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// ============================================
|
|
147
|
+
// Subagent Operations
|
|
148
|
+
// ============================================
|
|
149
|
+
|
|
150
|
+
export const subagentSpawnArgsSchema = z.object({
|
|
151
|
+
name: z.string().min(1).max(50),
|
|
152
|
+
task: z.string().min(1).max(10000),
|
|
153
|
+
tools: z.array(z.string()).default([]),
|
|
154
|
+
model: z.string().default("gpt-4o-mini"),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
export const subagentQueryArgsSchema = z.object({
|
|
158
|
+
subagentId: z.string(),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ============================================
|
|
162
|
+
// Artifacts
|
|
163
|
+
// ============================================
|
|
164
|
+
|
|
165
|
+
export const artifactSaveArgsSchema = z.object({
|
|
166
|
+
name: z.string().min(1).max(200),
|
|
167
|
+
type: z.string().default("text/plain"),
|
|
168
|
+
path: filePathSchema,
|
|
169
|
+
content: z.string().optional(),
|
|
170
|
+
metadata: z.record(z.unknown()).optional(),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ============================================
|
|
174
|
+
// Checkpoints
|
|
175
|
+
// ============================================
|
|
176
|
+
|
|
177
|
+
export const checkpointReasonSchema = z.enum([
|
|
178
|
+
"timeout",
|
|
179
|
+
"token_limit",
|
|
180
|
+
"manual",
|
|
181
|
+
"error_recovery",
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
export const checkpointCreateArgsSchema = z.object({
|
|
185
|
+
sessionId: z.string(),
|
|
186
|
+
threadId: z.string(),
|
|
187
|
+
iteration: z.number().int().min(0),
|
|
188
|
+
nextTask: z.string(),
|
|
189
|
+
reason: checkpointReasonSchema,
|
|
190
|
+
metadata: z.record(z.unknown()).optional(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Export all schemas
|
|
194
|
+
export const schemas = {
|
|
195
|
+
file: {
|
|
196
|
+
read: fileReadArgsSchema,
|
|
197
|
+
write: fileWriteArgsSchema,
|
|
198
|
+
edit: fileEditArgsSchema,
|
|
199
|
+
glob: globArgsSchema,
|
|
200
|
+
grep: grepArgsSchema,
|
|
201
|
+
},
|
|
202
|
+
bash: bashArgsSchema,
|
|
203
|
+
beads: {
|
|
204
|
+
create: beadCreateArgsSchema,
|
|
205
|
+
update: beadUpdateArgsSchema,
|
|
206
|
+
type: beadTypeSchema,
|
|
207
|
+
status: beadStatusSchema,
|
|
208
|
+
},
|
|
209
|
+
lsp: {
|
|
210
|
+
diagnostics: lspDiagnosticsArgsSchema,
|
|
211
|
+
completion: lspCompletionArgsSchema,
|
|
212
|
+
hover: lspHoverArgsSchema,
|
|
213
|
+
language: languageSchema,
|
|
214
|
+
},
|
|
215
|
+
browser: {
|
|
216
|
+
open: browserOpenArgsSchema,
|
|
217
|
+
snapshot: browserSnapshotArgsSchema,
|
|
218
|
+
click: browserClickArgsSchema,
|
|
219
|
+
type: browserTypeArgsSchema,
|
|
220
|
+
press: browserPressArgsSchema,
|
|
221
|
+
scroll: browserScrollArgsSchema,
|
|
222
|
+
},
|
|
223
|
+
subagent: {
|
|
224
|
+
spawn: subagentSpawnArgsSchema,
|
|
225
|
+
query: subagentQueryArgsSchema,
|
|
226
|
+
},
|
|
227
|
+
artifact: {
|
|
228
|
+
save: artifactSaveArgsSchema,
|
|
229
|
+
},
|
|
230
|
+
checkpoint: {
|
|
231
|
+
create: checkpointCreateArgsSchema,
|
|
232
|
+
},
|
|
233
|
+
};
|
package/shared/types.ts
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Types - Common TypeScript definitions
|
|
3
|
+
*
|
|
4
|
+
* Types shared between Convex backend and runtime processes.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ============================================
|
|
8
|
+
// Beads (Task Tracking)
|
|
9
|
+
// ============================================
|
|
10
|
+
|
|
11
|
+
export type BeadType = "task" | "bug" | "feature" | "epic" | "chore";
|
|
12
|
+
export type BeadStatus = "open" | "in_progress" | "blocked" | "closed";
|
|
13
|
+
export type BeadPriority = 0 | 1 | 2 | 3 | 4; // 0=critical, 4=backlog
|
|
14
|
+
|
|
15
|
+
export interface Bead {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
type: BeadType;
|
|
20
|
+
priority: BeadPriority;
|
|
21
|
+
labels: string[];
|
|
22
|
+
parentId?: string;
|
|
23
|
+
blockedBy: string[];
|
|
24
|
+
status: BeadStatus;
|
|
25
|
+
closedReason?: string;
|
|
26
|
+
assignee?: string;
|
|
27
|
+
threadId?: string;
|
|
28
|
+
createdAt: number;
|
|
29
|
+
updatedAt: number;
|
|
30
|
+
closedAt?: number;
|
|
31
|
+
relatedFiles: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ============================================
|
|
35
|
+
// Artifacts
|
|
36
|
+
// ============================================
|
|
37
|
+
|
|
38
|
+
export interface Artifact {
|
|
39
|
+
name: string;
|
|
40
|
+
type: string; // MIME type
|
|
41
|
+
path: string;
|
|
42
|
+
size: number;
|
|
43
|
+
content?: string;
|
|
44
|
+
storageId?: string;
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
46
|
+
threadId?: string;
|
|
47
|
+
createdAt: number;
|
|
48
|
+
syncedToCloud: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ============================================
|
|
52
|
+
// File State
|
|
53
|
+
// ============================================
|
|
54
|
+
|
|
55
|
+
export type FileOperation = "read" | "write" | "edit";
|
|
56
|
+
|
|
57
|
+
export interface FileState {
|
|
58
|
+
path: string;
|
|
59
|
+
contentHash?: string;
|
|
60
|
+
size?: number;
|
|
61
|
+
lastOperation: FileOperation;
|
|
62
|
+
lastAccessAt: number;
|
|
63
|
+
accessCount: number;
|
|
64
|
+
threadId?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface EditHistoryEntry {
|
|
68
|
+
path: string;
|
|
69
|
+
oldContentHash: string;
|
|
70
|
+
newContentHash: string;
|
|
71
|
+
diff: string;
|
|
72
|
+
verified: boolean;
|
|
73
|
+
threadId?: string;
|
|
74
|
+
createdAt: number;
|
|
75
|
+
rolledBack?: boolean;
|
|
76
|
+
rollbackReason?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ============================================
|
|
80
|
+
// Verification
|
|
81
|
+
// ============================================
|
|
82
|
+
|
|
83
|
+
export interface VerificationCheck {
|
|
84
|
+
name: string;
|
|
85
|
+
success: boolean;
|
|
86
|
+
output?: string;
|
|
87
|
+
durationMs?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface VerificationResult {
|
|
91
|
+
success: boolean;
|
|
92
|
+
checks: VerificationCheck[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface TestSuiteResult {
|
|
96
|
+
success: boolean;
|
|
97
|
+
exitCode: number | null;
|
|
98
|
+
output?: string;
|
|
99
|
+
errors?: string;
|
|
100
|
+
durationMs: number;
|
|
101
|
+
timedOut?: boolean;
|
|
102
|
+
testCommand: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ============================================
|
|
106
|
+
// Checkpoints
|
|
107
|
+
// ============================================
|
|
108
|
+
|
|
109
|
+
export type CheckpointReason = "timeout" | "token_limit" | "manual" | "error_recovery";
|
|
110
|
+
export type CheckpointStatus = "active" | "restored" | "completed" | "failed" | "superseded";
|
|
111
|
+
|
|
112
|
+
export interface FileSnapshot {
|
|
113
|
+
path: string;
|
|
114
|
+
contentHash: string;
|
|
115
|
+
size: number;
|
|
116
|
+
lastModified: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface BeadSnapshot {
|
|
120
|
+
id: string;
|
|
121
|
+
title: string;
|
|
122
|
+
status: string;
|
|
123
|
+
type: string;
|
|
124
|
+
priority: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface MessageSnapshot {
|
|
128
|
+
role: string;
|
|
129
|
+
content: string;
|
|
130
|
+
timestamp?: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Checkpoint {
|
|
134
|
+
sessionId: string;
|
|
135
|
+
threadId: string;
|
|
136
|
+
iteration: number;
|
|
137
|
+
messageHistory: MessageSnapshot[];
|
|
138
|
+
fileState: FileSnapshot[];
|
|
139
|
+
beadsState: BeadSnapshot[];
|
|
140
|
+
artifactsProduced: string[];
|
|
141
|
+
nextTask: string;
|
|
142
|
+
reason: CheckpointReason;
|
|
143
|
+
status: CheckpointStatus;
|
|
144
|
+
metadata?: Record<string, unknown>;
|
|
145
|
+
createdAt: number;
|
|
146
|
+
restoredAt?: number;
|
|
147
|
+
completedAt?: number;
|
|
148
|
+
error?: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ============================================
|
|
152
|
+
// Agent Decisions
|
|
153
|
+
// ============================================
|
|
154
|
+
|
|
155
|
+
export type DecisionType =
|
|
156
|
+
| "tool_selection"
|
|
157
|
+
| "file_edit"
|
|
158
|
+
| "task_breakdown"
|
|
159
|
+
| "verification"
|
|
160
|
+
| "rollback"
|
|
161
|
+
| "checkpoint"
|
|
162
|
+
| "error_recovery";
|
|
163
|
+
|
|
164
|
+
export type DecisionOutcome = "success" | "partial_success" | "failure" | "abandoned";
|
|
165
|
+
|
|
166
|
+
export interface AgentDecision {
|
|
167
|
+
threadId: string;
|
|
168
|
+
task: string;
|
|
169
|
+
decisionType: DecisionType;
|
|
170
|
+
selectedTools?: string[];
|
|
171
|
+
reasoning: string;
|
|
172
|
+
expectedOutcome?: string;
|
|
173
|
+
alternatives?: Array<{ option: string; reason: string }>;
|
|
174
|
+
confidence?: number;
|
|
175
|
+
outcome?: DecisionOutcome;
|
|
176
|
+
actualResult?: string;
|
|
177
|
+
timestamp: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ============================================
|
|
181
|
+
// LSP
|
|
182
|
+
// ============================================
|
|
183
|
+
|
|
184
|
+
export type Language = "typescript" | "python" | "rust";
|
|
185
|
+
|
|
186
|
+
export interface LspDiagnostic {
|
|
187
|
+
path: string;
|
|
188
|
+
line: number;
|
|
189
|
+
character: number;
|
|
190
|
+
severity: "error" | "warning" | "info" | "hint";
|
|
191
|
+
message: string;
|
|
192
|
+
code?: string | number;
|
|
193
|
+
source?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface LspCompletion {
|
|
197
|
+
label: string;
|
|
198
|
+
kind: string;
|
|
199
|
+
detail?: string;
|
|
200
|
+
documentation?: string;
|
|
201
|
+
insertText?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface LspHover {
|
|
205
|
+
contents: string;
|
|
206
|
+
range?: {
|
|
207
|
+
start: { line: number; character: number };
|
|
208
|
+
end: { line: number; character: number };
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ============================================
|
|
213
|
+
// Browser
|
|
214
|
+
// ============================================
|
|
215
|
+
|
|
216
|
+
export interface BrowserElement {
|
|
217
|
+
ref: string;
|
|
218
|
+
tag: string;
|
|
219
|
+
text?: string;
|
|
220
|
+
role?: string;
|
|
221
|
+
attributes: Record<string, string>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface BrowserSnapshot {
|
|
225
|
+
url: string;
|
|
226
|
+
title: string;
|
|
227
|
+
elements: BrowserElement[];
|
|
228
|
+
screenshot?: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ============================================
|
|
232
|
+
// Subagents
|
|
233
|
+
// ============================================
|
|
234
|
+
|
|
235
|
+
export type SubagentStatus = "pending" | "running" | "completed" | "failed";
|
|
236
|
+
|
|
237
|
+
export interface Subagent {
|
|
238
|
+
parentThreadId: string;
|
|
239
|
+
threadId: string;
|
|
240
|
+
name: string;
|
|
241
|
+
task: string;
|
|
242
|
+
tools: string[];
|
|
243
|
+
model: string;
|
|
244
|
+
status: SubagentStatus;
|
|
245
|
+
result?: unknown;
|
|
246
|
+
error?: string;
|
|
247
|
+
createdAt: number;
|
|
248
|
+
completedAt?: number;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ============================================
|
|
252
|
+
// Sync Queue
|
|
253
|
+
// ============================================
|
|
254
|
+
|
|
255
|
+
export type SyncItemType = "artifact" | "bead" | "decision" | "checkpoint" | "result";
|
|
256
|
+
export type SyncStatus = "pending" | "in_progress" | "completed" | "failed";
|
|
257
|
+
|
|
258
|
+
export interface SyncQueueItem {
|
|
259
|
+
type: SyncItemType;
|
|
260
|
+
itemId: string;
|
|
261
|
+
priority: number;
|
|
262
|
+
status: SyncStatus;
|
|
263
|
+
attempts: number;
|
|
264
|
+
lastError?: string;
|
|
265
|
+
cloudId?: string;
|
|
266
|
+
createdAt: number;
|
|
267
|
+
}
|