@plune-ai/cairn 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -8
- package/dist/agent/check-docs.d.ts +25 -0
- package/dist/agent/check-docs.d.ts.map +1 -0
- package/dist/agent/check-docs.js +57 -0
- package/dist/agent/check-docs.js.map +1 -0
- package/dist/agent/collect-docs.d.ts +94 -0
- package/dist/agent/collect-docs.d.ts.map +1 -0
- package/dist/agent/collect-docs.js +326 -0
- package/dist/agent/collect-docs.js.map +1 -0
- package/dist/agent/graph.d.ts +39 -2
- package/dist/agent/graph.d.ts.map +1 -1
- package/dist/agent/graph.js +113 -4
- package/dist/agent/graph.js.map +1 -1
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +114 -10
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/overlays.d.ts +88 -0
- package/dist/agent/overlays.d.ts.map +1 -0
- package/dist/agent/overlays.js +447 -0
- package/dist/agent/overlays.js.map +1 -0
- package/dist/agent/repair-loop.d.ts +8 -1
- package/dist/agent/repair-loop.d.ts.map +1 -1
- package/dist/agent/repair-loop.js +18 -3
- package/dist/agent/repair-loop.js.map +1 -1
- package/dist/analyze/index.d.ts +1 -1
- package/dist/analyze/index.d.ts.map +1 -1
- package/dist/analyze/index.js +3 -2
- package/dist/analyze/index.js.map +1 -1
- package/dist/api/adversarial.d.ts +1 -1
- package/dist/api/adversarial.js +1 -1
- package/dist/api/collection.d.ts +20 -0
- package/dist/api/collection.d.ts.map +1 -0
- package/dist/api/collection.js +357 -0
- package/dist/api/collection.js.map +1 -0
- package/dist/api/derived.d.ts +179 -0
- package/dist/api/derived.d.ts.map +1 -0
- package/dist/api/derived.js +852 -0
- package/dist/api/derived.js.map +1 -0
- package/dist/api/discover.d.ts +66 -0
- package/dist/api/discover.d.ts.map +1 -0
- package/dist/api/discover.js +125 -0
- package/dist/api/discover.js.map +1 -0
- package/dist/api/flows.d.ts +194 -0
- package/dist/api/flows.d.ts.map +1 -0
- package/dist/api/flows.js +663 -0
- package/dist/api/flows.js.map +1 -0
- package/dist/api/guard.d.ts +19 -0
- package/dist/api/guard.d.ts.map +1 -1
- package/dist/api/guard.js +18 -4
- package/dist/api/guard.js.map +1 -1
- package/dist/api/openapi.d.ts +17 -1
- package/dist/api/openapi.d.ts.map +1 -1
- package/dist/api/openapi.js +64 -3
- package/dist/api/openapi.js.map +1 -1
- package/dist/api/runner.d.ts.map +1 -1
- package/dist/api/runner.js +18 -14
- package/dist/api/runner.js.map +1 -1
- package/dist/api/two-actor.d.ts +165 -0
- package/dist/api/two-actor.d.ts.map +1 -0
- package/dist/api/two-actor.js +627 -0
- package/dist/api/two-actor.js.map +1 -0
- package/dist/artifacts/contract.d.ts +1 -1
- package/dist/artifacts/contract.d.ts.map +1 -1
- package/dist/artifacts/index.d.ts +5 -0
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +14 -10
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/report.d.ts +29 -2
- package/dist/artifacts/report.d.ts.map +1 -1
- package/dist/artifacts/report.js +65 -1
- package/dist/artifacts/report.js.map +1 -1
- package/dist/artifacts/testcase-md.d.ts +18 -0
- package/dist/artifacts/testcase-md.d.ts.map +1 -1
- package/dist/artifacts/testcase-md.js +15 -1
- package/dist/artifacts/testcase-md.js.map +1 -1
- package/dist/browser/api-traffic.d.ts +85 -0
- package/dist/browser/api-traffic.d.ts.map +1 -0
- package/dist/browser/api-traffic.js +283 -0
- package/dist/browser/api-traffic.js.map +1 -0
- package/dist/browser/backends/playwright-cli.d.ts.map +1 -1
- package/dist/browser/backends/playwright-cli.js +3 -0
- package/dist/browser/backends/playwright-cli.js.map +1 -1
- package/dist/browser/backends/playwright-lib.d.ts +84 -1
- package/dist/browser/backends/playwright-lib.d.ts.map +1 -1
- package/dist/browser/backends/playwright-lib.js +677 -32
- package/dist/browser/backends/playwright-lib.js.map +1 -1
- package/dist/browser/click-effect.d.ts +84 -0
- package/dist/browser/click-effect.d.ts.map +1 -0
- package/dist/browser/click-effect.js +235 -0
- package/dist/browser/click-effect.js.map +1 -0
- package/dist/browser/gateway.d.ts +9 -1
- package/dist/browser/gateway.d.ts.map +1 -1
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +5 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types.d.ts +196 -1
- package/dist/browser/types.d.ts.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +123 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/codegen/index.d.ts +10 -1
- package/dist/codegen/index.d.ts.map +1 -1
- package/dist/codegen/index.js +28 -7
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/lint.d.ts +32 -1
- package/dist/codegen/lint.d.ts.map +1 -1
- package/dist/codegen/lint.js +286 -1
- package/dist/codegen/lint.js.map +1 -1
- package/dist/codegen/mailbox.d.ts +19 -0
- package/dist/codegen/mailbox.d.ts.map +1 -0
- package/dist/codegen/mailbox.js +78 -0
- package/dist/codegen/mailbox.js.map +1 -0
- package/dist/codegen/schema.d.ts.map +1 -1
- package/dist/codegen/schema.js +3 -2
- package/dist/codegen/schema.js.map +1 -1
- package/dist/config/profiles.d.ts +2 -0
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +2 -0
- package/dist/config/profiles.js.map +1 -1
- package/dist/core/modalities/api.d.ts.map +1 -1
- package/dist/core/modalities/api.js +265 -29
- package/dist/core/modalities/api.js.map +1 -1
- package/dist/core/modalities/check-docs.d.ts +3 -0
- package/dist/core/modalities/check-docs.d.ts.map +1 -0
- package/dist/core/modalities/check-docs.js +64 -0
- package/dist/core/modalities/check-docs.js.map +1 -0
- package/dist/core/modalities/collect-docs.d.ts +3 -0
- package/dist/core/modalities/collect-docs.d.ts.map +1 -0
- package/dist/core/modalities/collect-docs.js +48 -0
- package/dist/core/modalities/collect-docs.js.map +1 -0
- package/dist/core/modalities/explore.d.ts.map +1 -1
- package/dist/core/modalities/explore.js +2 -0
- package/dist/core/modalities/explore.js.map +1 -1
- package/dist/core/modalities/mcp-test.d.ts +3 -0
- package/dist/core/modalities/mcp-test.d.ts.map +1 -0
- package/dist/core/modalities/mcp-test.js +26 -0
- package/dist/core/modalities/mcp-test.js.map +1 -0
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +11 -3
- package/dist/core/registry.js.map +1 -1
- package/dist/decider/uses/repair-triage.d.ts +9 -0
- package/dist/decider/uses/repair-triage.d.ts.map +1 -1
- package/dist/decider/uses/repair-triage.js +20 -3
- package/dist/decider/uses/repair-triage.js.map +1 -1
- package/dist/design/critique.d.ts +1 -1
- package/dist/design/index.d.ts +7 -1
- package/dist/design/index.d.ts.map +1 -1
- package/dist/design/index.js +20 -2
- package/dist/design/index.js.map +1 -1
- package/dist/design/schema.d.ts +9 -3
- package/dist/design/schema.d.ts.map +1 -1
- package/dist/design/schema.js +4 -1
- package/dist/design/schema.js.map +1 -1
- package/dist/documentarian/check.d.ts +91 -0
- package/dist/documentarian/check.d.ts.map +1 -0
- package/dist/documentarian/check.js +230 -0
- package/dist/documentarian/check.js.map +1 -0
- package/dist/documentarian/docs.d.ts +103 -0
- package/dist/documentarian/docs.d.ts.map +1 -0
- package/dist/documentarian/docs.js +243 -0
- package/dist/documentarian/docs.js.map +1 -0
- package/dist/documentarian/index.d.ts +2 -0
- package/dist/documentarian/index.d.ts.map +1 -1
- package/dist/documentarian/index.js +5 -4
- package/dist/documentarian/index.js.map +1 -1
- package/dist/environment/apply.js +1 -1
- package/dist/environment/apply.js.map +1 -1
- package/dist/flow/crawl.d.ts +4 -0
- package/dist/flow/crawl.d.ts.map +1 -1
- package/dist/flow/crawl.js +9 -2
- package/dist/flow/crawl.js.map +1 -1
- package/dist/fs/inside-dir.d.ts +8 -0
- package/dist/fs/inside-dir.d.ts.map +1 -0
- package/dist/fs/inside-dir.js +15 -0
- package/dist/fs/inside-dir.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/structured.d.ts +19 -0
- package/dist/llm/structured.d.ts.map +1 -1
- package/dist/llm/structured.js +61 -0
- package/dist/llm/structured.js.map +1 -1
- package/dist/mailbox/doctor.d.ts +10 -0
- package/dist/mailbox/doctor.d.ts.map +1 -0
- package/dist/mailbox/doctor.js +33 -0
- package/dist/mailbox/doctor.js.map +1 -0
- package/dist/mailbox/rule.d.ts +34 -0
- package/dist/mailbox/rule.d.ts.map +1 -0
- package/dist/mailbox/rule.js +47 -0
- package/dist/mailbox/rule.js.map +1 -0
- package/dist/mailbox/session.d.ts +5 -0
- package/dist/mailbox/session.d.ts.map +1 -1
- package/dist/mailbox/session.js +8 -0
- package/dist/mailbox/session.js.map +1 -1
- package/dist/mcp/server.d.ts +15 -5
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +75 -27
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +194 -82
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +82 -8
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp-test/adversarial.d.ts +80 -0
- package/dist/mcp-test/adversarial.d.ts.map +1 -0
- package/dist/mcp-test/adversarial.js +99 -0
- package/dist/mcp-test/adversarial.js.map +1 -0
- package/dist/mcp-test/advice.d.ts +20 -0
- package/dist/mcp-test/advice.d.ts.map +1 -0
- package/dist/mcp-test/advice.js +22 -0
- package/dist/mcp-test/advice.js.map +1 -0
- package/dist/mcp-test/call.d.ts +76 -0
- package/dist/mcp-test/call.d.ts.map +1 -0
- package/dist/mcp-test/call.js +105 -0
- package/dist/mcp-test/call.js.map +1 -0
- package/dist/mcp-test/cases.d.ts +154 -0
- package/dist/mcp-test/cases.d.ts.map +1 -0
- package/dist/mcp-test/cases.js +643 -0
- package/dist/mcp-test/cases.js.map +1 -0
- package/dist/mcp-test/connect.d.ts +70 -0
- package/dist/mcp-test/connect.d.ts.map +1 -0
- package/dist/mcp-test/connect.js +426 -0
- package/dist/mcp-test/connect.js.map +1 -0
- package/dist/mcp-test/coverage.d.ts +61 -0
- package/dist/mcp-test/coverage.d.ts.map +1 -0
- package/dist/mcp-test/coverage.js +76 -0
- package/dist/mcp-test/coverage.js.map +1 -0
- package/dist/mcp-test/discover.d.ts +40 -0
- package/dist/mcp-test/discover.d.ts.map +1 -0
- package/dist/mcp-test/discover.js +149 -0
- package/dist/mcp-test/discover.js.map +1 -0
- package/dist/mcp-test/guard.d.ts +161 -0
- package/dist/mcp-test/guard.d.ts.map +1 -0
- package/dist/mcp-test/guard.js +363 -0
- package/dist/mcp-test/guard.js.map +1 -0
- package/dist/mcp-test/model.d.ts +89 -0
- package/dist/mcp-test/model.d.ts.map +1 -0
- package/dist/mcp-test/model.js +88 -0
- package/dist/mcp-test/model.js.map +1 -0
- package/dist/mcp-test/payloads.d.ts +20 -0
- package/dist/mcp-test/payloads.d.ts.map +1 -0
- package/dist/mcp-test/payloads.js +20 -0
- package/dist/mcp-test/payloads.js.map +1 -0
- package/dist/mcp-test/report.d.ts +55 -0
- package/dist/mcp-test/report.d.ts.map +1 -0
- package/dist/mcp-test/report.js +157 -0
- package/dist/mcp-test/report.js.map +1 -0
- package/dist/mcp-test/run.d.ts +68 -0
- package/dist/mcp-test/run.d.ts.map +1 -0
- package/dist/mcp-test/run.js +467 -0
- package/dist/mcp-test/run.js.map +1 -0
- package/dist/mcp-test/runner.d.ts +133 -0
- package/dist/mcp-test/runner.d.ts.map +1 -0
- package/dist/mcp-test/runner.js +412 -0
- package/dist/mcp-test/runner.js.map +1 -0
- package/dist/mcp-test/schema.d.ts +103 -0
- package/dist/mcp-test/schema.d.ts.map +1 -0
- package/dist/mcp-test/schema.js +513 -0
- package/dist/mcp-test/schema.js.map +1 -0
- package/dist/mcp-test/secrets.d.ts +25 -0
- package/dist/mcp-test/secrets.d.ts.map +1 -0
- package/dist/mcp-test/secrets.js +67 -0
- package/dist/mcp-test/secrets.js.map +1 -0
- package/dist/observe/index.d.ts +3 -1
- package/dist/observe/index.d.ts.map +1 -1
- package/dist/observe/index.js +1 -0
- package/dist/observe/index.js.map +1 -1
- package/dist/observe/locator-hints.d.ts +18 -0
- package/dist/observe/locator-hints.d.ts.map +1 -0
- package/dist/observe/locator-hints.js +36 -0
- package/dist/observe/locator-hints.js.map +1 -0
- package/dist/observe/overlays.d.ts +135 -0
- package/dist/observe/overlays.d.ts.map +1 -0
- package/dist/observe/overlays.js +242 -0
- package/dist/observe/overlays.js.map +1 -0
- package/dist/observe/parse-aria.d.ts +7 -1
- package/dist/observe/parse-aria.d.ts.map +1 -1
- package/dist/observe/parse-aria.js +79 -4
- package/dist/observe/parse-aria.js.map +1 -1
- package/dist/probe/index.d.ts +3 -1
- package/dist/probe/index.d.ts.map +1 -1
- package/dist/probe/index.js +3 -2
- package/dist/probe/index.js.map +1 -1
- package/dist/project/index.d.ts +2 -0
- package/dist/project/index.d.ts.map +1 -1
- package/dist/project/index.js +10 -2
- package/dist/project/index.js.map +1 -1
- package/dist/prompts/local/describe-screen.d.ts +7 -0
- package/dist/prompts/local/describe-screen.d.ts.map +1 -0
- package/dist/prompts/local/describe-screen.js +29 -0
- package/dist/prompts/local/describe-screen.js.map +1 -0
- package/dist/prompts/local/index.d.ts.map +1 -1
- package/dist/prompts/local/index.js +7 -0
- package/dist/prompts/local/index.js.map +1 -1
- package/dist/prompts/local/name-overlays.d.ts +6 -0
- package/dist/prompts/local/name-overlays.d.ts.map +1 -0
- package/dist/prompts/local/name-overlays.js +16 -0
- package/dist/prompts/local/name-overlays.js.map +1 -0
- package/dist/prompts/local/qa-api-flows.d.ts +8 -0
- package/dist/prompts/local/qa-api-flows.d.ts.map +1 -0
- package/dist/prompts/local/qa-api-flows.js +19 -0
- package/dist/prompts/local/qa-api-flows.js.map +1 -0
- package/dist/prompts/local/qa-playwright-ts-writer.d.ts +1 -1
- package/dist/prompts/local/qa-playwright-ts-writer.d.ts.map +1 -1
- package/dist/prompts/local/qa-playwright-ts-writer.js +5 -1
- package/dist/prompts/local/qa-playwright-ts-writer.js.map +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.d.ts +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.d.ts.map +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.js +2 -0
- package/dist/prompts/local/qa-testcase-from-ui.js.map +1 -1
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +24 -2
- package/dist/session/index.js.map +1 -1
- package/dist/validate/index.d.ts +11 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +21 -0
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/runner.d.ts +15 -1
- package/dist/validate/runner.d.ts.map +1 -1
- package/dist/validate/runner.js +158 -25
- package/dist/validate/runner.js.map +1 -1
- package/dist/validate/write-guard.d.ts +24 -0
- package/dist/validate/write-guard.d.ts.map +1 -0
- package/dist/validate/write-guard.js +210 -0
- package/dist/validate/write-guard.js.map +1 -0
- package/dist/view/index.d.ts +9 -0
- package/dist/view/index.d.ts.map +1 -0
- package/dist/view/index.js +126 -0
- package/dist/view/index.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { FLOW_FIXTURE_FILE } from "../api/flows.js";
|
|
5
|
+
import { V, caseFlips, changesServer, decoded, recordedPath, recordedUrl, secretShaped } from "../browser/click-effect.js";
|
|
6
|
+
/**
|
|
7
|
+
* #285: observe's write guard for the validation run. Validation is a `playwright test` process of its own, so the guard
|
|
8
|
+
* reaches it as a module: the run's tsconfig maps `@playwright/test`, `playwright/test`, `playwright` and `playwright-core` to it; every generated
|
|
9
|
+
* spec (and the API flows fixture) imports the first. It is `@playwright/test` with these fixtures added:
|
|
10
|
+
* - every worker's browser gets a Fetch interception on the browser itself, as observe's press browser: every request
|
|
11
|
+
* that changes the server (`changesServer`) is aborted, on every origin, from any page, popup, frame or worker;
|
|
12
|
+
* - the `request` fixture and each test context's `request` (which `page.request` and `route.fetch()` use) refuse the
|
|
13
|
+
* same requests before sending them;
|
|
14
|
+
* - after each test, a write it sent to a guarded origin (the target's, the studied pages', the API's) fails it, with
|
|
15
|
+
* the method and URL. One to any other origin (analytics, say), and a beacon or CSP report to any origin, fails
|
|
16
|
+
* nothing: it was aborted, and a test that needed it fails on its own assertions. A test runs alone in its worker, so what its worker blocked while it ran is its own.
|
|
17
|
+
* Each block goes into `log` as it happens, with a line per worker the guard loaded in (`runSpecs` fails a run in which a
|
|
18
|
+
* test ran where it did not). The re-exported `chromium`, `firefox` and `webkit` refuse to launch or connect: a browser
|
|
19
|
+
* of a spec's own would have no guard.
|
|
20
|
+
* `request.newContext()` (the export, and the `playwright` fixture's `playwright.request`) gives guarded API contexts too,
|
|
21
|
+
* but to the API flows fixture's sign-in, whose login POST is by design (see `signInOfFlows`).
|
|
22
|
+
* Not covered: a context a spec makes with `browser.newContext()` (its `request`, its pages' `page.request` and
|
|
23
|
+
* `route.fetch()`; its pages' browser traffic is covered), the `playwright` fixture's browser types, WebSocket messages,
|
|
24
|
+
* and a GET that changes the server.
|
|
25
|
+
*/
|
|
26
|
+
function guardModule(pwTest, origins, log, flowsFixture) {
|
|
27
|
+
return `// Written by cairn for one validation run (#285): '@playwright/test' with the write guard on.
|
|
28
|
+
const pw = require(${JSON.stringify(pwTest)});
|
|
29
|
+
const { appendFileSync } = require('node:fs');
|
|
30
|
+
const ORIGINS = ${JSON.stringify(origins)};
|
|
31
|
+
const LOG = ${JSON.stringify(log)};
|
|
32
|
+
const V = ${JSON.stringify(V)};
|
|
33
|
+
const caseFlips = ${caseFlips.toString()};
|
|
34
|
+
const secretShaped = ${secretShaped.toString()};
|
|
35
|
+
const decoded = ${decoded.toString()};
|
|
36
|
+
const recordedPath = ${recordedPath.toString()};
|
|
37
|
+
const recordedUrl = ${recordedUrl.toString()};
|
|
38
|
+
const changesServer = ${changesServer.toString()};
|
|
39
|
+
const originOf = (url) => { try { return new URL(url).origin; } catch { return undefined; } };
|
|
40
|
+
// a URL that does not parse (a relative one) counts as the target's
|
|
41
|
+
const ours = (url) => { const o = originOf(url); return o === undefined || ORIGINS.length === 0 || ORIGINS.includes(o); };
|
|
42
|
+
const note = (line) => { try { appendFileSync(LOG, line + '\\n'); } catch {} };
|
|
43
|
+
/**
|
|
44
|
+
* Record one blocked write: the target's go to the test that sent them (unless \`fails\` is false); the rest are only
|
|
45
|
+
* logged, by origin.
|
|
46
|
+
*/
|
|
47
|
+
const block = (sent, method, url, fails = true) => {
|
|
48
|
+
const m = String(method).toUpperCase();
|
|
49
|
+
if (ours(url)) {
|
|
50
|
+
const named = m + ' ' + recordedUrl(String(url));
|
|
51
|
+
note('T ' + named);
|
|
52
|
+
if (fails) sent.push(named);
|
|
53
|
+
return named;
|
|
54
|
+
}
|
|
55
|
+
note('O ' + m + ' ' + originOf(url));
|
|
56
|
+
return m + ' ' + originOf(url);
|
|
57
|
+
};
|
|
58
|
+
const failure = (named) => new Error('The write guard blocked ' + named + ': validation sends no writes unless the run allows them (--allow-mutations).');
|
|
59
|
+
/** A beacon (sendBeacon, <a ping>) or a CSP report: the page sends it on its own, so it is aborted and logged, and fails no test. */
|
|
60
|
+
const SENT_ON_ITS_OWN = new Set(['Ping', 'CSPViolationReport']);
|
|
61
|
+
const SENDS = { post: 'POST', put: 'PUT', patch: 'PATCH', delete: 'DELETE' };
|
|
62
|
+
/** An API request context that refuses writes; reads, and everything else, go to it unchanged. */
|
|
63
|
+
const guardedRequest = (ctx, sent) => new Proxy(ctx, {
|
|
64
|
+
get(target, key) {
|
|
65
|
+
const value = Reflect.get(target, key);
|
|
66
|
+
if (typeof value !== 'function') return value;
|
|
67
|
+
// bound to the context itself, so a read's own fetch() inside Playwright is not checked (and keeps its call name)
|
|
68
|
+
if (!(Object.hasOwn(SENDS, key) || key === 'fetch' || key === '_innerFetch')) return value.bind(target);
|
|
69
|
+
return (...args) => {
|
|
70
|
+
let method, url;
|
|
71
|
+
if (key === '_innerFetch') { // route.fetch() calls it on the context's request
|
|
72
|
+
const o = args[0] ?? {};
|
|
73
|
+
method = o.method || o.request?.method() || 'GET';
|
|
74
|
+
url = o.url ?? o.request?.url();
|
|
75
|
+
} else {
|
|
76
|
+
const req = typeof args[0] === 'string' ? undefined : args[0];
|
|
77
|
+
method = key === 'fetch' ? (args[1]?.method ?? req?.method?.() ?? 'GET') : SENDS[key];
|
|
78
|
+
url = req?.url ? req.url() : String(args[0]);
|
|
79
|
+
}
|
|
80
|
+
if (changesServer(method)) return Promise.reject(failure(block(sent, method, url)));
|
|
81
|
+
// called as a method: Playwright names the call in its errors after the frame that made it (not \`apply\`)
|
|
82
|
+
return target[key](...args);
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
/** What this worker blocked on a guarded origin since its current test began. */
|
|
87
|
+
const SENT = [];
|
|
88
|
+
const norm = (s) => String(s).split(String.fromCharCode(92)).join('/').toLowerCase();
|
|
89
|
+
const SELF = norm(__filename);
|
|
90
|
+
/** The flows fixture cairn wrote into this run (--flows), or null: a file of that name the run did not write is no exemption. */
|
|
91
|
+
const FLOWS_FIXTURE = ${flowsFixture === undefined ? "null" : JSON.stringify(flowsFixture.split("\\").join("/").toLowerCase())};
|
|
92
|
+
const { fileURLToPath } = require('node:url');
|
|
93
|
+
/** The file a stack frame names, as a path: an ES module's frame names a file:// URL, percent-encoded. */
|
|
94
|
+
const frameFile = (line) => {
|
|
95
|
+
const m = /\\((.*):\\d+:\\d+\\)$/.exec(line) || /at (.*):\\d+:\\d+$/.exec(line);
|
|
96
|
+
if (!m) return undefined;
|
|
97
|
+
try { return norm(m[1].startsWith('file:') ? fileURLToPath(m[1]) : m[1]); } catch { return undefined; }
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The API flows fixture's sign-in (#230) sends its login POST by design: a context made by that function of that file
|
|
101
|
+
* is the one that stays unguarded. Every other caller (a spec, a helper, the fixture's data flows) gets a guarded one.
|
|
102
|
+
*/
|
|
103
|
+
const signInOfFlows = () => {
|
|
104
|
+
if (FLOWS_FIXTURE === null) return false;
|
|
105
|
+
const caller = String(new Error().stack).split('\\n').slice(1).find((l) => frameFile(l) !== SELF);
|
|
106
|
+
return caller !== undefined && /^\\s*at (?:async )?signIn \\(/.test(caller) && frameFile(caller) === FLOWS_FIXTURE;
|
|
107
|
+
};
|
|
108
|
+
// One object: the export \`request\`, the \`playwright\` fixture's \`playwright.request\` and the one the request fixture uses.
|
|
109
|
+
const newContext = pw.request.newContext.bind(pw.request);
|
|
110
|
+
pw.request.newContext = (...args) => {
|
|
111
|
+
const exempt = signInOfFlows();
|
|
112
|
+
return newContext(...args).then((ctx) => (exempt ? ctx : guardedRequest(ctx, SENT)));
|
|
113
|
+
};
|
|
114
|
+
const test = pw.test.extend({
|
|
115
|
+
cairnWriteGuard: [async ({ browser }, use, workerInfo) => {
|
|
116
|
+
const sent = SENT;
|
|
117
|
+
const cdp = await browser.newBrowserCDPSession();
|
|
118
|
+
cdp.on('Fetch.requestPaused', ({ requestId, request, resourceType }) => {
|
|
119
|
+
if (!changesServer(request.method)) {
|
|
120
|
+
cdp.send('Fetch.continueRequest', { requestId }).catch(() => undefined);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
block(sent, request.method, request.url, !SENT_ON_ITS_OWN.has(resourceType));
|
|
124
|
+
// "Aborted" (net::ERR_ABORTED): a stopped form post leaves the page where it was, with no error page over it
|
|
125
|
+
cdp.send('Fetch.failRequest', { requestId, errorReason: 'Aborted' }).catch(() => undefined);
|
|
126
|
+
});
|
|
127
|
+
await cdp.send('Fetch.enable', { patterns: [{ urlPattern: '*' }] });
|
|
128
|
+
note('W ' + workerInfo.workerIndex);
|
|
129
|
+
await use(sent);
|
|
130
|
+
}, { scope: 'worker', auto: true }],
|
|
131
|
+
cairnWriteCheck: [async ({ cairnWriteGuard }, use) => {
|
|
132
|
+
cairnWriteGuard.length = 0;
|
|
133
|
+
await use();
|
|
134
|
+
const mine = [...new Set(cairnWriteGuard.splice(0))];
|
|
135
|
+
if (mine.length > 0) throw failure(mine.join(', '));
|
|
136
|
+
}, { auto: true }],
|
|
137
|
+
request: async ({ request, cairnWriteGuard }, use) => {
|
|
138
|
+
await use(guardedRequest(request, cairnWriteGuard));
|
|
139
|
+
},
|
|
140
|
+
// A page takes its context's request when it opens (page.request), and route.fetch() goes through it too.
|
|
141
|
+
context: async ({ context, cairnWriteGuard }, use) => {
|
|
142
|
+
context.request = guardedRequest(context.request, cairnWriteGuard);
|
|
143
|
+
await use(context);
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
const unguarded = (type) => new Proxy(type, {
|
|
147
|
+
get(target, key) {
|
|
148
|
+
const value = Reflect.get(target, key);
|
|
149
|
+
if (typeof key === 'string' && /^(launch|connect)/.test(key)) {
|
|
150
|
+
return () => Promise.reject(new Error('The write guard refuses ' + target.name() + '.' + key + '() in validation: a browser of the spec\\'s own would send writes unchecked. Use the page and context fixtures.'));
|
|
151
|
+
}
|
|
152
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
156
|
+
${exportNames(pwTest).map((k) => `exports.${k} = pw.${k};`).join("\n")}
|
|
157
|
+
exports.chromium = unguarded(pw.chromium);
|
|
158
|
+
exports.firefox = unguarded(pw.firefox);
|
|
159
|
+
exports.webkit = unguarded(pw.webkit);
|
|
160
|
+
exports.test = test;
|
|
161
|
+
exports.default = test;
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* `@playwright/test`'s own export names, each written out: a spec run as an ES module finds a CommonJS module's names
|
|
166
|
+
* only where they stand as `exports.name =`.
|
|
167
|
+
*/
|
|
168
|
+
function exportNames(pwTest) {
|
|
169
|
+
const own = new Set(["test", "default", "chromium", "firefox", "webkit"]);
|
|
170
|
+
return Object.keys(createRequire(import.meta.url)(pwTest)).filter((k) => !own.has(k) && /^[A-Za-z_$][\w$]*$/.test(k));
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Write the guard into the run (`runDir` absolute); `origins` empty guards every origin. `flows`: cairn wrote the API flows
|
|
174
|
+
* fixture into this run, whose sign-in is then the one caller exempt.
|
|
175
|
+
*/
|
|
176
|
+
export async function installWriteGuard(runDir, origins, pwTest, flows = false) {
|
|
177
|
+
const module = join(runDir, "write-guard.cjs");
|
|
178
|
+
const tsconfig = join(runDir, "write-guard.tsconfig.json");
|
|
179
|
+
const log = join(runDir, "write-guard.log");
|
|
180
|
+
await rm(log, { force: true });
|
|
181
|
+
const guarded = [...new Set(origins.map((o) => new URL(o).origin))];
|
|
182
|
+
await writeFile(module, guardModule(pwTest, guarded, log, flows ? join(runDir, "tests", FLOW_FIXTURE_FILE) : undefined), "utf8");
|
|
183
|
+
// Exact keys: Playwright maps only these specifiers, and never inside node_modules, so the guard's own require stays real.
|
|
184
|
+
// The guard exports all that \`playwright\` and \`playwright-core\` do, so a spec that takes its browser types there gets it too.
|
|
185
|
+
const paths = Object.fromEntries(["@playwright/test", "playwright/test", "playwright", "playwright-core"].map((k) => [k, [module]]));
|
|
186
|
+
await writeFile(tsconfig, JSON.stringify({ compilerOptions: { allowJs: true, paths } }, null, 2), "utf8");
|
|
187
|
+
return {
|
|
188
|
+
tsconfig,
|
|
189
|
+
read: async () => {
|
|
190
|
+
const text = await readFile(log, "utf8").catch(() => "");
|
|
191
|
+
await rm(log, { force: true });
|
|
192
|
+
const record = { blocked: [], otherOrigins: new Map(), workers: new Set() };
|
|
193
|
+
for (const line of text.split("\n")) {
|
|
194
|
+
const [kind, method = "", at = ""] = line.split(" ");
|
|
195
|
+
if (kind === "W")
|
|
196
|
+
record.workers.add(Number(method));
|
|
197
|
+
else if (kind === "T" && !record.blocked.includes(`${method} ${at}`))
|
|
198
|
+
record.blocked.push(`${method} ${at}`);
|
|
199
|
+
else if (kind === "O") {
|
|
200
|
+
const seen = record.otherOrigins.get(at) ?? { methods: new Set(), count: 0 };
|
|
201
|
+
seen.methods.add(method);
|
|
202
|
+
seen.count += 1;
|
|
203
|
+
record.otherOrigins.set(at, seen);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return record;
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=write-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-guard.js","sourceRoot":"","sources":["../../src/validate/write-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE3H;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,WAAW,CAAC,MAAc,EAAE,OAAiB,EAAE,GAAW,EAAE,YAAgC;IACnG,OAAO;qBACY,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;;kBAEzB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;cAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;YACrB,IAAI,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,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** m:ss (h:mm:ss from an hour) for a chapter offset. */
|
|
2
|
+
export declare function formatTime(ms: number): string;
|
|
3
|
+
/** Build the page for a run directory. Rejects, naming the directory, when the run has no video. */
|
|
4
|
+
export declare function renderRunView(runDir: string): Promise<string>;
|
|
5
|
+
/** Write `view.html` into the run directory and return its path. */
|
|
6
|
+
export declare function writeRunView(runDir: string): Promise<string>;
|
|
7
|
+
/** Open a file in the default browser (only ever called for `--open`). */
|
|
8
|
+
export declare function openInBrowser(file: string): void;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/view/index.ts"],"names":[],"mappings":"AAeA,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAM7C;AAqED,oGAAoG;AACpG,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBnE;AAED,oEAAoE;AACpE,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKlE;AAED,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAUhD"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #211: one finished run as a single static HTML page — the scenario video and its steps (chapters).
|
|
3
|
+
* Reads what `--screencast` already writes (`screencasts/screencasts.json`); nothing leaves the machine.
|
|
4
|
+
*/
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { access, readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
9
|
+
/** A relative URL for the video: each path segment percent-encoded, then HTML-escaped. */
|
|
10
|
+
const videoHref = (p) => escapeHtml(p.split("/").map(encodeURIComponent).join("/"));
|
|
11
|
+
/** m:ss (h:mm:ss from an hour) for a chapter offset. */
|
|
12
|
+
export function formatTime(ms) {
|
|
13
|
+
const total = Math.max(0, Math.floor(ms / 1000));
|
|
14
|
+
const h = Math.floor(total / 3600);
|
|
15
|
+
const m = Math.floor((total % 3600) / 60);
|
|
16
|
+
const s = String(total % 60).padStart(2, "0");
|
|
17
|
+
return h > 0 ? `${String(h)}:${String(m).padStart(2, "0")}:${s}` : `${String(m)}:${s}`;
|
|
18
|
+
}
|
|
19
|
+
async function readEntries(runDir) {
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(await readFile(join(runDir, "screencasts", "screencasts.json"), "utf8"));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (!Array.isArray(parsed))
|
|
28
|
+
return [];
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const e of parsed) {
|
|
31
|
+
if (typeof e?.video !== "string")
|
|
32
|
+
continue;
|
|
33
|
+
try {
|
|
34
|
+
await access(join(runDir, e.video));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
continue; // the .webm is gone: nothing to play
|
|
38
|
+
}
|
|
39
|
+
out.push({ ...e, chapters: Array.isArray(e.chapters) ? e.chapters : [] });
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function renderEntry(e, i) {
|
|
44
|
+
const items = e.chapters
|
|
45
|
+
.map((c) => {
|
|
46
|
+
const at = Math.max(0, Number(c.atMs) || 0);
|
|
47
|
+
return `<li><button type="button" class="step" data-at="${String(at / 1000)}"><time>${formatTime(at)}</time><span>${escapeHtml(String(c.title))}</span></button></li>`;
|
|
48
|
+
})
|
|
49
|
+
.join("\n");
|
|
50
|
+
const steps = e.chapters.length
|
|
51
|
+
? `<ol class="steps">\n${items}\n</ol>`
|
|
52
|
+
: `<p class="none">This run recorded no steps.</p>`;
|
|
53
|
+
return `<section class="scenario" id="s${String(i)}">
|
|
54
|
+
<h2>${escapeHtml(String(e.test ?? ""))}</h2>
|
|
55
|
+
<div class="body"><video controls preload="metadata" src="${videoHref(e.video)}"></video>
|
|
56
|
+
${steps}</div>
|
|
57
|
+
</section>`;
|
|
58
|
+
}
|
|
59
|
+
const STYLE = `:root{--bg:#fff;--fg:#1b1f24;--muted:#57606a;--line:#d0d7de;--accent:#0969da;--cur:#ddf4ff}
|
|
60
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0d1117;--fg:#e6edf3;--muted:#9198a1;--line:#30363d;--accent:#58a6ff;--cur:#17304d}}
|
|
61
|
+
body{margin:0;padding:16px;background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,sans-serif}
|
|
62
|
+
h1{font-size:1.2rem}h2{font-size:1rem;margin:1.5rem 0 .5rem}
|
|
63
|
+
.body{display:flex;gap:16px;flex-wrap:wrap;align-items:flex-start}
|
|
64
|
+
video{flex:2 1 420px;max-width:100%;background:#000}
|
|
65
|
+
.steps{flex:1 1 260px;list-style:none;margin:0;padding:0;border:1px solid var(--line);border-radius:6px}
|
|
66
|
+
.steps li+li{border-top:1px solid var(--line)}
|
|
67
|
+
.step{all:unset;box-sizing:border-box;display:flex;gap:10px;width:100%;padding:8px 12px;cursor:pointer}
|
|
68
|
+
.step:hover{background:var(--cur)}
|
|
69
|
+
.step:focus-visible{outline:3px solid var(--accent);outline-offset:-3px}
|
|
70
|
+
.step[aria-current=true]{background:var(--cur);font-weight:600}
|
|
71
|
+
time{color:var(--muted);font-variant-numeric:tabular-nums;min-width:3.5em}
|
|
72
|
+
.none{flex:1 1 260px;color:var(--muted)}`;
|
|
73
|
+
const SCRIPT = `for (const sec of document.querySelectorAll('.scenario')) {
|
|
74
|
+
const v = sec.querySelector('video');
|
|
75
|
+
const steps = [...sec.querySelectorAll('.step')];
|
|
76
|
+
const at = (b) => parseFloat(b.dataset.at);
|
|
77
|
+
steps.forEach((b) => b.addEventListener('click', () => { v.currentTime = at(b); v.play().catch(() => {}); }));
|
|
78
|
+
const mark = () => {
|
|
79
|
+
let cur = null;
|
|
80
|
+
for (const b of steps) if (at(b) <= v.currentTime + 0.05) cur = b;
|
|
81
|
+
steps.forEach((b) => (b === cur ? b.setAttribute('aria-current', 'true') : b.removeAttribute('aria-current')));
|
|
82
|
+
};
|
|
83
|
+
v.addEventListener('timeupdate', mark);
|
|
84
|
+
v.addEventListener('seeked', mark);
|
|
85
|
+
}`;
|
|
86
|
+
/** Build the page for a run directory. Rejects, naming the directory, when the run has no video. */
|
|
87
|
+
export async function renderRunView(runDir) {
|
|
88
|
+
const entries = await readEntries(runDir);
|
|
89
|
+
if (entries.length === 0) {
|
|
90
|
+
throw new Error(`No video found in run directory ${runDir}: expected screencasts/screencasts.json with a .webm (record one with --screencast).`);
|
|
91
|
+
}
|
|
92
|
+
return `<!doctype html>
|
|
93
|
+
<html lang="en">
|
|
94
|
+
<head>
|
|
95
|
+
<meta charset="utf-8">
|
|
96
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
97
|
+
<title>Cairn run</title>
|
|
98
|
+
<style>${STYLE}</style>
|
|
99
|
+
</head>
|
|
100
|
+
<body>
|
|
101
|
+
<h1>Cairn run</h1>
|
|
102
|
+
${entries.map(renderEntry).join("\n")}
|
|
103
|
+
<script>${SCRIPT}</script>
|
|
104
|
+
</body>
|
|
105
|
+
</html>
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
/** Write `view.html` into the run directory and return its path. */
|
|
109
|
+
export async function writeRunView(runDir) {
|
|
110
|
+
const html = await renderRunView(runDir);
|
|
111
|
+
const out = join(runDir, "view.html");
|
|
112
|
+
await writeFile(out, html, "utf8");
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/** Open a file in the default browser (only ever called for `--open`). */
|
|
116
|
+
export function openInBrowser(file) {
|
|
117
|
+
const [cmd, args] = process.platform === "darwin" ? ["open", [file]]
|
|
118
|
+
: process.platform === "win32" ? ["cmd", ["/c", "start", "", file]]
|
|
119
|
+
: ["xdg-open", [file]];
|
|
120
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
121
|
+
child.on("error", () => {
|
|
122
|
+
process.stderr.write(`Could not open a browser; open ${file} yourself.\n`);
|
|
123
|
+
});
|
|
124
|
+
child.unref();
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/view/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,UAAU,GAAG,CAAC,CAAS,EAAU,EAAE,CACvC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAEtH,0FAA0F;AAC1F,MAAM,SAAS,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEpG,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EA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ACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,IAAI,cAAc,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plune-ai/cairn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Cairn — an AI that walks your system and leaves a trail of tests. Autonomous QA agent (UI today; API/unit/docs planned) powered by Claude/OpenRouter, with self-improvement via Langfuse.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"zod": "^4.4.3"
|
|
75
75
|
},
|
|
76
76
|
"optionalDependencies": {
|
|
77
|
-
"@modelcontextprotocol/
|
|
77
|
+
"@modelcontextprotocol/server": "2.4.0",
|
|
78
78
|
"ink": "^5.2.1",
|
|
79
79
|
"ink-select-input": "^6.2.0",
|
|
80
80
|
"ink-spinner": "^5.0.0",
|
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
"@langfuse/langchain": "^6.0.1",
|
|
119
119
|
"@langfuse/otel": "^6.0.1",
|
|
120
120
|
"@langfuse/tracing": "^6.0.1",
|
|
121
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
121
122
|
"@opentelemetry/api": "^1.9.1",
|
|
122
123
|
"@opentelemetry/sdk-node": "^0.218.0",
|
|
123
124
|
"@types/node": "^22.0.0",
|