@myrialabs/clopen 0.4.47 → 0.4.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/stream-manager.ts +62 -62
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +13 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/index.ts +21 -7
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +361 -25
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +64 -47
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +15 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +29 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +27 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +34 -45
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +7 -7
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +2 -4
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
|
@@ -16,20 +16,111 @@ import { browserMcpControl } from '$backend/preview';
|
|
|
16
16
|
import { debug } from '$shared/utils/logger';
|
|
17
17
|
import type { ActionDef, TablessActionContext } from './types';
|
|
18
18
|
import { commonFields } from './shared';
|
|
19
|
+
import {
|
|
20
|
+
DEVICE_MODEL_IDS,
|
|
21
|
+
DEVICE_PRESETS,
|
|
22
|
+
DEVICE_SIZES,
|
|
23
|
+
VIEWPORT_LIMITS,
|
|
24
|
+
canRotate,
|
|
25
|
+
defaultRotation,
|
|
26
|
+
getDeviceEmulation,
|
|
27
|
+
getDevicePreset,
|
|
28
|
+
type DeviceSize
|
|
29
|
+
} from '$shared/constants/preview';
|
|
30
|
+
import type { BrowserTab } from '$backend/preview/browser/types';
|
|
31
|
+
import type { EmulationPatch } from '$backend/preview/browser/viewport';
|
|
19
32
|
|
|
20
|
-
const DEVICE_SIZES = ['desktop', 'laptop', 'tablet', 'mobile'] as const;
|
|
21
33
|
const ROTATIONS = ['portrait', 'landscape'] as const;
|
|
22
34
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
const DEVICE_DOC = `device: a model — ${DEVICE_MODEL_IDS.join(' · ')} — sets its class, size, mockup and emulation (list_devices for sizes).
|
|
36
|
+
deviceSize: desktop · laptop (default) · tablet · mobile · responsive (no mockup, any size); picks the class's default model.
|
|
37
|
+
width+height (${VIEWPORT_LIMITS.min}–${VIEWPORT_LIMITS.max}) set an exact size on the current model and decide the orientation themselves.
|
|
38
|
+
touch, mobile (true/false/"auto"): touch events and the mobile viewport (<meta viewport>, overlay scrollbars) — on for tablet/mobile by default; changing either reloads the page.
|
|
39
|
+
colorScheme ("light"/"dark"/"auto"), reducedMotion ("reduce"/"no-preference"/"auto"): emulated media features.`;
|
|
40
|
+
|
|
41
|
+
const sizeField = (what: string) =>
|
|
42
|
+
z.number().int().min(VIEWPORT_LIMITS.min).max(VIEWPORT_LIMITS.max).optional().describe(`Exact viewport ${what} in CSS pixels. Give with the other dimension.`);
|
|
43
|
+
|
|
44
|
+
/** Device settings shared by open_tab and set_viewport. */
|
|
45
|
+
const deviceFields = {
|
|
46
|
+
device: z.enum(DEVICE_MODEL_IDS).optional().describe('Device model id.'),
|
|
47
|
+
deviceSize: z.enum(DEVICE_SIZES).optional().describe('Device class; its default model.'),
|
|
48
|
+
rotation: z.enum(ROTATIONS).optional().describe('Orientation.'),
|
|
49
|
+
width: sizeField('width'),
|
|
50
|
+
height: sizeField('height'),
|
|
51
|
+
touch: z.union([z.boolean(), z.literal('auto')]).optional().describe('Touch input; "auto" = device default.'),
|
|
52
|
+
mobile: z.union([z.boolean(), z.literal('auto')]).optional().describe('Mobile viewport; "auto" = device default.'),
|
|
53
|
+
colorScheme: z.enum(['light', 'dark', 'auto']).optional().describe('prefers-color-scheme.'),
|
|
54
|
+
reducedMotion: z.enum(['reduce', 'no-preference', 'auto']).optional().describe('prefers-reduced-motion.')
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
interface DeviceArgs {
|
|
58
|
+
device?: string;
|
|
59
|
+
deviceSize?: DeviceSize;
|
|
60
|
+
rotation?: 'portrait' | 'landscape';
|
|
61
|
+
width?: number;
|
|
62
|
+
height?: number;
|
|
63
|
+
touch?: boolean | 'auto';
|
|
64
|
+
mobile?: boolean | 'auto';
|
|
65
|
+
colorScheme?: 'light' | 'dark' | 'auto';
|
|
66
|
+
reducedMotion?: 'reduce' | 'no-preference' | 'auto';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** An exact size only counts when both halves of it were given. */
|
|
70
|
+
function exactSize(args: DeviceArgs) {
|
|
71
|
+
if ((args.width === undefined) !== (args.height === undefined)) {
|
|
72
|
+
throw new Error('width and height go together — give both, or neither');
|
|
73
|
+
}
|
|
74
|
+
return args.width && args.height ? { width: args.width, height: args.height } : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The class a request names, checking a model and a class do not disagree. */
|
|
78
|
+
function requestedClass(args: DeviceArgs): DeviceSize | undefined {
|
|
79
|
+
const preset = getDevicePreset(args.device);
|
|
80
|
+
if (args.device && !preset) throw new Error(`Unknown device '${args.device}' — see list_devices`);
|
|
81
|
+
if (preset && args.deviceSize && args.deviceSize !== preset.deviceSize) {
|
|
82
|
+
throw new Error(`'${args.device}' is a ${preset.deviceSize}, not a ${args.deviceSize}`);
|
|
83
|
+
}
|
|
84
|
+
return preset?.deviceSize ?? args.deviceSize;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A laptop's screen is hinged to its keyboard; it cannot stand up. */
|
|
88
|
+
function checkRotation(deviceSize: DeviceSize, args: DeviceArgs) {
|
|
89
|
+
const portraitSize = args.width && args.height && args.height > args.width;
|
|
90
|
+
if (!canRotate(deviceSize) && (args.rotation === 'portrait' || portraitSize)) {
|
|
91
|
+
throw new Error(`a ${deviceSize} cannot be portrait — use a monitor (desktop), a tablet, or responsive for a tall viewport`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** "auto" hands a setting back to the device; absent leaves it alone. */
|
|
96
|
+
function emulationPatch(args: DeviceArgs): EmulationPatch {
|
|
97
|
+
const auto = <T>(value: T | 'auto' | undefined): T | null | undefined => (value === 'auto' ? null : value);
|
|
98
|
+
return {
|
|
99
|
+
touch: auto(args.touch),
|
|
100
|
+
mobile: auto(args.mobile),
|
|
101
|
+
colorScheme: auto(args.colorScheme),
|
|
102
|
+
reducedMotion: auto(args.reducedMotion)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** One line describing everything about a tab's device. */
|
|
107
|
+
function describeDevice(tab: BrowserTab): string {
|
|
108
|
+
const model = getDevicePreset(tab.deviceModel)?.label ?? tab.deviceSize;
|
|
109
|
+
const { isMobile, hasTouch } = getDeviceEmulation(tab.deviceSize, tab.emulation);
|
|
110
|
+
const settings = [
|
|
111
|
+
hasTouch ? 'touch' : 'no touch',
|
|
112
|
+
isMobile ? 'mobile viewport' : 'desktop viewport',
|
|
113
|
+
tab.emulation.colorScheme && `color-scheme ${tab.emulation.colorScheme}`,
|
|
114
|
+
tab.emulation.reducedMotion && `reduced-motion ${tab.emulation.reducedMotion}`
|
|
115
|
+
].filter(Boolean);
|
|
116
|
+
return `${model} ${tab.rotation} ${tab.viewport.width}×${tab.viewport.height} · ${settings.join(', ')}`;
|
|
26
117
|
}
|
|
27
118
|
|
|
28
119
|
export const listTabs: ActionDef = {
|
|
29
120
|
type: 'list_tabs',
|
|
30
121
|
kind: 'control',
|
|
31
122
|
activity: 'Checking tabs',
|
|
32
|
-
doc: `list_tabs {} — every open tab with its id, URL,
|
|
123
|
+
doc: `list_tabs {} — every open tab with its id, URL, device and who controls it.
|
|
33
124
|
Use the id, not the position, with switch_tab/close_tab.`,
|
|
34
125
|
schema: z.object({ type: z.literal('list_tabs'), ...commonFields }),
|
|
35
126
|
needsTab: false,
|
|
@@ -40,10 +131,16 @@ export const listTabs: ActionDef = {
|
|
|
40
131
|
const lines = tabs.map((tab, index) => {
|
|
41
132
|
const owner = browserMcpControl.getTabOwner(tab.id);
|
|
42
133
|
const control = owner ? (owner === ctx.chatSessionId ? ' [yours]' : ' [another session]') : '';
|
|
134
|
+
const opener =
|
|
135
|
+
tab.openedBy?.kind === 'agent'
|
|
136
|
+
? tab.openedBy.chatSessionId === ctx.chatSessionId
|
|
137
|
+
? ' [opened by you]'
|
|
138
|
+
: ' [opened by another chat]'
|
|
139
|
+
: ' [opened by the user]';
|
|
43
140
|
return [
|
|
44
|
-
`${index + 1}. ${tab.isActive ? '*' : ' '} ${tab.id}${control} — ${tab.title || 'Untitled'}`,
|
|
141
|
+
`${index + 1}. ${tab.isActive ? '*' : ' '} ${tab.id}${control}${opener} — ${tab.title || 'Untitled'}`,
|
|
45
142
|
` ${tab.url || '(empty)'}`,
|
|
46
|
-
` ${tab
|
|
143
|
+
` ${describeDevice(tab)}${tab.isLoading ? ' · loading' : ''}`
|
|
47
144
|
].join('\n');
|
|
48
145
|
});
|
|
49
146
|
|
|
@@ -55,27 +152,31 @@ export const openTab: ActionDef = {
|
|
|
55
152
|
type: 'open_tab',
|
|
56
153
|
kind: 'control',
|
|
57
154
|
activity: 'Opening a tab',
|
|
58
|
-
doc: `open_tab {url?, deviceSize?, rotation?} — open a tab and make it the target.
|
|
59
|
-
|
|
60
|
-
rotation defaults to landscape for desktop/laptop, portrait for tablet/mobile.`,
|
|
155
|
+
doc: `open_tab {url?, device?, deviceSize?, rotation?, width?, height?, touch?, mobile?, colorScheme?, reducedMotion?} — open a tab and make it the target.
|
|
156
|
+
Device settings as for set_viewport. rotation defaults to the device's natural one.`,
|
|
61
157
|
schema: z.object({
|
|
62
158
|
type: z.literal('open_tab'),
|
|
63
159
|
url: z.string().url().optional().describe('URL to load, including protocol. Omit for a blank tab.'),
|
|
64
|
-
|
|
65
|
-
rotation: z.enum(ROTATIONS).optional().describe('Orientation. Omit for the device default.'),
|
|
160
|
+
...deviceFields,
|
|
66
161
|
...commonFields
|
|
67
162
|
}),
|
|
68
163
|
needsTab: false,
|
|
69
164
|
run: async (args, ctx: TablessActionContext) => {
|
|
70
|
-
const deviceSize = args
|
|
165
|
+
const deviceSize = requestedClass(args) ?? 'laptop';
|
|
166
|
+
checkRotation(deviceSize, args);
|
|
71
167
|
const rotation = args.rotation || defaultRotation(deviceSize);
|
|
72
168
|
|
|
73
|
-
const tab = await ctx.service.createTab(args.url || undefined, deviceSize, rotation)
|
|
169
|
+
const tab = await ctx.service.createTab(args.url || undefined, deviceSize, rotation, undefined, exactSize(args), {
|
|
170
|
+
deviceModel: args.device,
|
|
171
|
+
emulation: emulationPatch(args)
|
|
172
|
+
});
|
|
173
|
+
tab.openedBy = { kind: 'agent', chatSessionId: ctx.chatSessionId };
|
|
74
174
|
browserMcpControl.acquireControl(tab.id, ctx.chatSessionId, ctx.projectId);
|
|
75
175
|
ctx.invalidateTab();
|
|
76
176
|
|
|
77
|
-
|
|
78
|
-
|
|
177
|
+
const device = describeDevice(tab);
|
|
178
|
+
debug.log('mcp', `📑 Opened tab ${tab.id} (${device})`);
|
|
179
|
+
return { summary: `${tab.id} · ${tab.url || '(blank)'} · ${device}` };
|
|
79
180
|
}
|
|
80
181
|
};
|
|
81
182
|
|
|
@@ -116,7 +217,8 @@ export const closeTab: ActionDef = {
|
|
|
116
217
|
type: 'close_tab',
|
|
117
218
|
kind: 'control',
|
|
118
219
|
activity: 'Closing a tab',
|
|
119
|
-
doc: `close_tab {tabId?} — close a tab (default: the current one)
|
|
220
|
+
doc: `close_tab {tabId?} — close a tab (default: the current one).
|
|
221
|
+
Close every tab you opened once you are done with it. Keep one open only if this chat will use it again, it is waiting on the user (a login, an OTP, a captcha), or the user asked for it. Never close a tab the user opened unless asked.`,
|
|
120
222
|
schema: z.object({
|
|
121
223
|
type: z.literal('close_tab'),
|
|
122
224
|
tabId: z.string().optional().describe('Tab id from list_tabs. Omit to close the current tab.'),
|
|
@@ -139,27 +241,54 @@ export const closeTab: ActionDef = {
|
|
|
139
241
|
}
|
|
140
242
|
};
|
|
141
243
|
|
|
244
|
+
export const listDevices: ActionDef = {
|
|
245
|
+
type: 'list_devices',
|
|
246
|
+
kind: 'control',
|
|
247
|
+
activity: 'Checking devices',
|
|
248
|
+
doc: `list_devices {} — every device model with its class, system and size, and the current tab's device settings.`,
|
|
249
|
+
schema: z.object({ type: z.literal('list_devices'), ...commonFields }),
|
|
250
|
+
needsTab: false,
|
|
251
|
+
run: async (_args, ctx: TablessActionContext) => {
|
|
252
|
+
const lines = DEVICE_PRESETS.map(
|
|
253
|
+
(preset) => `${preset.id} — ${preset.label} · ${preset.deviceSize} · ${preset.os} · ${preset.width}×${preset.height}`
|
|
254
|
+
);
|
|
255
|
+
lines.push('responsive — no mockup, any size (width/height)');
|
|
256
|
+
|
|
257
|
+
const active = ctx.service.getActiveTab();
|
|
258
|
+
if (active) lines.push('', `current tab ${active.id}: ${describeDevice(active)}`);
|
|
259
|
+
|
|
260
|
+
return { summary: `${DEVICE_PRESETS.length} device models`, detail: lines.join('\n') };
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
142
264
|
export const setViewport: ActionDef = {
|
|
143
265
|
type: 'set_viewport',
|
|
144
266
|
kind: 'control',
|
|
145
|
-
activity: 'Changing the
|
|
146
|
-
doc: `set_viewport {deviceSize?, rotation?} —
|
|
147
|
-
|
|
267
|
+
activity: 'Changing the device',
|
|
268
|
+
doc: `set_viewport {device?, deviceSize?, rotation?, width?, height?, touch?, mobile?, colorScheme?, reducedMotion?} — change the current tab's device; anything left out stays as it is.
|
|
269
|
+
${DEVICE_DOC}
|
|
270
|
+
rotation alone turns the current size around; laptops stay landscape. Any of this re-runs the page's media queries, so it is how responsive layouts get tested.`,
|
|
148
271
|
schema: z.object({
|
|
149
272
|
type: z.literal('set_viewport'),
|
|
150
|
-
|
|
151
|
-
rotation: z.enum(ROTATIONS).optional().describe('Omit to keep the current orientation.'),
|
|
273
|
+
...deviceFields,
|
|
152
274
|
...commonFields
|
|
153
275
|
}),
|
|
154
276
|
run: async (args, ctx) => {
|
|
155
|
-
const deviceSize = args
|
|
156
|
-
|
|
277
|
+
const deviceSize = requestedClass(args) ?? ctx.tab.deviceSize;
|
|
278
|
+
checkRotation(deviceSize, args);
|
|
157
279
|
|
|
158
|
-
const ok = await ctx.service.setViewport(ctx.tab.id,
|
|
159
|
-
|
|
280
|
+
const ok = await ctx.service.setViewport(ctx.tab.id, {
|
|
281
|
+
deviceSize,
|
|
282
|
+
rotation: args.rotation,
|
|
283
|
+
size: exactSize(args),
|
|
284
|
+
deviceModel: args.device,
|
|
285
|
+
emulation: emulationPatch(args)
|
|
286
|
+
});
|
|
287
|
+
if (!ok) throw new Error(`Could not change the device of tab '${ctx.tab.id}'`);
|
|
160
288
|
|
|
161
|
-
|
|
289
|
+
const tab = ctx.service.getTab(ctx.tab.id) ?? ctx.tab;
|
|
290
|
+
return { summary: describeDevice(tab) };
|
|
162
291
|
}
|
|
163
292
|
};
|
|
164
293
|
|
|
165
|
-
export const tabActions: ActionDef[] = [listTabs, openTab, switchTab, closeTab, setViewport];
|
|
294
|
+
export const tabActions: ActionDef[] = [listTabs, openTab, switchTab, closeTab, listDevices, setViewport];
|
|
@@ -114,6 +114,7 @@ export async function getActiveTabSession(
|
|
|
114
114
|
|
|
115
115
|
debug.log('mcp', `📑 No tab open for project ${resolvedProjectId} — opening a blank one`);
|
|
116
116
|
const tab = await service.createTab(undefined, 'laptop', 'landscape');
|
|
117
|
+
tab.openedBy = { kind: 'agent', chatSessionId };
|
|
117
118
|
browserMcpControl.acquireControl(tab.id, chatSessionId, resolvedProjectId);
|
|
118
119
|
|
|
119
120
|
return { tab, service, opened: true };
|
|
@@ -16,13 +16,15 @@ Everything is one call. Pass an array of actions and they run in order, which is
|
|
|
16
16
|
HOW TO USE IT WELL
|
|
17
17
|
|
|
18
18
|
1. Batch. Put every step you can predict into one call: open_tab → wait_for → click → type → click → screenshot is a single call, not six. Split only where the next step depends on something you must read first.
|
|
19
|
-
2. Target by selector or text, not coordinates. Elements are resolved in every frame, scrolled into view, and aimed at their centre — coordinates go stale the moment the page reflows.
|
|
19
|
+
2. Target by selector or text, not coordinates. Elements are resolved in every frame, scrolled into view, and aimed at their centre — coordinates go stale the moment the page reflows. Text targeting prefers an exact match on something clickable that is actually on top (a modal's button over the paragraph that mentions it); use \`find\` when you are unsure what to name; use x/y only for canvases and images.
|
|
20
20
|
3. Read with analyze_dom, not screenshots. Text, links and structure come back as text, for the whole document, at a fraction of the cost. Screenshot when the answer is visual: canvas, charts, layout, iframes, captchas.
|
|
21
21
|
4. Navigate by URL. If analyze_dom gave you an href, \`navigate\` to it. Clicking a link to move around is slower and fails more.
|
|
22
22
|
5. Synchronise with wait_for, not wait. wait_for returns the instant the condition holds; a fixed delay is either too short (the batch fails) or too long (every run pays for it).
|
|
23
23
|
6. Failure stops the batch. Anything after a failed action is skipped and reported as skipped. Mark a step \`optional: true\` when it may legitimately not apply — dismissing a cookie banner that might not be there — or set onError:"continue" for genuinely independent steps.
|
|
24
24
|
7. Obstacles are yours to clear. Captcha, modal, cookie wall: solve or dismiss it and carry on. Do not stop to ask.
|
|
25
25
|
8. Check the report. Every action reports its own outcome, and the report ends with the tab and URL you left behind. If a result contradicts your plan, say so and re-plan rather than continuing on the assumption it worked.
|
|
26
|
+
9. Native dialogs are yours. When a page opens alert / confirm / prompt, the report says DIALOG OPEN and quotes it; nothing else runs until you answer with the dialog action. Decide as the user would — nobody else will.
|
|
27
|
+
10. Clean up your tabs. Close every tab you opened once you are done with it; the report lists the ones still open. Keep one only if this chat will use it again, it is waiting on the user (a login, an OTP, a captcha), or the user asked for it. Never close a tab the user opened unless asked.
|
|
26
28
|
|
|
27
29
|
WORKFLOWS
|
|
28
30
|
|
|
@@ -35,7 +37,8 @@ Fill a form
|
|
|
35
37
|
[{type, selector:"#email", text:"…"}, {type, selector:"#password", text:"…"}, {click, selector:"button[type=submit]"}, {wait_for, urlContains:"/dashboard"}]
|
|
36
38
|
|
|
37
39
|
Check a layout on mobile
|
|
38
|
-
[{set_viewport,
|
|
40
|
+
[{set_viewport, device:"iphone-16"}, {wait_for, state:"networkIdle"}, {screenshot}]
|
|
41
|
+
Same page on Android in dark mode: [{set_viewport, device:"galaxy-s24", colorScheme:"dark"}, {screenshot}]
|
|
39
42
|
|
|
40
43
|
Debug a page that misbehaves
|
|
41
44
|
[{clear_console}, {click, selector:"#save"}, {wait, ms:500}, {console_logs, level:"error"}]`;
|
|
@@ -38,7 +38,30 @@ export function formatReport(report: RunReport): {
|
|
|
38
38
|
if (report.aborted) {
|
|
39
39
|
lines.push('', 'Interrupted: the chat stream was cancelled, so the remaining actions did not run.');
|
|
40
40
|
} else if (report.skipped > 0) {
|
|
41
|
-
lines.push(
|
|
41
|
+
lines.push(
|
|
42
|
+
'',
|
|
43
|
+
report.dialog
|
|
44
|
+
? `${report.skipped} action(s) skipped: the page is paused on the dialog below.`
|
|
45
|
+
: `${report.skipped} action(s) skipped after the failure above (onError defaults to "stop").`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (report.dialog) {
|
|
50
|
+
const { tabId, type, message, defaultValue } = report.dialog;
|
|
51
|
+
const prompt = type === 'prompt' ? `, text:"…"` : '';
|
|
52
|
+
lines.push(
|
|
53
|
+
'',
|
|
54
|
+
`DIALOG OPEN on ${tabId} — ${type}: ${JSON.stringify(message)}${type === 'prompt' && defaultValue ? ` (default ${JSON.stringify(defaultValue)})` : ''}`,
|
|
55
|
+
`The page runs nothing until it is answered. Decide as the user would and reply with {type:"dialog", response:"accept"|"dismiss"${prompt}}.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (report.agentTabs?.length) {
|
|
60
|
+
const listed = report.agentTabs.map((tab) => `${tab.id} (${tab.url || 'blank'})`).join(', ');
|
|
61
|
+
lines.push(
|
|
62
|
+
'',
|
|
63
|
+
`Tabs you opened that are still open: ${listed}. Close each with close_tab once you are done — keep one only if this chat will use it again, it is waiting on the user, or the user asked to keep it.`
|
|
64
|
+
);
|
|
42
65
|
}
|
|
43
66
|
|
|
44
67
|
const content: Array<{ type: 'text'; text: string } | { type: 'image'; data: string; mimeType: string }> = [
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { BrowserAutonomousAction, BrowserTab } from '$backend/preview/browser/types';
|
|
21
|
+
import type { PendingDialogInfo } from '$backend/preview/browser/browser-dialog-handler';
|
|
21
22
|
import { projectContextService } from '$backend/mcp/internal/project-context';
|
|
22
23
|
import { debug } from '$shared/utils/logger';
|
|
23
24
|
import { ACTIONS_BY_TYPE } from './actions/index';
|
|
@@ -57,6 +58,10 @@ export interface RunReport {
|
|
|
57
58
|
url?: string;
|
|
58
59
|
/** Set when the batch had to open a tab because the browser had none. */
|
|
59
60
|
openedTabId?: string;
|
|
61
|
+
/** A dialog the page is blocked on — the agent has to answer it next. */
|
|
62
|
+
dialog?: PendingDialogInfo & { tabId: string };
|
|
63
|
+
/** Tabs this chat session opened that are still open, for the close-when-done nudge. */
|
|
64
|
+
agentTabs?: Array<{ id: string; url: string }>;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
/** Consecutive input gestures form one native run; control actions stand alone. */
|
|
@@ -139,7 +144,9 @@ export async function runActions(args: RunArgs): Promise<RunReport> {
|
|
|
139
144
|
|
|
140
145
|
// Check every step this group produced, not just the last: one native
|
|
141
146
|
// run can fail in the middle and still finish with a successful action.
|
|
142
|
-
|
|
147
|
+
// A dialog stops the batch whatever `optional` says: the page runs
|
|
148
|
+
// nothing until it is answered, so every later step would only hang.
|
|
149
|
+
stopped = !!report.dialog || report.steps.slice(before).some((step) => !step.ok && !tolerates(step));
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
report.failed = report.steps.some((step) => !step.ok && !tolerates(step));
|
|
@@ -155,11 +162,22 @@ export async function runActions(args: RunArgs): Promise<RunReport> {
|
|
|
155
162
|
if (current) {
|
|
156
163
|
report.tabId = current.id;
|
|
157
164
|
report.url = current.page.url();
|
|
165
|
+
|
|
166
|
+
// A dialog can open after the last action returned (an alert on a
|
|
167
|
+
// timer, a response handler). The next call would find the page
|
|
168
|
+
// paused with no idea why, so it is reported now.
|
|
169
|
+
const open = report.dialog ? null : service.getPendingDialog(current.id);
|
|
170
|
+
if (open) report.dialog = { ...open, tabId: current.id };
|
|
158
171
|
}
|
|
159
172
|
} catch {
|
|
160
173
|
// No tab left (closed by the batch, or none was ever open).
|
|
161
174
|
}
|
|
162
175
|
|
|
176
|
+
report.agentTabs = service
|
|
177
|
+
.getAllTabs()
|
|
178
|
+
.filter((candidate) => candidate.openedBy?.kind === 'agent' && candidate.openedBy.chatSessionId === chatSessionId)
|
|
179
|
+
.map((candidate) => ({ id: candidate.id, url: candidate.page.isClosed() ? candidate.url : candidate.page.url() }));
|
|
180
|
+
|
|
163
181
|
return report;
|
|
164
182
|
}
|
|
165
183
|
|
|
@@ -194,12 +212,54 @@ async function runControl(item: { index: number; args: ActionArgs }, deps: RunDe
|
|
|
194
212
|
// themselves from inside the engine (see ActionDef.activity); a control
|
|
195
213
|
// action has no gesture, and is often the longest step in a batch — a
|
|
196
214
|
// 30-second `wait_for` with a silent cursor on it reads as a hang.
|
|
215
|
+
// A page with a dialog open evaluates nothing and paints nothing, so a
|
|
216
|
+
// read or a screenshot would hang until someone answered. Only the
|
|
217
|
+
// tab-level actions and `dialog` itself still make sense.
|
|
218
|
+
const guarded = tab && def.needsTab !== false && def.type !== 'dialog';
|
|
219
|
+
const open = guarded ? deps.service.getPendingDialog(tab.id) : null;
|
|
220
|
+
if (tab && open) {
|
|
221
|
+
report.dialog = { ...open, tabId: tab.id };
|
|
222
|
+
report.steps.push({
|
|
223
|
+
index: item.index,
|
|
224
|
+
type: def.type,
|
|
225
|
+
ok: false,
|
|
226
|
+
error: `a ${open.type} dialog is open — answer it with the dialog action first`
|
|
227
|
+
});
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
|
|
197
231
|
if (tab && def.activity) {
|
|
198
232
|
labelled = tab.id;
|
|
199
233
|
browserMcpControl.emitActivity(tab.id, def.activity);
|
|
200
234
|
}
|
|
201
235
|
|
|
202
|
-
const
|
|
236
|
+
const running = def.run(item.args, deps.makeContext(tab));
|
|
237
|
+
const watch = guarded && tab ? deps.service.waitForDialog(tab.id) : null;
|
|
238
|
+
let winner: { kind: 'done'; output: Awaited<typeof running> } | { kind: 'dialog'; info: PendingDialogInfo };
|
|
239
|
+
try {
|
|
240
|
+
winner = await Promise.race([
|
|
241
|
+
running.then((output) => ({ kind: 'done' as const, output })),
|
|
242
|
+
...(watch ? [watch.promise.then((info) => ({ kind: 'dialog' as const, info }))] : [])
|
|
243
|
+
]);
|
|
244
|
+
} finally {
|
|
245
|
+
watch?.dispose();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (winner.kind === 'dialog') {
|
|
249
|
+
// The action is parked behind the dialog and finishes on its own once
|
|
250
|
+
// it is answered; nothing here waits for that.
|
|
251
|
+
running.catch(() => {});
|
|
252
|
+
report.dialog = { ...winner.info, tabId: tab!.id };
|
|
253
|
+
report.steps.push({
|
|
254
|
+
index: item.index,
|
|
255
|
+
type: def.type,
|
|
256
|
+
ok: false,
|
|
257
|
+
error: `interrupted: a ${winner.info.type} dialog opened`
|
|
258
|
+
});
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const output = winner.output;
|
|
203
263
|
report.steps.push({ index: item.index, type: def.type, ok: true, summary: output.summary, detail: output.detail });
|
|
204
264
|
if (output.images?.length) report.images.push(...output.images);
|
|
205
265
|
} catch (error) {
|
|
@@ -264,12 +324,17 @@ async function runInputGroup(items: Array<{ index: number; args: ActionArgs }>,
|
|
|
264
324
|
|
|
265
325
|
const outcome = await deps.service.performAutonomousActions(tab.id, primitives, deps.signal);
|
|
266
326
|
|
|
327
|
+
if (outcome.blockedBy) report.dialog = { ...outcome.blockedBy, tabId: tab.id };
|
|
328
|
+
|
|
267
329
|
// One engine result per primitive, in order.
|
|
268
330
|
mapped.forEach((entry, position) => {
|
|
269
331
|
const result = outcome.results[position];
|
|
270
332
|
if (!result) {
|
|
271
333
|
// The engine stopped before reaching this one.
|
|
272
|
-
|
|
334
|
+
const reason = outcome.blockedBy
|
|
335
|
+
? 'did not run — the page is paused on a dialog'
|
|
336
|
+
: 'did not run (batch stopped earlier)';
|
|
337
|
+
report.steps.push({ index: entry.index, type: entry.type, ok: false, error: reason });
|
|
273
338
|
return;
|
|
274
339
|
}
|
|
275
340
|
|
package/backend/memory/redact.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* keys, an `.env` a tool printed, an Authorization header inside a failed
|
|
6
6
|
* request. Memory is the worst possible place for those to land, because unlike
|
|
7
7
|
* a chat message a memory is durable, is re-injected into EVERY future turn on
|
|
8
|
-
* EVERY engine, and is readable
|
|
8
|
+
* EVERY engine, and is readable from every device. A secret that
|
|
9
9
|
* reaches a message is exposed once; a secret that reaches the graph is exposed
|
|
10
10
|
* continuously.
|
|
11
11
|
*
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* Tests for the note collection access rule.
|
|
3
3
|
*
|
|
4
4
|
* This one function decides who can read notes and who can read the image bytes
|
|
5
|
-
* behind them
|
|
6
|
-
* stay deliberate: it grants every signed-in account, so a regression that
|
|
7
|
-
* quietly widened the project case into it would be invisible in the UI.
|
|
5
|
+
* behind them, so both answers have to stay in step.
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
import { describe, it, expect, beforeAll, afterAll } from 'bun:test';
|
|
@@ -16,47 +14,51 @@ import { noteCollectionQueries } from '../database/queries/note-queries';
|
|
|
16
14
|
import { canAccessCollection } from './access';
|
|
17
15
|
import type { NoteCollection } from '$shared/types/database/schema';
|
|
18
16
|
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let projectId: string;
|
|
17
|
+
let listedId: string;
|
|
18
|
+
let removedId: string;
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
outsiderId = randomUUID();
|
|
27
|
-
projectId = projectQueries.create({
|
|
28
|
-
name: 'notes-access-test',
|
|
20
|
+
function createProject(name: string): string {
|
|
21
|
+
return projectQueries.create({
|
|
22
|
+
name,
|
|
29
23
|
// `projects.path` is unique, so a fixed path collides with whatever an
|
|
30
24
|
// earlier run left behind in the test data dir.
|
|
31
|
-
path: `/tmp
|
|
25
|
+
path: `/tmp/${name}-${randomUUID()}`,
|
|
32
26
|
created_at: new Date().toISOString(),
|
|
33
27
|
last_opened_at: new Date().toISOString()
|
|
34
28
|
}).id;
|
|
35
|
-
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeAll(async () => {
|
|
32
|
+
await initializeDatabase();
|
|
33
|
+
listedId = createProject('notes-access-listed');
|
|
34
|
+
projectQueries.list(listedId);
|
|
35
|
+
// Removed from the list (mode 'remove'): the record stays, access does not.
|
|
36
|
+
removedId = createProject('notes-access-removed');
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
afterAll(() => {
|
|
39
|
-
projectQueries.deleteProject(
|
|
40
|
+
projectQueries.deleteProject(listedId);
|
|
41
|
+
projectQueries.deleteProject(removedId);
|
|
40
42
|
closeDatabase();
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
describe('canAccessCollection — project scope', () => {
|
|
44
|
-
it('admits a
|
|
45
|
-
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId });
|
|
46
|
-
expect(canAccessCollection(
|
|
46
|
+
it('admits a collection of a listed project', () => {
|
|
47
|
+
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId: listedId });
|
|
48
|
+
expect(canAccessCollection(collection)).toBe(true);
|
|
47
49
|
noteCollectionQueries.delete(collection.id);
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
it('refuses
|
|
51
|
-
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId });
|
|
52
|
-
expect(canAccessCollection(
|
|
52
|
+
it('refuses a collection of a removed project', () => {
|
|
53
|
+
const collection = noteCollectionQueries.create({ name: 'P', scope: 'project', projectId: removedId });
|
|
54
|
+
expect(canAccessCollection(collection)).toBe(false);
|
|
53
55
|
noteCollectionQueries.delete(collection.id);
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
it('refuses a project collection with no project rather than admitting
|
|
58
|
+
it('refuses a project collection with no project rather than admitting it', () => {
|
|
57
59
|
// The table's CHECK makes this unreachable through the queries, but a row
|
|
58
60
|
// in this shape must fail closed rather than fall through to the global
|
|
59
|
-
// branch
|
|
61
|
+
// branch.
|
|
60
62
|
const malformed = {
|
|
61
63
|
id: 'x',
|
|
62
64
|
name: 'Malformed',
|
|
@@ -66,17 +68,14 @@ describe('canAccessCollection — project scope', () => {
|
|
|
66
68
|
created_at: '',
|
|
67
69
|
updated_at: ''
|
|
68
70
|
} as NoteCollection;
|
|
69
|
-
expect(canAccessCollection(
|
|
71
|
+
expect(canAccessCollection(malformed)).toBe(false);
|
|
70
72
|
});
|
|
71
73
|
});
|
|
72
74
|
|
|
73
75
|
describe('canAccessCollection — global scope', () => {
|
|
74
|
-
it('admits
|
|
75
|
-
// Deliberate: a global collection has no per-note ACL, so everything in it
|
|
76
|
-
// is readable by every account that can sign in.
|
|
76
|
+
it('admits a global collection', () => {
|
|
77
77
|
const collection = noteCollectionQueries.create({ name: 'G', scope: 'global' });
|
|
78
|
-
expect(canAccessCollection(
|
|
79
|
-
expect(canAccessCollection(outsiderId, collection)).toBe(true);
|
|
78
|
+
expect(canAccessCollection(collection)).toBe(true);
|
|
80
79
|
noteCollectionQueries.delete(collection.id);
|
|
81
80
|
});
|
|
82
81
|
});
|
package/backend/notes/access.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Whether a note collection can be reached.
|
|
3
3
|
*
|
|
4
4
|
* The rule lives here rather than in each route because three call sites need
|
|
5
5
|
* to agree on it — the WebSocket handlers, the image upload, and the image
|
|
@@ -11,17 +11,12 @@ import type { NoteCollection } from '$shared/types/database/schema';
|
|
|
11
11
|
import { projectQueries } from '../database/queries/project-queries';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `
|
|
17
|
-
* project-scoped API uses.
|
|
18
|
-
* - `global` — every signed-in user on this instance. Global collections are
|
|
19
|
-
* deliberately instance-wide: there is no per-note ACL, so anything put in
|
|
20
|
-
* one is readable by every account that can sign in, including members of
|
|
21
|
-
* unrelated projects.
|
|
14
|
+
* - `project` — reachable while its project is in the workspace list, the same
|
|
15
|
+
* check the rest of the project-scoped API uses.
|
|
16
|
+
* - `global` — always reachable.
|
|
22
17
|
*/
|
|
23
|
-
export function canAccessCollection(
|
|
18
|
+
export function canAccessCollection(collection: NoteCollection): boolean {
|
|
24
19
|
if (collection.scope === 'global') return true;
|
|
25
20
|
if (!collection.project_id) return false;
|
|
26
|
-
return projectQueries.
|
|
21
|
+
return projectQueries.isListed(collection.project_id);
|
|
27
22
|
}
|
|
@@ -95,7 +95,7 @@ export interface PermissionInventory {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export const permissionService = {
|
|
98
|
-
/** All stored global/project permission sets for the
|
|
98
|
+
/** All stored global/project permission sets for the Settings listing. Profile
|
|
99
99
|
* overlays are excluded — they are managed in the profile editor. */
|
|
100
100
|
list(projectId?: string): PermissionSetDTO[] {
|
|
101
101
|
const rows = projectId
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workspace clipboard's one job besides holding text: telling the user's
|
|
3
|
+
* devices about copies they did not make, and never echoing theirs back.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import { WorkspaceClipboard, type ClipboardChange } from './browser-clipboard';
|
|
8
|
+
|
|
9
|
+
function watch(clipboard: WorkspaceClipboard): ClipboardChange[] {
|
|
10
|
+
const changes: ClipboardChange[] = [];
|
|
11
|
+
clipboard.on('changed', (change: ClipboardChange) => changes.push(change));
|
|
12
|
+
return changes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('WorkspaceClipboard', () => {
|
|
16
|
+
test('a page copy is held and announced to the devices', () => {
|
|
17
|
+
const clipboard = new WorkspaceClipboard();
|
|
18
|
+
const changes = watch(clipboard);
|
|
19
|
+
|
|
20
|
+
clipboard.write('TOKEN', 'page');
|
|
21
|
+
|
|
22
|
+
expect(clipboard.read()).toBe('TOKEN');
|
|
23
|
+
expect(changes.map((change) => [change.text, change.source])).toEqual([['TOKEN', 'page']]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('a copy from the device is held but not sent back to it', () => {
|
|
27
|
+
const clipboard = new WorkspaceClipboard();
|
|
28
|
+
const changes = watch(clipboard);
|
|
29
|
+
|
|
30
|
+
clipboard.write('from my laptop', 'device');
|
|
31
|
+
|
|
32
|
+
expect(clipboard.read()).toBe('from my laptop');
|
|
33
|
+
expect(changes).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('writing the same text again announces nothing', () => {
|
|
37
|
+
const clipboard = new WorkspaceClipboard();
|
|
38
|
+
const changes = watch(clipboard);
|
|
39
|
+
|
|
40
|
+
clipboard.write('same', 'agent');
|
|
41
|
+
clipboard.write('same', 'page');
|
|
42
|
+
|
|
43
|
+
expect(changes).toHaveLength(1);
|
|
44
|
+
expect(clipboard.describe().source).toBe('page');
|
|
45
|
+
});
|
|
46
|
+
});
|