agentpath 0.0.0-stage → 0.1.0-alpha.2
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.md +105 -0
- package/README.md +101 -2
- package/THIRD_PARTY_NOTICES +12 -0
- package/apps/demo-site/dist/site.js +92 -0
- package/apps/studio/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/apps/studio/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/apps/studio/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/apps/studio/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/apps/studio/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/apps/studio/dist/assets/index-DH4wJPHm.js +67 -0
- package/apps/studio/dist/assets/index-DrnNh2ip.css +1 -0
- package/apps/studio/dist/index.html +14 -0
- package/audit.md +173 -0
- package/autonomous-mode.md +104 -0
- package/ci.md +118 -0
- package/coding-agents.md +143 -0
- package/concepts.md +145 -0
- package/contracts.md +356 -0
- package/examples/tasks/ambiguous.json +98 -0
- package/examples/tasks/assertion-failure.json +98 -0
- package/examples/tasks/broken.json +98 -0
- package/examples/tasks/fixed.json +98 -0
- package/examples/tasks/recovery.json +19 -0
- package/images/compare-recovery-desktop.jpg +0 -0
- package/images/compare-variants-desktop.jpg +0 -0
- package/images/overview-desktop.jpg +0 -0
- package/images/run-autonomous-passed-desktop.jpg +0 -0
- package/images/run-failed-desktop.jpg +0 -0
- package/images/run-failed-mobile.jpg +0 -0
- package/images/run-missing-artifact-desktop.jpg +0 -0
- package/images/task-editor-laptop.jpg +0 -0
- package/installation.md +102 -0
- package/ledger.md +62 -0
- package/licenses/-fontsource-variable-geist-mono.txt +93 -0
- package/licenses/-fontsource-variable-geist.txt +93 -0
- package/licenses/lucide-react.txt +43 -0
- package/licenses/react-dom.txt +21 -0
- package/licenses/react.txt +21 -0
- package/licenses/scheduler.txt +21 -0
- package/licenses/tailwindcss.txt +21 -0
- package/licenses/zod.txt +21 -0
- package/package.json +165 -4
- package/packages/cli/bin/agentpath.js +39 -0
- package/packages/cli/dist/audit-rerun.js +384 -0
- package/packages/cli/dist/audit.js +387 -0
- package/packages/cli/dist/change-summaries.js +87 -0
- package/packages/cli/dist/ci-report.js +88 -0
- package/packages/cli/dist/demo.js +88 -0
- package/packages/cli/dist/doctor.js +265 -0
- package/packages/cli/dist/explain.js +89 -0
- package/packages/cli/dist/git.js +7 -0
- package/packages/cli/dist/inspect.js +118 -0
- package/packages/cli/dist/ledger.js +509 -0
- package/packages/cli/dist/local.js +102 -0
- package/packages/cli/dist/main.js +708 -0
- package/packages/cli/dist/mcp.js +231 -0
- package/packages/cli/dist/paths.js +6 -0
- package/packages/cli/dist/playwright-fixture.js +185 -0
- package/packages/cli/dist/playwright-reporter.js +49 -0
- package/packages/cli/dist/tasks.js +37 -0
- package/packages/cli/dist/test-source.js +283 -0
- package/packages/cli/dist/watch.js +96 -0
- package/packages/contracts/dist/agent-settings.js +18 -0
- package/packages/contracts/dist/agent.js +175 -0
- package/packages/contracts/dist/audit.js +115 -0
- package/packages/contracts/dist/guidance.js +339 -0
- package/packages/contracts/dist/index.js +14 -0
- package/packages/contracts/dist/inspect.js +63 -0
- package/packages/contracts/dist/ledger.js +80 -0
- package/packages/contracts/dist/local.js +171 -0
- package/packages/contracts/dist/outcomes.js +94 -0
- package/packages/contracts/dist/platform.js +105 -0
- package/packages/contracts/dist/playwright-live.js +76 -0
- package/packages/contracts/dist/policy.js +93 -0
- package/packages/contracts/dist/run.js +178 -0
- package/packages/contracts/dist/task-issues.js +39 -0
- package/packages/contracts/dist/task.js +185 -0
- package/packages/contracts/dist/watch.js +57 -0
- package/packages/core/dist/action-feedback.js +103 -0
- package/packages/core/dist/actions.js +160 -0
- package/packages/core/dist/agent-loop.js +122 -0
- package/packages/core/dist/artifacts.js +156 -0
- package/packages/core/dist/assertions.js +120 -0
- package/packages/core/dist/autonomous.js +1 -0
- package/packages/core/dist/browser.js +196 -0
- package/packages/core/dist/compare.js +141 -0
- package/packages/core/dist/control-state.js +62 -0
- package/packages/core/dist/diagnostics.js +134 -0
- package/packages/core/dist/evidence-diff.js +93 -0
- package/packages/core/dist/evidence.js +203 -0
- package/packages/core/dist/index.js +22 -0
- package/packages/core/dist/inspect.js +257 -0
- package/packages/core/dist/integrity.js +176 -0
- package/packages/core/dist/liveness.js +114 -0
- package/packages/core/dist/local-files.js +61 -0
- package/packages/core/dist/locators.js +214 -0
- package/packages/core/dist/model-provider.js +88 -0
- package/packages/core/dist/observation.js +257 -0
- package/packages/core/dist/playwright-live.js +519 -0
- package/packages/core/dist/playwright-results.js +543 -0
- package/packages/core/dist/policy.js +182 -0
- package/packages/core/dist/privacy.js +93 -0
- package/packages/core/dist/recovery.js +54 -0
- package/packages/core/dist/retention.js +204 -0
- package/packages/core/dist/run-index.js +177 -0
- package/packages/core/dist/run-plan.js +28 -0
- package/packages/core/dist/run-repository.js +518 -0
- package/packages/core/dist/runner.js +913 -0
- package/packages/core/dist/storage.js +63 -0
- package/packages/core/dist/task-fingerprint.js +36 -0
- package/packages/core/dist/test-change-rerun.js +84 -0
- package/packages/core/dist/test-changes.js +896 -0
- package/packages/core/dist/timing.js +41 -0
- package/packages/core/dist/watch.js +165 -0
- package/packages/server/dist/index.js +265 -0
- package/packages/server/dist/task-store.js +103 -0
- package/quickstart.md +85 -0
- package/security.md +136 -0
- package/try-on-your-repo.md +54 -0
- package/understanding-results.md +159 -0
- package/writing-tasks.md +196 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { chromiumAvailability, runTask } from "#agentpath/core";
|
|
6
|
+
import { createDemoServer } from "#agentpath/demo-site";
|
|
7
|
+
import { studioPort } from "#agentpath/server";
|
|
8
|
+
import { closeLoopback, demoPort, errorCode, listenLoopback, portOption, sample, startStudio, startupError, waitForShutdown, withShutdown, } from "./local.js";
|
|
9
|
+
async function bind(start, port, explicit) {
|
|
10
|
+
try {
|
|
11
|
+
return await start(port);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (errorCode(error) !== "EADDRINUSE" || explicit)
|
|
15
|
+
throw error;
|
|
16
|
+
return start(0);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function demo(args) {
|
|
20
|
+
const { values } = parseArgs({ args, options: { port: { type: "string" }, "site-port": { type: "string" }, "shutdown-on-stdin-close": { type: "boolean" } } });
|
|
21
|
+
const port = portOption(values.port, studioPort);
|
|
22
|
+
const sitePort = portOption(values["site-port"], demoPort);
|
|
23
|
+
if (await chromiumAvailability() === "missing") {
|
|
24
|
+
throw new Error("Chromium is missing. Run agentpath browser install, then retry agentpath demo.");
|
|
25
|
+
}
|
|
26
|
+
return withShutdown(async (signal) => {
|
|
27
|
+
const workspace = await mkdtemp(join(tmpdir(), "agentpath-demo-")).catch(() => {
|
|
28
|
+
throw new Error("Could not create an isolated demo workspace. Check that your temporary directory is writable.");
|
|
29
|
+
});
|
|
30
|
+
const taskDirectory = join(workspace, ".agentpath", "tasks");
|
|
31
|
+
const runsDirectory = join(workspace, ".agentpath", "runs");
|
|
32
|
+
let repaired = false;
|
|
33
|
+
const site = createDemoServer({ recoveryReady: () => repaired });
|
|
34
|
+
const baseUrl = await bind((candidate) => listenLoopback(site, candidate), sitePort, values["site-port"] !== undefined)
|
|
35
|
+
.catch((error) => { throw startupError(error, "--site-port"); });
|
|
36
|
+
try {
|
|
37
|
+
const [fixed, broken, recovery, ambiguous, assertionFailure] = await Promise.all([
|
|
38
|
+
sample("fixed", baseUrl), sample("broken", baseUrl), sample("recovery", baseUrl),
|
|
39
|
+
sample("ambiguous", baseUrl), sample("assertion-failure", baseUrl),
|
|
40
|
+
]);
|
|
41
|
+
await mkdir(taskDirectory, { recursive: true, mode: 0o700 });
|
|
42
|
+
for (const task of [fixed, broken, recovery, ambiguous, assertionFailure]) {
|
|
43
|
+
await writeFile(join(taskDirectory, `${task.id}.json`), JSON.stringify(task, null, 2) + "\n", { mode: 0o600, flag: "wx" });
|
|
44
|
+
}
|
|
45
|
+
if (signal.aborted)
|
|
46
|
+
return;
|
|
47
|
+
const { server, url } = await bind((candidate) => startStudio(workspace, candidate), port, values.port !== undefined)
|
|
48
|
+
.catch((error) => { throw startupError(error); });
|
|
49
|
+
try {
|
|
50
|
+
console.log(`AgentPath Studio at ${url}\nDemo site at ${baseUrl}\nDemo workspace: ${workspace}`);
|
|
51
|
+
console.log("Recording four deterministic runs. Press Ctrl+C to stop both servers. The workspace and evidence are kept.");
|
|
52
|
+
const [passing, failing, before, after] = await (async () => {
|
|
53
|
+
const record = (task) => runTask(task, { runsDirectory, signal });
|
|
54
|
+
const outcomes = [];
|
|
55
|
+
for (const [task, expected, category] of [
|
|
56
|
+
[fixed, "passed"], [broken, "failed", "TARGET_NOT_FOUND"],
|
|
57
|
+
[recovery, "failed", "ASSERTION_FAILED"], [recovery, "passed"],
|
|
58
|
+
]) {
|
|
59
|
+
if (signal.aborted)
|
|
60
|
+
break;
|
|
61
|
+
const { result } = await record(task);
|
|
62
|
+
if (signal.aborted)
|
|
63
|
+
break;
|
|
64
|
+
if (result.status !== expected || (result.status === "failed" && result.failure.category !== category)) {
|
|
65
|
+
throw new Error(`Demo run ${result.runId} did not reach the expected outcome. Run agentpath doctor and inspect the saved run in the printed workspace.`);
|
|
66
|
+
}
|
|
67
|
+
outcomes.push(result.runId);
|
|
68
|
+
if (task === recovery)
|
|
69
|
+
repaired = true;
|
|
70
|
+
}
|
|
71
|
+
return outcomes;
|
|
72
|
+
})();
|
|
73
|
+
if (signal.aborted)
|
|
74
|
+
return;
|
|
75
|
+
console.log(`Passing cart: ${url}/#/runs/${passing}\nMissing-label evidence: ${url}/#/runs/${failing}`);
|
|
76
|
+
console.log(`Compare cart variants: ${url}/#/compare?baseline=${failing}&candidate=${passing}&mode=scenario-variants`);
|
|
77
|
+
console.log(`Compare workshop recovery: ${url}/#/compare?baseline=${before}&candidate=${after}`);
|
|
78
|
+
await waitForShutdown(signal);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await server.close();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await closeLoopback(site);
|
|
86
|
+
}
|
|
87
|
+
}, values["shutdown-on-stdin-close"]);
|
|
88
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { chromiumAvailability, RunIndex, RunRepository, runTask } from "#agentpath/core";
|
|
8
|
+
import { createDemoServer } from "#agentpath/demo-site";
|
|
9
|
+
import { studioPort } from "#agentpath/server";
|
|
10
|
+
import { checkPort, closeLoopback, errorCode, listenLoopback, portOption, sample, startStudio } from "./local.js";
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const playwright = require("playwright/package.json");
|
|
13
|
+
const { version } = require("../../../package.json");
|
|
14
|
+
const helpBrowser = "Run agentpath browser install. If launch still fails, check Playwright host libraries and Chromium sandbox support.";
|
|
15
|
+
const checksVersion = 1;
|
|
16
|
+
function check(id, status, message, resolution = "No action needed.") {
|
|
17
|
+
return { id, status, message, resolution };
|
|
18
|
+
}
|
|
19
|
+
async function browserChecks(directory) {
|
|
20
|
+
const location = await chromiumAvailability();
|
|
21
|
+
if (location === "missing") {
|
|
22
|
+
return [check("chromium-executable", "FAIL", "Playwright Chromium is missing or not executable.", "Run agentpath browser install with the same Chromium cache settings.")];
|
|
23
|
+
}
|
|
24
|
+
const checks = [check("chromium-executable", "PASS", `Chromium executable for Playwright ${playwright.version} was found.`)];
|
|
25
|
+
const site = createDemoServer();
|
|
26
|
+
try {
|
|
27
|
+
const url = await listenLoopback(site, 0);
|
|
28
|
+
const task = await sample("fixed", url);
|
|
29
|
+
const { result, directory: runDirectory } = await runTask({ ...task, browser: { runTimeoutMs: 18_000 },
|
|
30
|
+
artifacts: { screenshots: "off", accessibility: "off", trace: false } }, { runsDirectory: directory });
|
|
31
|
+
if (result.status !== "passed") {
|
|
32
|
+
checks.push(check("chromium-launch", "FAIL", "The sandboxed Chromium launch or rendered-page verification failed.", helpBrowser));
|
|
33
|
+
return checks;
|
|
34
|
+
}
|
|
35
|
+
const environment = JSON.parse(await readFile(join(runDirectory, "environment.json"), "utf8"));
|
|
36
|
+
checks.push(check("chromium-launch", "PASS", "Sandboxed Chromium launched behind the engine proxy and passed a loopback browser task."));
|
|
37
|
+
const browserVersion = environment.browserVersion;
|
|
38
|
+
if (browserVersion && /^\d+(\.\d+){1,3}$/.test(browserVersion)) {
|
|
39
|
+
checks.push(check("chromium-version", "PASS", `Playwright ${playwright.version} rendered and verified the fixture with its managed Chromium ${browserVersion}.`));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
checks.push(check("chromium-version", "WARNING", "The browser passed the smoke task but its version was unavailable.", "Reinstall the managed Chromium build with agentpath browser install."));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
checks.push(check("chromium-launch", "FAIL", "Could not complete the constrained Chromium smoke test.", helpBrowser));
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await closeLoopback(site);
|
|
50
|
+
}
|
|
51
|
+
return checks;
|
|
52
|
+
}
|
|
53
|
+
async function ensureDirectory(path) {
|
|
54
|
+
await mkdir(path, { mode: 0o700, recursive: true });
|
|
55
|
+
if (!(await lstat(path)).isDirectory())
|
|
56
|
+
throw new Error("Expected a real directory.");
|
|
57
|
+
}
|
|
58
|
+
async function workspaceChecks(workspace) {
|
|
59
|
+
const data = join(workspace, ".agentpath");
|
|
60
|
+
const runs = join(data, "runs");
|
|
61
|
+
const checks = [];
|
|
62
|
+
let probe;
|
|
63
|
+
try {
|
|
64
|
+
await ensureDirectory(workspace);
|
|
65
|
+
await ensureDirectory(data);
|
|
66
|
+
const workspaceProbe = await mkdtemp(join(data, "doctor-"));
|
|
67
|
+
await rm(workspaceProbe, { recursive: true });
|
|
68
|
+
checks.push(check("workspace", "PASS", "The workspace storage directory is writable."));
|
|
69
|
+
await ensureDirectory(runs);
|
|
70
|
+
probe = await mkdtemp(join(runs, ".doctor-"));
|
|
71
|
+
await writeFile(join(probe, "write-check"), "ok", { flag: "wx", mode: 0o600 });
|
|
72
|
+
const repository = new RunRepository(probe);
|
|
73
|
+
await repository.list();
|
|
74
|
+
checks.push(check("run-storage", "PASS", "Run storage initialized and an isolated run listing completed."));
|
|
75
|
+
try {
|
|
76
|
+
const index = await RunIndex.open(probe);
|
|
77
|
+
index?.close();
|
|
78
|
+
checks.push(index ? check("sqlite", "PASS", "The built-in SQLite run index opened.")
|
|
79
|
+
: check("sqlite", "WARNING", "SQLite is unavailable. Run listing uses a directory scan.", "Use a supported Node build with node:sqlite to enable indexing."));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
checks.push(check("sqlite", "WARNING", "The test SQLite index could not be opened. Run data is stored in directories.", "Check filesystem access. Use agentpath runs reindex if the workspace index needs rebuilding."));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const id = checks.length ? "run-storage" : "workspace";
|
|
87
|
+
const denied = ["EACCES", "EPERM", "EROFS"].includes(errorCode(error) ?? "");
|
|
88
|
+
checks.push(check(id, "FAIL", denied ? "Permission denied when writing local storage." : "Could not initialize local storage.", "Choose a writable directory with --workspace and ensure its storage paths are real directories."));
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
if (probe)
|
|
92
|
+
await rm(probe, { recursive: true, force: true }).catch(() => { });
|
|
93
|
+
}
|
|
94
|
+
return checks;
|
|
95
|
+
}
|
|
96
|
+
async function studioChecks(workspace, port) {
|
|
97
|
+
try {
|
|
98
|
+
await checkPort(port);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return [check("studio-port", "FAIL", errorCode(error) === "EADDRINUSE"
|
|
102
|
+
? "The requested Studio port is busy." : "Could not bind a loopback TCP port.", "Stop the program using the port or pass --port 0 to choose a free port.")];
|
|
103
|
+
}
|
|
104
|
+
const checks = [check("studio-port", "PASS", "The requested loopback port was available.")];
|
|
105
|
+
try {
|
|
106
|
+
const { server, url } = await startStudio(workspace, port);
|
|
107
|
+
try {
|
|
108
|
+
const health = await fetch(`${url}/api/health`, { signal: AbortSignal.timeout(3000) });
|
|
109
|
+
if (!health.ok || (await health.json()).status !== "ready")
|
|
110
|
+
throw new Error("Unhealthy API.");
|
|
111
|
+
const page = await fetch(url, { signal: AbortSignal.timeout(3000) });
|
|
112
|
+
if (!page.ok || !(await page.text()).includes("AgentPath Studio"))
|
|
113
|
+
throw new Error("Missing Studio document.");
|
|
114
|
+
checks.push(check("studio-health", "PASS", "Studio served its HTML and the local API returned ready."));
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
await server.close();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
checks.push(check("studio-health", "FAIL", "Studio could not start or return its health response.", "Check workspace permissions and port availability. Reinstall the package if Studio assets are missing."));
|
|
122
|
+
}
|
|
123
|
+
return checks;
|
|
124
|
+
}
|
|
125
|
+
async function modelCheck(provider, configured) {
|
|
126
|
+
if (!configured)
|
|
127
|
+
return check(provider, "WARNING", "No OpenAI-compatible endpoint configured. Deterministic runs are available.", "Set AGENTPATH_MODEL_ENDPOINT only if you want to check an OpenAI-compatible model service.");
|
|
128
|
+
let endpoint;
|
|
129
|
+
try {
|
|
130
|
+
endpoint = new URL(configured);
|
|
131
|
+
if (!["http:", "https:"].includes(endpoint.protocol) || endpoint.username || endpoint.password || endpoint.search || endpoint.hash) {
|
|
132
|
+
throw new Error("Invalid endpoint.");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return check(provider, "WARNING", "The model endpoint configuration is invalid.", "Use an HTTP(S) base URL without credentials, query parameters or fragments.");
|
|
137
|
+
}
|
|
138
|
+
const modelHint = "Start the model service or check its base URL, access and installed models. This is optional.";
|
|
139
|
+
const route = provider === "ollama" ? "api/tags" : /\/v1\/?$/.test(endpoint.pathname) ? "models" : "v1/models";
|
|
140
|
+
const url = new URL(route, endpoint.href.endsWith("/") ? endpoint : endpoint.href + "/");
|
|
141
|
+
// Runs approve an external endpoint, and send its key, only when AGENTPATH_MODEL_ENDPOINT is the exact normalized
|
|
142
|
+
// URL. Doctor applies the same rule, and says so instead of silently checking without the key.
|
|
143
|
+
if (provider === "openai-compatible" && configured !== endpoint.href) {
|
|
144
|
+
return check(provider, "WARNING", "AGENTPATH_MODEL_ENDPOINT is not written as a normalized URL, so runs will not use it.", `Set it to exactly ${JSON.stringify(endpoint.href)}.`);
|
|
145
|
+
}
|
|
146
|
+
const key = provider === "openai-compatible" ? process.env.AGENTPATH_MODEL_API_KEY : undefined;
|
|
147
|
+
let response;
|
|
148
|
+
try {
|
|
149
|
+
response = await fetch(url, { redirect: "error", signal: AbortSignal.timeout(2500),
|
|
150
|
+
headers: key ? { authorization: `Bearer ${key}` } : undefined });
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return check(provider, "WARNING", "The optional model endpoint is unavailable.", modelHint);
|
|
154
|
+
}
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
await response.body?.cancel().catch(() => { });
|
|
157
|
+
return check(provider, "WARNING", "The optional model endpoint rejected the model-list request.", modelHint);
|
|
158
|
+
}
|
|
159
|
+
const reader = response.body?.getReader();
|
|
160
|
+
try {
|
|
161
|
+
const decoder = new TextDecoder();
|
|
162
|
+
let body = "";
|
|
163
|
+
let bytes = 0;
|
|
164
|
+
while (reader) {
|
|
165
|
+
const { value, done } = await reader.read();
|
|
166
|
+
if (done)
|
|
167
|
+
break;
|
|
168
|
+
bytes += value.byteLength;
|
|
169
|
+
if (bytes > 512 * 1024)
|
|
170
|
+
throw new Error("Model list too large.");
|
|
171
|
+
body += decoder.decode(value, { stream: true });
|
|
172
|
+
}
|
|
173
|
+
const data = JSON.parse(body + decoder.decode());
|
|
174
|
+
const models = provider === "ollama" ? data?.models : data?.data;
|
|
175
|
+
const field = provider === "ollama" ? "name" : "id";
|
|
176
|
+
if (!Array.isArray(models) || models.some((entry) => typeof entry?.[field] !== "string"))
|
|
177
|
+
throw new Error("Invalid model list.");
|
|
178
|
+
if (!models.length)
|
|
179
|
+
return check(provider, "WARNING", "The endpoint reported no models.", modelHint);
|
|
180
|
+
return check(provider, "PASS", `The endpoint reported ${models.length} available model(s). No inference was run.`);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return check(provider, "WARNING", "The optional endpoint returned an invalid or incomplete model list.", modelHint);
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
await reader?.cancel().catch(() => { });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function isolatedBrowserChecks() {
|
|
190
|
+
let directory;
|
|
191
|
+
try {
|
|
192
|
+
directory = await mkdtemp(join(tmpdir(), "agentpath-browser-check-"));
|
|
193
|
+
return await browserChecks(directory);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return [check("chromium-launch", "FAIL", "Could not create an isolated browser test directory.", "Check permissions on your system temporary directory.")];
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
if (directory)
|
|
200
|
+
await rm(directory, { recursive: true, force: true }).catch(() => { });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function printChecks(checks) {
|
|
204
|
+
for (const entry of checks)
|
|
205
|
+
console.log(`${entry.status.padEnd(7)} ${entry.id} ${entry.message} ${entry.resolution}`);
|
|
206
|
+
}
|
|
207
|
+
export async function doctor(args) {
|
|
208
|
+
const { values } = parseArgs({ args, options: { json: { type: "boolean" }, workspace: { type: "string" }, port: { type: "string" } } });
|
|
209
|
+
const workspace = resolve(values.workspace ?? ".");
|
|
210
|
+
const port = portOption(values.port, studioPort);
|
|
211
|
+
const storage = await workspaceChecks(workspace);
|
|
212
|
+
const [studio, chromium, ollama, openai] = await Promise.all([
|
|
213
|
+
storage.some(({ status }) => status === "FAIL")
|
|
214
|
+
? checkPort(port).then(() => [check("studio-port", "PASS", "The requested loopback port was available.")], () => [check("studio-port", "FAIL", "The loopback port was unavailable.", "Try --port 0 or free the port.")])
|
|
215
|
+
: studioChecks(workspace, port),
|
|
216
|
+
isolatedBrowserChecks(),
|
|
217
|
+
modelCheck("ollama", "http://127.0.0.1:11434/"),
|
|
218
|
+
modelCheck("openai-compatible", process.env.AGENTPATH_MODEL_ENDPOINT),
|
|
219
|
+
]);
|
|
220
|
+
const qualifiedPlatform = ["darwin", "linux", "win32"].includes(process.platform) && ["arm64", "x64"].includes(process.arch);
|
|
221
|
+
const checks = [
|
|
222
|
+
check("agentpath", "PASS", `AgentPath ${version}.`),
|
|
223
|
+
qualifiedPlatform ? check("platform", "PASS", `${process.platform} / ${process.arch}.`)
|
|
224
|
+
: check("platform", "WARNING", `${process.platform} / ${process.arch} has no release coverage.`, "Use a Playwright-supported macOS, Linux or Windows environment."),
|
|
225
|
+
check("node", "PASS", `Node ${process.versions.node}.`),
|
|
226
|
+
check("dependencies", "PASS", `The compiled runtime and required modules loaded. Playwright ${playwright.version}.`),
|
|
227
|
+
...storage, ...studio, ...chromium, ollama, openai,
|
|
228
|
+
];
|
|
229
|
+
const ready = checks.every(({ status }) => status !== "FAIL");
|
|
230
|
+
if (values.json)
|
|
231
|
+
console.log(JSON.stringify({ schemaVersion: checksVersion, version, ready, checks }));
|
|
232
|
+
else {
|
|
233
|
+
printChecks(checks);
|
|
234
|
+
console.log(ready ? "Ready for deterministic browser tasks. Try agentpath demo." : "Resolve failed checks and run agentpath doctor again.");
|
|
235
|
+
}
|
|
236
|
+
return ready ? 0 : 2;
|
|
237
|
+
}
|
|
238
|
+
export async function installBrowser(args) {
|
|
239
|
+
if (args.length !== 1 || args[0] !== "install")
|
|
240
|
+
throw new Error("Use agentpath browser install.");
|
|
241
|
+
const cli = require.resolve("playwright/package.json");
|
|
242
|
+
const entry = resolve(cli, "..", playwright.bin.playwright);
|
|
243
|
+
console.log(`Installing managed Chromium for Playwright ${playwright.version} (${process.platform} / ${process.arch}).`);
|
|
244
|
+
const code = await new Promise((done, reject) => {
|
|
245
|
+
const child = spawn(process.execPath, [entry, "install", "chromium"], { stdio: "inherit" });
|
|
246
|
+
child.once("error", reject);
|
|
247
|
+
child.once("close", done);
|
|
248
|
+
}).catch(() => null);
|
|
249
|
+
if (code !== 0) {
|
|
250
|
+
console.error("Chromium installation failed. Check network access and cache permissions, then retry agentpath browser install.");
|
|
251
|
+
return 2;
|
|
252
|
+
}
|
|
253
|
+
const checks = await isolatedBrowserChecks();
|
|
254
|
+
printChecks(checks);
|
|
255
|
+
if (checks.some(({ status }) => status === "FAIL")) {
|
|
256
|
+
if (process.platform === "linux") {
|
|
257
|
+
console.error("On Linux, ask your administrator to provision Playwright's Chromium system libraries and sandbox support.");
|
|
258
|
+
console.error("See https://playwright.dev/docs/browsers#install-system-dependencies for install-deps chromium.");
|
|
259
|
+
}
|
|
260
|
+
console.error("Playwright finished installation. Run agentpath doctor to diagnose the launch failure.");
|
|
261
|
+
return 2;
|
|
262
|
+
}
|
|
263
|
+
console.log("Chromium installed and verified. Next, run agentpath doctor or agentpath demo.");
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { explainPlaywrightResults } from "#agentpath/core";
|
|
4
|
+
const quote = (value) => JSON.stringify(value);
|
|
5
|
+
// Guidance is worded for task files; explain has no task file or allowlist, so name what it does have.
|
|
6
|
+
const forTests = (statement) => statement
|
|
7
|
+
.replace("the task's target is out of date", "the test's locator is out of date")
|
|
8
|
+
.replace("Requests to allowed hosts", "Requests to the test's page hosts")
|
|
9
|
+
.replace("can answer input the task sent", "can answer input the test sent");
|
|
10
|
+
const direction = { task: "points to the test", site: "points to the site", unclear: "fact" };
|
|
11
|
+
function locatorText(locator) {
|
|
12
|
+
const exact = locator.exact ? ", exact" : "";
|
|
13
|
+
return locator.by === "role" ? `role ${locator.role} named ${quote(locator.name ?? "")}${exact}` : `label ${quote(locator.label)}${exact}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Human-readable explanations. Names, paths and hosts come from the page and Playwright's files: they are
|
|
17
|
+
* quoted, never interpreted, and labelled as untrusted page data.
|
|
18
|
+
*/
|
|
19
|
+
export function formatExplanations(results) {
|
|
20
|
+
const lines = [];
|
|
21
|
+
for (const result of results) {
|
|
22
|
+
lines.push(`${result.test ? quote(result.test) : result.directory}${result.location ? ` (${result.location})` : ""}`);
|
|
23
|
+
if (result.status !== "explained") {
|
|
24
|
+
lines.push(` Not explained: ${result.reason ?? result.status}`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (result.chain) {
|
|
28
|
+
lines.push(` Failed locator: ${result.chain.text}`);
|
|
29
|
+
if (result.chain.steps.length > 1)
|
|
30
|
+
lines.push(` Matches by step at the end of the test: ${result.chain.steps.map((step) => `${step.code} → ${step.count ?? "?"}`).join(", ")}`);
|
|
31
|
+
}
|
|
32
|
+
else if (result.locator)
|
|
33
|
+
lines.push(` Failed locator: ${locatorText(result.locator)}`);
|
|
34
|
+
if (result.presentInSnapshot === true) {
|
|
35
|
+
lines.push(" A matching target is in Playwright's page snapshot taken at the failure: it may have appeared late, or been hidden, disabled or covered.");
|
|
36
|
+
}
|
|
37
|
+
for (const finding of result.guidance?.findings ?? [])
|
|
38
|
+
lines.push(` [${direction[finding.pointsTo]}] ${forTests(finding.statement)}`);
|
|
39
|
+
for (const suggestion of result.suggestedLocators ?? [])
|
|
40
|
+
lines.push(` Suggested locator (never applied): page.${suggestion}`);
|
|
41
|
+
if (result.presentInSnapshot === false && !result.nearMatches?.length)
|
|
42
|
+
lines.push(" No target in Playwright's page snapshot matches the locator or resembles it.");
|
|
43
|
+
if (!result.guidance?.findings.length && result.presentInSnapshot !== true)
|
|
44
|
+
lines.push(" No recorded fact points either way.");
|
|
45
|
+
}
|
|
46
|
+
if (result.live === "no-page")
|
|
47
|
+
lines.push(` AgentPath fixture: it ran, but read no page of this test. ${result.liveReason ?? ""}`.trimEnd());
|
|
48
|
+
if (result.lateCheck?.outcome === "not-run")
|
|
49
|
+
lines.push(` Late check: not run. ${result.lateCheck.reason ?? ""}`.trimEnd());
|
|
50
|
+
if (result.status !== "explained" && result.failedRequests?.length) {
|
|
51
|
+
lines.push(` Failed requests to the test's page hosts: ${result.failedRequests.map((entry) => `${entry.method} ${entry.host}${entry.path} → ${entry.status ?? "network error"}`).join("; ")}`);
|
|
52
|
+
}
|
|
53
|
+
lines.push(` Trace: ${result.trace === "read" ? "network log read" : result.trace === "absent" ? (result.live === "read" ? "none (failed requests were recorded by the AgentPath fixture)" : "none (record traces on failure, or use the AgentPath fixture, to see failed requests)") : "unreadable"}`);
|
|
54
|
+
lines.push("");
|
|
55
|
+
}
|
|
56
|
+
if (!results.length)
|
|
57
|
+
lines.push("No failed tests found (no error-context.md files).", "");
|
|
58
|
+
if (results.some((result) => result.live === "read" || result.live === "no-page")) {
|
|
59
|
+
lines.push("Names and paths above are untrusted text from the page under test. Where the AgentPath fixture ran, it read the open page at the end of the test without acting; elsewhere no late check ran. No egress boundary applied.");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
lines.push("Names and paths above are untrusted text from the page under test. No late check ran and no egress boundary applied: this reads Playwright's own output only.");
|
|
63
|
+
}
|
|
64
|
+
return lines;
|
|
65
|
+
}
|
|
66
|
+
/** The JSON carries the same test wording as the text output; "task" in pointsTo means the test. */
|
|
67
|
+
export function wordedForTests(results) {
|
|
68
|
+
return results.map((result) => result.guidance
|
|
69
|
+
? { ...result, guidance: { ...result.guidance, findings: result.guidance.findings.map((finding) => ({ ...finding, statement: forTests(finding.statement) })) } }
|
|
70
|
+
: result);
|
|
71
|
+
}
|
|
72
|
+
export async function explainCommand(args) {
|
|
73
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { json: { type: "boolean" } } });
|
|
74
|
+
if (positionals.length > 1)
|
|
75
|
+
throw new Error("explain takes one Playwright output directory.");
|
|
76
|
+
const root = resolve(positionals[0] ?? "test-results");
|
|
77
|
+
let results;
|
|
78
|
+
try {
|
|
79
|
+
results = await explainPlaywrightResults(root);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new Error("The Playwright output directory could not be read. Pass the directory Playwright writes results to (test-results by default).");
|
|
83
|
+
}
|
|
84
|
+
if (values.json)
|
|
85
|
+
console.log(JSON.stringify({ untrusted: "page-provided text", results: wordedForTests(results) }));
|
|
86
|
+
else
|
|
87
|
+
console.log(formatExplanations(results).join("\n"));
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
/** Runs one read-only git command with an argument list (never a shell). */
|
|
3
|
+
export function git(cwd, args, maxBuffer = 64 * 1024 * 1024) {
|
|
4
|
+
return new Promise((resolvePromise, reject) => {
|
|
5
|
+
execFile("git", args, { cwd, maxBuffer, encoding: "utf8", env: { ...process.env, GIT_OPTIONAL_LOCKS: "0", GIT_TERMINAL_PROMPT: "0" } }, (error, stdout) => error ? reject(error) : resolvePromise(stdout));
|
|
6
|
+
});
|
|
7
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { inspectionRequestSchema, INSPECTION_LIMITS } from "#agentpath/contracts";
|
|
3
|
+
import { inspectPage, InspectionFailure } from "#agentpath/core";
|
|
4
|
+
const quote = (value) => JSON.stringify(value);
|
|
5
|
+
const times = (count) => `${count} match${count === 1 ? "" : "es"}`;
|
|
6
|
+
function matchNote(entry) {
|
|
7
|
+
switch (entry.match) {
|
|
8
|
+
case "unique": return "";
|
|
9
|
+
case "ambiguous": return ` — ambiguous, ${times(entry.matches ?? 0)}; a step would fail`;
|
|
10
|
+
case "not-matched": return " — the exact locator found no match";
|
|
11
|
+
case "unconfirmed": return " — not confirmed before the deadline";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function blockedLine(hosts, truncated) {
|
|
15
|
+
if (!hosts.length)
|
|
16
|
+
return undefined;
|
|
17
|
+
const list = hosts.map(({ host, requests }) => `${quote(host)} (${requests})`).join(", ");
|
|
18
|
+
return `Blocked requests to hosts outside --allow: ${list}${truncated ? ", and more" : ""}`;
|
|
19
|
+
}
|
|
20
|
+
/** Human-readable listing. Every page-provided name, label and host is quoted, never interpreted. */
|
|
21
|
+
export function formatInspection(result) {
|
|
22
|
+
const lines = [`Targets on ${result.url}`];
|
|
23
|
+
lines.push("", "Role and name (use { \"by\": \"role\", \"role\": <role>, \"name\": <name> }):");
|
|
24
|
+
for (const target of result.targets) {
|
|
25
|
+
const cut = target.nameTruncated ? ` — name cut at ${INSPECTION_LIMITS.text} characters` : "";
|
|
26
|
+
lines.push(` ${target.role} ${quote(target.name)}${cut}${matchNote(target)}`);
|
|
27
|
+
}
|
|
28
|
+
if (!result.targets.length)
|
|
29
|
+
lines.push(" (none)");
|
|
30
|
+
if (result.targetsTruncated)
|
|
31
|
+
lines.push(` … more targets not listed (limit ${INSPECTION_LIMITS.targets})`);
|
|
32
|
+
lines.push("", "Label (use { \"by\": \"label\", \"label\": <label> }):");
|
|
33
|
+
for (const label of result.labels) {
|
|
34
|
+
const cut = label.labelTruncated ? ` — label cut at ${INSPECTION_LIMITS.text} characters` : "";
|
|
35
|
+
lines.push(` ${quote(label.label)}${cut}${matchNote(label)}`);
|
|
36
|
+
}
|
|
37
|
+
if (!result.labels.length)
|
|
38
|
+
lines.push(" (none)");
|
|
39
|
+
if (result.labelsTruncated)
|
|
40
|
+
lines.push(` … more labels not listed (limit ${INSPECTION_LIMITS.labels})`);
|
|
41
|
+
if (result.unnamed.length) {
|
|
42
|
+
lines.push("", "Unnamed (cannot be targeted by name):");
|
|
43
|
+
for (const entry of result.unnamed) {
|
|
44
|
+
const nameless = entry.roleMatches === 1
|
|
45
|
+
? " — the only " + entry.role + ": usable without a name in waits and assertions"
|
|
46
|
+
: "";
|
|
47
|
+
lines.push(` ${entry.role} ×${entry.count}${nameless}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (result.embeddedFrames) {
|
|
51
|
+
lines.push("", `The page has ${result.embeddedFrames} embedded frame${result.embeddedFrames === 1 ? "" : "s"} (iframe). Targets inside frames are not listed or searched.`);
|
|
52
|
+
}
|
|
53
|
+
const blocked = blockedLine(result.blockedHosts, result.blockedHostsTruncated);
|
|
54
|
+
if (blocked)
|
|
55
|
+
lines.push("", blocked);
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
58
|
+
export async function inspectCommand(args) {
|
|
59
|
+
const { positionals, values } = parseArgs({
|
|
60
|
+
args, allowPositionals: true,
|
|
61
|
+
options: { allow: { type: "string", multiple: true }, json: { type: "boolean" }, mobile: { type: "boolean" } },
|
|
62
|
+
});
|
|
63
|
+
if (positionals.length !== 1)
|
|
64
|
+
throw new Error("inspect requires exactly one URL.");
|
|
65
|
+
// Without --allow, only the URL's own host is reachable: the operator typed it.
|
|
66
|
+
let allowed = values.allow ?? [];
|
|
67
|
+
if (!allowed.length) {
|
|
68
|
+
try {
|
|
69
|
+
allowed = [new URL(positionals[0]).host];
|
|
70
|
+
}
|
|
71
|
+
catch { /* the schema names the invalid URL */ }
|
|
72
|
+
}
|
|
73
|
+
if (!allowed.length)
|
|
74
|
+
throw new Error("inspect requires a valid http(s) URL, such as http://127.0.0.1:4173/.");
|
|
75
|
+
const request = inspectionRequestSchema.safeParse({ url: positionals[0], allowedHosts: allowed });
|
|
76
|
+
if (!request.success) {
|
|
77
|
+
const issues = request.error.issues.map((issue) => `${issue.path[0] === "allowedHosts" ? "--allow" : issue.path.join(".") || "(request)"} — ${issue.message}`);
|
|
78
|
+
throw new Error(`Invalid inspect options\n${issues.join("\n")}`);
|
|
79
|
+
}
|
|
80
|
+
const controller = new AbortController();
|
|
81
|
+
const abort = () => controller.abort();
|
|
82
|
+
let interrupted = 130;
|
|
83
|
+
const terminate = () => {
|
|
84
|
+
interrupted = 143;
|
|
85
|
+
abort();
|
|
86
|
+
};
|
|
87
|
+
process.on("SIGINT", abort);
|
|
88
|
+
process.on("SIGTERM", terminate);
|
|
89
|
+
try {
|
|
90
|
+
const result = await inspectPage(request.data, { signal: controller.signal, mobile: values.mobile === true });
|
|
91
|
+
if (values.json)
|
|
92
|
+
console.log(JSON.stringify(result));
|
|
93
|
+
else
|
|
94
|
+
for (const line of formatInspection(result))
|
|
95
|
+
console.log(line);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (controller.signal.aborted)
|
|
100
|
+
return interrupted;
|
|
101
|
+
if (error instanceof InspectionFailure) {
|
|
102
|
+
const lines = [error.message];
|
|
103
|
+
if (error.observation.disallowedHost !== undefined)
|
|
104
|
+
lines.push(`Blocked destination host: ${quote(error.observation.disallowedHost)}`);
|
|
105
|
+
const blocked = blockedLine(error.blockedHosts, error.blockedHostsTruncated);
|
|
106
|
+
if (blocked)
|
|
107
|
+
lines.push(blocked);
|
|
108
|
+
if (error.investigation)
|
|
109
|
+
lines.push(`Next: ${error.investigation}`);
|
|
110
|
+
throw new Error(lines.join("\n"));
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
process.removeListener("SIGINT", abort);
|
|
116
|
+
process.removeListener("SIGTERM", terminate);
|
|
117
|
+
}
|
|
118
|
+
}
|