opencode-pair-autonomy 1.0.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.
Files changed (128) hide show
  1. package/README.md +90 -0
  2. package/bin/opencode-pair-autonomy.js +20 -0
  3. package/dist/__tests__/comment-guard.test.d.ts +1 -0
  4. package/dist/__tests__/config.test.d.ts +1 -0
  5. package/dist/__tests__/learning.test.d.ts +1 -0
  6. package/dist/__tests__/plan-mode.test.d.ts +1 -0
  7. package/dist/agents.d.ts +2 -0
  8. package/dist/cli.d.ts +1 -0
  9. package/dist/cli.js +15351 -0
  10. package/dist/commands.d.ts +2 -0
  11. package/dist/config.d.ts +3 -0
  12. package/dist/hooks/comment-guard.d.ts +15 -0
  13. package/dist/hooks/file-edited.d.ts +7 -0
  14. package/dist/hooks/index.d.ts +46 -0
  15. package/dist/hooks/post-tool-use.d.ts +5 -0
  16. package/dist/hooks/pre-compact.d.ts +4 -0
  17. package/dist/hooks/pre-tool-use.d.ts +5 -0
  18. package/dist/hooks/prompt-refiner.d.ts +38 -0
  19. package/dist/hooks/runtime.d.ts +91 -0
  20. package/dist/hooks/sdk.d.ts +6 -0
  21. package/dist/hooks/session-end.d.ts +4 -0
  22. package/dist/hooks/session-start.d.ts +19 -0
  23. package/dist/hooks/stop.d.ts +5 -0
  24. package/dist/i18n/index.d.ts +15 -0
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.js +17823 -0
  27. package/dist/installer.d.ts +12 -0
  28. package/dist/learning/analyzer.d.ts +15 -0
  29. package/dist/learning/store.d.ts +4 -0
  30. package/dist/learning/types.d.ts +32 -0
  31. package/dist/mcp.d.ts +4 -0
  32. package/dist/project-facts.d.ts +8 -0
  33. package/dist/prompts/coordinator.d.ts +2 -0
  34. package/dist/prompts/shared.d.ts +5 -0
  35. package/dist/prompts/workers.d.ts +8 -0
  36. package/dist/types.d.ts +81 -0
  37. package/dist/utils.d.ts +6 -0
  38. package/examples/opencode-pair-autonomy.jsonc +35 -0
  39. package/examples/opencode.jsonc +17 -0
  40. package/package.json +103 -0
  41. package/vendor/mcp/pg-mcp/README.md +91 -0
  42. package/vendor/mcp/pg-mcp/config.example.json +26 -0
  43. package/vendor/mcp/pg-mcp/config.json +15 -0
  44. package/vendor/mcp/pg-mcp/package-lock.json +1288 -0
  45. package/vendor/mcp/pg-mcp/package.json +18 -0
  46. package/vendor/mcp/pg-mcp/src/config.js +71 -0
  47. package/vendor/mcp/pg-mcp/src/db.js +85 -0
  48. package/vendor/mcp/pg-mcp/src/index.js +203 -0
  49. package/vendor/mcp/pg-mcp/src/sqlGuard.js +75 -0
  50. package/vendor/mcp/pg-mcp/src/tools.js +89 -0
  51. package/vendor/mcp/ssh-mcp/README.md +46 -0
  52. package/vendor/mcp/ssh-mcp/config.example.json +23 -0
  53. package/vendor/mcp/ssh-mcp/config.json +6 -0
  54. package/vendor/mcp/ssh-mcp/package-lock.json +1142 -0
  55. package/vendor/mcp/ssh-mcp/package.json +18 -0
  56. package/vendor/mcp/ssh-mcp/src/config.js +140 -0
  57. package/vendor/mcp/ssh-mcp/src/index.js +130 -0
  58. package/vendor/mcp/ssh-mcp/src/ssh.js +163 -0
  59. package/vendor/mcp/sudo-mcp/README.md +51 -0
  60. package/vendor/mcp/sudo-mcp/config.example.json +28 -0
  61. package/vendor/mcp/sudo-mcp/config.json +28 -0
  62. package/vendor/mcp/sudo-mcp/package-lock.json +1145 -0
  63. package/vendor/mcp/sudo-mcp/package.json +18 -0
  64. package/vendor/mcp/sudo-mcp/src/config.js +57 -0
  65. package/vendor/mcp/sudo-mcp/src/index.js +267 -0
  66. package/vendor/mcp/sudo-mcp/src/runner.js +168 -0
  67. package/vendor/mcp/web-agent-mcp/package-lock.json +2886 -0
  68. package/vendor/mcp/web-agent-mcp/package.json +28 -0
  69. package/vendor/mcp/web-agent-mcp/src/adapters/cloakbrowser/adapter.ts +335 -0
  70. package/vendor/mcp/web-agent-mcp/src/adapters/cloakbrowser/auth-heuristics.ts +324 -0
  71. package/vendor/mcp/web-agent-mcp/src/adapters/cloakbrowser/launcher.ts +1340 -0
  72. package/vendor/mcp/web-agent-mcp/src/config/env.ts +107 -0
  73. package/vendor/mcp/web-agent-mcp/src/core/action-flow.ts +82 -0
  74. package/vendor/mcp/web-agent-mcp/src/core/artifact-store.ts +109 -0
  75. package/vendor/mcp/web-agent-mcp/src/core/errors.ts +108 -0
  76. package/vendor/mcp/web-agent-mcp/src/core/observation-flow.ts +38 -0
  77. package/vendor/mcp/web-agent-mcp/src/core/policy-engine.ts +113 -0
  78. package/vendor/mcp/web-agent-mcp/src/core/retry-policy.ts +42 -0
  79. package/vendor/mcp/web-agent-mcp/src/core/session-manager.ts +670 -0
  80. package/vendor/mcp/web-agent-mcp/src/core/session-restart-policy.ts +34 -0
  81. package/vendor/mcp/web-agent-mcp/src/core/task-history.ts +97 -0
  82. package/vendor/mcp/web-agent-mcp/src/index.ts +3 -0
  83. package/vendor/mcp/web-agent-mcp/src/schemas/act.ts +167 -0
  84. package/vendor/mcp/web-agent-mcp/src/schemas/common.ts +56 -0
  85. package/vendor/mcp/web-agent-mcp/src/schemas/observe.ts +214 -0
  86. package/vendor/mcp/web-agent-mcp/src/schemas/page.ts +21 -0
  87. package/vendor/mcp/web-agent-mcp/src/schemas/policy.ts +42 -0
  88. package/vendor/mcp/web-agent-mcp/src/schemas/runtime.ts +21 -0
  89. package/vendor/mcp/web-agent-mcp/src/schemas/session.ts +63 -0
  90. package/vendor/mcp/web-agent-mcp/src/server.ts +75 -0
  91. package/vendor/mcp/web-agent-mcp/src/tools/act/click.ts +68 -0
  92. package/vendor/mcp/web-agent-mcp/src/tools/act/drag.ts +57 -0
  93. package/vendor/mcp/web-agent-mcp/src/tools/act/enter-code.ts +78 -0
  94. package/vendor/mcp/web-agent-mcp/src/tools/act/fill.ts +65 -0
  95. package/vendor/mcp/web-agent-mcp/src/tools/act/pinch.ts +58 -0
  96. package/vendor/mcp/web-agent-mcp/src/tools/act/press.ts +67 -0
  97. package/vendor/mcp/web-agent-mcp/src/tools/act/shared.ts +73 -0
  98. package/vendor/mcp/web-agent-mcp/src/tools/act/swipe.ts +59 -0
  99. package/vendor/mcp/web-agent-mcp/src/tools/act/wait-for.ts +56 -0
  100. package/vendor/mcp/web-agent-mcp/src/tools/act/wheel.ts +59 -0
  101. package/vendor/mcp/web-agent-mcp/src/tools/observe/a11y.ts +60 -0
  102. package/vendor/mcp/web-agent-mcp/src/tools/observe/auth-state.ts +92 -0
  103. package/vendor/mcp/web-agent-mcp/src/tools/observe/boxes.ts +66 -0
  104. package/vendor/mcp/web-agent-mcp/src/tools/observe/console.ts +67 -0
  105. package/vendor/mcp/web-agent-mcp/src/tools/observe/dom.ts +60 -0
  106. package/vendor/mcp/web-agent-mcp/src/tools/observe/network.ts +67 -0
  107. package/vendor/mcp/web-agent-mcp/src/tools/observe/page-state.ts +93 -0
  108. package/vendor/mcp/web-agent-mcp/src/tools/observe/screenshot.ts +73 -0
  109. package/vendor/mcp/web-agent-mcp/src/tools/observe/text.ts +70 -0
  110. package/vendor/mcp/web-agent-mcp/src/tools/observe/wait-for-network.ts +70 -0
  111. package/vendor/mcp/web-agent-mcp/src/tools/page/navigate.ts +59 -0
  112. package/vendor/mcp/web-agent-mcp/src/tools/policy/recommend-observation.ts +40 -0
  113. package/vendor/mcp/web-agent-mcp/src/tools/register-tools.ts +55 -0
  114. package/vendor/mcp/web-agent-mcp/src/tools/runtime/evaluate-js.ts +83 -0
  115. package/vendor/mcp/web-agent-mcp/src/tools/session/close.ts +41 -0
  116. package/vendor/mcp/web-agent-mcp/src/tools/session/create.ts +86 -0
  117. package/vendor/mcp/web-agent-mcp/src/tools/session/restart.ts +72 -0
  118. package/vendor/mcp/web-agent-mcp/src/utils/fs.ts +28 -0
  119. package/vendor/mcp/web-agent-mcp/src/utils/ids.ts +9 -0
  120. package/vendor/mcp/web-agent-mcp/src/utils/time.ts +7 -0
  121. package/vendor/mcp/web-agent-mcp/tsconfig.json +22 -0
  122. package/vendor/skills/editorial-technical-ui/SKILL.md +84 -0
  123. package/vendor/skills/figma-console/SKILL.md +839 -0
  124. package/vendor/skills/go-fiber-postgres/SKILL.md +31 -0
  125. package/vendor/skills/opencode-plugin-dev/SKILL.md +31 -0
  126. package/vendor/skills/rust-media-desktop/SKILL.md +30 -0
  127. package/vendor/skills/vue-vite-ui/SKILL.md +31 -0
  128. package/vendor/skills/web-agent-browser/SKILL.md +140 -0
@@ -0,0 +1,97 @@
1
+ import path from "node:path";
2
+ import type { WebAgentEnv } from "../config/env.js";
3
+ import { createId } from "../utils/ids.js";
4
+ import { nowIso } from "../utils/time.js";
5
+ import { appendJsonLine } from "../utils/fs.js";
6
+
7
+ export type TaskRecord = {
8
+ task_id: string;
9
+ kind: string;
10
+ status: "started" | "succeeded" | "failed";
11
+ created_at: string;
12
+ ended_at?: string;
13
+ session_id?: string;
14
+ page_id?: string;
15
+ summary?: Record<string, unknown>;
16
+ };
17
+
18
+ export type ActionRecord = {
19
+ action_id: string;
20
+ task_id?: string;
21
+ session_id?: string;
22
+ page_id?: string;
23
+ kind: string;
24
+ status: "started" | "succeeded" | "failed";
25
+ started_at: string;
26
+ ended_at?: string;
27
+ input_summary?: Record<string, unknown>;
28
+ result_summary?: Record<string, unknown>;
29
+ error_code?: string;
30
+ };
31
+
32
+ export class TaskHistoryStore {
33
+ private readonly taskPath: string;
34
+ private readonly actionPath: string;
35
+
36
+ constructor(env: WebAgentEnv) {
37
+ this.taskPath = path.join(env.historyDir, "tasks.jsonl");
38
+ this.actionPath = path.join(env.historyDir, "actions.jsonl");
39
+ }
40
+
41
+ async startTask(kind: string, summary?: Record<string, unknown>) {
42
+ const task: TaskRecord = {
43
+ task_id: createId("task"),
44
+ kind,
45
+ status: "started",
46
+ created_at: nowIso(),
47
+ summary,
48
+ };
49
+ await appendJsonLine(this.taskPath, task);
50
+ return task;
51
+ }
52
+
53
+ async finishTask(
54
+ task: TaskRecord,
55
+ status: "succeeded" | "failed",
56
+ summary?: Record<string, unknown>,
57
+ ) {
58
+ await appendJsonLine(this.taskPath, {
59
+ ...task,
60
+ status,
61
+ ended_at: nowIso(),
62
+ summary: summary ?? task.summary,
63
+ });
64
+ }
65
+
66
+ async startAction(
67
+ kind: string,
68
+ inputSummary?: Record<string, unknown>,
69
+ refs?: Partial<ActionRecord>,
70
+ ) {
71
+ const action: ActionRecord = {
72
+ action_id: createId("action"),
73
+ kind,
74
+ status: "started",
75
+ started_at: nowIso(),
76
+ input_summary: inputSummary,
77
+ ...refs,
78
+ };
79
+ await appendJsonLine(this.actionPath, action);
80
+ return action;
81
+ }
82
+
83
+ async finishAction(
84
+ action: ActionRecord,
85
+ status: "succeeded" | "failed",
86
+ resultSummary?: Record<string, unknown>,
87
+ errorCode?: string,
88
+ ) {
89
+ await appendJsonLine(this.actionPath, {
90
+ ...action,
91
+ status,
92
+ ended_at: nowIso(),
93
+ result_summary: resultSummary,
94
+ error_code: errorCode,
95
+ });
96
+ }
97
+ }
@@ -0,0 +1,3 @@
1
+ export { createServer, startStdioServer } from "./server.js";
2
+ export type { WebAgentEnv } from "./config/env.js";
3
+ export type { ManagedSession, ManagedPage } from "./core/session-manager.js";
@@ -0,0 +1,167 @@
1
+ import { z } from "zod";
2
+ import {
3
+ followUpByGoalSchema,
4
+ observationRecommendationSchema,
5
+ sessionRestartRecommendationSchema,
6
+ } from "./policy.js";
7
+
8
+ export const actionResultSchema = z.object({
9
+ action_id: z.string(),
10
+ applied_mode: z.enum(["semantic", "physical"]),
11
+ verification_hint: z.string().optional(),
12
+ retry_hint: z.string().optional(),
13
+ fallback_observation: observationRecommendationSchema.optional(),
14
+ follow_up_by_goal: followUpByGoalSchema,
15
+ session_restart: sessionRestartRecommendationSchema.optional(),
16
+ });
17
+
18
+ export const clickInputSchema = z.object({
19
+ session_id: z.string().min(1),
20
+ page_id: z.string().min(1).optional(),
21
+ selector: z.string().min(1),
22
+ frame_selector: z
23
+ .string()
24
+ .min(1)
25
+ .optional()
26
+ .describe(
27
+ "CSS selector of an iframe to scope the action into (e.g. 'iframe#aid-auth-widget-iFrame'). Use when the target element is inside a cross-origin or embedded iframe.",
28
+ ),
29
+ button: z.enum(["left", "right", "middle"]).default("left"),
30
+ click_count: z.number().int().min(1).max(3).default(1),
31
+ timeout_ms: z.number().int().positive().max(60000).optional(),
32
+ });
33
+
34
+ export const fillInputSchema = z.object({
35
+ session_id: z.string().min(1),
36
+ page_id: z.string().min(1).optional(),
37
+ selector: z.string().min(1),
38
+ frame_selector: z
39
+ .string()
40
+ .min(1)
41
+ .optional()
42
+ .describe(
43
+ "CSS selector of an iframe to scope the action into (e.g. 'iframe#aid-auth-widget-iFrame'). Use when the target element is inside a cross-origin or embedded iframe.",
44
+ ),
45
+ value: z.string(),
46
+ clear_first: z.boolean().default(true),
47
+ timeout_ms: z.number().int().positive().max(60000).optional(),
48
+ });
49
+
50
+ export const pressInputSchema = z.object({
51
+ session_id: z.string().min(1),
52
+ page_id: z.string().min(1).optional(),
53
+ key: z.string().min(1),
54
+ selector: z.string().min(1).optional(),
55
+ frame_selector: z
56
+ .string()
57
+ .min(1)
58
+ .optional()
59
+ .describe(
60
+ "CSS selector of an iframe to scope the action into. Use when the target element is inside a cross-origin or embedded iframe.",
61
+ ),
62
+ timeout_ms: z.number().int().positive().max(60000).optional(),
63
+ });
64
+
65
+ export const enterCodeInputSchema = z.object({
66
+ session_id: z.string().min(1),
67
+ page_id: z.string().min(1).optional(),
68
+ selector: z.string().min(1).optional(),
69
+ frame_selector: z
70
+ .string()
71
+ .min(1)
72
+ .optional()
73
+ .describe(
74
+ "CSS selector of an iframe to scope the action into. Use when the target element is inside a cross-origin or embedded iframe.",
75
+ ),
76
+ code: z.string().min(1),
77
+ submit: z.boolean().default(false),
78
+ timeout_ms: z.number().int().positive().max(60000).optional(),
79
+ });
80
+
81
+ export const waitForInputSchema = z
82
+ .object({
83
+ session_id: z.string().min(1),
84
+ page_id: z.string().min(1).optional(),
85
+ selector: z.string().min(1).optional(),
86
+ text: z.string().min(1).optional(),
87
+ timeout_ms: z.number().int().positive().max(60000).default(5000),
88
+ })
89
+ .refine((value) => Boolean(value.selector || value.text), {
90
+ message: "Provide either selector or text for wait_for.",
91
+ });
92
+
93
+ export const wheelInputSchema = z
94
+ .object({
95
+ session_id: z.string().min(1),
96
+ page_id: z.string().min(1).optional(),
97
+ selector: z.string().min(1).optional(),
98
+ delta_x: z.number().default(0),
99
+ delta_y: z.number().default(0),
100
+ steps: z.number().int().min(1).max(100).default(1),
101
+ step_delay_ms: z.number().int().min(0).max(1000).default(0),
102
+ timeout_ms: z.number().int().positive().max(60000).optional(),
103
+ })
104
+ .refine((value) => value.delta_x !== 0 || value.delta_y !== 0, {
105
+ message: "delta_x or delta_y must be non-zero for wheel.",
106
+ });
107
+
108
+ export const dragInputSchema = z.object({
109
+ session_id: z.string().min(1),
110
+ page_id: z.string().min(1).optional(),
111
+ from_selector: z.string().min(1),
112
+ to_selector: z.string().min(1),
113
+ steps: z.number().int().min(1).max(200).default(20),
114
+ timeout_ms: z.number().int().positive().max(60000).optional(),
115
+ });
116
+
117
+ export const swipeInputSchema = z
118
+ .object({
119
+ session_id: z.string().min(1),
120
+ page_id: z.string().min(1).optional(),
121
+ selector: z.string().min(1).optional(),
122
+ start_x: z.number().optional(),
123
+ start_y: z.number().optional(),
124
+ delta_x: z.number().default(0),
125
+ delta_y: z.number().default(0),
126
+ speed: z.number().positive().max(5000).default(800),
127
+ })
128
+ .refine((value) => value.delta_x !== 0 || value.delta_y !== 0, {
129
+ message: "delta_x or delta_y must be non-zero for swipe.",
130
+ })
131
+ .refine(
132
+ (value) =>
133
+ Boolean(value.selector) ||
134
+ (value.start_x !== undefined && value.start_y !== undefined),
135
+ {
136
+ message: "Provide a selector or both start_x and start_y for swipe.",
137
+ },
138
+ );
139
+
140
+ export const pinchInputSchema = z
141
+ .object({
142
+ session_id: z.string().min(1),
143
+ page_id: z.string().min(1).optional(),
144
+ selector: z.string().min(1).optional(),
145
+ center_x: z.number().optional(),
146
+ center_y: z.number().optional(),
147
+ scale_factor: z.number().positive(),
148
+ speed: z.number().positive().max(5000).default(800),
149
+ })
150
+ .refine(
151
+ (value) =>
152
+ Boolean(value.selector) ||
153
+ (value.center_x !== undefined && value.center_y !== undefined),
154
+ {
155
+ message: "Provide a selector or both center_x and center_y for pinch.",
156
+ },
157
+ );
158
+
159
+ export type ClickInput = z.infer<typeof clickInputSchema>;
160
+ export type FillInput = z.infer<typeof fillInputSchema>;
161
+ export type PressInput = z.infer<typeof pressInputSchema>;
162
+ export type EnterCodeInput = z.infer<typeof enterCodeInputSchema>;
163
+ export type WaitForInput = z.infer<typeof waitForInputSchema>;
164
+ export type WheelInput = z.infer<typeof wheelInputSchema>;
165
+ export type DragInput = z.infer<typeof dragInputSchema>;
166
+ export type SwipeInput = z.infer<typeof swipeInputSchema>;
167
+ export type PinchInput = z.infer<typeof pinchInputSchema>;
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+
3
+ export const errorTypeSchema = z.enum([
4
+ "INPUT",
5
+ "STATE",
6
+ "BROWSER",
7
+ "NETWORK",
8
+ "STORAGE",
9
+ "INTERNAL",
10
+ ]);
11
+
12
+ export const toolEnvelopeBaseSchema = z.object({
13
+ ok: z.boolean(),
14
+ code: z.string(),
15
+ message: z.string().optional(),
16
+ task_id: z.string().optional(),
17
+ action_id: z.string().optional(),
18
+ session_id: z.string().optional(),
19
+ page_id: z.string().optional(),
20
+ artifact_ids: z.array(z.string()).optional(),
21
+ warnings: z.array(z.string()).optional(),
22
+ error: z
23
+ .object({
24
+ type: errorTypeSchema,
25
+ details: z.record(z.string(), z.unknown()).optional(),
26
+ })
27
+ .optional(),
28
+ });
29
+
30
+ export type ErrorType = z.infer<typeof errorTypeSchema>;
31
+
32
+ export type ToolEnvelope<TData = unknown> = z.infer<
33
+ typeof toolEnvelopeBaseSchema
34
+ > & {
35
+ data?: TData;
36
+ };
37
+
38
+ export function createToolTextContent(value: unknown) {
39
+ return [{ type: "text" as const, text: JSON.stringify(value, null, 2) }];
40
+ }
41
+
42
+ export function createToolSuccess<TData>(envelope: ToolEnvelope<TData>) {
43
+ const structuredContent = envelope.data ?? envelope;
44
+
45
+ return {
46
+ content: createToolTextContent(structuredContent),
47
+ structuredContent,
48
+ };
49
+ }
50
+
51
+ export function createToolFailure<TData>(envelope: ToolEnvelope<TData>) {
52
+ return {
53
+ content: createToolTextContent(envelope.error ?? envelope),
54
+ isError: true,
55
+ };
56
+ }
@@ -0,0 +1,214 @@
1
+ import { z } from "zod";
2
+
3
+ export const observeSessionInputSchema = z.object({
4
+ session_id: z.string().min(1),
5
+ page_id: z.string().min(1).optional()
6
+ });
7
+
8
+ export const screenshotInputSchema = observeSessionInputSchema.extend({
9
+ mode: z.enum(["viewport", "full", "element"]).default("viewport"),
10
+ selector: z.string().min(1).optional(),
11
+ format: z.enum(["png", "jpeg"]).default("jpeg"),
12
+ quality: z.number().int().min(1).max(100).optional()
13
+ }).superRefine((value, ctx) => {
14
+ if (value.mode === "element" && !value.selector) {
15
+ ctx.addIssue({
16
+ code: z.ZodIssueCode.custom,
17
+ message: "selector is required when screenshot mode is element",
18
+ path: ["selector"]
19
+ });
20
+ }
21
+ });
22
+
23
+ export const boxesInputSchema = observeSessionInputSchema.extend({
24
+ selectors: z.array(z.string().min(1)).min(1).max(50)
25
+ });
26
+
27
+ export const logsInputSchema = observeSessionInputSchema.extend({
28
+ limit: z.number().int().positive().max(500).default(50)
29
+ });
30
+
31
+ export const pageStateInputSchema = observeSessionInputSchema.extend({
32
+ recent_network_limit: z.number().int().positive().max(100).default(10)
33
+ });
34
+
35
+ export const authStateInputSchema = observeSessionInputSchema.extend({
36
+ recent_network_limit: z.number().int().positive().max(100).default(20)
37
+ });
38
+
39
+ export const waitForNetworkInputSchema = observeSessionInputSchema.extend({
40
+ url_pattern: z.string().min(1),
41
+ use_regex: z.boolean().default(false),
42
+ status: z.number().int().min(100).max(599).optional(),
43
+ outcome: z.enum(["response", "failed"]).optional(),
44
+ timeout_ms: z.number().int().positive().max(60000).default(5000),
45
+ poll_interval_ms: z.number().int().positive().max(1000).default(100)
46
+ });
47
+
48
+ export const artifactMetadataSchema = z.object({
49
+ artifact_id: z.string(),
50
+ kind: z.enum(["a11y", "dom", "text", "markdown", "boxes", "screenshot", "console", "network", "eval"]),
51
+ created_at: z.string(),
52
+ url: z.string().optional(),
53
+ title: z.string().optional(),
54
+ storage_path: z.string().optional(),
55
+ bytes: z.number().optional()
56
+ });
57
+
58
+ export const followUpByGoalSchemaLazy = z.object({
59
+ interact: z.any(),
60
+ read: z.any(),
61
+ visual_verify: z.any(),
62
+ debug: z.any(),
63
+ gesture: z.any()
64
+ });
65
+
66
+ const networkEntrySchema = z.object({
67
+ url: z.string(),
68
+ method: z.string(),
69
+ status: z.number().optional(),
70
+ resourceType: z.string(),
71
+ outcome: z.enum(["response", "failed"]),
72
+ failureText: z.string().optional(),
73
+ timestamp: z.string()
74
+ });
75
+
76
+ const interactiveElementSchema = z.object({
77
+ tag: z.string(),
78
+ type: z.string().optional(),
79
+ id: z.string().optional(),
80
+ name: z.string().optional(),
81
+ placeholder: z.string().optional(),
82
+ text: z.string().optional(),
83
+ autocomplete: z.string().optional(),
84
+ visible: z.boolean()
85
+ });
86
+
87
+ const frameSummarySchema = z.object({
88
+ index: z.number().int().nonnegative(),
89
+ name: z.string().optional(),
90
+ url: z.string(),
91
+ title: z.string().optional(),
92
+ text_preview: z.string(),
93
+ truncated: z.boolean(),
94
+ input_count: z.number().int().nonnegative(),
95
+ button_count: z.number().int().nonnegative()
96
+ });
97
+
98
+ export const observeA11yOutputSchema = z.object({
99
+ snapshot_id: z.string(),
100
+ format: z.literal("a11y"),
101
+ url: z.string(),
102
+ title: z.string().optional(),
103
+ tree: z.unknown(),
104
+ follow_up_by_goal: followUpByGoalSchemaLazy
105
+ });
106
+
107
+ export const observeDomOutputSchema = z.object({
108
+ snapshot_id: z.string(),
109
+ format: z.literal("dom"),
110
+ url: z.string(),
111
+ title: z.string().optional(),
112
+ dom_summary: z.object({
113
+ headings: z.array(z.string()),
114
+ links: z.number(),
115
+ buttons: z.number(),
116
+ forms: z.number(),
117
+ inputs: z.number()
118
+ }),
119
+ follow_up_by_goal: followUpByGoalSchemaLazy
120
+ });
121
+
122
+ export const observeTextOutputSchema = z.object({
123
+ artifact_id: z.string(),
124
+ format: z.enum(["text", "markdown"]),
125
+ content: z.string(),
126
+ truncated: z.boolean(),
127
+ url: z.string(),
128
+ title: z.string().optional(),
129
+ follow_up_by_goal: followUpByGoalSchemaLazy
130
+ });
131
+
132
+ export const observeBoxesOutputSchema = z.object({
133
+ element_map_id: z.string(),
134
+ elements: z.array(
135
+ z.object({
136
+ selector: z.string(),
137
+ x: z.number(),
138
+ y: z.number(),
139
+ width: z.number(),
140
+ height: z.number(),
141
+ visible: z.boolean()
142
+ })
143
+ )
144
+ });
145
+
146
+ export const observeLogsOutputSchema = z.object({
147
+ artifact_id: z.string(),
148
+ entries: z.array(z.unknown())
149
+ });
150
+
151
+ export const observeScreenshotOutputSchema = z.object({
152
+ screenshot_id: z.string(),
153
+ mode: z.enum(["viewport", "full", "element"]),
154
+ width: z.number().optional(),
155
+ height: z.number().optional(),
156
+ bytes: z.number().optional(),
157
+ mime_type: z.string(),
158
+ storage_path: z.string().optional(),
159
+ follow_up_by_goal: followUpByGoalSchemaLazy
160
+ });
161
+
162
+ export const observePageStateOutputSchema = z.object({
163
+ snapshot_id: z.string(),
164
+ url: z.string(),
165
+ title: z.string().optional(),
166
+ text: z.string(),
167
+ truncated: z.boolean(),
168
+ dom_summary: z.object({
169
+ headings: z.array(z.string()),
170
+ links: z.number(),
171
+ buttons: z.number(),
172
+ forms: z.number(),
173
+ inputs: z.number()
174
+ }),
175
+ inputs: z.array(interactiveElementSchema),
176
+ buttons: z.array(interactiveElementSchema),
177
+ frames: z.array(frameSummarySchema),
178
+ recent_network: z.array(networkEntrySchema),
179
+ follow_up_by_goal: followUpByGoalSchemaLazy
180
+ });
181
+
182
+ export const observeAuthStateOutputSchema = z.object({
183
+ snapshot_id: z.string(),
184
+ url: z.string(),
185
+ title: z.string().optional(),
186
+ state: z.enum([
187
+ "email_prompt",
188
+ "password_prompt",
189
+ "phone_selection",
190
+ "verification_code",
191
+ "trust_prompt",
192
+ "authenticated",
193
+ "unknown"
194
+ ]),
195
+ confidence: z.enum(["high", "medium", "low"]),
196
+ summary: z.string(),
197
+ evidence: z.array(z.string()),
198
+ suggested_selectors: z.array(z.string()),
199
+ candidate_frames: z.array(frameSummarySchema),
200
+ recent_network: z.array(networkEntrySchema),
201
+ follow_up_by_goal: followUpByGoalSchemaLazy
202
+ });
203
+
204
+ export const waitForNetworkOutputSchema = z.object({
205
+ entry: networkEntrySchema,
206
+ elapsed_ms: z.number().int().nonnegative()
207
+ });
208
+
209
+ export type ScreenshotInput = z.infer<typeof screenshotInputSchema>;
210
+ export type BoxesInput = z.infer<typeof boxesInputSchema>;
211
+ export type LogsInput = z.infer<typeof logsInputSchema>;
212
+ export type PageStateInput = z.infer<typeof pageStateInputSchema>;
213
+ export type AuthStateInput = z.infer<typeof authStateInputSchema>;
214
+ export type WaitForNetworkInput = z.infer<typeof waitForNetworkInputSchema>;
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ import { followUpByGoalSchema } from "./policy.js";
3
+
4
+ export const navigatePageInputSchema = z.object({
5
+ session_id: z.string().min(1),
6
+ page_id: z.string().min(1).optional(),
7
+ url: z.string().url(),
8
+ wait_until: z.enum(["domcontentloaded", "load", "networkidle"]).default("domcontentloaded")
9
+ });
10
+
11
+ export const navigatePageOutputSchema = z.object({
12
+ page_id: z.string(),
13
+ requested_url: z.string(),
14
+ final_url: z.string(),
15
+ title: z.string().optional(),
16
+ navigation_id: z.string(),
17
+ timings: z.object({
18
+ elapsed_ms: z.number().nonnegative()
19
+ }),
20
+ follow_up_by_goal: followUpByGoalSchema
21
+ });
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+
3
+ export const observationRecommendationSchema = z.object({
4
+ recommended_tool: z.enum([
5
+ "observe.a11y",
6
+ "observe.dom",
7
+ "observe.text",
8
+ "observe.boxes",
9
+ "observe.screenshot"
10
+ ]),
11
+ screenshot_mode: z.enum(["none", "element", "viewport", "full"]).default("none"),
12
+ rationale: z.array(z.string()),
13
+ escalation_order: z.array(z.string())
14
+ });
15
+
16
+ export const followUpByGoalSchema = z.object({
17
+ interact: observationRecommendationSchema,
18
+ read: observationRecommendationSchema,
19
+ visual_verify: observationRecommendationSchema,
20
+ debug: observationRecommendationSchema,
21
+ gesture: observationRecommendationSchema
22
+ });
23
+
24
+ export const sessionRestartRecommendationSchema = z.object({
25
+ recommended: z.boolean(),
26
+ reason: z.string().optional()
27
+ });
28
+
29
+ export const recommendObservationInputSchema = z.object({
30
+ goal: z.enum(["interact", "read", "visual_verify", "debug", "gesture"]),
31
+ page_state_known: z.boolean().default(false),
32
+ target_selector_known: z.boolean().default(false),
33
+ needs_precise_coordinates: z.boolean().default(false),
34
+ needs_full_page_context: z.boolean().default(false),
35
+ recent_failure: z
36
+ .enum(["none", "semantic_not_found", "semantic_failed", "layout_uncertain", "runtime_error"])
37
+ .default("none")
38
+ });
39
+
40
+ export const recommendObservationOutputSchema = observationRecommendationSchema;
41
+
42
+ export type RecommendObservationInput = z.infer<typeof recommendObservationInputSchema>;
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+
3
+ export const evaluateJsInputSchema = z.object({
4
+ session_id: z.string().min(1),
5
+ page_id: z.string().min(1).optional(),
6
+ expression: z.string().min(1),
7
+ await_promise: z.boolean().default(true)
8
+ });
9
+
10
+ export const evaluateJsOutputSchema = z.object({
11
+ artifact_id: z.string(),
12
+ value: z.unknown().optional(),
13
+ preview: z.string().optional(),
14
+ truncated: z.boolean(),
15
+ url: z.string(),
16
+ title: z.string().optional(),
17
+ bytes: z.number().optional(),
18
+ storage_path: z.string().optional()
19
+ });
20
+
21
+ export type EvaluateJsInput = z.infer<typeof evaluateJsInputSchema>;
@@ -0,0 +1,63 @@
1
+ import { z } from "zod";
2
+
3
+ export const profileModeSchema = z.enum(["ephemeral", "persistent"]);
4
+
5
+ export const viewportSchema = z.object({
6
+ width: z.number().int().positive(),
7
+ height: z.number().int().positive()
8
+ });
9
+
10
+ export const createSessionInputSchema = z.object({
11
+ profile_mode: profileModeSchema.optional(),
12
+ locale: z.string().optional(),
13
+ timezone_id: z.string().optional(),
14
+ user_data_dir: z.string().optional(),
15
+ profile_directory: z.string().optional(),
16
+ humanize: z.boolean().optional(),
17
+ launch_args: z.array(z.string().min(1)).max(20).optional(),
18
+ viewport: viewportSchema.optional()
19
+ });
20
+
21
+ export const closeSessionInputSchema = z.object({
22
+ session_id: z.string().min(1)
23
+ });
24
+
25
+ export const restartSessionInputSchema = z.object({
26
+ session_id: z.string().min(1)
27
+ });
28
+
29
+ export const sessionOutputSchema = z.object({
30
+ session_id: z.string(),
31
+ context_id: z.string(),
32
+ page_id: z.string(),
33
+ status: z.enum(["active", "closing", "closed", "error"]),
34
+ profile_mode: profileModeSchema,
35
+ locale: z.string().optional(),
36
+ timezone_id: z.string().optional(),
37
+ user_data_dir: z.string().optional(),
38
+ profile_directory: z.string().optional(),
39
+ humanize: z.boolean(),
40
+ launch_args: z.array(z.string()),
41
+ viewport: viewportSchema,
42
+ created_at: z.string(),
43
+ health: z.object({
44
+ consecutive_errors: z.number().int().nonnegative(),
45
+ last_error_at: z.string().optional(),
46
+ restart_recommended: z.boolean()
47
+ }),
48
+ capabilities: z.object({
49
+ observe: z.boolean(),
50
+ screenshot: z.boolean(),
51
+ evaluate: z.boolean()
52
+ })
53
+ });
54
+
55
+ export const sessionCloseOutputSchema = z.object({
56
+ session_id: z.string(),
57
+ closed: z.boolean(),
58
+ status: z.enum(["active", "closing", "closed", "error"])
59
+ });
60
+
61
+ export const sessionRestartOutputSchema = sessionOutputSchema;
62
+
63
+ export type CreateSessionInput = z.infer<typeof createSessionInputSchema>;