@itaila/archetype 0.3.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +475 -0
- package/dist/audit/audit-persona.d.ts +163 -0
- package/dist/audit/audit-persona.d.ts.map +1 -0
- package/dist/audit/audit-persona.js +415 -0
- package/dist/audit/audit-persona.js.map +1 -0
- package/dist/audit/brain-reflection.d.ts +33 -0
- package/dist/audit/brain-reflection.d.ts.map +1 -0
- package/dist/audit/brain-reflection.js +148 -0
- package/dist/audit/brain-reflection.js.map +1 -0
- package/dist/audit/conversation-audit.d.ts +12 -0
- package/dist/audit/conversation-audit.d.ts.map +1 -0
- package/dist/audit/conversation-audit.js +76 -0
- package/dist/audit/conversation-audit.js.map +1 -0
- package/dist/audit/prompt-audit.d.ts +10 -0
- package/dist/audit/prompt-audit.d.ts.map +1 -0
- package/dist/audit/prompt-audit.js +153 -0
- package/dist/audit/prompt-audit.js.map +1 -0
- package/dist/audit/prompt-dump.d.ts +137 -0
- package/dist/audit/prompt-dump.d.ts.map +1 -0
- package/dist/audit/prompt-dump.js +269 -0
- package/dist/audit/prompt-dump.js.map +1 -0
- package/dist/audit/trace-integrity.d.ts +33 -0
- package/dist/audit/trace-integrity.d.ts.map +1 -0
- package/dist/audit/trace-integrity.js +109 -0
- package/dist/audit/trace-integrity.js.map +1 -0
- package/dist/audit/types.d.ts +92 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/audit/types.js +2 -0
- package/dist/audit/types.js.map +1 -0
- package/dist/audit/version.d.ts +14 -0
- package/dist/audit/version.d.ts.map +1 -0
- package/dist/audit/version.js +65 -0
- package/dist/audit/version.js.map +1 -0
- package/dist/brain.d.ts +7 -0
- package/dist/brain.d.ts.map +1 -0
- package/dist/brain.js +83 -0
- package/dist/brain.js.map +1 -0
- package/dist/builder/actions.d.ts +60 -0
- package/dist/builder/actions.d.ts.map +1 -0
- package/dist/builder/actions.js +257 -0
- package/dist/builder/actions.js.map +1 -0
- package/dist/builder/browser.d.ts +140 -0
- package/dist/builder/browser.d.ts.map +1 -0
- package/dist/builder/browser.js +232 -0
- package/dist/builder/browser.js.map +1 -0
- package/dist/builder/executor.d.ts +228 -0
- package/dist/builder/executor.d.ts.map +1 -0
- package/dist/builder/executor.js +1548 -0
- package/dist/builder/executor.js.map +1 -0
- package/dist/builder/index.d.ts +24 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +24 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/node-test-discovery.d.ts +13 -0
- package/dist/builder/node-test-discovery.d.ts.map +1 -0
- package/dist/builder/node-test-discovery.js +45 -0
- package/dist/builder/node-test-discovery.js.map +1 -0
- package/dist/builder/sandbox.d.ts +172 -0
- package/dist/builder/sandbox.d.ts.map +1 -0
- package/dist/builder/sandbox.js +294 -0
- package/dist/builder/sandbox.js.map +1 -0
- package/dist/builder/workspace-files.d.ts +63 -0
- package/dist/builder/workspace-files.d.ts.map +1 -0
- package/dist/builder/workspace-files.js +190 -0
- package/dist/builder/workspace-files.js.map +1 -0
- package/dist/core/actions.d.ts +55 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +311 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/attachment-notes.d.ts +7 -0
- package/dist/core/attachment-notes.d.ts.map +1 -0
- package/dist/core/attachment-notes.js +38 -0
- package/dist/core/attachment-notes.js.map +1 -0
- package/dist/core/context.d.ts +10 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +108 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/crud-prompt.d.ts +16 -0
- package/dist/core/crud-prompt.d.ts.map +1 -0
- package/dist/core/crud-prompt.js +268 -0
- package/dist/core/crud-prompt.js.map +1 -0
- package/dist/core/crud-schema.d.ts +12 -0
- package/dist/core/crud-schema.d.ts.map +1 -0
- package/dist/core/crud-schema.js +42 -0
- package/dist/core/crud-schema.js.map +1 -0
- package/dist/core/effective-config.d.ts +13 -0
- package/dist/core/effective-config.d.ts.map +1 -0
- package/dist/core/effective-config.js +33 -0
- package/dist/core/effective-config.js.map +1 -0
- package/dist/core/entities.d.ts +82 -0
- package/dist/core/entities.d.ts.map +1 -0
- package/dist/core/entities.js +116 -0
- package/dist/core/entities.js.map +1 -0
- package/dist/core/entity-helpers.d.ts +47 -0
- package/dist/core/entity-helpers.d.ts.map +1 -0
- package/dist/core/entity-helpers.js +122 -0
- package/dist/core/entity-helpers.js.map +1 -0
- package/dist/core/entity-registry.d.ts +47 -0
- package/dist/core/entity-registry.d.ts.map +1 -0
- package/dist/core/entity-registry.js +54 -0
- package/dist/core/entity-registry.js.map +1 -0
- package/dist/core/eq.d.ts +13 -0
- package/dist/core/eq.d.ts.map +1 -0
- package/dist/core/eq.js +41 -0
- package/dist/core/eq.js.map +1 -0
- package/dist/core/focus-context.d.ts +19 -0
- package/dist/core/focus-context.d.ts.map +1 -0
- package/dist/core/focus-context.js +46 -0
- package/dist/core/focus-context.js.map +1 -0
- package/dist/core/focus-mode-actions.d.ts +23 -0
- package/dist/core/focus-mode-actions.d.ts.map +1 -0
- package/dist/core/focus-mode-actions.js +74 -0
- package/dist/core/focus-mode-actions.js.map +1 -0
- package/dist/core/greeting.d.ts +10 -0
- package/dist/core/greeting.d.ts.map +1 -0
- package/dist/core/greeting.js +41 -0
- package/dist/core/greeting.js.map +1 -0
- package/dist/core/identity.d.ts +13 -0
- package/dist/core/identity.d.ts.map +1 -0
- package/dist/core/identity.js +54 -0
- package/dist/core/identity.js.map +1 -0
- package/dist/core/knowledge.d.ts +10 -0
- package/dist/core/knowledge.d.ts.map +1 -0
- package/dist/core/knowledge.js +40 -0
- package/dist/core/knowledge.js.map +1 -0
- package/dist/core/memory-actions.d.ts +38 -0
- package/dist/core/memory-actions.d.ts.map +1 -0
- package/dist/core/memory-actions.js +181 -0
- package/dist/core/memory-actions.js.map +1 -0
- package/dist/core/memory.d.ts +35 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +168 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/peer-actions.d.ts +15 -0
- package/dist/core/peer-actions.d.ts.map +1 -0
- package/dist/core/peer-actions.js +33 -0
- package/dist/core/peer-actions.js.map +1 -0
- package/dist/core/prompt-builder.d.ts +46 -0
- package/dist/core/prompt-builder.d.ts.map +1 -0
- package/dist/core/prompt-builder.js +543 -0
- package/dist/core/prompt-builder.js.map +1 -0
- package/dist/core/prompt-mode.d.ts +3 -0
- package/dist/core/prompt-mode.d.ts.map +1 -0
- package/dist/core/prompt-mode.js +6 -0
- package/dist/core/prompt-mode.js.map +1 -0
- package/dist/core/prompted-turn.d.ts +6 -0
- package/dist/core/prompted-turn.d.ts.map +1 -0
- package/dist/core/prompted-turn.js +48 -0
- package/dist/core/prompted-turn.js.map +1 -0
- package/dist/core/request-builder.d.ts +14 -0
- package/dist/core/request-builder.d.ts.map +1 -0
- package/dist/core/request-builder.js +64 -0
- package/dist/core/request-builder.js.map +1 -0
- package/dist/core/session-routing.d.ts +23 -0
- package/dist/core/session-routing.d.ts.map +1 -0
- package/dist/core/session-routing.js +59 -0
- package/dist/core/session-routing.js.map +1 -0
- package/dist/core/voice.d.ts +6 -0
- package/dist/core/voice.d.ts.map +1 -0
- package/dist/core/voice.js +30 -0
- package/dist/core/voice.js.map +1 -0
- package/dist/engine/chat.d.ts +45 -0
- package/dist/engine/chat.d.ts.map +1 -0
- package/dist/engine/chat.js +308 -0
- package/dist/engine/chat.js.map +1 -0
- package/dist/engine/continuity.d.ts +107 -0
- package/dist/engine/continuity.d.ts.map +1 -0
- package/dist/engine/continuity.js +320 -0
- package/dist/engine/continuity.js.map +1 -0
- package/dist/engine/crud.d.ts +62 -0
- package/dist/engine/crud.d.ts.map +1 -0
- package/dist/engine/crud.js +260 -0
- package/dist/engine/crud.js.map +1 -0
- package/dist/engine/side-effects.d.ts +93 -0
- package/dist/engine/side-effects.d.ts.map +1 -0
- package/dist/engine/side-effects.js +271 -0
- package/dist/engine/side-effects.js.map +1 -0
- package/dist/engine/staging.d.ts +29 -0
- package/dist/engine/staging.d.ts.map +1 -0
- package/dist/engine/staging.js +159 -0
- package/dist/engine/staging.js.map +1 -0
- package/dist/engine/working-set.d.ts +18 -0
- package/dist/engine/working-set.d.ts.map +1 -0
- package/dist/engine/working-set.js +246 -0
- package/dist/engine/working-set.js.map +1 -0
- package/dist/evals/action-contracts.d.ts +40 -0
- package/dist/evals/action-contracts.d.ts.map +1 -0
- package/dist/evals/action-contracts.js +208 -0
- package/dist/evals/action-contracts.js.map +1 -0
- package/dist/evals/brain-bloat.d.ts +39 -0
- package/dist/evals/brain-bloat.d.ts.map +1 -0
- package/dist/evals/brain-bloat.js +167 -0
- package/dist/evals/brain-bloat.js.map +1 -0
- package/dist/evals/brain-prescriptions.d.ts +30 -0
- package/dist/evals/brain-prescriptions.d.ts.map +1 -0
- package/dist/evals/brain-prescriptions.js +148 -0
- package/dist/evals/brain-prescriptions.js.map +1 -0
- package/dist/evals/cross-layer-duplicates.d.ts +49 -0
- package/dist/evals/cross-layer-duplicates.d.ts.map +1 -0
- package/dist/evals/cross-layer-duplicates.js +289 -0
- package/dist/evals/cross-layer-duplicates.js.map +1 -0
- package/dist/evals/entity-visibility.d.ts +28 -0
- package/dist/evals/entity-visibility.d.ts.map +1 -0
- package/dist/evals/entity-visibility.js +216 -0
- package/dist/evals/entity-visibility.js.map +1 -0
- package/dist/evals/index.d.ts +19 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +11 -0
- package/dist/evals/index.js.map +1 -0
- package/dist/evals/judge.d.ts +22 -0
- package/dist/evals/judge.d.ts.map +1 -0
- package/dist/evals/judge.js +337 -0
- package/dist/evals/judge.js.map +1 -0
- package/dist/evals/operational-contract.d.ts +40 -0
- package/dist/evals/operational-contract.d.ts.map +1 -0
- package/dist/evals/operational-contract.js +115 -0
- package/dist/evals/operational-contract.js.map +1 -0
- package/dist/evals/prompt-content.d.ts +14 -0
- package/dist/evals/prompt-content.d.ts.map +1 -0
- package/dist/evals/prompt-content.js +104 -0
- package/dist/evals/prompt-content.js.map +1 -0
- package/dist/evals/runtime.d.ts +4 -0
- package/dist/evals/runtime.d.ts.map +1 -0
- package/dist/evals/runtime.js +197 -0
- package/dist/evals/runtime.js.map +1 -0
- package/dist/evals/sample-projects.d.ts +143 -0
- package/dist/evals/sample-projects.d.ts.map +1 -0
- package/dist/evals/sample-projects.js +644 -0
- package/dist/evals/sample-projects.js.map +1 -0
- package/dist/evals/types.d.ts +88 -0
- package/dist/evals/types.d.ts.map +1 -0
- package/dist/evals/types.js +2 -0
- package/dist/evals/types.js.map +1 -0
- package/dist/foundation/index.d.ts +158 -0
- package/dist/foundation/index.d.ts.map +1 -0
- package/dist/foundation/index.js +256 -0
- package/dist/foundation/index.js.map +1 -0
- package/dist/index.d.ts +223 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +998 -0
- package/dist/index.js.map +1 -0
- package/dist/managed/autonomous-loop.d.ts +199 -0
- package/dist/managed/autonomous-loop.d.ts.map +1 -0
- package/dist/managed/autonomous-loop.js +451 -0
- package/dist/managed/autonomous-loop.js.map +1 -0
- package/dist/managed/conversation.d.ts +20 -0
- package/dist/managed/conversation.d.ts.map +1 -0
- package/dist/managed/conversation.js +40 -0
- package/dist/managed/conversation.js.map +1 -0
- package/dist/managed/knowledge.d.ts +7 -0
- package/dist/managed/knowledge.d.ts.map +1 -0
- package/dist/managed/knowledge.js +174 -0
- package/dist/managed/knowledge.js.map +1 -0
- package/dist/managed/memory-manager.d.ts +7 -0
- package/dist/managed/memory-manager.d.ts.map +1 -0
- package/dist/managed/memory-manager.js +18 -0
- package/dist/managed/memory-manager.js.map +1 -0
- package/dist/managed/memory-review.d.ts +45 -0
- package/dist/managed/memory-review.d.ts.map +1 -0
- package/dist/managed/memory-review.js +130 -0
- package/dist/managed/memory-review.js.map +1 -0
- package/dist/managed/storage.d.ts +2 -0
- package/dist/managed/storage.d.ts.map +1 -0
- package/dist/managed/storage.js +2 -0
- package/dist/managed/storage.js.map +1 -0
- package/dist/managed/work-history.d.ts +23 -0
- package/dist/managed/work-history.d.ts.map +1 -0
- package/dist/managed/work-history.js +31 -0
- package/dist/managed/work-history.js.map +1 -0
- package/dist/observability/index.d.ts +15 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +15 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/render-run-markdown.d.ts +90 -0
- package/dist/observability/render-run-markdown.d.ts.map +1 -0
- package/dist/observability/render-run-markdown.js +231 -0
- package/dist/observability/render-run-markdown.js.map +1 -0
- package/dist/observability/turn-reporter.d.ts +20 -0
- package/dist/observability/turn-reporter.d.ts.map +1 -0
- package/dist/observability/turn-reporter.js +106 -0
- package/dist/observability/turn-reporter.js.map +1 -0
- package/dist/persona.d.ts +49 -0
- package/dist/persona.d.ts.map +1 -0
- package/dist/persona.js +287 -0
- package/dist/persona.js.map +1 -0
- package/dist/playbook/defaults.d.ts +25 -0
- package/dist/playbook/defaults.d.ts.map +1 -0
- package/dist/playbook/defaults.js +108 -0
- package/dist/playbook/defaults.js.map +1 -0
- package/dist/playbook/invariants.d.ts +244 -0
- package/dist/playbook/invariants.d.ts.map +1 -0
- package/dist/playbook/invariants.js +259 -0
- package/dist/playbook/invariants.js.map +1 -0
- package/dist/playbook/templates.d.ts +7 -0
- package/dist/playbook/templates.d.ts.map +1 -0
- package/dist/playbook/templates.js +437 -0
- package/dist/playbook/templates.js.map +1 -0
- package/dist/providers/gemini.d.ts +73 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +536 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/types.d.ts +2 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/zod-to-gemini.d.ts +8 -0
- package/dist/providers/zod-to-gemini.d.ts.map +1 -0
- package/dist/providers/zod-to-gemini.js +148 -0
- package/dist/providers/zod-to-gemini.js.map +1 -0
- package/dist/samples/pm-spec-agent.d.ts +22 -0
- package/dist/samples/pm-spec-agent.d.ts.map +1 -0
- package/dist/samples/pm-spec-agent.js +53 -0
- package/dist/samples/pm-spec-agent.js.map +1 -0
- package/dist/types.d.ts +920 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrowserHarness — live-browser primitive for coder personas that
|
|
3
|
+
* build browser-rendered artifacts (games, forms, dashboards). Lets the
|
|
4
|
+
* model actually see the page and interact with it instead of inferring
|
|
5
|
+
* behavior from code alone.
|
|
6
|
+
*
|
|
7
|
+
* Contract:
|
|
8
|
+
* — `open` navigate to a path under the allowed origin
|
|
9
|
+
* — `click` click by visible text (primary) or CSS selector (fallback)
|
|
10
|
+
* — `type` type literal text into the focused element
|
|
11
|
+
* — `key` press one named key (ArrowUp, Enter, etc) once
|
|
12
|
+
* — `screenshot` capture a PNG (bytes + base64)
|
|
13
|
+
* — `getConsoleEntries` read captured console output
|
|
14
|
+
* — `close` terminate the browser + clean up the profile dir
|
|
15
|
+
*
|
|
16
|
+
* What belongs here (archetype layer):
|
|
17
|
+
* — `BrowserHarness` interface + all result types
|
|
18
|
+
* — `PlaywrightBrowser` default impl using playwright chromium
|
|
19
|
+
* — Origin-allowlist enforcement (route blocker + navigation check)
|
|
20
|
+
* — Ephemeral profile directory lifecycle
|
|
21
|
+
*
|
|
22
|
+
* What does NOT belong here:
|
|
23
|
+
* — Evidence-file persistence. `screenshot()` returns bytes and base64;
|
|
24
|
+
* the host app decides whether to write a PNG file, upload, attach
|
|
25
|
+
* the bytes to the next prompt turn, etc.
|
|
26
|
+
* — Tool-action wiring (archetype/builder/actions.ts owns the action
|
|
27
|
+
* contracts; the executor dispatch maps them to BrowserHarness calls).
|
|
28
|
+
*
|
|
29
|
+
* Node-only. Playwright is a runtime dep of the *host app* (not
|
|
30
|
+
* archetype) — we dynamically import `playwright` inside the default
|
|
31
|
+
* impl, so archetype ships without pulling chromium binaries.
|
|
32
|
+
*/
|
|
33
|
+
import fs from 'node:fs';
|
|
34
|
+
import os from 'node:os';
|
|
35
|
+
import path from 'node:path';
|
|
36
|
+
export class PlaywrightBrowser {
|
|
37
|
+
allowedOrigin;
|
|
38
|
+
profileDir;
|
|
39
|
+
ownsProfileDir;
|
|
40
|
+
viewport;
|
|
41
|
+
context = null;
|
|
42
|
+
page = null;
|
|
43
|
+
consoleEntries = [];
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.allowedOrigin = normalizeOrigin(options.allowedOrigin);
|
|
46
|
+
if (options.profileDir) {
|
|
47
|
+
this.profileDir = path.resolve(options.profileDir);
|
|
48
|
+
this.ownsProfileDir = false;
|
|
49
|
+
fs.mkdirSync(this.profileDir, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.profileDir = fs.mkdtempSync(path.join(os.tmpdir(), 'archetype-browser-profile-'));
|
|
53
|
+
this.ownsProfileDir = true;
|
|
54
|
+
}
|
|
55
|
+
this.viewport = {
|
|
56
|
+
width: options.viewportWidth ?? 1440,
|
|
57
|
+
height: options.viewportHeight ?? 960,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async open(relativePath = '/') {
|
|
61
|
+
const page = await this.ensurePage();
|
|
62
|
+
const targetUrl = new URL(relativePath, `${this.allowedOrigin}/`).toString();
|
|
63
|
+
enforceAllowedUrl(targetUrl, this.allowedOrigin);
|
|
64
|
+
this.consoleEntries.length = 0;
|
|
65
|
+
const response = await page.goto(targetUrl, { waitUntil: 'networkidle' });
|
|
66
|
+
if (!response) {
|
|
67
|
+
throw new Error(`Browser failed to load ${targetUrl}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
ok: response.ok(),
|
|
71
|
+
url: page.url(),
|
|
72
|
+
title: await page.title(),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async screenshot(_label = 'page') {
|
|
76
|
+
const page = await this.ensurePage();
|
|
77
|
+
const bytes = await page.screenshot({ fullPage: true });
|
|
78
|
+
return { ok: true, bytes, base64: bytes.toString('base64') };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Type literal text into the focused element (or a specified selector).
|
|
82
|
+
* Mirrors playwright's `keyboard.type` — sends key-by-key so form/game
|
|
83
|
+
* handlers fire. If `selector` is given, focus it first.
|
|
84
|
+
*/
|
|
85
|
+
async type(input) {
|
|
86
|
+
const page = await this.ensurePage();
|
|
87
|
+
if (!input.text || input.text.length === 0) {
|
|
88
|
+
return { ok: false, detail: 'browserType requires a non-empty `text` param.' };
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
if (input.selector && input.selector.trim().length > 0) {
|
|
92
|
+
await page.focus(input.selector, { timeout: 3000 });
|
|
93
|
+
}
|
|
94
|
+
await page.keyboard.type(input.text);
|
|
95
|
+
const scope = input.selector ? ` into "${input.selector}"` : '';
|
|
96
|
+
return { ok: true, detail: `typed ${JSON.stringify(input.text)}${scope}` };
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
return { ok: false, detail: firstLineOf(err) };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Press a single named key (ArrowUp, Enter, Escape, Tab, Space, a-z,
|
|
104
|
+
* 0-9, etc). Mirrors playwright's `keyboard.press` — one keydown +
|
|
105
|
+
* keyup so game handlers fire once.
|
|
106
|
+
*/
|
|
107
|
+
async key(input) {
|
|
108
|
+
const page = await this.ensurePage();
|
|
109
|
+
if (!input.key || input.key.length === 0) {
|
|
110
|
+
return { ok: false, detail: 'browserKey requires a non-empty `key` param.' };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
if (input.selector && input.selector.trim().length > 0) {
|
|
114
|
+
await page.focus(input.selector, { timeout: 3000 });
|
|
115
|
+
}
|
|
116
|
+
await page.keyboard.press(input.key);
|
|
117
|
+
const scope = input.selector ? ` (focus "${input.selector}")` : '';
|
|
118
|
+
return { ok: true, detail: `pressed ${JSON.stringify(input.key)}${scope}` };
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
return { ok: false, detail: firstLineOf(err) };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Click an element. Primary: visible text match (matches how the model
|
|
126
|
+
* thinks about UI). Fallback: CSS selector. Returns the match mode
|
|
127
|
+
* + detail so the executor can render a truthful outcome note.
|
|
128
|
+
*/
|
|
129
|
+
async click(input) {
|
|
130
|
+
const page = await this.ensurePage();
|
|
131
|
+
if (input.text && input.text.trim().length > 0) {
|
|
132
|
+
const locator = page.getByText(input.text, { exact: false }).first();
|
|
133
|
+
try {
|
|
134
|
+
await locator.click({ timeout: 3000 });
|
|
135
|
+
return { ok: true, matched: 'text', detail: `clicked element with text matching "${input.text}"` };
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
if (!input.selector) {
|
|
139
|
+
return { ok: false, matched: 'none', detail: `no element with visible text "${input.text}" within 3s — ${firstLineOf(err)}` };
|
|
140
|
+
}
|
|
141
|
+
// text miss; fall through to selector fallback
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (input.selector && input.selector.trim().length > 0) {
|
|
145
|
+
try {
|
|
146
|
+
await page.click(input.selector, { timeout: 3000 });
|
|
147
|
+
return { ok: true, matched: 'selector', detail: `clicked element matching selector "${input.selector}"` };
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
return { ok: false, matched: 'none', detail: `selector "${input.selector}" did not match a clickable element within 3s — ${firstLineOf(err)}` };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { ok: false, matched: 'none', detail: 'browserClick requires at least one of `text` or `selector` to be provided' };
|
|
154
|
+
}
|
|
155
|
+
getConsoleEntries() {
|
|
156
|
+
return [...this.consoleEntries];
|
|
157
|
+
}
|
|
158
|
+
async close() {
|
|
159
|
+
await this.context?.close();
|
|
160
|
+
this.context = null;
|
|
161
|
+
this.page = null;
|
|
162
|
+
if (this.ownsProfileDir) {
|
|
163
|
+
fs.rmSync(this.profileDir, { recursive: true, force: true });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async ensurePage() {
|
|
167
|
+
if (this.page)
|
|
168
|
+
return this.page;
|
|
169
|
+
const { chromium } = await loadPlaywright();
|
|
170
|
+
this.context = await chromium.launchPersistentContext(this.profileDir, {
|
|
171
|
+
headless: true,
|
|
172
|
+
viewport: this.viewport,
|
|
173
|
+
acceptDownloads: false,
|
|
174
|
+
});
|
|
175
|
+
await this.context.route('**/*', async (route) => {
|
|
176
|
+
const requestUrl = route.request().url();
|
|
177
|
+
if (requestUrl.startsWith(this.allowedOrigin)) {
|
|
178
|
+
await route.continue();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
await route.abort();
|
|
182
|
+
});
|
|
183
|
+
const pages = this.context.pages();
|
|
184
|
+
this.page = pages[0] ?? await this.context.newPage();
|
|
185
|
+
this.page.on('console', (message) => {
|
|
186
|
+
this.consoleEntries.push(formatConsoleEntry(message));
|
|
187
|
+
});
|
|
188
|
+
return this.page;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ─── Internals ───────────────────────────────────────────────────────
|
|
192
|
+
async function loadPlaywright() {
|
|
193
|
+
try {
|
|
194
|
+
// Dynamic import keeps archetype free of a hard playwright dep. The
|
|
195
|
+
// `as never` cast prevents the TS compiler from requiring playwright
|
|
196
|
+
// type declarations at archetype build time — consumers still get
|
|
197
|
+
// correct types via our locally-declared PlaywrightChromium.
|
|
198
|
+
const mod = await import('playwright');
|
|
199
|
+
return mod;
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
throw new Error(`PlaywrightBrowser requires the 'playwright' package installed in the host app. Install with: npm install playwright. Underlying error: ${firstLineOf(err)}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function formatConsoleEntry(message) {
|
|
206
|
+
const location = message.location();
|
|
207
|
+
return {
|
|
208
|
+
type: message.type(),
|
|
209
|
+
text: message.text(),
|
|
210
|
+
location: {
|
|
211
|
+
url: location.url,
|
|
212
|
+
lineNumber: location.lineNumber,
|
|
213
|
+
columnNumber: location.columnNumber,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function normalizeOrigin(origin) {
|
|
218
|
+
const url = new URL(origin);
|
|
219
|
+
return `${url.protocol}//${url.host}`;
|
|
220
|
+
}
|
|
221
|
+
function enforceAllowedUrl(candidate, allowedOrigin) {
|
|
222
|
+
const url = new URL(candidate);
|
|
223
|
+
const normalized = `${url.protocol}//${url.host}`;
|
|
224
|
+
if (normalized !== allowedOrigin) {
|
|
225
|
+
throw new Error(`Browser navigation blocked outside allowed origin: ${candidate}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function firstLineOf(err) {
|
|
229
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
230
|
+
return msg.split('\n')[0];
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/builder/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AA8H5B,MAAM,OAAO,iBAAiB;IACX,aAAa,CAAQ;IACrB,UAAU,CAAQ;IAClB,cAAc,CAAS;IACvB,QAAQ,CAAmC;IACpD,OAAO,GAA6B,IAAI,CAAA;IACxC,IAAI,GAA0B,IAAI,CAAA;IACzB,cAAc,GAA0B,EAAE,CAAA;IAE3D,YAAY,OAAiC;QAC3C,IAAI,CAA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CAAC,IAAI,EAAE;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;QACpB,QAAQ,EAAE;YACR,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,YAAY,EAAE,QAAQ,CAAC,YAAY;SACpC;KACF,CAAA;AACH,CAAC;AAED,SAAS,eAAe,CAAC,MAAc;IACrC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3B,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,EAAE,CAAA;AACvC,CAAC;AAED,SAAS,iBAAiB,CAAC,SAAiB,EAAE,aAAqB;IACjE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAC9B,MAAM,UAAU,GAAG,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,EAAE,CAAA;IACjD,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,sDAAsD,SAAS,EAAE,CAAC,CAAA;IACpF,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC5D,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import type { BrowserHarness } from './browser.js';
|
|
2
|
+
import type { ChatAttachment, ParsedAction, TurnLedgerActionOutcome } from '../types.js';
|
|
3
|
+
import type { SandboxExecResult, SandboxSpawnResult } from './sandbox.js';
|
|
4
|
+
import { type WorkspaceMount } from './workspace-files.js';
|
|
5
|
+
/**
|
|
6
|
+
* The minimum sandbox surface the executor needs. Hosts can implement
|
|
7
|
+
* this directly over archetype's `Sandbox` (via SrtSandbox.exec) or
|
|
8
|
+
* wrap it with their own preset layer (foundry's BenchmarkSandboxExecutor).
|
|
9
|
+
*/
|
|
10
|
+
export interface CoderSandbox {
|
|
11
|
+
/**
|
|
12
|
+
* Execute an arbitrary argv inside the sandbox. Maps to the model's
|
|
13
|
+
* `runCommand` action.
|
|
14
|
+
*/
|
|
15
|
+
runCommand(input: {
|
|
16
|
+
command: string[];
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
/** Optional command cwd. Mounted workspaces use a canonical visible cwd. */
|
|
19
|
+
cwd?: string;
|
|
20
|
+
/** Additional readable paths needed by the command cwd. */
|
|
21
|
+
extraReadPaths?: string[];
|
|
22
|
+
/** Additional writable paths needed by the command cwd. */
|
|
23
|
+
extraWritePaths?: string[];
|
|
24
|
+
}): Promise<SandboxExecResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute a named preset tool (runInstall, runBuild, runTests, runLint,
|
|
27
|
+
* runStart). The host owns what each preset means; this module just
|
|
28
|
+
* forwards the name it received from the model. runStart resolves with
|
|
29
|
+
* `origin` so the host knows the live URL.
|
|
30
|
+
*/
|
|
31
|
+
runTool(name: CoderSandboxToolName, input?: {
|
|
32
|
+
/** Optional command cwd. Mounted workspaces use a canonical visible cwd. */
|
|
33
|
+
cwd?: string;
|
|
34
|
+
/** Additional readable paths needed by the command cwd. */
|
|
35
|
+
extraReadPaths?: string[];
|
|
36
|
+
/** Additional writable paths needed by the command cwd. */
|
|
37
|
+
extraWritePaths?: string[];
|
|
38
|
+
}): Promise<CoderSandboxToolResult>;
|
|
39
|
+
}
|
|
40
|
+
export type CoderSandboxToolName = 'runInstall' | 'runBuild' | 'runTests' | 'runLint' | 'runStart';
|
|
41
|
+
export interface CoderSandboxToolDocumentation {
|
|
42
|
+
/**
|
|
43
|
+
* Human-facing command equivalent for docs/handoffs. Hosts should provide
|
|
44
|
+
* this when a preset wraps hidden setup, absolute trusted binaries, or
|
|
45
|
+
* sandbox-only paths that would otherwise make artifact instructions stale.
|
|
46
|
+
*/
|
|
47
|
+
userFacingCommand?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Compact factual note about hidden preset setup that affects whether the
|
|
50
|
+
* userFacingCommand is replayable outside the harness.
|
|
51
|
+
*/
|
|
52
|
+
userFacingNote?: string;
|
|
53
|
+
}
|
|
54
|
+
export type CoderSandboxToolResult = (SandboxExecResult & CoderSandboxToolDocumentation) | (SandboxSpawnResult & {
|
|
55
|
+
origin: string;
|
|
56
|
+
} & CoderSandboxToolDocumentation);
|
|
57
|
+
export interface CoderExecutorContext {
|
|
58
|
+
/** Absolute path to the workspace root the persona operates in. */
|
|
59
|
+
workspaceRoot: string;
|
|
60
|
+
/**
|
|
61
|
+
* Optional virtual roots exposed to the persona, e.g.
|
|
62
|
+
* [{prefix:"spec", root:"/tmp/spec", writable:false},
|
|
63
|
+
* {prefix:"artifact", root:"/tmp/artifact", writable:true}].
|
|
64
|
+
* File actions understand these prefixes and report outcomes using the
|
|
65
|
+
* same visible path, so hosts don't need to hand-roll spec/artifact routing.
|
|
66
|
+
*/
|
|
67
|
+
workspaceMounts?: readonly WorkspaceMount[];
|
|
68
|
+
/** Default mount for unprefixed file writes. Defaults to workspaceRoot. */
|
|
69
|
+
defaultMountPrefix?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Visible mount that corresponds to the live browser document root.
|
|
72
|
+
* Defaults to defaultMountPrefix when omitted. This stays separate from
|
|
73
|
+
* defaultMountPrefix because a reviewer persona may write spec files by
|
|
74
|
+
* default while opening a mounted artifact in the browser.
|
|
75
|
+
*/
|
|
76
|
+
browserMountPrefix?: string;
|
|
77
|
+
/** Sandbox adapter the persona routes sandbox-tool calls through. */
|
|
78
|
+
sandbox: CoderSandbox;
|
|
79
|
+
/** Live browser harness, or null if no local server is running yet. */
|
|
80
|
+
browser: BrowserHarness | null;
|
|
81
|
+
}
|
|
82
|
+
export interface CoderActionAttachment {
|
|
83
|
+
type: 'image';
|
|
84
|
+
mimeType: string;
|
|
85
|
+
data: string;
|
|
86
|
+
}
|
|
87
|
+
export interface CoderActionContinuity {
|
|
88
|
+
/**
|
|
89
|
+
* Full result text shown on the immediately following turn.
|
|
90
|
+
*/
|
|
91
|
+
resultText: string;
|
|
92
|
+
/**
|
|
93
|
+
* How many future turns should continue seeing resultText before continuity
|
|
94
|
+
* decays into staleText. Defaults to 1.
|
|
95
|
+
*/
|
|
96
|
+
resultTurns?: number;
|
|
97
|
+
/**
|
|
98
|
+
* What later turns should see after resultText ages out. If omitted,
|
|
99
|
+
* resultText remains the durable outcome note.
|
|
100
|
+
*/
|
|
101
|
+
staleText?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Short concrete anchors that should remain visible if the host audits or
|
|
104
|
+
* trims the continuity payload.
|
|
105
|
+
*/
|
|
106
|
+
auditAnchors?: string[];
|
|
107
|
+
}
|
|
108
|
+
export interface CoderActionResult {
|
|
109
|
+
/** Text for the next turn's user-input message. */
|
|
110
|
+
historyNote: string;
|
|
111
|
+
/**
|
|
112
|
+
* Canonical trace line for the host's run log (TURNS.md, etc). Block
|
|
113
|
+
* shape already indented; host can embed directly.
|
|
114
|
+
*/
|
|
115
|
+
log: string;
|
|
116
|
+
/** Hint: did the action mutate the artifact's shippable state? */
|
|
117
|
+
mutatedArtifact?: boolean;
|
|
118
|
+
/** Hint: did the action produce a browser screenshot? */
|
|
119
|
+
capturedScreenshot?: boolean;
|
|
120
|
+
/** Hint: runStart returned an origin. Host spins up its browser harness. */
|
|
121
|
+
liveOrigin?: string;
|
|
122
|
+
/** Hint: this action was a sandbox-tool or runCommand call. */
|
|
123
|
+
sandboxToolCall?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Raw exit code from sandbox-tool / runCommand calls. Set only when
|
|
126
|
+
* `sandboxToolCall` is true. Hosts can use this to drive their own
|
|
127
|
+
* pass/fail tracking without parsing the log string.
|
|
128
|
+
*/
|
|
129
|
+
toolExitCode?: number;
|
|
130
|
+
/** Multimodal attachments (screenshot PNG). */
|
|
131
|
+
attachments?: CoderActionAttachment[];
|
|
132
|
+
/** First-class continuity payload for the next turn. */
|
|
133
|
+
continuity?: CoderActionContinuity;
|
|
134
|
+
/** Mechanical outcome of the action. This is not quality judgment. */
|
|
135
|
+
ok?: boolean;
|
|
136
|
+
/** Broad executor family for batch semantics and host telemetry. */
|
|
137
|
+
kind?: CoderActionKind;
|
|
138
|
+
/** True when a same-turn action was not run because an earlier action failed. */
|
|
139
|
+
skipped?: boolean;
|
|
140
|
+
}
|
|
141
|
+
export type CoderActionKind = 'fileMutation' | 'read' | 'sandbox' | 'browser' | 'unhandled';
|
|
142
|
+
export interface CoderActionExecution<TAction extends {
|
|
143
|
+
name: string;
|
|
144
|
+
params: Record<string, unknown>;
|
|
145
|
+
} = {
|
|
146
|
+
name: string;
|
|
147
|
+
params: Record<string, unknown>;
|
|
148
|
+
}> {
|
|
149
|
+
action: TAction;
|
|
150
|
+
result: CoderActionResult | null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Return the text a host should carry into the immediately following
|
|
154
|
+
* continuity surface for a coder action.
|
|
155
|
+
*
|
|
156
|
+
* Use this instead of reading `continuity.staleText` directly. `staleText`
|
|
157
|
+
* is intentionally a later-turn tombstone; showing it immediately makes a
|
|
158
|
+
* successful read/search look as if the result was already unavailable.
|
|
159
|
+
*/
|
|
160
|
+
export declare function immediateCoderActionOutcome(result: Pick<CoderActionResult, 'historyNote' | 'continuity'>): string;
|
|
161
|
+
/**
|
|
162
|
+
* Return the compact factual note safe to share beyond the actor's private
|
|
163
|
+
* workset. This preserves the important truth ("file X was written",
|
|
164
|
+
* "edit failed", "console was read") without carrying large read/search
|
|
165
|
+
* payloads into another participant's history.
|
|
166
|
+
*/
|
|
167
|
+
export declare function compactCoderActionOutcome(result: Pick<CoderActionResult, 'historyNote' | 'continuity' | 'toolExitCode'>): string;
|
|
168
|
+
/**
|
|
169
|
+
* Return an outcome note suitable for stored chat history. Small factual
|
|
170
|
+
* results stay attached to the narrative that caused them ("I will list" is
|
|
171
|
+
* followed by the actual list result); large results decay to their compact
|
|
172
|
+
* recovery note so history does not become a file-content cache.
|
|
173
|
+
*/
|
|
174
|
+
export declare function historyCoderActionOutcome(result: Pick<CoderActionResult, 'historyNote' | 'continuity'>, options?: {
|
|
175
|
+
maxBytes?: number;
|
|
176
|
+
}): string;
|
|
177
|
+
export declare function coderActionOutcomeForLedger(action: Pick<ParsedAction, 'name' | 'params'>, result: Pick<CoderActionResult, 'historyNote' | 'continuity'>, options?: {
|
|
178
|
+
maxBytes?: number;
|
|
179
|
+
}): TurnLedgerActionOutcome;
|
|
180
|
+
/**
|
|
181
|
+
* Execute one parsed coder action. Returns the structured result if the
|
|
182
|
+
* name matches a coder primitive, or `null` if the host should dispatch
|
|
183
|
+
* it (benchmark-specific actions like markMilestone).
|
|
184
|
+
*
|
|
185
|
+
* Never throws on user input — every failure is surfaced through the
|
|
186
|
+
* `historyNote` + `log` strings so the model sees what went wrong.
|
|
187
|
+
*/
|
|
188
|
+
export declare function executeCoderAction(input: {
|
|
189
|
+
action: {
|
|
190
|
+
name: string;
|
|
191
|
+
params: Record<string, unknown>;
|
|
192
|
+
};
|
|
193
|
+
context: CoderExecutorContext;
|
|
194
|
+
}): Promise<CoderActionResult | null>;
|
|
195
|
+
/**
|
|
196
|
+
* Execute a same-turn batch of coder actions with truthful continuity.
|
|
197
|
+
*
|
|
198
|
+
* The model chose every action in the batch before seeing any tool result
|
|
199
|
+
* from that same batch. Successful actions remain durable facts; the model
|
|
200
|
+
* chose a sequence, not one hidden turn-wide transaction. After any failure,
|
|
201
|
+
* runTests and finishAttempt are skipped because their result would claim
|
|
202
|
+
* verification/completion for a turn where some intended tool work failed.
|
|
203
|
+
*
|
|
204
|
+
* Unknown actions return `null` so hosts can dispatch them normally.
|
|
205
|
+
*/
|
|
206
|
+
export declare function executeCoderActions<TAction extends {
|
|
207
|
+
name: string;
|
|
208
|
+
params: Record<string, unknown>;
|
|
209
|
+
}>(input: {
|
|
210
|
+
actions: readonly TAction[];
|
|
211
|
+
context: CoderExecutorContext;
|
|
212
|
+
onActionResult?(execution: CoderActionExecution<TAction>, context: CoderExecutorContext): Promise<void> | void;
|
|
213
|
+
}): Promise<Array<CoderActionExecution<TAction>>>;
|
|
214
|
+
export declare function collectCoderActionAttachmentsForNextTurn(results: readonly CoderActionResult[]): ChatAttachment[];
|
|
215
|
+
/**
|
|
216
|
+
* Resolve a model-supplied relative path against the workspace root,
|
|
217
|
+
* refusing any path that escapes the workspace. Throws — the model
|
|
218
|
+
* should never see a path-traversal attempt succeed.
|
|
219
|
+
*/
|
|
220
|
+
export declare function resolveWorkspacePath(root: string, relativePath: string): string;
|
|
221
|
+
/**
|
|
222
|
+
* Read a workspace file safely: returns a sentinel string for missing
|
|
223
|
+
* / oversized / binary files instead of throwing. No silent truncation
|
|
224
|
+
* for text files — if the model called readFile, it needs the full
|
|
225
|
+
* content to form editFile.oldText correctly.
|
|
226
|
+
*/
|
|
227
|
+
export declare function safeReadWorkspaceText(filePath: string): string;
|
|
228
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/builder/executor.ts"],"names":[],"mappings":"AAwDA,OAAO,KAAK,EACV,cAAc,EACf,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAA;AAI7B;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE;QAChB,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,4EAA4E;Q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