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.
Files changed (127) hide show
  1. package/LICENSE.md +105 -0
  2. package/README.md +101 -2
  3. package/THIRD_PARTY_NOTICES +12 -0
  4. package/apps/demo-site/dist/site.js +92 -0
  5. package/apps/studio/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  6. package/apps/studio/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  7. package/apps/studio/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  8. package/apps/studio/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  9. package/apps/studio/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  10. package/apps/studio/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  11. package/apps/studio/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  12. package/apps/studio/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  13. package/apps/studio/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  14. package/apps/studio/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  15. package/apps/studio/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  16. package/apps/studio/dist/assets/index-DH4wJPHm.js +67 -0
  17. package/apps/studio/dist/assets/index-DrnNh2ip.css +1 -0
  18. package/apps/studio/dist/index.html +14 -0
  19. package/audit.md +173 -0
  20. package/autonomous-mode.md +104 -0
  21. package/ci.md +118 -0
  22. package/coding-agents.md +143 -0
  23. package/concepts.md +145 -0
  24. package/contracts.md +356 -0
  25. package/examples/tasks/ambiguous.json +98 -0
  26. package/examples/tasks/assertion-failure.json +98 -0
  27. package/examples/tasks/broken.json +98 -0
  28. package/examples/tasks/fixed.json +98 -0
  29. package/examples/tasks/recovery.json +19 -0
  30. package/images/compare-recovery-desktop.jpg +0 -0
  31. package/images/compare-variants-desktop.jpg +0 -0
  32. package/images/overview-desktop.jpg +0 -0
  33. package/images/run-autonomous-passed-desktop.jpg +0 -0
  34. package/images/run-failed-desktop.jpg +0 -0
  35. package/images/run-failed-mobile.jpg +0 -0
  36. package/images/run-missing-artifact-desktop.jpg +0 -0
  37. package/images/task-editor-laptop.jpg +0 -0
  38. package/installation.md +102 -0
  39. package/ledger.md +62 -0
  40. package/licenses/-fontsource-variable-geist-mono.txt +93 -0
  41. package/licenses/-fontsource-variable-geist.txt +93 -0
  42. package/licenses/lucide-react.txt +43 -0
  43. package/licenses/react-dom.txt +21 -0
  44. package/licenses/react.txt +21 -0
  45. package/licenses/scheduler.txt +21 -0
  46. package/licenses/tailwindcss.txt +21 -0
  47. package/licenses/zod.txt +21 -0
  48. package/package.json +165 -4
  49. package/packages/cli/bin/agentpath.js +39 -0
  50. package/packages/cli/dist/audit-rerun.js +384 -0
  51. package/packages/cli/dist/audit.js +387 -0
  52. package/packages/cli/dist/change-summaries.js +87 -0
  53. package/packages/cli/dist/ci-report.js +88 -0
  54. package/packages/cli/dist/demo.js +88 -0
  55. package/packages/cli/dist/doctor.js +265 -0
  56. package/packages/cli/dist/explain.js +89 -0
  57. package/packages/cli/dist/git.js +7 -0
  58. package/packages/cli/dist/inspect.js +118 -0
  59. package/packages/cli/dist/ledger.js +509 -0
  60. package/packages/cli/dist/local.js +102 -0
  61. package/packages/cli/dist/main.js +708 -0
  62. package/packages/cli/dist/mcp.js +231 -0
  63. package/packages/cli/dist/paths.js +6 -0
  64. package/packages/cli/dist/playwright-fixture.js +185 -0
  65. package/packages/cli/dist/playwright-reporter.js +49 -0
  66. package/packages/cli/dist/tasks.js +37 -0
  67. package/packages/cli/dist/test-source.js +283 -0
  68. package/packages/cli/dist/watch.js +96 -0
  69. package/packages/contracts/dist/agent-settings.js +18 -0
  70. package/packages/contracts/dist/agent.js +175 -0
  71. package/packages/contracts/dist/audit.js +115 -0
  72. package/packages/contracts/dist/guidance.js +339 -0
  73. package/packages/contracts/dist/index.js +14 -0
  74. package/packages/contracts/dist/inspect.js +63 -0
  75. package/packages/contracts/dist/ledger.js +80 -0
  76. package/packages/contracts/dist/local.js +171 -0
  77. package/packages/contracts/dist/outcomes.js +94 -0
  78. package/packages/contracts/dist/platform.js +105 -0
  79. package/packages/contracts/dist/playwright-live.js +76 -0
  80. package/packages/contracts/dist/policy.js +93 -0
  81. package/packages/contracts/dist/run.js +178 -0
  82. package/packages/contracts/dist/task-issues.js +39 -0
  83. package/packages/contracts/dist/task.js +185 -0
  84. package/packages/contracts/dist/watch.js +57 -0
  85. package/packages/core/dist/action-feedback.js +103 -0
  86. package/packages/core/dist/actions.js +160 -0
  87. package/packages/core/dist/agent-loop.js +122 -0
  88. package/packages/core/dist/artifacts.js +156 -0
  89. package/packages/core/dist/assertions.js +120 -0
  90. package/packages/core/dist/autonomous.js +1 -0
  91. package/packages/core/dist/browser.js +196 -0
  92. package/packages/core/dist/compare.js +141 -0
  93. package/packages/core/dist/control-state.js +62 -0
  94. package/packages/core/dist/diagnostics.js +134 -0
  95. package/packages/core/dist/evidence-diff.js +93 -0
  96. package/packages/core/dist/evidence.js +203 -0
  97. package/packages/core/dist/index.js +22 -0
  98. package/packages/core/dist/inspect.js +257 -0
  99. package/packages/core/dist/integrity.js +176 -0
  100. package/packages/core/dist/liveness.js +114 -0
  101. package/packages/core/dist/local-files.js +61 -0
  102. package/packages/core/dist/locators.js +214 -0
  103. package/packages/core/dist/model-provider.js +88 -0
  104. package/packages/core/dist/observation.js +257 -0
  105. package/packages/core/dist/playwright-live.js +519 -0
  106. package/packages/core/dist/playwright-results.js +543 -0
  107. package/packages/core/dist/policy.js +182 -0
  108. package/packages/core/dist/privacy.js +93 -0
  109. package/packages/core/dist/recovery.js +54 -0
  110. package/packages/core/dist/retention.js +204 -0
  111. package/packages/core/dist/run-index.js +177 -0
  112. package/packages/core/dist/run-plan.js +28 -0
  113. package/packages/core/dist/run-repository.js +518 -0
  114. package/packages/core/dist/runner.js +913 -0
  115. package/packages/core/dist/storage.js +63 -0
  116. package/packages/core/dist/task-fingerprint.js +36 -0
  117. package/packages/core/dist/test-change-rerun.js +84 -0
  118. package/packages/core/dist/test-changes.js +896 -0
  119. package/packages/core/dist/timing.js +41 -0
  120. package/packages/core/dist/watch.js +165 -0
  121. package/packages/server/dist/index.js +265 -0
  122. package/packages/server/dist/task-store.js +103 -0
  123. package/quickstart.md +85 -0
  124. package/security.md +136 -0
  125. package/try-on-your-repo.md +54 -0
  126. package/understanding-results.md +159 -0
  127. package/writing-tasks.md +196 -0
@@ -0,0 +1,63 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { appendFile, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { runEventSchema, runResultSchema, SCHEMA_VERSION, } from "#agentpath/contracts";
5
+ export class RunStorage {
6
+ runId;
7
+ directory;
8
+ onEvent;
9
+ artifacts = [];
10
+ #sequence = 0;
11
+ constructor(runId, directory, onEvent) {
12
+ this.runId = runId;
13
+ this.directory = directory;
14
+ this.onEvent = onEvent;
15
+ }
16
+ static async create(runsDirectory = ".agentpath/runs", onEvent) {
17
+ const runId = randomUUID();
18
+ const root = resolve(runsDirectory);
19
+ const directory = join(root, runId);
20
+ await mkdir(root, { recursive: true, mode: 0o700 });
21
+ if (!(await lstat(root)).isDirectory())
22
+ throw new Error("The runs directory must be a real directory.");
23
+ await mkdir(directory, { mode: 0o700 });
24
+ await mkdir(join(directory, "evidence"), { mode: 0o700 });
25
+ return new RunStorage(runId, directory, onEvent);
26
+ }
27
+ path(relative) {
28
+ return join(this.directory, relative);
29
+ }
30
+ async write(relative, data) {
31
+ await writeLocalJson(this.path(relative), data);
32
+ }
33
+ async emit(data) {
34
+ const event = runEventSchema.parse({
35
+ ...data, schemaVersion: SCHEMA_VERSION, runId: this.runId, sequence: this.#sequence++, at: new Date().toISOString(),
36
+ });
37
+ await appendFile(this.path("events.jsonl"), JSON.stringify(event) + "\n", { mode: 0o600 });
38
+ try {
39
+ this.onEvent?.(event);
40
+ }
41
+ catch {
42
+ // An observer cannot change the outcome of a run.
43
+ }
44
+ }
45
+ add(kind, path) {
46
+ const ref = { kind, path };
47
+ this.artifacts.push(ref);
48
+ return ref;
49
+ }
50
+ }
51
+ export async function readRunResult(directory) {
52
+ return runResultSchema.parse(JSON.parse(await readFile(join(directory, "result.json"), "utf8")));
53
+ }
54
+ export async function writeLocalJson(path, data) {
55
+ const temporary = join(dirname(path), `.${randomUUID()}.tmp`);
56
+ try {
57
+ await writeFile(temporary, JSON.stringify(data, null, 2) + "\n", { mode: 0o600, flag: "wx" });
58
+ await rename(temporary, path);
59
+ }
60
+ finally {
61
+ await rm(temporary, { force: true });
62
+ }
63
+ }
@@ -0,0 +1,36 @@
1
+ import { createHash } from "node:crypto";
2
+ import { taskSchema } from "#agentpath/contracts";
3
+ export function canonicalJson(value) {
4
+ if (Array.isArray(value))
5
+ return `[${value.map(canonicalJson).join(",")}]`;
6
+ if (value !== null && typeof value === "object") {
7
+ return `{${Object.entries(value).filter(([, entry]) => entry !== undefined).sort(([a], [b]) => a.localeCompare(b, "en"))
8
+ .map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(",")}}`;
9
+ }
10
+ return JSON.stringify(value);
11
+ }
12
+ export function definitionHash(value) {
13
+ return createHash("sha256").update(canonicalJson(value)).digest("hex");
14
+ }
15
+ export function fingerprintTask(input) {
16
+ const task = taskSchema.parse(input);
17
+ const assertions = task.assertions;
18
+ const definition = {
19
+ mode: task.mode, schemaVersion: task.schemaVersion,
20
+ baseUrl: new URL(task.baseUrl).href,
21
+ allowedHosts: [...task.allowedHosts].sort(),
22
+ browser: { ...task.browser, runTimeoutMs: task.browser.runTimeoutMs ?? 120_000 }, artifacts: task.artifacts,
23
+ ...(task.mode === "autonomous" ? { goal: task.goal, agent: task.agent } : {}),
24
+ steps: (task.mode === "deterministic" ? task.steps : []).map((step) => step.action === "navigate" ? { ...step, url: new URL(step.url, task.baseUrl).href } : step),
25
+ assertions,
26
+ };
27
+ return {
28
+ definitionFingerprint: definitionHash(definition),
29
+ assertionsFingerprint: definitionHash(assertions),
30
+ // The policy is a separate, independently compared contract. It is excluded from the task definition so that
31
+ // adding a policy never changes goal-contract equivalence, and tasks without one keep their fingerprints.
32
+ ...(task.policy ? { policyFingerprint: definitionHash(task.policy) } : {}),
33
+ stepCount: task.mode === "deterministic" ? task.steps.length : 0,
34
+ assertionCount: assertions.length,
35
+ };
36
+ }
@@ -0,0 +1,84 @@
1
+ // Classification for `agentpath audit --rerun` (docs/audit.md). Pure: the CLI runs Playwright and passes the results in.
2
+ import { evidenceDirection, failedRequestFindings } from "#agentpath/contracts";
3
+ import { plainText } from "./test-changes.js";
4
+ const STATEMENT_LIMIT = 2000;
5
+ const TEST_FILE = /^(.*?)(\.(?:spec|test)\.(?:ts|mts|cts|js|mjs|cjs))$/;
6
+ /**
7
+ * The name of a copy written by a rerun. A file with this shape left in a checkout is stale. The second form is the
8
+ * one earlier versions wrote ("cart.agentpath-base-<token>.spec.ts"), still recognised so an old copy is not missed.
9
+ */
10
+ export const RERUN_COPY = /(?:^|\/)agentpath-base-[0-9a-f]{8}-[^/]*\.[cm]?[jt]sx?$|\.agentpath-base-[0-9a-f]{8}\.[^/]*[cm]?[jt]sx?$/;
11
+ /**
12
+ * The copy's file name: beside the original, with the token in front, so the whole original name stays its ending.
13
+ * A testMatch that selects by an ending ("*.spec.ts", "*e2e.spec.ts", /.*\.e2e\.ts/) then selects the copy too:
14
+ * "e2e.spec.ts" becomes "agentpath-base-<token>-e2e.spec.ts". Only a name with a test ending is copied.
15
+ */
16
+ export function rerunCopyName(fileName, token) {
17
+ if (!/^[0-9a-f]{8}$/.test(token))
18
+ throw new Error("A copy token is eight hexadecimal digits.");
19
+ if (!TEST_FILE.test(fileName) && !/^[^.]+\..*\.[cm]?[jt]sx?$/.test(fileName))
20
+ return undefined;
21
+ return `agentpath-base-${token}-${fileName}`;
22
+ }
23
+ /** A side's result from Playwright's JSON outcome and, for a failure, explain's reading of it. */
24
+ export function rerunSide(outcome, lastStatus, explanation) {
25
+ if (outcome === "skipped")
26
+ return { status: "skipped" };
27
+ if (outcome === "expected")
28
+ return { status: lastStatus === "skipped" ? "skipped" : "passed" };
29
+ if (outcome !== "unexpected" || lastStatus === "interrupted")
30
+ return { status: "not-run" };
31
+ // A timeout counts only when it waited on a locator: a slow navigation or a hung helper has none.
32
+ const pageFailure = explanation !== undefined && explanation.status !== "unreadable"
33
+ && (explanation.errorKind === "strict" || explanation.errorKind === "expect"
34
+ || (explanation.errorKind === "missing" && explanation.status !== "no-locator"));
35
+ // Without guidance (a locator explain does not read), the failed requests still say what the trace recorded.
36
+ const findings = explanation?.guidance?.findings ?? failedRequestFindings(explanation?.failedRequests ?? []);
37
+ return { status: "failed", pageFailure, ...(findings.length ? { findings } : {}) };
38
+ }
39
+ function classifyProject(old, confirm, head, control) {
40
+ const newSide = head === "absent" ? "absent" : head?.status ?? "not-run";
41
+ const base = { old: old.status, new: newSide };
42
+ if (old.status === "passed")
43
+ return { outcome: "not-needed", ...base };
44
+ if (old.status !== "failed")
45
+ return { outcome: "inconclusive", ...base, reason: `The old version ${old.status === "skipped" ? "skipped itself" : "did not run"} on this build.` };
46
+ if (!old.pageFailure) {
47
+ return { outcome: "inconclusive", ...base, reason: "The old version failed outside a locator or assertion, for example while loading the page or in a helper that changed." };
48
+ }
49
+ if (confirm?.status !== "failed" || !confirm.pageFailure) {
50
+ return { outcome: "inconclusive", ...base, reason: confirm?.status === "passed" ? "The old version failed once, then passed: a flaky result." : "The old version's failure could not be confirmed by a second run." };
51
+ }
52
+ if (newSide === "failed")
53
+ return { outcome: "inconclusive", ...base, reason: "Both versions fail on this build." };
54
+ if (newSide === "not-run")
55
+ return { outcome: "inconclusive", ...base, reason: "The new version did not run." };
56
+ // A skipped or removed new version shows nothing about this run's environment; an unchanged test must.
57
+ if (newSide !== "passed" && control?.status !== "passed") {
58
+ return { outcome: "inconclusive", ...base, reason: "The new version is skipped or gone, and no unchanged test of the same file passed from the same copy, so the old failure may come from the environment (sign-in, setup, test order) rather than the build." };
59
+ }
60
+ const statements = (old.findings ?? []).slice(0, 20).map((finding) => {
61
+ const statement = plainText(finding.statement);
62
+ return { pointsTo: finding.pointsTo, statement: statement.length > STATEMENT_LIMIT ? `${statement.slice(0, STATEMENT_LIMIT - 1)}…` : statement };
63
+ });
64
+ return { outcome: "change-needed", ...base, ...(statements.length ? { statements } : {}) };
65
+ }
66
+ /**
67
+ * The rerun outcome of one flagged test across Playwright projects. `control` is an unchanged test of the same old
68
+ * file, run from the same copy: when the new version is skipped or gone, it must pass for the change to be needed. A project where the change is needed decides;
69
+ * otherwise an inconclusive project; otherwise the old version passed everywhere. Returns the direction for a
70
+ * change-needed outcome, by the same rule as `watch`.
71
+ */
72
+ export function classifyRerun(old, confirm, head, control = new Map()) {
73
+ if (!old.size) {
74
+ return { rerun: { outcome: "inconclusive", old: "not-run", new: head === "absent" ? "absent" : "not-run",
75
+ reason: "Playwright did not run the old version. Its testMatch, testIgnore or --project may exclude the copy." } };
76
+ }
77
+ const per = [...old].map(([project, result]) => ({
78
+ project, ...classifyProject(result, confirm.get(project), head === "absent" ? "absent" : head.get(project), control.get(project)),
79
+ }));
80
+ const chosen = per.find((entry) => entry.outcome === "change-needed") ?? per.find((entry) => entry.outcome === "inconclusive") ?? per[0];
81
+ const { project, ...rest } = chosen;
82
+ const rerun = { ...rest, ...(project ? { project: plainText(project).slice(0, 200) } : {}) };
83
+ return rerun.outcome === "change-needed" ? { rerun, direction: evidenceDirection(rerun.statements ?? []) } : { rerun };
84
+ }