inhuman 0.1.0 → 0.2.0
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/bin/inhuman.mjs +2 -20
- package/dist/bin.d.ts +6 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +16 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli/blobs-command.d.ts +31 -0
- package/dist/cli/blobs-command.d.ts.map +1 -0
- package/dist/cli/blobs-command.js +184 -0
- package/dist/cli/blobs-command.js.map +1 -0
- package/dist/cli/browser.d.ts +3 -0
- package/dist/cli/browser.d.ts.map +1 -0
- package/dist/cli/browser.js +10 -0
- package/dist/cli/browser.js.map +1 -0
- package/dist/cli/completion-command.d.ts +15 -0
- package/dist/cli/completion-command.d.ts.map +1 -0
- package/dist/cli/completion-command.js +201 -0
- package/dist/cli/completion-command.js.map +1 -0
- package/dist/cli/context.d.ts +23 -0
- package/dist/cli/context.d.ts.map +1 -0
- package/dist/cli/context.js +67 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/daemon.d.ts +22 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +61 -0
- package/dist/cli/daemon.js.map +1 -0
- package/dist/cli/eval-command.d.ts +16 -0
- package/dist/cli/eval-command.d.ts.map +1 -0
- package/dist/cli/eval-command.js +114 -0
- package/dist/cli/eval-command.js.map +1 -0
- package/dist/cli/install-command.d.ts +8 -0
- package/dist/cli/install-command.d.ts.map +1 -0
- package/dist/cli/install-command.js +25 -0
- package/dist/cli/install-command.js.map +1 -0
- package/dist/cli/kernel-client.d.ts +3 -0
- package/dist/cli/kernel-client.d.ts.map +1 -0
- package/dist/cli/kernel-client.js +12 -0
- package/dist/cli/kernel-client.js.map +1 -0
- package/dist/cli/mcp-commands.d.ts +61 -0
- package/dist/cli/mcp-commands.d.ts.map +1 -0
- package/dist/cli/mcp-commands.js +139 -0
- package/dist/cli/mcp-commands.js.map +1 -0
- package/dist/cli/mcp.d.ts +25 -0
- package/dist/cli/mcp.d.ts.map +1 -0
- package/dist/cli/mcp.js +261 -0
- package/dist/cli/mcp.js.map +1 -0
- package/dist/cli/register.d.ts +12 -0
- package/dist/cli/register.d.ts.map +1 -0
- package/dist/cli/register.js +133 -0
- package/dist/cli/register.js.map +1 -0
- package/dist/cli/remote-commands.d.ts +49 -0
- package/dist/cli/remote-commands.d.ts.map +1 -0
- package/dist/cli/remote-commands.js +184 -0
- package/dist/cli/remote-commands.js.map +1 -0
- package/dist/cli/resume-complete.d.ts +24 -0
- package/dist/cli/resume-complete.d.ts.map +1 -0
- package/dist/cli/resume-complete.js +35 -0
- package/dist/cli/resume-complete.js.map +1 -0
- package/dist/cli/shell-import.d.ts +22 -0
- package/dist/cli/shell-import.d.ts.map +1 -0
- package/dist/cli/shell-import.js +32 -0
- package/dist/cli/shell-import.js.map +1 -0
- package/dist/cli/tui-command.d.ts +11 -0
- package/dist/cli/tui-command.d.ts.map +1 -0
- package/dist/cli/tui-command.js +41 -0
- package/dist/cli/tui-command.js.map +1 -0
- package/dist/cli/web-commands.d.ts +54 -0
- package/dist/cli/web-commands.d.ts.map +1 -0
- package/dist/cli/web-commands.js +106 -0
- package/dist/cli/web-commands.js.map +1 -0
- package/dist/cli/web-door-command.d.ts +11 -0
- package/dist/cli/web-door-command.d.ts.map +1 -0
- package/dist/cli/web-door-command.js +151 -0
- package/dist/cli/web-door-command.js.map +1 -0
- package/dist/cli/web-door.d.ts +25 -0
- package/dist/cli/web-door.d.ts.map +1 -0
- package/dist/cli/web-door.js +116 -0
- package/dist/cli/web-door.js.map +1 -0
- package/dist/cli/web-static.d.ts +8 -0
- package/dist/cli/web-static.d.ts.map +1 -0
- package/dist/cli/web-static.js +23 -0
- package/dist/cli/web-static.js.map +1 -0
- package/dist/eval/progress.d.ts +8 -0
- package/dist/eval/progress.d.ts.map +1 -0
- package/dist/eval/progress.js +64 -0
- package/dist/eval/progress.js.map +1 -0
- package/dist/eval/run.d.ts +20 -0
- package/dist/eval/run.d.ts.map +1 -0
- package/dist/eval/run.js +301 -0
- package/dist/eval/run.js.map +1 -0
- package/package.json +42 -5
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { existsSync } from "node:fs";
|
|
54
|
+
import { realpath } from "node:fs/promises";
|
|
55
|
+
import { dirname, join } from "node:path";
|
|
56
|
+
import { fileURLToPath } from "node:url";
|
|
57
|
+
import { daemonRunning } from "@inhuman.tools/harness";
|
|
58
|
+
import { Client } from "@inhuman.tools/harness-sdk";
|
|
59
|
+
import { daemonSocketPath } from "@inhuman.tools/harness-sdk/paths";
|
|
60
|
+
import { Option } from "clipanion";
|
|
61
|
+
import { KernelCommand } from "./context.js";
|
|
62
|
+
import { importShell } from "./shell-import.js";
|
|
63
|
+
import { clearDoorRecord, DOOR_MISSES_TO_LEAVE, DOOR_PROBE_MS, writeDoorRecord } from "./web-door.js";
|
|
64
|
+
/**
|
|
65
|
+
* Internal: the detached process `inhuman start` and `inhuman web` start. Serves the built client until the daemon is gone.
|
|
66
|
+
* It has no `usage`, so help does not list it.
|
|
67
|
+
*/
|
|
68
|
+
export class WebDoorCommand extends KernelCommand {
|
|
69
|
+
static paths = [["web-door"]];
|
|
70
|
+
port = Option.String("--port", "8787");
|
|
71
|
+
async execute() {
|
|
72
|
+
const port = Number(this.port);
|
|
73
|
+
const web = await importShell(this.context, { label: "web shell", specifier: "@inhuman.tools/harness-web-app/server" }, () => import("@inhuman.tools/harness-web-app/server"));
|
|
74
|
+
if (web === undefined)
|
|
75
|
+
return 1;
|
|
76
|
+
const webAppRoot = dirname(fileURLToPath(import.meta.resolve("@inhuman.tools/harness-web-app/package.json")));
|
|
77
|
+
const kernel = await realpath(this.kernelPath());
|
|
78
|
+
const sock = daemonSocketPath(kernel);
|
|
79
|
+
if (!existsSync(sock)) {
|
|
80
|
+
this.context.writeErr("web-door: daemon socket is missing");
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
const fileRoots = new Set([process.cwd()]);
|
|
84
|
+
try {
|
|
85
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
86
|
+
try {
|
|
87
|
+
const client = __addDisposableResource(env_1, await Client.kernel(kernel), true);
|
|
88
|
+
for (const path of Object.keys(client.plexus.root.projects))
|
|
89
|
+
fileRoots.add(path);
|
|
90
|
+
}
|
|
91
|
+
catch (e_1) {
|
|
92
|
+
env_1.error = e_1;
|
|
93
|
+
env_1.hasError = true;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
const result_1 = __disposeResources(env_1);
|
|
97
|
+
if (result_1)
|
|
98
|
+
await result_1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// /file still serves the process cwd.
|
|
103
|
+
}
|
|
104
|
+
const options = {
|
|
105
|
+
sockPath: sock,
|
|
106
|
+
pages: "static",
|
|
107
|
+
staticDir: join(webAppRoot, "dist/client"),
|
|
108
|
+
fileRoots: [...fileRoots],
|
|
109
|
+
extraOrigins: (process.env["HARNESS_WEB_ALLOWED_ORIGINS"] ?? "")
|
|
110
|
+
.split(",")
|
|
111
|
+
.map((origin) => origin.trim())
|
|
112
|
+
.filter((origin) => origin !== ""),
|
|
113
|
+
};
|
|
114
|
+
let app;
|
|
115
|
+
try {
|
|
116
|
+
app = await web.listenWebApp({ ...options, port });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (error.code !== "EADDRINUSE") {
|
|
120
|
+
this.context.writeErr(error);
|
|
121
|
+
return 1;
|
|
122
|
+
}
|
|
123
|
+
app = await web.listenWebApp({ ...options, port: 0 });
|
|
124
|
+
}
|
|
125
|
+
const url = `http://127.0.0.1:${app.port}/`;
|
|
126
|
+
await writeDoorRecord(kernel, { pid: process.pid, port: app.port, url });
|
|
127
|
+
this.context.stdout.write(`web-door ${process.pid} ${url}\n`);
|
|
128
|
+
await new Promise((resolve) => {
|
|
129
|
+
let misses = 0;
|
|
130
|
+
const timer = setInterval(() => {
|
|
131
|
+
void (async () => {
|
|
132
|
+
const alive = await daemonRunning(kernel);
|
|
133
|
+
misses = alive ? 0 : misses + 1;
|
|
134
|
+
if (misses >= DOOR_MISSES_TO_LEAVE)
|
|
135
|
+
resolve();
|
|
136
|
+
})();
|
|
137
|
+
}, DOOR_PROBE_MS);
|
|
138
|
+
const leave = () => {
|
|
139
|
+
clearInterval(timer);
|
|
140
|
+
resolve();
|
|
141
|
+
};
|
|
142
|
+
process.once("SIGINT", leave);
|
|
143
|
+
process.once("SIGTERM", leave);
|
|
144
|
+
});
|
|
145
|
+
this.context.stdout.write("web-door leaving\n");
|
|
146
|
+
await clearDoorRecord(kernel, process.pid);
|
|
147
|
+
await app.close();
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=web-door-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-door-command.js","sourceRoot":"","sources":["../../src/cli/web-door-command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEz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AAC,oBAAoB,CAAC,CAAC;QAChD,MAAM,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC;IACX,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type DoorRecord = {
|
|
2
|
+
readonly pid: number;
|
|
3
|
+
readonly port: number;
|
|
4
|
+
readonly url: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const DOOR_PROBE_MS = 2000;
|
|
7
|
+
export declare const DOOR_MISSES_TO_LEAVE = 3;
|
|
8
|
+
export declare function doorRecordPath(kernel: string): string;
|
|
9
|
+
export declare function doorLogPath(kernel: string): string;
|
|
10
|
+
export declare function parseDoorRecord(text: string): DoorRecord | undefined;
|
|
11
|
+
export declare function readDoorRecord(kernel: string): Promise<DoorRecord | undefined>;
|
|
12
|
+
export declare function writeDoorRecord(kernel: string, record: DoorRecord): Promise<void>;
|
|
13
|
+
/** Remove the record only if it is still ours: a newer door may have replaced it. */
|
|
14
|
+
export declare function clearDoorRecord(kernel: string, pid: number): Promise<void>;
|
|
15
|
+
export declare function pidAlive(pid: number): boolean;
|
|
16
|
+
export type DoorProbe = {
|
|
17
|
+
readonly alive: (pid: number) => boolean;
|
|
18
|
+
readonly answers: (url: string) => Promise<boolean>;
|
|
19
|
+
};
|
|
20
|
+
export declare const realProbe: DoorProbe;
|
|
21
|
+
/** The recorded door when its process is alive and its URL answers; otherwise undefined. */
|
|
22
|
+
export declare function liveDoor(kernel: string, probe?: DoorProbe): Promise<DoorRecord | undefined>;
|
|
23
|
+
/** Spawn `inhuman web-door` detached and wait until it has recorded itself and answers. */
|
|
24
|
+
export declare function startDoor(kernel: string, port: number): Promise<DoorRecord>;
|
|
25
|
+
//# sourceMappingURL=web-door.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-door.d.ts","sourceRoot":"","sources":["../../src/cli/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5G;AAID,2FAA2F;AAC3F,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CA4BjF"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web door: a detached `inhuman web-door` process that serves the built client on loopback and
|
|
3
|
+
* proxies rooms to the daemon socket. `inhuman start` and `inhuman web` start one when none is live and leaves it running.
|
|
4
|
+
* The door records itself in `<kernel>/web.json`, logs to `<kernel>/web.log`, and leaves when the
|
|
5
|
+
* daemon has been gone for a few probes, so nothing is left behind after `inhuman daemon stop`.
|
|
6
|
+
*/
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { closeSync, openSync } from "node:fs";
|
|
9
|
+
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
export const DOOR_PROBE_MS = 2000;
|
|
13
|
+
export const DOOR_MISSES_TO_LEAVE = 3;
|
|
14
|
+
export function doorRecordPath(kernel) {
|
|
15
|
+
return join(kernel, "web.json");
|
|
16
|
+
}
|
|
17
|
+
export function doorLogPath(kernel) {
|
|
18
|
+
return join(kernel, "web.log");
|
|
19
|
+
}
|
|
20
|
+
export function parseDoorRecord(text) {
|
|
21
|
+
try {
|
|
22
|
+
const value = JSON.parse(text);
|
|
23
|
+
if (typeof value !== "object" || value === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
const { pid, port, url } = value;
|
|
26
|
+
if (typeof pid !== "number" || typeof port !== "number" || typeof url !== "string")
|
|
27
|
+
return undefined;
|
|
28
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
29
|
+
return undefined;
|
|
30
|
+
return { pid, port, url };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function readDoorRecord(kernel) {
|
|
37
|
+
try {
|
|
38
|
+
return parseDoorRecord(await readFile(doorRecordPath(kernel), "utf8"));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function writeDoorRecord(kernel, record) {
|
|
45
|
+
await writeFile(doorRecordPath(kernel), `${JSON.stringify(record)}\n`);
|
|
46
|
+
}
|
|
47
|
+
/** Remove the record only if it is still ours: a newer door may have replaced it. */
|
|
48
|
+
export async function clearDoorRecord(kernel, pid) {
|
|
49
|
+
const current = await readDoorRecord(kernel);
|
|
50
|
+
if (current?.pid === pid)
|
|
51
|
+
await rm(doorRecordPath(kernel), { force: true });
|
|
52
|
+
}
|
|
53
|
+
export function pidAlive(pid) {
|
|
54
|
+
try {
|
|
55
|
+
process.kill(pid, 0);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return error.code === "EPERM";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const realProbe = {
|
|
63
|
+
alive: pidAlive,
|
|
64
|
+
answers: async (url) => {
|
|
65
|
+
try {
|
|
66
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(1500) });
|
|
67
|
+
await response.body?.cancel();
|
|
68
|
+
return response.ok;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
/** The recorded door when its process is alive and its URL answers; otherwise undefined. */
|
|
76
|
+
export async function liveDoor(kernel, probe = realProbe) {
|
|
77
|
+
const record = await readDoorRecord(kernel);
|
|
78
|
+
if (record === undefined || !probe.alive(record.pid))
|
|
79
|
+
return undefined;
|
|
80
|
+
return (await probe.answers(record.url)) ? record : undefined;
|
|
81
|
+
}
|
|
82
|
+
const START_TIMEOUT_MS = 15_000;
|
|
83
|
+
/** Spawn `inhuman web-door` detached and wait until it has recorded itself and answers. */
|
|
84
|
+
export async function startDoor(kernel, port) {
|
|
85
|
+
const entry = fileURLToPath(new URL("../bin.js", import.meta.url));
|
|
86
|
+
const log = openSync(doorLogPath(kernel), "a");
|
|
87
|
+
let exited = null;
|
|
88
|
+
let child;
|
|
89
|
+
try {
|
|
90
|
+
child = spawn(process.execPath, [entry, "web-door", "--kernel", kernel, "--port", String(port)], {
|
|
91
|
+
detached: true,
|
|
92
|
+
stdio: ["ignore", log, log],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
closeSync(log);
|
|
97
|
+
}
|
|
98
|
+
child.once("exit", (code) => {
|
|
99
|
+
exited = code ?? 1;
|
|
100
|
+
});
|
|
101
|
+
child.once("error", () => {
|
|
102
|
+
exited = 1;
|
|
103
|
+
});
|
|
104
|
+
child.unref();
|
|
105
|
+
const deadline = Date.now() + START_TIMEOUT_MS;
|
|
106
|
+
while (Date.now() < deadline) {
|
|
107
|
+
if (exited !== null)
|
|
108
|
+
throw new Error(`web door exited ${exited} before it listened (see ${doorLogPath(kernel)})`);
|
|
109
|
+
const record = await readDoorRecord(kernel);
|
|
110
|
+
if (record !== undefined && record.pid === child.pid && (await realProbe.answers(record.url)))
|
|
111
|
+
return record;
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`web door did not come up in time (see ${doorLogPath(kernel)})`);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=web-door.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-door.js","sourceRoot":"","sources":["../../src/cli/web-door.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,IAA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C,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;QACvB,MAAM,GAAG,CAAC,CAAC;IACb,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC;IAC/C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,4BAA4B,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClH,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,MAAM,CAAC;QAC7G,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Read by the daemon (`kernel/remote-http.ts`): where the web app's built client lives. */
|
|
2
|
+
export declare const WEB_STATIC_DIR_ENV = "HARNESS_WEB_STATIC_DIR";
|
|
3
|
+
/**
|
|
4
|
+
* The daemon does not depend on the web app, so a daemon this CLI spawns learns the built client's
|
|
5
|
+
* directory through its environment. A daemon that is already running keeps what it was started with.
|
|
6
|
+
*/
|
|
7
|
+
export declare function exportWebStaticDir(env?: NodeJS.ProcessEnv): void;
|
|
8
|
+
//# sourceMappingURL=web-static.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-static.d.ts","sourceRoot":"","sources":["../../src/cli/web-static.ts"],"names":[],"mappings":"AAIA,4FAA4F;AAC5F,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,IAAI,CAS7E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/** Read by the daemon (`kernel/remote-http.ts`): where the web app's built client lives. */
|
|
5
|
+
export const WEB_STATIC_DIR_ENV = "HARNESS_WEB_STATIC_DIR";
|
|
6
|
+
/**
|
|
7
|
+
* The daemon does not depend on the web app, so a daemon this CLI spawns learns the built client's
|
|
8
|
+
* directory through its environment. A daemon that is already running keeps what it was started with.
|
|
9
|
+
*/
|
|
10
|
+
export function exportWebStaticDir(env = process.env) {
|
|
11
|
+
if ((env[WEB_STATIC_DIR_ENV] ?? "").trim() !== "")
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
const root = dirname(fileURLToPath(import.meta.resolve("@inhuman.tools/harness-web-app/package.json")));
|
|
15
|
+
const dir = join(root, "dist/client");
|
|
16
|
+
if (existsSync(join(dir, "index.html")))
|
|
17
|
+
env[WEB_STATIC_DIR_ENV] = dir;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// The web app is not installed; /app/* will answer 404 with a reason.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=web-static.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-static.js","sourceRoot":"","sources":["../../src/cli/web-static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACrE,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO;IAC1D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,6CAA6C,CAAC,CAAC,CAAC,CAAC;QACxG,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACtC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YAAE,GAAG,CAAC,kBAAkB,CAAC,GAAG,GAAG,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,sEAAsE;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eval stderr face for a running program bag. Notifications and bag-child
|
|
3
|
+
* completions are origin atoms on the bag; the ReACT tape does not list them.
|
|
4
|
+
* Completions never dump responseText (that is the IR).
|
|
5
|
+
*/
|
|
6
|
+
import { ProgrammaticJob } from "@inhuman.tools/harness-model";
|
|
7
|
+
export declare function visitEvalProgress(program: ProgrammaticJob, emit: (id: string, line: string) => void): void;
|
|
8
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/eval/progress.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAGL,eAAe,EAEhB,MAAM,8BAA8B,CAAC;AAItC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAM1G"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eval stderr face for a running program bag. Notifications and bag-child
|
|
3
|
+
* completions are origin atoms on the bag; the ReACT tape does not list them.
|
|
4
|
+
* Completions never dump responseText (that is the IR).
|
|
5
|
+
*/
|
|
6
|
+
import { tapeCompletion, } from "@inhuman.tools/harness-model";
|
|
7
|
+
const STATUS_CAP = 80;
|
|
8
|
+
export function visitEvalProgress(program, emit) {
|
|
9
|
+
for (const [index, note] of program.notifications.entries())
|
|
10
|
+
emitNote(note, `note:${index}`, emit);
|
|
11
|
+
for (const [index, child] of program.children.entries()) {
|
|
12
|
+
const pew = tapeCompletion(child);
|
|
13
|
+
if (pew != null)
|
|
14
|
+
emitPew(pew, `pew:${index}`, emit);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function emitNote(note, fallbackId, emit) {
|
|
18
|
+
const text = note.message.trim();
|
|
19
|
+
if (text === "")
|
|
20
|
+
return;
|
|
21
|
+
emit(stableId(note, fallbackId), ` ${text}`);
|
|
22
|
+
}
|
|
23
|
+
function emitPew(chunk, fallbackId, emit) {
|
|
24
|
+
const name = chunk.model.trim() !== "" ? chunk.model.trim() : "completion";
|
|
25
|
+
const id = stableId(chunk, fallbackId);
|
|
26
|
+
if (!chunk.isDone) {
|
|
27
|
+
emit(`${id}:live`, ` ${name} live`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
emit(`${id}:done`, ` ${name} ${pewStatus(chunk)}`);
|
|
31
|
+
}
|
|
32
|
+
function stableId(node, fallback) {
|
|
33
|
+
try {
|
|
34
|
+
const id = node.uuid;
|
|
35
|
+
if (typeof id === "string" && id !== "")
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
/* PLEXUS_UUID: unmaterialized Yjs accessor throws */
|
|
40
|
+
}
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
function pewStatus(chunk) {
|
|
44
|
+
if (chunk.outcome === "failed") {
|
|
45
|
+
const picked = chunk.failReason ?? chunk.endDetail ?? "failed";
|
|
46
|
+
return clampStatus(picked.trim().replaceAll(/\s+/g, " "));
|
|
47
|
+
}
|
|
48
|
+
const ms = chunk.durationMs();
|
|
49
|
+
if (ms == null)
|
|
50
|
+
return "done";
|
|
51
|
+
if (ms < 1000)
|
|
52
|
+
return `${ms}ms`;
|
|
53
|
+
const seconds = ms / 1000;
|
|
54
|
+
if (seconds < 10)
|
|
55
|
+
return `${seconds.toFixed(1)}s`;
|
|
56
|
+
return `${Math.round(seconds)}s`;
|
|
57
|
+
}
|
|
58
|
+
function clampStatus(text) {
|
|
59
|
+
const points = [...text];
|
|
60
|
+
if (points.length <= STATUS_CAP)
|
|
61
|
+
return text;
|
|
62
|
+
return `${points.slice(0, STATUS_CAP - 1).join("")}…`;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.js","sourceRoot":"","sources":["../../src/eval/progress.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAIL,cAAc,GACf,MAAM,8BAA8B,CAAC;AAEtC,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,MAAM,UAAU,iBAAiB,CAAC,OAAwB,EAAE,IAAwC;IAClG,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;IACnG,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QACxD,MAAM,GAAG,GAAG,cAAc,CAAC,KAAK,CAAC,C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AS,SAAS,CAAC,KAA4B;IAC7C,IAAI,KAAK,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,SAAS,IAAI,QAAQ,CAAC;QAC/D,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IAC9B,IAAI,EAAE,IAAI,IAAI;QAAE,OAAO,MAAM,CAAC;IAC9B,IAAI,EAAE,GAAG,IAAI;QAAE,OAAO,GAAG,EAAE,IAAI,CAAC;IAChC,MAAM,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC;IAC1B,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAClD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACzB,IAAI,MAAM,CAAC,MAAM,IAAI,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type EvalPermissionMode } from "@inhuman.tools/harness-model";
|
|
2
|
+
import { type CliAgentFlags, type ShellStreams } from "@inhuman.tools/harness-sdk/launch";
|
|
3
|
+
export type EvalPrintFormat = "scheme" | "json";
|
|
4
|
+
export type EvalRunOpts = {
|
|
5
|
+
readonly kernel: string;
|
|
6
|
+
readonly project: string;
|
|
7
|
+
readonly expr: string;
|
|
8
|
+
readonly source?: string;
|
|
9
|
+
readonly sourcePath?: string;
|
|
10
|
+
readonly policy: EvalPermissionMode;
|
|
11
|
+
readonly format: EvalPrintFormat;
|
|
12
|
+
readonly agent?: CliAgentFlags;
|
|
13
|
+
readonly streams: ShellStreams;
|
|
14
|
+
/** Start or attach the daemon. The launcher owns that; the shell only asks. */
|
|
15
|
+
readonly ensure: (kernel: string, options?: {
|
|
16
|
+
readonly restart?: boolean;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
export declare function runEval(opts: EvalRunOpts): Promise<number>;
|
|
20
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/eval/run.ts"],"names":[],"mappings":"AAQA,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,mCAAmC,CAAC;AAM3C,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9F,CAAC;AAEF,wBAAsB,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAqNhE"}
|