@tea-agent/loop-agent 0.43.0-next.17 → 0.43.0-next.19
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/AGENTS.md +1 -1
- package/CHANGELOG.md +68 -2309
- package/README.md +7 -0
- package/dist/application/dag/args.js +8 -0
- package/dist/application/task-lifecycle/advance.js +38 -7
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +2 -0
- package/dist/cli/program.js +3 -1
- package/dist/cli/update/init-surface-notifier.js +2 -0
- package/dist/cli/update/policy.js +2 -0
- package/dist/commands/cursor-prompt.js +2 -0
- package/dist/commands/dag-approve.js +2 -0
- package/dist/commands/dag-final-verification.js +2 -0
- package/dist/commands/dag-init-hybrid.js +2 -0
- package/dist/commands/dag-reconcile-tasks.js +2 -0
- package/dist/commands/dag-reject.js +2 -0
- package/dist/commands/dag-report.js +2 -0
- package/dist/commands/dag-rerun.js +2 -0
- package/dist/commands/dag-resume.js +2 -0
- package/dist/commands/dag-workflow-compile.js +2 -0
- package/dist/commands/dag-workflow-plan.js +2 -0
- package/dist/commands/dag-workflow-validate.js +2 -0
- package/dist/commands/delegate.js +2 -0
- package/dist/commands/examples.js +2 -0
- package/dist/commands/import-prd.js +2 -0
- package/dist/commands/init-model-catalog.js +2 -0
- package/dist/commands/init.js +19 -13
- package/dist/commands/instructions.js +2 -0
- package/dist/commands/knowledge.js +2 -0
- package/dist/commands/loop-benchmark.js +2 -0
- package/dist/commands/pi-prompt.js +2 -0
- package/dist/commands/pi-reuse-benchmark.js +2 -0
- package/dist/commands/promote-run.js +2 -0
- package/dist/commands/stats.js +1 -1
- package/dist/commands/study-init.js +2 -0
- package/dist/commands/task-advance.js +34 -0
- package/dist/commands/task-source-prepare.js +2 -0
- package/dist/commands/worktree-create.js +2 -0
- package/dist/commands/worktree-remove.js +2 -0
- package/dist/executors/dag-pi-executor.js +1640 -194
- package/dist/executors/pi-executor.js +85 -3
- package/dist/executors/pi-sdk-executor.js +18 -0
- package/dist/executors/shell-executor.js +92 -7
- package/dist/executors/shell-verification.js +3 -0
- package/dist/governance/exec-plans.js +6 -3
- package/dist/infrastructure/console/app-data.js +6 -0
- package/dist/shared/artifacts-core.js +2 -0
- package/dist/shared/backend-dogfood-preflight.js +47 -0
- package/dist/shared/dag-failure-category.js +3 -0
- package/dist/shared/git-progress.js +2 -0
- package/dist/shared/one-shot-prompt-args.js +2 -0
- package/dist/shared/operator/capabilities.js +180 -0
- package/dist/shared/package-metadata.js +6 -4
- package/dist/shared/pi-context-pressure/sift-bridge.js +1 -1
- package/dist/shared/reference-context.js +2 -0
- package/dist/task/config-types.js +29 -0
- package/dist/task/contract/project.js +9 -0
- package/dist/task/contract/recover.js +6 -0
- package/dist/task/contract/schema.js +17 -0
- package/dist/task/source-prepare/artifact-meta.js +9 -2
- package/dist/task/source-prepare/build-draft.js +60 -0
- package/dist/task/source-prepare/fragment-inventory.js +4 -1
- package/dist/task/source-prepare/parse-intent.js +36 -11
- package/dist/task/task-demand-routing.js +5 -2
- package/dist/worker/console/chat/browser-automation.js +468 -308
- package/dist/worker/console/chat/browser-routes.js +175 -57
- package/dist/worker/console/chat/explore-tools.js +5 -2
- package/dist/worker/console/chat/pi-mode-loop-isolation.js +155 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +115 -20
- package/dist/worker/console/chat/pi-runtime/custom-tools/operator-tools.js +24 -16
- package/dist/worker/console/chat/pi-runtime/custom-tools/scheduled-goal-tools.js +22 -0
- package/dist/worker/console/chat/pi-runtime/progressive-tools.js +195 -0
- package/dist/worker/console/chat/pi-runtime.js +95 -28
- package/dist/worker/console/chat/routes.js +20 -1
- package/dist/worker/console/chat/scheduled-goal-booking.js +59 -0
- package/dist/worker/console/chat/scheduled-goal-delivery.js +27 -0
- package/dist/worker/console/chat/scheduled-goal-request.js +190 -0
- package/dist/worker/console/chat/sdd-data-alignment.js +1 -1
- package/dist/worker/console/chat/session-mode.js +8 -4
- package/dist/worker/console/chat/session-store.js +42 -9
- package/dist/worker/console/chat/tool-preview.js +115 -0
- package/dist/worker/console/chat/tools.js +7 -1
- package/dist/worker/console/chat/turn-order.js +13 -0
- package/dist/worker/console/chat/turn-process.js +32 -30
- package/dist/worker/console/operator-actions.js +50 -0
- package/dist/worker/console/prd-intake-bridge.js +54 -1
- package/dist/worker/console/scheduled-goal-host.js +98 -0
- package/dist/worker/console/scheduled-goal-operation-adapter.js +127 -0
- package/dist/worker/console/server.js +15 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-C4NXyedy.js → abnfDiagram-N423BO3Z-8-j6y-sd.js} +1 -1
- package/dist/worker/console/static/assets/{arc-NZ3qXvBI.js → arc-eoQiMvuk.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-COZSRvml.js → architectureDiagram-T3A2C74G-C4A3uMcI.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Ck0Gxi9C.js → blockDiagram-VBNYF7ZC-D4zD2F-Q.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BX5HQ4Ox.js → c4Diagram-5PPSVZJV-j1RkJziL.js} +1 -1
- package/dist/worker/console/static/assets/channel-ChE7y-cx.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-CoviemSL.js → chunk-2GRJ4B5K-YBHmhik1.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-DbOdOkbZ.js → chunk-2Q5K7J3B-COfWyo9P.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-BsG2pmdQ.js → chunk-5RXB4S5H-I99OUkHY.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-DGdvrNm8.js → chunk-5VM5RSS4-XKxoJNJ4.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-BAy7Yd6y.js → chunk-6Q2QTUOP-DLT_cYx1.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-D9UA7hUb.js → chunk-GF5L2VYU-CxcKZ9mV.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DPz7SZ8V.js → chunk-JWPE2WC7-V1EqXdjY.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-BmuEOIh7.js → chunk-KBJHAD2P-DebTtdFp.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-CIhBWnd8.js → chunk-RYQCIY6F-B-ivNRDf.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-CScR6mDD.js → chunk-XXDRQBXY-DC_Ds11b.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-C01TCf2X.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-C01TCf2X.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BjpfWaUr.js → cose-bilkent-JH36ORCC-sWEqKwIb.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-BFQohJgT.js → cynefin-VYW2F7L2-BXa_dcu4.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-D3gzRJnS.js → cynefinDiagram-MW4NZA55-C-Mle84F.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-5eojkhoA.js → dagre-VZM6K2ZE-CXPDBITe.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-CpD8LWu_.js → diagram-7IWD3JNH-CC-WJQfa.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-B8_4qJ2a.js → diagram-B4RE2ZJO-CDAV5Vs4.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-HOsXf0eu.js → diagram-LBJQPF4R-CmFiAcNz.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-BqwRwiWP.js → diagram-Q27KOJAE-DPBZHuyn.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-BRVCNZe1.js → diagram-UB23O5K3-jUlm_Ds3.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-Cvb1TgGh.js → ebnfDiagram-BXEA7PRR-DWhQ3mfY.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DS0O0qG9.js → erDiagram-JOGREHBK-Tr2gMqet.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-BHIRvRr3.js → flowDiagram-UKHOOZJN-DJjVQHPA.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-DcCJ1JWx.js → ganttDiagram-PKOTCBZU-D74dQ4u0.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-B9ia5ony.js → gitGraphDiagram-DS77QQ5N-DwW0tZ0X.js} +1 -1
- package/dist/worker/console/static/assets/index-BWkIfcrK.css +1 -0
- package/dist/worker/console/static/assets/{index-wXlQohNs.js → index-Cdkvw_H6.js} +97 -97
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-3ogpgegn.js → infoDiagram-6WML65LV-ILCbxJyb.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-4tgpQ5SL.js → ishikawaDiagram-WSZJBQD7-DeuWBQ89.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DNfgHqFx.js → journeyDiagram-NVQOT4AX-CF5ih8Fk.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-Dz7ngC8z.js → kanban-definition-27J2QSJJ-C7yOSuRO.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DI7Jv62E.js → linear-BDZ9riWi.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-CQA4Nzmo.js → mermaid.core-7pKqYtpZ.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-CtsMc8Mf.js → mindmap-definition-FAOFIHXS-LeJDybSU.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-ByppE9yH.js → pegDiagram-VL7TDLO6-BJvT3pMD.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-B5PtgFgt.js → pieDiagram-7S7Q4E2Y-_rGqpMan.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-Cq4p0k2K.js → quadrantDiagram-CIZ2JOQS-DPcSv5aA.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-DjfkyljN.js → railroadDiagram-AXF67PYL-Drxx4hkJ.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DzynNRSl.js → requirementDiagram-LRYGKXZP-BCTUdU4z.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-Cj7TCpTJ.js → sankeyDiagram-W5VNT64P-B6wzbZmB.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-C73C6ykA.js → sequenceDiagram-SI44F4Z6-BGt8d3QQ.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-BiNLgN2x.js → sizeCapture-X5ZJPWSS-7nlhJKo7.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-UwvjS64-.js → stateDiagram-OKZ733FA-Cv2stqMA.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DC7V5vcq.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-CC7DH98r.js → swimlanes-SLNWSIFB-qDAo4Yc1.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Bwy4QUTO.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-LSBXTR70.js → timeline-definition-Z64GVDOM-CKbDNKTr.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BAuxWwGP.js → vennDiagram-T6HMQDX7-DI-9EHic.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y--E5_gjZx.js → wardleyDiagram-T6FBY63Y-BrzzRDpX.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-dJWNmyzF.js → xychartDiagram-ELKLHX3M-BclH5hGh.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +41 -11
- package/dist/worker/console/static-src/operator-chat/compaction-message.js +3 -17
- package/dist/worker/console/static-src/operator-chat/slash-palette-nav.js +15 -5
- package/dist/worker/console/static-src/operator-chat/timeline-merge.js +29 -0
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +2 -5
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +2 -0
- package/dist/worker/console/static-src/prd-file-import.js +3 -1
- package/dist/worker/console/workspace-context.js +17 -1
- package/dist/worker/delivery/git-transaction.js +2 -0
- package/dist/worker/feature/fullstack-validate.js +2 -0
- package/dist/worker/loop-agent/loop-agent-client.js +8 -2
- package/dist/worker/materialize/harness-task-materializer.js +4 -1
- package/dist/worker/metrics/projector.js +1 -1
- package/dist/worker/observability/event-store.js +4 -1
- package/dist/worker/observability/read-model.js +4 -1
- package/dist/worker/observe/node-transparency.js +23 -1
- package/dist/worker/observe/routes.js +4 -0
- package/dist/worker/observe/static/operator-chrome.js +3 -1
- package/dist/worker/outcomes/declared-artifacts.js +2 -0
- package/dist/worker/preflight.js +3 -0
- package/dist/worker/scheduler/scheduled-goal-dispatch.js +117 -0
- package/dist/worker/scheduler/scheduled-goal-evidence.js +167 -0
- package/dist/worker/scheduler/scheduled-goal-recovery.js +62 -0
- package/dist/worker/scheduler/scheduled-goal-store.js +699 -0
- package/dist/worker/scheduler/scheduled-goal-supervisor.js +132 -0
- package/dist/worker/scheduler/scheduled-goal-time.js +102 -0
- package/dist/worker/scheduler/scheduled-goal-types.js +95 -0
- package/dist/worker/task-spec/validate.js +4 -1
- package/dist/workflows/dag/backend-test-markdown-workflow.js +6 -24
- package/dist/workflows/dag/backend-test-plan-protocol.js +82 -5
- package/dist/workflows/dag/dag-retry-schema.js +11 -0
- package/dist/workflows/dag/decision-envelope.js +2 -0
- package/dist/workflows/dag/dynamic-runtime/shared.js +2 -2
- package/dist/workflows/dag/frontend-closeout.js +4 -2
- package/dist/workflows/dag/frontend-committed-facts.js +461 -0
- package/dist/workflows/dag/frontend-durable-tools.js +15 -3
- package/dist/workflows/dag/frontend-implementation-contract.js +365 -8
- package/dist/workflows/dag/frontend-plan-canary.js +53 -0
- package/dist/workflows/dag/frontend-plan-decision-contract.js +803 -0
- package/dist/workflows/dag/frontend-plan-render.js +0 -2
- package/dist/workflows/dag/frontend-prewrite-gate.js +3 -3
- package/dist/workflows/dag/frontend-provider-capability-matrix.js +8 -61
- package/dist/workflows/dag/frontend-recovery-run.js +57 -0
- package/dist/workflows/dag/frontend-review-context.js +43 -70
- package/dist/workflows/dag/frontend-risk.js +92 -10
- package/dist/workflows/dag/frontend-session-budget.js +117 -3
- package/dist/workflows/dag/frontend-shape.js +11 -55
- package/dist/workflows/dag/frontend-test-execution-evidence.js +35 -10
- package/dist/workflows/dag/frontend-typed-event-store.js +32 -25
- package/dist/workflows/dag/frontend-verification-trace.js +25 -12
- package/dist/workflows/dag/frontend-writer-admission.js +3 -47
- package/dist/workflows/dag/frontend-writer-status.js +0 -23
- package/dist/workflows/dag/init-hybrid.js +202 -111
- package/dist/workflows/dag/interrupt-request.js +2 -0
- package/dist/workflows/dag/lifecycle.js +11 -2
- package/dist/workflows/dag/node-execution.js +50 -13
- package/dist/workflows/dag/reconcile-run.js +2 -0
- package/dist/workflows/dag/repair-artifact.js +3 -1
- package/dist/workflows/dag/report.js +2 -0
- package/dist/workflows/dag/rerun-plan.js +10 -0
- package/dist/workflows/dag/rerun-task.js +79 -1
- package/dist/workflows/dag/retry-policy.js +18 -0
- package/dist/workflows/dag/scheduler.js +2 -4
- package/dist/workflows/dag/types.js +44 -6
- package/dist/workflows/dag/validate.js +4 -0
- package/docs/README.md +1 -0
- package/docs/governance/README.md +1 -0
- package/docs/init-surface.manifest.json +1 -0
- package/docs/operations/README.md +2 -0
- package/docs/templates/README.md +1 -1
- package/docs/templates/agent-dag.schema.json +2 -2
- package/docs/templates/backend-test-dag.json +14 -10
- package/docs/templates/frontend-implementation-contract.schema.json +0 -7
- package/docs/templates/frontend-implementation-dag.json +8 -9
- package/package.json +8 -3
- package/skills/frontend-bounded-implement/SKILL.md +3 -4
- package/skills/frontend-design-review/SKILL.md +7 -12
- package/skills/frontend-design-review/references/review-checklist.md +7 -7
- package/skills/frontend-plan/SKILL.md +8 -18
- package/skills/frontend-plan/references/decision-contract.md +19 -26
- package/skills/frontend-review/SKILL.md +21 -25
- package/skills/frontend-review/references/review-findings.md +48 -24
- package/dist/worker/console/static/assets/channel-BxdTlb_5.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-_ByA1Nf8.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-_ByA1Nf8.js +0 -1
- package/dist/worker/console/static/assets/index-B9goN3S5.css +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-nLgMZ0D3.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BcYqTady.js +0 -8
- package/dist/workflows/dag/frontend-shadow-dual-write.js +0 -975
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HTTP
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* refuses to embed a site). The probe is display-only (headers back to the
|
|
6
|
-
* caller), restricted to http(s) URLs, with a hard timeout. Local addresses
|
|
7
|
-
* are allowed — the panel routinely browses local dev servers.
|
|
2
|
+
* HTTP API for the Console Browser panel. The panel renders screenshots from
|
|
3
|
+
* the controlled browser and sends pointer/keyboard input back to the same
|
|
4
|
+
* Playwright page used by Operator Chat tools.
|
|
8
5
|
*/
|
|
9
6
|
import { embeddabilityOf, extractFrameAncestors, normalizeBrowserUrl, } from "./browser-policy.js";
|
|
10
7
|
function workspaceIdOf(req) {
|
|
@@ -22,7 +19,38 @@ function sendJson(res, status, body) {
|
|
|
22
19
|
});
|
|
23
20
|
res.end(JSON.stringify(body));
|
|
24
21
|
}
|
|
25
|
-
|
|
22
|
+
function errorPayload(error) {
|
|
23
|
+
return {
|
|
24
|
+
code: error instanceof Error && "code" in error
|
|
25
|
+
? String(error.code)
|
|
26
|
+
: "BROWSER_OPERATION_FAILED",
|
|
27
|
+
message: error instanceof Error ? error.message : String(error),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function requireScope(req, deps) {
|
|
31
|
+
const ws = workspaceIdOf(req);
|
|
32
|
+
if (!ws) {
|
|
33
|
+
return { ok: false, status: 400, code: "WORKSPACE_REQUIRED", message: "workspaceId is required" };
|
|
34
|
+
}
|
|
35
|
+
if (deps.requireWorkspace && !deps.requireWorkspace(req).ok) {
|
|
36
|
+
return { ok: false, status: 403, code: "WORKSPACE_DENIED", message: "workspace scope mismatch" };
|
|
37
|
+
}
|
|
38
|
+
return { ok: true };
|
|
39
|
+
}
|
|
40
|
+
async function readJson(req) {
|
|
41
|
+
const chunks = [];
|
|
42
|
+
let size = 0;
|
|
43
|
+
for await (const chunk of req) {
|
|
44
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
45
|
+
size += buffer.byteLength;
|
|
46
|
+
if (size > 1024 * 1024)
|
|
47
|
+
throw new Error("request body exceeds 1MB");
|
|
48
|
+
chunks.push(buffer);
|
|
49
|
+
}
|
|
50
|
+
if (chunks.length === 0)
|
|
51
|
+
return {};
|
|
52
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
53
|
+
}
|
|
26
54
|
export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
27
55
|
if (!pathname.startsWith("/api/operator/v1/chat/browser"))
|
|
28
56
|
return false;
|
|
@@ -31,27 +59,33 @@ export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
|
31
59
|
const parts = rest.split("/").filter(Boolean);
|
|
32
60
|
const sub = parts[0] ?? "";
|
|
33
61
|
try {
|
|
34
|
-
if (method === "GET" && sub === "
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
62
|
+
if (method === "GET" && sub === "state" && parts.length === 1) {
|
|
63
|
+
const scope = requireScope(req, deps);
|
|
64
|
+
if (!scope.ok) {
|
|
65
|
+
sendJson(res, scope.status, {
|
|
66
|
+
ok: false,
|
|
67
|
+
error: { code: scope.code, message: scope.message },
|
|
68
|
+
});
|
|
69
|
+
return true;
|
|
45
70
|
}
|
|
46
|
-
|
|
47
|
-
sendJson(res,
|
|
71
|
+
if (!deps.automation) {
|
|
72
|
+
sendJson(res, 200, { ok: true, data: { page: null } });
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
const page = await deps.automation.state();
|
|
76
|
+
sendJson(res, 200, { ok: true, data: { page } });
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (method === "GET" && sub === "probe" && parts.length === 1) {
|
|
80
|
+
const scope = requireScope(req, deps);
|
|
81
|
+
if (!scope.ok) {
|
|
82
|
+
sendJson(res, scope.status, {
|
|
48
83
|
ok: false,
|
|
49
|
-
error: { code:
|
|
84
|
+
error: { code: scope.code, message: scope.message },
|
|
50
85
|
});
|
|
51
86
|
return true;
|
|
52
87
|
}
|
|
53
|
-
const
|
|
54
|
-
const raw = url.searchParams.get("url") ?? "";
|
|
88
|
+
const raw = new URL(req.url ?? "/", "http://localhost").searchParams.get("url") ?? "";
|
|
55
89
|
const normalized = normalizeBrowserUrl(raw);
|
|
56
90
|
if (normalized.kind !== "ok") {
|
|
57
91
|
sendJson(res, 400, {
|
|
@@ -65,26 +99,22 @@ export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
|
65
99
|
});
|
|
66
100
|
return true;
|
|
67
101
|
}
|
|
68
|
-
const parsed = new URL(normalized.url);
|
|
69
102
|
const controller = new AbortController();
|
|
70
103
|
const timer = setTimeout(() => controller.abort(), 8000);
|
|
71
104
|
try {
|
|
72
|
-
let response = await fetch(
|
|
105
|
+
let response = await fetch(normalized.url, {
|
|
73
106
|
method: "HEAD",
|
|
74
107
|
redirect: "follow",
|
|
75
108
|
signal: controller.signal,
|
|
76
109
|
});
|
|
77
|
-
// Some servers answer HEAD with 405/501; retry once as GET
|
|
78
|
-
// (the body is discarded — only the headers matter).
|
|
79
110
|
if (response.status === 405 || response.status === 501) {
|
|
80
|
-
response = await fetch(
|
|
111
|
+
response = await fetch(normalized.url, {
|
|
81
112
|
method: "GET",
|
|
82
113
|
redirect: "follow",
|
|
83
114
|
signal: controller.signal,
|
|
84
115
|
});
|
|
85
116
|
}
|
|
86
|
-
const
|
|
87
|
-
const frameAncestors = extractFrameAncestors(csp);
|
|
117
|
+
const frameAncestors = extractFrameAncestors(response.headers.get("content-security-policy"));
|
|
88
118
|
const xFrameOptions = response.headers.get("x-frame-options");
|
|
89
119
|
const probe = {
|
|
90
120
|
reachable: true,
|
|
@@ -100,11 +130,12 @@ export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
|
100
130
|
return true;
|
|
101
131
|
}
|
|
102
132
|
catch {
|
|
103
|
-
// DNS / TLS / connection / timeout: nothing to judge — the
|
|
104
|
-
// client keeps the plain iframe.
|
|
105
133
|
sendJson(res, 200, {
|
|
106
134
|
ok: true,
|
|
107
|
-
data: {
|
|
135
|
+
data: {
|
|
136
|
+
probe: { reachable: false },
|
|
137
|
+
verdict: "unknown",
|
|
138
|
+
},
|
|
108
139
|
});
|
|
109
140
|
return true;
|
|
110
141
|
}
|
|
@@ -112,30 +143,25 @@ export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
|
112
143
|
clearTimeout(timer);
|
|
113
144
|
}
|
|
114
145
|
}
|
|
115
|
-
if (method === "
|
|
116
|
-
const
|
|
117
|
-
if (!
|
|
118
|
-
sendJson(res,
|
|
146
|
+
if (method === "POST" && parts.length >= 1) {
|
|
147
|
+
const scope = requireScope(req, deps);
|
|
148
|
+
if (!scope.ok) {
|
|
149
|
+
sendJson(res, scope.status, {
|
|
119
150
|
ok: false,
|
|
120
|
-
error: { code:
|
|
151
|
+
error: { code: scope.code, message: scope.message },
|
|
121
152
|
});
|
|
122
153
|
return true;
|
|
123
154
|
}
|
|
124
|
-
if (deps.requireWorkspace) {
|
|
125
|
-
const scope = deps.requireWorkspace(req);
|
|
126
|
-
if (!scope.ok) {
|
|
127
|
-
sendJson(res, 403, {
|
|
128
|
-
ok: false,
|
|
129
|
-
error: { code: "WORKSPACE_DENIED", message: "workspace scope mismatch" },
|
|
130
|
-
});
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
155
|
if (!deps.automation) {
|
|
135
|
-
sendJson(res,
|
|
156
|
+
sendJson(res, 503, {
|
|
157
|
+
ok: false,
|
|
158
|
+
error: { code: "BROWSER_UNAVAILABLE", message: "browser service unavailable" },
|
|
159
|
+
});
|
|
136
160
|
return true;
|
|
137
161
|
}
|
|
138
|
-
|
|
162
|
+
const body = await readJson(req);
|
|
163
|
+
const result = await dispatchBrowserPost(deps.automation, sub, body);
|
|
164
|
+
sendJson(res, 200, { ok: true, data: result });
|
|
139
165
|
return true;
|
|
140
166
|
}
|
|
141
167
|
sendJson(res, 404, {
|
|
@@ -146,13 +172,7 @@ export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
|
146
172
|
}
|
|
147
173
|
catch (error) {
|
|
148
174
|
if (!res.headersSent) {
|
|
149
|
-
sendJson(res, 500, {
|
|
150
|
-
ok: false,
|
|
151
|
-
error: {
|
|
152
|
-
code: "BROWSER_INTERNAL",
|
|
153
|
-
message: error instanceof Error ? error.message : String(error),
|
|
154
|
-
},
|
|
155
|
-
});
|
|
175
|
+
sendJson(res, 500, { ok: false, error: errorPayload(error) });
|
|
156
176
|
}
|
|
157
177
|
else {
|
|
158
178
|
res.end();
|
|
@@ -160,3 +180,101 @@ export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
|
160
180
|
return true;
|
|
161
181
|
}
|
|
162
182
|
}
|
|
183
|
+
async function dispatchBrowserPost(automation, action, body) {
|
|
184
|
+
switch (action) {
|
|
185
|
+
case "navigate": {
|
|
186
|
+
const result = await automation.navigate(string(body.url));
|
|
187
|
+
if (!result.ok)
|
|
188
|
+
throw new BrowserRouteError(result.code, result.error);
|
|
189
|
+
return result.page;
|
|
190
|
+
}
|
|
191
|
+
case "focus":
|
|
192
|
+
return automation.focus();
|
|
193
|
+
case "reload":
|
|
194
|
+
return automation.reload();
|
|
195
|
+
case "back":
|
|
196
|
+
return automation.goBack();
|
|
197
|
+
case "forward":
|
|
198
|
+
return automation.goForward();
|
|
199
|
+
case "scroll":
|
|
200
|
+
return automation.scroll({
|
|
201
|
+
direction: body.direction === "up" ? "up" : "down",
|
|
202
|
+
amount: numberOrUndefined(body.amount),
|
|
203
|
+
});
|
|
204
|
+
case "tab":
|
|
205
|
+
if (body.mode === "new")
|
|
206
|
+
return automation.newTab(optionalString(body.url));
|
|
207
|
+
if (body.mode === "close")
|
|
208
|
+
return automation.closeTab(numberOrUndefined(body.tabId));
|
|
209
|
+
return automation.selectTab(number(body.tabId));
|
|
210
|
+
case "dialog":
|
|
211
|
+
return automation.handleDialog(body.action === "dismiss" ? "dismiss" : "accept", optionalString(body.promptText));
|
|
212
|
+
case "pointer": {
|
|
213
|
+
const type = string(body.type);
|
|
214
|
+
if (!["mousemove", "mousedown", "mouseup", "wheel"].includes(type)) {
|
|
215
|
+
throw new Error("invalid pointer event type");
|
|
216
|
+
}
|
|
217
|
+
const event = type === "wheel"
|
|
218
|
+
? {
|
|
219
|
+
type,
|
|
220
|
+
x: number(body.x),
|
|
221
|
+
y: number(body.y),
|
|
222
|
+
deltaX: number(body.deltaX ?? 0),
|
|
223
|
+
deltaY: number(body.deltaY ?? 0),
|
|
224
|
+
}
|
|
225
|
+
: {
|
|
226
|
+
type,
|
|
227
|
+
x: number(body.x),
|
|
228
|
+
y: number(body.y),
|
|
229
|
+
...(body.button === "middle" || body.button === "right"
|
|
230
|
+
? { button: body.button }
|
|
231
|
+
: {}),
|
|
232
|
+
};
|
|
233
|
+
return automation.dispatchPointer(event);
|
|
234
|
+
}
|
|
235
|
+
case "keyboard": {
|
|
236
|
+
const type = string(body.type);
|
|
237
|
+
if (type !== "keydown" && type !== "keyup")
|
|
238
|
+
throw new Error("invalid keyboard event type");
|
|
239
|
+
const key = string(body.key);
|
|
240
|
+
if (!isPanelKeyboardKey(key)) {
|
|
241
|
+
throw new Error("invalid keyboard key; use the text action for printable characters");
|
|
242
|
+
}
|
|
243
|
+
return automation.dispatchKeyboard({ type, key });
|
|
244
|
+
}
|
|
245
|
+
case "text":
|
|
246
|
+
return automation.inputText(string(body.text));
|
|
247
|
+
case "wait":
|
|
248
|
+
return automation.waitFor(number(body.ms ?? 500));
|
|
249
|
+
default:
|
|
250
|
+
throw new Error(`unknown browser action: ${action}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
class BrowserRouteError extends Error {
|
|
254
|
+
code;
|
|
255
|
+
constructor(code, message) {
|
|
256
|
+
super(message);
|
|
257
|
+
this.code = code;
|
|
258
|
+
this.name = "BrowserRouteError";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function string(value) {
|
|
262
|
+
if (typeof value !== "string")
|
|
263
|
+
throw new Error("expected string");
|
|
264
|
+
return value;
|
|
265
|
+
}
|
|
266
|
+
function optionalString(value) {
|
|
267
|
+
return typeof value === "string" ? value : undefined;
|
|
268
|
+
}
|
|
269
|
+
function number(value) {
|
|
270
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
271
|
+
throw new Error("expected finite number");
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
274
|
+
function numberOrUndefined(value) {
|
|
275
|
+
return value === undefined || value === null ? undefined : number(value);
|
|
276
|
+
}
|
|
277
|
+
function isPanelKeyboardKey(key) {
|
|
278
|
+
return /^(Control|Meta|Alt|Shift)(\+[A-Za-z0-9][A-Za-z0-9]*)?$/.test(key)
|
|
279
|
+
|| (key.length > 1 && /^[A-Za-z][A-Za-z0-9]*$/.test(key));
|
|
280
|
+
}
|
|
@@ -279,8 +279,11 @@ export async function safeGrep(repoRoot, pattern, options) {
|
|
|
279
279
|
for (let i = 0; i < lines.length; i++) {
|
|
280
280
|
if (matches.length >= GREP_MATCH_LIMIT)
|
|
281
281
|
break;
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
const line = lines[i];
|
|
283
|
+
if (line === undefined)
|
|
284
|
+
continue;
|
|
285
|
+
if (re.test(line)) {
|
|
286
|
+
const { scrubbed, redactions } = scrubSecrets(line);
|
|
284
287
|
if (redactions.length > 0) {
|
|
285
288
|
for (const r of redactions) {
|
|
286
289
|
const found = totalRedactions.find((t) => t.name === r.name);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi-mode loop isolation for loop-agent init projections.
|
|
3
|
+
*
|
|
4
|
+
* Pi mode ("自由对话") should not auto-load the governance AGENTS.md managed
|
|
5
|
+
* block that `loop-agent init` writes into a target project, nor the loop-agent
|
|
6
|
+
* built-in skills it mirrors into `<cwd>/.agents/skills/`. Manual `/skills:name`
|
|
7
|
+
* invocation and third-party/custom project skills must stay available; the
|
|
8
|
+
* Workflow mode is untouched (isolation applied only for `sessionMode ===
|
|
9
|
+
* "pi"`).
|
|
10
|
+
*
|
|
11
|
+
* Everything here is a pure function over discovered resources + persisted
|
|
12
|
+
* auto-invocation prefs, so it is trivially unit-testable.
|
|
13
|
+
*/
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { skillResourceId, } from "./resource-preferences-store.js";
|
|
16
|
+
/** init.ts `MANAGED_BLOCK_START` / `MANAGED_BLOCK_END` (docs/templates/init-managed-agents.md). */
|
|
17
|
+
export const LOOP_AGENTS_MANAGED_BLOCK_START = "<!-- LOOP_AGENT_INIT_START -->";
|
|
18
|
+
export const LOOP_AGENTS_MANAGED_BLOCK_END = "<!-- LOOP_AGENT_INIT_END -->";
|
|
19
|
+
/**
|
|
20
|
+
* Built-in skill directory names that `loop-agent init` mirrors from the
|
|
21
|
+
* package's `skills/` into a target project's `.agents/skills/`.
|
|
22
|
+
*
|
|
23
|
+
* MUST be kept in sync with the repo-root `skills/` directory; a CI check
|
|
24
|
+
* asserts they match (see `scripts/check-loop-builtin-skills.sh`).
|
|
25
|
+
*/
|
|
26
|
+
export const LOOP_BUILTIN_SKILL_DIR_NAMES = [
|
|
27
|
+
"agent-worker",
|
|
28
|
+
"ai-engineering-context",
|
|
29
|
+
"analyze-product-dependencies",
|
|
30
|
+
"analyze-product-requirements",
|
|
31
|
+
"browser-tools",
|
|
32
|
+
"code-review-core",
|
|
33
|
+
"codebase-scout",
|
|
34
|
+
"fe-test-ui-scout",
|
|
35
|
+
"frontend-bounded-implement",
|
|
36
|
+
"frontend-contract",
|
|
37
|
+
"frontend-design-review",
|
|
38
|
+
"frontend-plan",
|
|
39
|
+
"frontend-review",
|
|
40
|
+
"frontend-scout",
|
|
41
|
+
"frontend-verification",
|
|
42
|
+
"grill-me",
|
|
43
|
+
"grill-with-docs",
|
|
44
|
+
"improve-codebase-architecture",
|
|
45
|
+
"init-capability-evolution",
|
|
46
|
+
"local-jacoco-coverage",
|
|
47
|
+
"loop-agent",
|
|
48
|
+
"playwright-cli",
|
|
49
|
+
"playwright-cli-case-generator",
|
|
50
|
+
"requesting-code-review",
|
|
51
|
+
"systematic-debugging",
|
|
52
|
+
"test-driven-development",
|
|
53
|
+
"using-git-worktrees",
|
|
54
|
+
"verification-before-completion",
|
|
55
|
+
"webapp-testing",
|
|
56
|
+
];
|
|
57
|
+
/* Case-insensitive set for fast membership (paths are compared lower-cased). */
|
|
58
|
+
const LOOP_BUILTIN_SKILL_NAMES_LOWER = new Set(LOOP_BUILTIN_SKILL_DIR_NAMES.map((name) => name.toLowerCase()));
|
|
59
|
+
/** Normalize to forward slashes + lower case for Windows/macOS path compares. */
|
|
60
|
+
function normalizeForCompare(value) {
|
|
61
|
+
return value.replace(/\\/g, "/").toLowerCase();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Strip the loop-agent init managed block (inclusive of both markers) from an
|
|
65
|
+
* AGENTS.md content string.
|
|
66
|
+
*
|
|
67
|
+
* Returns the content unchanged when no valid marker pair is present (missing
|
|
68
|
+
* either marker, or END before START), so user-authored AGENTS.md and non-loop
|
|
69
|
+
* roots are never touched.
|
|
70
|
+
*/
|
|
71
|
+
export function stripLoopManagedBlock(content) {
|
|
72
|
+
const start = content.indexOf(LOOP_AGENTS_MANAGED_BLOCK_START);
|
|
73
|
+
if (start < 0)
|
|
74
|
+
return content;
|
|
75
|
+
const end = content.indexOf(LOOP_AGENTS_MANAGED_BLOCK_END, start + LOOP_AGENTS_MANAGED_BLOCK_START.length);
|
|
76
|
+
if (end < 0)
|
|
77
|
+
return content;
|
|
78
|
+
const endPos = end + LOOP_AGENTS_MANAGED_BLOCK_END.length;
|
|
79
|
+
const before = content.slice(0, start).trimEnd();
|
|
80
|
+
const after = content.slice(endPos).trimStart();
|
|
81
|
+
return `${before}${before && after ? "\n\n" : ""}${after}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* True when a discovered skill is a loop-agent init projection: its file path
|
|
85
|
+
* is under `<cwd>/.agents/skills/<builtin-name>/` for a name in the builtin
|
|
86
|
+
* whitelist. Global user skills (`~/.agents/skills`, `~/.pi/agent/skills`) and
|
|
87
|
+
* third-party project skills outside the whitelist return false.
|
|
88
|
+
*/
|
|
89
|
+
export function isLoopInitProjectedSkill(skill, cwd) {
|
|
90
|
+
if (!skill?.filePath)
|
|
91
|
+
return false;
|
|
92
|
+
const cwdNorm = normalizeForCompare(path.resolve(cwd));
|
|
93
|
+
const fileNorm = normalizeForCompare(path.resolve(skill.filePath));
|
|
94
|
+
const prefix = `${cwdNorm}/.agents/skills/`;
|
|
95
|
+
if (!fileNorm.startsWith(prefix))
|
|
96
|
+
return false;
|
|
97
|
+
const rest = fileNorm.slice(prefix.length);
|
|
98
|
+
const topSeg = rest.split("/")[0];
|
|
99
|
+
if (!topSeg)
|
|
100
|
+
return false;
|
|
101
|
+
return LOOP_BUILTIN_SKILL_NAMES_LOWER.has(topSeg);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Pi-mode default isolation over skills: for skills that are loop init
|
|
105
|
+
* projections, default `disableModelInvocation` to true UNLESS the user has
|
|
106
|
+
* EXPLICITLY tuned auto-invocation ON for that resource id in the persisted
|
|
107
|
+
* prefs. Explicitly ON wins over the Pi default; explicit OFF is treated as the
|
|
108
|
+
* Pi default. Non-loop skills pass through untouched.
|
|
109
|
+
*/
|
|
110
|
+
export function applyPiModeSkillIsolation(skills, prefs, cwd) {
|
|
111
|
+
return skills.map((skill) => {
|
|
112
|
+
if (!isLoopInitProjectedSkill(skill, cwd))
|
|
113
|
+
return skill;
|
|
114
|
+
const id = skillResourceId(skill);
|
|
115
|
+
const pref = prefs.skills[id];
|
|
116
|
+
if (pref?.autoInvocationEnabled === true)
|
|
117
|
+
return skill;
|
|
118
|
+
if (skill.disableModelInvocation === true)
|
|
119
|
+
return skill;
|
|
120
|
+
return { ...skill, disableModelInvocation: true };
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Build the pi-mode loop isolation resource-loader option fragments.
|
|
125
|
+
*
|
|
126
|
+
* - When `enabled` (session mode pi): returns an `agentsFilesOverride` that
|
|
127
|
+
* strips the loop-agent managed AGENTS.md block, and wraps the given
|
|
128
|
+
* `skillsOverride` so it ALSO applies Pi-mode default isolation after the
|
|
129
|
+
* persisted auto-invocation prefs.
|
|
130
|
+
* - When disabled (workflow): returns ONLY the provided `skillsOverride`
|
|
131
|
+
* unchanged, so workflow session behavior is byte-for-byte identical to today.
|
|
132
|
+
*/
|
|
133
|
+
export function buildPiModeLoopIsolationOptions(options) {
|
|
134
|
+
if (!options.enabled) {
|
|
135
|
+
return { skillsOverride: options.skillsOverride };
|
|
136
|
+
}
|
|
137
|
+
const { cwd, readPreferences } = options;
|
|
138
|
+
const agentsFilesOverride = (current) => ({
|
|
139
|
+
agentsFiles: current.agentsFiles.map((file) => ({
|
|
140
|
+
...file,
|
|
141
|
+
content: stripLoopManagedBlock(file.content),
|
|
142
|
+
})),
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
agentsFilesOverride,
|
|
146
|
+
skillsOverride: (current) => {
|
|
147
|
+
const prefs = readPreferences() ?? { schemaVersion: 1, skills: {} };
|
|
148
|
+
const withPrefs = options.skillsOverride(current);
|
|
149
|
+
return {
|
|
150
|
+
skills: applyPiModeSkillIsolation(withPrefs.skills, prefs, cwd),
|
|
151
|
+
diagnostics: current.diagnostics,
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session-independent browser tools shared by workflow and Pi chat
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Session-independent Playwright browser tools shared by workflow and Pi chat
|
|
3
|
+
* modes. Actions use refs from the AI-mode aria snapshot and return a fresh
|
|
4
|
+
* snapshot. Screenshots are captured only by the explicit screenshot tool.
|
|
5
5
|
*/
|
|
6
|
-
const BROWSER_TOOLS_DESCRIPTION = "Operate the Console sidebar
|
|
6
|
+
const BROWSER_TOOLS_DESCRIPTION = "Operate the workspace-controlled visible external browser. The Console sidebar stays an iframe and does not proxy page input. `browser_navigate` opens a URL in the external window; `browser_snapshot` returns the current aria snapshot with element refs; `browser_act` clicks/fills/presses/hovers a ref; `browser_search` fills and submits the real search form; `browser_tabs`, `browser_scroll`, `browser_press`, `browser_dialog`, `browser_wait`, and `browser_screenshot` manage state. Use refs only from the immediately preceding snapshot. It never edits workspace files and does not execute page JavaScript.";
|
|
7
7
|
export async function buildBrowserTools(options) {
|
|
8
8
|
const [{ Type }, { defineTool }] = await Promise.all([
|
|
9
9
|
import("typebox"),
|
|
@@ -11,7 +11,10 @@ export async function buildBrowserTools(options) {
|
|
|
11
11
|
]);
|
|
12
12
|
const automation = options.automation;
|
|
13
13
|
const urlParameter = Type.String({
|
|
14
|
-
description: "Absolute http(s) URL.
|
|
14
|
+
description: "Absolute http(s) URL.",
|
|
15
|
+
});
|
|
16
|
+
const refParameter = Type.String({
|
|
17
|
+
description: "Element ref from the most recent browser_snapshot (for example e12).",
|
|
15
18
|
});
|
|
16
19
|
async function execute(operation) {
|
|
17
20
|
try {
|
|
@@ -37,17 +40,17 @@ export async function buildBrowserTools(options) {
|
|
|
37
40
|
return [
|
|
38
41
|
defineTool({
|
|
39
42
|
name: "browser_navigate",
|
|
40
|
-
label: "
|
|
43
|
+
label: "Browser navigate",
|
|
41
44
|
description: BROWSER_TOOLS_DESCRIPTION,
|
|
42
45
|
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
43
46
|
parameters: Type.Object({ url: urlParameter }, { additionalProperties: false }),
|
|
44
47
|
async execute(_toolCallId, params) {
|
|
45
|
-
return execute(() => automation.navigate(params.url
|
|
48
|
+
return execute(() => automation.navigate(params.url));
|
|
46
49
|
},
|
|
47
50
|
}),
|
|
48
51
|
defineTool({
|
|
49
52
|
name: "browser_search",
|
|
50
|
-
label: "
|
|
53
|
+
label: "Browser search",
|
|
51
54
|
description: BROWSER_TOOLS_DESCRIPTION,
|
|
52
55
|
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
53
56
|
parameters: Type.Object({
|
|
@@ -59,30 +62,122 @@ export async function buildBrowserTools(options) {
|
|
|
59
62
|
},
|
|
60
63
|
}),
|
|
61
64
|
defineTool({
|
|
62
|
-
name: "
|
|
63
|
-
label: "
|
|
65
|
+
name: "browser_snapshot",
|
|
66
|
+
label: "Browser snapshot",
|
|
64
67
|
description: BROWSER_TOOLS_DESCRIPTION,
|
|
65
68
|
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
66
|
-
parameters: Type.Object({
|
|
67
|
-
async execute(
|
|
68
|
-
return execute(() => automation.
|
|
69
|
+
parameters: Type.Object({}, { additionalProperties: false }),
|
|
70
|
+
async execute() {
|
|
71
|
+
return execute(() => automation.snapshot({ screenshot: false }));
|
|
69
72
|
},
|
|
70
73
|
}),
|
|
71
74
|
defineTool({
|
|
72
75
|
name: "browser_act",
|
|
73
|
-
label: "
|
|
76
|
+
label: "Browser act",
|
|
74
77
|
description: BROWSER_TOOLS_DESCRIPTION,
|
|
75
78
|
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
76
79
|
parameters: Type.Object({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
type: Type.Union([
|
|
81
|
+
Type.Literal("click"),
|
|
82
|
+
Type.Literal("fill"),
|
|
83
|
+
Type.Literal("press"),
|
|
84
|
+
Type.Literal("hover"),
|
|
85
|
+
]),
|
|
86
|
+
ref: refParameter,
|
|
80
87
|
value: Type.Optional(Type.String()),
|
|
88
|
+
key: Type.Optional(Type.String()),
|
|
89
|
+
}, { additionalProperties: false }),
|
|
90
|
+
async execute(_toolCallId, params) {
|
|
91
|
+
return execute(() => automation.act(params.type === "fill"
|
|
92
|
+
? { type: "fill", ref: params.ref, value: params.value ?? "" }
|
|
93
|
+
: params.type === "press"
|
|
94
|
+
? { type: "press", ref: params.ref, key: params.key ?? "Enter" }
|
|
95
|
+
: { type: params.type, ref: params.ref }));
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
defineTool({
|
|
99
|
+
name: "browser_tabs",
|
|
100
|
+
label: "Browser tabs",
|
|
101
|
+
description: BROWSER_TOOLS_DESCRIPTION,
|
|
102
|
+
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
103
|
+
parameters: Type.Object({
|
|
104
|
+
action: Type.Union([
|
|
105
|
+
Type.Literal("list"),
|
|
106
|
+
Type.Literal("new"),
|
|
107
|
+
Type.Literal("select"),
|
|
108
|
+
Type.Literal("close"),
|
|
109
|
+
]),
|
|
110
|
+
tabId: Type.Optional(Type.Integer()),
|
|
111
|
+
url: Type.Optional(urlParameter),
|
|
112
|
+
}, { additionalProperties: false }),
|
|
113
|
+
async execute(_toolCallId, params) {
|
|
114
|
+
return execute(() => {
|
|
115
|
+
if (params.action === "list")
|
|
116
|
+
return automation.snapshot({ screenshot: false });
|
|
117
|
+
if (params.action === "new")
|
|
118
|
+
return automation.newTab(params.url);
|
|
119
|
+
if (params.tabId === undefined)
|
|
120
|
+
throw new Error("tabId is required");
|
|
121
|
+
return params.action === "select"
|
|
122
|
+
? automation.selectTab(params.tabId)
|
|
123
|
+
: automation.closeTab(params.tabId);
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
defineTool({
|
|
128
|
+
name: "browser_scroll",
|
|
129
|
+
label: "Browser scroll",
|
|
130
|
+
description: BROWSER_TOOLS_DESCRIPTION,
|
|
131
|
+
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
132
|
+
parameters: Type.Object({
|
|
133
|
+
direction: Type.Union([Type.Literal("up"), Type.Literal("down")]),
|
|
134
|
+
amount: Type.Optional(Type.Integer({ minimum: 50, maximum: 3000 })),
|
|
135
|
+
}, { additionalProperties: false }),
|
|
136
|
+
async execute(_toolCallId, params) {
|
|
137
|
+
return execute(() => automation.scroll(params));
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
defineTool({
|
|
141
|
+
name: "browser_press",
|
|
142
|
+
label: "Browser press key",
|
|
143
|
+
description: BROWSER_TOOLS_DESCRIPTION,
|
|
144
|
+
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
145
|
+
parameters: Type.Object({ key: Type.String() }, { additionalProperties: false }),
|
|
146
|
+
async execute(_toolCallId, params) {
|
|
147
|
+
return execute(() => automation.pressKey(params.key));
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
defineTool({
|
|
151
|
+
name: "browser_dialog",
|
|
152
|
+
label: "Browser dialog",
|
|
153
|
+
description: BROWSER_TOOLS_DESCRIPTION,
|
|
154
|
+
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
155
|
+
parameters: Type.Object({
|
|
156
|
+
action: Type.Union([Type.Literal("accept"), Type.Literal("dismiss")]),
|
|
157
|
+
promptText: Type.Optional(Type.String()),
|
|
81
158
|
}, { additionalProperties: false }),
|
|
82
159
|
async execute(_toolCallId, params) {
|
|
83
|
-
return execute(() => automation.
|
|
84
|
-
|
|
85
|
-
|
|
160
|
+
return execute(() => automation.handleDialog(params.action, params.promptText));
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
defineTool({
|
|
164
|
+
name: "browser_wait",
|
|
165
|
+
label: "Browser wait",
|
|
166
|
+
description: BROWSER_TOOLS_DESCRIPTION,
|
|
167
|
+
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
168
|
+
parameters: Type.Object({ ms: Type.Integer({ minimum: 0, maximum: 10_000 }) }, { additionalProperties: false }),
|
|
169
|
+
async execute(_toolCallId, params) {
|
|
170
|
+
return execute(() => automation.waitFor(params.ms));
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
defineTool({
|
|
174
|
+
name: "browser_screenshot",
|
|
175
|
+
label: "Browser screenshot",
|
|
176
|
+
description: BROWSER_TOOLS_DESCRIPTION,
|
|
177
|
+
promptSnippet: BROWSER_TOOLS_DESCRIPTION,
|
|
178
|
+
parameters: Type.Object({}, { additionalProperties: false }),
|
|
179
|
+
async execute() {
|
|
180
|
+
return execute(() => automation.screenshot());
|
|
86
181
|
},
|
|
87
182
|
}),
|
|
88
183
|
];
|