@ultrst-armada/kloks 1.25.0 → 1.25.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultrst-armada/kloks",
3
- "version": "1.25.0",
3
+ "version": "1.25.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -187,9 +187,10 @@
187
187
  "build": "pnpm -r run build",
188
188
  "postbuild": "node -e \"import('fs').then(fs => { for (const pkg of fs.readdirSync('packages')) { const d = 'packages/' + pkg + '/dist'; if (!fs.existsSync(d)) continue; for (const f of fs.readdirSync(d, { recursive: true })) { const p = d + '/' + f; if (fs.statSync(p).isFile() && (p.endsWith('.js') || p.endsWith('.d.ts'))) { const c = fs.readFileSync(p, 'utf8'); const n = c.replaceAll('@kloks/', '@ultrst-armada/kloks/').replaceAll('@ultrst/kloks/', '@ultrst-armada/kloks/').replaceAll('\\\"kloks/', '\\\"@ultrst-armada/kloks/').replaceAll('\\'kloks/', '\\'@ultrst-armada/kloks/'); if (c !== n) fs.writeFileSync(p, n); } } } })\"",
189
189
  "prepublishOnly": "npm run postbuild",
190
- "test": "vitest run",
190
+ "test": "vitest run && pnpm run verify:npm-trusted-publishing",
191
191
  "typecheck": "pnpm -r run typecheck",
192
- "clean": "pnpm -r run clean"
192
+ "clean": "pnpm -r run clean",
193
+ "verify:npm-trusted-publishing": "node scripts/verify-npm-trusted-publishing.mjs"
193
194
  },
194
195
  "dependencies": {
195
196
  "@dinilmusick/gutts": "^1.4.4",
@@ -0,0 +1,155 @@
1
+ // src/development/webContainerRuntime.ts
2
+ var COMMANDS = {
3
+ install: { command: "pnpm", args: ["install", "--frozen-lockfile"] },
4
+ lint: { command: "pnpm", args: ["lint"] },
5
+ test: { command: "pnpm", args: ["test"] },
6
+ build: { command: "pnpm", args: ["build"] },
7
+ validate: { command: "pnpm", args: ["validate"] },
8
+ check: { command: "pnpm", args: ["lint"] }
9
+ };
10
+ function resolveWebContainerCommand(task) {
11
+ const command = COMMANDS[task];
12
+ return { command: command.command, args: [...command.args] };
13
+ }
14
+ function parseDevelopmentDiagnostics(output, exitCode = 0) {
15
+ const diagnostics = [];
16
+ const seen = /* @__PURE__ */ new Set();
17
+ const add = (diagnostic) => {
18
+ const key = [diagnostic.source, diagnostic.code, diagnostic.file, diagnostic.line, diagnostic.message].join("|");
19
+ if (!seen.has(key)) {
20
+ seen.add(key);
21
+ diagnostics.push(diagnostic);
22
+ }
23
+ };
24
+ for (const line of output.split(/\r?\n/)) {
25
+ const typescript = line.match(/^(.+?)\((\d+),(\d+)\):\s*(error|warning)\s+(TS\d+):\s*(.+)$/);
26
+ if (typescript) {
27
+ add({ source: "typescript", severity: typescript[4], file: typescript[1], line: Number(typescript[2]), column: Number(typescript[3]), code: typescript[5], message: typescript[6] });
28
+ continue;
29
+ }
30
+ const eslint = line.match(/^(.+?):(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+([^\s]+)$/);
31
+ if (eslint) {
32
+ add({ source: "eslint", severity: eslint[4], file: eslint[1], line: Number(eslint[2]), column: Number(eslint[3]), code: eslint[6], message: eslint[5] });
33
+ continue;
34
+ }
35
+ const bundler = line.match(/(?:✘|×|ERROR|error:|Error:)\s*(.+)$/);
36
+ if (bundler) add({ source: "bundler", severity: "error", message: bundler[1].trim() });
37
+ if (/\bWARN(?:ING)?\b/i.test(line)) add({ source: "package-manager", severity: "warning", message: line.trim() });
38
+ }
39
+ if (exitCode !== 0 && diagnostics.every((item) => item.severity !== "error")) {
40
+ add({ source: "unknown", severity: "error", message: "Command failed with exit code " + exitCode + "; inspect captured output for details." });
41
+ }
42
+ return diagnostics;
43
+ }
44
+ function captureDevelopmentProcess(process) {
45
+ const [consumerOutput, diagnosticOutput] = process.output.tee();
46
+ const logs = (async () => {
47
+ const reader = diagnosticOutput.getReader();
48
+ let output = "";
49
+ try {
50
+ while (true) {
51
+ const next = await reader.read();
52
+ if (next.done) break;
53
+ output += next.value;
54
+ }
55
+ } finally {
56
+ reader.releaseLock();
57
+ }
58
+ const exitCode = await process.exit;
59
+ return { output, exitCode, diagnostics: parseDevelopmentDiagnostics(output, exitCode) };
60
+ })();
61
+ return { ...process, output: consumerOutput, logs };
62
+ }
63
+ var runQueue = Promise.resolve();
64
+ var sharedContainer = null;
65
+ var sharedContainerPromise = null;
66
+ var WebContainerRuntime = class {
67
+ async boot() {
68
+ if (typeof window !== "undefined" && !window.crossOriginIsolated) {
69
+ throw new Error("WebContainer requires a cross-origin-isolated page. Ensure COOP=same-origin and COEP=require-corp are served.");
70
+ }
71
+ if (sharedContainer) return sharedContainer;
72
+ if (!sharedContainerPromise) {
73
+ sharedContainerPromise = import("@webcontainer/api").then(async (module) => {
74
+ const container = await module.WebContainer.boot({ coep: "require-corp", workdirName: "kloks-development" });
75
+ sharedContainer = container;
76
+ return container;
77
+ }).catch((error) => {
78
+ sharedContainerPromise = null;
79
+ throw error;
80
+ });
81
+ }
82
+ return sharedContainerPromise;
83
+ }
84
+ async mount(files, mountPoint = "/", sourceSha) {
85
+ const container = await this.boot();
86
+ await container.mount(files, mountPoint === "/" ? void 0 : { mountPoint });
87
+ return { mounted: true, mountPoint, sourceSha };
88
+ }
89
+ async runProcess(command, args, cwd, env, sourceSha) {
90
+ const container = await this.boot();
91
+ const process = await container.spawn(command, args, { cwd, env });
92
+ const started = Date.now();
93
+ let output = "";
94
+ const reader = process.output.getReader();
95
+ try {
96
+ while (true) {
97
+ const next = await reader.read();
98
+ if (next.done) break;
99
+ output += next.value;
100
+ }
101
+ } finally {
102
+ reader.releaseLock();
103
+ }
104
+ const exitCode = await process.exit;
105
+ return {
106
+ exitCode,
107
+ output,
108
+ command: [command, ...args].join(" "),
109
+ durationMs: Date.now() - started,
110
+ diagnostics: parseDevelopmentDiagnostics(output, exitCode),
111
+ sourceSha
112
+ };
113
+ }
114
+ async run(task, cwd, env, sourceSha) {
115
+ const spec = resolveWebContainerCommand(task);
116
+ return this.runCommand(spec.command, spec.args, cwd, env, sourceSha);
117
+ }
118
+ async runCommand(command, args = [], cwd, env, sourceSha) {
119
+ const previous = runQueue;
120
+ let release;
121
+ runQueue = new Promise((resolve) => {
122
+ release = resolve;
123
+ });
124
+ await previous;
125
+ try {
126
+ return await this.runProcess(command, args, cwd, env, sourceSha);
127
+ } finally {
128
+ release();
129
+ }
130
+ }
131
+ async spawnCommand(command, args = [], cwd, env, sourceSha) {
132
+ const container = await this.boot();
133
+ const process = await container.spawn(command, args, { cwd, env });
134
+ return { processId: globalThis.crypto.randomUUID(), sourceSha, command: [command, ...args].join(" "), startedAt: (/* @__PURE__ */ new Date()).toISOString(), process: captureDevelopmentProcess(process) };
135
+ }
136
+ async teardown(mountPoint) {
137
+ const container = sharedContainer;
138
+ if (!container) return { tornDown: true, mountPoint };
139
+ if (mountPoint && mountPoint !== "/") {
140
+ await container.fs.rm(mountPoint, { recursive: true, force: true });
141
+ return { tornDown: true, mountPoint };
142
+ }
143
+ sharedContainer = null;
144
+ sharedContainerPromise = null;
145
+ await container.teardown();
146
+ return { tornDown: true, mountPoint: "/" };
147
+ }
148
+ };
149
+
150
+ export {
151
+ resolveWebContainerCommand,
152
+ parseDevelopmentDiagnostics,
153
+ captureDevelopmentProcess,
154
+ WebContainerRuntime
155
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ WebContainerRuntime,
3
+ resolveWebContainerCommand
4
+ } from "./chunk-CA5HVC4X.js";
5
+ import {
6
+ createService,
7
+ createServiceDefinition
8
+ } from "./chunk-SXDYW3QA.js";
9
+
10
+ // src/development/webContainerService.ts
11
+ var runtime = new WebContainerRuntime();
12
+ var WebContainerServiceDefinition = createServiceDefinition({
13
+ id: "kloks.backend.webContainer",
14
+ name: "WebContainerService",
15
+ version: "1.3.0",
16
+ operations: {
17
+ boot: { id: "WebContainerService.boot", name: "boot", handler: async () => {
18
+ await runtime.boot();
19
+ return { ready: true };
20
+ } },
21
+ mount: { id: "WebContainerService.mount", name: "mount", handler: async (input) => runtime.mount(input.files, input.mountPoint, input.sourceSha) },
22
+ run: { id: "WebContainerService.run", name: "run", handler: async (input) => runtime.run(input.task, input.cwd, input.env, input.sourceSha) },
23
+ runCommand: { id: "WebContainerService.runCommand", name: "runCommand", handler: async (input) => runtime.runCommand(input.command, input.args, input.cwd, input.env, input.sourceSha) },
24
+ spawnCommand: { id: "WebContainerService.spawnCommand", name: "spawnCommand", handler: async (input) => runtime.spawnCommand(input.command, input.args, input.cwd, input.env, input.sourceSha) },
25
+ teardown: { id: "WebContainerService.teardown", name: "teardown", handler: async (input) => runtime.teardown(input?.mountPoint) },
26
+ command: { id: "WebContainerService.command", name: "command", handler: async (input) => ({ task: input.task, command: resolveWebContainerCommand(input.task) }) }
27
+ }
28
+ });
29
+ var WebContainerServiceFacade = {
30
+ id: WebContainerServiceDefinition.id,
31
+ name: WebContainerServiceDefinition.name,
32
+ version: WebContainerServiceDefinition.version,
33
+ runtime: "client",
34
+ deployment: "local",
35
+ definition: WebContainerServiceDefinition,
36
+ createInstance: () => createService(WebContainerServiceDefinition),
37
+ execute: async (op, input) => {
38
+ const instance = createService(WebContainerServiceDefinition);
39
+ await instance.start();
40
+ return instance.call(op, input);
41
+ }
42
+ };
43
+
44
+ export {
45
+ WebContainerServiceDefinition,
46
+ WebContainerServiceFacade
47
+ };
@@ -1,51 +1,11 @@
1
+ import { a as WebContainerRuntime, D as DevelopmentRequest, b as DevelopmentResult } from '../webContainerRuntime-BnHB2bNz.js';
2
+ export { d as DevelopmentDiagnostic, e as DevelopmentProvider, f as DevelopmentServiceContract, g as DevelopmentTask, h as WebContainerCommand, W as WebContainerRunCommandInput, c as captureDevelopmentProcess, p as parseDevelopmentDiagnostics, r as resolveWebContainerCommand } from '../webContainerRuntime-BnHB2bNz.js';
1
3
  import * as _ultrst_armada_krnl from '@ultrst-armada/krnl';
2
4
  import { ServiceDefinition } from '@ultrst-armada/krnl';
5
+ export { WebContainerServiceDefinition, WebContainerServiceFacade } from './webContainerService.js';
3
6
  export { InspectionCheck, InspectionCheckResult, InspectionError, InspectionErrorKind, InspectionLog, InspectionViewport, PlaywrightInspectionRequest, PlaywrightInspectionResult } from './playwrightInspectionTypes.js';
4
7
  export { PlaywrightInspectionRuntime, PlaywrightInspectionServiceDefinition, PlaywrightInspectionServiceFacade } from './playwrightInspectionService.js';
5
8
 
6
- type DevelopmentProvider = 'webcontainer' | 'github-actions';
7
- type DevelopmentTask = 'install' | 'lint' | 'test' | 'build' | 'validate' | 'check';
8
- interface DevelopmentRequest {
9
- provider: DevelopmentProvider;
10
- task: DevelopmentTask;
11
- repository?: string;
12
- ref?: string;
13
- workflowId?: string | number;
14
- workflowInputs?: Record<string, string>;
15
- cwd?: string;
16
- env?: Record<string, string>;
17
- sourceSha?: string;
18
- }
19
- interface DevelopmentDiagnostic {
20
- severity: 'error' | 'warning' | 'info';
21
- source: 'typescript' | 'eslint' | 'bundler' | 'package-manager' | 'runtime' | 'unknown';
22
- code?: string;
23
- file?: string;
24
- line?: number;
25
- column?: number;
26
- message: string;
27
- }
28
- interface DevelopmentResult {
29
- provider: DevelopmentProvider;
30
- task: DevelopmentTask;
31
- ok: boolean;
32
- exitCode?: number;
33
- output?: string;
34
- command?: string;
35
- durationMs?: number;
36
- diagnostics?: DevelopmentDiagnostic[];
37
- sourceSha?: string;
38
- runId?: number;
39
- url?: string;
40
- }
41
- interface WebContainerCommand {
42
- command: string;
43
- args: string[];
44
- }
45
- interface DevelopmentServiceContract {
46
- definition: ServiceDefinition;
47
- }
48
-
49
9
  interface GitHubActionsConfig {
50
10
  token: string;
51
11
  apiBaseUrl?: string;
@@ -101,75 +61,6 @@ declare const GitHubActionsServiceFacade: {
101
61
  execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
102
62
  };
103
63
 
104
- declare function resolveWebContainerCommand(task: DevelopmentTask): WebContainerCommand;
105
- declare function parseDevelopmentDiagnostics(output: string, exitCode?: number): DevelopmentDiagnostic[];
106
- declare function captureDevelopmentProcess<T extends {
107
- output: ReadableStream<string>;
108
- exit: Promise<number>;
109
- }>(process: T): T & {
110
- output: ReadableStream<string>;
111
- logs: Promise<{
112
- output: string;
113
- exitCode: number;
114
- diagnostics: DevelopmentDiagnostic[];
115
- }>;
116
- };
117
- interface WebContainerRunCommandInput {
118
- command: string;
119
- args?: string[];
120
- cwd?: string;
121
- env?: Record<string, string | number | boolean>;
122
- sourceSha?: string;
123
- }
124
- declare class WebContainerRuntime {
125
- boot(): Promise<any>;
126
- mount(files: Record<string, unknown>, mountPoint?: string, sourceSha?: string): Promise<{
127
- mounted: boolean;
128
- mountPoint: string;
129
- sourceSha: string;
130
- }>;
131
- private runProcess;
132
- run(task: DevelopmentTask, cwd?: string, env?: Record<string, string>, sourceSha?: string): Promise<{
133
- exitCode: any;
134
- output: string;
135
- command: string;
136
- durationMs: number;
137
- diagnostics: DevelopmentDiagnostic[];
138
- sourceSha: string;
139
- }>;
140
- runCommand(command: string, args?: string[], cwd?: string, env?: Record<string, string | number | boolean>, sourceSha?: string): Promise<{
141
- exitCode: any;
142
- output: string;
143
- command: string;
144
- durationMs: number;
145
- diagnostics: DevelopmentDiagnostic[];
146
- sourceSha: string;
147
- }>;
148
- spawnCommand(command: string, args?: string[], cwd?: string, env?: Record<string, string | number | boolean>, sourceSha?: string): Promise<{
149
- processId: `${string}-${string}-${string}-${string}-${string}`;
150
- sourceSha: string;
151
- command: string;
152
- startedAt: string;
153
- process: any;
154
- }>;
155
- teardown(mountPoint?: string): Promise<{
156
- tornDown: boolean;
157
- mountPoint: string;
158
- }>;
159
- }
160
-
161
- declare const WebContainerServiceDefinition: ServiceDefinition;
162
- declare const WebContainerServiceFacade: {
163
- id: string;
164
- name: string;
165
- version: string;
166
- runtime: "client";
167
- deployment: "local";
168
- definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
169
- createInstance: () => _ultrst_armada_krnl.ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
170
- execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
171
- };
172
-
173
64
  declare function resolveDevelopmentCommand(task: DevelopmentRequest['task']): [string, string[]];
174
65
  declare const DevelopmentServiceDefinition: ServiceDefinition;
175
66
  declare class DevelopmentRuntime {
@@ -343,4 +234,4 @@ declare const AgentHarnessServiceFacade: {
343
234
  execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
344
235
  };
345
236
 
346
- export { type AgentHarnessProvider, type AgentHarnessProviderInfo, type AgentHarnessResult, type AgentHarnessRunInput, AgentHarnessRuntime, type AgentHarnessServiceContract, AgentHarnessServiceDefinition, AgentHarnessServiceFacade, type CodeDiagnosticsInput, type CodeDiagnosticsResult, CodeDiagnosticsService, type CodeValidationInput, type CodeValidationResult, CodeValidationRuntime, CodeValidationServiceDefinition, CodeValidationServiceFacade, type DevelopmentDiagnostic, type DevelopmentProvider, type DevelopmentRequest, type DevelopmentResult, DevelopmentRuntime, type DevelopmentServiceContract, DevelopmentServiceDefinition, DevelopmentServiceFacade, type DevelopmentTask, GitHubActionsClient, type GitHubActionsConfig, GitHubActionsServiceDefinition, GitHubActionsServiceFacade, TYPESCRIPT_LANGUAGE_SERVER_PACKAGE, TYPESCRIPT_LANGUAGE_SERVER_VERSION, type TypeScriptLanguageServerNotificationInput, type TypeScriptLanguageServerRequestInput, type TypeScriptLanguageServerResponse, TypeScriptLanguageServerServiceDefinition, TypeScriptLanguageServerServiceFacade, type TypeScriptLanguageServerStartInput, type TypeScriptLanguageServerStatus, type ValidationDiagnostic, type ValidationLayer, type WebContainerCommand, type WebContainerRunCommandInput, WebContainerRuntime, WebContainerServiceDefinition, WebContainerServiceFacade, type WorkflowRun, captureDevelopmentProcess, codeDiagnosticsService, parseDevelopmentDiagnostics, resolveDevelopmentCommand, resolveWebContainerCommand };
237
+ export { type AgentHarnessProvider, type AgentHarnessProviderInfo, type AgentHarnessResult, type AgentHarnessRunInput, AgentHarnessRuntime, type AgentHarnessServiceContract, AgentHarnessServiceDefinition, AgentHarnessServiceFacade, type CodeDiagnosticsInput, type CodeDiagnosticsResult, CodeDiagnosticsService, type CodeValidationInput, type CodeValidationResult, CodeValidationRuntime, CodeValidationServiceDefinition, CodeValidationServiceFacade, DevelopmentRequest, DevelopmentResult, DevelopmentRuntime, DevelopmentServiceDefinition, DevelopmentServiceFacade, GitHubActionsClient, type GitHubActionsConfig, GitHubActionsServiceDefinition, GitHubActionsServiceFacade, TYPESCRIPT_LANGUAGE_SERVER_PACKAGE, TYPESCRIPT_LANGUAGE_SERVER_VERSION, type TypeScriptLanguageServerNotificationInput, type TypeScriptLanguageServerRequestInput, type TypeScriptLanguageServerResponse, TypeScriptLanguageServerServiceDefinition, TypeScriptLanguageServerServiceFacade, type TypeScriptLanguageServerStartInput, type TypeScriptLanguageServerStatus, type ValidationDiagnostic, type ValidationLayer, WebContainerRuntime, type WorkflowRun, codeDiagnosticsService, resolveDevelopmentCommand };
@@ -1,4 +1,14 @@
1
1
  import "../chunk-YEGS4HTA.js";
2
+ import {
3
+ WebContainerServiceDefinition,
4
+ WebContainerServiceFacade
5
+ } from "../chunk-GKQ42CYW.js";
6
+ import {
7
+ WebContainerRuntime,
8
+ captureDevelopmentProcess,
9
+ parseDevelopmentDiagnostics,
10
+ resolveWebContainerCommand
11
+ } from "../chunk-CA5HVC4X.js";
2
12
  import {
3
13
  PlaywrightInspectionRuntime,
4
14
  PlaywrightInspectionServiceDefinition,
@@ -104,189 +114,6 @@ var GitHubActionsServiceFacade = {
104
114
  }
105
115
  };
106
116
 
107
- // src/development/webContainerRuntime.ts
108
- var COMMANDS = {
109
- install: { command: "pnpm", args: ["install", "--frozen-lockfile"] },
110
- lint: { command: "pnpm", args: ["lint"] },
111
- test: { command: "pnpm", args: ["test"] },
112
- build: { command: "pnpm", args: ["build"] },
113
- validate: { command: "pnpm", args: ["validate"] },
114
- check: { command: "pnpm", args: ["lint"] }
115
- };
116
- function resolveWebContainerCommand(task) {
117
- const command = COMMANDS[task];
118
- return { command: command.command, args: [...command.args] };
119
- }
120
- function parseDevelopmentDiagnostics(output, exitCode = 0) {
121
- const diagnostics = [];
122
- const seen = /* @__PURE__ */ new Set();
123
- const add = (diagnostic) => {
124
- const key = [diagnostic.source, diagnostic.code, diagnostic.file, diagnostic.line, diagnostic.message].join("|");
125
- if (!seen.has(key)) {
126
- seen.add(key);
127
- diagnostics.push(diagnostic);
128
- }
129
- };
130
- for (const line of output.split(/\r?\n/)) {
131
- const typescript = line.match(/^(.+?)\((\d+),(\d+)\):\s*(error|warning)\s+(TS\d+):\s*(.+)$/);
132
- if (typescript) {
133
- add({ source: "typescript", severity: typescript[4], file: typescript[1], line: Number(typescript[2]), column: Number(typescript[3]), code: typescript[5], message: typescript[6] });
134
- continue;
135
- }
136
- const eslint = line.match(/^(.+?):(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+([^\s]+)$/);
137
- if (eslint) {
138
- add({ source: "eslint", severity: eslint[4], file: eslint[1], line: Number(eslint[2]), column: Number(eslint[3]), code: eslint[6], message: eslint[5] });
139
- continue;
140
- }
141
- const bundler = line.match(/(?:✘|×|ERROR|error:|Error:)\s*(.+)$/);
142
- if (bundler) add({ source: "bundler", severity: "error", message: bundler[1].trim() });
143
- if (/\bWARN(?:ING)?\b/i.test(line)) add({ source: "package-manager", severity: "warning", message: line.trim() });
144
- }
145
- if (exitCode !== 0 && diagnostics.every((item) => item.severity !== "error")) {
146
- add({ source: "unknown", severity: "error", message: "Command failed with exit code " + exitCode + "; inspect captured output for details." });
147
- }
148
- return diagnostics;
149
- }
150
- function captureDevelopmentProcess(process) {
151
- const [consumerOutput, diagnosticOutput] = process.output.tee();
152
- const logs = (async () => {
153
- const reader = diagnosticOutput.getReader();
154
- let output = "";
155
- try {
156
- while (true) {
157
- const next = await reader.read();
158
- if (next.done) break;
159
- output += next.value;
160
- }
161
- } finally {
162
- reader.releaseLock();
163
- }
164
- const exitCode = await process.exit;
165
- return { output, exitCode, diagnostics: parseDevelopmentDiagnostics(output, exitCode) };
166
- })();
167
- return { ...process, output: consumerOutput, logs };
168
- }
169
- var runQueue = Promise.resolve();
170
- var sharedContainer = null;
171
- var sharedContainerPromise = null;
172
- var WebContainerRuntime = class {
173
- async boot() {
174
- if (typeof window !== "undefined" && !window.crossOriginIsolated) {
175
- throw new Error("WebContainer requires a cross-origin-isolated page. Ensure COOP=same-origin and COEP=require-corp are served.");
176
- }
177
- if (sharedContainer) return sharedContainer;
178
- if (!sharedContainerPromise) {
179
- sharedContainerPromise = import("@webcontainer/api").then(async (module) => {
180
- const container = await module.WebContainer.boot({ coep: "require-corp", workdirName: "kloks-development" });
181
- sharedContainer = container;
182
- return container;
183
- }).catch((error) => {
184
- sharedContainerPromise = null;
185
- throw error;
186
- });
187
- }
188
- return sharedContainerPromise;
189
- }
190
- async mount(files, mountPoint = "/", sourceSha) {
191
- const container = await this.boot();
192
- await container.mount(files, mountPoint === "/" ? void 0 : { mountPoint });
193
- return { mounted: true, mountPoint, sourceSha };
194
- }
195
- async runProcess(command, args, cwd, env, sourceSha) {
196
- const container = await this.boot();
197
- const process = await container.spawn(command, args, { cwd, env });
198
- const started = Date.now();
199
- let output = "";
200
- const reader = process.output.getReader();
201
- try {
202
- while (true) {
203
- const next = await reader.read();
204
- if (next.done) break;
205
- output += next.value;
206
- }
207
- } finally {
208
- reader.releaseLock();
209
- }
210
- const exitCode = await process.exit;
211
- return {
212
- exitCode,
213
- output,
214
- command: [command, ...args].join(" "),
215
- durationMs: Date.now() - started,
216
- diagnostics: parseDevelopmentDiagnostics(output, exitCode),
217
- sourceSha
218
- };
219
- }
220
- async run(task, cwd, env, sourceSha) {
221
- const spec = resolveWebContainerCommand(task);
222
- return this.runCommand(spec.command, spec.args, cwd, env, sourceSha);
223
- }
224
- async runCommand(command, args = [], cwd, env, sourceSha) {
225
- const previous = runQueue;
226
- let release;
227
- runQueue = new Promise((resolve) => {
228
- release = resolve;
229
- });
230
- await previous;
231
- try {
232
- return await this.runProcess(command, args, cwd, env, sourceSha);
233
- } finally {
234
- release();
235
- }
236
- }
237
- async spawnCommand(command, args = [], cwd, env, sourceSha) {
238
- const container = await this.boot();
239
- const process = await container.spawn(command, args, { cwd, env });
240
- return { processId: globalThis.crypto.randomUUID(), sourceSha, command: [command, ...args].join(" "), startedAt: (/* @__PURE__ */ new Date()).toISOString(), process: captureDevelopmentProcess(process) };
241
- }
242
- async teardown(mountPoint) {
243
- const container = sharedContainer;
244
- if (!container) return { tornDown: true, mountPoint };
245
- if (mountPoint && mountPoint !== "/") {
246
- await container.fs.rm(mountPoint, { recursive: true, force: true });
247
- return { tornDown: true, mountPoint };
248
- }
249
- sharedContainer = null;
250
- sharedContainerPromise = null;
251
- await container.teardown();
252
- return { tornDown: true, mountPoint: "/" };
253
- }
254
- };
255
-
256
- // src/development/webContainerService.ts
257
- var runtime = new WebContainerRuntime();
258
- var WebContainerServiceDefinition = createServiceDefinition({
259
- id: "kloks.backend.webContainer",
260
- name: "WebContainerService",
261
- version: "1.3.0",
262
- operations: {
263
- boot: { id: "WebContainerService.boot", name: "boot", handler: async () => {
264
- await runtime.boot();
265
- return { ready: true };
266
- } },
267
- mount: { id: "WebContainerService.mount", name: "mount", handler: async (input) => runtime.mount(input.files, input.mountPoint, input.sourceSha) },
268
- run: { id: "WebContainerService.run", name: "run", handler: async (input) => runtime.run(input.task, input.cwd, input.env, input.sourceSha) },
269
- runCommand: { id: "WebContainerService.runCommand", name: "runCommand", handler: async (input) => runtime.runCommand(input.command, input.args, input.cwd, input.env, input.sourceSha) },
270
- spawnCommand: { id: "WebContainerService.spawnCommand", name: "spawnCommand", handler: async (input) => runtime.spawnCommand(input.command, input.args, input.cwd, input.env, input.sourceSha) },
271
- teardown: { id: "WebContainerService.teardown", name: "teardown", handler: async (input) => runtime.teardown(input?.mountPoint) },
272
- command: { id: "WebContainerService.command", name: "command", handler: async (input) => ({ task: input.task, command: resolveWebContainerCommand(input.task) }) }
273
- }
274
- });
275
- var WebContainerServiceFacade = {
276
- id: WebContainerServiceDefinition.id,
277
- name: WebContainerServiceDefinition.name,
278
- version: WebContainerServiceDefinition.version,
279
- runtime: "client",
280
- deployment: "local",
281
- definition: WebContainerServiceDefinition,
282
- createInstance: () => createService(WebContainerServiceDefinition),
283
- execute: async (op, input) => {
284
- const instance = createService(WebContainerServiceDefinition);
285
- await instance.start();
286
- return instance.call(op, input);
287
- }
288
- };
289
-
290
117
  // src/development/developmentService.ts
291
118
  function resolveDevelopmentCommand(task) {
292
119
  const { command, args } = resolveWebContainerCommand(task);
@@ -357,7 +184,7 @@ var DevelopmentServiceFacade = {
357
184
  };
358
185
 
359
186
  // src/development/codeValidationService.ts
360
- var COMMANDS2 = {
187
+ var COMMANDS = {
361
188
  syntax: { command: "pnpm", args: ["exec", "tsc", "--noEmit"] },
362
189
  lint: { command: "pnpm", args: ["run", "lint", "--if-present"] },
363
190
  test: { command: "pnpm", args: ["run", "test", "--if-present"] },
@@ -369,8 +196,8 @@ var COMMANDS2 = {
369
196
  var DEFAULT_LAYERS = ["lockfile-check", "syntax", "lint", "krnl", "frnl"];
370
197
  var commandText = (command, args) => [command, ...args].join(" ");
371
198
  var CodeValidationRuntime = class {
372
- constructor(runtime5 = new WebContainerRuntime()) {
373
- this.runtime = runtime5;
199
+ constructor(runtime4 = new WebContainerRuntime()) {
200
+ this.runtime = runtime4;
374
201
  }
375
202
  runtime;
376
203
  async validate(input = {}) {
@@ -387,7 +214,7 @@ var CodeValidationRuntime = class {
387
214
  diagnostics.push(await this.validateLawL9(input.cwd, input.maxLines ?? 200));
388
215
  continue;
389
216
  }
390
- const spec = COMMANDS2[layer];
217
+ const spec = COMMANDS[layer];
391
218
  const result = await this.runtime.runCommand(spec.command, spec.args, input.cwd, input.env);
392
219
  diagnostics.push({ layer, ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: commandText(spec.command, spec.args) });
393
220
  if (result.exitCode !== 0) break;
@@ -400,12 +227,12 @@ var CodeValidationRuntime = class {
400
227
  return { layer: "law-l9", ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: script };
401
228
  }
402
229
  };
403
- var runtime2 = new CodeValidationRuntime();
230
+ var runtime = new CodeValidationRuntime();
404
231
  var CodeValidationServiceDefinition = createServiceDefinition({
405
232
  id: "kloks.backend.codeValidation",
406
233
  name: "CodeValidationService",
407
234
  version: "1.1.0",
408
- operations: { validate: { id: "CodeValidationService.validate", name: "validate", handler: async (input) => runtime2.validate(input) } }
235
+ operations: { validate: { id: "CodeValidationService.validate", name: "validate", handler: async (input) => runtime.validate(input) } }
409
236
  });
410
237
  var CodeValidationServiceFacade = {
411
238
  id: CodeValidationServiceDefinition.id,
@@ -424,8 +251,8 @@ var CodeValidationServiceFacade = {
424
251
 
425
252
  // src/development/codeDiagnosticsService.ts
426
253
  var CodeDiagnosticsService = class {
427
- constructor(runtime5 = new WebContainerRuntime()) {
428
- this.runtime = runtime5;
254
+ constructor(runtime4 = new WebContainerRuntime()) {
255
+ this.runtime = runtime4;
429
256
  }
430
257
  runtime;
431
258
  async diagnostics(input = {}) {
@@ -443,8 +270,8 @@ var TYPESCRIPT_LANGUAGE_SERVER_VERSION = "6.0.2";
443
270
  var PACKAGE = TYPESCRIPT_LANGUAGE_SERVER_PACKAGE;
444
271
  var DEFAULT_VERSION = TYPESCRIPT_LANGUAGE_SERVER_VERSION;
445
272
  var TypeScriptLanguageServerRuntime = class {
446
- constructor(runtime5 = new WebContainerRuntime()) {
447
- this.runtime = runtime5;
273
+ constructor(runtime4 = new WebContainerRuntime()) {
274
+ this.runtime = runtime4;
448
275
  }
449
276
  runtime;
450
277
  process = null;
@@ -542,17 +369,17 @@ var TypeScriptLanguageServerRuntime = class {
542
369
  }
543
370
  }
544
371
  };
545
- var runtime3 = new TypeScriptLanguageServerRuntime();
372
+ var runtime2 = new TypeScriptLanguageServerRuntime();
546
373
  var TypeScriptLanguageServerServiceDefinition = createServiceDefinition({
547
374
  id: "kloks.backend.typescriptLanguageServer",
548
375
  name: "TypeScriptLanguageServerService",
549
376
  version: "1.0.0",
550
377
  operations: {
551
- start: { id: "TypeScriptLanguageServerService.start", name: "start", handler: async (input) => runtime3.start(input) },
552
- request: { id: "TypeScriptLanguageServerService.request", name: "request", handler: async (input) => runtime3.request(input) },
553
- notify: { id: "TypeScriptLanguageServerService.notify", name: "notify", handler: async (input) => runtime3.notify(input) },
554
- stop: { id: "TypeScriptLanguageServerService.stop", name: "stop", handler: async () => runtime3.stop() },
555
- status: { id: "TypeScriptLanguageServerService.status", name: "status", handler: async () => runtime3.status() }
378
+ start: { id: "TypeScriptLanguageServerService.start", name: "start", handler: async (input) => runtime2.start(input) },
379
+ request: { id: "TypeScriptLanguageServerService.request", name: "request", handler: async (input) => runtime2.request(input) },
380
+ notify: { id: "TypeScriptLanguageServerService.notify", name: "notify", handler: async (input) => runtime2.notify(input) },
381
+ stop: { id: "TypeScriptLanguageServerService.stop", name: "stop", handler: async () => runtime2.stop() },
382
+ status: { id: "TypeScriptLanguageServerService.status", name: "status", handler: async () => runtime2.status() }
556
383
  }
557
384
  });
558
385
  var TypeScriptLanguageServerServiceFacade = {
@@ -595,8 +422,8 @@ var PROVIDERS = [
595
422
  }
596
423
  ];
597
424
  var AgentHarnessRuntime = class {
598
- constructor(runtime5 = new WebContainerRuntime()) {
599
- this.runtime = runtime5;
425
+ constructor(runtime4 = new WebContainerRuntime()) {
426
+ this.runtime = runtime4;
600
427
  }
601
428
  runtime;
602
429
  providers() {
@@ -623,7 +450,7 @@ var AgentHarnessRuntime = class {
623
450
  };
624
451
  }
625
452
  };
626
- var runtime4 = new AgentHarnessRuntime();
453
+ var runtime3 = new AgentHarnessRuntime();
627
454
  var AgentHarnessServiceDefinition = createServiceDefinition({
628
455
  id: "kloks.backend.agentHarness",
629
456
  name: "AgentHarnessService",
@@ -632,12 +459,12 @@ var AgentHarnessServiceDefinition = createServiceDefinition({
632
459
  providers: {
633
460
  id: "AgentHarnessService.providers",
634
461
  name: "providers",
635
- handler: async () => runtime4.providers()
462
+ handler: async () => runtime3.providers()
636
463
  },
637
464
  run: {
638
465
  id: "AgentHarnessService.run",
639
466
  name: "run",
640
- handler: async (input) => runtime4.run(input)
467
+ handler: async (input) => runtime3.run(input)
641
468
  }
642
469
  }
643
470
  });
@@ -0,0 +1,2 @@
1
+ export { W as WebContainerRunCommandInput, a as WebContainerRuntime, c as captureDevelopmentProcess, p as parseDevelopmentDiagnostics, r as resolveWebContainerCommand } from '../webContainerRuntime-BnHB2bNz.js';
2
+ import '@ultrst-armada/krnl';
@@ -0,0 +1,12 @@
1
+ import {
2
+ WebContainerRuntime,
3
+ captureDevelopmentProcess,
4
+ parseDevelopmentDiagnostics,
5
+ resolveWebContainerCommand
6
+ } from "../chunk-CA5HVC4X.js";
7
+ export {
8
+ WebContainerRuntime,
9
+ captureDevelopmentProcess,
10
+ parseDevelopmentDiagnostics,
11
+ resolveWebContainerCommand
12
+ };
@@ -0,0 +1,17 @@
1
+ import * as _ultrst_armada_krnl from '@ultrst-armada/krnl';
2
+ import { ServiceDefinition } from '@ultrst-armada/krnl';
3
+ export { W as WebContainerRunCommandInput, a as WebContainerRuntime, c as captureDevelopmentProcess, p as parseDevelopmentDiagnostics, r as resolveWebContainerCommand } from '../webContainerRuntime-BnHB2bNz.js';
4
+
5
+ declare const WebContainerServiceDefinition: ServiceDefinition;
6
+ declare const WebContainerServiceFacade: {
7
+ id: string;
8
+ name: string;
9
+ version: string;
10
+ runtime: "client";
11
+ deployment: "local";
12
+ definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
13
+ createInstance: () => _ultrst_armada_krnl.ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
14
+ execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
15
+ };
16
+
17
+ export { WebContainerServiceDefinition, WebContainerServiceFacade };
@@ -0,0 +1,19 @@
1
+ import {
2
+ WebContainerServiceDefinition,
3
+ WebContainerServiceFacade
4
+ } from "../chunk-GKQ42CYW.js";
5
+ import {
6
+ WebContainerRuntime,
7
+ captureDevelopmentProcess,
8
+ parseDevelopmentDiagnostics,
9
+ resolveWebContainerCommand
10
+ } from "../chunk-CA5HVC4X.js";
11
+ import "../chunk-SXDYW3QA.js";
12
+ export {
13
+ WebContainerRuntime,
14
+ WebContainerServiceDefinition,
15
+ WebContainerServiceFacade,
16
+ captureDevelopmentProcess,
17
+ parseDevelopmentDiagnostics,
18
+ resolveWebContainerCommand
19
+ };
@@ -0,0 +1,103 @@
1
+ import { ServiceDefinition } from '@ultrst-armada/krnl';
2
+
3
+ type DevelopmentProvider = 'webcontainer' | 'github-actions';
4
+ type DevelopmentTask = 'install' | 'lint' | 'test' | 'build' | 'validate' | 'check';
5
+ interface DevelopmentRequest {
6
+ provider: DevelopmentProvider;
7
+ task: DevelopmentTask;
8
+ repository?: string;
9
+ ref?: string;
10
+ workflowId?: string | number;
11
+ workflowInputs?: Record<string, string>;
12
+ cwd?: string;
13
+ env?: Record<string, string>;
14
+ sourceSha?: string;
15
+ }
16
+ interface DevelopmentDiagnostic {
17
+ severity: 'error' | 'warning' | 'info';
18
+ source: 'typescript' | 'eslint' | 'bundler' | 'package-manager' | 'runtime' | 'unknown';
19
+ code?: string;
20
+ file?: string;
21
+ line?: number;
22
+ column?: number;
23
+ message: string;
24
+ }
25
+ interface DevelopmentResult {
26
+ provider: DevelopmentProvider;
27
+ task: DevelopmentTask;
28
+ ok: boolean;
29
+ exitCode?: number;
30
+ output?: string;
31
+ command?: string;
32
+ durationMs?: number;
33
+ diagnostics?: DevelopmentDiagnostic[];
34
+ sourceSha?: string;
35
+ runId?: number;
36
+ url?: string;
37
+ }
38
+ interface WebContainerCommand {
39
+ command: string;
40
+ args: string[];
41
+ }
42
+ interface DevelopmentServiceContract {
43
+ definition: ServiceDefinition;
44
+ }
45
+
46
+ declare function resolveWebContainerCommand(task: DevelopmentTask): WebContainerCommand;
47
+ declare function parseDevelopmentDiagnostics(output: string, exitCode?: number): DevelopmentDiagnostic[];
48
+ declare function captureDevelopmentProcess<T extends {
49
+ output: ReadableStream<string>;
50
+ exit: Promise<number>;
51
+ }>(process: T): T & {
52
+ output: ReadableStream<string>;
53
+ logs: Promise<{
54
+ output: string;
55
+ exitCode: number;
56
+ diagnostics: DevelopmentDiagnostic[];
57
+ }>;
58
+ };
59
+ interface WebContainerRunCommandInput {
60
+ command: string;
61
+ args?: string[];
62
+ cwd?: string;
63
+ env?: Record<string, string | number | boolean>;
64
+ sourceSha?: string;
65
+ }
66
+ declare class WebContainerRuntime {
67
+ boot(): Promise<any>;
68
+ mount(files: Record<string, unknown>, mountPoint?: string, sourceSha?: string): Promise<{
69
+ mounted: boolean;
70
+ mountPoint: string;
71
+ sourceSha: string;
72
+ }>;
73
+ private runProcess;
74
+ run(task: DevelopmentTask, cwd?: string, env?: Record<string, string>, sourceSha?: string): Promise<{
75
+ exitCode: any;
76
+ output: string;
77
+ command: string;
78
+ durationMs: number;
79
+ diagnostics: DevelopmentDiagnostic[];
80
+ sourceSha: string;
81
+ }>;
82
+ runCommand(command: string, args?: string[], cwd?: string, env?: Record<string, string | number | boolean>, sourceSha?: string): Promise<{
83
+ exitCode: any;
84
+ output: string;
85
+ command: string;
86
+ durationMs: number;
87
+ diagnostics: DevelopmentDiagnostic[];
88
+ sourceSha: string;
89
+ }>;
90
+ spawnCommand(command: string, args?: string[], cwd?: string, env?: Record<string, string | number | boolean>, sourceSha?: string): Promise<{
91
+ processId: `${string}-${string}-${string}-${string}-${string}`;
92
+ sourceSha: string;
93
+ command: string;
94
+ startedAt: string;
95
+ process: any;
96
+ }>;
97
+ teardown(mountPoint?: string): Promise<{
98
+ tornDown: boolean;
99
+ mountPoint: string;
100
+ }>;
101
+ }
102
+
103
+ export { type DevelopmentRequest as D, type WebContainerRunCommandInput as W, WebContainerRuntime as a, type DevelopmentResult as b, captureDevelopmentProcess as c, type DevelopmentDiagnostic as d, type DevelopmentProvider as e, type DevelopmentServiceContract as f, type DevelopmentTask as g, type WebContainerCommand as h, parseDevelopmentDiagnostics as p, resolveWebContainerCommand as r };
@@ -73,6 +73,11 @@
73
73
  "types": "./dist/development/index.d.ts",
74
74
  "default": "./dist/development/index.js"
75
75
  },
76
+ "./development/webcontainer": {
77
+ "import": "./dist/development/webContainerService.js",
78
+ "types": "./dist/development/webContainerService.d.ts",
79
+ "default": "./dist/development/webContainerService.js"
80
+ },
76
81
  "./ai-provider": {
77
82
  "import": "./dist/ai-provider/index.js",
78
83
  "types": "./dist/ai-provider/index.d.ts",
@@ -110,7 +115,7 @@
110
115
  }
111
116
  },
112
117
  "scripts": {
113
- "build": "tsup src/index.ts src/krnl-services.ts src/krnl-ai-services.ts src/services/index.ts src/auth/index.ts src/storage/index.ts src/workspace/index.ts src/control-plane/index.ts src/api/index.ts src/connectivity/index.ts src/client/index.ts src/srkl/index.ts src/development/index.ts src/development/playwrightInspectionService.ts src/development/playwrightInspectionTypes.ts src/ai-provider/index.ts src/ai-inference/index.ts src/ai-models/index.ts src/ai-routing/index.ts src/ai-keys/index.ts src/ai-tools/index.ts --format esm --dts --clean --external @kloks/functions --external react --external @kloks/state-graph --external @neondatabase/serverless --external @supabase/supabase-js --external @aws-sdk/client-s3 --external @aws-sdk/lib-storage --external zod --external ws --external @webcontainer/api --external playwright && tsup src/development/client.ts --format esm --dts --out-dir dist/development --splitting false --platform browser --external @ultrst-armada/krnl",
118
+ "build": "tsup src/index.ts src/krnl-services.ts src/krnl-ai-services.ts src/services/index.ts src/auth/index.ts src/storage/index.ts src/workspace/index.ts src/control-plane/index.ts src/api/index.ts src/connectivity/index.ts src/client/index.ts src/srkl/index.ts src/development/index.ts src/development/webContainerService.ts src/development/webContainerRuntime.ts src/development/playwrightInspectionService.ts src/development/playwrightInspectionTypes.ts src/ai-provider/index.ts src/ai-inference/index.ts src/ai-models/index.ts src/ai-routing/index.ts src/ai-keys/index.ts src/ai-tools/index.ts --format esm --dts --clean --external @kloks/functions --external react --external @kloks/state-graph --external @neondatabase/serverless --external @supabase/supabase-js --external @aws-sdk/client-s3 --external @aws-sdk/lib-storage --external zod --external ws --external @webcontainer/api --external playwright && tsup src/development/client.ts --format esm --dts --out-dir dist/development --splitting false --platform browser --external @ultrst-armada/krnl",
114
119
  "typecheck": "tsc --noEmit",
115
120
  "clean": "rm -rf dist"
116
121
  },
@@ -454,6 +454,75 @@ declare const krnlSystemDbClientServiceFacade: {
454
454
  execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
455
455
  };
456
456
 
457
+ interface GitHubAppInstallation {
458
+ account: string;
459
+ appId: number;
460
+ installationId: number;
461
+ privateKey: string;
462
+ }
463
+ interface GitHubAppConnectorOptions {
464
+ installations: GitHubAppInstallation[];
465
+ apiBaseUrl?: string;
466
+ fetchImpl?: typeof fetch;
467
+ now?: () => number;
468
+ signer?: (installation: GitHubAppInstallation, nowSeconds: number) => Promise<string>;
469
+ }
470
+ interface GitHubOperationResult<T> {
471
+ ok: true;
472
+ operation: string;
473
+ data: T;
474
+ diagnostics: {
475
+ startedAt: string;
476
+ completedAt: string;
477
+ status: number;
478
+ requestId?: string;
479
+ };
480
+ }
481
+ interface GitHubOperationError {
482
+ ok: false;
483
+ operation: string;
484
+ error: {
485
+ message: string;
486
+ status?: number;
487
+ diagnostics?: unknown;
488
+ };
489
+ }
490
+ type GitHubResult<T> = GitHubOperationResult<T> | GitHubOperationError;
491
+ interface GitHubWorkflowRun {
492
+ id: number;
493
+ status: string;
494
+ conclusion: string | null;
495
+ html_url?: string;
496
+ created_at: string;
497
+ updated_at: string;
498
+ run_number?: number;
499
+ }
500
+ declare class GitHubAppConnector {
501
+ readonly id = "github-app";
502
+ private readonly apiBaseUrl;
503
+ private readonly fetchImpl;
504
+ private readonly now;
505
+ private readonly signer;
506
+ private readonly installations;
507
+ private readonly tokens;
508
+ constructor(options: GitHubAppConnectorOptions);
509
+ listAccounts(): string[];
510
+ private installation;
511
+ private installationToken;
512
+ private request;
513
+ getRepository(account: string, repository: string): Promise<GitHubResult<unknown>>;
514
+ listRepositories(account: string, page?: number, perPage?: number): Promise<GitHubResult<unknown>>;
515
+ getFile(account: string, repository: string, path: string, ref?: string): Promise<GitHubResult<unknown>>;
516
+ commitFile(account: string, repository: string, path: string, content: string, message: string, branch: string, sha?: string): Promise<GitHubResult<unknown>>;
517
+ createPullRequest(account: string, repository: string, title: string, body: string, head: string, base?: string): Promise<GitHubResult<unknown>>;
518
+ dispatchWorkflow(account: string, repository: string, workflow: string, ref: string, inputs?: Record<string, string>): Promise<GitHubResult<undefined>>;
519
+ pollWorkflow(account: string, repository: string, workflow: string, ref: string, startedAfter: string, options?: {
520
+ timeoutMs?: number;
521
+ intervalMs?: number;
522
+ }): Promise<GitHubResult<GitHubWorkflowRun>>;
523
+ }
524
+ declare const createGitHubAppConnector: (options: GitHubAppConnectorOptions) => GitHubAppConnector;
525
+
457
526
  interface GitHubVcsProviderOptions {
458
527
  token: string;
459
528
  apiBaseUrl?: string;
@@ -625,4 +694,4 @@ declare const krnlServiceDDefinition: ServiceDefinition<Record<string, unknown>,
625
694
  declare const krnlServiceDFacade: ServiceFacade<Record<string, unknown>, Record<string, unknown>>;
626
695
  declare const krnlExposeServiceD: typeof exposeServiceD;
627
696
 
628
- export { AuthClientServiceDefinition, AuthClientServiceFacade, type AuthListener, AuthService, AuthServiceUISchema, CLEAN_DATABASE_CLUSTER, CommandVerificationProvider, type CounterState, DEFAULT_CONNECTIONS, type EcosystemServiceCategory, type GitHubFile, GitHubVcsProvider, type GitHubVcsProviderOptions, type IAuthStore, KLOKSServiceIndex, 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 ServiceIdentity, type ServiceMatch, type ServiceMatchClass, type ServiceMatchEvidence, type ServiceOperationIdentity, 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, buildServiceIdentity, clearSession, compareServices, 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 };
697
+ export { AuthClientServiceDefinition, AuthClientServiceFacade, type AuthListener, AuthService, AuthServiceUISchema, CLEAN_DATABASE_CLUSTER, CommandVerificationProvider, type CounterState, DEFAULT_CONNECTIONS, type EcosystemServiceCategory, GitHubAppConnector, type GitHubAppConnectorOptions, type GitHubAppInstallation, type GitHubFile, type GitHubOperationError, type GitHubOperationResult, type GitHubResult, GitHubVcsProvider, type GitHubVcsProviderOptions, type GitHubWorkflowRun, type IAuthStore, KLOKSServiceIndex, 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 ServiceIdentity, type ServiceMatch, type ServiceMatchClass, type ServiceMatchEvidence, type ServiceOperationIdentity, 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, buildServiceIdentity, clearSession, compareServices, createGitHubAppConnector, 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 };
@@ -2792,6 +2792,118 @@ var krnlStorageClientServiceFacade = StorageClientServiceFacade;
2792
2792
  var krnlSystemDbClientServiceDefinition = SystemDbClientServiceDefinition;
2793
2793
  var krnlSystemDbClientServiceFacade = SystemDbClientServiceFacade;
2794
2794
 
2795
+ // src/engineering/github-app-connector.ts
2796
+ var encoder = new TextEncoder();
2797
+ var base64 = (bytes) => {
2798
+ let binary = "";
2799
+ for (const byte of bytes) binary += String.fromCharCode(byte);
2800
+ return btoa(binary);
2801
+ };
2802
+ var base64Url = (bytes) => base64(bytes).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
2803
+ var pemToDer = (pem) => {
2804
+ const value = pem.replace(/-----BEGIN PRIVATE KEY-----|-----END PRIVATE KEY-----|\s/g, "");
2805
+ const binary = atob(value);
2806
+ return Uint8Array.from(binary, (char) => char.charCodeAt(0));
2807
+ };
2808
+ var signAppJwt = async (installation, nowSeconds) => {
2809
+ const header = base64Url(encoder.encode(JSON.stringify({ alg: "RS256", typ: "JWT" })));
2810
+ const payload = base64Url(encoder.encode(JSON.stringify({ iat: nowSeconds - 30, exp: nowSeconds + 540, iss: String(installation.appId) })));
2811
+ const key = await crypto.subtle.importKey("pkcs8", pemToDer(installation.privateKey).buffer, { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, false, ["sign"]);
2812
+ const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, encoder.encode(header + "." + payload));
2813
+ return header + "." + payload + "." + base64Url(new Uint8Array(signature));
2814
+ };
2815
+ var GitHubAppConnector = class {
2816
+ id = "github-app";
2817
+ apiBaseUrl;
2818
+ fetchImpl;
2819
+ now;
2820
+ signer;
2821
+ installations;
2822
+ tokens = /* @__PURE__ */ new Map();
2823
+ constructor(options) {
2824
+ if (options.installations.length === 0) throw new Error("At least one GitHub App installation is required");
2825
+ this.apiBaseUrl = options.apiBaseUrl ?? "https://api.github.com";
2826
+ this.fetchImpl = options.fetchImpl ?? fetch;
2827
+ this.now = options.now ?? (() => Date.now());
2828
+ this.signer = options.signer ?? signAppJwt;
2829
+ this.installations = new Map(options.installations.map((installation) => [installation.account, installation]));
2830
+ }
2831
+ listAccounts() {
2832
+ return [...this.installations.keys()].sort();
2833
+ }
2834
+ installation(account) {
2835
+ const value = this.installations.get(account);
2836
+ if (!value) throw new Error("Unknown GitHub App installation account: " + account);
2837
+ return value;
2838
+ }
2839
+ async installationToken(account) {
2840
+ const cached = this.tokens.get(account);
2841
+ if (cached && cached.expiresAt > this.now() + 6e4) return cached.token;
2842
+ const installation = this.installation(account);
2843
+ const jwt = await this.signer(installation, Math.floor(this.now() / 1e3));
2844
+ const response = await this.fetchImpl(this.apiBaseUrl + "/app/installations/" + installation.installationId + "/access_tokens", {
2845
+ method: "POST",
2846
+ headers: { accept: "application/vnd.github+json", authorization: "Bearer " + jwt, "x-github-api-version": "2022-11-28", "content-type": "application/json" }
2847
+ });
2848
+ if (!response.ok) throw new Error("GitHub installation token request failed (" + response.status + "): " + await response.text());
2849
+ const body = await response.json();
2850
+ this.tokens.set(account, { token: body.token, expiresAt: Date.parse(body.expires_at) });
2851
+ return body.token;
2852
+ }
2853
+ async request(account, path2, init = {}) {
2854
+ const operation = (init.method ?? "GET") + " " + path2;
2855
+ const startedAt = new Date(this.now()).toISOString();
2856
+ try {
2857
+ const token = await this.installationToken(account);
2858
+ const response = await this.fetchImpl(this.apiBaseUrl + path2, {
2859
+ ...init,
2860
+ headers: { accept: "application/vnd.github+json", authorization: "Bearer " + token, "x-github-api-version": "2022-11-28", ...init.body ? { "content-type": "application/json" } : {}, ...init.headers ?? {} }
2861
+ });
2862
+ const requestId = response.headers.get("x-github-request-id") ?? void 0;
2863
+ const completedAt = new Date(this.now()).toISOString();
2864
+ if (!response.ok) return { ok: false, operation, error: { message: "GitHub API " + response.status + ": " + await response.text(), status: response.status, diagnostics: { requestId } } };
2865
+ const data = response.status === 204 ? void 0 : await response.json();
2866
+ return { ok: true, operation, data, diagnostics: { startedAt, completedAt, status: response.status, requestId } };
2867
+ } catch (error) {
2868
+ return { ok: false, operation, error: { message: error instanceof Error ? error.message : String(error) } };
2869
+ }
2870
+ }
2871
+ getRepository(account, repository) {
2872
+ return this.request(account, "/repos/" + repository);
2873
+ }
2874
+ listRepositories(account, page = 1, perPage = 100) {
2875
+ return this.request(account, "/installation/repositories?page=" + page + "&per_page=" + perPage);
2876
+ }
2877
+ getFile(account, repository, path2, ref) {
2878
+ const query = ref ? "?ref=" + encodeURIComponent(ref) : "";
2879
+ return this.request(account, "/repos/" + repository + "/contents/" + path2 + query);
2880
+ }
2881
+ commitFile(account, repository, path2, content, message, branch, sha) {
2882
+ const encoded = base64(encoder.encode(content));
2883
+ return this.request(account, "/repos/" + repository + "/contents/" + path2, { method: "PUT", body: JSON.stringify({ message, content: encoded, branch, ...sha ? { sha } : {} }) });
2884
+ }
2885
+ createPullRequest(account, repository, title, body, head, base = "main") {
2886
+ return this.request(account, "/repos/" + repository + "/pulls", { method: "POST", body: JSON.stringify({ title, body, head, base }) });
2887
+ }
2888
+ dispatchWorkflow(account, repository, workflow, ref, inputs = {}) {
2889
+ return this.request(account, "/repos/" + repository + "/actions/workflows/" + workflow + "/dispatches", { method: "POST", body: JSON.stringify({ ref, inputs }) });
2890
+ }
2891
+ async pollWorkflow(account, repository, workflow, ref, startedAfter, options = {}) {
2892
+ const timeoutMs = options.timeoutMs ?? 3e5;
2893
+ const intervalMs = options.intervalMs ?? 2e3;
2894
+ const deadline = this.now() + timeoutMs;
2895
+ while (this.now() <= deadline) {
2896
+ const result = await this.request(account, "/repos/" + repository + "/actions/workflows/" + workflow + "/runs?branch=" + encodeURIComponent(ref) + "&per_page=20");
2897
+ if (result.ok === false) return result;
2898
+ const run = result.data.workflow_runs.find((candidate) => candidate.created_at >= startedAfter);
2899
+ if (run && ["completed", "cancelled"].includes(run.status)) return { ...result, data: run };
2900
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
2901
+ }
2902
+ return { ok: false, operation: "GET workflow poll", error: { message: "Workflow polling timed out", diagnostics: { timeoutMs, repository, workflow, ref, startedAfter } } };
2903
+ }
2904
+ };
2905
+ var createGitHubAppConnector = (options) => new GitHubAppConnector(options);
2906
+
2795
2907
  // src/engineering/github-vcs-provider.ts
2796
2908
  var GitHubVcsProvider = class {
2797
2909
  constructor(options) {
@@ -3215,6 +3327,7 @@ export {
3215
3327
  CLEAN_DATABASE_CLUSTER,
3216
3328
  CommandVerificationProvider,
3217
3329
  DEFAULT_CONNECTIONS,
3330
+ GitHubAppConnector,
3218
3331
  GitHubVcsProvider,
3219
3332
  KLOKSServiceIndex,
3220
3333
  LocalExecutionProvider,
@@ -3245,6 +3358,7 @@ export {
3245
3358
  buildServiceIdentity,
3246
3359
  clearSession,
3247
3360
  compareServices,
3361
+ createGitHubAppConnector,
3248
3362
  createMonacoIdeService,
3249
3363
  createServiceB,
3250
3364
  createServiceC,
@@ -170,6 +170,34 @@
170
170
  "BackendFacade.services"
171
171
  ]
172
172
  }
173
+ },
174
+ {
175
+ "id": "kloks.service.githubAppConnector",
176
+ "name": "GitHub App Connector",
177
+ "version": "1.0.0",
178
+ "description": "Portable GitHub App integration with multiple installations, repository/file/commit/PR operations and asynchronous workflow dispatch/monitoring.",
179
+ "backend": {
180
+ "package": "@ultrst-armada/kloks",
181
+ "export": "GitHubAppConnector",
182
+ "facade": "GitHubAppConnector"
183
+ },
184
+ "modes": [
185
+ "backend"
186
+ ],
187
+ "targets": {
188
+ "backend": [
189
+ "BackendFacade.services"
190
+ ]
191
+ },
192
+ "capabilities": [
193
+ "github-app",
194
+ "repositories",
195
+ "files",
196
+ "commits",
197
+ "pull-requests",
198
+ "workflow-dispatch",
199
+ "workflow-monitoring"
200
+ ]
173
201
  }
174
202
  ]
175
203
  }
@@ -7,6 +7,15 @@ import {
7
7
  instantiateSubgraph
8
8
  } from "./chunk-S22PMERU.js";
9
9
  import "./chunk-RHRXPY2U.js";
10
+ import {
11
+ LifecycleCycleError,
12
+ LifecycleGraph,
13
+ SKIPO_STATE,
14
+ SkipoStateEngine,
15
+ useLifecycleScope,
16
+ useSkipoBind,
17
+ useSkipoState
18
+ } from "./chunk-EW4ACSZB.js";
10
19
  import {
11
20
  AttractionEngine,
12
21
  GhostInferenceEngine,
@@ -22,15 +31,6 @@ import {
22
31
  WireTypeRegistry,
23
32
  initializeDefaultGraphRules
24
33
  } from "./chunk-TZOL3RN7.js";
25
- import {
26
- LifecycleCycleError,
27
- LifecycleGraph,
28
- SKIPO_STATE,
29
- SkipoStateEngine,
30
- useLifecycleScope,
31
- useSkipoBind,
32
- useSkipoState
33
- } from "./chunk-EW4ACSZB.js";
34
34
  import {
35
35
  CommandApi,
36
36
  GhostStore,
@@ -1,8 +0,0 @@
1
- {
2
- "schema": 1,
3
- "packageName": "@ultrst-armada/kloks",
4
- "version": "1.25.0",
5
- "sourceCommit": "06b060da4edadee7e3ffe2fd79e503d675c2da5b",
6
- "releaseWorkflow": "npm Release",
7
- "workflowRunId": "41989086753"
8
- }