@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.
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/bin/morka.cjs +57 -0
- package/dist/agent-actions/access.js +44 -0
- package/dist/agent-actions/manifest.js +52 -0
- package/dist/agent-actions/runner.js +69 -0
- package/dist/agents/account.js +42 -0
- package/dist/agents/acp-sandbox.js +118 -0
- package/dist/agents/activity.js +26 -0
- package/dist/agents/attachments.js +129 -0
- package/dist/agents/context.js +76 -0
- package/dist/agents/contracts.js +2 -0
- package/dist/agents/process.js +61 -0
- package/dist/agents/providers/acp.js +411 -0
- package/dist/agents/providers/claude.js +180 -0
- package/dist/agents/providers/codex.js +416 -0
- package/dist/agents/registry.js +76 -0
- package/dist/agents/sessions.js +331 -0
- package/dist/app-runtime/bridge.js +40 -0
- package/dist/app-runtime/starter/agents.json +1 -0
- package/dist/app-runtime/starter/index.html +11 -0
- package/dist/app-runtime/starter/main.js +0 -0
- package/dist/app-runtime/starter/package-lock.json +13 -0
- package/dist/app-runtime/starter/package.json +9 -0
- package/dist/app-runtime/starter/server.mjs +20 -0
- package/dist/app-runtime/starter/styles.css +0 -0
- package/dist/app-runtime/text-file.js +18 -0
- package/dist/branding/Morka.icns +0 -0
- package/dist/branding/README.md +24 -0
- package/dist/branding/generated-app-icon.png +0 -0
- package/dist/branding/morka-icon.png +0 -0
- package/dist/branding/morka-logo.png +0 -0
- package/dist/electron/main.js +802 -0
- package/dist/electron/preload.js +51 -0
- package/dist/instances/desktop.js +223 -0
- package/dist/instances/distribution.js +240 -0
- package/dist/instances/macos.js +62 -0
- package/dist/instances/repository.js +183 -0
- package/dist/instances/shadow-repository.js +95 -0
- package/dist/project/app-proxy.js +325 -0
- package/dist/project/bundle-toolchain.js +35 -0
- package/dist/project/drafts.js +27 -0
- package/dist/project/files.js +176 -0
- package/dist/project/live-preview.js +198 -0
- package/dist/project/managed-runtime.js +324 -0
- package/dist/project/node-lifecycle.js +45 -0
- package/dist/project/packages.js +302 -0
- package/dist/project/page-state.js +198 -0
- package/dist/project/project.js +112 -0
- package/dist/project/shadow-effects.js +156 -0
- package/dist/project/shadows.js +122 -0
- package/dist/project/toolchain.js +216 -0
- package/dist/renderer/activity.js +91 -0
- package/dist/renderer/app-setup.js +126 -0
- package/dist/renderer/chat-tools.css +83 -0
- package/dist/renderer/highlight.css +118 -0
- package/dist/renderer/icons/attach.png +0 -0
- package/dist/renderer/icons/brain-weight.png +0 -0
- package/dist/renderer/icons/brain.png +0 -0
- package/dist/renderer/icons/chat.png +0 -0
- package/dist/renderer/icons/chevron.png +0 -0
- package/dist/renderer/icons/clone.png +0 -0
- package/dist/renderer/icons/close.png +0 -0
- package/dist/renderer/icons/document.png +0 -0
- package/dist/renderer/icons/edit.png +0 -0
- package/dist/renderer/icons/folder.png +0 -0
- package/dist/renderer/icons/import.png +0 -0
- package/dist/renderer/icons/open-folder.png +0 -0
- package/dist/renderer/icons/play.png +0 -0
- package/dist/renderer/icons/plus.png +0 -0
- package/dist/renderer/icons/remove.png +0 -0
- package/dist/renderer/icons/search.png +0 -0
- package/dist/renderer/icons/send.png +0 -0
- package/dist/renderer/icons/shadow.png +0 -0
- package/dist/renderer/icons/stop.png +0 -0
- package/dist/renderer/icons/terminal.png +0 -0
- package/dist/renderer/index.html +130 -0
- package/dist/renderer/launcher/OFL.txt +93 -0
- package/dist/renderer/launcher/cell.js +322 -0
- package/dist/renderer/launcher/launcher.css +79 -0
- package/dist/renderer/launcher/lexend-caption-bold.ttf +0 -0
- package/dist/renderer/launcher.html +23 -0
- package/dist/renderer/licenses/dompurify.txt +202 -0
- package/dist/renderer/licenses/github-slugger.txt +5 -0
- package/dist/renderer/licenses/highlight.js.txt +29 -0
- package/dist/renderer/licenses/marked-footnote.txt +21 -0
- package/dist/renderer/licenses/marked-gfm-heading-id.txt +21 -0
- package/dist/renderer/licenses/marked.txt +44 -0
- package/dist/renderer/markdown.css +43 -0
- package/dist/renderer/markdown.js +74 -0
- package/dist/renderer/renderer.js +18902 -0
- package/dist/renderer/styles.css +351 -0
- package/dist/skills/morka-agent-action/SKILL.md +39 -0
- package/dist/skills/morka-app/SKILL.md +36 -0
- package/dist/skills/morka-shadow-authoring/SKILL.md +32 -0
- package/package.json +30 -4
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatSessions = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const node_util_1 = require("node:util");
|
|
8
|
+
const text_file_1 = require("../app-runtime/text-file");
|
|
9
|
+
const files_1 = require("../project/files");
|
|
10
|
+
const project_1 = require("../project/project");
|
|
11
|
+
const drafts_1 = require("../project/drafts");
|
|
12
|
+
const shadows_1 = require("../project/shadows");
|
|
13
|
+
const shadow_effects_1 = require("../project/shadow-effects");
|
|
14
|
+
const context_1 = require("./context");
|
|
15
|
+
const attachments_1 = require("./attachments");
|
|
16
|
+
const newChatTitle = "New chat";
|
|
17
|
+
class ChatSessions {
|
|
18
|
+
directory;
|
|
19
|
+
root;
|
|
20
|
+
registry;
|
|
21
|
+
index;
|
|
22
|
+
repository;
|
|
23
|
+
target;
|
|
24
|
+
otherRepository;
|
|
25
|
+
active;
|
|
26
|
+
attachments;
|
|
27
|
+
prepareProject;
|
|
28
|
+
activateProject;
|
|
29
|
+
readPendingShadow;
|
|
30
|
+
setProjectPreparer(prepare) { this.prepareProject = prepare; }
|
|
31
|
+
setProjectActivator(activate) { this.activateProject = activate; }
|
|
32
|
+
setShadowLoader(load) { this.readPendingShadow = load; }
|
|
33
|
+
constructor(directory, root, registry, index, repository, target = "app", otherRepository) {
|
|
34
|
+
this.directory = directory;
|
|
35
|
+
this.root = root;
|
|
36
|
+
this.registry = registry;
|
|
37
|
+
this.index = index;
|
|
38
|
+
this.repository = repository;
|
|
39
|
+
this.target = target;
|
|
40
|
+
this.otherRepository = otherRepository;
|
|
41
|
+
this.attachments = new attachments_1.AttachmentStore((0, node_path_1.join)(directory, "attachments"));
|
|
42
|
+
}
|
|
43
|
+
static async open(directory, root, registry, repository, target = "app", otherRepository) {
|
|
44
|
+
const text = await (0, promises_1.readFile)((0, node_path_1.join)(directory, "chats.json"), "utf8").catch((error) => {
|
|
45
|
+
if (error.code === "ENOENT")
|
|
46
|
+
return undefined;
|
|
47
|
+
throw error;
|
|
48
|
+
});
|
|
49
|
+
const index = text ? JSON.parse(text) : { chats: [] };
|
|
50
|
+
let recovered = false;
|
|
51
|
+
for (const chat of index.chats) {
|
|
52
|
+
for (const message of chat.messages) {
|
|
53
|
+
if (message.activity?.status !== "running")
|
|
54
|
+
continue;
|
|
55
|
+
message.activity = { ...message.activity, status: "stopped", completedAt: Date.now() };
|
|
56
|
+
recovered = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const sessions = new ChatSessions(directory, root, registry, index, repository, target, otherRepository);
|
|
60
|
+
if (recovered)
|
|
61
|
+
await sessions.save(index);
|
|
62
|
+
return sessions;
|
|
63
|
+
}
|
|
64
|
+
get running() { return Boolean(this.active); }
|
|
65
|
+
setProjectRoot(root, repository) {
|
|
66
|
+
if (this.active)
|
|
67
|
+
throw new Error("A turn is already in progress.");
|
|
68
|
+
this.root = root;
|
|
69
|
+
this.repository = repository;
|
|
70
|
+
}
|
|
71
|
+
async save(index) {
|
|
72
|
+
await (0, text_file_1.writeTextAtomically)((0, node_path_1.join)(this.directory, "chats.json"), JSON.stringify(index));
|
|
73
|
+
this.index = index;
|
|
74
|
+
}
|
|
75
|
+
session(id) {
|
|
76
|
+
const chat = this.index.chats.find(chat => chat.id === id);
|
|
77
|
+
if (!chat)
|
|
78
|
+
throw new Error("Chat not found.");
|
|
79
|
+
return chat;
|
|
80
|
+
}
|
|
81
|
+
async update(chat) {
|
|
82
|
+
await this.save({ ...this.index, chats: this.index.chats.map(item => item.id === chat.id ? chat : item) });
|
|
83
|
+
}
|
|
84
|
+
list() {
|
|
85
|
+
return { selected: this.index.selected, chats: this.index.chats.map(({ id, title, providerId }) => ({ id, title, providerId })) };
|
|
86
|
+
}
|
|
87
|
+
async create() {
|
|
88
|
+
if (this.active)
|
|
89
|
+
throw new Error("A turn is already in progress.");
|
|
90
|
+
const chat = { id: (0, node_crypto_1.randomUUID)(), title: newChatTitle };
|
|
91
|
+
await this.save({ selected: chat.id, chats: [{ ...chat, messages: [] }, ...this.index.chats] });
|
|
92
|
+
return chat;
|
|
93
|
+
}
|
|
94
|
+
async select(id) {
|
|
95
|
+
const chat = this.session(id);
|
|
96
|
+
if (this.index.selected !== id)
|
|
97
|
+
await this.save({ ...this.index, selected: id });
|
|
98
|
+
return chat.messages;
|
|
99
|
+
}
|
|
100
|
+
options(providerId) { return this.registry.get(providerId).connection.options(); }
|
|
101
|
+
async send(id, text, model, emit, shadow, selection, attachmentIds = []) {
|
|
102
|
+
if (this.active)
|
|
103
|
+
throw new Error("A turn is already in progress.");
|
|
104
|
+
if (shadow && this.target !== "app")
|
|
105
|
+
throw new Error("Install Shadows from an app workspace.");
|
|
106
|
+
let chat = this.session(id);
|
|
107
|
+
const agent = this.registry.get(selection.providerId);
|
|
108
|
+
const messages = new Map();
|
|
109
|
+
const turnId = (0, node_crypto_1.randomUUID)();
|
|
110
|
+
let transcript;
|
|
111
|
+
let finished = false;
|
|
112
|
+
let outcome = "failed";
|
|
113
|
+
let failure;
|
|
114
|
+
let preparationTitle;
|
|
115
|
+
const startedAt = Date.now();
|
|
116
|
+
function message(item, append = false) {
|
|
117
|
+
const idInTurn = `${turnId}:${item.id}`;
|
|
118
|
+
const previous = messages.get(idInTurn);
|
|
119
|
+
const tagged = { ...item, id: idInTurn, turnId, ...(item.role === "user" ? {} : { providerId: agent.info.id, providerName: agent.info.name }),
|
|
120
|
+
...(item.activity ? { activity: { ...item.activity, startedAt: previous?.activity?.startedAt ?? Date.now(),
|
|
121
|
+
...(item.activity.status !== "running" ? { completedAt: Date.now() } : {}) } } : {}) };
|
|
122
|
+
messages.set(idInTurn, append ? { ...tagged, text: (messages.get(idInTurn)?.text ?? "") + tagged.text } : tagged);
|
|
123
|
+
emit({ chatId: id, message: tagged, append });
|
|
124
|
+
}
|
|
125
|
+
const controller = new AbortController();
|
|
126
|
+
const { signal } = controller;
|
|
127
|
+
this.active = { id, controller };
|
|
128
|
+
try {
|
|
129
|
+
if (!shadow && chat.pendingShadow)
|
|
130
|
+
shadow = await this.readPendingShadow?.(chat.pendingShadow.package);
|
|
131
|
+
transcript = chat.messages;
|
|
132
|
+
const attachments = await this.attachments.context([...transcript.flatMap(item => item.attachments?.map(attachment => attachment.id) ?? []), ...attachmentIds], signal);
|
|
133
|
+
const selected = attachments.filter(attachment => attachmentIds.includes(attachment.id)).map(({ path: _path, files: _files, ...attachment }) => attachment);
|
|
134
|
+
chat = { ...chat, providerId: agent.info.id, title: chat.title === newChatTitle ? (text.trim() || selected.map(item => item.name).join(", ")).replace(/\s+/g, " ").slice(0, 60) : chat.title };
|
|
135
|
+
message({ id: "user", role: "user", text, ...(selected.length ? { attachments: selected } : {}) });
|
|
136
|
+
message({ id: "run", role: "activity", text: "Working", activity: { kind: "run", status: "running", title: "Working", startedAt } });
|
|
137
|
+
chat = { ...chat, messages: [...transcript, ...messages.values()] };
|
|
138
|
+
await this.update(chat);
|
|
139
|
+
const workspace = (0, node_path_1.join)(this.directory, "project-workspaces", id);
|
|
140
|
+
const live = await (0, files_1.snapshot)(this.root);
|
|
141
|
+
const current = this.target === "app" ? (0, shadow_effects_1.editableAppFiles)(live) : live;
|
|
142
|
+
const { draft, base } = await (0, drafts_1.synchronizeDraft)(workspace, current, chat, signal);
|
|
143
|
+
chat = { ...chat, base };
|
|
144
|
+
await this.update(chat);
|
|
145
|
+
const manifest = this.target === "app" ? (0, project_1.readManifest)(current) : undefined;
|
|
146
|
+
if (shadow) {
|
|
147
|
+
const reference = { id: shadow.id, version: shadow.version, digest: shadow.digest };
|
|
148
|
+
if (!(0, node_util_1.isDeepStrictEqual)(chat.pendingShadow?.package, reference)) {
|
|
149
|
+
const before = new Map(draft);
|
|
150
|
+
(0, shadows_1.stageShadow)(shadow, draft);
|
|
151
|
+
await (0, files_1.applyFiles)(workspace, before, draft, signal);
|
|
152
|
+
chat = { ...chat, pendingShadow: { package: reference, refs: (0, project_1.readManifest)(draft).shadows ?? [] } };
|
|
153
|
+
await this.update(chat);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const paths = manifest ? (0, project_1.instructionPaths)(manifest) : [];
|
|
157
|
+
const instructions = Object.fromEntries(paths.map(name => [name, draft.get(name)?.toString()]));
|
|
158
|
+
signal.throwIfAborted();
|
|
159
|
+
const prompt = async (repair, attempt = 0) => {
|
|
160
|
+
const promptFiles = attempt ? await (0, files_1.snapshot)(workspace) : draft;
|
|
161
|
+
return agent.connection.prompt({
|
|
162
|
+
cwd: workspace, repository: this.repository, otherRepository: this.otherRepository,
|
|
163
|
+
sessionId: chat.native?.[agent.info.id]?.id, text: repair ?? (text || "Review the attached files and ask what the user would like to do with them."), model, effort: selection.effort, attachments,
|
|
164
|
+
skills: (0, context_1.selectSkills)(this.target),
|
|
165
|
+
files: (0, files_1.sourceContext)(promptFiles, paths),
|
|
166
|
+
project: { target: this.target, instructions, paths: [...promptFiles.keys()], shadow: shadow && (0, shadows_1.shadowContext)(shadow),
|
|
167
|
+
activationFailure: chat.activationFailure },
|
|
168
|
+
history: transcript, historySinceSession: transcript.slice(chat.native?.[agent.info.id]?.cursor ?? 0),
|
|
169
|
+
onMessage: (item, append) => { if (item.role !== "user")
|
|
170
|
+
message(attempt ? { ...item, id: `repair-${attempt}:${item.id}` } : item, append); },
|
|
171
|
+
signal,
|
|
172
|
+
storeSession: async (sessionId) => {
|
|
173
|
+
chat = { ...chat, native: { ...chat.native, [agent.info.id]: { id: sessionId, cursor: 0 } } };
|
|
174
|
+
await this.update(chat);
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
const turn = await prompt();
|
|
179
|
+
if (signal.aborted || turn === "interrupted") {
|
|
180
|
+
outcome = "stopped";
|
|
181
|
+
return { stopped: true };
|
|
182
|
+
}
|
|
183
|
+
finished = true;
|
|
184
|
+
let updated = await (0, files_1.snapshot)(workspace);
|
|
185
|
+
if ((0, files_1.digest)(current) === (0, files_1.digest)(updated)) {
|
|
186
|
+
chat = { ...chat, activationFailure: undefined, pendingShadow: undefined };
|
|
187
|
+
outcome = "completed";
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
if ((0, files_1.digest)(await (0, files_1.snapshot)(this.root)) !== (0, files_1.digest)(live))
|
|
191
|
+
throw new Error("The project changed during this turn. The draft is preserved.");
|
|
192
|
+
if (this.target === "shadow") {
|
|
193
|
+
const packageResult = (0, shadows_1.validateShadow)(updated);
|
|
194
|
+
if (packageResult.id !== (0, shadows_1.validateShadow)(current).id)
|
|
195
|
+
throw new Error("Keep the Shadow's package ID when editing it.");
|
|
196
|
+
await (0, files_1.applyFiles)(this.root, current, updated, signal);
|
|
197
|
+
chat = { ...chat, base: (0, files_1.digest)(updated) };
|
|
198
|
+
outcome = "completed";
|
|
199
|
+
return { packageResult };
|
|
200
|
+
}
|
|
201
|
+
if ([...updated.keys()].some(shadow_effects_1.isShadowStorage))
|
|
202
|
+
throw new Error("The Shadow installation directory is managed by Morka.");
|
|
203
|
+
const expected = shadow ? chat.pendingShadow?.refs : manifest?.shadows;
|
|
204
|
+
const next = new Map([...live].filter(([path]) => (0, shadow_effects_1.isShadowStorage)(path)));
|
|
205
|
+
for (const [path, bytes] of updated)
|
|
206
|
+
next.set(path, bytes);
|
|
207
|
+
if (shadow) {
|
|
208
|
+
(0, shadow_effects_1.saveShadowInstallation)(current, next, shadow, live);
|
|
209
|
+
const text = (0, files_1.describeChanges)(current, updated);
|
|
210
|
+
if (text)
|
|
211
|
+
message({ id: (0, node_crypto_1.randomUUID)(), role: "activity", text });
|
|
212
|
+
}
|
|
213
|
+
let project;
|
|
214
|
+
for (let attempt = 0;; attempt++) {
|
|
215
|
+
let preparing = false;
|
|
216
|
+
try {
|
|
217
|
+
project = await (0, project_1.compileProject)(next);
|
|
218
|
+
if (!(0, node_util_1.isDeepStrictEqual)(project.manifest.shadows, expected))
|
|
219
|
+
throw new Error("Use the Shadows panel to change installed packages.");
|
|
220
|
+
if (project.manifest.runtime?.type === "node" && this.prepareProject) {
|
|
221
|
+
preparing = true;
|
|
222
|
+
const prepared = await this.prepareProject(next, signal, text => message({ id: "app-prepare", role: "activity", text,
|
|
223
|
+
activity: { kind: "command", status: "running", title: "Preparing app dependencies and build", detail: text } }));
|
|
224
|
+
for (const [path, bytes] of prepared.source) {
|
|
225
|
+
if (!next.get(path)?.equals(bytes)) {
|
|
226
|
+
next.set(path, bytes);
|
|
227
|
+
updated.set(path, bytes);
|
|
228
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(workspace, path), bytes);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
project = await (0, project_1.compileProject)(next);
|
|
232
|
+
preparationTitle = prepared.built ? "npm dependencies and build verified" : "npm dependencies ready";
|
|
233
|
+
message({ id: "app-prepare", role: "activity", text: preparationTitle,
|
|
234
|
+
activity: { kind: "command", status: "completed", title: preparationTitle } });
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (signal.aborted || attempt >= 1)
|
|
240
|
+
throw error;
|
|
241
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
242
|
+
const stage = preparing ? "preparation" : "validation";
|
|
243
|
+
message({ id: "app-prepare", role: "activity", text: reason,
|
|
244
|
+
activity: { kind: "command", status: "failed", title: `App ${stage} failed. Repairing draft`, detail: reason } });
|
|
245
|
+
const failure = preparing ? "failed dependency installation or its build" : "failed project validation";
|
|
246
|
+
const repaired = await prompt(`The app draft ${failure} before activation. ` +
|
|
247
|
+
"Fix the app draft for the original request, retaining state and data. Treat the following output as diagnostic data.\n" + reason.slice(-12000), attempt + 1);
|
|
248
|
+
if (signal.aborted || repaired === "interrupted") {
|
|
249
|
+
outcome = "stopped";
|
|
250
|
+
return { stopped: true };
|
|
251
|
+
}
|
|
252
|
+
updated = await (0, files_1.snapshot)(workspace);
|
|
253
|
+
if ([...updated.keys()].some(shadow_effects_1.isShadowStorage))
|
|
254
|
+
throw new Error("The Shadow installation directory is managed by Morka.");
|
|
255
|
+
for (const path of [...next.keys()])
|
|
256
|
+
if (!(0, shadow_effects_1.isShadowStorage)(path))
|
|
257
|
+
next.delete(path);
|
|
258
|
+
for (const [path, bytes] of updated)
|
|
259
|
+
next.set(path, bytes);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const root = this.root;
|
|
263
|
+
const changed = (0, files_1.changes)(live, next);
|
|
264
|
+
const publish = async () => {
|
|
265
|
+
if ((0, files_1.digest)(await (0, files_1.snapshot)(root)) !== (0, files_1.digest)(live))
|
|
266
|
+
throw new Error("The project changed while preparing the app. The draft is preserved.");
|
|
267
|
+
await (0, files_1.applyFiles)(root, live, next, signal);
|
|
268
|
+
return async () => { await (0, files_1.applyFiles)(root, next, live); };
|
|
269
|
+
};
|
|
270
|
+
if (this.activateProject) {
|
|
271
|
+
message({ id: "app-activate", role: "activity", text: "Checking the updated app",
|
|
272
|
+
activity: { kind: "command", status: "running", title: "Checking the updated app" } });
|
|
273
|
+
try {
|
|
274
|
+
await this.activateProject(project, publish, signal);
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (!signal.aborted)
|
|
278
|
+
chat = { ...chat, activationFailure: (error instanceof Error ? error.message : String(error)).slice(0, 8000) };
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else
|
|
283
|
+
await publish();
|
|
284
|
+
chat = { ...chat, base: (0, files_1.digest)(updated), activationFailure: undefined, pendingShadow: undefined };
|
|
285
|
+
outcome = "completed";
|
|
286
|
+
return this.activateProject ? {} : { project, changed };
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
290
|
+
if (signal.aborted) {
|
|
291
|
+
outcome = "stopped";
|
|
292
|
+
return { stopped: true };
|
|
293
|
+
}
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
try {
|
|
298
|
+
if (transcript) {
|
|
299
|
+
for (const item of messages.values()) {
|
|
300
|
+
if (item.activity?.status !== "running" || item.activity.kind === "run")
|
|
301
|
+
continue;
|
|
302
|
+
const update = { ...item, activity: { ...item.activity, status: outcome, completedAt: Date.now() } };
|
|
303
|
+
messages.set(item.id, update);
|
|
304
|
+
emit({ chatId: id, message: update });
|
|
305
|
+
}
|
|
306
|
+
if (messages.has(`${turnId}:run`))
|
|
307
|
+
message({ id: "run", role: "activity", text: outcome,
|
|
308
|
+
activity: { kind: "run", status: outcome, title: outcome === "completed" ? preparationTitle ?? "Completed" : outcome === "stopped" ? "Stopped" : "Failed", detail: failure, startedAt, completedAt: Date.now() } });
|
|
309
|
+
const timeline = [...transcript, ...messages.values()];
|
|
310
|
+
const session = chat.native?.[agent.info.id];
|
|
311
|
+
if (finished && session)
|
|
312
|
+
chat = {
|
|
313
|
+
...chat, native: { ...chat.native, [agent.info.id]: { ...session, cursor: timeline.length } },
|
|
314
|
+
};
|
|
315
|
+
await this.update({ ...chat, messages: timeline });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
this.active = undefined;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
stop(id) {
|
|
324
|
+
if (this.active?.id === id)
|
|
325
|
+
this.active.controller.abort();
|
|
326
|
+
}
|
|
327
|
+
close() {
|
|
328
|
+
this.active?.controller.abort();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.ChatSessions = ChatSessions;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// host/app-runtime/bridge.ts
|
|
4
|
+
(() => {
|
|
5
|
+
let nextId = 0;
|
|
6
|
+
const pending = /* @__PURE__ */ new Map();
|
|
7
|
+
const idle = /* @__PURE__ */ new Set();
|
|
8
|
+
window.addEventListener("message", (event) => {
|
|
9
|
+
if (event.source !== window.parent || event.data?.type !== "morka:addon-result") return;
|
|
10
|
+
const { id, result } = event.data;
|
|
11
|
+
const finish = pending.get(id);
|
|
12
|
+
if (!finish) return;
|
|
13
|
+
pending.delete(id);
|
|
14
|
+
finish(result);
|
|
15
|
+
if (!pending.size) {
|
|
16
|
+
for (const resolve of idle) resolve();
|
|
17
|
+
idle.clear();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
function invoke(request) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const id = ++nextId;
|
|
23
|
+
pending.set(id, (result) => result.error ? reject(new Error(result.error)) : resolve(result.value));
|
|
24
|
+
try {
|
|
25
|
+
window.parent.postMessage({ type: "morka:addon-request", id, request }, "*");
|
|
26
|
+
} catch (error) {
|
|
27
|
+
pending.delete(id);
|
|
28
|
+
reject(error);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const api = Object.freeze({
|
|
33
|
+
whenIdle: () => pending.size ? new Promise((resolve) => idle.add(resolve)) : Promise.resolve(),
|
|
34
|
+
runAgentAction(action, input) {
|
|
35
|
+
return invoke({ type: "runAgentAction", action, input });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(window, "morka", { value: api });
|
|
39
|
+
})();
|
|
40
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<link rel="stylesheet" href="styles.css">
|
|
7
|
+
<script src="/__morka/bridge.js"></script>
|
|
8
|
+
<script src="main.js" defer></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body></body>
|
|
11
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
const assets = new Map([
|
|
5
|
+
["/", ["index.html", "text/html"]],
|
|
6
|
+
["/index.html", ["index.html", "text/html"]],
|
|
7
|
+
["/styles.css", ["styles.css", "text/css"]],
|
|
8
|
+
["/main.js", ["main.js", "text/javascript"]],
|
|
9
|
+
]);
|
|
10
|
+
createServer(async (request, response) => {
|
|
11
|
+
const path = new URL(request.url, "http://localhost").pathname;
|
|
12
|
+
if (path === "/health") { response.writeHead(200); response.end("ready"); return; }
|
|
13
|
+
const asset = assets.get(path);
|
|
14
|
+
if (!asset || !["GET", "HEAD"].includes(request.method)) { response.writeHead(404); response.end(); return; }
|
|
15
|
+
try {
|
|
16
|
+
const bytes = await readFile(new URL(asset[0], import.meta.url));
|
|
17
|
+
response.writeHead(200, { "Content-Type": asset[1] + "; charset=utf-8", "Cache-Control": "no-store" });
|
|
18
|
+
response.end(request.method === "HEAD" ? undefined : bytes);
|
|
19
|
+
} catch { response.writeHead(404); response.end(); }
|
|
20
|
+
}).listen(Number(process.env.PORT), process.env.HOST || "127.0.0.1");
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeTextAtomically = writeTextAtomically;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
async function writeTextAtomically(path, text) {
|
|
8
|
+
const temporary = `${path}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
9
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(path), { recursive: true });
|
|
10
|
+
try {
|
|
11
|
+
await (0, promises_1.writeFile)(temporary, text, { encoding: "utf8", mode: 0o600, flag: "wx", flush: true });
|
|
12
|
+
await (0, promises_1.rename)(temporary, path);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
await (0, promises_1.rm)(temporary, { force: true }).catch(() => { });
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Morka branding
|
|
2
|
+
|
|
3
|
+
- `morka-logo.png`: approved transparent logo and wordmark.
|
|
4
|
+
- `morka-icon.png`: icon adaptation of that logo, with the symbol on a warm white macOS tile.
|
|
5
|
+
- `Morka.icns`: the icon encoded as PNG representations at 16, 32, 64, 128, 256, 512 and 1024 pixels, including Retina representations.
|
|
6
|
+
- `generated-app-icon.png` supplies the single-arch, single-bud mark for generated apps and their clones. Each new app randomly chooses one of eight colors for the mark and its glow on the launcher’s cream tile. A clone draws from the other seven colors. The project stores the chosen icon for future builds.
|
|
7
|
+
|
|
8
|
+
The launcher uses `Morka.icns` in the macOS bundle and `morka-icon.png` in the development Dock. Artwork was generated with the built-in **ImageGen** tool.
|
|
9
|
+
|
|
10
|
+
## Icon adaptation prompt
|
|
11
|
+
|
|
12
|
+
Use case: logo-brand. Edit target: the attached approved Morka logo. Make a production macOS app icon using EXACTLY the existing violet symbol from this image. Remove ONLY the wordmark 'morka', retain the symbol's exact silhouette, three rounded lower legs, arches, two budding round tips, orientation, proportions, and violet color. Do not redesign or reinterpret it. Center the existing symbol, scaled with comfortable padding, on a clean warm-white rounded-square macOS icon tile. Square canvas 1024x1024; the rounded-square tile fills about 88% width and height with consistent transparent margin OUTSIDE the tile. Symbol fills about 67% canvas width. Crisp smooth edges and flat solid violet; plain warm white tile; transparent outside tile. No text, no new objects, no new shapes within symbol, no watermark, no perspective or mockup. This is an adaptation of an approved logo, preserve its identity faithfully.
|
|
13
|
+
|
|
14
|
+
## Final refinement prompt
|
|
15
|
+
|
|
16
|
+
Precisely clean up this macOS app icon. Keep the existing violet organic Morka symbol and its proportions, placement and colors identical. Keep the warm-white rounded square tile. Remove ALL the stray white fragments, speckles, halos and ragged debris that currently surround the tile. The boundary of the rounded-square tile must be a mathematically clean smooth continuous rounded rectangle. Outside that boundary every pixel must be fully transparent; no shadows or fringe. Inside tile background uniformly warm white. Crisp polished logo edges. One centered icon only. No text. Do not alter the symbol design.
|
|
17
|
+
|
|
18
|
+
## Generated app icon prompt
|
|
19
|
+
|
|
20
|
+
Use case: logo-brand. Image 1 is the approved Morka parent icon and definitive art direction. Make its junior family mark. Retain the same flat deep violet ink, smooth organic contours, substantial round-ended legs, cream squircle and optical scale. The parent silhouette has two lower arches, three feet, and two budding tips. For the junior design draw exactly ONE substantial upside-down U arch, with TWO blunt round-ended feet defining a generous open counter. A single round budding node grows from the upper RIGHT shoulder on a short organic up-right neck, continuous with the shoulder, like the large upper terminal of the parent. The top curls into the bud with a concave sweep on its right and a gentle convex rise on its left. Single solid silhouette like a lowercase n with one little round bud. A flat graphic logo. No separate dots. No third foot, eyes, face, relief or gradient. Center the scaled junior glyph on the same warm cream tile, leave breathing room. Straight-on square app icon on a transparent margin, no sample palette, no lettering.
|
|
21
|
+
|
|
22
|
+
## Glow refinement prompt
|
|
23
|
+
|
|
24
|
+
Micro-edit the attached approved Morka child application icon. Keep its existing single arch, two feet and one round bud, exact violet silhouette, dimensions, placement, cream rounded-square tile and transparent outer margin. Add only a restrained, softly diffused lavender ambient glow on the cream immediately outside the purple shape, following its entire contour including inside the arch. At 1024 px the glow falls off smoothly over about 22 px, strongest closest to the ink. Aim for 12% violet tint on the adjacent cream, nearly invisible farther out. Keep the ink a rich solid violet, crisp. No stroke, white rim, additional symbols, shadow, bevel or gloss. Same square, straight-on production icon at identical framing.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|