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,177 @@
1
+ import { chmod, lstat, mkdir, rm, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ /** Derived, rebuildable listing cache. Canonical run files remain the source of truth. */
4
+ export const INDEX_DIRECTORY = ".index";
5
+ export const INDEX_VERSION = 1;
6
+ const INDEX_FILE = `runs-v${INDEX_VERSION}.sqlite`;
7
+ let sqlite;
8
+ /** Loads the built-in binding lazily so an unsupported runtime falls back to a directory scan. */
9
+ function binding() {
10
+ sqlite ??= import("node:sqlite").catch(() => undefined);
11
+ return sqlite;
12
+ }
13
+ /** Errors other than lock contention mean the index file cannot be trusted and should be rebuilt. */
14
+ export function isIndexCorruption(error) {
15
+ const code = error?.errcode;
16
+ return typeof code === "number" && ![5, 6].includes(code & 0xff);
17
+ }
18
+ const SCHEMA = `
19
+ CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL) WITHOUT ROWID;
20
+ CREATE TABLE IF NOT EXISTS runs (
21
+ run_id TEXT PRIMARY KEY,
22
+ task_id TEXT,
23
+ started_at TEXT,
24
+ sort_key TEXT NOT NULL,
25
+ record TEXT NOT NULL CHECK (record IN ('passed', 'failed', 'cancelled', 'unfinished', 'unreadable')),
26
+ duration_ms REAL,
27
+ signature TEXT NOT NULL,
28
+ indexed_at TEXT NOT NULL
29
+ ) WITHOUT ROWID;
30
+ CREATE INDEX IF NOT EXISTS runs_order ON runs (sort_key DESC, run_id DESC);
31
+ CREATE INDEX IF NOT EXISTS runs_task ON runs (task_id, sort_key DESC, run_id DESC);
32
+ CREATE INDEX IF NOT EXISTS runs_record ON runs (record, sort_key DESC, run_id DESC);
33
+ `;
34
+ export class RunIndex {
35
+ db;
36
+ #closed = false;
37
+ constructor(db) {
38
+ this.db = db;
39
+ }
40
+ static path(root) {
41
+ return join(root, INDEX_DIRECTORY, INDEX_FILE);
42
+ }
43
+ /**
44
+ * Opens the index for one operation. Returns undefined when the runs root is absent or is not a real
45
+ * directory, or when the runtime has no SQLite binding.
46
+ */
47
+ static async open(root) {
48
+ const module = await binding();
49
+ if (!module)
50
+ return;
51
+ try {
52
+ if (!(await lstat(root)).isDirectory())
53
+ return;
54
+ }
55
+ catch {
56
+ return;
57
+ }
58
+ const directory = join(root, INDEX_DIRECTORY);
59
+ await mkdir(directory, { mode: 0o700, recursive: true });
60
+ if (!(await lstat(directory)).isDirectory())
61
+ return;
62
+ // Create the file owner-only first; SQLite gives its -wal and -shm files the same mode.
63
+ await writeFile(RunIndex.path(root), "", { flag: "a", mode: 0o600 });
64
+ await chmod(RunIndex.path(root), 0o600).catch(() => { });
65
+ try {
66
+ return RunIndex.connect(module, root);
67
+ }
68
+ catch (error) {
69
+ if (!isIndexCorruption(error))
70
+ throw error;
71
+ // A corrupt or incompatible file is discarded: every row can be derived again from the run directories.
72
+ await RunIndex.destroy(root);
73
+ await writeFile(RunIndex.path(root), "", { flag: "a", mode: 0o600 });
74
+ return RunIndex.connect(module, root);
75
+ }
76
+ }
77
+ static connect(module, root) {
78
+ const db = new module.DatabaseSync(RunIndex.path(root));
79
+ try {
80
+ db.exec("PRAGMA busy_timeout = 5000");
81
+ db.exec("PRAGMA journal_mode = WAL");
82
+ db.exec("PRAGMA synchronous = NORMAL");
83
+ const version = db.prepare("PRAGMA user_version").get().user_version;
84
+ if (version !== 0 && version !== INDEX_VERSION) {
85
+ throw Object.assign(new Error("Unsupported run index version."), { errcode: 26 });
86
+ }
87
+ db.exec(SCHEMA);
88
+ db.exec(`PRAGMA user_version = ${INDEX_VERSION}`);
89
+ return new RunIndex(db);
90
+ }
91
+ catch (error) {
92
+ db.close();
93
+ throw error;
94
+ }
95
+ }
96
+ /** Removes the index and its SQLite journal files. */
97
+ static async destroy(root) {
98
+ const path = RunIndex.path(root);
99
+ await Promise.all(["", "-wal", "-shm", "-journal"].map((suffix) => rm(path + suffix, { force: true })));
100
+ }
101
+ close() {
102
+ if (this.#closed)
103
+ return;
104
+ this.#closed = true;
105
+ this.db.close();
106
+ }
107
+ signatures() {
108
+ const rows = this.db.prepare("SELECT run_id, record, signature FROM runs").all();
109
+ return new Map(rows.map((row) => [row.run_id, { record: row.record, signature: row.signature }]));
110
+ }
111
+ /** Applies changes in one transaction, so an interrupted update leaves the previous state intact. */
112
+ apply(upserts, deletes = [], replace = false) {
113
+ const insert = this.db.prepare(`
114
+ INSERT INTO runs (run_id, task_id, started_at, sort_key, record, duration_ms, signature, indexed_at)
115
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
116
+ ON CONFLICT (run_id) DO UPDATE SET task_id = excluded.task_id, started_at = excluded.started_at,
117
+ sort_key = excluded.sort_key, record = excluded.record, duration_ms = excluded.duration_ms,
118
+ signature = excluded.signature, indexed_at = excluded.indexed_at`);
119
+ const remove = this.db.prepare("DELETE FROM runs WHERE run_id = ?");
120
+ const now = new Date().toISOString();
121
+ this.db.exec("BEGIN IMMEDIATE");
122
+ try {
123
+ if (replace)
124
+ this.db.exec("DELETE FROM runs");
125
+ for (const id of deletes)
126
+ remove.run(id);
127
+ for (const row of upserts) {
128
+ insert.run(row.runId, row.taskId ?? null, row.startedAt ?? null, row.startedAt ?? "", row.record, row.durationMs ?? null, row.signature, now);
129
+ }
130
+ this.db.prepare("INSERT OR REPLACE INTO meta (key, value) VALUES ('updatedAt', ?)").run(now);
131
+ this.db.exec("COMMIT");
132
+ }
133
+ catch (error) {
134
+ this.db.exec("ROLLBACK");
135
+ throw error;
136
+ }
137
+ }
138
+ count() {
139
+ return this.db.prepare("SELECT COUNT(*) AS count FROM runs").get().count;
140
+ }
141
+ /** Keyset page ordered by start time (missing times last), then run ID, both descending. */
142
+ page(query) {
143
+ const where = [];
144
+ const values = [];
145
+ if (query.records?.length) {
146
+ where.push(`record IN (${query.records.map(() => "?").join(", ")})`);
147
+ values.push(...query.records);
148
+ }
149
+ if (query.taskId) {
150
+ where.push("task_id = ?");
151
+ values.push(query.taskId);
152
+ }
153
+ if (query.since) {
154
+ where.push("sort_key >= ?");
155
+ values.push(query.since);
156
+ }
157
+ if (query.until) {
158
+ where.push("sort_key <> '' AND sort_key < ?");
159
+ values.push(query.until);
160
+ }
161
+ if (query.after) {
162
+ // A row value lets SQLite seek in runs_order; the equivalent OR form scanned the index from the top on every
163
+ // page, so a page 250 deep in 50,000 runs took 39 ms in SQL instead of under 1 ms.
164
+ where.push("(sort_key, run_id) < (?, ?)");
165
+ values.push(query.after.k, query.after.id);
166
+ }
167
+ values.push(query.limit);
168
+ const rows = this.db.prepare(`SELECT run_id, task_id, started_at, record, duration_ms, signature FROM runs
169
+ ${where.length ? `WHERE ${where.join(" AND ")}` : ""} ORDER BY sort_key DESC, run_id DESC LIMIT ?`).all(...values);
170
+ return rows.map((row) => ({
171
+ runId: row.run_id, record: row.record, signature: row.signature,
172
+ ...(row.task_id === null ? {} : { taskId: row.task_id }),
173
+ ...(row.started_at === null ? {} : { startedAt: row.started_at }),
174
+ ...(row.duration_ms === null ? {} : { durationMs: row.duration_ms }),
175
+ }));
176
+ }
177
+ }
@@ -0,0 +1,28 @@
1
+ import { createHash } from "node:crypto";
2
+ import { runPlanSchema, SCHEMA_VERSION } from "#agentpath/contracts";
3
+ export function recordPlan(task, recorder) {
4
+ function describe(kind, locator, suffix = "") {
5
+ const target = locator?.by === "role"
6
+ ? locator.name === undefined ? `the only ${locator.role}` : `${locator.role} “${recorder.redact(locator.name)}”`
7
+ : locator ? `label “${recorder.redact(locator.label)}”` : "";
8
+ const key = createHash("sha256").update(JSON.stringify([kind, locator ?? null])).digest("hex");
9
+ const recordedTarget = locator && {
10
+ by: locator.by, role: locator.by === "role" ? locator.role : undefined,
11
+ // An empty name without a name state means the target named no accessible name.
12
+ name: recorder.redact(locator.by === "role" ? locator.name ?? "" : locator.label),
13
+ nameState: recorder.redact(locator.by === "role" ? locator.name ?? "" : locator.label) === "[redacted]" ? "redacted" : undefined,
14
+ };
15
+ return { kind, key, expectation: kind === "count" ? `Exactly ${suffix} matching elements.`
16
+ : kind === "text" ? "One visible matching element contains the configured text."
17
+ : kind === "url" ? "The current URL matches the configured pattern."
18
+ : kind === "visible" ? "One matching element is visible."
19
+ : kind === "wait" ? `The semantic target reaches the ${suffix} state.`
20
+ : kind === "navigate" ? "Load the configured destination."
21
+ : "Complete the configured action on one exact semantic target.", target: recordedTarget, intent: [kind, target, suffix].filter(Boolean).join(" · ") };
22
+ }
23
+ return runPlanSchema.parse({
24
+ schemaVersion: SCHEMA_VERSION, identityVersion: 2,
25
+ steps: task.steps.map((step) => describe(step.action, "target" in step ? step.target : undefined, step.action === "wait" ? step.state : "")),
26
+ assertions: task.assertions.map((assertion) => describe(assertion.assert, "target" in assertion ? assertion.target : undefined, assertion.assert === "count" ? String(assertion.count) : "")),
27
+ });
28
+ }