@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,324 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ManagedRuntime = void 0;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_fs_1 = require("node:fs");
7
+ const node_net_1 = require("node:net");
8
+ const node_crypto_1 = require("node:crypto");
9
+ const node_path_1 = require("node:path");
10
+ const node_util_1 = require("node:util");
11
+ const text_file_1 = require("../app-runtime/text-file");
12
+ const packages_1 = require("./packages");
13
+ const app_proxy_1 = require("./app-proxy");
14
+ const toolchain_1 = require("./toolchain");
15
+ const files_1 = require("./files");
16
+ async function freePort() {
17
+ const server = (0, node_net_1.createServer)();
18
+ await new Promise((resolve, reject) => { server.once("error", reject); server.listen(0, "127.0.0.1", resolve); });
19
+ const address = server.address();
20
+ if (!address || typeof address === "string")
21
+ throw new Error("Could not allocate an app service port.");
22
+ await new Promise(resolve => server.close(() => resolve()));
23
+ return address.port;
24
+ }
25
+ async function seedHome(source, destination) {
26
+ for (const entry of await (0, promises_1.readdir)(source, { withFileTypes: true })) {
27
+ if (entry.name === "tmp")
28
+ continue;
29
+ const from = (0, node_path_1.join)(source, entry.name), to = (0, node_path_1.join)(destination, entry.name);
30
+ const exists = await (0, files_1.info)(to);
31
+ if (entry.isDirectory()) {
32
+ if (!exists)
33
+ await (0, promises_1.mkdir)(to, { mode: 0o700 });
34
+ if (!exists || exists.isDirectory())
35
+ await seedHome(from, to);
36
+ }
37
+ else if (!exists && entry.isFile()) {
38
+ await (0, promises_1.copyFile)(from, to, node_fs_1.constants.COPYFILE_EXCL | node_fs_1.constants.COPYFILE_FICLONE);
39
+ await (0, promises_1.chmod)(to, 0o600 | ((await (0, files_1.info)(from)).mode & 0o111));
40
+ }
41
+ else if (!exists && entry.isSymbolicLink())
42
+ await (0, promises_1.symlink)(await (0, promises_1.readlink)(from), to);
43
+ }
44
+ }
45
+ class ManagedRuntime {
46
+ root;
47
+ home;
48
+ dataDirectory;
49
+ onExit;
50
+ active;
51
+ shutdown = new AbortController();
52
+ proxy;
53
+ job;
54
+ currentSource;
55
+ owner = (0, node_crypto_1.randomUUID)();
56
+ packages;
57
+ constructor(root, home, dataDirectory, onExit, toolchainRoot, originsDirectory, bridge) {
58
+ this.root = root;
59
+ this.home = home;
60
+ this.dataDirectory = dataDirectory;
61
+ this.onExit = onExit;
62
+ this.packages = new packages_1.AppPackages(home, toolchainRoot);
63
+ this.proxy = new app_proxy_1.AppProxy((0, node_path_1.join)(home, "origin.json"), originsDirectory, bridge);
64
+ }
65
+ get spec() { return this.active?.spec; }
66
+ get url() { return this.active?.alive ? this.proxy.url : undefined; }
67
+ get sourceFiles() { return this.currentSource ? new Map(this.currentSource) : undefined; }
68
+ async saved() {
69
+ const text = await (0, promises_1.readFile)((0, node_path_1.join)(this.home, "active.json"), "utf8").catch(error => {
70
+ if (error.code === "ENOENT")
71
+ return "{}";
72
+ throw error;
73
+ });
74
+ return JSON.parse(text);
75
+ }
76
+ async recover(previous = false) {
77
+ const state = await this.saved();
78
+ return this.packages.recover(previous ? state.previous : state.artifact);
79
+ }
80
+ async prepare(source, options = {}) {
81
+ const active = this.active;
82
+ if (active?.alive && this.currentSource && !active.artifact.built && await this.packages.sameConfiguration(active.artifact)) {
83
+ const changed = [...new Set([...source.keys(), ...this.currentSource.keys()])].filter(path => {
84
+ const before = this.currentSource.get(path), after = source.get(path);
85
+ return !before || !after || !before.equals(after);
86
+ });
87
+ if (changed.length && changed.every(path => path.endsWith(".css") && source.has(path)))
88
+ return this.packages.styles(active.artifact, source, changed, options.signal);
89
+ }
90
+ return this.packages.prepare(source, options);
91
+ }
92
+ async update(source, spec, callbacks, options = {}) {
93
+ if (this.job)
94
+ throw new Error("An app release is already being prepared.");
95
+ const signal = AbortSignal.any([this.shutdown.signal, ...(options.signal ? [options.signal] : [])]);
96
+ this.job = this.deploy(source, spec, callbacks, { ...options, signal });
97
+ try {
98
+ await this.job;
99
+ }
100
+ finally {
101
+ this.job = undefined;
102
+ }
103
+ return this.proxy.url;
104
+ }
105
+ async deploy(source, spec, callbacks, options) {
106
+ const previous = this.active;
107
+ const changed = this.currentSource ? [...new Set([...source.keys(), ...this.currentSource.keys()])].filter(path => {
108
+ const before = this.currentSource.get(path), after = source.get(path);
109
+ return !before || !after || !before.equals(after);
110
+ }) : [];
111
+ const sameConfig = previous ? await this.packages.sameConfiguration(previous.artifact) : false;
112
+ if (previous?.alive && !changed.length && sameConfig && JSON.stringify(previous.spec) === JSON.stringify(spec)) {
113
+ await callbacks.publish?.();
114
+ return;
115
+ }
116
+ const stylesheetOnly = previous?.alive && sameConfig && JSON.stringify(previous.spec) === JSON.stringify(spec) && !previous.artifact.built &&
117
+ changed.length > 0 && changed.every(path => path.endsWith(".css") && source.has(path));
118
+ if (stylesheetOnly) {
119
+ const artifact = await this.packages.styles(previous.artifact, source, changed, options.signal);
120
+ options.signal.throwIfAborted();
121
+ const hits = this.proxy.stylesheetHits;
122
+ const restoreStyles = this.proxy.styles(new Map(changed.map(path => [path, source.get(path)])), this.currentSource);
123
+ let undo;
124
+ try {
125
+ await callbacks.activate(this.proxy.url, changed);
126
+ if (this.proxy.stylesheetHits > hits) {
127
+ options.signal.throwIfAborted();
128
+ undo = await callbacks.publish?.();
129
+ await this.record(artifact, previous.processDirectory);
130
+ const previousKey = previous.artifact.key;
131
+ previous.artifact = artifact;
132
+ this.currentSource = new Map(source);
133
+ await this.packages.collect([artifact.key, previousKey, (0, node_path_1.basename)((0, node_path_1.dirname)(previous.processDirectory))]).catch(() => { });
134
+ return;
135
+ }
136
+ }
137
+ catch (error) {
138
+ restoreStyles();
139
+ await this.restoreFailedActivation(error, callbacks, undo);
140
+ }
141
+ restoreStyles();
142
+ }
143
+ const artifact = options.prepared ?? await this.packages.prepare(source, { signal: options.signal, onLog: options.onLog });
144
+ await this.proxy.start(Number(new URL(spec.url).port) || 0);
145
+ const candidate = await this.launch(artifact, spec, options.signal);
146
+ let committed = false;
147
+ let restoreRoute;
148
+ let undo;
149
+ try {
150
+ await this.ready(candidate, options.signal);
151
+ options.signal.throwIfAborted();
152
+ await callbacks.beforeActivate();
153
+ this.proxy.hold();
154
+ await this.proxy.drained(previous?.target, true, options.signal);
155
+ restoreRoute = this.proxy.route(candidate.target, true);
156
+ await callbacks.activate(this.proxy.url);
157
+ this.proxy.hold();
158
+ if (!options.prepared)
159
+ await this.migrate(candidate, options.signal);
160
+ await this.ready(candidate, options.signal);
161
+ options.signal.throwIfAborted();
162
+ undo = await callbacks.publish?.();
163
+ await this.record(artifact, artifact.directory);
164
+ this.active = candidate;
165
+ this.currentSource = new Map(source);
166
+ this.proxy.confirmPreview();
167
+ committed = true;
168
+ }
169
+ catch (error) {
170
+ if (restoreRoute) {
171
+ restoreRoute();
172
+ await this.restoreFailedActivation(error, callbacks, undo);
173
+ }
174
+ throw error;
175
+ }
176
+ finally {
177
+ this.proxy.release();
178
+ if (!committed)
179
+ await this.stopGeneration(candidate);
180
+ else if (previous) {
181
+ // Mutating requests drained before the switch. Finish old read streams
182
+ // after the replacement page is restored, then retire only old code.
183
+ await this.proxy.drained(previous.target).catch(() => { });
184
+ await this.stopGeneration(previous);
185
+ }
186
+ if (committed && this.active) {
187
+ const state = await this.saved().catch(() => ({ previous: undefined }));
188
+ await this.packages.collect([this.active.artifact.key, (0, node_path_1.basename)((0, node_path_1.dirname)(this.active.processDirectory)),
189
+ ...(state.previous ? [state.previous] : [])]).catch(() => { });
190
+ }
191
+ }
192
+ }
193
+ async restoreFailedActivation(error, callbacks, undo) {
194
+ const repairs = await Promise.allSettled([undo?.(), callbacks.rollback?.()]);
195
+ const failed = repairs.find(result => result.status === "rejected");
196
+ if (failed)
197
+ throw new Error(`${error instanceof Error ? error.message : error}\nRecovery also reported: ${failed.reason}`, { cause: error });
198
+ throw error;
199
+ }
200
+ async environment(artifact, extra = {}) {
201
+ const profile = (0, node_path_1.join)(this.home, "process-home");
202
+ await (0, promises_1.mkdir)((0, node_path_1.join)(profile, "tmp"), { recursive: true, mode: 0o700 });
203
+ const preparedHome = (0, node_path_1.join)(artifact.directory, "..", "home");
204
+ if ((await (0, files_1.info)(preparedHome))?.isDirectory()) {
205
+ // Installation-created caches/assets travel with the release. Hydrate
206
+ // missing files only; never replace existing app settings or user files.
207
+ await seedHome(preparedHome, profile);
208
+ }
209
+ await (0, promises_1.mkdir)(this.dataDirectory, { recursive: true, mode: 0o700 });
210
+ const envFile = (0, node_path_1.join)(this.root, ".env");
211
+ const appEnv = (await (0, files_1.info)(envFile))?.isFile() ? (0, node_util_1.parseEnv)(await (0, promises_1.readFile)(envFile, "utf8")) : {};
212
+ return (0, toolchain_1.runtimeEnvironment)(artifact.toolchain, profile, { ...appEnv, NODE_ENV: "production",
213
+ npm_config_update_notifier: "false", npm_config_audit: "false", npm_config_fund: "false",
214
+ MORKA_DATA_DIR: this.dataDirectory, MORKA_APP_ORIGIN: this.proxy.url, ...extra });
215
+ }
216
+ async launch(artifact, spec, signal) {
217
+ signal.throwIfAborted();
218
+ const pkg = JSON.parse(await (0, promises_1.readFile)((0, node_path_1.join)(artifact.directory, "package.json"), "utf8"));
219
+ if (typeof pkg.scripts?.[spec.script] !== "string")
220
+ throw new Error(`The app needs an npm script named “${spec.script}”.`);
221
+ const port = await freePort();
222
+ const child = (0, node_child_process_1.spawn)(artifact.toolchain.node, [artifact.toolchain.npm, "run", spec.script], {
223
+ cwd: artifact.directory, env: await this.environment(artifact, { HOST: "127.0.0.1", PORT: String(port), MORKA_PHASE: "prepare",
224
+ MORKA_ACTIVE_FILE: (0, node_path_1.join)(this.home, "active.json"), MORKA_PROCESS_DIR: artifact.directory,
225
+ MORKA_HOST_PID: String(process.pid), MORKA_OWNER: this.owner,
226
+ NODE_OPTIONS: `--require ${JSON.stringify((0, node_path_1.join)(__dirname, "node-lifecycle.js"))}` }),
227
+ detached: process.platform !== "win32", windowsHide: true, stdio: ["ignore", "pipe", "pipe", "ipc"],
228
+ });
229
+ const generation = { artifact, processDirectory: artifact.directory, spec, child,
230
+ target: `http://127.0.0.1:${port}/`, alive: true, complete: Promise.resolve(), logs: "" };
231
+ const log = (chunk) => { generation.logs = (generation.logs + chunk.toString()).slice(-8000); };
232
+ child.stdout?.on("data", log);
233
+ child.stderr?.on("data", log);
234
+ generation.complete = new Promise(resolve => {
235
+ const exited = () => {
236
+ generation.alive = false;
237
+ if (this.active === generation && !this.shutdown.signal.aborted)
238
+ this.onExit(generation.logs || "The app service exited.");
239
+ resolve();
240
+ };
241
+ child.once("error", error => { generation.logs += error.message; exited(); });
242
+ child.once("close", exited);
243
+ });
244
+ return generation;
245
+ }
246
+ async ready(generation, signal) {
247
+ const health = new URL(generation.spec.ready);
248
+ const url = new URL(health.pathname + health.search, generation.target);
249
+ const deadline = Date.now() + 60_000;
250
+ while (true) {
251
+ signal.throwIfAborted();
252
+ if (!generation.alive)
253
+ throw new Error("The candidate app exited before it was ready.\n" + generation.logs);
254
+ const response = await fetch(url, { redirect: "manual", signal: AbortSignal.any([signal, AbortSignal.timeout(1000)]) }).catch(() => undefined);
255
+ await response?.body?.cancel().catch(() => { });
256
+ if (response?.ok && generation.alive)
257
+ return;
258
+ if (Date.now() > deadline)
259
+ throw new Error("The candidate app did not become healthy; the current app was kept running.\n" + generation.logs);
260
+ await new Promise(resolve => setTimeout(resolve, 100));
261
+ }
262
+ }
263
+ async migrate(candidate, signal) {
264
+ const migration = candidate.spec.migration;
265
+ if (!migration)
266
+ return;
267
+ const file = (0, node_path_1.join)(this.home, "migrations.json");
268
+ const completed = JSON.parse(await (0, promises_1.readFile)(file, "utf8").catch(() => "{}"));
269
+ const key = migration.id;
270
+ if (completed[key])
271
+ return;
272
+ const child = (0, node_child_process_1.spawn)(candidate.artifact.toolchain.node, [candidate.artifact.toolchain.npm, "run", migration.script], {
273
+ cwd: candidate.artifact.directory, env: await this.environment(candidate.artifact, { MORKA_PHASE: "migration" }),
274
+ detached: process.platform !== "win32", windowsHide: true, stdio: ["ignore", "pipe", "pipe"],
275
+ });
276
+ let logs = "";
277
+ child.stdout?.on("data", chunk => { logs = (logs + chunk).slice(-8000); });
278
+ child.stderr?.on("data", chunk => { logs = (logs + chunk).slice(-8000); });
279
+ await (0, toolchain_1.waitForProcess)(child, signal, 5 * 60_000).catch(error => { throw new Error(`The compatible migration failed. The existing release remains active. ${error}\n${logs}`); });
280
+ completed[key] = true;
281
+ await (0, text_file_1.writeTextAtomically)(file, JSON.stringify(completed) + "\n");
282
+ }
283
+ async record(artifact, processDirectory) {
284
+ const saved = await this.saved();
285
+ const previous = saved.artifact && saved.artifact !== artifact.key ? saved.artifact : saved.previous;
286
+ await (0, text_file_1.writeTextAtomically)((0, node_path_1.join)(this.home, "active.json"), JSON.stringify({ version: 1,
287
+ artifact: artifact.key, sourceHash: artifact.sourceHash, processDirectory, dataDirectory: this.dataDirectory,
288
+ owner: this.owner, hostPid: process.pid, previous }) + "\n");
289
+ }
290
+ async stopGeneration(generation) {
291
+ if (this.active === generation)
292
+ this.active = undefined;
293
+ (0, toolchain_1.killProcess)(generation.child);
294
+ let timer;
295
+ await Promise.race([generation.complete, new Promise(resolve => { timer = setTimeout(resolve, 3000); })]);
296
+ if (timer)
297
+ clearTimeout(timer);
298
+ (0, toolchain_1.killProcess)(generation.child, "SIGKILL");
299
+ await generation.complete;
300
+ }
301
+ async stop() {
302
+ this.shutdown.abort(new Error("The app is closing."));
303
+ await this.job?.catch(() => { });
304
+ this.proxy.hold();
305
+ if (this.active) {
306
+ // Closing a window must not cut a write that the user already submitted.
307
+ let drained = false;
308
+ while (!drained) {
309
+ try {
310
+ await this.proxy.drained(this.active.target, true);
311
+ drained = true;
312
+ }
313
+ catch { /* Keep waiting; the OS's explicit Force Quit remains available. */ }
314
+ }
315
+ const state = await this.saved().catch(() => undefined);
316
+ if (state?.owner === this.owner) {
317
+ await (0, text_file_1.writeTextAtomically)((0, node_path_1.join)(this.home, "active.json"), JSON.stringify({ ...state, owner: "" }) + "\n").catch(console.error);
318
+ }
319
+ await this.stopGeneration(this.active);
320
+ }
321
+ await this.proxy.close();
322
+ }
323
+ }
324
+ exports.ManagedRuntime = ManagedRuntime;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Loaded through NODE_OPTIONS in each managed app Node process, including
4
+ // servers started by npm scripts. It contains no Electron or host capabilities.
5
+ (() => {
6
+ if (!process.env.MORKA_ACTIVE_FILE || !process.env.MORKA_PROCESS_DIR)
7
+ return;
8
+ const fs = require("node:fs");
9
+ const file = process.env.MORKA_ACTIVE_FILE;
10
+ const directory = process.env.MORKA_PROCESS_DIR;
11
+ const emitter = process;
12
+ let phase = "prepare";
13
+ const isActive = () => {
14
+ try {
15
+ const active = JSON.parse(fs.readFileSync(file, "utf8"));
16
+ return active.processDirectory === directory && active.owner === process.env.MORKA_OWNER;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ };
22
+ const observe = () => {
23
+ const host = Number(process.env.MORKA_HOST_PID);
24
+ if (host > 0) {
25
+ try {
26
+ process.kill(host, 0);
27
+ }
28
+ catch {
29
+ process.exit(0);
30
+ }
31
+ }
32
+ const next = isActive() ? "active" : phase === "active" ? "retired" : "prepare";
33
+ if (next === phase)
34
+ return;
35
+ phase = next;
36
+ process.env.MORKA_PHASE = next;
37
+ emitter.emit(next === "active" ? "morka:activate" : "morka:retire");
38
+ };
39
+ Object.defineProperty(globalThis, "morkaRuntime", { value: Object.freeze({ isActive, get phase() { return phase; } }) });
40
+ fs.watchFile(file, { interval: 100, persistent: false }, observe);
41
+ const timer = setInterval(observe, 1000);
42
+ timer.unref();
43
+ observe();
44
+ process.once("exit", () => { clearInterval(timer); fs.unwatchFile(file, observe); });
45
+ })();