@ultrst-armada/kloks 1.24.4 → 1.24.5
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/.krusbl-release-attestation.json +3 -3
- package/package.json +1 -1
- package/packages/backend/dist/development/index.js +639 -28
- package/packages/backend/dist/index.d.ts +0 -3
- package/packages/backend/dist/index.js +0 -61
- package/packages/state-graph/dist/index.js +14 -14
- package/packages/backend/dist/chunk-FJ5LZFBV.js +0 -667
|
@@ -1,38 +1,649 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AgentHarnessRuntime,
|
|
3
|
-
AgentHarnessServiceDefinition,
|
|
4
|
-
AgentHarnessServiceFacade,
|
|
5
|
-
CodeDiagnosticsService,
|
|
6
|
-
CodeValidationRuntime,
|
|
7
|
-
CodeValidationServiceDefinition,
|
|
8
|
-
CodeValidationServiceFacade,
|
|
9
|
-
DevelopmentRuntime,
|
|
10
|
-
DevelopmentServiceDefinition,
|
|
11
|
-
DevelopmentServiceFacade,
|
|
12
|
-
GitHubActionsClient,
|
|
13
|
-
GitHubActionsServiceDefinition,
|
|
14
|
-
GitHubActionsServiceFacade,
|
|
15
|
-
TYPESCRIPT_LANGUAGE_SERVER_PACKAGE,
|
|
16
|
-
TYPESCRIPT_LANGUAGE_SERVER_VERSION,
|
|
17
|
-
TypeScriptLanguageServerServiceDefinition,
|
|
18
|
-
TypeScriptLanguageServerServiceFacade,
|
|
19
|
-
WebContainerRuntime,
|
|
20
|
-
WebContainerServiceDefinition,
|
|
21
|
-
WebContainerServiceFacade,
|
|
22
|
-
captureDevelopmentProcess,
|
|
23
|
-
codeDiagnosticsService,
|
|
24
|
-
parseDevelopmentDiagnostics,
|
|
25
|
-
resolveDevelopmentCommand,
|
|
26
|
-
resolveWebContainerCommand
|
|
27
|
-
} from "../chunk-FJ5LZFBV.js";
|
|
28
1
|
import "../chunk-YEGS4HTA.js";
|
|
29
2
|
import {
|
|
30
3
|
PlaywrightInspectionRuntime,
|
|
31
4
|
PlaywrightInspectionServiceDefinition,
|
|
32
5
|
PlaywrightInspectionServiceFacade
|
|
33
6
|
} from "../chunk-2OPIDIIB.js";
|
|
34
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
createService,
|
|
9
|
+
createServiceDefinition
|
|
10
|
+
} from "../chunk-MWSYNRNZ.js";
|
|
35
11
|
import "../chunk-QGM4M3NI.js";
|
|
12
|
+
|
|
13
|
+
// src/development/githubActionsService.ts
|
|
14
|
+
var GitHubActionsClient = class {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.baseUrl = config.apiBaseUrl ?? "https://api.github.com";
|
|
18
|
+
this.fetchImpl = config.fetchImpl ?? fetch;
|
|
19
|
+
}
|
|
20
|
+
config;
|
|
21
|
+
baseUrl;
|
|
22
|
+
fetchImpl;
|
|
23
|
+
async request(path, init = {}) {
|
|
24
|
+
const response = await this.fetchImpl(this.baseUrl + path, {
|
|
25
|
+
...init,
|
|
26
|
+
headers: {
|
|
27
|
+
Accept: "application/vnd.github+json",
|
|
28
|
+
Authorization: `Bearer ${this.config.token}`,
|
|
29
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
30
|
+
...init.headers ?? {}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const text = await response.text();
|
|
34
|
+
const data = text ? JSON.parse(text) : void 0;
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(`GitHub Actions request failed (${response.status}): ${data?.message ?? response.statusText}`);
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
listWorkflowRuns(repository, workflowId, branch) {
|
|
41
|
+
const suffix = workflowId ? `/actions/workflows/${workflowId}/runs` : "/actions/runs";
|
|
42
|
+
const query = branch ? `?branch=${encodeURIComponent(branch)}` : "";
|
|
43
|
+
return this.request(`/repos/${repository}${suffix}${query}`);
|
|
44
|
+
}
|
|
45
|
+
getWorkflowRun(repository, runId) {
|
|
46
|
+
return this.request(`/repos/${repository}/actions/runs/${runId}`);
|
|
47
|
+
}
|
|
48
|
+
getWorkflowJobs(repository, runId) {
|
|
49
|
+
return this.request(
|
|
50
|
+
`/repos/${repository}/actions/runs/${runId}/jobs`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
getJobLogs(repository, jobId) {
|
|
54
|
+
return this.request(`/repos/${repository}/actions/jobs/${jobId}/logs`);
|
|
55
|
+
}
|
|
56
|
+
listArtifacts(repository, runId) {
|
|
57
|
+
const path = runId ? `/repos/${repository}/actions/runs/${runId}/artifacts` : `/repos/${repository}/actions/artifacts`;
|
|
58
|
+
return this.request(path);
|
|
59
|
+
}
|
|
60
|
+
dispatchWorkflow(repository, workflowId, ref, inputs = {}) {
|
|
61
|
+
return this.request(`/repos/${repository}/actions/workflows/${workflowId}/dispatches`, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
body: JSON.stringify({ ref, inputs }),
|
|
64
|
+
headers: { "Content-Type": "application/json" }
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
rerunWorkflow(repository, runId) {
|
|
68
|
+
return this.request(`/repos/${repository}/actions/runs/${runId}/rerun`, { method: "POST" });
|
|
69
|
+
}
|
|
70
|
+
rerunFailedJobs(repository, runId) {
|
|
71
|
+
return this.request(`/repos/${repository}/actions/runs/${runId}/rerun-failed-jobs`, { method: "POST" });
|
|
72
|
+
}
|
|
73
|
+
cancelWorkflow(repository, runId) {
|
|
74
|
+
return this.request(`/repos/${repository}/actions/runs/${runId}/cancel`, { method: "POST" });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var GitHubActionsServiceDefinition = createServiceDefinition({
|
|
78
|
+
id: "kloks.backend.githubActions",
|
|
79
|
+
name: "GitHubActionsService",
|
|
80
|
+
version: "1.0.0",
|
|
81
|
+
operations: {
|
|
82
|
+
listWorkflowRuns: { id: "GitHubActionsService.listWorkflowRuns", name: "listWorkflowRuns", handler: async (i) => new GitHubActionsClient({ token: i.token }).listWorkflowRuns(i.repository, i.workflowId, i.branch) },
|
|
83
|
+
getWorkflowRun: { id: "GitHubActionsService.getWorkflowRun", name: "getWorkflowRun", handler: async (i) => new GitHubActionsClient({ token: i.token }).getWorkflowRun(i.repository, i.runId) },
|
|
84
|
+
getWorkflowJobs: { id: "GitHubActionsService.getWorkflowJobs", name: "getWorkflowJobs", handler: async (i) => new GitHubActionsClient({ token: i.token }).getWorkflowJobs(i.repository, i.runId) },
|
|
85
|
+
getJobLogs: { id: "GitHubActionsService.getJobLogs", name: "getJobLogs", handler: async (i) => new GitHubActionsClient({ token: i.token }).getJobLogs(i.repository, i.jobId) },
|
|
86
|
+
listArtifacts: { id: "GitHubActionsService.listArtifacts", name: "listArtifacts", handler: async (i) => new GitHubActionsClient({ token: i.token }).listArtifacts(i.repository, i.runId) },
|
|
87
|
+
dispatchWorkflow: { id: "GitHubActionsService.dispatchWorkflow", name: "dispatchWorkflow", handler: async (i) => new GitHubActionsClient({ token: i.token }).dispatchWorkflow(i.repository, i.workflowId, i.ref, i.inputs) },
|
|
88
|
+
rerunWorkflow: { id: "GitHubActionsService.rerunWorkflow", name: "rerunWorkflow", handler: async (i) => new GitHubActionsClient({ token: i.token }).rerunWorkflow(i.repository, i.runId) },
|
|
89
|
+
rerunFailedJobs: { id: "GitHubActionsService.rerunFailedJobs", name: "rerunFailedJobs", handler: async (i) => new GitHubActionsClient({ token: i.token }).rerunFailedJobs(i.repository, i.runId) },
|
|
90
|
+
cancelWorkflow: { id: "GitHubActionsService.cancelWorkflow", name: "cancelWorkflow", handler: async (i) => new GitHubActionsClient({ token: i.token }).cancelWorkflow(i.repository, i.runId) }
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
var GitHubActionsServiceFacade = {
|
|
94
|
+
id: GitHubActionsServiceDefinition.id,
|
|
95
|
+
name: GitHubActionsServiceDefinition.name,
|
|
96
|
+
version: GitHubActionsServiceDefinition.version,
|
|
97
|
+
runtime: "server",
|
|
98
|
+
deployment: "remote",
|
|
99
|
+
definition: GitHubActionsServiceDefinition,
|
|
100
|
+
createInstance: () => createService(GitHubActionsServiceDefinition),
|
|
101
|
+
execute: async (op, input) => {
|
|
102
|
+
const instance = createService(GitHubActionsServiceDefinition);
|
|
103
|
+
await instance.start();
|
|
104
|
+
return instance.call(op, input);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/development/webContainerService.ts
|
|
109
|
+
var COMMANDS = {
|
|
110
|
+
install: { command: "pnpm", args: ["install", "--no-frozen-lockfile"] },
|
|
111
|
+
lint: { command: "pnpm", args: ["lint"] },
|
|
112
|
+
test: { command: "pnpm", args: ["test"] },
|
|
113
|
+
build: { command: "pnpm", args: ["build"] },
|
|
114
|
+
validate: { command: "pnpm", args: ["validate"] },
|
|
115
|
+
check: { command: "pnpm", args: ["lint"] }
|
|
116
|
+
};
|
|
117
|
+
function parseDevelopmentDiagnostics(output, exitCode = 0) {
|
|
118
|
+
const diagnostics = [];
|
|
119
|
+
const seen = /* @__PURE__ */ new Set();
|
|
120
|
+
const add = (diagnostic) => {
|
|
121
|
+
const key = [diagnostic.source, diagnostic.code, diagnostic.file, diagnostic.line, diagnostic.message].join("|");
|
|
122
|
+
if (!seen.has(key)) {
|
|
123
|
+
seen.add(key);
|
|
124
|
+
diagnostics.push(diagnostic);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
for (const line of output.split(/\r?\n/)) {
|
|
128
|
+
const typescript = line.match(/^(.+?)\((\d+),(\d+)\):\s*(error|warning)\s+(TS\d+):\s*(.+)$/);
|
|
129
|
+
if (typescript) {
|
|
130
|
+
add({ source: "typescript", severity: typescript[4], file: typescript[1], line: Number(typescript[2]), column: Number(typescript[3]), code: typescript[5], message: typescript[6] });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const eslint = line.match(/^(.+?):(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+([^\s]+)$/);
|
|
134
|
+
if (eslint) {
|
|
135
|
+
add({ source: "eslint", severity: eslint[4], file: eslint[1], line: Number(eslint[2]), column: Number(eslint[3]), code: eslint[6], message: eslint[5] });
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const bundler = line.match(/(?:✘|×|ERROR|error:|Error:)\s*(.+)$/);
|
|
139
|
+
if (bundler) add({ source: "bundler", severity: "error", message: bundler[1].trim() });
|
|
140
|
+
if (/\bWARN(?:ING)?\b/i.test(line)) add({ source: "package-manager", severity: "warning", message: line.trim() });
|
|
141
|
+
}
|
|
142
|
+
if (exitCode !== 0 && diagnostics.every((item) => item.severity !== "error")) {
|
|
143
|
+
add({ source: "unknown", severity: "error", message: "Command failed with exit code " + exitCode + "; inspect captured output for details." });
|
|
144
|
+
}
|
|
145
|
+
return diagnostics;
|
|
146
|
+
}
|
|
147
|
+
function captureDevelopmentProcess(process) {
|
|
148
|
+
const [consumerOutput, diagnosticOutput] = process.output.tee();
|
|
149
|
+
const logs = (async () => {
|
|
150
|
+
const reader = diagnosticOutput.getReader();
|
|
151
|
+
let output = "";
|
|
152
|
+
try {
|
|
153
|
+
while (true) {
|
|
154
|
+
const next = await reader.read();
|
|
155
|
+
if (next.done) break;
|
|
156
|
+
output += next.value;
|
|
157
|
+
}
|
|
158
|
+
} finally {
|
|
159
|
+
reader.releaseLock();
|
|
160
|
+
}
|
|
161
|
+
const exitCode = await process.exit;
|
|
162
|
+
return { output, exitCode, diagnostics: parseDevelopmentDiagnostics(output, exitCode) };
|
|
163
|
+
})();
|
|
164
|
+
return { ...process, output: consumerOutput, logs };
|
|
165
|
+
}
|
|
166
|
+
function resolveWebContainerCommand(task) {
|
|
167
|
+
const command = COMMANDS[task];
|
|
168
|
+
return { command: command.command, args: [...command.args] };
|
|
169
|
+
}
|
|
170
|
+
var runQueue = Promise.resolve();
|
|
171
|
+
var sharedContainer = null;
|
|
172
|
+
var sharedContainerPromise = null;
|
|
173
|
+
var WebContainerRuntime = class {
|
|
174
|
+
async boot() {
|
|
175
|
+
if (typeof window !== "undefined" && !window.crossOriginIsolated) {
|
|
176
|
+
throw new Error("WebContainer requires a cross-origin-isolated page. Ensure COOP=same-origin and COEP=require-corp are served.");
|
|
177
|
+
}
|
|
178
|
+
if (sharedContainer) return sharedContainer;
|
|
179
|
+
if (!sharedContainerPromise) {
|
|
180
|
+
sharedContainerPromise = import("@webcontainer/api").then(async (module) => {
|
|
181
|
+
const container = await module.WebContainer.boot({
|
|
182
|
+
coep: "require-corp",
|
|
183
|
+
workdirName: "kloks-development"
|
|
184
|
+
});
|
|
185
|
+
sharedContainer = container;
|
|
186
|
+
return container;
|
|
187
|
+
}).catch((error) => {
|
|
188
|
+
sharedContainerPromise = null;
|
|
189
|
+
throw error;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return sharedContainerPromise;
|
|
193
|
+
}
|
|
194
|
+
async mount(files, mountPoint) {
|
|
195
|
+
const container = await this.boot();
|
|
196
|
+
await container.mount(files, mountPoint ? { mountPoint } : void 0);
|
|
197
|
+
return { mounted: true, mountPoint: mountPoint ?? "/" };
|
|
198
|
+
}
|
|
199
|
+
async runProcess(command, args, cwd, env) {
|
|
200
|
+
const container = await this.boot();
|
|
201
|
+
const process = await container.spawn(command, args, { cwd, env });
|
|
202
|
+
const started = Date.now();
|
|
203
|
+
let output = "";
|
|
204
|
+
const reader = process.output.getReader();
|
|
205
|
+
try {
|
|
206
|
+
while (true) {
|
|
207
|
+
const next = await reader.read();
|
|
208
|
+
if (next.done) break;
|
|
209
|
+
output += next.value;
|
|
210
|
+
}
|
|
211
|
+
} finally {
|
|
212
|
+
reader.releaseLock();
|
|
213
|
+
}
|
|
214
|
+
const exitCode = await process.exit;
|
|
215
|
+
return { exitCode, output, command: [command, ...args].join(" "), durationMs: Date.now() - started, diagnostics: parseDevelopmentDiagnostics(output, exitCode) };
|
|
216
|
+
}
|
|
217
|
+
async run(task, cwd, env) {
|
|
218
|
+
const spec = resolveWebContainerCommand(task);
|
|
219
|
+
return this.runCommand(spec.command, spec.args, cwd, env);
|
|
220
|
+
}
|
|
221
|
+
async runCommand(command, args = [], cwd, env) {
|
|
222
|
+
const previous = runQueue;
|
|
223
|
+
let release;
|
|
224
|
+
runQueue = new Promise((resolve) => {
|
|
225
|
+
release = resolve;
|
|
226
|
+
});
|
|
227
|
+
await previous;
|
|
228
|
+
try {
|
|
229
|
+
return await this.runProcess(command, args, cwd, env);
|
|
230
|
+
} finally {
|
|
231
|
+
release();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async spawnCommand(command, args = [], cwd, env) {
|
|
235
|
+
const container = await this.boot();
|
|
236
|
+
const process = await container.spawn(command, args, { cwd, env });
|
|
237
|
+
return captureDevelopmentProcess(process);
|
|
238
|
+
}
|
|
239
|
+
async teardown() {
|
|
240
|
+
const container = sharedContainer;
|
|
241
|
+
sharedContainer = null;
|
|
242
|
+
sharedContainerPromise = null;
|
|
243
|
+
await container?.teardown();
|
|
244
|
+
return { tornDown: true };
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var runtime = new WebContainerRuntime();
|
|
248
|
+
var WebContainerServiceDefinition = createServiceDefinition({
|
|
249
|
+
id: "kloks.backend.webContainer",
|
|
250
|
+
name: "WebContainerService",
|
|
251
|
+
version: "1.2.0",
|
|
252
|
+
operations: {
|
|
253
|
+
boot: { id: "WebContainerService.boot", name: "boot", handler: async () => {
|
|
254
|
+
await runtime.boot();
|
|
255
|
+
return { ready: true };
|
|
256
|
+
} },
|
|
257
|
+
mount: { id: "WebContainerService.mount", name: "mount", handler: async (input) => runtime.mount(input.files, input.mountPoint) },
|
|
258
|
+
run: { id: "WebContainerService.run", name: "run", handler: async (input) => runtime.run(input.task, input.cwd, input.env) },
|
|
259
|
+
runCommand: { id: "WebContainerService.runCommand", name: "runCommand", handler: async (input) => runtime.runCommand(input.command, input.args, input.cwd, input.env) },
|
|
260
|
+
teardown: { id: "WebContainerService.teardown", name: "teardown", handler: async () => runtime.teardown() },
|
|
261
|
+
command: { id: "WebContainerService.command", name: "command", handler: async (input) => ({ task: input.task, command: resolveWebContainerCommand(input.task) }) }
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
var WebContainerServiceFacade = {
|
|
265
|
+
id: WebContainerServiceDefinition.id,
|
|
266
|
+
name: WebContainerServiceDefinition.name,
|
|
267
|
+
version: WebContainerServiceDefinition.version,
|
|
268
|
+
runtime: "client",
|
|
269
|
+
deployment: "local",
|
|
270
|
+
definition: WebContainerServiceDefinition,
|
|
271
|
+
createInstance: () => createService(WebContainerServiceDefinition),
|
|
272
|
+
execute: async (op, input) => {
|
|
273
|
+
const instance = createService(WebContainerServiceDefinition);
|
|
274
|
+
await instance.start();
|
|
275
|
+
return instance.call(op, input);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/development/developmentService.ts
|
|
280
|
+
function resolveDevelopmentCommand(task) {
|
|
281
|
+
const { command, args } = resolveWebContainerCommand(task);
|
|
282
|
+
return [command, args];
|
|
283
|
+
}
|
|
284
|
+
var DevelopmentServiceDefinition = createServiceDefinition({
|
|
285
|
+
id: "kloks.backend.development",
|
|
286
|
+
name: "DevelopmentService",
|
|
287
|
+
version: "1.1.0",
|
|
288
|
+
operations: {
|
|
289
|
+
plan: {
|
|
290
|
+
id: "DevelopmentService.plan",
|
|
291
|
+
name: "plan",
|
|
292
|
+
handler: async (input) => {
|
|
293
|
+
const [command, args] = resolveDevelopmentCommand(input.task);
|
|
294
|
+
return { task: input.task, command, args };
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
describeProviders: {
|
|
298
|
+
id: "DevelopmentService.describeProviders",
|
|
299
|
+
name: "describeProviders",
|
|
300
|
+
handler: async () => ({
|
|
301
|
+
providers: [
|
|
302
|
+
{ id: "webcontainer", capabilities: ["install", "lint", "test", "build", "validate", "check", "process-host"] },
|
|
303
|
+
{ id: "typescript-language-server", capabilities: ["lsp", "diagnostics", "completion", "hover", "definition", "references", "rename", "symbols"] },
|
|
304
|
+
{ id: "agent-harness", capabilities: ["deepseek", "openai", "google", "headless", "sdk", "acp"] },
|
|
305
|
+
{ id: "github-actions", capabilities: ["dispatch", "observe", "rerun", "cancel"] }
|
|
306
|
+
]
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
var DevelopmentRuntime = class {
|
|
312
|
+
constructor(webContainer = new WebContainerRuntime(), githubActions) {
|
|
313
|
+
this.webContainer = webContainer;
|
|
314
|
+
this.githubActions = githubActions;
|
|
315
|
+
}
|
|
316
|
+
webContainer;
|
|
317
|
+
githubActions;
|
|
318
|
+
async run(request) {
|
|
319
|
+
if (request.provider === "webcontainer") {
|
|
320
|
+
const result = await this.webContainer.run(request.task, request.cwd, request.env);
|
|
321
|
+
return { provider: request.provider, task: request.task, ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: result.command, durationMs: result.durationMs, diagnostics: result.diagnostics };
|
|
322
|
+
}
|
|
323
|
+
if (!this.githubActions || !request.repository || !request.workflowId || !request.ref) {
|
|
324
|
+
throw new Error("GitHub Actions execution requires repository, workflowId, ref, and an authenticated client");
|
|
325
|
+
}
|
|
326
|
+
await this.githubActions.dispatchWorkflow(request.repository, request.workflowId, request.ref, {
|
|
327
|
+
task: request.task,
|
|
328
|
+
...request.workflowInputs ?? {}
|
|
329
|
+
});
|
|
330
|
+
return { provider: request.provider, task: request.task, ok: true, output: "Workflow dispatched; observe its run for final status." };
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
var DevelopmentServiceFacade = {
|
|
334
|
+
id: DevelopmentServiceDefinition.id,
|
|
335
|
+
name: DevelopmentServiceDefinition.name,
|
|
336
|
+
version: DevelopmentServiceDefinition.version,
|
|
337
|
+
runtime: "server",
|
|
338
|
+
deployment: "local",
|
|
339
|
+
definition: DevelopmentServiceDefinition,
|
|
340
|
+
createInstance: () => createService(DevelopmentServiceDefinition),
|
|
341
|
+
execute: async (op, input) => {
|
|
342
|
+
const instance = createService(DevelopmentServiceDefinition);
|
|
343
|
+
await instance.start();
|
|
344
|
+
return instance.call(op, input);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// src/development/codeValidationService.ts
|
|
349
|
+
var COMMANDS2 = {
|
|
350
|
+
syntax: { command: "pnpm", args: ["exec", "tsc", "--noEmit"] },
|
|
351
|
+
lint: { command: "pnpm", args: ["run", "lint", "--if-present"] },
|
|
352
|
+
test: { command: "pnpm", args: ["run", "test", "--if-present"] },
|
|
353
|
+
build: { command: "pnpm", args: ["run", "build", "--if-present"] },
|
|
354
|
+
krnl: { command: "pnpm", args: ["exec", "krnl", "validate"] },
|
|
355
|
+
frnl: { command: "pnpm", args: ["exec", "frnl", "validate"] },
|
|
356
|
+
"lockfile-check": { command: "pnpm", args: ["install", "--frozen-lockfile", "--ignore-scripts"] }
|
|
357
|
+
};
|
|
358
|
+
var DEFAULT_LAYERS = ["lockfile-check", "syntax", "lint", "krnl", "frnl"];
|
|
359
|
+
var commandText = (command, args) => [command, ...args].join(" ");
|
|
360
|
+
var CodeValidationRuntime = class {
|
|
361
|
+
constructor(runtime5 = new WebContainerRuntime()) {
|
|
362
|
+
this.runtime = runtime5;
|
|
363
|
+
}
|
|
364
|
+
runtime;
|
|
365
|
+
async validate(input = {}) {
|
|
366
|
+
if (input.files) await this.runtime.mount(input.files);
|
|
367
|
+
const diagnostics = [];
|
|
368
|
+
if (input.install) {
|
|
369
|
+
const installed = await this.runtime.runCommand("pnpm", ["install", "--frozen-lockfile", "--ignore-scripts"], input.cwd, input.env);
|
|
370
|
+
diagnostics.push({ layer: "lockfile-check", ok: installed.exitCode === 0, exitCode: installed.exitCode, output: installed.output, command: "pnpm install --frozen-lockfile --ignore-scripts" });
|
|
371
|
+
if (installed.exitCode !== 0) return { ok: false, diagnostics, failedLayers: ["lockfile-check"] };
|
|
372
|
+
}
|
|
373
|
+
const layers = input.layers?.length ? input.layers : DEFAULT_LAYERS;
|
|
374
|
+
for (const layer of layers) {
|
|
375
|
+
if (layer === "law-l9") {
|
|
376
|
+
diagnostics.push(await this.validateLawL9(input.cwd, input.maxLines ?? 200));
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const spec = COMMANDS2[layer];
|
|
380
|
+
const result = await this.runtime.runCommand(spec.command, spec.args, input.cwd, input.env);
|
|
381
|
+
diagnostics.push({ layer, ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: commandText(spec.command, spec.args) });
|
|
382
|
+
if (result.exitCode !== 0) break;
|
|
383
|
+
}
|
|
384
|
+
return { ok: diagnostics.every((item) => item.ok), diagnostics, failedLayers: diagnostics.filter((item) => !item.ok).map((item) => item.layer) };
|
|
385
|
+
}
|
|
386
|
+
async validateLawL9(cwd = ".", maxLines = 200) {
|
|
387
|
+
const script = `python3 -c 'import os,sys; bad=[]; root="src"; [bad.append(os.path.join(r,f)+": "+str(len(open(os.path.join(r,f),encoding="utf-8",errors="ignore").readlines()))+" lines") for r,_,fs in os.walk(root) for f in fs if f.endswith((".ts",".tsx",".js",".jsx")) and not f.endswith(".d.ts") and len(open(os.path.join(r,f),encoding="utf-8",errors="ignore").readlines())>200]; print("\\n".join(bad)); sys.exit(1 if bad else 0)'`;
|
|
388
|
+
const result = await this.runtime.runCommand("sh", ["-lc", script], cwd);
|
|
389
|
+
return { layer: "law-l9", ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: script };
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
var runtime2 = new CodeValidationRuntime();
|
|
393
|
+
var CodeValidationServiceDefinition = createServiceDefinition({
|
|
394
|
+
id: "kloks.backend.codeValidation",
|
|
395
|
+
name: "CodeValidationService",
|
|
396
|
+
version: "1.1.0",
|
|
397
|
+
operations: { validate: { id: "CodeValidationService.validate", name: "validate", handler: async (input) => runtime2.validate(input) } }
|
|
398
|
+
});
|
|
399
|
+
var CodeValidationServiceFacade = {
|
|
400
|
+
id: CodeValidationServiceDefinition.id,
|
|
401
|
+
name: CodeValidationServiceDefinition.name,
|
|
402
|
+
version: CodeValidationServiceDefinition.version,
|
|
403
|
+
runtime: "client",
|
|
404
|
+
deployment: "local",
|
|
405
|
+
definition: CodeValidationServiceDefinition,
|
|
406
|
+
createInstance: () => createService(CodeValidationServiceDefinition),
|
|
407
|
+
execute: async (op, input) => {
|
|
408
|
+
const instance = createService(CodeValidationServiceDefinition);
|
|
409
|
+
await instance.start();
|
|
410
|
+
return instance.call(op, input);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// src/development/codeDiagnosticsService.ts
|
|
415
|
+
var CodeDiagnosticsService = class {
|
|
416
|
+
constructor(runtime5 = new WebContainerRuntime()) {
|
|
417
|
+
this.runtime = runtime5;
|
|
418
|
+
}
|
|
419
|
+
runtime;
|
|
420
|
+
async diagnostics(input = {}) {
|
|
421
|
+
const args = ["exec", "tsc", "--noEmit", "--pretty", "false"];
|
|
422
|
+
if (input.file) args.push(input.file);
|
|
423
|
+
const result = await this.runtime.runCommand("pnpm", args, input.cwd);
|
|
424
|
+
return { ok: result.exitCode === 0, output: result.output, command: ["pnpm", ...args].join(" ") };
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
var codeDiagnosticsService = new CodeDiagnosticsService();
|
|
428
|
+
|
|
429
|
+
// src/development/typescriptLanguageServerService.ts
|
|
430
|
+
var TYPESCRIPT_LANGUAGE_SERVER_PACKAGE = "typescript-language-server";
|
|
431
|
+
var TYPESCRIPT_LANGUAGE_SERVER_VERSION = "6.0.2";
|
|
432
|
+
var PACKAGE = TYPESCRIPT_LANGUAGE_SERVER_PACKAGE;
|
|
433
|
+
var DEFAULT_VERSION = TYPESCRIPT_LANGUAGE_SERVER_VERSION;
|
|
434
|
+
var TypeScriptLanguageServerRuntime = class {
|
|
435
|
+
constructor(runtime5 = new WebContainerRuntime()) {
|
|
436
|
+
this.runtime = runtime5;
|
|
437
|
+
}
|
|
438
|
+
runtime;
|
|
439
|
+
process = null;
|
|
440
|
+
writer = null;
|
|
441
|
+
pending = /* @__PURE__ */ new Map();
|
|
442
|
+
buffer = "";
|
|
443
|
+
cwd = ".";
|
|
444
|
+
version = DEFAULT_VERSION;
|
|
445
|
+
async start(input = {}) {
|
|
446
|
+
if (this.process) return this.status();
|
|
447
|
+
this.cwd = input.cwd ?? ".";
|
|
448
|
+
this.version = input.version ?? DEFAULT_VERSION;
|
|
449
|
+
if (input.install !== false) {
|
|
450
|
+
await this.runtime.runCommand("pnpm", ["add", "-D", "typescript@7.0.2", PACKAGE + "@" + this.version], this.cwd);
|
|
451
|
+
}
|
|
452
|
+
this.process = await this.runtime.spawnCommand("pnpm", ["exec", PACKAGE, "--stdio"], this.cwd);
|
|
453
|
+
this.writer = this.process.input.getWriter();
|
|
454
|
+
void this.readOutput(this.process.output);
|
|
455
|
+
return this.status();
|
|
456
|
+
}
|
|
457
|
+
async request(input) {
|
|
458
|
+
await this.ensureRunning();
|
|
459
|
+
const promise = new Promise((resolve, reject) => {
|
|
460
|
+
this.pending.set(input.id, { resolve, reject });
|
|
461
|
+
});
|
|
462
|
+
await this.write(input);
|
|
463
|
+
return promise;
|
|
464
|
+
}
|
|
465
|
+
async notify(input) {
|
|
466
|
+
await this.ensureRunning();
|
|
467
|
+
await this.write(input);
|
|
468
|
+
return { sent: true };
|
|
469
|
+
}
|
|
470
|
+
async stop() {
|
|
471
|
+
const process = this.process;
|
|
472
|
+
this.process = null;
|
|
473
|
+
this.writer?.releaseLock();
|
|
474
|
+
this.writer = null;
|
|
475
|
+
for (const pending of this.pending.values()) pending.reject(new Error("Language server stopped"));
|
|
476
|
+
this.pending.clear();
|
|
477
|
+
if (process) await process.kill();
|
|
478
|
+
return { stopped: true };
|
|
479
|
+
}
|
|
480
|
+
status() {
|
|
481
|
+
return { running: Boolean(this.process), cwd: this.cwd, package: PACKAGE, version: this.version };
|
|
482
|
+
}
|
|
483
|
+
async ensureRunning() {
|
|
484
|
+
if (!this.process) await this.start({ cwd: this.cwd, install: false, version: this.version });
|
|
485
|
+
}
|
|
486
|
+
async write(message) {
|
|
487
|
+
if (!this.writer) throw new Error("Language server input is unavailable");
|
|
488
|
+
const body = JSON.stringify({ jsonrpc: "2.0", ...message });
|
|
489
|
+
const frame = "Content-Length: " + new TextEncoder().encode(body).byteLength + "\r\n\r\n" + body;
|
|
490
|
+
await this.writer.write(frame);
|
|
491
|
+
}
|
|
492
|
+
async readOutput(output) {
|
|
493
|
+
const reader = output.getReader();
|
|
494
|
+
try {
|
|
495
|
+
while (true) {
|
|
496
|
+
const next = await reader.read();
|
|
497
|
+
if (next.done) break;
|
|
498
|
+
this.buffer += next.value;
|
|
499
|
+
this.consumeFrames();
|
|
500
|
+
}
|
|
501
|
+
} catch (error) {
|
|
502
|
+
for (const pending of this.pending.values()) pending.reject(error instanceof Error ? error : new Error(String(error)));
|
|
503
|
+
this.pending.clear();
|
|
504
|
+
} finally {
|
|
505
|
+
reader.releaseLock();
|
|
506
|
+
this.process = null;
|
|
507
|
+
this.writer?.releaseLock();
|
|
508
|
+
this.writer = null;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
consumeFrames() {
|
|
512
|
+
while (true) {
|
|
513
|
+
const separator = this.buffer.indexOf("\r\n\r\n");
|
|
514
|
+
if (separator < 0) return;
|
|
515
|
+
const header = this.buffer.slice(0, separator);
|
|
516
|
+
const match = header.match(/Content-Length:\s*(\d+)/i);
|
|
517
|
+
if (!match) {
|
|
518
|
+
this.buffer = this.buffer.slice(separator + 4);
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const length = Number(match[1]);
|
|
522
|
+
const start = separator + 4;
|
|
523
|
+
if (this.buffer.length - start < length) return;
|
|
524
|
+
const body = this.buffer.slice(start, start + length);
|
|
525
|
+
this.buffer = this.buffer.slice(start + length);
|
|
526
|
+
const response = JSON.parse(body);
|
|
527
|
+
if (response.id !== void 0 && response.id !== null) {
|
|
528
|
+
this.pending.get(response.id)?.resolve(response);
|
|
529
|
+
this.pending.delete(response.id);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var runtime3 = new TypeScriptLanguageServerRuntime();
|
|
535
|
+
var TypeScriptLanguageServerServiceDefinition = createServiceDefinition({
|
|
536
|
+
id: "kloks.backend.typescriptLanguageServer",
|
|
537
|
+
name: "TypeScriptLanguageServerService",
|
|
538
|
+
version: "1.0.0",
|
|
539
|
+
operations: {
|
|
540
|
+
start: { id: "TypeScriptLanguageServerService.start", name: "start", handler: async (input) => runtime3.start(input) },
|
|
541
|
+
request: { id: "TypeScriptLanguageServerService.request", name: "request", handler: async (input) => runtime3.request(input) },
|
|
542
|
+
notify: { id: "TypeScriptLanguageServerService.notify", name: "notify", handler: async (input) => runtime3.notify(input) },
|
|
543
|
+
stop: { id: "TypeScriptLanguageServerService.stop", name: "stop", handler: async () => runtime3.stop() },
|
|
544
|
+
status: { id: "TypeScriptLanguageServerService.status", name: "status", handler: async () => runtime3.status() }
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
var TypeScriptLanguageServerServiceFacade = {
|
|
548
|
+
id: TypeScriptLanguageServerServiceDefinition.id,
|
|
549
|
+
name: TypeScriptLanguageServerServiceDefinition.name,
|
|
550
|
+
version: TypeScriptLanguageServerServiceDefinition.version,
|
|
551
|
+
runtime: "client",
|
|
552
|
+
deployment: "local",
|
|
553
|
+
definition: TypeScriptLanguageServerServiceDefinition,
|
|
554
|
+
createInstance: () => createService(TypeScriptLanguageServerServiceDefinition),
|
|
555
|
+
execute: async (op, input) => {
|
|
556
|
+
const instance = createService(TypeScriptLanguageServerServiceDefinition);
|
|
557
|
+
await instance.start();
|
|
558
|
+
return instance.call(op, input);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
// src/development/agentHarnessService.ts
|
|
563
|
+
var PROVIDERS = [
|
|
564
|
+
{
|
|
565
|
+
id: "deepseek",
|
|
566
|
+
name: "DeepSeek Harness",
|
|
567
|
+
package: "@deepseek-ai/dsh",
|
|
568
|
+
capabilities: ["headless", "sdk", "acp", "web"],
|
|
569
|
+
implemented: true
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
id: "openai",
|
|
573
|
+
name: "OpenAI Agents SDK",
|
|
574
|
+
package: "@openai/agents",
|
|
575
|
+
capabilities: ["agents", "tools", "handoffs", "guardrails", "sessions", "tracing"],
|
|
576
|
+
implemented: false
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
id: "google",
|
|
580
|
+
name: "Google ADK",
|
|
581
|
+
package: "@google/adk",
|
|
582
|
+
capabilities: ["agents", "tools", "multi-agent", "evaluation", "deployment"],
|
|
583
|
+
implemented: false
|
|
584
|
+
}
|
|
585
|
+
];
|
|
586
|
+
var AgentHarnessRuntime = class {
|
|
587
|
+
constructor(runtime5 = new WebContainerRuntime()) {
|
|
588
|
+
this.runtime = runtime5;
|
|
589
|
+
}
|
|
590
|
+
runtime;
|
|
591
|
+
providers() {
|
|
592
|
+
return PROVIDERS.map((provider) => ({ ...provider, capabilities: [...provider.capabilities] }));
|
|
593
|
+
}
|
|
594
|
+
async run(input) {
|
|
595
|
+
if (input.provider !== "deepseek") {
|
|
596
|
+
throw new Error(
|
|
597
|
+
`Agent harness provider "${input.provider}" is registered but not yet executable; install and register its adapter before running it.`
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
const started = Date.now();
|
|
601
|
+
const profile = input.profile ?? "headless";
|
|
602
|
+
const command = "pnpm";
|
|
603
|
+
const args = ["exec", "dsh", "--profile", profile, input.prompt];
|
|
604
|
+
const result = await this.runtime.runCommand(command, args, input.cwd ?? ".", input.env);
|
|
605
|
+
return {
|
|
606
|
+
provider: input.provider,
|
|
607
|
+
ok: result.exitCode === 0,
|
|
608
|
+
exitCode: result.exitCode,
|
|
609
|
+
output: result.output,
|
|
610
|
+
durationMs: Date.now() - started,
|
|
611
|
+
command: [command, ...args].join(" ")
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
var runtime4 = new AgentHarnessRuntime();
|
|
616
|
+
var AgentHarnessServiceDefinition = createServiceDefinition({
|
|
617
|
+
id: "kloks.backend.agentHarness",
|
|
618
|
+
name: "AgentHarnessService",
|
|
619
|
+
version: "1.0.0",
|
|
620
|
+
operations: {
|
|
621
|
+
providers: {
|
|
622
|
+
id: "AgentHarnessService.providers",
|
|
623
|
+
name: "providers",
|
|
624
|
+
handler: async () => runtime4.providers()
|
|
625
|
+
},
|
|
626
|
+
run: {
|
|
627
|
+
id: "AgentHarnessService.run",
|
|
628
|
+
name: "run",
|
|
629
|
+
handler: async (input) => runtime4.run(input)
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
var AgentHarnessServiceFacade = {
|
|
634
|
+
id: AgentHarnessServiceDefinition.id,
|
|
635
|
+
name: AgentHarnessServiceDefinition.name,
|
|
636
|
+
version: AgentHarnessServiceDefinition.version,
|
|
637
|
+
runtime: "client",
|
|
638
|
+
deployment: "local",
|
|
639
|
+
definition: AgentHarnessServiceDefinition,
|
|
640
|
+
createInstance: () => createService(AgentHarnessServiceDefinition),
|
|
641
|
+
execute: async (op, input) => {
|
|
642
|
+
const instance = createService(AgentHarnessServiceDefinition);
|
|
643
|
+
await instance.start();
|
|
644
|
+
return instance.call(op, input);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
36
647
|
export {
|
|
37
648
|
AgentHarnessRuntime,
|
|
38
649
|
AgentHarnessServiceDefinition,
|