@ultrst-armada/kloks 1.23.0 → 1.24.1

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 (26) hide show
  1. package/.krusbl-release-attestation.json +3 -3
  2. package/package.json +6 -1
  3. package/packages/backend/dist/auth/index.d.ts +2 -0
  4. package/packages/backend/dist/auth/index.js +2 -2
  5. package/packages/backend/dist/{chunk-WTBAG4AV.js → chunk-2HCQ2SIR.js} +9 -3
  6. package/packages/backend/dist/{chunk-IJ5QNZCY.js → chunk-6TRVGWXP.js} +282 -47
  7. package/packages/backend/dist/{chunk-W6JNJD3Q.js → chunk-A3BE6ROS.js} +1 -1
  8. package/packages/backend/dist/{chunk-3IUA66RS.js → chunk-HF5SGQ5V.js} +1 -1
  9. package/packages/backend/dist/{chunk-47IVAXPJ.js → chunk-IGZB4RYT.js} +1 -1
  10. package/packages/backend/dist/{chunk-VAFCR2MS.js → chunk-JCMB7BIM.js} +11 -3
  11. package/packages/backend/dist/{chunk-VN2YMZJO.js → chunk-JGUWYVOL.js} +1 -1
  12. package/packages/backend/dist/{chunk-NB2X3HEX.js → chunk-VTU6CNZD.js} +4 -4
  13. package/packages/backend/dist/{chunk-6DNGLKAV.js → chunk-WQ4XZY4L.js} +5 -5
  14. package/packages/backend/dist/development/index.d.ts +108 -6
  15. package/packages/backend/dist/development/index.js +15 -3
  16. package/packages/backend/dist/index.d.ts +1 -1
  17. package/packages/backend/dist/index.js +32 -20
  18. package/packages/backend/dist/krnl-services.js +5 -5
  19. package/packages/backend/dist/services/index.js +3 -3
  20. package/packages/backend/dist/srkl/index.js +2 -2
  21. package/packages/backend/dist/workspace/index.js +3 -3
  22. package/packages/backend/package.json +1 -1
  23. package/packages/semantic-runtime/dist/index.d.ts +132 -2
  24. package/packages/semantic-runtime/dist/index.js +300 -8
  25. package/packages/services/dist/index.d.ts +71 -1
  26. package/packages/services/dist/index.js +125 -0
@@ -15,7 +15,14 @@ var CapabilityRegistry = class {
15
15
  return [...this.items.values()];
16
16
  }
17
17
  findBySemanticType(semanticType) {
18
- return this.list().filter((c) => (c.requirements ?? []).some((r) => r.semanticType === semanticType));
18
+ return this.list().filter(
19
+ (c) => (c.requirements ?? []).some((r) => r.semanticType === semanticType) || (c.provides ?? []).some((p) => p.semanticType === semanticType)
20
+ );
21
+ }
22
+ findProviders(semanticType) {
23
+ return this.list().filter(
24
+ (c) => (c.provides ?? []).some((p) => p.semanticType === semanticType)
25
+ );
19
26
  }
20
27
  };
21
28
 
@@ -34,6 +41,43 @@ var ContextResolver = class {
34
41
  };
35
42
 
36
43
  // src/resolution.ts
44
+ var CapabilityRequirementSource = class {
45
+ constructor(registry, executor) {
46
+ this.registry = registry;
47
+ this.executor = executor;
48
+ }
49
+ registry;
50
+ executor;
51
+ name = "capability-execution";
52
+ async canResolve(requirement) {
53
+ return this.registry.findProviders(requirement.semanticType).length > 0;
54
+ }
55
+ async resolve(requirement, context) {
56
+ const candidates = this.registry.findProviders(requirement.semanticType);
57
+ if (candidates.length === 0) throw new Error(`No capability provides ${requirement.semanticType}`);
58
+ return this.executeProvider(candidates[0], context, /* @__PURE__ */ new Set([candidates[0].id]));
59
+ }
60
+ async executeProvider(capability, context, visiting) {
61
+ const input = {};
62
+ for (const template of capability.requirements ?? []) {
63
+ if (!template.required) continue;
64
+ const existing = context.task.requirements.find((r) => r.semanticType === template.semanticType && r.value !== void 0);
65
+ if (existing) {
66
+ input[template.sourceField ?? template.id] = existing.value;
67
+ continue;
68
+ }
69
+ const providers = this.registry.findProviders(template.semanticType).filter((candidate) => !visiting.has(candidate.id));
70
+ if (!providers.length)
71
+ throw new Error(`CAPABILITY_REQUIRES_EXECUTION:${capability.id}:${template.semanticType}`);
72
+ const provider = providers[0];
73
+ visiting.add(provider.id);
74
+ const value = await this.executeProvider(provider, context, visiting);
75
+ input[template.sourceField ?? template.id] = value;
76
+ visiting.delete(provider.id);
77
+ }
78
+ return this.executor.execute(capability, input, context);
79
+ }
80
+ };
37
81
  var RequirementResolver = class {
38
82
  constructor(registry, sources = []) {
39
83
  this.registry = registry;
@@ -42,14 +86,17 @@ var RequirementResolver = class {
42
86
  registry;
43
87
  sources;
44
88
  async resolve(requirement, context) {
89
+ if (requirement.value !== void 0)
90
+ return { resolved: true, value: requirement.value, source: "task-context" };
45
91
  for (const source of this.sources) {
46
92
  if (await source.canResolve(requirement, context))
47
93
  return { resolved: true, value: await source.resolve(requirement, context), source: source.name };
48
94
  }
49
- const candidates = this.registry.list().filter((c) => c.inputSchema?.properties?.[requirement.sourceField ?? ""] !== void 0);
50
- if (candidates.length === 0)
51
- return { resolved: false, reason: "NO_INTERNAL_RESOLUTION" };
52
- return { resolved: false, reason: "CAPABILITY_REQUIRES_EXECUTION", source: candidates[0].id };
95
+ const providers = this.registry.findProviders(requirement.semanticType);
96
+ if (providers.length) return { resolved: false, reason: "CAPABILITY_REQUIRES_EXECUTION", source: providers[0].id, capabilityId: providers[0].id };
97
+ const candidates = this.registry.list().filter((capability) => capability.inputSchema?.properties?.[requirement.sourceField ?? ""] !== void 0);
98
+ if (candidates.length) return { resolved: false, reason: "CAPABILITY_REQUIRES_EXECUTION", source: candidates[0].id, capabilityId: candidates[0].id };
99
+ return { resolved: false, reason: "NO_INTERNAL_RESOLUTION" };
53
100
  }
54
101
  };
55
102
 
@@ -73,9 +120,9 @@ var TaskRuntime = class {
73
120
  }
74
121
  events;
75
122
  store;
76
- create(request, parentTaskId, contextId = crypto.randomUUID()) {
123
+ create(request, parentTaskId, contextId) {
77
124
  const id = crypto.randomUUID();
78
- const context = { taskId: id, parentTaskId, request, requirements: [], artifacts: [], contextId };
125
+ const context = { taskId: id, parentTaskId, request, requirements: [], artifacts: [], contextId: contextId ?? crypto.randomUUID() };
79
126
  const task = { id, status: "submitted", request, context };
80
127
  this.store.set(task);
81
128
  this.events?.emit({ type: "task.created", task });
@@ -84,6 +131,9 @@ var TaskRuntime = class {
84
131
  get(id) {
85
132
  return this.store.get(id);
86
133
  }
134
+ list() {
135
+ return this.store.list();
136
+ }
87
137
  transition(id, status) {
88
138
  const task = this.mustGet(id);
89
139
  task.status = status;
@@ -93,7 +143,9 @@ var TaskRuntime = class {
93
143
  }
94
144
  addRequirement(id, requirement) {
95
145
  const task = this.mustGet(id);
96
- task.context.requirements.push(requirement);
146
+ const existing = task.context.requirements.find((r) => r.id === requirement.id);
147
+ if (existing) Object.assign(existing, requirement);
148
+ else task.context.requirements.push(requirement);
97
149
  task.status = "input-required";
98
150
  this.store.set(task);
99
151
  this.events?.emit({ type: "task.requirement", task });
@@ -193,13 +245,253 @@ var CapabilityExecutionRuntime = class {
193
245
  return { artifact: { id: crypto.randomUUID(), type: capability.outputSchema?.type ?? "application/json", value, producer: capability.id, taskId: context.task.taskId, provenance: { capabilityId: capability.id } } };
194
246
  }
195
247
  };
248
+
249
+ // src/orchestrator.ts
250
+ var SemanticOrchestrator = class {
251
+ constructor(capabilities, tasks, requirements, planner, executor, authorization) {
252
+ this.capabilities = capabilities;
253
+ this.tasks = tasks;
254
+ this.requirements = requirements;
255
+ this.planner = planner;
256
+ this.executor = executor;
257
+ this.authorization = authorization;
258
+ }
259
+ capabilities;
260
+ tasks;
261
+ requirements;
262
+ planner;
263
+ executor;
264
+ authorization;
265
+ graphs = new TaskGraphRuntime();
266
+ async run(task, context) {
267
+ this.tasks.transition(task.id, "working");
268
+ try {
269
+ const plan = await this.planner.plan(task.request, context);
270
+ task.context.intent = plan.intent;
271
+ if (plan.requirements?.length) for (const requirement of plan.requirements) {
272
+ const existing = task.context.requirements.find((r) => r.id === requirement.id);
273
+ if (existing) Object.assign(existing, { ...requirement, value: existing.value });
274
+ else task.context.requirements.push(requirement);
275
+ }
276
+ for (const requirement of task.context.requirements) {
277
+ if (!requirement.required || requirement.value !== void 0) continue;
278
+ const resolved = await this.requirements.resolve(requirement, context);
279
+ if (resolved.resolved) {
280
+ requirement.value = resolved.value;
281
+ continue;
282
+ }
283
+ this.tasks.addRequirement(task.id, requirement);
284
+ return { status: "input-required", task: this.tasks.get(task.id), requirements: [requirement] };
285
+ }
286
+ const graph = this.graphs.create(task.id, plan.nodes);
287
+ const outputs = [];
288
+ while (true) {
289
+ const ready = this.graphs.ready(graph.id);
290
+ if (ready.length === 0) break;
291
+ await Promise.all(ready.map(async (node) => {
292
+ const capability = this.capabilities.get(node.capabilityId);
293
+ if (!capability) throw new Error(`Unknown capability: ${node.capabilityId}`);
294
+ const input = this.resolveInput(node.input, task.context.requirements);
295
+ const executionResult = this.authorization ? await new CapabilityExecutionRuntime(this.authorization).execute(capability, input, context, this.executor) : await new CapabilityExecutionRuntime().execute(capability, input, context, this.executor);
296
+ this.tasks.addArtifact(task.id, executionResult.artifact);
297
+ outputs.push(executionResult.artifact.value);
298
+ this.graphs.transition(graph.id, node.id, "completed");
299
+ }));
300
+ }
301
+ const unfinished = graph.nodes.some((n) => n.status !== "completed");
302
+ if (unfinished) throw new Error("TASK_GRAPH_STALLED");
303
+ task.result = outputs.length === 1 ? outputs[0] : outputs;
304
+ this.tasks.transition(task.id, "completed");
305
+ return { status: "completed", task: this.tasks.get(task.id), output: outputs };
306
+ } catch (error) {
307
+ const message = error instanceof Error ? error.message : String(error);
308
+ task.error = message;
309
+ this.tasks.transition(task.id, "failed");
310
+ return { status: "failed", task: this.tasks.get(task.id), error: message };
311
+ }
312
+ }
313
+ resolveInput(input, requirements) {
314
+ if (!input || typeof input !== "object") return input;
315
+ const values = new Map(requirements.map((r) => [r.id, r.value]));
316
+ const visit = (value) => {
317
+ if (typeof value === "string" && value.startsWith("$requirement:"))
318
+ return values.get(value.slice("$requirement:".length));
319
+ if (Array.isArray(value)) return value.map(visit);
320
+ if (value && typeof value === "object")
321
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, visit(v)]));
322
+ return value;
323
+ };
324
+ return visit(input);
325
+ }
326
+ };
327
+
328
+ // src/conversation.ts
329
+ var MemoryConversationStore = class {
330
+ items = /* @__PURE__ */ new Map();
331
+ get(id) {
332
+ return this.items.get(id);
333
+ }
334
+ set(conversation) {
335
+ this.items.set(conversation.id, conversation);
336
+ }
337
+ };
338
+ var ConversationRuntime = class {
339
+ constructor(options) {
340
+ this.options = options;
341
+ this.store = options.store ?? new MemoryConversationStore();
342
+ }
343
+ options;
344
+ store;
345
+ async send(input, conversationId, taskId) {
346
+ const conversation = this.getOrCreate(conversationId);
347
+ let task = taskId ? this.options.tasks.get(taskId) : void 0;
348
+ if (!task && conversation.taskIds.length > 0) {
349
+ const lastTaskId = conversation.taskIds[conversation.taskIds.length - 1];
350
+ const candidate = this.options.tasks.get(lastTaskId);
351
+ if (candidate && candidate.status === "input-required") task = candidate;
352
+ }
353
+ const activeTask = task ?? this.options.tasks.create(input, void 0, conversation.id);
354
+ if (!task) conversation.taskIds.push(activeTask.id);
355
+ conversation.messages.push({
356
+ id: crypto.randomUUID(),
357
+ role: "user",
358
+ content: input,
359
+ taskId: activeTask.id,
360
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
361
+ });
362
+ this.store.set(conversation);
363
+ const context = await this.options.buildContext(activeTask.id, conversation.id);
364
+ if (task && activeTask.status === "input-required") {
365
+ const requirement = activeTask.context.requirements.find((r) => r.required && r.value === void 0);
366
+ if (requirement) {
367
+ requirement.value = await this.options.inputResolver.resolve(input, requirement, context);
368
+ activeTask.status = "submitted";
369
+ }
370
+ }
371
+ const result = await this.options.orchestrator.run(activeTask, context);
372
+ conversation.messages.push({
373
+ id: crypto.randomUUID(),
374
+ role: "agent",
375
+ content: this.describe(result),
376
+ taskId: activeTask.id,
377
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
378
+ });
379
+ this.store.set(conversation);
380
+ return result;
381
+ }
382
+ get(id) {
383
+ return this.store.get(id);
384
+ }
385
+ getOrCreate(id) {
386
+ if (id) {
387
+ const existing = this.store.get(id);
388
+ if (existing) return existing;
389
+ }
390
+ const conversation = { id: id ?? crypto.randomUUID(), messages: [], taskIds: [] };
391
+ this.store.set(conversation);
392
+ return conversation;
393
+ }
394
+ describe(result) {
395
+ if (result.status === "completed") return "Task completed.";
396
+ if (result.status === "input-required")
397
+ return result.requirements.map((r) => r.description).join(" ");
398
+ return `Task failed: ${result.error}`;
399
+ }
400
+ };
401
+
402
+ // src/workspaceStore.ts
403
+ function text(value) {
404
+ return typeof value === "string" ? value : Buffer.from(value).toString("utf8");
405
+ }
406
+ function safe(id) {
407
+ return id.replace(/[^a-zA-Z0-9._-]/g, "_");
408
+ }
409
+ var WorkspaceTaskStore = class {
410
+ constructor(workspace, workspaceId, root = "SEMANTIC/tasks") {
411
+ this.workspace = workspace;
412
+ this.workspaceId = workspaceId;
413
+ this.root = root;
414
+ }
415
+ workspace;
416
+ workspaceId;
417
+ root;
418
+ items = /* @__PURE__ */ new Map();
419
+ async hydrate() {
420
+ const entries = await this.workspace.listFiles(this.workspaceId, this.root);
421
+ for (const entry of entries) {
422
+ if (entry.isFolder || !entry.name.endsWith(".json")) continue;
423
+ try {
424
+ const task = JSON.parse(text(await this.workspace.readFile(this.workspaceId, entry.path)));
425
+ this.items.set(task.id, task);
426
+ } catch {
427
+ }
428
+ }
429
+ return this.list();
430
+ }
431
+ get(id) {
432
+ return this.items.get(id);
433
+ }
434
+ set(task) {
435
+ this.items.set(task.id, task);
436
+ void this.workspace.writeFile(this.workspaceId, `${this.root}/${safe(task.id)}.json`, JSON.stringify(task, null, 2));
437
+ }
438
+ list() {
439
+ return [...this.items.values()];
440
+ }
441
+ async delete(id) {
442
+ this.items.delete(id);
443
+ await this.workspace.deleteFile(this.workspaceId, `${this.root}/${safe(id)}.json`);
444
+ }
445
+ };
446
+ var WorkspaceConversationStore = class {
447
+ constructor(workspace, workspaceId, root = "SEMANTIC/conversations") {
448
+ this.workspace = workspace;
449
+ this.workspaceId = workspaceId;
450
+ this.root = root;
451
+ }
452
+ workspace;
453
+ workspaceId;
454
+ root;
455
+ items = /* @__PURE__ */ new Map();
456
+ async hydrate() {
457
+ const entries = await this.workspace.listFiles(this.workspaceId, this.root);
458
+ for (const entry of entries) {
459
+ if (entry.isFolder || !entry.name.endsWith(".json")) continue;
460
+ try {
461
+ const conversation = JSON.parse(text(await this.workspace.readFile(this.workspaceId, entry.path)));
462
+ this.items.set(conversation.id, conversation);
463
+ } catch {
464
+ }
465
+ }
466
+ return this.list();
467
+ }
468
+ get(id) {
469
+ return this.items.get(id);
470
+ }
471
+ set(conversation) {
472
+ this.items.set(conversation.id, conversation);
473
+ void this.workspace.writeFile(this.workspaceId, `${this.root}/${safe(conversation.id)}.json`, JSON.stringify(conversation, null, 2));
474
+ }
475
+ list() {
476
+ return [...this.items.values()];
477
+ }
478
+ async delete(id) {
479
+ this.items.delete(id);
480
+ await this.workspace.deleteFile(this.workspaceId, `${this.root}/${safe(id)}.json`);
481
+ }
482
+ };
196
483
  export {
197
484
  AgentRegistry,
198
485
  CapabilityExecutionRuntime,
199
486
  CapabilityRegistry,
487
+ CapabilityRequirementSource,
200
488
  ContextResolver,
489
+ ConversationRuntime,
201
490
  RequirementResolver,
491
+ SemanticOrchestrator,
202
492
  TaskGraphRuntime,
203
493
  TaskRuntime,
494
+ WorkspaceConversationStore,
495
+ WorkspaceTaskStore,
204
496
  createSemanticRequest
205
497
  };
@@ -454,6 +454,76 @@ declare const krnlSystemDbClientServiceFacade: {
454
454
  execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
455
455
  };
456
456
 
457
+ interface GitHubVcsProviderOptions {
458
+ token: string;
459
+ apiBaseUrl?: string;
460
+ }
461
+ interface GitHubFile {
462
+ path: string;
463
+ content: string;
464
+ sha?: string;
465
+ }
466
+ declare class GitHubVcsProvider {
467
+ private readonly options;
468
+ readonly id = "github";
469
+ private readonly apiBaseUrl;
470
+ constructor(options: GitHubVcsProviderOptions);
471
+ private request;
472
+ getRepository(repository: string): Promise<unknown>;
473
+ createBranch(repository: string, branch: string, sha: string): Promise<unknown>;
474
+ getFile(repository: string, path: string, ref?: string): Promise<GitHubFile>;
475
+ writeFile(repository: string, file: GitHubFile, message: string, branch: string): Promise<unknown>;
476
+ createPullRequest(repository: string, title: string, body: string, head: string, base?: string): Promise<unknown>;
477
+ }
478
+
479
+ interface LocalExecutionRequest {
480
+ command: string;
481
+ cwd?: string;
482
+ environment?: Readonly<Record<string, string>>;
483
+ timeoutMs?: number;
484
+ }
485
+ interface LocalExecutionResult {
486
+ executionId: string;
487
+ status: "succeeded" | "failed" | "timed-out";
488
+ exitCode?: number;
489
+ stdout: string;
490
+ stderr: string;
491
+ }
492
+ declare class LocalExecutionProvider {
493
+ readonly id = "local";
494
+ execute(request: LocalExecutionRequest): Promise<LocalExecutionResult>;
495
+ }
496
+
497
+ interface Workspace {
498
+ id: string;
499
+ root: string;
500
+ }
501
+ declare class LocalWorkspaceProvider {
502
+ readonly id = "local-workspace";
503
+ private readonly workspaces;
504
+ create(prefix?: string): Promise<Workspace>;
505
+ get(workspaceId: string): Workspace;
506
+ destroy(workspaceId: string): Promise<void>;
507
+ }
508
+
509
+ interface VerificationStep {
510
+ id: string;
511
+ name: string;
512
+ command: string;
513
+ cwd?: string;
514
+ }
515
+ interface VerificationReport {
516
+ id: string;
517
+ status: "passed" | "failed";
518
+ checks: readonly LocalExecutionResult[];
519
+ }
520
+ declare class CommandVerificationProvider {
521
+ private readonly execution;
522
+ readonly id = "command-verification";
523
+ constructor(execution?: LocalExecutionProvider);
524
+ verify(steps: readonly VerificationStep[]): Promise<VerificationReport>;
525
+ }
526
+
457
527
  interface ServiceFacade<TState extends Record<string, unknown> = Record<string, unknown>, TEvents extends Record<string, unknown> = Record<string, unknown>> {
458
528
  readonly id: string;
459
529
  readonly name: string;
@@ -510,4 +580,4 @@ declare const krnlServiceDDefinition: ServiceDefinition<Record<string, unknown>,
510
580
  declare const krnlServiceDFacade: ServiceFacade<Record<string, unknown>, Record<string, unknown>>;
511
581
  declare const krnlExposeServiceD: typeof exposeServiceD;
512
582
 
513
- export { AuthClientServiceDefinition, AuthClientServiceFacade, type AuthListener, AuthService, AuthServiceUISchema, CLEAN_DATABASE_CLUSTER, type CounterState, DEFAULT_CONNECTIONS, type EcosystemServiceCategory, type IAuthStore, type MathInput, MonacoIdeServiceDefinition, MonacoIdeServiceFacade, type ProtocolExposureHandle, STORAGE_KEY_CONNECTIONS, ServiceADefinition, ServiceAFacade, ServiceBDefinition, ServiceBFacade, ServiceCDefinition, ServiceCFacade, ServiceDDefinition, ServiceDFacade, type ServiceFacade, type SrklAccount, SrklAccountClient, type SrklAccountClientOptions, type SrklAccountManifest, type SrklAccountSyncResult, StorageClientServiceDefinition, StorageClientServiceFacade, StorageService, StorageServiceUISchema, SystemDbClientServiceDefinition, SystemDbClientServiceFacade, SystemDbService, SystemDbServiceUISchema, type SystemEnvironmentStatus, type SystemTelemetry, type TelemetryEvents, UIAuthoringServiceDefinition, UIAuthoringServiceFacade, authService, clearSession, createMonacoIdeService, createServiceB, createServiceC, createSrklAccountClient, createUIAuthoringService, createWorkspace, deleteWorkspace, exposeServiceD, fetchWorkspaces, krnlAuthClientServiceDefinition, krnlAuthClientServiceFacade, krnlCreateServiceB, krnlCreateServiceC, krnlExposeServiceD, krnlServiceADefinition, krnlServiceAFacade, krnlServiceBDefinition, krnlServiceBFacade, krnlServiceCDefinition, krnlServiceCFacade, krnlServiceDDefinition, krnlServiceDFacade, krnlStorageClientServiceDefinition, krnlStorageClientServiceFacade, krnlSystemDbClientServiceDefinition, krnlSystemDbClientServiceFacade, loadDatabase, loginAdmin, loginUser, mergeSrklAccounts, persistDatabase, register, restoreSession, setActiveWorkspace, setSession, storageService, systemDbService, updateWorkspace, verifyPassword };
583
+ export { AuthClientServiceDefinition, AuthClientServiceFacade, type AuthListener, AuthService, AuthServiceUISchema, CLEAN_DATABASE_CLUSTER, CommandVerificationProvider, type CounterState, DEFAULT_CONNECTIONS, type EcosystemServiceCategory, type GitHubFile, GitHubVcsProvider, type GitHubVcsProviderOptions, type IAuthStore, LocalExecutionProvider, type LocalExecutionRequest, type LocalExecutionResult, LocalWorkspaceProvider, type MathInput, MonacoIdeServiceDefinition, MonacoIdeServiceFacade, type ProtocolExposureHandle, STORAGE_KEY_CONNECTIONS, ServiceADefinition, ServiceAFacade, ServiceBDefinition, ServiceBFacade, ServiceCDefinition, ServiceCFacade, ServiceDDefinition, ServiceDFacade, type ServiceFacade, type SrklAccount, SrklAccountClient, type SrklAccountClientOptions, type SrklAccountManifest, type SrklAccountSyncResult, StorageClientServiceDefinition, StorageClientServiceFacade, StorageService, StorageServiceUISchema, SystemDbClientServiceDefinition, SystemDbClientServiceFacade, SystemDbService, SystemDbServiceUISchema, type SystemEnvironmentStatus, type SystemTelemetry, type TelemetryEvents, UIAuthoringServiceDefinition, UIAuthoringServiceFacade, type VerificationReport, type VerificationStep, type Workspace, authService, clearSession, createMonacoIdeService, createServiceB, createServiceC, createSrklAccountClient, createUIAuthoringService, createWorkspace, deleteWorkspace, exposeServiceD, fetchWorkspaces, krnlAuthClientServiceDefinition, krnlAuthClientServiceFacade, krnlCreateServiceB, krnlCreateServiceC, krnlExposeServiceD, krnlServiceADefinition, krnlServiceAFacade, krnlServiceBDefinition, krnlServiceBFacade, krnlServiceCDefinition, krnlServiceCFacade, krnlServiceDDefinition, krnlServiceDFacade, krnlStorageClientServiceDefinition, krnlStorageClientServiceFacade, krnlSystemDbClientServiceDefinition, krnlSystemDbClientServiceFacade, loadDatabase, loginAdmin, loginUser, mergeSrklAccounts, persistDatabase, register, restoreSession, setActiveWorkspace, setSession, storageService, systemDbService, updateWorkspace, verifyPassword };
@@ -2787,6 +2787,127 @@ var krnlStorageClientServiceFacade = StorageClientServiceFacade;
2787
2787
  var krnlSystemDbClientServiceDefinition = SystemDbClientServiceDefinition;
2788
2788
  var krnlSystemDbClientServiceFacade = SystemDbClientServiceFacade;
2789
2789
 
2790
+ // src/engineering/github-vcs-provider.ts
2791
+ var GitHubVcsProvider = class {
2792
+ constructor(options) {
2793
+ this.options = options;
2794
+ this.apiBaseUrl = options.apiBaseUrl ?? "https://api.github.com";
2795
+ }
2796
+ options;
2797
+ id = "github";
2798
+ apiBaseUrl;
2799
+ async request(path2, init = {}) {
2800
+ const response = await fetch(this.apiBaseUrl + path2, {
2801
+ ...init,
2802
+ headers: {
2803
+ accept: "application/vnd.github+json",
2804
+ authorization: `Bearer ${this.options.token}`,
2805
+ "x-github-api-version": "2022-11-28",
2806
+ "content-type": "application/json",
2807
+ ...init.headers ?? {}
2808
+ }
2809
+ });
2810
+ if (!response.ok) throw new Error(`GitHub API ${response.status}: ${await response.text()}`);
2811
+ return response.status === 204 ? void 0 : await response.json();
2812
+ }
2813
+ getRepository(repository) {
2814
+ return this.request(`/repos/${repository}`);
2815
+ }
2816
+ createBranch(repository, branch, sha) {
2817
+ return this.request(`/repos/${repository}/git/refs`, { method: "POST", body: JSON.stringify({ ref: `refs/heads/${branch}`, sha }) });
2818
+ }
2819
+ getFile(repository, path2, ref) {
2820
+ const query = ref ? `?ref=${encodeURIComponent(ref)}` : "";
2821
+ return this.request(`/repos/${repository}/contents/${path2}${query}`);
2822
+ }
2823
+ writeFile(repository, file, message, branch) {
2824
+ return this.request(`/repos/${repository}/contents/${file.path}`, { method: "PUT", body: JSON.stringify({ message, content: Buffer.from(file.content, "utf8").toString("base64"), sha: file.sha, branch }) });
2825
+ }
2826
+ createPullRequest(repository, title, body, head, base = "main") {
2827
+ return this.request(`/repos/${repository}/pulls`, { method: "POST", body: JSON.stringify({ title, body, head, base }) });
2828
+ }
2829
+ };
2830
+
2831
+ // src/engineering/local-execution-provider.ts
2832
+ import { spawn } from "child_process";
2833
+ var LocalExecutionProvider = class {
2834
+ id = "local";
2835
+ async execute(request) {
2836
+ const executionId = crypto.randomUUID();
2837
+ return new Promise((resolve) => {
2838
+ const child = spawn("sh", ["-lc", request.command], {
2839
+ cwd: request.cwd,
2840
+ env: { ...process.env, ...request.environment ?? {} }
2841
+ });
2842
+ let stdout = "";
2843
+ let stderr = "";
2844
+ let settled = false;
2845
+ let timer;
2846
+ const finish = (result) => {
2847
+ if (settled) return;
2848
+ settled = true;
2849
+ if (timer) clearTimeout(timer);
2850
+ resolve(result);
2851
+ };
2852
+ child.stdout.on("data", (chunk2) => {
2853
+ stdout += chunk2.toString();
2854
+ });
2855
+ child.stderr.on("data", (chunk2) => {
2856
+ stderr += chunk2.toString();
2857
+ });
2858
+ child.on("error", (error) => finish({ executionId, status: "failed", exitCode: void 0, stdout, stderr: stderr + error.message }));
2859
+ child.on("close", (code) => finish({ executionId, status: code === 0 ? "succeeded" : "failed", exitCode: code ?? void 0, stdout, stderr }));
2860
+ if (request.timeoutMs && request.timeoutMs > 0) timer = setTimeout(() => {
2861
+ child.kill("SIGTERM");
2862
+ finish({ executionId, status: "timed-out", stdout, stderr });
2863
+ }, request.timeoutMs);
2864
+ });
2865
+ }
2866
+ };
2867
+
2868
+ // src/engineering/workspace-provider.ts
2869
+ import { mkdtemp, rm } from "fs/promises";
2870
+ import { tmpdir } from "os";
2871
+ import { join } from "path";
2872
+ var LocalWorkspaceProvider = class {
2873
+ id = "local-workspace";
2874
+ workspaces = /* @__PURE__ */ new Map();
2875
+ async create(prefix = "krusbl-") {
2876
+ const root = await mkdtemp(join(tmpdir(), prefix));
2877
+ const workspace = { id: crypto.randomUUID(), root };
2878
+ this.workspaces.set(workspace.id, workspace);
2879
+ return workspace;
2880
+ }
2881
+ get(workspaceId) {
2882
+ const workspace = this.workspaces.get(workspaceId);
2883
+ if (!workspace) throw new Error(`Unknown workspace: ${workspaceId}`);
2884
+ return workspace;
2885
+ }
2886
+ async destroy(workspaceId) {
2887
+ const workspace = this.get(workspaceId);
2888
+ await rm(workspace.root, { recursive: true, force: true });
2889
+ this.workspaces.delete(workspaceId);
2890
+ }
2891
+ };
2892
+
2893
+ // src/engineering/verification-provider.ts
2894
+ var CommandVerificationProvider = class {
2895
+ constructor(execution = new LocalExecutionProvider()) {
2896
+ this.execution = execution;
2897
+ }
2898
+ execution;
2899
+ id = "command-verification";
2900
+ async verify(steps) {
2901
+ const checks = [];
2902
+ for (const step of steps) {
2903
+ const result = await this.execution.execute({ command: step.command, cwd: step.cwd });
2904
+ checks.push(result);
2905
+ if (result.status !== "succeeded") return { id: crypto.randomUUID(), status: "failed", checks };
2906
+ }
2907
+ return { id: crypto.randomUUID(), status: "passed", checks };
2908
+ }
2909
+ };
2910
+
2790
2911
  // src/index.ts
2791
2912
  var ServiceADefinition = createServiceDefinition({
2792
2913
  id: "kloks.service.a",
@@ -3012,7 +3133,11 @@ export {
3012
3133
  AuthService,
3013
3134
  AuthServiceUISchema,
3014
3135
  CLEAN_DATABASE_CLUSTER,
3136
+ CommandVerificationProvider,
3015
3137
  DEFAULT_CONNECTIONS,
3138
+ GitHubVcsProvider,
3139
+ LocalExecutionProvider,
3140
+ LocalWorkspaceProvider,
3016
3141
  MonacoIdeServiceDefinition,
3017
3142
  MonacoIdeServiceFacade,
3018
3143
  STORAGE_KEY_CONNECTIONS,