humanish 0.0.1 → 0.15.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/AGENTS.md +77 -0
- package/CONTRIBUTING.md +39 -0
- package/LICENSE +21 -0
- package/README.md +435 -8
- package/SECURITY.md +34 -0
- package/dist/actor-contract.d.ts +107 -0
- package/dist/actor-contract.js +286 -0
- package/dist/actor-contract.js.map +1 -0
- package/dist/actor-registry.d.ts +73 -0
- package/dist/actor-registry.js +93 -0
- package/dist/actor-registry.js.map +1 -0
- package/dist/adapter-extension.d.ts +54 -0
- package/dist/adapter-extension.js +214 -0
- package/dist/adapter-extension.js.map +1 -0
- package/dist/argv.d.ts +1 -0
- package/dist/argv.js +8 -0
- package/dist/argv.js.map +1 -0
- package/dist/artifact-reference.d.ts +22 -0
- package/dist/artifact-reference.js +47 -0
- package/dist/artifact-reference.js.map +1 -0
- package/dist/browser-evidence-hygiene.d.ts +7 -0
- package/dist/browser-evidence-hygiene.js +40 -0
- package/dist/browser-evidence-hygiene.js.map +1 -0
- package/dist/claude-agent-sdk.d.ts +94 -0
- package/dist/claude-agent-sdk.js +356 -0
- package/dist/claude-agent-sdk.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -0
- package/dist/codex-app-server-ui.d.ts +39 -0
- package/dist/codex-app-server-ui.js +327 -0
- package/dist/codex-app-server-ui.js.map +1 -0
- package/dist/codex-app-server.d.ts +141 -0
- package/dist/codex-app-server.js +747 -0
- package/dist/codex-app-server.js.map +1 -0
- package/dist/command-failure.d.ts +29 -0
- package/dist/command-failure.js +54 -0
- package/dist/command-failure.js.map +1 -0
- package/dist/computer-use-actor.d.ts +52 -0
- package/dist/computer-use-actor.js +48 -0
- package/dist/computer-use-actor.js.map +1 -0
- package/dist/computer-use.d.ts +232 -0
- package/dist/computer-use.js +615 -0
- package/dist/computer-use.js.map +1 -0
- package/dist/concurrency.d.ts +1 -0
- package/dist/concurrency.js +27 -0
- package/dist/concurrency.js.map +1 -0
- package/dist/concurrent-shared-world-lab.d.ts +115 -0
- package/dist/concurrent-shared-world-lab.js +1092 -0
- package/dist/concurrent-shared-world-lab.js.map +1 -0
- package/dist/core/git-state.d.ts +31 -0
- package/dist/core/git-state.js +142 -0
- package/dist/core/git-state.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/run-primitives.d.ts +66 -0
- package/dist/core/run-primitives.js +120 -0
- package/dist/core/run-primitives.js.map +1 -0
- package/dist/cua-actor-lab.d.ts +620 -0
- package/dist/cua-actor-lab.js +2834 -0
- package/dist/cua-actor-lab.js.map +1 -0
- package/dist/device-presets.d.ts +67 -0
- package/dist/device-presets.js +50 -0
- package/dist/device-presets.js.map +1 -0
- package/dist/e2b-desktop-executor.d.ts +101 -0
- package/dist/e2b-desktop-executor.js +309 -0
- package/dist/e2b-desktop-executor.js.map +1 -0
- package/dist/e2b-desktop-launch.d.ts +144 -0
- package/dist/e2b-desktop-launch.js +59 -0
- package/dist/e2b-desktop-launch.js.map +1 -0
- package/dist/e2b-detached.d.ts +53 -0
- package/dist/e2b-detached.js +130 -0
- package/dist/e2b-detached.js.map +1 -0
- package/dist/e2b-terminal-lab.d.ts +345 -0
- package/dist/e2b-terminal-lab.js +1467 -0
- package/dist/e2b-terminal-lab.js.map +1 -0
- package/dist/env-file.d.ts +14 -0
- package/dist/env-file.js +108 -0
- package/dist/env-file.js.map +1 -0
- package/dist/feedback.d.ts +51 -0
- package/dist/feedback.js +313 -0
- package/dist/feedback.js.map +1 -0
- package/dist/image-evidence.d.ts +2 -0
- package/dist/image-evidence.js +33 -0
- package/dist/image-evidence.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/init-templates.d.ts +12 -0
- package/dist/init-templates.js +369 -0
- package/dist/init-templates.js.map +1 -0
- package/dist/init.d.ts +26 -0
- package/dist/init.js +343 -0
- package/dist/init.js.map +1 -0
- package/dist/lab-app-runner.d.ts +78 -0
- package/dist/lab-app-runner.js +403 -0
- package/dist/lab-app-runner.js.map +1 -0
- package/dist/lab-config.d.ts +578 -0
- package/dist/lab-config.js +1751 -0
- package/dist/lab-config.js.map +1 -0
- package/dist/lab-engine.d.ts +77 -0
- package/dist/lab-engine.js +216 -0
- package/dist/lab-engine.js.map +1 -0
- package/dist/lab-preflight.d.ts +67 -0
- package/dist/lab-preflight.js +385 -0
- package/dist/lab-preflight.js.map +1 -0
- package/dist/labs.d.ts +53 -0
- package/dist/labs.js +176 -0
- package/dist/labs.js.map +1 -0
- package/dist/observer-assets.d.ts +2 -0
- package/dist/observer-assets.js +2630 -0
- package/dist/observer-assets.js.map +1 -0
- package/dist/observer-data.d.ts +63 -0
- package/dist/observer-data.js +145 -0
- package/dist/observer-data.js.map +1 -0
- package/dist/observer-static.d.ts +39 -0
- package/dist/observer-static.js +192 -0
- package/dist/observer-static.js.map +1 -0
- package/dist/observer.d.ts +46 -0
- package/dist/observer.js +353 -0
- package/dist/observer.js.map +1 -0
- package/dist/openai-responses-cu.d.ts +113 -0
- package/dist/openai-responses-cu.js +531 -0
- package/dist/openai-responses-cu.js.map +1 -0
- package/dist/oss-lab.d.ts +52 -0
- package/dist/oss-lab.js +299 -0
- package/dist/oss-lab.js.map +1 -0
- package/dist/oss-meta-lab-scoring.d.ts +15 -0
- package/dist/oss-meta-lab-scoring.js +145 -0
- package/dist/oss-meta-lab-scoring.js.map +1 -0
- package/dist/oss-meta-lab.d.ts +279 -0
- package/dist/oss-meta-lab.js +4889 -0
- package/dist/oss-meta-lab.js.map +1 -0
- package/dist/oss-remote-telemetry.d.ts +77 -0
- package/dist/oss-remote-telemetry.js +403 -0
- package/dist/oss-remote-telemetry.js.map +1 -0
- package/dist/persona.d.ts +35 -0
- package/dist/persona.js +133 -0
- package/dist/persona.js.map +1 -0
- package/dist/pi-agent-core.d.ts +77 -0
- package/dist/pi-agent-core.js +203 -0
- package/dist/pi-agent-core.js.map +1 -0
- package/dist/program.d.ts +54 -0
- package/dist/program.js +2347 -0
- package/dist/program.js.map +1 -0
- package/dist/redaction.d.ts +90 -0
- package/dist/redaction.js +292 -0
- package/dist/redaction.js.map +1 -0
- package/dist/run.d.ts +784 -0
- package/dist/run.js +4555 -0
- package/dist/run.js.map +1 -0
- package/dist/scripted-browser-actor.d.ts +294 -0
- package/dist/scripted-browser-actor.js +1286 -0
- package/dist/scripted-browser-actor.js.map +1 -0
- package/dist/scripted-browser-lab.d.ts +107 -0
- package/dist/scripted-browser-lab.js +738 -0
- package/dist/scripted-browser-lab.js.map +1 -0
- package/dist/shared-world-lab.d.ts +208 -0
- package/dist/shared-world-lab.js +1048 -0
- package/dist/shared-world-lab.js.map +1 -0
- package/dist/source-archive.d.ts +82 -0
- package/dist/source-archive.js +365 -0
- package/dist/source-archive.js.map +1 -0
- package/dist/stop-conditions.d.ts +26 -0
- package/dist/stop-conditions.js +66 -0
- package/dist/stop-conditions.js.map +1 -0
- package/dist/terminal-agent-actor.d.ts +36 -0
- package/dist/terminal-agent-actor.js +23 -0
- package/dist/terminal-agent-actor.js.map +1 -0
- package/docs/architecture/actor-contract.md +431 -0
- package/docs/architecture/github-feedback-loop.md +189 -0
- package/docs/architecture/local-codex-tui-actor.md +213 -0
- package/docs/architecture/observer.md +118 -0
- package/docs/architecture/oss-lab-poc.md +242 -0
- package/docs/architecture/project-layout.md +166 -0
- package/docs/architecture/state-driven-executor.md +203 -0
- package/docs/architecture/terminal-product-lane.md +148 -0
- package/docs/contracts/adapter-fixtures.md +80 -0
- package/docs/contracts/core.md +71 -0
- package/docs/contracts/feedback.md +145 -0
- package/docs/contracts/policy.md +305 -0
- package/docs/contracts/run-bundle.md +358 -0
- package/docs/contracts/schemas.md +984 -0
- package/docs/goals/current.md +409 -0
- package/docs/principles/invariants-and-defaults.md +135 -0
- package/docs/principles/self-driving-harness.md +129 -0
- package/docs/product/open-source-install-experience.md +229 -0
- package/docs/ramp/README.md +200 -0
- package/docs/release/open-source-readiness.md +208 -0
- package/docs/release/public-readiness-standard.md +205 -0
- package/docs/roadmap/world-class-open-source-v0.md +311 -0
- package/package.json +102 -8
- package/skills/humanish/SKILL.md +244 -0
- package/skills/humanish/agents/openai.yaml +7 -0
- package/index.js +0 -1
package/dist/observer.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { buildObserverData } from "./observer-data.js";
|
|
7
|
+
import { observerClientJs, observerCss } from "./observer-assets.js";
|
|
8
|
+
import { listRuns, loadRunBundle, verifyRun } from "./run.js";
|
|
9
|
+
export const OBSERVER_SCHEMA = "humanish.observer-result.v1";
|
|
10
|
+
const observerRuntimeStreamUrls = new WeakMap();
|
|
11
|
+
export function attachObserverRuntimeStreamUrls(result, streams) {
|
|
12
|
+
observerRuntimeStreamUrls.set(result, streams.filter((stream) => stream.streamId && stream.url));
|
|
13
|
+
}
|
|
14
|
+
export async function renderObserver(cwdInput, runInput, options = {}) {
|
|
15
|
+
const cwd = path.resolve(cwdInput);
|
|
16
|
+
const verified = await verifyRun(cwd, runInput);
|
|
17
|
+
if (!verified.ok) {
|
|
18
|
+
return {
|
|
19
|
+
schema: OBSERVER_SCHEMA,
|
|
20
|
+
ok: false,
|
|
21
|
+
cwd,
|
|
22
|
+
run: runInput,
|
|
23
|
+
warnings: [],
|
|
24
|
+
error: {
|
|
25
|
+
code: verified.error?.code === "HUMANISH_RUN_NOT_FOUND" ? "HUMANISH_RUN_NOT_FOUND" : "HUMANISH_INVALID_RUN_BUNDLE",
|
|
26
|
+
message: verified.error?.message ?? "Run bundle failed verification."
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const loaded = await loadRunBundle(cwd, runInput);
|
|
31
|
+
if (!loaded) {
|
|
32
|
+
return {
|
|
33
|
+
schema: OBSERVER_SCHEMA,
|
|
34
|
+
ok: false,
|
|
35
|
+
cwd,
|
|
36
|
+
run: runInput,
|
|
37
|
+
warnings: [],
|
|
38
|
+
error: {
|
|
39
|
+
code: "HUMANISH_RUN_NOT_FOUND",
|
|
40
|
+
message: `Run not found: ${runInput}`
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const observerDir = path.join(loaded.runDir, "observer");
|
|
45
|
+
const observerPath = path.join(observerDir, "index.html");
|
|
46
|
+
const observerDataPath = path.join(observerDir, "observer-data.json");
|
|
47
|
+
const eventsPath = path.join(loaded.runDir, "events.ndjson");
|
|
48
|
+
const observerData = buildObserverData(loaded.bundle);
|
|
49
|
+
await mkdir(observerDir, { recursive: true });
|
|
50
|
+
await writeJson(observerDataPath, observerData);
|
|
51
|
+
await writeFile(observerPath, renderObserverHtml(observerData), "utf8");
|
|
52
|
+
const relativeObserverPath = path.relative(cwd, observerPath);
|
|
53
|
+
const observerUrl = pathToFileURL(observerPath).href;
|
|
54
|
+
const openResult = options.open === true ? openTarget(observerPath) : { opened: false };
|
|
55
|
+
return {
|
|
56
|
+
schema: OBSERVER_SCHEMA,
|
|
57
|
+
ok: true,
|
|
58
|
+
cwd,
|
|
59
|
+
run: loaded.bundle.runId,
|
|
60
|
+
observerPath: relativeObserverPath,
|
|
61
|
+
observerDataPath: path.relative(cwd, observerDataPath),
|
|
62
|
+
eventsPath: path.relative(cwd, eventsPath),
|
|
63
|
+
observerUrl,
|
|
64
|
+
bundlePath: loaded.bundlePath,
|
|
65
|
+
opened: openResult.opened,
|
|
66
|
+
...(openResult.command ? { openCommand: openResult.command } : {}),
|
|
67
|
+
warnings: [
|
|
68
|
+
loaded.bundle.mode === "live"
|
|
69
|
+
? "Observer renders verified local evidence artifacts; runtime stream auth URLs are not persisted."
|
|
70
|
+
: "Observer renders local contract evidence only; dry-run lanes do not claim product behavior proof.",
|
|
71
|
+
"Before filing public feedback, use `humanish feedback issue` so redaction and public-safety checks gate the payload.",
|
|
72
|
+
...(openResult.warning ? [openResult.warning] : [])
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export async function serveObserver(result, options = {}) {
|
|
77
|
+
if (!result.ok || !result.observerPath) {
|
|
78
|
+
throw new Error("Cannot serve an observer result that did not render successfully.");
|
|
79
|
+
}
|
|
80
|
+
const cwd = path.resolve(result.cwd);
|
|
81
|
+
const observerPath = path.join(cwd, result.observerPath);
|
|
82
|
+
const runRoot = path.dirname(path.dirname(observerPath));
|
|
83
|
+
const proofRoot = path.dirname(runRoot);
|
|
84
|
+
const runtimeStreamUrls = () => observerRuntimeStreamUrls.get(result) ?? [];
|
|
85
|
+
const server = createServer(async (request, response) => {
|
|
86
|
+
try {
|
|
87
|
+
const url = new URL(request.url ?? "/", `http://${request.headers.host ?? "127.0.0.1"}`);
|
|
88
|
+
if (url.pathname === "/") {
|
|
89
|
+
response.writeHead(302, { location: "/observer/index.html" });
|
|
90
|
+
response.end();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (url.pathname === "/_humanish/history.json") {
|
|
94
|
+
const history = await buildHistoryIndex(cwd);
|
|
95
|
+
writeResponse(response, 200, JSON.stringify(history, null, 2), "application/json; charset=utf-8");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const runRoute = matchRunRoute(url.pathname);
|
|
99
|
+
if (runRoute) {
|
|
100
|
+
const targetRoot = path.join(proofRoot, runRoute.runId);
|
|
101
|
+
await serveRunPath(targetRoot, runRoute.relativePath || "observer/index.html", response, runtimeStreamUrls());
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
await serveRunPath(runRoot, decodeURIComponent(url.pathname.slice(1)), response, runtimeStreamUrls());
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
writeResponse(response, 500, error instanceof Error ? error.message : String(error), "text/plain; charset=utf-8");
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const port = await listen(server, options.port ?? 0);
|
|
111
|
+
const url = `http://127.0.0.1:${port}/observer/index.html`;
|
|
112
|
+
const openResult = options.open === true ? openTarget(url) : { opened: false };
|
|
113
|
+
return {
|
|
114
|
+
url,
|
|
115
|
+
opened: openResult.opened,
|
|
116
|
+
...(openResult.command ? { openCommand: openResult.command } : {}),
|
|
117
|
+
...(openResult.warning ? { warning: openResult.warning } : {}),
|
|
118
|
+
close: () => closeServer(server)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function renderObserverHtml(data) {
|
|
122
|
+
return `<!doctype html>
|
|
123
|
+
<html lang="en" data-theme="dark">
|
|
124
|
+
<head>
|
|
125
|
+
<meta charset="utf-8">
|
|
126
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
127
|
+
<title>Humanish Observer - ${escapeHtml(data.run.runId)}</title>
|
|
128
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
129
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
130
|
+
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;450;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
131
|
+
<style>${observerCss()}</style>
|
|
132
|
+
</head>
|
|
133
|
+
<body>
|
|
134
|
+
<div class="app" id="app" aria-label="Humanish Observer mission control">
|
|
135
|
+
<div class="boot" id="boot" aria-hidden="true"></div>
|
|
136
|
+
</div>
|
|
137
|
+
<noscript>This Observer renders local run evidence with JavaScript. Inspect the run bundle directly at <code>../run.json</code>.</noscript>
|
|
138
|
+
<script id="observer-data" type="application/json">${escapeJsonScript(data)}</script>
|
|
139
|
+
<script>${observerClientJs()}</script>
|
|
140
|
+
</body>
|
|
141
|
+
</html>
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
async function serveRunPath(runRoot, relativePath, response, runtimeStreamUrls = []) {
|
|
145
|
+
const root = path.resolve(runRoot);
|
|
146
|
+
const cleanedRelativePath = relativePath === "" ? "observer/index.html" : relativePath;
|
|
147
|
+
const filePath = path.resolve(root, cleanedRelativePath);
|
|
148
|
+
if (!isPathInside(root, filePath)) {
|
|
149
|
+
writeResponse(response, 403, "Forbidden", "text/plain; charset=utf-8");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (cleanedRelativePath === "observer/index.html") {
|
|
153
|
+
const observerData = await readObserverData(root, runtimeStreamUrls);
|
|
154
|
+
if (!observerData) {
|
|
155
|
+
writeResponse(response, 404, "Observer data not found", "text/plain; charset=utf-8");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
writeResponse(response, 200, renderObserverHtml(observerData), "text/html; charset=utf-8");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (cleanedRelativePath === "observer/observer-data.json") {
|
|
162
|
+
const observerData = await readObserverData(root, runtimeStreamUrls);
|
|
163
|
+
if (!observerData) {
|
|
164
|
+
writeResponse(response, 404, "Observer data not found", "text/plain; charset=utf-8");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
writeResponse(response, 200, JSON.stringify(observerData, null, 2), "application/json; charset=utf-8");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const body = await readFile(filePath);
|
|
172
|
+
response.writeHead(200, {
|
|
173
|
+
"cache-control": "no-store",
|
|
174
|
+
"content-type": contentTypeForPath(filePath)
|
|
175
|
+
});
|
|
176
|
+
response.end(body);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
writeResponse(response, 404, "Not found", "text/plain; charset=utf-8");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function readObserverData(runRoot, runtimeStreamUrls = []) {
|
|
183
|
+
// Best-effort load from either source. Both reads swallow all errors on
|
|
184
|
+
// purpose: this runs on every browser poll of a live run, where run.json may
|
|
185
|
+
// be absent, still being written (a partial-JSON parse error), or superseded
|
|
186
|
+
// by observer-data.json. A transient failure just falls through to the next
|
|
187
|
+
// source, or to null -> a 404 the poller retries; it must not surface a 500.
|
|
188
|
+
try {
|
|
189
|
+
const bundle = JSON.parse(await readFile(path.join(runRoot, "run.json"), "utf8"));
|
|
190
|
+
return withRuntimeStreamUrls(buildObserverData(bundle), runtimeStreamUrls);
|
|
191
|
+
}
|
|
192
|
+
catch { }
|
|
193
|
+
try {
|
|
194
|
+
return withRuntimeStreamUrls(JSON.parse(await readFile(path.join(runRoot, "observer", "observer-data.json"), "utf8")), runtimeStreamUrls);
|
|
195
|
+
}
|
|
196
|
+
catch { }
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
function withRuntimeStreamUrls(data, runtimeStreamUrls) {
|
|
200
|
+
if (runtimeStreamUrls.length === 0) {
|
|
201
|
+
return data;
|
|
202
|
+
}
|
|
203
|
+
const urlsByStream = new Map(runtimeStreamUrls.map((stream) => [stream.streamId, stream.url]));
|
|
204
|
+
return {
|
|
205
|
+
...data,
|
|
206
|
+
streams: data.streams.map((stream) => {
|
|
207
|
+
const runtimeUrl = urlsByStream.get(stream.id);
|
|
208
|
+
if (!runtimeUrl) {
|
|
209
|
+
return stream;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
...stream,
|
|
213
|
+
embed: {
|
|
214
|
+
...(stream.embed ?? { title: stream.label }),
|
|
215
|
+
kind: "iframe",
|
|
216
|
+
url: runtimeUrl
|
|
217
|
+
},
|
|
218
|
+
transport: "sse",
|
|
219
|
+
url: runtimeUrl
|
|
220
|
+
};
|
|
221
|
+
})
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
async function buildHistoryIndex(cwd) {
|
|
225
|
+
const listed = await listRuns(cwd);
|
|
226
|
+
const runs = await Promise.all(listed.runs.slice(0, 80).map(async (run) => {
|
|
227
|
+
const root = path.join(cwd, run.path);
|
|
228
|
+
const data = await readObserverData(root);
|
|
229
|
+
return {
|
|
230
|
+
runId: run.runId,
|
|
231
|
+
createdAt: run.createdAt,
|
|
232
|
+
mode: run.mode,
|
|
233
|
+
href: `/_humanish/runs/${encodeURIComponent(run.runId)}/observer/index.html`,
|
|
234
|
+
status: data?.run.status ?? "unknown",
|
|
235
|
+
streamCount: data?.streams.length ?? 0
|
|
236
|
+
};
|
|
237
|
+
}));
|
|
238
|
+
return { latestRunId: listed.latest, runs };
|
|
239
|
+
}
|
|
240
|
+
function matchRunRoute(pathname) {
|
|
241
|
+
const match = pathname.match(/^\/_humanish\/runs\/([^/]+)(?:\/(.*))?$/);
|
|
242
|
+
if (!match)
|
|
243
|
+
return null;
|
|
244
|
+
return {
|
|
245
|
+
runId: decodeURIComponent(match[1] ?? ""),
|
|
246
|
+
relativePath: decodeURIComponent(match[2] || "observer/index.html")
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function writeJson(filePath, value) {
|
|
250
|
+
return writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
251
|
+
}
|
|
252
|
+
function writeResponse(response, status, body, contentType) {
|
|
253
|
+
response.writeHead(status, {
|
|
254
|
+
"cache-control": "no-store",
|
|
255
|
+
"content-type": contentType
|
|
256
|
+
});
|
|
257
|
+
response.end(body);
|
|
258
|
+
}
|
|
259
|
+
function contentTypeForPath(filePath) {
|
|
260
|
+
switch (path.extname(filePath)) {
|
|
261
|
+
case ".html":
|
|
262
|
+
return "text/html; charset=utf-8";
|
|
263
|
+
case ".json":
|
|
264
|
+
return "application/json; charset=utf-8";
|
|
265
|
+
case ".md":
|
|
266
|
+
return "text/markdown; charset=utf-8";
|
|
267
|
+
case ".ndjson":
|
|
268
|
+
return "application/x-ndjson; charset=utf-8";
|
|
269
|
+
case ".png":
|
|
270
|
+
return "image/png";
|
|
271
|
+
case ".jpg":
|
|
272
|
+
case ".jpeg":
|
|
273
|
+
return "image/jpeg";
|
|
274
|
+
case ".webp":
|
|
275
|
+
return "image/webp";
|
|
276
|
+
default:
|
|
277
|
+
return "text/plain; charset=utf-8";
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
export function openTarget(target) {
|
|
281
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
282
|
+
const args = process.platform === "win32" ? ["/c", "start", "", target] : [target];
|
|
283
|
+
try {
|
|
284
|
+
const child = spawn(command, args, {
|
|
285
|
+
detached: true,
|
|
286
|
+
stdio: "ignore"
|
|
287
|
+
});
|
|
288
|
+
child.unref();
|
|
289
|
+
return { opened: true, command: [command, ...args].join(" ") };
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
return {
|
|
293
|
+
opened: false,
|
|
294
|
+
command: [command, ...args].join(" "),
|
|
295
|
+
warning: `Could not open observer automatically: ${error instanceof Error ? error.message : String(error)}`
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function listen(server, port) {
|
|
300
|
+
return new Promise((resolve, reject) => {
|
|
301
|
+
server.once("error", reject);
|
|
302
|
+
server.listen(port, "127.0.0.1", () => {
|
|
303
|
+
server.off("error", reject);
|
|
304
|
+
const address = server.address();
|
|
305
|
+
if (!address || typeof address === "string") {
|
|
306
|
+
reject(new Error("Observer server did not bind to a TCP port."));
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
resolve(address.port);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function closeServer(server) {
|
|
314
|
+
return new Promise((resolve, reject) => {
|
|
315
|
+
server.close((error) => {
|
|
316
|
+
if (error) {
|
|
317
|
+
reject(error);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
resolve();
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function isPathInside(root, filePath) {
|
|
326
|
+
const relative = path.relative(root, filePath);
|
|
327
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
328
|
+
}
|
|
329
|
+
function escapeHtml(value) {
|
|
330
|
+
return value.replace(/[&<>"']/g, (char) => {
|
|
331
|
+
switch (char) {
|
|
332
|
+
case "&":
|
|
333
|
+
return "&";
|
|
334
|
+
case "<":
|
|
335
|
+
return "<";
|
|
336
|
+
case ">":
|
|
337
|
+
return ">";
|
|
338
|
+
case "\"":
|
|
339
|
+
return """;
|
|
340
|
+
default:
|
|
341
|
+
return "'";
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function escapeJsonScript(value) {
|
|
346
|
+
return JSON.stringify(value)
|
|
347
|
+
.replace(/</g, "\\u003c")
|
|
348
|
+
.replace(/>/g, "\\u003e")
|
|
349
|
+
.replace(/&/g, "\\u0026")
|
|
350
|
+
.replace(/\u2028/g, "\\u2028")
|
|
351
|
+
.replace(/\u2029/g, "\\u2029");
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.js","sourceRoot":"","sources":["../src/observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAoC,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9D,MAAM,CAAC,MAAM,eAAe,GAAG,6BAA6B,CAAC;AA4C7D,MAAM,yBAAyB,GAAG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C,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;QACxC,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,GAAG;gBACN,OAAO,OAAO,CAAC;YACjB,KAAK,GAAG;gBACN,OAAO,MAAM,CAAC;YAChB,KAAK,GAAG;gBACN,OAAO,MAAM,CAAC;YAChB,KAAK,IAAI;gBACP,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,OAAO,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SACzB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7B,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ActorCapabilities } from "./actor-contract.js";
|
|
2
|
+
import type { CuaAction, CuaProvider, CuaSafetyCheck, CuaTurn } from "./computer-use.js";
|
|
3
|
+
export declare const OPENAI_RESPONSES_CU_CAPABILITIES: ActorCapabilities;
|
|
4
|
+
export declare const DEFAULT_OPENAI_CU_MODEL = "gpt-5.5";
|
|
5
|
+
/**
|
|
6
|
+
* Map an OpenAI computer action object to a provider-neutral CuaAction, or null
|
|
7
|
+
* for an unknown type. Every coordinate and field is read defensively so a
|
|
8
|
+
* malformed action never throws and a non-number coordinate becomes 0.
|
|
9
|
+
*/
|
|
10
|
+
export declare function openAiActionToCua(action: unknown): CuaAction | null;
|
|
11
|
+
export interface ParsedOpenAiResponse {
|
|
12
|
+
turn: CuaTurn;
|
|
13
|
+
callIds: string[];
|
|
14
|
+
outputItems: unknown[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse a Responses API response into a provider-neutral CuaTurn plus the
|
|
18
|
+
* computer_call ids (needed to build the next turn's call outputs) and the raw
|
|
19
|
+
* output items (needed for ZDR explicit-context continuation). Pure: no network,
|
|
20
|
+
* no mutation of the input. Optional CuaTurn fields are only set when present so
|
|
21
|
+
* the result satisfies exactOptionalPropertyTypes.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseOpenAiResponse(raw: unknown): ParsedOpenAiResponse;
|
|
24
|
+
export interface OpenAiCuContext {
|
|
25
|
+
model: string;
|
|
26
|
+
instructions: string;
|
|
27
|
+
reasoningEffort: "low" | "medium" | "high";
|
|
28
|
+
safetyIdentifier?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Build the first-turn request body: instructions + an initial user text input. */
|
|
31
|
+
export declare function buildInitialRequest(ctx: OpenAiCuContext): Record<string, unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* Build one computer_call_output for a pending call id, carrying the latest
|
|
34
|
+
* screenshot as an inline data URL. Acknowledged safety checks (if any) are
|
|
35
|
+
* echoed back so the model can proceed past a check the harness approved.
|
|
36
|
+
*
|
|
37
|
+
* The screenshot param is `Buffer | undefined` because CuaObservation.screenshot is now
|
|
38
|
+
* optional (a non-vision executor omits it). This provider is a VISION model (it sets
|
|
39
|
+
* requiresFrame), so a missing frame is a hard error here — defense-in-depth: the loop's
|
|
40
|
+
* per-turn requiresFrame guard already fails closed before this is reached, but throwing keeps
|
|
41
|
+
* the mapper self-validating and isolable.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildCallOutput(callId: string, screenshot: Buffer | undefined, acknowledged?: CuaSafetyCheck[]): Record<string, unknown>;
|
|
44
|
+
export interface ContinuationRequestArgs {
|
|
45
|
+
ctx: OpenAiCuContext;
|
|
46
|
+
previousResponseId: string | undefined;
|
|
47
|
+
callOutputs: object[];
|
|
48
|
+
contextHint?: string;
|
|
49
|
+
explicitContextItems?: unknown[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build a continuation request body. Two modes:
|
|
53
|
+
* - default: thread server-side state via previous_response_id and send only the
|
|
54
|
+
* new call outputs (plus an optional hint).
|
|
55
|
+
* - explicit-context (ZDR): no previous_response_id; the prior output items are
|
|
56
|
+
* re-sent inline ahead of the new call outputs so the model has full context
|
|
57
|
+
* without the server retaining any.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildContinuationRequest(args: ContinuationRequestArgs): Record<string, unknown>;
|
|
60
|
+
/** The opt-in gate for response wire capture: a directory path, or unset for off. */
|
|
61
|
+
export declare const WIRE_CAPTURE_ENV = "HUMANISH_CUA_WIRE_CAPTURE_DIR";
|
|
62
|
+
/**
|
|
63
|
+
* Deep-copy a captured wire value with every string — object keys included —
|
|
64
|
+
* passed through the shared redactText, so a secret-shaped echo in a response
|
|
65
|
+
* can never persist to disk. Pure; non-string primitives pass through unchanged.
|
|
66
|
+
*/
|
|
67
|
+
export declare function redactWireJson(value: unknown): unknown;
|
|
68
|
+
/** Deterministic ordered capture file name for the 1-based nth provider call. */
|
|
69
|
+
export declare function wireCaptureFileName(callNumber: number): string;
|
|
70
|
+
/**
|
|
71
|
+
* The minimal slice of the fetch contract the shim depends on. Injecting this
|
|
72
|
+
* (rather than importing a fetch type) keeps the module dependency-free and lets
|
|
73
|
+
* CI tests run with a fake that never touches the network.
|
|
74
|
+
*/
|
|
75
|
+
export type FetchLike = (url: string, init: {
|
|
76
|
+
method: string;
|
|
77
|
+
headers: Record<string, string>;
|
|
78
|
+
body: string;
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}) => Promise<{
|
|
81
|
+
ok: boolean;
|
|
82
|
+
status: number;
|
|
83
|
+
text(): Promise<string>;
|
|
84
|
+
json(): Promise<unknown>;
|
|
85
|
+
}>;
|
|
86
|
+
export interface OpenAiResponsesProviderOptions {
|
|
87
|
+
apiKey: string;
|
|
88
|
+
model?: string;
|
|
89
|
+
reasoningEffort?: "low" | "medium" | "high";
|
|
90
|
+
safetyIdentifier?: string;
|
|
91
|
+
endpoint?: string;
|
|
92
|
+
fetchFn?: FetchLike;
|
|
93
|
+
maxRetries?: number;
|
|
94
|
+
delayFn?: (ms: number) => Promise<void>;
|
|
95
|
+
zeroDataRetention?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Environment for the wire-capture gate (HUMANISH_CUA_WIRE_CAPTURE_DIR — see the
|
|
98
|
+
* module header). Injectable so deterministic tests control the gate without
|
|
99
|
+
* mutating process.env. Defaults to process.env.
|
|
100
|
+
*/
|
|
101
|
+
env?: Record<string, string | undefined>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a stateful CuaProvider backed by the OpenAI Responses API. The first
|
|
105
|
+
* turn opens a session (buildInitialRequest); subsequent turns send the prior
|
|
106
|
+
* call outputs (with the latest screenshot) and thread state via
|
|
107
|
+
* previous_response_id, transparently falling back to explicit-context mode if
|
|
108
|
+
* the account rejects server-side retention. Transient HTTP failures are retried
|
|
109
|
+
* with exponential backoff. Returns ONLY a CuaTurn from nextTurn; nothing
|
|
110
|
+
* sensitive (the key, the request body, the screenshot, the raw response body)
|
|
111
|
+
* is ever returned or logged.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createOpenAiResponsesProvider(options: OpenAiResponsesProviderOptions): CuaProvider;
|