@morkaai/runtime 0.0.0-stage → 0.2.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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -2
  3. package/bin/morka.cjs +57 -0
  4. package/dist/agent-actions/access.js +44 -0
  5. package/dist/agent-actions/manifest.js +52 -0
  6. package/dist/agent-actions/runner.js +69 -0
  7. package/dist/agents/account.js +42 -0
  8. package/dist/agents/acp-sandbox.js +118 -0
  9. package/dist/agents/activity.js +26 -0
  10. package/dist/agents/attachments.js +129 -0
  11. package/dist/agents/context.js +76 -0
  12. package/dist/agents/contracts.js +2 -0
  13. package/dist/agents/process.js +61 -0
  14. package/dist/agents/providers/acp.js +411 -0
  15. package/dist/agents/providers/claude.js +180 -0
  16. package/dist/agents/providers/codex.js +416 -0
  17. package/dist/agents/registry.js +76 -0
  18. package/dist/agents/sessions.js +331 -0
  19. package/dist/app-runtime/bridge.js +40 -0
  20. package/dist/app-runtime/starter/agents.json +1 -0
  21. package/dist/app-runtime/starter/index.html +11 -0
  22. package/dist/app-runtime/starter/main.js +0 -0
  23. package/dist/app-runtime/starter/package-lock.json +13 -0
  24. package/dist/app-runtime/starter/package.json +9 -0
  25. package/dist/app-runtime/starter/server.mjs +20 -0
  26. package/dist/app-runtime/starter/styles.css +0 -0
  27. package/dist/app-runtime/text-file.js +18 -0
  28. package/dist/branding/Morka.icns +0 -0
  29. package/dist/branding/README.md +24 -0
  30. package/dist/branding/generated-app-icon.png +0 -0
  31. package/dist/branding/morka-icon.png +0 -0
  32. package/dist/branding/morka-logo.png +0 -0
  33. package/dist/electron/main.js +802 -0
  34. package/dist/electron/preload.js +51 -0
  35. package/dist/instances/desktop.js +223 -0
  36. package/dist/instances/distribution.js +240 -0
  37. package/dist/instances/macos.js +62 -0
  38. package/dist/instances/repository.js +183 -0
  39. package/dist/instances/shadow-repository.js +95 -0
  40. package/dist/project/app-proxy.js +325 -0
  41. package/dist/project/bundle-toolchain.js +35 -0
  42. package/dist/project/drafts.js +27 -0
  43. package/dist/project/files.js +176 -0
  44. package/dist/project/live-preview.js +198 -0
  45. package/dist/project/managed-runtime.js +324 -0
  46. package/dist/project/node-lifecycle.js +45 -0
  47. package/dist/project/packages.js +302 -0
  48. package/dist/project/page-state.js +198 -0
  49. package/dist/project/project.js +112 -0
  50. package/dist/project/shadow-effects.js +156 -0
  51. package/dist/project/shadows.js +122 -0
  52. package/dist/project/toolchain.js +216 -0
  53. package/dist/renderer/activity.js +91 -0
  54. package/dist/renderer/app-setup.js +126 -0
  55. package/dist/renderer/chat-tools.css +83 -0
  56. package/dist/renderer/highlight.css +118 -0
  57. package/dist/renderer/icons/attach.png +0 -0
  58. package/dist/renderer/icons/brain-weight.png +0 -0
  59. package/dist/renderer/icons/brain.png +0 -0
  60. package/dist/renderer/icons/chat.png +0 -0
  61. package/dist/renderer/icons/chevron.png +0 -0
  62. package/dist/renderer/icons/clone.png +0 -0
  63. package/dist/renderer/icons/close.png +0 -0
  64. package/dist/renderer/icons/document.png +0 -0
  65. package/dist/renderer/icons/edit.png +0 -0
  66. package/dist/renderer/icons/folder.png +0 -0
  67. package/dist/renderer/icons/import.png +0 -0
  68. package/dist/renderer/icons/open-folder.png +0 -0
  69. package/dist/renderer/icons/play.png +0 -0
  70. package/dist/renderer/icons/plus.png +0 -0
  71. package/dist/renderer/icons/remove.png +0 -0
  72. package/dist/renderer/icons/search.png +0 -0
  73. package/dist/renderer/icons/send.png +0 -0
  74. package/dist/renderer/icons/shadow.png +0 -0
  75. package/dist/renderer/icons/stop.png +0 -0
  76. package/dist/renderer/icons/terminal.png +0 -0
  77. package/dist/renderer/index.html +130 -0
  78. package/dist/renderer/launcher/OFL.txt +93 -0
  79. package/dist/renderer/launcher/cell.js +322 -0
  80. package/dist/renderer/launcher/launcher.css +79 -0
  81. package/dist/renderer/launcher/lexend-caption-bold.ttf +0 -0
  82. package/dist/renderer/launcher.html +23 -0
  83. package/dist/renderer/licenses/dompurify.txt +202 -0
  84. package/dist/renderer/licenses/github-slugger.txt +5 -0
  85. package/dist/renderer/licenses/highlight.js.txt +29 -0
  86. package/dist/renderer/licenses/marked-footnote.txt +21 -0
  87. package/dist/renderer/licenses/marked-gfm-heading-id.txt +21 -0
  88. package/dist/renderer/licenses/marked.txt +44 -0
  89. package/dist/renderer/markdown.css +43 -0
  90. package/dist/renderer/markdown.js +74 -0
  91. package/dist/renderer/renderer.js +18902 -0
  92. package/dist/renderer/styles.css +351 -0
  93. package/dist/skills/morka-agent-action/SKILL.md +39 -0
  94. package/dist/skills/morka-app/SKILL.md +36 -0
  95. package/dist/skills/morka-shadow-authoring/SKILL.md +32 -0
  96. package/package.json +30 -4
@@ -0,0 +1,416 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CodexConnection = exports.CodexClient = void 0;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const node_os_1 = require("node:os");
6
+ const node_path_1 = require("node:path");
7
+ const node_readline_1 = require("node:readline");
8
+ const context_1 = require("../context");
9
+ const attachments_1 = require("../attachments");
10
+ const activity_1 = require("../activity");
11
+ const process_1 = require("../process");
12
+ // Command rules can authorize shell execution outside the write sandbox. Keep
13
+ // native apply_patch available, which checks file permissions independently.
14
+ const disabledFeatures = [
15
+ "hooks", "plugins", "apps", "computer_use", "browser_use", "request_permissions_tool", "skill_mcp_dependency_install",
16
+ "shell_tool", "shell_snapshot", "code_mode", "code_mode_only", "multi_agent", "multi_agent_v2", "runtime_agent_instances",
17
+ ];
18
+ function toMessage(item) {
19
+ switch (item.type) {
20
+ case "agentMessage":
21
+ return { id: item.id, role: "assistant", text: item.text };
22
+ case "commandExecution":
23
+ return { id: item.id, role: "activity", text: item.command,
24
+ activity: (0, activity_1.toolActivity)("command", { command: item.command }, item.exitCode ? "failed" : (0, activity_1.activityStatus)(item.status), item.aggregatedOutput) };
25
+ case "fileChange":
26
+ return { id: item.id, role: "activity", text: item.changes.map(change => change.path).join(", "),
27
+ activity: { kind: "edit", status: (0, activity_1.activityStatus)(item.status), title: `Edit · ${item.changes.map(change => change.path.split("/").at(-1)).join(", ")}`,
28
+ detail: item.changes.map(change => change.path + (change.diff ? "\n" + change.diff : "")).join("\n\n").slice(-32_000) } };
29
+ case "mcpToolCall":
30
+ case "dynamicToolCall":
31
+ return { id: item.id, role: "activity", text: item.tool,
32
+ activity: (0, activity_1.toolActivity)(item.tool, item.arguments, (0, activity_1.activityStatus)(item.status), JSON.stringify(item.error ?? item.result)) };
33
+ case "webSearch":
34
+ return { id: item.id, role: "activity", text: item.query, activity: (0, activity_1.toolActivity)("search", { query: item.query }, (0, activity_1.activityStatus)(item.status)) };
35
+ case "imageView":
36
+ return { id: item.id, role: "activity", text: item.path, activity: (0, activity_1.toolActivity)("view", { path: item.path }, "completed") };
37
+ }
38
+ }
39
+ class CodexClient {
40
+ skillsRoot;
41
+ runtime;
42
+ child;
43
+ ready;
44
+ loaded = new Set();
45
+ disabledServers = new Set();
46
+ pending = new Map();
47
+ policyCheck = Promise.resolve();
48
+ nextId = 0;
49
+ active;
50
+ failure;
51
+ constructor(skillsRoot, runtime = false) {
52
+ this.skillsRoot = skillsRoot;
53
+ this.runtime = runtime;
54
+ this.ready = this.initialize().then(() => this.restrictServers()).catch(error => {
55
+ this.close();
56
+ throw error;
57
+ });
58
+ }
59
+ get disconnected() { return Boolean(this.failure); }
60
+ async initialize() {
61
+ if (this.failure)
62
+ throw this.failure;
63
+ const previous = this.child;
64
+ const args = ["app-server", "-c", "mcp_servers={}", "-c", 'web_search="disabled"',
65
+ "-c", 'approval_policy="never"', "-c", 'sandbox_mode="read-only"',
66
+ ...disabledFeatures.flatMap(name => ["--disable", name]),
67
+ ...[...this.disabledServers].flatMap(server => ["-c", `mcp_servers.${server}.enabled=false`])];
68
+ const cli = await (0, process_1.agentLaunch)("codex", args);
69
+ if (this.failure)
70
+ throw this.failure;
71
+ const child = (0, node_child_process_1.spawn)(cli.command, cli.args, {
72
+ cwd: (0, node_os_1.homedir)(), env: cli.env, stdio: ["pipe", "pipe", "pipe"], windowsHide: true,
73
+ });
74
+ this.child = child;
75
+ if (previous) {
76
+ const replaced = new Error("The Codex connection was restarted to apply project restrictions.");
77
+ for (const finish of this.pending.values())
78
+ finish(undefined, replaced);
79
+ this.pending.clear();
80
+ this.loaded.clear();
81
+ previous.kill();
82
+ }
83
+ const onError = (error) => { if (this.child === child)
84
+ this.fail(error); };
85
+ child.stderr.resume();
86
+ child.on("error", (error) => onError(error.code === "ENOENT"
87
+ ? new Error("Codex was not found. Set CODEX_BIN to the CLI path.") : error));
88
+ child.stdin.on("error", onError);
89
+ child.on("close", () => onError(new Error("The Codex connection closed.")));
90
+ (0, node_readline_1.createInterface)({ input: child.stdout, crlfDelay: Infinity }).on("line", (line) => {
91
+ if (this.child === child)
92
+ this.receive(line);
93
+ });
94
+ await this.request("initialize", {
95
+ clientInfo: { name: "morka", title: "Morka", version: "0.1.0" },
96
+ capabilities: { experimentalApi: true },
97
+ });
98
+ this.write({ method: "initialized" });
99
+ await this.request("skills/extraRoots/set", { extraRoots: [this.skillsRoot] });
100
+ }
101
+ async enabledServers(cwd) {
102
+ const { config } = await this.request("config/read", { cwd, includeLayers: false });
103
+ const hooks = await this.request("hooks/list", { cwds: cwd ? [cwd] : [] });
104
+ if (hooks.data.some(entry => entry.hooks.some(hook => hook.enabled)) ||
105
+ disabledFeatures.some(name => config.features?.[name] !== false) ||
106
+ config.approval_policy !== "never" || config.sandbox_mode !== "read-only" || config.web_search !== "disabled") {
107
+ throw new Error("Codex could not verify the required sandbox and tool restrictions.");
108
+ }
109
+ return Object.entries(config.mcp_servers ?? {}).filter(([, server]) => server.enabled !== false).map(([name]) => name);
110
+ }
111
+ async restrictServers(cwd) {
112
+ const enabled = await this.enabledServers(cwd);
113
+ if (!enabled.length)
114
+ return;
115
+ if (enabled.some(name => !/^[\w-]+$/.test(name) || this.disabledServers.has(name))) {
116
+ throw new Error("Codex could not verify that all MCP servers were disabled.");
117
+ }
118
+ for (const name of enabled)
119
+ this.disabledServers.add(name);
120
+ // Config layers merge MCP entries, so an empty table alone cannot disable inherited servers.
121
+ await this.initialize();
122
+ if ((await this.enabledServers(cwd)).length) {
123
+ throw new Error("Codex could not verify that all MCP servers were disabled.");
124
+ }
125
+ }
126
+ async verifyPolicy(cwd) {
127
+ await this.ready;
128
+ const check = this.policyCheck.then(() => this.restrictServers(cwd));
129
+ this.policyCheck = check.catch(() => { });
130
+ await check;
131
+ }
132
+ write(message) {
133
+ if (!this.failure)
134
+ this.child.stdin.write(JSON.stringify(message) + "\n");
135
+ }
136
+ request(method, params) {
137
+ if (this.failure)
138
+ return Promise.reject(this.failure);
139
+ const id = ++this.nextId;
140
+ return new Promise((resolve, reject) => {
141
+ const timeout = setTimeout(() => {
142
+ this.pending.delete(id);
143
+ reject(new Error(`Codex did not respond to ${method}.`));
144
+ }, 60_000);
145
+ this.pending.set(id, (result, error) => {
146
+ clearTimeout(timeout);
147
+ if (error)
148
+ reject(error);
149
+ else
150
+ resolve(result);
151
+ });
152
+ this.write({ id, method, params });
153
+ });
154
+ }
155
+ receive(line) {
156
+ let message;
157
+ try {
158
+ message = JSON.parse(line);
159
+ }
160
+ catch {
161
+ return;
162
+ }
163
+ if (message.id !== undefined) {
164
+ if (message.method) {
165
+ this.write({ id: message.id, error: { code: -32601, message: "Unsupported client request." } });
166
+ }
167
+ else if (typeof message.id === "number") {
168
+ const finish = this.pending.get(message.id);
169
+ this.pending.delete(message.id);
170
+ finish?.(message.result, message.error && new Error(message.error.message));
171
+ }
172
+ return;
173
+ }
174
+ const active = this.active;
175
+ const event = message.params;
176
+ if (!active || !event || event.threadId !== active.threadId)
177
+ return;
178
+ const turnId = event.turnId ?? event.turn?.id;
179
+ if (active.id && turnId !== active.id)
180
+ return;
181
+ switch (message.method) {
182
+ case "turn/started":
183
+ active.id = event.turn?.id;
184
+ break;
185
+ case "item/started":
186
+ case "item/completed": {
187
+ if (!event.item || event.item.type === "userMessage")
188
+ break;
189
+ active.items.set(event.item.id, event.item);
190
+ const item = toMessage(event.item);
191
+ if (item?.text)
192
+ active.onMessage(item);
193
+ break;
194
+ }
195
+ case "item/commandExecution/outputDelta": {
196
+ const item = event.itemId && active.items.get(event.itemId);
197
+ if (item && item.type === "commandExecution" && event.delta) {
198
+ item.aggregatedOutput = ((item.aggregatedOutput ?? "") + event.delta).slice(-32_000);
199
+ active.onMessage(toMessage(item));
200
+ }
201
+ break;
202
+ }
203
+ case "turn/plan/updated":
204
+ if (event.plan)
205
+ active.onMessage({ id: "plan", role: "activity", text: event.explanation ?? "Plan",
206
+ activity: { kind: "plan", status: event.plan.every(step => step.status === "completed") ? "completed" : "running", title: "Plan",
207
+ detail: [event.explanation, ...event.plan.map(step => `${step.status} · ${step.step}`)].filter(Boolean).join("\n") } });
208
+ break;
209
+ case "item/agentMessage/delta":
210
+ if (event.itemId && event.delta)
211
+ active.onMessage({ id: event.itemId, role: "assistant", text: event.delta }, true);
212
+ break;
213
+ case "turn/completed":
214
+ if (event.turn)
215
+ active.finish(event.turn);
216
+ break;
217
+ }
218
+ }
219
+ fail(error) {
220
+ if (this.failure)
221
+ return;
222
+ this.failure = error;
223
+ for (const finish of this.pending.values())
224
+ finish(undefined, error);
225
+ this.pending.clear();
226
+ this.active?.finish(error);
227
+ }
228
+ async start(cwd) {
229
+ await this.verifyPolicy(cwd);
230
+ return this.startThread(cwd, false);
231
+ }
232
+ async startThread(cwd, ephemeral) {
233
+ const { thread } = await this.request("thread/start", {
234
+ cwd, ephemeral, sandbox: "read-only", approvalPolicy: "never",
235
+ });
236
+ if (Boolean(thread.ephemeral) !== ephemeral)
237
+ throw new Error("Codex returned an unexpected session type.");
238
+ this.loaded.add(thread.id);
239
+ return thread.id;
240
+ }
241
+ async options() {
242
+ await this.ready;
243
+ const models = [];
244
+ let defaultModel;
245
+ let cursor = null;
246
+ do {
247
+ const page = await this.request("model/list", { cursor });
248
+ defaultModel ??= page.data.find(item => item.isDefault)?.model;
249
+ models.push(...page.data.map(({ model, displayName, supportedReasoningEfforts, defaultReasoningEffort }) => ({
250
+ id: model, name: displayName, efforts: supportedReasoningEfforts?.map(option => (0, context_1.effortChoice)(option.reasoningEffort)),
251
+ defaultEffort: defaultReasoningEffort,
252
+ })));
253
+ cursor = page.nextCursor;
254
+ } while (cursor);
255
+ return { models, defaultModel };
256
+ }
257
+ async send(threadId, turn, storeThread) {
258
+ const { cwd, text, model, effort, files, project, historySinceSession, skills, onMessage, signal } = turn;
259
+ await this.verifyPolicy(cwd);
260
+ if (!this.loaded.has(threadId)) {
261
+ await this.request("thread/resume", { threadId, cwd, excludeTurns: true, sandbox: "read-only", approvalPolicy: "never" });
262
+ this.loaded.add(threadId);
263
+ }
264
+ const instructions = [
265
+ (0, context_1.projectInstructions)(project),
266
+ "Use apply_patch for changes.",
267
+ ...await (0, context_1.readEditingSkills)(skills, this.skillsRoot, "`apply_patch`"),
268
+ ].join("\n\n");
269
+ return this.performTurn(threadId, {
270
+ cwd, input: [{ type: "text", text, text_elements: [] },
271
+ ...turn.attachments?.flatMap(attachment => attachment.files.filter(file => file.mimeType).map(file => ({ type: "localImage", path: file.path }))) ?? []], model, effort, approvalPolicy: "never",
272
+ additionalContext: {
273
+ project_files: { kind: "untrusted", name: "project_files", value: JSON.stringify(files) },
274
+ project_paths: { kind: "untrusted", name: "project_paths", value: JSON.stringify(project.paths) },
275
+ project_instructions: { kind: "application", value: instructions },
276
+ ...(turn.attachments?.length ? { attachments: { kind: "untrusted", name: "attachments", value: (0, attachments_1.attachmentContext)(turn.attachments) } } : {}),
277
+ ...(historySinceSession.length ? { shared_history: { kind: "untrusted", name: "shared_history", value: "Conversation in Morka since your last turn, or before this native session began (JSON): " + (0, context_1.sharedHistory)(historySinceSession) } } : {}),
278
+ ...(project.shadow ? { shadow_package: { kind: "untrusted", name: "shadow_package", value: project.shadow } } : {}),
279
+ },
280
+ sandboxPolicy: { type: "workspaceWrite", writableRoots: [cwd], networkAccess: false,
281
+ excludeTmpdirEnvVar: true, excludeSlashTmp: true },
282
+ }, onMessage, signal, storeThread);
283
+ }
284
+ async skillInputs(cwd, root, names) {
285
+ const response = await this.request("skills/list", {
286
+ cwds: [cwd], forceReload: this.runtime,
287
+ });
288
+ const available = response.data.flatMap(entry => entry.skills);
289
+ return names.map(name => {
290
+ const path = (0, node_path_1.join)(root, name, "SKILL.md");
291
+ const skill = available.find(skill => skill.name === name && skill.path === path && skill.enabled);
292
+ if (!skill)
293
+ throw new Error(`Codex could not find the ${name} skill.`);
294
+ return { type: "skill", name: skill.name, path: skill.path };
295
+ });
296
+ }
297
+ async runAction(action) {
298
+ const { cwd, skillRoot: root, skill, text, schema: outputSchema, signal } = action;
299
+ await this.verifyPolicy(cwd);
300
+ await this.request("skills/extraRoots/set", { extraRoots: [root] });
301
+ const skills = await this.skillInputs(cwd, root, [skill]);
302
+ signal.throwIfAborted();
303
+ const threadId = await this.startThread(cwd, true);
304
+ let reply = "";
305
+ try {
306
+ const turn = await this.performTurn(threadId, {
307
+ cwd, input: [{ type: "text", text: `$${skill}\n${text}`, text_elements: [] }, ...skills],
308
+ outputSchema, approvalPolicy: "never", sandboxPolicy: { type: "readOnly", networkAccess: false },
309
+ }, (message, append) => {
310
+ if (message.role === "assistant" && !append)
311
+ reply = message.text;
312
+ }, signal);
313
+ if (turn.status !== "completed")
314
+ throw new Error(turn.error?.message ?? "The agent action did not complete.");
315
+ if (!reply)
316
+ throw new Error("The agent did not return a result.");
317
+ return reply;
318
+ }
319
+ finally {
320
+ this.loaded.delete(threadId);
321
+ await this.request("thread/unsubscribe", { threadId }).catch(() => { });
322
+ }
323
+ }
324
+ async performTurn(threadId, params, onMessage, signal, storeThread) {
325
+ signal.throwIfAborted();
326
+ let finish;
327
+ const completed = new Promise((resolve) => { finish = resolve; });
328
+ const active = { threadId, onMessage, finish, items: new Map() };
329
+ this.active = active;
330
+ const stop = () => { void this.stop(threadId).catch(finish); };
331
+ signal.addEventListener("abort", stop, { once: true });
332
+ try {
333
+ const { turn } = await this.request("turn/start", {
334
+ threadId, ...params,
335
+ });
336
+ active.id ??= turn.id;
337
+ if (storeThread) {
338
+ try {
339
+ await storeThread();
340
+ }
341
+ catch (error) {
342
+ await this.stop(threadId).catch(console.error);
343
+ throw error;
344
+ }
345
+ }
346
+ if (active.stopRequested)
347
+ await this.stop(threadId);
348
+ const result = await completed;
349
+ if (result instanceof Error)
350
+ throw result;
351
+ return result;
352
+ }
353
+ finally {
354
+ signal.removeEventListener("abort", stop);
355
+ if (this.active === active)
356
+ this.active = undefined;
357
+ }
358
+ }
359
+ async stop(threadId) {
360
+ const active = this.active;
361
+ if (active?.threadId !== threadId)
362
+ return;
363
+ if (!active.id)
364
+ active.stopRequested = true;
365
+ else
366
+ await this.request("turn/interrupt", { threadId, turnId: active.id });
367
+ }
368
+ close() {
369
+ this.fail(new Error("Morka is closing."));
370
+ this.child?.kill();
371
+ }
372
+ }
373
+ exports.CodexClient = CodexClient;
374
+ class CodexConnection {
375
+ skills;
376
+ editing;
377
+ runtime;
378
+ constructor(skills) {
379
+ this.skills = skills;
380
+ }
381
+ connect() {
382
+ if (!this.editing || this.editing.disconnected)
383
+ this.editing = new CodexClient(this.skills);
384
+ return this.editing;
385
+ }
386
+ options() { return this.connect().options(); }
387
+ async prompt(turn) {
388
+ const client = this.connect();
389
+ const id = turn.sessionId ?? await client.start(turn.cwd);
390
+ const result = await client.send(id, turn, turn.sessionId ? undefined : () => turn.storeSession(id));
391
+ if (result.status === "interrupted" || turn.signal.aborted)
392
+ return "interrupted";
393
+ if (result.status !== "completed")
394
+ throw new Error(result.error?.message ?? "The Codex turn did not complete.");
395
+ return "completed";
396
+ }
397
+ async runAction(turn) {
398
+ if (!this.runtime || this.runtime.disconnected)
399
+ this.runtime = new CodexClient(turn.skillRoot, true);
400
+ const runtime = this.runtime;
401
+ const stop = () => runtime.close();
402
+ turn.signal.addEventListener("abort", stop, { once: true });
403
+ try {
404
+ turn.signal.throwIfAborted();
405
+ return await runtime.runAction(turn);
406
+ }
407
+ finally {
408
+ turn.signal.removeEventListener("abort", stop);
409
+ }
410
+ }
411
+ close() {
412
+ this.editing?.close();
413
+ this.runtime?.close();
414
+ }
415
+ }
416
+ exports.CodexConnection = CodexConnection;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentRegistry = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_os_1 = require("node:os");
6
+ const node_path_1 = require("node:path");
7
+ const acp_1 = require("./providers/acp");
8
+ const claude_1 = require("./providers/claude");
9
+ const codex_1 = require("./providers/codex");
10
+ const account_1 = require("./account");
11
+ function profile(value) {
12
+ const entry = value;
13
+ if (!entry || typeof entry.id !== "string" || !/^[a-z0-9][a-z0-9-]{0,62}$/.test(entry.id) ||
14
+ ["codex", "claude"].includes(entry.id) || typeof entry.name !== "string" || !entry.name.trim() ||
15
+ typeof entry.command !== "string" || !entry.command.trim() || (!(0, node_path_1.isAbsolute)(entry.command) && entry.command.includes("/")) ||
16
+ !Array.isArray(entry.args) || !entry.args.every(arg => typeof arg === "string") ||
17
+ (entry.readPaths !== undefined && (!Array.isArray(entry.readPaths) || !entry.readPaths.every(path => typeof path === "string" && (0, node_path_1.isAbsolute)(path)))) ||
18
+ (entry.env !== undefined && (!entry.env || typeof entry.env !== "object" || Array.isArray(entry.env) ||
19
+ !Object.entries(entry.env).every(([name, text]) => /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name) && typeof text === "string")))) {
20
+ throw new Error("Invalid ACP agent profile.");
21
+ }
22
+ return entry;
23
+ }
24
+ class AgentRegistry {
25
+ entries = new Map();
26
+ static async open(directory, project, skills) {
27
+ const registry = new AgentRegistry();
28
+ registry.add("codex", "Codex", new codex_1.CodexConnection(skills));
29
+ registry.add("claude", "Claude Code", new claude_1.ClaudeConnection(skills));
30
+ const home = (0, node_os_1.homedir)();
31
+ const installations = [(0, node_path_1.join)(home, ".local/lib"), (0, node_path_1.join)(home, ".local/bin")];
32
+ const builtins = [
33
+ { id: "hermes", name: "Hermes", command: process.env.HERMES_BIN || "hermes", args: ["acp"],
34
+ readPaths: [...installations, ...["hermes-agent", "node", "tools", "installs"].map(path => (0, node_path_1.join)(home, ".hermes", path))] },
35
+ { id: "pi", name: "Pi", command: process.env.PI_ACP_BIN || "pi-acp", args: [], readPaths: installations },
36
+ ];
37
+ const override = process.env.MORKA_ACP_PROFILES;
38
+ const configured = override || (0, node_path_1.join)(directory, "acp-profiles.json");
39
+ const raw = await (0, promises_1.readFile)(configured, "utf8").catch((error) => {
40
+ if (error.code === "ENOENT" && !override)
41
+ return "[]";
42
+ throw error;
43
+ });
44
+ const data = JSON.parse(raw);
45
+ if (!Array.isArray(data))
46
+ throw new Error("The ACP profiles file must contain an array.");
47
+ for (const entry of [...builtins, ...data.map(profile)]) {
48
+ if (process.platform === "darwin") {
49
+ registry.add(entry.id, entry.name, new acp_1.AcpConnection(entry, skills, (0, node_path_1.join)(directory, "agents", entry.id), project));
50
+ }
51
+ }
52
+ return registry;
53
+ }
54
+ add(id, name, connection) {
55
+ this.entries.set(id, { info: { id, name }, connection });
56
+ }
57
+ providers() { return [...this.entries.values()].map(({ info }) => info); }
58
+ async setup() {
59
+ return Promise.all([...this.entries.entries()].map(async ([id, { info, connection }]) => ({
60
+ ...info,
61
+ supportsActions: Boolean(connection.runAction),
62
+ ...(id === "codex" || id === "claude" ? await (0, account_1.localAccount)(id) : { state: "managed" }),
63
+ })));
64
+ }
65
+ get(id) {
66
+ const entry = this.entries.get(id);
67
+ if (!entry)
68
+ throw new Error("This agent is not registered in Morka.");
69
+ return entry;
70
+ }
71
+ close() {
72
+ for (const { connection } of this.entries.values())
73
+ connection.close();
74
+ }
75
+ }
76
+ exports.AgentRegistry = AgentRegistry;