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,171 @@
1
+ import { z } from "zod";
2
+ import { agentTraceSchema } from "./agent.js";
3
+ import { assertionKindSchema, SCHEMA_VERSION, stepActionSchema, taskIdSchema, taskSchema } from "./task.js";
4
+ import { accessibilitySnapshotSchema, assertionResultSchema, comparisonSchema, environmentSchema, failureCategorySchema, failureEvidenceSchema, observationSchema, runEventSchema, runIdSchema, runResultSchema, stepResultSchema, verdictSchema, } from "./run.js";
5
+ import { captureStateRecordSchema, integrityStatusSchema, runLivenessSchema } from "./platform.js";
6
+ import { policyComparisonSchema, policyRecordSchema, runOutcomesSchema } from "./policy.js";
7
+ const index = z.int().nonnegative();
8
+ export const recordedTargetSchema = z.strictObject({
9
+ by: z.enum(["role", "label"]), role: z.string().optional(), name: z.string(),
10
+ nameState: z.enum(["redacted", "withheld"]).optional(),
11
+ });
12
+ const identity = z.object({ target: recordedTargetSchema.optional(), expectation: z.string().optional(), key: z.string().min(1), intent: z.string().min(1) });
13
+ export const runPlanSchema = z.strictObject({
14
+ schemaVersion: z.literal(SCHEMA_VERSION),
15
+ identityVersion: z.literal(2).optional(),
16
+ mode: z.enum(["deterministic", "autonomous"]).optional(),
17
+ steps: z.array(identity.extend({ kind: stepActionSchema })).max(100),
18
+ assertions: z.array(identity.extend({ kind: assertionKindSchema })).max(100),
19
+ });
20
+ export const runMetadataSchema = z.strictObject({
21
+ schemaVersion: z.literal(SCHEMA_VERSION),
22
+ runId: runIdSchema, taskId: taskIdSchema,
23
+ fingerprintVersion: z.literal(1), hashAlgorithm: z.literal("sha256"),
24
+ definitionFingerprint: z.string().regex(/^[a-f0-9]{64}$/),
25
+ assertionsFingerprint: z.string().regex(/^[a-f0-9]{64}$/),
26
+ stepCount: index.max(100), assertionCount: index.max(100),
27
+ privacyPolicy: z.literal("minimal-after-input-v1"),
28
+ /** SHA-256 of the canonical action policy. Absent when the task configured no policy (and in older runs). */
29
+ policyFingerprint: z.string().regex(/^[a-f0-9]{64}$/).optional(),
30
+ });
31
+ export const operationObservationsSchema = z.strictObject({
32
+ schemaVersion: z.literal(SCHEMA_VERSION),
33
+ runId: runIdSchema,
34
+ operations: z.array(z.strictObject({
35
+ phase: z.enum(["step", "assertion"]), index,
36
+ observation: observationSchema,
37
+ })).max(200),
38
+ });
39
+ export const evidenceAvailabilitySchema = z.strictObject({
40
+ checked: z.literal(true),
41
+ // "modified" and "unexpected" come from the integrity sidecar.
42
+ issues: z.array(z.strictObject({ path: z.string(), reason: z.enum(["missing", "unreadable", "inconsistent", "modified", "unexpected"]) })),
43
+ integrity: integrityStatusSchema.optional(),
44
+ });
45
+ export const BLOCKED_HOST_LIMIT = 20;
46
+ export const FAILED_REQUEST_LIMIT = 10;
47
+ export const FAILED_REQUEST_PATH_LIMIT = 200;
48
+ export const browserObservationsSchema = z.strictObject({
49
+ schemaVersion: z.literal(SCHEMA_VERSION),
50
+ pageErrors: index,
51
+ consoleErrors: index,
52
+ cleanup: z.enum(["complete", "forced", "unconfirmed"]).optional(),
53
+ /** hosts outside the allowlist whose requests were blocked, most requested first. */
54
+ blockedHosts: z.array(z.strictObject({ host: z.string().min(1).max(260), requests: z.int().min(1) })).max(BLOCKED_HOST_LIMIT).optional(),
55
+ blockedHostsTruncated: z.literal(true).optional(),
56
+ /**
57
+ * requests to allowed hosts that returned HTTP 400 or above or failed at the network level, in
58
+ * the order first seen. The path excludes the query and follows the evidence privacy policy.
59
+ */
60
+ failedRequests: z.array(z.strictObject({
61
+ host: z.string().min(1).max(260),
62
+ path: z.string().min(1).max(FAILED_REQUEST_PATH_LIMIT),
63
+ method: z.string().min(1).max(16),
64
+ resourceType: z.string().min(1).max(32),
65
+ status: z.int().min(400).max(599).optional(),
66
+ failure: z.literal("network").optional(),
67
+ count: z.int().min(1),
68
+ })).max(FAILED_REQUEST_LIMIT).optional(),
69
+ failedRequestsTruncated: z.literal(true).optional(),
70
+ });
71
+ export const taskPathSchema = z.strictObject({ taskId: taskIdSchema });
72
+ export const runPathSchema = z.strictObject({ runId: runIdSchema });
73
+ export const runRequestSchema = taskPathSchema;
74
+ export const artifactPathSchema = runPathSchema.extend({ index: z.string().regex(/^(0|[1-9][0-9]{0,5})$/).transform(Number) });
75
+ export const artifactResponseSchema = z.instanceof(Uint8Array);
76
+ export const comparisonModeSchema = z.enum(["same-task", "scenario-variants"]);
77
+ export const compareRequestSchema = z.strictObject({
78
+ baseline: runIdSchema, candidate: runIdSchema, mode: comparisonModeSchema.default("same-task"),
79
+ });
80
+ export const taskListSchema = z.array(taskSchema);
81
+ export const healthSchema = z.strictObject({
82
+ status: z.literal("ready"), runtime: z.string(), platform: z.string(),
83
+ chromium: z.enum(["installed", "missing"]), activeRuns: index, concurrency: z.int().positive(),
84
+ });
85
+ export const errorResponseSchema = z.strictObject({
86
+ error: z.string(),
87
+ issues: z.array(z.strictObject({ path: z.string(), message: z.string() })).optional(),
88
+ });
89
+ export const runSummarySchema = z.strictObject({
90
+ runId: runIdSchema, taskId: taskIdSchema.optional(), mode: z.enum(["deterministic", "autonomous"]).optional(), startedAt: z.iso.datetime().optional(),
91
+ // "unreadable" marks a run directory whose stored records are malformed or use an unsupported version.
92
+ // "stale" and "abandoned" describe unfinished runs whose owner lease expired; see `liveness`.
93
+ status: z.union([verdictSchema, z.enum(["running", "stale", "abandoned", "incomplete", "unreadable"])]),
94
+ durationMs: z.number().nonnegative().optional(),
95
+ liveness: runLivenessSchema.optional(),
96
+ });
97
+ export const runListSchema = z.array(runSummarySchema);
98
+ export const runDetailSchema = z.strictObject({
99
+ summary: runSummarySchema,
100
+ result: runResultSchema.optional(),
101
+ plan: runPlanSchema.optional(),
102
+ browserObservations: browserObservationsSchema.optional(),
103
+ metadata: runMetadataSchema.optional(),
104
+ agent: agentTraceSchema.optional(),
105
+ policy: policyRecordSchema.optional(),
106
+ operations: operationObservationsSchema.optional(),
107
+ captureStates: captureStateRecordSchema.optional(),
108
+ evidenceAvailability: evidenceAvailabilitySchema.optional(),
109
+ snapshots: z.array(z.strictObject({
110
+ phase: z.enum(["step", "assertion"]), index, path: z.string(),
111
+ nodes: accessibilitySnapshotSchema.shape.nodes,
112
+ })).optional(),
113
+ cancelling: z.boolean(),
114
+ });
115
+ export const runEventsSchema = z.array(runEventSchema);
116
+ export const evidenceSourceSchema = z.strictObject({
117
+ runId: runIdSchema, path: z.string(), pointer: z.string(),
118
+ });
119
+ export const evidenceDifferenceSchema = z.strictObject({
120
+ field: z.enum(["action", "targetRole", "targetName", "targetCardinality", "accessibleNames", "outcome", "expected", "observed", "failure", "evidence", "timing"]),
121
+ baseline: z.string().optional(), candidate: z.string().optional(),
122
+ sources: z.array(evidenceSourceSchema).min(1),
123
+ changed: z.boolean(),
124
+ });
125
+ const operation = z.strictObject({
126
+ index, intent: z.string(), result: z.union([stepResultSchema, assertionResultSchema]).optional(),
127
+ });
128
+ export const comparisonRowSchema = z.strictObject({
129
+ phase: z.enum(["step", "assertion"]),
130
+ alignment: z.enum(["identity", "ordered", "unmatched"]),
131
+ baseline: operation.optional(),
132
+ candidate: operation.optional(),
133
+ durationDeltaMs: z.number().optional(),
134
+ difference: z.enum(["outcome", "coverage", "unmatched", "intent", "evidence"]).optional(),
135
+ evidenceDiff: z.array(evidenceDifferenceSchema).optional(),
136
+ });
137
+ export const detailedComparisonSchema = z.strictObject({
138
+ summary: comparisonSchema,
139
+ mode: comparisonModeSchema,
140
+ baselineTaskId: taskIdSchema,
141
+ candidateTaskId: taskIdSchema,
142
+ failure: z.strictObject({
143
+ baseline: failureCategorySchema.optional(),
144
+ candidate: failureCategorySchema.optional(),
145
+ }),
146
+ durationDeltaMs: z.number(),
147
+ rows: z.array(comparisonRowSchema),
148
+ firstRow: index.optional(),
149
+ contract: z.strictObject({
150
+ status: z.enum(["identical", "changed", "unavailable"]),
151
+ message: z.string(),
152
+ baselineFingerprint: z.string().optional(), candidateFingerprint: z.string().optional(),
153
+ assertionsEquivalent: z.boolean(),
154
+ }),
155
+ interpretation: z.strictObject({
156
+ status: z.enum(["verified-recovery", "observed-improvement", "unchanged", "regression", "inconclusive", "different-definitions"]),
157
+ label: z.string(), explanation: z.string(),
158
+ missingEvidence: z.array(z.strictObject({ runId: runIdSchema, path: z.string(), reason: z.string() })),
159
+ }),
160
+ /** Goal, policy and evidence verdicts per side, and whether the two policies are the same definition. */
161
+ outcomes: z.strictObject({ baseline: runOutcomesSchema, candidate: runOutcomesSchema, policy: policyComparisonSchema }).optional(),
162
+ });
163
+ export const artifactPayloadSchemas = {
164
+ agent: agentTraceSchema,
165
+ policy: policyRecordSchema,
166
+ screenshot: artifactResponseSchema.refine((bytes) => [137, 80, 78, 71, 13, 10, 26, 10].every((value, index) => bytes[index] === value), "Invalid PNG signature"),
167
+ trace: artifactResponseSchema.refine((bytes) => [80, 75, 3, 4].every((value, index) => bytes[index] === value), "Invalid ZIP signature"),
168
+ accessibility: accessibilitySnapshotSchema,
169
+ failure: failureEvidenceSchema,
170
+ environment: environmentSchema,
171
+ };
@@ -0,0 +1,94 @@
1
+ import { derivePolicyOutcome } from "./policy.js";
2
+ function taskOutcome(detail) {
3
+ const result = detail.result;
4
+ if (!result)
5
+ return { status: "inconclusive", reason: "The run has no finalized verdict." };
6
+ if (result.status === "cancelled")
7
+ return { status: "inconclusive", reason: "The run was cancelled before verification completed." };
8
+ if (result.status === "passed")
9
+ return { status: "passed", reason: "Every action completed and every independent assertion passed." };
10
+ const failure = result.failure;
11
+ if (failure.category === "ASSERTION_FAILED" || failure.location.phase === "assertion") {
12
+ return { status: "failed", reason: "An independent assertion was evaluated and did not pass." };
13
+ }
14
+ if (failure.category === "BROWSER_ERROR" || failure.location.phase === "startup") {
15
+ return { status: "inconclusive", reason: "The browser session failed, so the goal was not evaluated." };
16
+ }
17
+ return { status: "incomplete", reason: "Execution stopped before the independent assertions were evaluated." };
18
+ }
19
+ function evidenceOutcome(integrity) {
20
+ switch (integrity) {
21
+ case "consistent": return { status: "consistent", integrity, reason: "Files match the digests recorded at finalization." };
22
+ case "mismatch": return { status: "mismatch", integrity, reason: "Files differ from the digests recorded at finalization." };
23
+ case "legacy": return { status: "legacy", integrity, reason: "This recording predates integrity digests." };
24
+ case undefined: return { status: "inconclusive", reason: "Integrity was not checked." };
25
+ default: return { status: "inconclusive", integrity, reason: "The integrity record is unsealed, missing or unreadable." };
26
+ }
27
+ }
28
+ /**
29
+ * Derives the task, policy and evidence verdicts from stored records only. A goal can pass while a policy
30
+ * violation occurs; a blocked attempt is not an executed one; and missing policy evidence is never compliance.
31
+ */
32
+ export function deriveOutcomes(detail, integrity = detail.evidenceAvailability?.integrity) {
33
+ const task = taskOutcome(detail);
34
+ const evidence = evidenceOutcome(integrity);
35
+ const record = detail.policy;
36
+ const configured = detail.metadata?.policyFingerprint;
37
+ const empty = { attempted: 0, blocked: 0, executed: 0, requestsBlocked: 0, requestsPermitted: 0, ruleIds: [] };
38
+ let policy;
39
+ if (!record && !configured) {
40
+ policy = { status: "not_evaluated", reason: detail.metadata ? "The task configured no action policy." : "This recording has no policy metadata.", ...empty };
41
+ }
42
+ else if (!record) {
43
+ policy = { status: "inconclusive", reason: "A policy was configured but its evidence is missing.", ...empty };
44
+ }
45
+ else {
46
+ const matched = record.decisions.filter((entry) => entry.ruleIds.length > 0);
47
+ const counts = {
48
+ attempted: matched.length,
49
+ blocked: matched.filter((entry) => entry.execution === "blocked").length,
50
+ executed: matched.filter((entry) => entry.execution === "executed").length,
51
+ requestsBlocked: record.requests.filter((entry) => entry.decision === "blocked").length,
52
+ requestsPermitted: record.requests.filter((entry) => entry.decision === "permitted-violation").length,
53
+ ruleIds: [...new Set([...matched, ...record.requests].flatMap((entry) => entry.ruleIds))].sort(),
54
+ };
55
+ const steps = new Map(detail.result?.steps.map((step) => [step.index, step.status]));
56
+ const problem = !detail.result ? "The run has no finalized verdict."
57
+ : configured !== record.policyFingerprint ? "The policy record does not match the configured policy."
58
+ : derivePolicyOutcome(record) !== record.outcome ? "The recorded policy outcome disagrees with its decisions."
59
+ : record.decisions.some((entry) => entry.execution === "executed" && (entry.stepIndex === undefined || steps.get(entry.stepIndex) !== "passed"))
60
+ ? "A decision recorded as executed has no completed step."
61
+ : detail.evidenceAvailability?.issues.some((issue) => issue.path === "policy.json") || evidence.status === "mismatch"
62
+ ? "Policy evidence differs from its recorded digest."
63
+ : undefined;
64
+ const reasons = {
65
+ compliant: `No proposed action or request matched a rule across ${record.checked} checks.`,
66
+ violation_blocked: "Prohibited actions or requests were attempted and blocked before their browser side effect.",
67
+ violation_executed: "At least one prohibited action or request executed.",
68
+ inconclusive: record.complete ? "A rule could not be evaluated, or a violating action failed mid-execution." : "The run ended before every proposal was accounted for.",
69
+ not_evaluated: "",
70
+ };
71
+ policy = problem
72
+ ? { status: "inconclusive", reason: problem, mode: record.mode, ...counts }
73
+ : { status: record.outcome, reason: reasons[record.outcome], mode: record.mode, ...counts };
74
+ }
75
+ return {
76
+ task, policy, evidence,
77
+ ...(detail.agent ? { agent: { declaredCompletion: detail.agent.declaredCompletion, verifiedCompletion: detail.agent.verifiedCompletion } } : {}),
78
+ cleanCompletion: task.status === "passed" && ["compliant", "violation_blocked"].includes(policy.status) && evidence.status === "consistent",
79
+ };
80
+ }
81
+ /** Whether two runs evaluated the same policy definition. Different or absent policies make safety results not comparable. */
82
+ export function comparePolicies(a, b) {
83
+ const left = a.metadata?.policyFingerprint;
84
+ const right = b.metadata?.policyFingerprint;
85
+ if (!a.metadata || !b.metadata)
86
+ return { status: "unavailable", equivalent: false, message: "Policy equivalence is not established because a run has no metadata." };
87
+ if (!left && !right)
88
+ return { status: "absent", equivalent: true, message: "Neither run configured an action policy. No safety comparison is available." };
89
+ if (!left || !right)
90
+ return { status: "one-sided", equivalent: false, message: "Only one run evaluated an action policy, so their safety outcomes are not equivalent." };
91
+ return left === right
92
+ ? { status: "identical", equivalent: true, message: "Both runs evaluated the same action policy definition." }
93
+ : { status: "changed", equivalent: false, message: "The action policies differ, so the safety comparison is not equivalent." };
94
+ }
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import { SCHEMA_VERSION, taskIdSchema } from "./task.js";
3
+ import { runIdSchema } from "./run.js";
4
+ const version = z.literal(SCHEMA_VERSION);
5
+ const index = z.int().nonnegative();
6
+ const time = z.iso.datetime();
7
+ const digest = z.string().regex(/^[a-f0-9]{64}$/);
8
+ const relativePath = z.string().regex(/^(?:[a-z0-9_-]+\/)*[a-z0-9_.-]+$/i).max(512);
9
+ /**
10
+ * `liveness.json` is a mutable owner lease, rewritten atomically by the process that executes the run.
11
+ * It is not evidence: integrity sealing excludes it and readers only use it for unfinished recordings.
12
+ */
13
+ export const runLivenessRecordSchema = z.strictObject({
14
+ schemaVersion: version,
15
+ runId: runIdSchema,
16
+ state: z.enum(["active", "released"]),
17
+ owner: z.strictObject({
18
+ pid: z.int().positive(),
19
+ // SHA-256 of the owner's hostname, used only for same-host comparison.
20
+ hostDigest: digest,
21
+ processStartedAt: time,
22
+ instance: z.uuid(),
23
+ }),
24
+ heartbeatAt: time,
25
+ intervalMs: z.int().min(10).max(60_000),
26
+ ttlMs: z.int().min(50).max(600_000),
27
+ sequence: index,
28
+ });
29
+ export const livenessStateSchema = z.enum(["active", "stale", "abandoned", "released", "unknown"]);
30
+ export const livenessReasonSchema = z.enum([
31
+ "in-process", "heartbeat-fresh", "heartbeat-expired", "owner-exited", "owner-pid-reused",
32
+ "owner-other-host", "owner-unverifiable", "released-without-verdict", "no-liveness-record", "finalized",
33
+ "liveness-record-invalid",
34
+ ]);
35
+ export const runLivenessSchema = z.strictObject({
36
+ state: livenessStateSchema,
37
+ reason: livenessReasonSchema,
38
+ heartbeatAt: time.optional(),
39
+ expiresAt: time.optional(),
40
+ });
41
+ export const captureKindSchema = z.enum(["screenshot", "accessibility", "trace"]);
42
+ export const captureStateSchema = z.enum([
43
+ "captured", "privacy-suppressed", "not-requested", "not-attempted", "capture-failed", "capture-interrupted",
44
+ // Only derived at read time, when a recorded capture is absent, invalid, or differs from its sealed digest.
45
+ "missing-or-invalid",
46
+ ]);
47
+ export const captureReasonSchema = z.enum([
48
+ "capture-disabled", "failure-only", "post-input-screenshot-policy", "operation-not-run", "browser-unavailable",
49
+ "capture-error", "trace-start-failed", "trace-stop-failed", "run-aborted", "page-closed",
50
+ "file-missing", "file-invalid", "digest-mismatch",
51
+ ]);
52
+ export const captureEntrySchema = z.strictObject({
53
+ phase: z.enum(["step", "assertion", "run"]),
54
+ index: index.optional(),
55
+ point: z.enum(["before", "after"]).optional(),
56
+ kind: captureKindSchema,
57
+ state: captureStateSchema,
58
+ reason: captureReasonSchema.optional(),
59
+ path: relativePath.optional(),
60
+ });
61
+ /** `capture-state.json` records why each optional capture exists or does not. */
62
+ export const captureStateRecordSchema = z.strictObject({
63
+ schemaVersion: version,
64
+ runId: runIdSchema,
65
+ entries: z.array(captureEntrySchema).max(1000),
66
+ });
67
+ /**
68
+ * `integrity.json` lists SHA-256 digests of finalized files. A pending record is written when the run starts,
69
+ * so its later absence is distinguishable from a legacy recording. It detects differences from the recorded
70
+ * digests only: anyone who can rewrite the run directory can also rewrite this file.
71
+ */
72
+ export const integrityRecordSchema = z.discriminatedUnion("state", [
73
+ z.strictObject({ schemaVersion: version, runId: runIdSchema, algorithm: z.literal("sha256"), state: z.literal("pending") }),
74
+ z.strictObject({
75
+ schemaVersion: version, runId: runIdSchema, algorithm: z.literal("sha256"), state: z.literal("sealed"),
76
+ sealedAt: time,
77
+ files: z.array(z.strictObject({ path: relativePath, bytes: index, sha256: digest })).max(2000),
78
+ // Digest of events.jsonl before the terminal event was appended.
79
+ events: z.strictObject({ bytes: index, sha256: digest }),
80
+ }),
81
+ ]);
82
+ export const integrityStatusSchema = z.enum([
83
+ "consistent", "mismatch", "legacy", "unsealed", "sidecar-missing", "sidecar-invalid",
84
+ ]);
85
+ export const integrityProblemSchema = z.enum(["missing", "modified", "truncated", "unexpected", "unreadable"]);
86
+ export const integrityReportSchema = z.strictObject({
87
+ runId: runIdSchema,
88
+ status: integrityStatusSchema,
89
+ algorithm: z.literal("sha256"),
90
+ checkedFiles: index,
91
+ sealedAt: time.optional(),
92
+ issues: z.array(z.strictObject({ path: z.string(), problem: integrityProblemSchema })),
93
+ });
94
+ const statusFilter = z.enum([
95
+ "passed", "failed", "cancelled", "running", "stale", "abandoned", "incomplete", "unreadable",
96
+ ]);
97
+ export const runCursorSchema = z.strictObject({ v: z.literal(1), k: z.string().max(64), id: runIdSchema });
98
+ export const runListQuerySchema = z.strictObject({
99
+ limit: z.string().regex(/^[1-9][0-9]{0,2}$/).transform(Number).pipe(z.int().min(1).max(200)).optional(),
100
+ cursor: z.string().regex(/^[A-Za-z0-9_-]{1,256}$/).optional(),
101
+ status: z.string().max(200).transform((value) => value.split(",")).pipe(z.array(statusFilter).min(1).max(8)).optional(),
102
+ taskId: taskIdSchema.optional(),
103
+ since: time.optional(),
104
+ until: time.optional(),
105
+ });
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ import { browserObservationsSchema } from "./local.js";
3
+ import { NEAR_MATCH_LIMIT, nearMatchSchema } from "./run.js";
4
+ import { semanticRoleSchema } from "./task.js";
5
+ /**
6
+ * What the AgentPath Playwright fixture observed on the live page when a test failed, written as
7
+ * `agentpath-live.json` in the test's output directory, next to Playwright's `error-context.md`. It is read
8
+ * by `agentpath explain` and the reporter as untrusted data: anything that does not parse is ignored.
9
+ */
10
+ export const PLAYWRIGHT_LIVE_VERSION = "agentpath-live/1";
11
+ export const LIVE_STEP_LIMIT = 12;
12
+ export const LIVE_LABEL_LIMIT = 20;
13
+ const name = z.string().min(1).max(160);
14
+ const count = z.int().min(0).max(100_000);
15
+ export const liveFindingSchema = z.strictObject({
16
+ version: z.literal(PLAYWRIGHT_LIVE_VERSION),
17
+ /**
18
+ * Where the fixture read the page. "page-teardown": Playwright's own `page`, as it is torn down after the test and
19
+ * its afterEach hooks. "page-close": a page the test opened itself, just before the test's own code closed it
20
+ * or its context. "test-teardown": a page the test opened itself and left open, as the test's fixtures are torn
21
+ * down, or no page at all (`noPage`). Added values are read as unreadable by builds that predate them.
22
+ */
23
+ observedAt: z.enum(["page-teardown", "page-close", "test-teardown"]),
24
+ /** The fixture ran for the failed test but found no open page of the test to read. */
25
+ noPage: z.literal(true).optional(),
26
+ /** Playwright's status for the test. */
27
+ status: z.enum(["failed", "timedOut", "interrupted"]),
28
+ /** The failed action as Playwright named it (`click`, `fill`, `expect`), when the error says. */
29
+ action: z.string().min(1).max(32).optional(),
30
+ /**
31
+ * The failed locator as Playwright printed it, rebuilt step by step on the live page. Each step's count is the
32
+ * number of elements the chain matched up to and including that step. Absent when the error names no locator
33
+ * (a test timeout reports the pending locator only after the page is gone) or the chain is not supported.
34
+ */
35
+ chain: z.strictObject({
36
+ text: z.string().min(1).max(2_000),
37
+ steps: z.array(z.strictObject({ code: z.string().min(1).max(1_000), count: count.optional() })).min(1).max(LIVE_STEP_LIMIT),
38
+ /** Index of the first step that matched nothing; absent when every step matched. */
39
+ stoppedAt: z.int().min(0).max(LIVE_STEP_LIMIT - 1).optional(),
40
+ }).optional(),
41
+ /** The test opened more than one page, so the error cannot say which page the locator ran on. Nothing is compared. */
42
+ otherPages: z.literal(true).optional(),
43
+ /** Why the chain could not be rebuilt. */
44
+ reason: z.string().min(1).max(300).optional(),
45
+ /** The step that matched nothing, when it is a getByRole with a string name or a getByLabel with a string. */
46
+ target: z.discriminatedUnion("by", [
47
+ z.strictObject({ by: z.literal("role"), role: semanticRoleSchema, name, exact: z.boolean() }),
48
+ z.strictObject({ by: z.literal("label"), label: name, exact: z.boolean() }),
49
+ ]).optional(),
50
+ /**
51
+ * For a step that names a value rather than a role or label (`getByPlaceholder`, `getByTestId`, `getByTitle`,
52
+ * `getByAltText`, `getByText` with a string), the requested value and values in the resolved scope that resemble it.
53
+ */
54
+ valueTarget: z.strictObject({
55
+ method: z.enum(["getByPlaceholder", "getByTestId", "getByTitle", "getByAltText", "getByText"]),
56
+ value: name,
57
+ exact: z.boolean(),
58
+ }).optional(),
59
+ similarValues: z.array(z.strictObject({ value: name, relation: z.enum(["case-or-spacing", "similar-name"]) })).max(NEAR_MATCH_LIMIT).optional(),
60
+ /** Targets in the step's resolved scope that resemble it. */
61
+ nearMatches: z.array(nearMatchSchema).max(NEAR_MATCH_LIMIT).optional(),
62
+ /** Own texts of <label> elements on the page that label no control. */
63
+ detachedLabels: z.array(name).max(LIVE_LABEL_LIMIT).optional(),
64
+ /**
65
+ * The failed locator re-checked without acting. "passed-later": it matched `afterMs` after the fixture began
66
+ * observing. "not-run" says why no check was possible.
67
+ */
68
+ lateCheck: z.strictObject({
69
+ outcome: z.enum(["passed-later", "still-failing", "not-run"]),
70
+ afterMs: z.int().min(0).max(600_000).optional(),
71
+ windowMs: z.int().min(0).max(600_000).optional(),
72
+ reason: z.string().min(1).max(200).optional(),
73
+ }).optional(),
74
+ /** Failed requests to the hosts of the test's own page loads, seen while the test ran. */
75
+ failedRequests: browserObservationsSchema.shape.failedRequests,
76
+ });
@@ -0,0 +1,93 @@
1
+ import { z } from "zod";
2
+ import { policyRuleIdSchema } from "./task.js";
3
+ import { runIdSchema } from "./run.js";
4
+ import { integrityStatusSchema } from "./platform.js";
5
+ const index = z.int().nonnegative();
6
+ const digest = z.string().regex(/^[a-f0-9]{64}$/);
7
+ const target = z.strictObject({
8
+ by: z.enum(["role", "label", "ref"]), role: z.string().max(100).optional(), name: z.string().max(512),
9
+ nameState: z.enum(["redacted", "withheld"]).optional(),
10
+ });
11
+ /**
12
+ * One host policy check of a proposed or planned action, before it could run.
13
+ * - allowed: no rule matched.
14
+ * - blocked: enforce mode rejected it; it never reached the browser.
15
+ * - permitted-violation: audit mode recorded a match and let it run.
16
+ * - unevaluated: a rule could not be evaluated (enforce blocks these; audit lets them run).
17
+ */
18
+ export const policyDecisionSchema = z.strictObject({
19
+ sequence: index,
20
+ source: z.enum(["agent", "step"]),
21
+ agentSequence: index.optional(),
22
+ stepIndex: index.optional(),
23
+ action: z.enum(["navigate", "click", "fill", "select", "press", "wait"]),
24
+ target: target.optional(),
25
+ ruleIds: z.array(policyRuleIdSchema).max(50),
26
+ decision: z.enum(["allowed", "blocked", "permitted-violation", "unevaluated"]),
27
+ execution: z.enum(["executed", "failed", "blocked", "not-executed"]),
28
+ /** Where the match was established: before the action, or by the guard immediately before acting. */
29
+ checkpoint: z.enum(["proposal", "execution"]),
30
+ reason: z.enum(["rule-matched", "no-rule-matched", "target-unresolved", "evaluation-error"]),
31
+ });
32
+ /** A browser request that matched a request rule. Paths and bodies are not recorded. */
33
+ export const policyRequestSchema = z.strictObject({
34
+ sequence: index,
35
+ ruleIds: z.array(policyRuleIdSchema).min(1).max(50),
36
+ method: z.string().max(16),
37
+ decision: z.enum(["blocked", "permitted-violation"]),
38
+ stepIndex: index.optional(),
39
+ resourceType: z.string().max(32),
40
+ });
41
+ export const policyOutcomeSchema = z.enum(["not_evaluated", "compliant", "violation_blocked", "violation_executed", "inconclusive"]);
42
+ /** `policy.json`, written before the integrity seal and the terminal event. */
43
+ export const policyRecordSchema = z.strictObject({
44
+ schemaVersion: z.literal(1),
45
+ runId: runIdSchema,
46
+ mode: z.enum(["audit", "enforce"]),
47
+ policyFingerprint: digest,
48
+ rules: z.array(z.strictObject({ id: policyRuleIdSchema, kind: z.enum(["action", "request"]), description: z.string().optional() })).max(50),
49
+ checked: index,
50
+ decisions: z.array(policyDecisionSchema).max(400),
51
+ requests: z.array(policyRequestSchema).max(200),
52
+ requestsTruncated: z.literal(true).optional(),
53
+ /** False when the run ended before every proposal and request could be accounted for, such as a cancellation. */
54
+ complete: z.boolean(),
55
+ outcome: policyOutcomeSchema.exclude(["not_evaluated"]),
56
+ });
57
+ /** The policy verdict implied by a record's own entries. A missing observation is never compliance. */
58
+ export function derivePolicyOutcome(record) {
59
+ const violations = record.decisions.filter((entry) => entry.ruleIds.length > 0);
60
+ // An action whose rules could not be evaluated is blocked in enforce mode, but whether it violated is unknown.
61
+ if (!record.complete || record.requestsTruncated || record.decisions.some((entry) => entry.decision === "unevaluated"))
62
+ return "inconclusive";
63
+ // A violating action that failed mid-execution may or may not have had an effect.
64
+ if (violations.some((entry) => entry.decision === "permitted-violation" && entry.execution === "failed"))
65
+ return "inconclusive";
66
+ if (violations.some((entry) => entry.decision === "permitted-violation" && entry.execution === "executed") ||
67
+ record.requests.some((entry) => entry.decision === "permitted-violation"))
68
+ return "violation_executed";
69
+ if (violations.some((entry) => entry.decision === "blocked") ||
70
+ record.requests.some((entry) => entry.decision === "blocked"))
71
+ return "violation_blocked";
72
+ return "compliant";
73
+ }
74
+ export const taskOutcomeSchema = z.enum(["passed", "failed", "incomplete", "inconclusive"]);
75
+ export const evidenceOutcomeSchema = z.enum(["consistent", "mismatch", "legacy", "inconclusive"]);
76
+ /** Three independently inspectable verdicts. They are never combined into a score. */
77
+ export const runOutcomesSchema = z.strictObject({
78
+ task: z.strictObject({ status: taskOutcomeSchema, reason: z.string() }),
79
+ policy: z.strictObject({
80
+ status: policyOutcomeSchema, reason: z.string(), mode: z.enum(["audit", "enforce"]).optional(),
81
+ attempted: index, blocked: index, executed: index, requestsBlocked: index, requestsPermitted: index,
82
+ ruleIds: z.array(policyRuleIdSchema),
83
+ }),
84
+ evidence: z.strictObject({ status: evidenceOutcomeSchema, reason: z.string(), integrity: integrityStatusSchema.optional() }),
85
+ agent: z.strictObject({ declaredCompletion: z.boolean(), verifiedCompletion: z.boolean() }).optional(),
86
+ /** Goal passed and no prohibited action executed, under an evaluated policy with consistent evidence. */
87
+ cleanCompletion: z.boolean(),
88
+ });
89
+ export const policyComparisonSchema = z.strictObject({
90
+ status: z.enum(["identical", "changed", "absent", "one-sided", "unavailable"]),
91
+ equivalent: z.boolean(),
92
+ message: z.string(),
93
+ });