Merge origin/main after approved conflict preparation

This commit is contained in:
Brennan Benson
2026-11-12 15:42:07 -08:00
888 changed files with 15942 additions and 12237 deletions
+3 -1
View File
@@ -54,6 +54,8 @@ on:
- 'tests/e2e/computer-linux.e2e.ts'
- 'tests/e2e/computer-windows.e2e.ts'
- 'tests/e2e/computer-windows-store.e2e.ts'
- 'tests/e2e/computer-windows-background.e2e.ts'
- 'tests/e2e/helpers/windows-semantic-controls-fixture.*'
- 'tests/e2e/helpers/computer-cli-driver.ts'
- 'tests/e2e/helpers/computer-driver.ts'
- 'tests/e2e/vitest.config.ts'
@@ -151,4 +153,4 @@ jobs:
- run: pnpm verify:computer-native
- run: pnpm build:cli
- run: pnpm run build:electron-vite:parallel
- run: pnpm test:e2e:computer --reporter=verbose tests/e2e/computer-windows.e2e.ts tests/e2e/computer-windows-store.e2e.ts
- run: pnpm test:e2e:computer --reporter=verbose tests/e2e/computer-windows.e2e.ts tests/e2e/computer-windows-store.e2e.ts tests/e2e/computer-windows-background.e2e.ts
+1 -1
View File
@@ -247,7 +247,7 @@ jobs:
run: node "$(if [ -f config/scripts/orcad-distribution/template/build-orcad-template.mjs ]; then printf %s config/scripts/orcad-distribution/template/build-orcad-template.mjs; else printf %s config/scripts/build-orcad-template.mjs; fi)" --targets linux-${{ runner.arch == 'ARM64' && 'arm64' || 'x64' }}-glibc
- name: Verify a structured chat from the desktop server template
if: runner.os == 'Linux'
run: pnpm test:node-server --artifact src/main/orcad/orcad-packaged-structured-chat.integration.test.ts --maxWorkers=2
run: pnpm test:node-server --artifact src/main/orcad/testing/structured-chat/orcad-packaged-structured-chat.integration.test.ts --maxWorkers=2
# Only a Windows runner compiles it; arm64 cross-compiles here.
# Before the Node 18 check below: the build script imports TypeScript, which Node 18 cannot load.
# orcad's instance lock and stop proof read a PID's creation time through it; the x64 binary this
+2 -2
View File
@@ -15,8 +15,8 @@ on:
- 'src/main/managed-server/**'
- 'src/main/ssh/migration-source/**'
- 'src/main/persistence/migrating-orcad-catalog/**'
- 'src/main/orcad/orcad-artifact-materializer.ts'
- 'src/main/orcad/orcad-host-unavailable.ts'
- 'src/main/orcad/artifact-slots/orcad-artifact-materializer.ts'
- 'src/main/orcad/diagnostics/orcad-host-unavailable.ts'
- 'src/main/node-runtime/**'
- 'src/main/ssh/remote-exec/**'
- 'src/main/ssh/remote-host/**'
+3 -3
View File
@@ -12,8 +12,8 @@ on:
- 'src/main/managed-server/**'
- 'src/main/ssh/migration-source/**'
- 'src/main/persistence/migrating-orcad-catalog/**'
- 'src/main/orcad/orcad-artifact-materializer.ts'
- 'src/main/orcad/orcad-host-unavailable.ts'
- 'src/main/orcad/artifact-slots/orcad-artifact-materializer.ts'
- 'src/main/orcad/diagnostics/orcad-host-unavailable.ts'
- 'src/main/node-runtime/**'
- 'src/main/ssh/remote-exec/**'
- 'src/main/ssh/remote-host/**'
@@ -38,7 +38,7 @@ on:
- 'config/scripts/native-build/windows/build-windows-cli-launcher.mjs'
- 'config/scripts/native-build/windows/windows-rust-executable-build.mjs'
- 'native/windows-cli-launcher/**'
- 'src/main/orcad/orcad-cli-launcher.ts'
- 'src/main/orcad/serve-startup/orcad-cli-launcher.ts'
- '.github/actions/prepare-windows-cli-launcher/**'
- 'config/patches/node-pty*'
- 'config/patches/@vscode__windows-process-tree*'
+2 -3
View File
@@ -221,8 +221,8 @@ jobs:
pnpm-lock.yaml
cloud/pnpm-lock.yaml
# These two tests import the cloud relay workspace directly. Keeping them in one job
# avoids installing and building the same workspace once per unit-test shard.
# This test imports the cloud relay workspace directly. Its dedicated job avoids
# installing and building the same workspace once per unit-test shard.
- name: Install relay integration dependencies
id: relay_dependencies
if: ${{ !cancelled() && steps.root_dependencies.outcome == 'success' }}
@@ -237,5 +237,4 @@ jobs:
ORCA_BACKGROUND_LAUNCH: '1'
run: >-
pnpm exec vitest run --config config/vitest.config.ts
tests/e2e/relay-region-compatibility.unit.test.ts
tests/e2e/relay-region-correction.unit.test.ts
+1 -1
View File
@@ -5,7 +5,7 @@ import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs
import { SignJWT, exportJWK, generateKeyPair, importJWK, type JWK } from 'jose'
import nacl from 'tweetnacl'
import WebSocket from 'ws'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/relay-control-client'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client'
import { CloudRelayTransport } from '../../../../src/main/runtime/rpc/transports/relay-transport'
export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
@@ -2,7 +2,7 @@
// client wrapper, the echo service, phone sockets and workerd memory sampling.
import { execSync } from 'node:child_process'
import WebSocket from 'ws'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/relay-control-client'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client'
import { CloudRelayTransport } from '../../../../src/main/runtime/rpc/transports/relay-transport'
export const PORT = 8787
@@ -39,7 +39,7 @@ export async function runLifecycleChecks(ctx: Ctx, main: Control, mainAck: Ack):
mute.on('close', (c) => (muteClose = c))
await new Promise((res) => mute.on('open', res))
// Complete the handshake by hand with the shipped proof answerer, then never pong.
const { answerRelayHostChallenge } = await import('../../../../src/main/runtime/mobile-cloud-relay/relay-host-proof')
const { answerRelayHostChallenge } = await import('../../../../src/main/runtime/mobile-cloud-relay/control-channel/relay-host-proof')
mute.send(JSON.stringify({ type: 'host-hello', v: 1, relayHostId: ctx.relayHostId, assignmentEpoch: 7,
hostPublicKeyB64: ctx.keypair.publicKeyB64, appVersion: 'spike' }))
mute.on('message', (raw) => {
@@ -5,7 +5,7 @@ import { readFileSync } from 'node:fs'
import { SignJWT, type KeyLike } from 'jose'
import nacl from 'tweetnacl'
import WebSocket from 'ws'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/relay-control-client'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client'
import { CloudRelayTransport } from '../../../../src/main/runtime/rpc/transports/relay-transport'
export const PORT = 8789
@@ -8,7 +8,7 @@ import { join } from 'node:path'
import { SignJWT, type KeyLike } from 'jose'
import nacl from 'tweetnacl'
import WebSocket from 'ws'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/relay-control-client'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client'
import { CloudRelayTransport } from '../../../../src/main/runtime/rpc/transports/relay-transport'
import { RelayPhoneHelloSchema } from '../../../../src/shared/remote-runtime/relay/mobile-relay-phone-protocol'
+1 -1
View File
@@ -15,7 +15,7 @@ import { SignJWT, exportJWK, generateKeyPair, type KeyLike } from 'jose'
import nacl from 'tweetnacl'
import pg from 'pg'
import WebSocket from 'ws'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/relay-control-client'
import { RelayControlClient } from '../../../../src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client'
import { CloudRelayTransport } from '../../../../src/main/runtime/rpc/transports/relay-transport'
import { RelayPhoneHelloSchema } from '../../../../src/shared/remote-runtime/relay/mobile-relay-phone-protocol'
@@ -1,8 +0,0 @@
Exact relay contract snapshots from `027acb4efa2e6b226d40df266b86367423946d62`, `cloud/packages/relay-contract/src/`. Used to exercise the pre-correction strict wire parsers. Do not format or edit these baseline sources.
```text
aba94e108a5cd0f1af8b38875429ad8636d24c43a728273e3df60d9a1a1d1b6d director-messages.ts
bd13b5a694a5d683a5b680c14e46ab33f4ef4a5bfedf040d046b09d540cb4c17 wire-scalars.ts
bc89116f884a2f20a6588f9b91219aa596bc2410d28b499a93a78350def109d5 relay-regions.ts
8fcae470a5fc72f2fcdde9d2f09cd20289c256356dd490484ac1cfa53839fbe4 control-messages.ts
```
@@ -1,146 +0,0 @@
import { z } from 'zod'
import {
Base6432ByteSchema,
Base64Raw24ByteSchema,
Base64Url32ByteSchema,
EpochMsSchema,
GenerationSchema,
OpaqueIdSchema,
PositiveDurationMsSchema,
RelayHostIdSchema
} from './wire-scalars.js'
const AppVersionSchema = z.string().min(1).max(128)
const BoundedCiphertextSchema = z
.string()
.min(1)
.max(16 * 1024)
.regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)
const ConnectionKindSchema = z.enum(['invite', 'resume'])
export const HostHelloSchema = z
.object({
v: z.literal(1),
relayHostId: RelayHostIdSchema,
assignmentEpoch: GenerationSchema,
hostPublicKeyB64: Base6432ByteSchema,
appVersion: AppVersionSchema,
previousGeneration: GenerationSchema.optional(),
controlResumeSecret: Base64Url32ByteSchema.optional()
})
.strict()
export const HostChallengeSchema = z
.object({
challengeId: OpaqueIdSchema,
relayEphemeralPublicKeyB64: Base6432ByteSchema,
nonceB64: Base64Raw24ByteSchema,
ciphertextB64: BoundedCiphertextSchema,
expiresAt: EpochMsSchema
})
.strict()
export const HostChallengeAckSchema = z
.object({ challengeId: OpaqueIdSchema, proofB64: Base6432ByteSchema })
.strict()
// Advertised on the control upgrade rather than in host-hello: HostHelloSchema
// is strict, so a new hello key is refused by every already-deployed cell.
export const RELAY_HOST_CAPABILITIES_HEADER = 'x-orca-host-capabilities'
// The host accepts kind/relayDeviceId on a pendingConns entry. A host that does
// not advertise this parses those entries strictly and would drop the whole ack.
export const RELAY_HOST_CAPABILITY_PENDING_CONN_DETAILS = 'pending-conn-details'
export function parseRelayHostCapabilities(
header: string | string[] | undefined
): ReadonlySet<string> {
const raw = Array.isArray(header) ? header.join(',') : (header ?? '')
return new Set(
raw
.split(',')
.map((token) => token.trim())
.filter((token) => token.length > 0 && token.length <= 64)
.slice(0, 16)
)
}
// kind/relayDeviceId are optional so an entry stays readable by a host that
// predates them; the cell only emits them to a host that advertised support.
const PendingConnectionSchema = z
.object({
connId: OpaqueIdSchema,
connTicket: Base64Url32ByteSchema,
kind: ConnectionKindSchema.optional(),
relayDeviceId: OpaqueIdSchema.optional()
})
.strict()
export const HostHelloAckSchema = z
.object({
v: z.literal(1),
generation: GenerationSchema,
controlResumeSecret: Base64Url32ByteSchema,
leaseExpiresAt: EpochMsSchema,
activeConnIds: z.array(OpaqueIdSchema).max(8),
pendingConns: z.array(PendingConnectionSchema).max(8)
})
.strict()
export const ConnectionOpenSchema = z
.object({
connId: OpaqueIdSchema,
connTicket: Base64Url32ByteSchema,
kind: ConnectionKindSchema,
relayDeviceId: OpaqueIdSchema,
attachDeadlineMs: PositiveDurationMsSchema
})
.strict()
export const HostDataAuthSchema = z
.object({
v: z.literal(1),
connTicket: Base64Url32ByteSchema,
generation: GenerationSchema
})
.strict()
export const InviteCreateSchema = z
.object({ reqId: OpaqueIdSchema, relayDeviceId: OpaqueIdSchema })
.strict()
export const InviteCreatedSchema = z
.object({
reqId: OpaqueIdSchema,
inviteToken: Base64Url32ByteSchema,
expiresAt: EpochMsSchema,
maxAttempts: z.number().int().positive().max(16)
})
.strict()
export const DeviceRevokeSchema = z
.object({ reqId: OpaqueIdSchema, relayDeviceId: OpaqueIdSchema })
.strict()
export const AuthRefreshSchema = z.object({ relayJwt: z.string().min(1).max(8 * 1024) }).strict()
export const DrainSchema = z
.object({
graceMs: z.number().int().nonnegative().max(60 * 60 * 1000),
recovery: z.literal('resolve-director')
})
.strict()
export const HeartbeatSchema = z.object({ t: EpochMsSchema }).strict()
export type HostHello = z.infer<typeof HostHelloSchema>
export type HostChallenge = z.infer<typeof HostChallengeSchema>
export type HostChallengeAck = z.infer<typeof HostChallengeAckSchema>
export type HostHelloAck = z.infer<typeof HostHelloAckSchema>
export type ConnectionOpen = z.infer<typeof ConnectionOpenSchema>
export type HostDataAuth = z.infer<typeof HostDataAuthSchema>
export type InviteCreate = z.infer<typeof InviteCreateSchema>
export type InviteCreated = z.infer<typeof InviteCreatedSchema>
export type DeviceRevoke = z.infer<typeof DeviceRevokeSchema>
export type AuthRefresh = z.infer<typeof AuthRefreshSchema>
export type Drain = z.infer<typeof DrainSchema>
export type Heartbeat = z.infer<typeof HeartbeatSchema>
@@ -1,75 +0,0 @@
import { z } from 'zod'
import {
Base64Url32ByteSchema,
CanonicalHttpsOriginSchema,
EpochMsSchema,
GenerationSchema,
RelayHostIdSchema
} from './wire-scalars.js'
import { RelayRegionSchema } from './relay-regions.js'
const SignedAssignmentLeaseSchema = z.string().min(1).max(8 * 1024)
export const AssignmentRequestSchema = z
.object({
v: z.literal(1),
relayHostId: RelayHostIdSchema,
// Client-declared reconnection; the director verifies it against the
// durable assignment before granting fast-lane admission.
reconnect: z.boolean().optional(),
preferredRegion: RelayRegionSchema.optional()
})
.strict()
export const AssignmentResponseSchema = z
.object({
v: z.literal(1),
cellUrl: CanonicalHttpsOriginSchema,
assignmentEpoch: GenerationSchema,
lease: SignedAssignmentLeaseSchema
})
.strict()
export const ResolveRequestSchema = z
.object({
v: z.literal(1),
relayHostId: RelayHostIdSchema,
resumeToken: Base64Url32ByteSchema
})
.strict()
export const ResolveResponseSchema = z
.object({
v: z.literal(1),
cellUrl: CanonicalHttpsOriginSchema,
assignmentEpoch: GenerationSchema,
leaseExpiresAt: EpochMsSchema
})
.strict()
export const RelayMovedSchema = z
.object({
v: z.literal(1),
cellUrl: CanonicalHttpsOriginSchema,
assignmentEpoch: GenerationSchema
})
.strict()
export function isTrustedNewerMove(input: {
sourceOrigin: string
configuredDirectorOrigin: string
currentAssignmentEpoch: number
move: z.infer<typeof RelayMovedSchema>
}): boolean {
// Why: cells and stale director responses must never redirect a credential-bearing client.
return (
input.sourceOrigin === input.configuredDirectorOrigin &&
input.move.assignmentEpoch > input.currentAssignmentEpoch
)
}
export type AssignmentRequest = z.infer<typeof AssignmentRequestSchema>
export type AssignmentResponse = z.infer<typeof AssignmentResponseSchema>
export type ResolveRequest = z.infer<typeof ResolveRequestSchema>
export type ResolveResponse = z.infer<typeof ResolveResponseSchema>
export type RelayMoved = z.infer<typeof RelayMovedSchema>
@@ -1,71 +0,0 @@
import { z } from 'zod'
export const RELAY_REGIONS = ['us-central1', 'asia-east2'] as const
export const RelayRegionSchema = z.enum(RELAY_REGIONS)
export type RelayRegion = z.infer<typeof RelayRegionSchema>
export const RELAY_DEFAULT_REGION: RelayRegion = 'us-central1'
// Field-name segment for the flat per-region runtime counters, spelled out rather than derived so
// the Terraform side can hold the same literal and a test can compare the two. `satisfies` makes a
// new region a compile error here, which is the point: a region with no segment would silently
// drop out of the region-skew alert's denominators.
export const RELAY_REGION_METRIC_SEGMENTS = {
'us-central1': 'UsCentral1',
'asia-east2': 'AsiaEast2'
} as const satisfies Record<RelayRegion, string>
const RelayProbeOriginSchema = z.string().url().max(2_048).refine(isCanonicalHttpsOrigin)
export const RelayRegionCatalogResponseSchema = z
.object({
v: z.literal(1),
regions: z
.array(
z
.object({
region: RelayRegionSchema,
probeOrigins: z.array(RelayProbeOriginSchema).min(1).max(2)
})
.strict()
)
.max(RELAY_REGIONS.length)
})
.strict()
.superRefine((catalog, context) => {
const regions = new Set<RelayRegion>()
const origins = new Set<string>()
for (const [regionIndex, entry] of catalog.regions.entries()) {
if (regions.has(entry.region)) {
context.addIssue({
code: 'custom',
message: 'duplicate relay region',
path: ['regions', regionIndex, 'region']
})
}
regions.add(entry.region)
for (const [originIndex, origin] of entry.probeOrigins.entries()) {
if (origins.has(origin)) {
context.addIssue({
code: 'custom',
message: 'duplicate relay probe origin',
path: ['regions', regionIndex, 'probeOrigins', originIndex]
})
}
origins.add(origin)
}
}
})
export type RelayRegionCatalogResponse = z.infer<typeof RelayRegionCatalogResponseSchema>
function isCanonicalHttpsOrigin(value: string): boolean {
try {
const url = new URL(value)
return url.protocol === 'https:' && url.origin === value
} catch {
return false
}
}
@@ -1,20 +0,0 @@
import { z } from 'zod'
export const Base64Url32ByteSchema = z.string().regex(/^[A-Za-z0-9_-]{43}$/)
export const Base64Url24ByteSchema = z.string().regex(/^[A-Za-z0-9_-]{32}$/)
export const Base6432ByteSchema = z.string().regex(/^(?:[A-Za-z0-9+/]{4}){10}[A-Za-z0-9+/]{3}=$/)
export const Base64Raw24ByteSchema = z.string().regex(/^(?:[A-Za-z0-9+/]{4}){8}$/)
export const RelayHostIdSchema = z.string().regex(/^[A-Za-z0-9_-]{16}$/)
export const OpaqueIdSchema = z.string().min(1).max(128)
export const EpochMsSchema = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
export const GenerationSchema = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
export const PositiveDurationMsSchema = z.number().int().positive().max(24 * 60 * 60 * 1000)
export const CanonicalHttpsOriginSchema = z.string().max(2048).refine((value) => {
try {
const url = new URL(value)
return url.protocol === 'https:' && url.origin === value && url.pathname === '/'
} catch {
return false
}
}, 'must be a canonical HTTPS origin')
+2 -2
View File
@@ -9,8 +9,8 @@ export const CLI_MAIN_ENTRY_NAMES = [
'skills/bundled-skill-install/bundled-skill-local-host',
'skills/bundled-skill-install/bundled-skill-installation',
'filesystem/macos-tree-clone',
'orcad/orcad-stale-lock-reclaim',
'orcad/orcad-host-identity-reset',
'orcad/instance-lock/orcad-stale-lock-reclaim',
'orcad/profile-state/orcad-host-identity-reset',
'plugins/plugin-artifact-validation',
'plugins/plugin-content-hash',
'plugins/plugin-catalog-release-entry',
+1 -1
View File
@@ -8,7 +8,7 @@
2 src/main/daemon/transport/stream/daemon-stream-backlog-probe.ts
1 src/main/daemon/process-scopes/daemon-user-manager-lifetime.ts
1 src/main/daemon/process-scopes/terminal-scopes.ts
2 src/main/orcad/node-pty-precondition.ts
2 src/main/orcad/native-runtime/node-pty-precondition.ts
1 src/main/pty/process-retirement/posix-pty-process-table.ts
1 src/main/pty/shell-startup/pwsh.ts
2 src/main/pty/shell-startup/zsh-startup-hook-pty-harness.ts
+2 -2
View File
@@ -368,8 +368,8 @@ module.exports = {
'out/main/computer-sidecar.js',
'out/main/parcel-watcher-process-entry.js',
'out/main/orcad/orcad-local-serve-selection-entry.js',
'out/main/orcad/orcad-stale-lock-reclaim.js',
'out/main/orcad/orcad-host-identity-reset.js',
'out/main/orcad/instance-lock/orcad-stale-lock-reclaim.js',
'out/main/orcad/profile-state/orcad-host-identity-reset.js',
'out/main/chunks/**',
'out/renderer/**',
'out/mobile-web/**',
+13 -14
View File
@@ -13,7 +13,6 @@
1 test-no-in-test-import-actual:src/main/linear/issues/linear-description-images.test.ts
1 test-no-in-test-import-actual:src/main/managed-server/host-state/orcad-snapshot-room.test.ts
1 test-no-in-test-import-actual:src/main/omp/omp-session-cwd-lookup.test.ts
1 test-no-in-test-import-actual:src/main/orcad/electron-serve-provider-selection.test.ts
1 test-no-in-test-import-actual:src/main/pty/scrollback/overlay-mirror.test.ts
1 test-no-in-test-import-actual:src/main/runtime/rpc/server/pairing/mobile-pairing-userdata-path.test.ts
1 test-no-in-test-import-actual:src/main/runtime/terminal/artifacts/orca-runtime-files-terminal-artifact-swap-detection.test.ts
@@ -452,11 +451,11 @@
1 test-no-wall-clock:src/main/opencode/status-hooks/overlay-dir-gc.test.ts
2 test-no-wall-clock:src/main/orca-profiles/cloud-auth/profile-cloud-service-connect-overlap.test.ts
2 test-no-wall-clock:src/main/orca-profiles/cloud-auth/profile-cloud-service-sign-out-connect-race.test.ts
2 test-no-wall-clock:src/main/orcad/orcad-artifact-cache-retention.test.ts
1 test-no-wall-clock:src/main/orcad/orcad-artifact-materializer.test.ts
6 test-no-wall-clock:src/main/orcad/orcad-serve-parity.integration.test.ts
1 test-no-wall-clock:src/main/orcad/orcad-stale-lock-reclaim.test.ts
3 test-no-wall-clock:src/main/orcad/orcad-stop-request-shutdown.integration.test.ts
2 test-no-wall-clock:src/main/orcad/artifact-slots/orcad-artifact-cache-retention.test.ts
1 test-no-wall-clock:src/main/orcad/artifact-slots/orcad-artifact-materializer.test.ts
6 test-no-wall-clock:src/main/orcad/testing/serve-lifecycle/orcad-serve-parity.integration.test.ts
1 test-no-wall-clock:src/main/orcad/instance-lock/orcad-stale-lock-reclaim.test.ts
3 test-no-wall-clock:src/main/orcad/host-lifecycle/managed-stop/orcad-stop-request-shutdown.integration.test.ts
1 test-no-wall-clock:src/main/persistence/closed-terminal-tab-write-fence.test.ts
1 test-no-wall-clock:src/main/persistence/profile-state/backup/profile-state-backup-rotation.test.ts
1 test-no-wall-clock:src/main/persistence/profile-state/recovery/profile-state-section-repair.test.ts
@@ -476,7 +475,7 @@
1 test-no-wall-clock:src/main/runtime/agent-session/lifecycle/structured-codex-child-work-runtime.test.ts
2 test-no-wall-clock:src/main/runtime/agent-session/structured-agent-session-held-signal.test.ts
1 test-no-wall-clock:src/main/runtime/agent-session/structured-child-records-switch.test.ts
1 test-no-wall-clock:src/main/runtime/mobile-cloud-relay/mobile-relay-e2ee.integration.test.ts
1 test-no-wall-clock:src/main/runtime/mobile-cloud-relay/testing/mobile-relay-e2ee.integration.test.ts
2 test-no-wall-clock:src/main/runtime/orchestration/mailbox/terminal-pointer/orchestration-codex-real-pty.integration.test.ts
1 test-no-wall-clock:src/main/runtime/push/push-device-registration-persistence.test.ts
1 test-no-wall-clock:src/main/runtime/push/push-registration-rpc.test.ts
@@ -604,18 +603,18 @@
4 test-timeout-needs-reason:src/main/managed-server/lifecycle/orcad-managed-tunnel-transport-real-openssh.test.ts
3 test-timeout-needs-reason:src/main/native-chat/agent-model-catalog/agent-model-catalog-probe-runner.test.ts
1 test-timeout-needs-reason:src/main/notebook/notebook-kernel.test.ts
1 test-timeout-needs-reason:src/main/orcad/orcad-bundle-native-load-order.test.ts
1 test-timeout-needs-reason:src/main/orcad/orcad-packaged-node-pty.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/orcad-packaged-structured-chat.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/orcad-serve-parity.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/orcad-stop-request-shutdown.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/orcad-windows-conpty-breakaway.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/native-runtime/orcad-bundle-native-load-order.test.ts
1 test-timeout-needs-reason:src/main/orcad/native-runtime/orcad-packaged-node-pty.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/testing/structured-chat/orcad-packaged-structured-chat.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/testing/serve-lifecycle/orcad-serve-parity.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/host-lifecycle/managed-stop/orcad-stop-request-shutdown.integration.test.ts
1 test-timeout-needs-reason:src/main/orcad/native-runtime/orcad-windows-conpty-breakaway.integration.test.ts
1 test-timeout-needs-reason:src/main/persistence/applying-settings/persistence-source-control-ai-migration.test.ts
2 test-timeout-needs-reason:src/main/providers/agent-foreground-process-git-bash.win32.test.ts
1 test-timeout-needs-reason:src/main/providers/local-pty/local-pty-child-process-verdict.test.ts
2 test-timeout-needs-reason:src/main/providers/startup-line-typed-length.live-shell.test.ts
5 test-timeout-needs-reason:src/main/pty/process-retirement/node-pty-master-fd-retirement.test.ts
1 test-timeout-needs-reason:src/main/runtime/mobile-cloud-relay/mobile-relay-e2ee.integration.test.ts
1 test-timeout-needs-reason:src/main/runtime/mobile-cloud-relay/testing/mobile-relay-e2ee.integration.test.ts
1 test-timeout-needs-reason:src/main/runtime/rpc/server/orchestration-cli-subprocess.test.ts
2 test-timeout-needs-reason:src/main/runtime/rpc/server/remote-runtime-request-connection.integration.test.ts
1 test-timeout-needs-reason:src/main/runtime/session-construction/agent-session/remote-agent-session-host-authority.integration.test.ts
+1 -1
View File
@@ -47,7 +47,7 @@
5 src/main/persistence/restoring-sessions/session-owner-fields.ts
12 src/main/persistence/restoring-sessions/session-owner-removal.ts
2 src/main/persistence/restoring-sessions/workspace-pane-normalization.ts
4 src/main/persistence/terminal-topology/terminal-topology-membership.ts
4 src/main/persistence/terminal-topology/pane-ownership/terminal-topology-membership.ts
1 src/main/persistence/tracking-repos/project-group-operations.ts
4 src/main/persistence/tracking-repos/repo-worktree-pruning.ts
3 src/main/persistence/tracking-repos/worktree-identity-migration.ts
+35 -35
View File
@@ -342,39 +342,39 @@
2 src/main/orca-profiles/storage/new-profile-state.ts
5 src/main/orca-profiles/storage/profile-legacy-state-import.ts
2 src/main/orcad/launcher.ts
7 src/main/orcad/node-pty-prebuilt-slot.ts
2 src/main/orcad/node-pty-precondition.ts
2 src/main/orcad/orcad-agent-browser-binary.ts
1 src/main/orcad/orcad-app-paths.ts
1 src/main/orcad/orcad-artifact-identity.ts
2 src/main/orcad/orcad-artifact-materializer.ts
12 src/main/orcad/orcad-bundled-runtime.ts
2 src/main/orcad/orcad-cli-launcher.ts
1 src/main/orcad/orcad-command-arguments.ts
1 src/main/orcad/orcad-completed-stop-receipt.ts
2 src/main/orcad/orcad-daemon-slot-pins.ts
2 src/main/orcad/orcad-data-root-locality.ts
3 src/main/orcad/orcad-data-root-privacy.ts
4 src/main/orcad/orcad-host-account-launch-env-store.ts
1 src/main/orcad/orcad-host-adapters.ts
1 src/main/orcad/orcad-host-identity-reset.ts
2 src/main/orcad/orcad-idle-stop-record.ts
3 src/main/orcad/orcad-instance-lock-hold.ts
16 src/main/orcad/orcad-instance-lock-reclaim.ts
4 src/main/orcad/orcad-instance-lock.ts
7 src/main/orcad/orcad-local-serve-selection.ts
1 src/main/orcad/orcad-lock-clone-machine.ts
1 src/main/orcad/orcad-managed-stop-cancellation.ts
3 src/main/orcad/orcad-managed-stop-decision.ts
2 src/main/orcad/orcad-managed-stop-request.ts
4 src/main/orcad/orcad-plaintext-credential-migration.ts
5 src/main/orcad/orcad-process-start-time.ts
11 src/main/orcad/orcad-secret-key-record.ts
3 src/main/orcad/orcad-stale-lock-reclaim.ts
1 src/main/orcad/orcad-stop-request-listener.ts
1 src/main/orcad/orcad-wsl-holder-release.ts
2 src/main/orcad/orcad-wsl-host-claude-profile-refresh.ts
1 src/main/orcad/serve-profile-ssh-targets.ts
7 src/main/orcad/native-runtime/node-pty-prebuilt-slot.ts
2 src/main/orcad/native-runtime/node-pty-precondition.ts
2 src/main/orcad/browser-providers/orcad-agent-browser-binary.ts
1 src/main/orcad/host-runtime/orcad-app-paths.ts
1 src/main/orcad/artifact-slots/orcad-artifact-identity.ts
2 src/main/orcad/artifact-slots/orcad-artifact-materializer.ts
12 src/main/orcad/runtime-launch/orcad-bundled-runtime.ts
2 src/main/orcad/serve-startup/orcad-cli-launcher.ts
1 src/main/orcad/serve-startup/orcad-command-arguments.ts
1 src/main/orcad/host-lifecycle/managed-stop/orcad-completed-stop-receipt.ts
2 src/main/orcad/artifact-slots/orcad-daemon-slot-pins.ts
2 src/main/orcad/instance-lock/orcad-data-root-locality.ts
3 src/main/orcad/instance-lock/orcad-data-root-privacy.ts
4 src/main/orcad/account-launch/orcad-host-account-launch-env-store.ts
1 src/main/orcad/host-runtime/orcad-host-adapters.ts
1 src/main/orcad/profile-state/orcad-host-identity-reset.ts
2 src/main/orcad/host-lifecycle/idle-exit/orcad-idle-stop-record.ts
3 src/main/orcad/instance-lock/orcad-instance-lock-hold.ts
16 src/main/orcad/instance-lock/orcad-instance-lock-reclaim.ts
4 src/main/orcad/instance-lock/orcad-instance-lock.ts
7 src/main/orcad/serve-startup/orcad-local-serve-selection.ts
1 src/main/orcad/instance-lock/orcad-lock-clone-machine.ts
1 src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-cancellation.ts
3 src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-decision.ts
2 src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-request.ts
4 src/main/orcad/credentials/orcad-plaintext-credential-migration.ts
5 src/main/orcad/instance-lock/orcad-process-start-time.ts
11 src/main/orcad/credentials/orcad-secret-key-record.ts
3 src/main/orcad/instance-lock/orcad-stale-lock-reclaim.ts
1 src/main/orcad/host-lifecycle/managed-stop/orcad-stop-request-listener.ts
1 src/main/orcad/instance-lock/orcad-wsl-holder-release.ts
2 src/main/orcad/account-launch/orcad-wsl-host-claude-profile-refresh.ts
1 src/main/orcad/profile-state/serve-profile-ssh-targets.ts
6 src/main/persistence/atomic-snapshot-writer.ts
5 src/main/persistence/loading-store/user-data-path.ts
4 src/main/persistence/migrating-orcad-catalog/blob-transfer/orcad-migration-blob-installers.ts
@@ -475,8 +475,8 @@
1 src/main/runtime/client/navigation/desktop-chat-creation-history.ts
9 src/main/runtime/host-instance-identity.ts
4 src/main/runtime/hosts/platform-probe/host-descriptor.ts
5 src/main/runtime/mobile-cloud-relay/relay-region-preference.ts
2 src/main/runtime/mobile-cloud-relay/relay-revoke-outbox.ts
5 src/main/runtime/mobile-cloud-relay/region-selection/relay-region-preference.ts
2 src/main/runtime/mobile-cloud-relay/pairing/relay-revoke-outbox.ts
1 src/main/runtime/orchestration/db/runtime-orchestration-database-access.ts
2 src/main/runtime/push/push-unregister-outbox.ts
1 src/main/runtime/rpc/methods/mobile-delivery/bundled-mobile-web-bundle.ts
+2 -2
View File
@@ -27,8 +27,8 @@
1 src/main/ipc/worktree-logic.ts
1 src/main/network/macos-tailscale-dns-diagnostic.ts
1 src/main/opencode/status-hooks/legacy-plugin-acl-retry.ts
2 src/main/orcad/node-pty-precondition.ts
1 src/main/orcad/orcad-data-root-privacy.ts
2 src/main/orcad/native-runtime/node-pty-precondition.ts
1 src/main/orcad/instance-lock/orcad-data-root-privacy.ts
2 src/main/persistence/profile-state/access/profile-state-access-identity.ts
1 src/main/persistence/profile-state/recovery/profile-state-recovery-copy.ts
1 src/main/plugins/catalog/plugin-private-marketplace-ssh-shim.cjs
+5 -5
View File
@@ -38,10 +38,10 @@
1 src/main/native-chat/agent-session-wire/recovery/structured-agent-session-usage-limit-continue.ts
1 src/main/native-chat/agent-session-wire/termination/structured-agent-session-idle-sweep.ts
1 src/main/notifications/desktop-presence-reporter.ts
1 src/main/orcad/orcad-browser-install-park.ts
1 src/main/orcad/orcad-event-loop-watchdog.ts
1 src/main/orcad/orcad-lock-clone-machine.ts
1 src/main/orcad/orcad-stop-request-listener.ts
1 src/main/orcad/browser-providers/orcad-browser-install-park.ts
1 src/main/orcad/diagnostics/orcad-event-loop-watchdog.ts
1 src/main/orcad/instance-lock/orcad-lock-clone-machine.ts
1 src/main/orcad/host-lifecycle/managed-stop/orcad-stop-request-listener.ts
1 src/main/plugins/catalog/plugin-auto-updater.ts
1 src/main/plugins/catalog/plugin-kill-list-service.ts
1 src/main/plugins/installation/plugin-git-repository.ts
@@ -49,7 +49,7 @@
1 src/main/rate-limits/service/service-polling.ts
1 src/main/runtime/agent-state-rules/agent-state-rules-live-update.ts
1 src/main/runtime/mobile-cloud-relay/desktop-relay-service.ts
3 src/main/runtime/mobile-cloud-relay/relay-control-liveness.ts
3 src/main/runtime/mobile-cloud-relay/control-channel/relay-control-liveness.ts
1 src/main/runtime/rpc/methods/orchestration/messaging/check-run.ts
1 src/main/runtime/rpc/mobile/mobile-socket-wiring.ts
1 src/main/runtime/rpc/transports/websocket/remote-runtime-server-heartbeat.ts
+10 -25
View File
@@ -2182,21 +2182,19 @@
"providers": ["local-daemon", "ssh-daemon", "paired-runtime"],
"coveredPlatforms": ["macos"],
"coveredProviders": ["local-daemon"],
"coverageNotes": "Audit 3959 retires the whole session.test.ts driver (27 authored / 33 finite cases): startup/echo filtering, readiness input gates, ownership confirmation, detach authority, and termination retry/exit ordering alarms are intentionally lost. No equivalent replacement or fresh runtime validation is claimed. Audit1627 removes low-value mocked daemon projections, scalar tables and duplicate terminal examples without equivalent replacement coverage. Per-source reviews record retained terminal content preservation, process ownership refusal and recovery boundaries together with injected/native/remote limits. Affected historical receipts are retired; gates without active current evidence are downgraded. Historical scope before this audit: Real TerminalHost, Session, and subprocess wrapper with injected native I/O failures and mocked OS signals. Local non-daemon and SSH-relay implementations are unaffected; daemon consumers on SSH, WSL, paired runtimes, and mobile retain host-owned semantics. Live Linux/Windows/WSL and remote runs remain gaps. No git or folder-workspace assumptions. The fault-injection suite also runs with simulated darwin/linux/win32 platform branches; these do not constitute native OS coverage. Native macOS coverage now proves shell exit and PTY master-fd closure, input/output round trips, and teardown of a paused producer for both graceful and immediate cleanup. Windows single-close/job escalation and pre-listener output/status are fault-injected contracts. Audit1302: src/main/daemon/terminal-host-teardown-recreate.test.ts: Fake subprocess handles synthesize exits via real40ms/30s timers or manual exit callback, with descendant retirement mocked away; assertions inspect isNew/refusal/spawn counts. No real subprocess/PTY teardown/recreation or owned-tree retention boundary. Lose artificial teardown/attach/shutdown/cancellation scheduling alarms; no equivalent replacement. Reduced selectors require fresh validation; prior full-suite receipts do not validate removed or changed coverage. No equivalent replacement or physical-provider claim.",
"coverageNotes": "Audit 3959 retires the whole session.test.ts driver (27 authored / 33 finite cases): startup/echo filtering, readiness input gates, ownership confirmation, detach authority, and termination retry/exit ordering alarms are intentionally lost. No equivalent replacement or fresh runtime validation is claimed. Audit1627 removes low-value mocked daemon projections, scalar tables and duplicate terminal examples without equivalent replacement coverage. Per-source reviews record retained terminal content preservation, process ownership refusal and recovery boundaries together with injected/native/remote limits. Affected historical receipts are retired; gates without active current evidence are downgraded. Historical scope before this audit: Real TerminalHost, Session, and subprocess wrapper with injected native I/O failures and mocked OS signals. Local non-daemon and SSH-relay implementations are unaffected; daemon consumers on SSH, WSL, paired runtimes, and mobile retain host-owned semantics. Live Linux/Windows/WSL and remote runs remain gaps. No git or folder-workspace assumptions. The fault-injection suite also runs with simulated darwin/linux/win32 platform branches; these do not constitute native OS coverage. Archived native macOS results previously exercised shell exit and PTY master-fd closure, input/output round trips, and teardown of a paused producer; that suite is now retired without replacement. Windows single-close/job escalation and pre-listener output/status are fault-injected contracts. Audit1302: src/main/daemon/terminal-host-teardown-recreate.test.ts: Fake subprocess handles synthesize exits via real40ms/30s timers or manual exit callback, with descendant retirement mocked away; assertions inspect isNew/refusal/spawn counts. No real subprocess/PTY teardown/recreation or owned-tree retention boundary. Lose artificial teardown/attach/shutdown/cancellation scheduling alarms; no equivalent replacement. Reduced selectors require fresh validation; prior full-suite receipts do not validate removed or changed coverage. No equivalent replacement or physical-provider claim.\nOrcad folder cleanup intentionally retires the Cartesian native failed-I/O test under repository test policy, without equivalent replacement. Remaining selectors retain their narrower scope. Dated evidenceRuns remain historical and do not validate this changed selector.",
"motivatingLinks": ["docs/terminal-daemon-session-leak-investigation.md"],
"invariant": "I/O errors must not establish physical exit or disable termination of an owned PTY. Session and native handle disposal require the exit event.",
"oracle": "Inject write and resize failures, require graceful and forced signals to reach the native owner, keep producer resume available, suppress repeated failed I/O, deliver output and exit, and suppress signals after exit. Across 32 create/close cycles per failure, retain each session before exit and release its native handle and emulator exactly once afterwards. Mark physical exit before notifying listeners; reentrant kill/forceKill/signal from those listeners must never signal the retired PID. A native POSIX test performs input/output and resize, pauses the producer, injects each I/O failure, then gracefully or immediately closes 16 real shells; require ESRCH for each child PID and EBADF for each PTY master fd.",
"oracle": "Inject write and resize failures, require graceful and forced signals to reach the native owner, keep producer resume available, suppress repeated failed I/O, deliver output and exit, and suppress signals after exit. Across 32 create/close cycles per failure, retain each session before exit and release its native handle and emulator exactly once afterwards. Mark physical exit before notifying listeners; reentrant kill/forceKill/signal from those listeners must never signal the retired PID. The former native POSIX shell/PID/fd oracle is retired without replacement.",
"commands": [
"pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-cleanup.test.ts",
"pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-cleanup.test.ts src/main/daemon/pty-subprocess/testing/pty-subprocess-handle-lifecycle.test.ts src/main/daemon/terminal-host/testing/terminal-host-session-reaping-leak.test.ts src/main/daemon/terminal-host/testing/terminal-session-teardown.test.ts",
"pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts"
"pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-cleanup.test.ts src/main/daemon/pty-subprocess/testing/pty-subprocess-handle-lifecycle.test.ts src/main/daemon/terminal-host/testing/terminal-host-session-reaping-leak.test.ts src/main/daemon/terminal-host/testing/terminal-session-teardown.test.ts"
],
"testFiles": [
"src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-cleanup.test.ts",
"src/main/daemon/pty-subprocess/testing/pty-subprocess-handle-lifecycle.test.ts",
"src/main/daemon/terminal-host/testing/terminal-host-session-reaping-leak.test.ts",
"src/main/daemon/terminal-host/testing/terminal-session-teardown.test.ts",
"src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts"
"src/main/daemon/terminal-host/testing/terminal-session-teardown.test.ts"
],
"assertionRefs": [
{
@@ -2207,10 +2205,6 @@
"suppresses repeated native I/O failures while still delivering output and exit",
"blocks reentrant termination from an exit listener after I/O failure"
]
},
{
"file": "src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts",
"assertions": ["reaps real shells and master fds after %s failure (immediate=%s)"]
}
],
"evidenceRuns": [
@@ -2223,16 +2217,6 @@
"durationSeconds": 3.71,
"summary": "32 tests passed with 4 Windows-only cases skipped; simulated macOS/Linux/Windows branches include 192 failed-I/O create/close cycles and exit-listener reentrancy.",
"currentCommand": "pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-cleanup.test.ts"
},
{
"date": "2026-09-07",
"runner": "local",
"platform": "macos",
"command": "pnpm test src/main/daemon/pty-subprocess-io-failure-native.test.ts",
"result": "passed",
"durationSeconds": 2.52,
"summary": "Four native cases pass across 16 real shells, including input/output, pause before teardown, confirmed PID absence, and closed PTY master fds.",
"currentCommand": "pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts"
}
],
"runtimeBudget": {
@@ -2257,10 +2241,11 @@
"knownGaps": [
"Audit1627 removes low-value mocked daemon projections, scalar tables and duplicate terminal examples without equivalent replacement coverage. Per-source reviews record retained terminal content preservation, process ownership refusal and recovery boundaries together with injected/native/remote limits. Affected historical receipts are retired; gates without active current evidence are downgraded.",
"Fault injection proves a leak mechanism, not causality for the historical 427-session incident.",
"Real Linux/Windows/WSL, remote, startup-close, login-wrapper descendants, and multi-day load evidence remain outstanding. Native tests inject synchronous I/O errors; they do not model every asynchronous node-pty pipe failure.",
"Real Linux/Windows/WSL, remote, startup-close, login-wrapper descendants, and multi-day load evidence remain outstanding. The archived native tests injected synchronous I/O errors; they did not model every asynchronous node-pty pipe failure. No active native-shell coverage remains after their retirement.",
"No output throughput change or interactive latency benchmark is included.",
"Audit1302: src/main/daemon/terminal-host-teardown-recreate.test.ts: Fake subprocess handles synthesize exits via real40ms/30s timers or manual exit callback, with descendant retirement mocked away; assertions inspect isNew/refusal/spawn counts. No real subprocess/PTY teardown/recreation or owned-tree retention boundary. Lose artificial teardown/attach/shutdown/cancellation scheduling alarms; no equivalent replacement. Reduced selectors require fresh validation; prior full-suite receipts do not validate removed or changed coverage. No equivalent replacement or physical-provider claim.",
"Audit1302 retired the complete dated receipt after source coverage changed. Its result does not validate the reduced selector. Original receipt verbatim:\n{\n \"date\": \"2026-09-07\",\n \"runner\": \"local\",\n \"platform\": \"macos\",\n \"command\": \"pnpm test src/main/daemon/pty-subprocess-io-failure-cleanup.test.ts src/main/daemon/pty-subprocess-handle-lifecycle.test.ts src/main/daemon/terminal-host-session-reaping-leak.test.ts src/main/daemon/terminal-host-teardown-recreate.test.ts src/main/daemon/terminal-session-teardown.test.ts src/main/daemon/session.test.ts\",\n \"result\": \"passed\",\n \"durationSeconds\": 0.617,\n \"summary\": \"136 tests passed across six files; failed-I/O cycle tests cover 64 closures.\"\n }"
"Audit1302 retired the complete dated receipt after source coverage changed. Its result does not validate the reduced selector. Original receipt verbatim:\n{\n \"date\": \"2026-09-07\",\n \"runner\": \"local\",\n \"platform\": \"macos\",\n \"command\": \"pnpm test src/main/daemon/pty-subprocess-io-failure-cleanup.test.ts src/main/daemon/pty-subprocess-handle-lifecycle.test.ts src/main/daemon/terminal-host-session-reaping-leak.test.ts src/main/daemon/terminal-host-teardown-recreate.test.ts src/main/daemon/terminal-session-teardown.test.ts src/main/daemon/session.test.ts\",\n \"result\": \"passed\",\n \"durationSeconds\": 0.617,\n \"summary\": \"136 tests passed across six files; failed-I/O cycle tests cover 64 closures.\"\n }",
"Orcad owner layout retires this native test receipt without replacement. Original receipt verbatim:\n{\n \"date\": \"2026-09-07\",\n \"runner\": \"local\",\n \"platform\": \"macos\",\n \"command\": \"pnpm test src/main/daemon/pty-subprocess-io-failure-native.test.ts\",\n \"result\": \"passed\",\n \"durationSeconds\": 2.52,\n \"summary\": \"Four native cases pass across 16 real shells, including input/output, pause before teardown, confirmed PID absence, and closed PTY master fds.\",\n \"currentCommand\": \"pnpm test src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts\"\n }"
],
"demotionRule": "Keep experimental; investigate any lost cleanup signal, premature exit, or unexplained flake."
},
@@ -6193,7 +6178,7 @@
"commands": [
"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/terminal/surface/orca-runtime-terminal-close-continuity.test.ts",
"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/construction/orca-runtime.test.ts",
"pnpm dlx node@24 ./node_modules/vitest/vitest.mjs run --config config/vitest.config.ts src/main/agent-hooks/server/testing/authority/server-pane-authority.test.ts src/main/ipc/agent-hooks.test.ts src/main/ipc/agent-pane-authority-ownership.test.ts src/main/persistence/terminal-topology/persistence-pane-identity-migration.test.ts src/main/persistence/terminal-topology/persistence-pty-binding-reconciliation.test.ts src/renderer/src/store/slices/agent-status/agent-pane-authority.test.ts src/renderer/src/store/terminals/terminal-pane-detach-agent-identity.test.ts src/renderer/src/store/terminals/terminal-tab-retirement-store.test.ts src/renderer/src/components/shared/kill-all-terminal-surfaces.test.ts",
"pnpm dlx node@24 ./node_modules/vitest/vitest.mjs run --config config/vitest.config.ts src/main/agent-hooks/server/testing/authority/server-pane-authority.test.ts src/main/ipc/agent-hooks.test.ts src/main/ipc/agent-pane-authority-ownership.test.ts src/main/persistence/restoring-sessions/persistence-pane-identity-migration.test.ts src/main/persistence/loading-store/terminal-bindings/persistence-pty-binding-reconciliation.test.ts src/renderer/src/store/slices/agent-status/agent-pane-authority.test.ts src/renderer/src/store/terminals/terminal-pane-detach-agent-identity.test.ts src/renderer/src/store/terminals/terminal-tab-retirement-store.test.ts src/renderer/src/components/shared/kill-all-terminal-surfaces.test.ts",
"pnpm exec vitest run --config config/vitest.config.ts src/main/pty/process-retirement/pty-descendant-termination.test.ts src/main/daemon/terminal-host/testing/terminal-host.test.ts src/main/providers/local-pty/local-pty-provider-shutdown.test.ts src/main/runtime/workspaces/removal/worktree-teardown.test.ts",
"pnpm run test:e2e -- tests/e2e/terminal-tab-close-restart-persistence.spec.ts --workers=1",
"pnpm run test:e2e -- tests/e2e/terminal-parked-close-retirement.spec.ts --workers=1",
@@ -6207,8 +6192,8 @@
"src/main/agent-hooks/server/testing/authority/server-pane-authority.test.ts",
"src/main/ipc/agent-hooks.test.ts",
"src/main/ipc/agent-pane-authority-ownership.test.ts",
"src/main/persistence/terminal-topology/persistence-pane-identity-migration.test.ts",
"src/main/persistence/terminal-topology/persistence-pty-binding-reconciliation.test.ts",
"src/main/persistence/restoring-sessions/persistence-pane-identity-migration.test.ts",
"src/main/persistence/loading-store/terminal-bindings/persistence-pty-binding-reconciliation.test.ts",
"src/main/pty/process-retirement/pty-descendant-termination.test.ts",
"src/main/daemon/terminal-host/testing/terminal-host.test.ts",
"src/main/providers/local-pty/local-pty-provider-shutdown.test.ts",
+74 -113
View File
@@ -180,7 +180,6 @@
"config/scripts/desktop-distribution/linux/package-linux-formats-appimage.test.mjs": 624,
"config/scripts/desktop-distribution/linux/package-linux-formats.test.mjs": 282,
"config/scripts/desktop-distribution/runtime-verification/packaged-node-pty-prebuild-prune.test.mjs": 74,
"config/scripts/orcad-distribution/template/packaged-orcad-browser.test.mjs": 407,
"config/scripts/desktop-distribution/runtime-verification/packaged-process-host.test.mjs": 537,
"config/scripts/desktop-distribution/runtime-verification/packaged-repository-input-exclusion.test.mjs": 222,
"config/scripts/desktop-distribution/runtime-verification/packaged-source-map-prune.test.mjs": 73,
@@ -1553,7 +1552,6 @@
"src/main/daemon/pty-subprocess/testing/pty-subprocess-foreground-identity.test.ts": 818,
"src/main/daemon/pty-subprocess/testing/pty-subprocess-handle-lifecycle.test.ts": 449,
"src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-cleanup.test.ts": 1127,
"src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts": 3285,
"src/main/daemon/pty-subprocess/testing/pty-subprocess-spawn-file-foreground.test.ts": 528,
"src/main/daemon/pty-subprocess/testing/pty-subprocess-windows-shell-launch.test.ts": 459,
"src/main/daemon/pty-subprocess/testing/pty-subprocess.test.ts": 431,
@@ -2460,46 +2458,40 @@
"src/main/orca-profiles/project-transfer/profile-project-transfer-migration.test.ts": 1642,
"src/main/orca-profiles/project-transfer/profile-project-transfer.test.ts": 1456,
"src/main/orca-profiles/profile-telemetry-consent-seed.test.ts": 536,
"src/main/orcad/electron-serve-provider-selection.test.ts": 554,
"src/main/orcad/electron-sidecar-tab-registry.test.ts": 105,
"src/main/orcad/external-chromium-browser-session.test.ts": 152,
"src/main/orcad/node-pty-prebuilt-slot.test.ts": 185,
"src/main/orcad/node-pty-precondition.test.ts": 477,
"src/main/orcad/orcad-agent-session-claim-signer.test.ts": 64,
"src/main/orcad/orcad-app-paths.test.ts": 45,
"src/main/orcad/orcad-artifact-cache-retention.test.ts": 301,
"src/main/orcad/orcad-artifact-materializer.test.ts": 1129,
"src/main/orcad/browser-providers/electron/electron-sidecar-tab-registry.test.ts": 105,
"src/main/orcad/browser-providers/chromium/external-chromium-browser-session.test.ts": 152,
"src/main/orcad/native-runtime/node-pty-prebuilt-slot.test.ts": 185,
"src/main/orcad/native-runtime/node-pty-precondition.test.ts": 477,
"src/main/orcad/host-runtime/orcad-app-paths.test.ts": 45,
"src/main/orcad/artifact-slots/orcad-artifact-cache-retention.test.ts": 301,
"src/main/orcad/artifact-slots/orcad-artifact-materializer.test.ts": 1129,
"src/main/orcad/orcad-bind-address.test.ts": 41,
"src/main/orcad/orcad-browser-install-park.test.ts": 131,
"src/main/orcad/orcad-browser-provider.test.ts": 479,
"src/main/orcad/orcad-bundle-native-load-order.test.ts": 3555,
"src/main/orcad/orcad-chat-restart-offer.test.ts": 3691,
"src/main/orcad/orcad-cli-launcher.integration.test.ts": 390,
"src/main/orcad/orcad-cli-launcher.test.ts": 232,
"src/main/orcad/browser-providers/orcad-browser-provider.test.ts": 479,
"src/main/orcad/native-runtime/orcad-bundle-native-load-order.test.ts": 3555,
"src/main/orcad/serve-startup/orcad-cli-launcher.integration.test.ts": 390,
"src/main/orcad/serve-startup/orcad-cli-launcher.test.ts": 232,
"src/main/orcad/orcad-cli-orchestration.integration.test.ts": 214,
"src/main/orcad/orcad-forked-child-paths.test.ts": 337,
"src/main/orcad/orcad-help.integration.test.ts": 5016,
"src/main/orcad/orcad-idle-exit-monitor.test.ts": 106,
"src/main/orcad/orcad-instance-lock.test.ts": 315,
"src/main/orcad/orcad-launcher-isolation.integration.test.ts": 617,
"src/main/orcad/orcad-lifecycle-host.test.ts": 407,
"src/main/orcad/orcad-managed-idle-exit-chat-provider.test.ts": 2062,
"src/main/orcad/orcad-managed-idle-exit.test.ts": 180,
"src/main/orcad/orcad-managed-stop-cancel-race.test.ts": 218,
"src/main/orcad/orcad-managed-stop-cancellation.test.ts": 285,
"src/main/orcad/orcad-managed-stop-identity.test.ts": 270,
"src/main/orcad/orcad-managed-stop.test.ts": 1726,
"src/main/orcad/orcad-observability.test.ts": 187,
"src/main/orcad/orcad-packaged-node-pty.integration.test.ts": 78,
"src/main/orcad/orcad-packaged-structured-chat.integration.test.ts": 448,
"src/main/orcad/orcad-plaintext-credential-migration.test.ts": 223,
"src/main/orcad/orcad-process-start-time.test.ts": 77,
"src/main/orcad/orcad-secret-store.test.ts": 2281,
"src/main/orcad/orcad-serve-parity.integration.test.ts": 280,
"src/main/orcad/orcad-stale-lock-reclaim.test.ts": 258,
"src/main/orcad/orcad-startup-qualification.test.ts": 102,
"src/main/orcad/orcad-stop-request-shutdown.integration.test.ts": 293,
"src/main/orcad/orcad-windows-conpty-breakaway.integration.test.ts": 79,
"src/main/orcad/serve-startup/orcad-help.integration.test.ts": 5016,
"src/main/orcad/host-lifecycle/idle-exit/orcad-idle-exit-monitor.test.ts": 106,
"src/main/orcad/instance-lock/orcad-instance-lock.test.ts": 315,
"src/main/orcad/runtime-launch/orcad-launcher-isolation.integration.test.ts": 617,
"src/main/orcad/host-lifecycle/orcad-lifecycle-host.test.ts": 407,
"src/main/orcad/host-lifecycle/idle-exit/orcad-managed-idle-exit.test.ts": 180,
"src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-cancel-race.test.ts": 218,
"src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-cancellation.test.ts": 285,
"src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-identity.test.ts": 270,
"src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop.test.ts": 1726,
"src/main/orcad/diagnostics/orcad-observability.test.ts": 187,
"src/main/orcad/native-runtime/orcad-packaged-node-pty.integration.test.ts": 78,
"src/main/orcad/testing/structured-chat/orcad-packaged-structured-chat.integration.test.ts": 448,
"src/main/orcad/credentials/orcad-plaintext-credential-migration.test.ts": 223,
"src/main/orcad/instance-lock/orcad-process-start-time.test.ts": 77,
"src/main/orcad/credentials/orcad-secret-store.test.ts": 2281,
"src/main/orcad/testing/serve-lifecycle/orcad-serve-parity.integration.test.ts": 280,
"src/main/orcad/instance-lock/orcad-stale-lock-reclaim.test.ts": 258,
"src/main/orcad/runtime-launch/orcad-startup-qualification.test.ts": 102,
"src/main/orcad/host-lifecycle/managed-stop/orcad-stop-request-shutdown.integration.test.ts": 293,
"src/main/orcad/native-runtime/orcad-windows-conpty-breakaway.integration.test.ts": 79,
"src/main/persistence/preferences/persistence-onboarding-language-cohort.test.ts": 1760,
"src/main/persistence/applying-settings/persistence-automation-extra-agent-args.test.ts": 2268,
"src/main/persistence/applying-settings/persistence-automation-mode-precondition.test.ts": 1595,
@@ -2526,7 +2518,6 @@
"src/main/persistence/loading-store/terminal-bindings/reused-terminal-id-unbind.test.ts": 312,
"src/main/persistence/loading-store/profile-writing/state-write-round-trip.test.ts": 1983,
"src/main/persistence/loading-store/workspace-sessions/store-host-partition-before-unload.test.ts": 1670,
"src/main/persistence/loading-store/terminal-bindings/terminal-close-async-durability.test.ts": 5719,
"src/main/persistence/loading-store/workspace-sessions/workspace-session-terminal-binding-replay.test.ts": 95,
"src/main/persistence/loading-store/worktree-metadata/worktree-meta-write-normalization.test.ts": 127,
"src/main/persistence/migrating-orcad-catalog/blob-transfer/orcad-migration-blob-staging.test.ts": 466,
@@ -2595,43 +2586,39 @@
"src/main/persistence/restoring-sessions/workspace-pane-normalization-index.test.ts": 466,
"src/main/persistence/runtime-authored-workspace-session-fields.test.ts": 64,
"src/main/persistence/scheduling-automations/automation-run-operations.test.ts": 151,
"src/main/persistence/terminal-topology/closed-pane-binding-fence.test.ts": 289,
"src/main/persistence/terminal-topology/duplicate-pty-pane-repair.test.ts": 2087,
"src/main/persistence/terminal-topology/editor-renames-across-partitions.test.ts": 526,
"src/main/persistence/terminal-topology/open-in-new-group-layout-apply.test.ts": 1943,
"src/main/persistence/terminal-topology/pane-last-grid.test.ts": 5642,
"src/main/persistence/terminal-topology/persistence-closed-pane-binding-fence.test.ts": 1926,
"src/main/persistence/terminal-topology/persistence-cross-host-pane-identity.test.ts": 1744,
"src/main/persistence/terminal-topology/persistence-empty-root-layout-load.test.ts": 1841,
"src/main/persistence/terminal-topology/persistence-layout-binding-recovery.test.ts": 1835,
"src/main/persistence/terminal-topology/persistence-pane-alias-selective-saves.test.ts": 1961,
"src/main/persistence/terminal-topology/persistence-pane-identity-migration.test.ts": 5772,
"src/main/persistence/terminal-topology/persistence-pty-binding-leaf-tab-resolution.test.ts": 1996,
"src/main/persistence/terminal-topology/persistence-pty-binding-reconciliation.test.ts": 1898,
"src/main/persistence/terminal-topology/persistence-runtime-admitted-terminal-membership.test.ts": 2143,
"src/main/persistence/terminal-topology/persistence-split-pane-incarnation.test.ts": 1790,
"src/main/persistence/terminal-topology/persistence-ssh-pending-pty-kill.test.ts": 1776,
"src/main/persistence/terminal-topology/persistence-ssh-remote-cli-control-migration.test.ts": 1738,
"src/main/persistence/terminal-topology/persistence-ssh-remote-pty-binding-replay.test.ts": 1853,
"src/main/persistence/terminal-topology/persistence-ssh-remote-pty-leases.test.ts": 2079,
"src/main/persistence/terminal-topology/persistence-tab-terminal-pane-binding-load.test.ts": 1795,
"src/main/persistence/terminal-topology/terminal-close-write-failure-store.test.ts": 2870,
"src/main/persistence/terminal-topology/terminal-close-write-failure-switch-off.test.ts": 2027,
"src/main/persistence/terminal-topology/pane-ownership/duplicate-pty-pane-repair.test.ts": 2087,
"src/main/persistence/terminal-topology/command-application/editor-renames-across-partitions.test.ts": 526,
"src/main/persistence/terminal-topology/command-application/open-in-new-group-layout-apply.test.ts": 1943,
"src/main/persistence/terminal-topology/command-application/pane-last-grid.test.ts": 5642,
"src/main/persistence/terminal-topology/pane-ownership/persistence-closed-pane-binding-fence.test.ts": 1926,
"src/main/persistence/restoring-sessions/persistence-cross-host-pane-identity.test.ts": 1744,
"src/main/persistence/restoring-sessions/persistence-empty-root-layout-load.test.ts": 1841,
"src/main/persistence/loading-store/workspace-sessions/persistence-layout-binding-recovery.test.ts": 1835,
"src/main/persistence/restoring-sessions/persistence-pane-identity-migration.test.ts": 5772,
"src/main/persistence/terminal-topology/pane-ownership/persistence-pty-binding-leaf-tab-resolution.test.ts": 1996,
"src/main/persistence/loading-store/terminal-bindings/persistence-pty-binding-reconciliation.test.ts": 1898,
"src/main/persistence/terminal-topology/pane-admission/persistence-runtime-admitted-terminal-membership.test.ts": 2143,
"src/main/persistence/loading-store/terminal-bindings/persistence-split-pane-incarnation.test.ts": 1790,
"src/main/persistence/leasing-ssh-ptys/persistence-ssh-pending-pty-kill.test.ts": 1776,
"src/main/persistence/loading-store/workspace-sessions/persistence-ssh-remote-pty-binding-replay.test.ts": 1853,
"src/main/persistence/leasing-ssh-ptys/persistence-ssh-remote-pty-leases.test.ts": 2079,
"src/main/persistence/restoring-sessions/persistence-tab-terminal-pane-binding-load.test.ts": 1795,
"src/main/persistence/terminal-topology/command-application/terminal-close-write-failure-store.test.ts": 2870,
"src/main/persistence/terminal-topology/command-application/terminal-close-write-failure-switch-off.test.ts": 2027,
"src/main/persistence/terminal-topology/terminal-layout-apply.test.ts": 2005,
"src/main/persistence/terminal-topology/terminal-layout-create-resend.test.ts": 1773,
"src/main/persistence/terminal-topology/terminal-layout-create.test.ts": 2107,
"src/main/persistence/terminal-topology/terminal-layout-pane-ops.test.ts": 1753,
"src/main/persistence/terminal-topology/terminal-layout-rename-tabs.test.ts": 1977,
"src/main/persistence/terminal-topology/terminal-layout-sleep-wake.test.ts": 2198,
"src/main/persistence/terminal-topology/terminal-leaf-move-concurrent-close.test.ts": 1847,
"src/main/persistence/terminal-topology/terminal-leaf-move.test.ts": 2197,
"src/main/persistence/terminal-topology/terminal-owner-invariants.test.ts": 285,
"src/main/persistence/terminal-topology/terminal-pane-admission-layout-owner.test.ts": 1796,
"src/main/persistence/terminal-topology/terminal-sleep-quit-resume.test.ts": 1766,
"src/main/persistence/terminal-topology/terminal-window-pane-detach.test.ts": 1941,
"src/main/persistence/terminal-topology/unshown-live-terminal-placement-restart.test.ts": 2114,
"src/main/persistence/terminal-topology/windowless-host-reload-keeps-terminals.test.ts": 1872,
"src/main/persistence/terminal-topology/windowless-restart-lost-binding.test.ts": 1626,
"src/main/persistence/terminal-topology/pane-admission/terminal-layout-create-resend.test.ts": 1773,
"src/main/persistence/terminal-topology/pane-admission/terminal-layout-create.test.ts": 2107,
"src/main/persistence/terminal-topology/command-application/terminal-layout-pane-ops.test.ts": 1753,
"src/main/persistence/terminal-topology/command-application/terminal-layout-rename-tabs.test.ts": 1977,
"src/main/persistence/terminal-topology/command-application/terminal-layout-sleep-wake.test.ts": 2198,
"src/main/persistence/terminal-topology/pane-moves/terminal-leaf-move-concurrent-close.test.ts": 1847,
"src/main/persistence/terminal-topology/pane-moves/terminal-leaf-move.test.ts": 2197,
"src/shared/workspace-layout/terminal-topology/terminal-owner-invariants.test.ts": 285,
"src/main/persistence/terminal-topology/pane-admission/terminal-pane-admission-layout-owner.test.ts": 1796,
"src/main/persistence/loading-store/workspace-sessions/terminal-sleep-quit-resume.test.ts": 1766,
"src/main/persistence/terminal-topology/pane-moves/terminal-window-pane-detach.test.ts": 1941,
"src/main/runtime/terminal/adoption/unshown-live-terminal-placement-restart.test.ts": 2114,
"src/main/persistence/restoring-sessions/windowless-restart-lost-binding.test.ts": 1626,
"src/main/persistence/tracking-repos/local-worktree-metadata-scan-expectation.test.ts": 544,
"src/main/persistence/tracking-repos/missing-local-worktree-metadata-pruning.test.ts": 619,
"src/main/persistence/tracking-repos/persistence-deregistered-repo-residue.test.ts": 2374,
@@ -2992,7 +2979,6 @@
"src/main/runtime/terminal/output/headless-terminal-dispose-write-ordering.test.ts": 4309,
"src/main/runtime/terminal/recovery/held-pane-reopen-layout-owner.test.ts": 5093,
"src/main/runtime/terminal/wait/hermes-slash-readiness-transcript.test.ts": 4931,
"src/main/runtime/terminal/stop/hook-status-resume-sleep-ordering.test.ts": 9614,
"src/main/runtime/agent-session/environment/host-account-sign-in-flows.test.ts": 68,
"src/main/runtime/hosts/platform-probe/host-descriptor.test.ts": 207,
"src/main/runtime/terminal/surface/host-pane-remount-terminal-handle.test.ts": 5293,
@@ -3008,19 +2994,17 @@
"src/main/runtime/workspaces/creation/managed-worktree-create-registry.test.ts": 4143,
"src/main/runtime/workspaces/creation/managed-worktree-create-telemetry.test.ts": 4152,
"src/main/runtime/workspaces/removal/missing-worktree-terminal-reconciliation.test.ts": 432,
"src/main/runtime/mobile-cloud-relay/desktop-relay-service-installer.test.ts": 48,
"src/main/runtime/mobile-cloud-relay/mobile-relay-e2ee.integration.test.ts": 408,
"src/main/runtime/mobile-cloud-relay/relay-auth-coordinator-readiness.test.ts": 580,
"src/main/runtime/mobile-cloud-relay/relay-auth-coordinator-recovery.test.ts": 161,
"src/main/runtime/mobile-cloud-relay/relay-auth-coordinator.test.ts": 1013,
"src/main/runtime/mobile-cloud-relay/relay-control-client.test.ts": 701,
"src/main/runtime/mobile-cloud-relay/testing/desktop-relay-service-installer.test.ts": 48,
"src/main/runtime/mobile-cloud-relay/testing/mobile-relay-e2ee.integration.test.ts": 408,
"src/main/runtime/mobile-cloud-relay/authentication/relay-auth-coordinator-readiness.test.ts": 580,
"src/main/runtime/mobile-cloud-relay/authentication/relay-auth-coordinator.test.ts": 1013,
"src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client.test.ts": 701,
"src/main/runtime/mobile-cloud-relay/relay-control-origin.test.ts": 147,
"src/main/runtime/mobile-cloud-relay/relay-host-proof.test.ts": 122,
"src/main/runtime/mobile-cloud-relay/relay-http-client.test.ts": 175,
"src/main/runtime/mobile-cloud-relay/relay-readiness-retention.test.ts": 196,
"src/main/runtime/mobile-cloud-relay/relay-region-preference.test.ts": 253,
"src/main/runtime/mobile-cloud-relay/relay-region-refresh.test.ts": 127,
"src/main/runtime/mobile-cloud-relay/relay-revoke-outbox.test.ts": 73,
"src/main/runtime/mobile-cloud-relay/control-channel/relay-host-proof.test.ts": 122,
"src/main/runtime/mobile-cloud-relay/director/relay-http-client.test.ts": 175,
"src/main/runtime/mobile-cloud-relay/authentication/relay-readiness-retention.test.ts": 196,
"src/main/runtime/mobile-cloud-relay/region-selection/relay-region-preference.test.ts": 253,
"src/main/runtime/mobile-cloud-relay/pairing/relay-revoke-outbox.test.ts": 73,
"src/main/runtime/mobile-cloud-relay/relay-session-broker.test.ts": 804,
"src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts": 11377,
"src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.test.ts": 1185,
@@ -3050,8 +3034,6 @@
"src/main/runtime/browser/screencast/orca-runtime-browser-screencast-fanout.test.ts": 607,
"src/main/runtime/browser/client-pages/orca-runtime-browser.test.ts": 682,
"src/main/runtime/terminal/query/orca-runtime-codex-idle-title-chat-address.test.ts": 5781,
"src/main/runtime/terminal/surface/orca-runtime-cold-restore-terminal-membership-layout-owner.test.ts": 4130,
"src/main/runtime/terminal/surface/orca-runtime-cold-restore-terminal-membership.test.ts": 3716,
"src/main/runtime/terminal/wait/orca-runtime-exact-worker-provider-session.test.ts": 3617,
"src/main/runtime/terminal/lifecycle/orca-runtime-exited-split-pane-close.test.ts": 4235,
"src/main/runtime/files/orca-runtime-files-preview-budget.test.ts": 672,
@@ -3517,7 +3499,6 @@
"src/main/runtime/rpc/server/runtime-rpc-browser-host-admission.test.ts": 4402,
"src/main/runtime/rpc/server/runtime-rpc-delegated-device-sync.test.ts": 4986,
"src/main/runtime/rpc/server/runtime-rpc-device-key-dispatch.test.ts": 3597,
"src/main/runtime/rpc/server/runtime-rpc-device-revocation.test.ts": 5350,
"src/main/runtime/rpc/server/runtime-rpc-local-disconnect-forwarding.test.ts": 5138,
"src/main/runtime/rpc/server/runtime-rpc-long-poll-transport.test.ts": 30838,
"src/main/runtime/rpc/server/runtime-rpc-metadata-lifecycle.test.ts": 4652,
@@ -3550,8 +3531,6 @@
"src/main/runtime/workspaces/lineage/runtime-worktree-lineage-controller.test.ts": 1027,
"src/main/runtime/workspaces/startup/runtime-worktree-startup-readiness.test.ts": 289,
"src/main/runtime/workspaces/process-listing/runtime-worktree-structured-agent-rows-liveness.test.ts": 1412,
"src/main/runtime/browser/headless/serve-browser-tabs-layout-owner.test.ts": 321,
"src/main/runtime/session-lifecycle/close/close-by-split-handle-layout-owner.test.ts": 5010,
"src/main/runtime/session-lifecycle/close/close-mobile-row-in-main-layout.test.ts": 4514,
"src/main/runtime/session-lifecycle/projection/pane-sleeping-record.test.ts": 76,
"src/main/runtime/session-lifecycle/projection/sleep-record-pane-claim.test.ts": 48,
@@ -3640,7 +3619,6 @@
"src/main/runtime/terminal/output/tail/terminal-tail-redraw-spans.test.ts": 166,
"src/main/runtime/terminal-tail-redraw-wall-time.test.ts": 43418,
"src/main/runtime/terminal/output/tail/terminal-tail-sentinel-index.test.ts": 3649,
"src/main/runtime/terminal/stop/terminal-update-admission-census.test.ts": 4182,
"src/main/runtime/terminal/output/terminal-vertical-control-scan.test.ts": 168,
"src/main/runtime/terminal/wait/terminal-wait-detection.test.ts": 220,
"src/main/runtime/terminal/wait/terminal-wait-name-only-idle.test.ts": 5018,
@@ -3661,7 +3639,6 @@
"src/main/runtime/terminal/stop/exact-terminal-stop-liveness.test.ts": 4321,
"src/main/runtime/terminal/stop/terminal-update-admission.test.ts": 48,
"src/main/runtime/terminal/surface/closed-pane-exit-cleanup-main.test.ts": 4281,
"src/main/runtime/terminal/surface/main-terminal-acquisition.test.ts": 4330,
"src/main/runtime/terminal/surface/terminal-surface-replies-main.test.ts": 4324,
"src/main/runtime/terminal/wait/tui-idle-codex-plan-menu.test.ts": 4441,
"src/main/runtime/terminal/wait/tui-idle-command-paint.test.ts": 4148,
@@ -3676,8 +3653,6 @@
"src/main/runtime/terminal/surface/workspace-layout-operation-frames.test.ts": 2136,
"src/main/runtime/terminal/surface/workspace-layout-stream.test.ts": 427,
"src/main/runtime/terminal/surface/workspace-session-membership-scaling.test.ts": 72,
"src/main/runtime/workspaces/persisted-surfaces/live-terminal-placement-before-initial-tab.test.ts": 6111,
"src/main/runtime/workspaces/persisted-surfaces/sweep-terminal-placement.test.ts": 12352,
"src/main/runtime/workspaces/lifecycle/workspace-lifecycle-queue.test.ts": 116,
"src/main/runtime/workspaces/sleep/workspace-sleep-execution.test.ts": 110,
"src/main/runtime/workspaces/startup/worktree-agent-first-surface.test.ts": 5816,
@@ -3796,7 +3771,6 @@
"src/main/managed-server/install/orcad-launch-ssh-session.test.ts": 689,
"src/main/managed-server/migration/transfers/orcad-migration-blob-coordinator.test.ts": 1464,
"src/main/managed-server/migration/catalog/orcad-migration-catalog-client-frame-budget.test.ts": 405,
"src/main/managed-server/migration/catalog/orcad-migration-catalog-client-source-kind.test.ts": 400,
"src/main/managed-server/migration/catalog/orcad-migration-catalog-client.test.ts": 400,
"src/main/managed-server/migration/cutover/orcad-migration-cutover-coordinator.test.ts": 2408,
"src/main/managed-server/migration/cutover/orcad-migration-delta-move.test.ts": 3812,
@@ -4223,7 +4197,6 @@
"src/preload/renderer-heap-statistics-reader.test.ts": 50,
"src/preload/renderer-process-memory-reader.test.ts": 66,
"src/preload/renderer-restart-wiring.test.ts": 96,
"src/preload/runtime-environment-subscriptions.test.ts": 71,
"src/preload/ssh-authority-forwarding.test.ts": 1111,
"src/preload/updater-package-recovery.test.ts": 1102,
"src/preload/usage-provider-api.test.ts": 46,
@@ -6368,7 +6341,6 @@
"src/shared/git/worktrees/git-worktree-admin.test.ts": 161,
"src/shared/github/account-binding.test.ts": 48,
"src/shared/github/api-availability.test.ts": 47,
"src/shared/source-control/review-comments/pr-comments-resolution-prompt.test.ts": 49,
"src/shared/github/project-board-columns.test.ts": 64,
"src/shared/github/project-identity.test.ts": 33,
"src/shared/github/project-ref-input.test.ts": 40,
@@ -6596,16 +6568,12 @@
"src/shared/plugins/authoring/plugin-host-typings.test.ts": 2140,
"src/shared/plugins/catalog/plugin-catalog-release.test.ts": 229,
"src/shared/plugins/catalog/plugin-catalog.test.ts": 630,
"src/shared/plugins/catalog/plugin-detail-fields.test.ts": 171,
"src/shared/plugins/catalog/plugin-kill-list.test.ts": 195,
"src/shared/plugins/catalog/plugin-marketplace.test.ts": 246,
"src/shared/plugins/catalog/plugin-repository-link.test.ts": 205,
"src/shared/plugins/contributions/plugin-command-replaces.test.ts": 230,
"src/shared/plugins/contributions/plugin-content-pack-contributions.test.ts": 227,
"src/shared/plugins/contributions/plugin-custom-editor-contribution.test.ts": 238,
"src/shared/plugins/contributions/plugin-execution-profile.test.ts": 164,
"src/shared/plugins/contributions/plugin-panel-contribution.test.ts": 240,
"src/shared/plugins/contributions/plugin-status-bar-item-contribution.test.ts": 232,
"src/shared/plugins/declarative/plugin-declarative-catalog-rich.test.ts": 147,
"src/shared/plugins/declarative/plugin-declarative-example.test.ts": 198,
"src/shared/plugins/declarative/plugin-declarative-tree.test.ts": 168,
@@ -6617,21 +6585,14 @@
"src/shared/plugins/declarative/runtime/declarative-storage-sync.test.ts": 190,
"src/shared/plugins/declarative/testing/orca-testing-hooks.test.ts": 506,
"src/shared/plugins/declarative/testing/orca-testing-worker.test.ts": 480,
"src/shared/plugins/declarative/testing/orca-testing.test.ts": 489,
"src/shared/plugins/declarative/testing/testing-editor-host.test.ts": 197,
"src/shared/plugins/frames/plugin-frame-document-session.test.ts": 404,
"src/shared/plugins/frames/plugin-frame-document.test.ts": 426,
"src/shared/plugins/frames/plugin-frame-facades.test.ts": 383,
"src/shared/plugins/frames/plugin-frame-guest.test.ts": 50,
"src/shared/plugins/frames/plugin-panel-call-admission.test.ts": 89,
"src/shared/plugins/frames/plugin-panel-message-budget.test.ts": 99,
"src/shared/plugins/frames/plugin-panel-shell.test.ts": 376,
"src/shared/plugins/images/plugin-image-format.test.ts": 104,
"src/shared/plugins/images/plugin-image-url.test.ts": 42,
"src/shared/plugins/installation/plugin-file-validation.test.ts": 363,
"src/shared/plugins/installation/plugin-path-safety.test.ts": 221,
"src/shared/plugins/manifest/plugin-display-text.test.ts": 285,
"src/shared/plugins/manifest/plugin-manifest-source-module-floor.test.ts": 212,
"src/shared/plugins/manifest/plugin-manifest-v2-rules.test.ts": 239,
"src/shared/plugins/manifest/plugin-manifest.test.ts": 234,
"src/shared/plugins/view/plugin-editor-shot-acts.test.ts": 112,
@@ -45,7 +45,6 @@ export const UNIT_EXCLUDE = [
'src/shared/terminal/pty/ingress/pty-reply-echo-shapes.node-pty.test.ts',
'src/shared/startup-shell-portability.live-shell.test.ts',
'src/shared/posix-command-path-lookup.test.ts',
'tests/e2e/relay-region-compatibility.unit.test.ts',
'tests/e2e/relay-region-correction.unit.test.ts',
'src/main/browser/cookies/browser-google-cookie-clear.electron.test.ts',
// Electron probes with in-process deadlines; the package job runs them serially.
@@ -13,7 +13,7 @@ import {
/** Files that decide which runtime executable launches orcad or the terminal daemon. */
export const RUNTIME_LAUNCHER_PATHS = [
// orcad handoff to its bundled runtime, and the pinned runtimes it can hand off to.
'src/main/orcad/orcad-bundled-runtime.ts',
'src/main/orcad/runtime-launch/orcad-bundled-runtime.ts',
'src/main/orcad/launcher.ts',
'config/scripts/orcad-distribution/server-bundle/orcad-entry-build.mjs',
'src/shared/node-runtime-pin.ts',
@@ -21,8 +21,8 @@ const CROSS_HOST_PREFIXES = [
'src/main/ssh/',
'src/main/managed-server/',
'src/main/node-runtime/',
'src/main/orcad/orcad-artifact-materializer.ts',
'src/main/orcad/orcad-host-unavailable.ts',
'src/main/orcad/artifact-slots/orcad-artifact-materializer.ts',
'src/main/orcad/diagnostics/orcad-host-unavailable.ts',
'src/main/providers/',
'src/wsl-guest/'
]
@@ -1,11 +1,11 @@
/** Mirrors ORCA_REQUIRED_TEST_INPUTS_ENV in src/main/orcad/orcad-node-slot-fixture.ts. */
/** Mirrors ORCA_REQUIRED_TEST_INPUTS_ENV in src/main/orcad/testing/native-slots/orcad-node-slot-fixture.ts. */
export const REQUIRED_TEST_INPUTS_ENV = 'ORCA_REQUIRED_TEST_INPUTS'
export const CROSS_RUNTIME_TEST_PATHS = []
// Need the built desktop server template; CI runs them by path after build-orcad-template.mjs.
export const TEMPLATE_TEST_PATHS = [
'src/main/orcad/orcad-packaged-structured-chat.integration.test.ts'
'src/main/orcad/testing/structured-chat/orcad-packaged-structured-chat.integration.test.ts'
]
export function nodeServerTestPaths({
@@ -18,10 +18,10 @@ export function nodeServerTestPaths({
'src/main/persistence/loading-store/profile-writing/profile-state',
'src/main/sqlite',
// The orcad server's identity and stop path, which Windows SSH hosts rely on (W2).
'src/main/orcad/orcad-instance-lock.test.ts',
'src/main/orcad/orcad-process-start-time.test.ts',
'src/main/orcad/orcad-managed-stop.test.ts',
'src/main/orcad/orcad-managed-stop-cancellation.test.ts',
'src/main/orcad/instance-lock/orcad-instance-lock.test.ts',
'src/main/orcad/instance-lock/orcad-process-start-time.test.ts',
'src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop.test.ts',
'src/main/orcad/host-lifecycle/managed-stop/orcad-managed-stop-cancellation.test.ts',
// The directory, not a prefix: its siblings are POSIX-host unit tests pr.yml already runs.
'src/main/daemon/pty-subprocess/conpty-startup-input-reader.ts',
'src/main/daemon/pty-subprocess/daemon-pty-physical-owner.ts',
@@ -39,18 +39,17 @@ export function nodeServerTestPaths({
'src/main/daemon/pty-subprocess/spawn-preflight.ts',
'src/main/daemon/pty-subprocess/subprocess-handle.ts',
'src/main/daemon/pty-subprocess/testing/pty-subprocess-spawn-file-foreground.test.ts',
'src/main/daemon/pty-subprocess/testing/pty-subprocess-io-failure-native.test.ts',
...(artifact
? [
'tests/e2e/daemon-running-work-probe.unit.test.ts',
'src/shared/terminal/pty/lifecycle/pty-running-work-probe.test.ts',
'src/main/orcad/orcad-packaged-node-pty.integration.test.ts',
'src/main/orcad/native-runtime/orcad-packaged-node-pty.integration.test.ts',
'src/main/providers/agent-foreground-process-git-bash.win32.test.ts',
'src/main/orcad/orcad-cli-launcher.integration.test.ts',
'src/main/orcad/orcad-launcher-isolation.integration.test.ts',
'src/main/orcad/orcad-stop-request-shutdown.integration.test.ts',
'src/main/orcad/orcad-windows-conpty-breakaway.integration.test.ts',
'src/main/orcad/orcad-serve-parity.integration.test.ts',
'src/main/orcad/serve-startup/orcad-cli-launcher.integration.test.ts',
'src/main/orcad/runtime-launch/orcad-launcher-isolation.integration.test.ts',
'src/main/orcad/host-lifecycle/managed-stop/orcad-stop-request-shutdown.integration.test.ts',
'src/main/orcad/native-runtime/orcad-windows-conpty-breakaway.integration.test.ts',
'src/main/orcad/testing/serve-lifecycle/orcad-serve-parity.integration.test.ts',
'config/scripts/archives/platform-command/zip-extractor-command.test.mjs'
]
: []),
@@ -1,12 +1,12 @@
import { createHash } from 'node:crypto'
import { existsSync } from 'node:fs'
import { copyFile, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from 'node:fs/promises'
import 'node:fs'
import { copyFile, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import { tmpdir } from 'node:os'
import { basename, dirname, join } from 'node:path'
import { dirname, join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { assembleOrcadArtifact } from '../../../../src/main/orcad/orcad-artifact-materializer.ts'
import { readOrcadArtifactIdentity } from '../../../../src/main/orcad/orcad-artifact-identity.ts'
import '../../../../src/main/orcad/artifact-slots/orcad-artifact-materializer.ts'
import '../../../../src/main/orcad/artifact-slots/orcad-artifact-identity.ts'
import {
ORCAD_TEMPLATE_MANIFEST_FILENAME,
orcadRipgrepArtifact
@@ -46,63 +46,6 @@ async function fixture() {
}
describe('packaged ripgrep storage', () => {
it('preserves every deployed slot byte and version, including old schema 3 templates', async () => {
const f = await fixture()
const original = new Map()
const cacheRoot = join(f.appDir, 'cache')
for (const target of Object.keys(f.manifest.targets)) {
const slot = await assembleOrcadArtifact({ templateDir: f.templateDir, cacheRoot, target })
original.set(target, basename(slot))
}
expect(compactPackagedOrcadRipgrep(f.resourcesDir)).toBeGreaterThan(0)
expect(compactPackagedOrcadRipgrep(f.resourcesDir)).toBe(0)
for (const target of Object.keys(f.manifest.targets)) {
const slot = await assembleOrcadArtifact({
templateDir: f.templateDir,
cacheRoot: join(f.appDir, 'fresh-cache'),
target
})
expect(basename(slot)).toBe(original.get(target))
expect(await readOrcadArtifactIdentity(slot)).toBe(original.get(target))
const filename = orcadRipgrepArtifact(target)
expect(await readFile(join(slot, filename))).toEqual(
await readFile(join(f.resourcesDir, filename))
)
if (process.platform !== 'win32' && !target.startsWith('win32-')) {
expect((await stat(join(slot, filename))).mode & 0o777).toBe(0o755)
}
expect(existsSync(join(f.templateDir, 'targets', target, filename))).toBe(
target.startsWith('darwin-')
)
}
// No template storage schema reaches the deployment slot.
expect(
existsSync(
join(
cacheRoot,
'linux-x64-glibc',
original.get('linux-x64-glibc'),
ORCAD_TEMPLATE_MANIFEST_FILENAME
)
)
).toBe(false)
})
it('keeps binaries that differ and never removes Darwin signing inputs', async () => {
const f = await fixture()
const desktop = join(f.resourcesDir, 'ripgrep/linux-arm64/rg')
await writeFile(desktop, 'different desktop bytes')
compactPackagedOrcadRipgrep(f.resourcesDir)
const manifest = JSON.parse(await readFile(f.manifestPath, 'utf8'))
expect(manifest.schemaVersion).toBe(4)
for (const [target, entry] of Object.entries(manifest.targets)) {
expect(entry.packagedRipgrep).toBe(
target.startsWith('darwin-') || target.startsWith('linux-arm64') ? undefined : true
)
}
expect(await readFile(desktop, 'utf8')).toBe('different desktop bytes')
})
it('does not launder corrupted target bytes while removing duplicates', async () => {
const f = await fixture()
await writeFile(join(f.templateDir, 'targets/linux-x64-glibc/ripgrep/linux-x64/rg'), 'tampered')
@@ -1,69 +0,0 @@
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { assembleOrcadArtifact } from '../../../../src/main/orcad/orcad-artifact-materializer.ts'
import { ORCAD_TEMPLATE_MANIFEST_FILENAME } from '../../../../src/shared/orcad-artifacts.ts'
import { writeOrcadTemplateTestFixture } from './orcad-template-test-fixture.mjs'
const require = createRequire(import.meta.url)
const {
finalizePackagedOrcadTemplate,
resealSignedWindowsApp
} = require('./packaged-orcad-template.cjs')
const roots = []
afterEach(async () => {
vi.restoreAllMocks()
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })))
})
async function packagedApp() {
vi.spyOn(console, 'log').mockImplementation(() => {})
const appDir = await mkdtemp(join(tmpdir(), 'orca-packaged-browser-'))
roots.push(appDir)
const resourcesDir = join(appDir, 'resources')
const templateDir = await writeOrcadTemplateTestFixture(resourcesDir)
const driver = join(resourcesDir, 'agent-browser-win32-x64.exe')
await writeFile(driver, 'desktop driver')
await finalizePackagedOrcadTemplate(resourcesDir, { platform: 'win32', signMacBinary: vi.fn() })
return {
appDir,
templateDir,
driver,
manifestPath: join(templateDir, ORCAD_TEMPLATE_MANIFEST_FILENAME)
}
}
describe("packaged orcad uses the app's agent-browser driver (#33846)", () => {
it("materializes the host target's slot with the driver the app ships", async () => {
const app = await packagedApp()
const slot = await assembleOrcadArtifact({
templateDir: app.templateDir,
cacheRoot: join(app.appDir, 'cache'),
target: 'win32-x64'
})
expect(await readFile(join(slot, 'agent-browser-win32-x64.exe'), 'utf8')).toBe('desktop driver')
// A target that carries its own copy keeps it.
const manifest = JSON.parse(await readFile(app.manifestPath, 'utf8'))
expect(manifest.targets['linux-x64-glibc'].packagedBrowser).toBeUndefined()
expect(manifest.targets['win32-arm64'].browserName).toBeUndefined()
})
it('reseals the driver after SignPath rewrites it', async () => {
const app = await packagedApp()
await writeFile(app.driver, 'authenticode-signed driver')
const list = join(app.appDir, 'inner-signing-list.txt')
await writeFile(list, 'Orca.exe\r\nresources\\agent-browser-win32-x64.exe\r\n')
resealSignedWindowsApp(app.appDir, list)
const slot = await assembleOrcadArtifact({
templateDir: app.templateDir,
cacheRoot: join(app.appDir, 'cache'),
target: 'win32-x64'
})
expect(await readFile(join(slot, 'agent-browser-win32-x64.exe'), 'utf8')).toBe(
'authenticode-signed driver'
)
})
})
@@ -141,7 +141,7 @@ const NODE_RUNTIME_INCLUDE = [
'src/main/ipc/renderer-shutdown-checkpoint-sleep-records.test.ts',
'src/main/runtime/agent-session/records/structured-agent-session-startup-tab-restore.test.ts',
'src/shared/remote-runtime/control/remote-runtime-shared-control-connection.test.ts',
'src/main/runtime/mobile-cloud-relay/relay-control-client.test.ts',
'src/main/runtime/mobile-cloud-relay/control-channel/relay-control-client.test.ts',
'src/main/ipc/filesystem/watchers/filesystem-watcher-ignore-real.test.ts',
'src/main/ipc/runtime-environments/runtime-environment-preference.test.ts',
'src/renderer/src/components/emulator-pane/emulator-device-frame-visibility.test.tsx',
@@ -130,10 +130,10 @@ const CODEX_INDEX_HEAL_CONTRACT_PREFIXES = [
]
const ORCAD_BROWSER_PREFIXES = [
'src/main/orcad/external-chromium-',
'src/main/orcad/orcad-browser-provider',
'src/main/orcad/orcad-agent-browser-binary',
'src/main/orcad/electron-serve-browser-process'
'src/main/orcad/browser-providers/chromium/external-chromium-',
'src/main/orcad/browser-providers/orcad-browser-provider',
'src/main/orcad/browser-providers/orcad-agent-browser-binary',
'src/main/orcad/browser-providers/electron/electron-serve-browser-process'
]
// Include page build/verification/manifest/packaging, entry/routes/imported mobile sources and render-check shell policy.
+16 -2
View File
@@ -37,7 +37,19 @@ orca computer click --app com.spotify.client --element-index 42 --json
Element indexes are scoped to the latest `get-app-state` result and may be **sparse**. In `--json` output, read the tree from `result.snapshot.treeText`. Do not invent indexes from `elementCount`. Refresh state after navigation, focus changes, scrolling, or any app re-render before reusing an index.
Action results return only the accessibility-tree lines that changed since the last state for that window (`~` changed, `+` added, `-` removed), marked by `snapshot.treeDiff`; pass `--full-tree` to get the whole tree. To find one control in a large window, `get-app-state --query <text>` prints only matching elements and their ancestors, and `--max-elements <n>` caps the output.
Action results return only the accessibility-tree lines that changed since the last state for that window (`~` changed, `+` added, `-` removed), marked by `snapshot.treeDiff`; pass `--full-tree` to get the whole tree. To find one control in a large window, `get-app-state --query <text>` prints only matching elements and their ancestors, and `--max-elements <n>` caps the output. A window larger than the snapshot limit shows `... N more not shown (snapshot limit)` where the tree was cut; `get-app-state --element-index <n>` reads only that element's subtree, so pass the cut-off children's parent to see them.
## Waiting for the app
Instead of sleeping between actions, wait for what the app should show next. `wait` returns as soon as the condition holds, prints the matching elements or windows, and fails with `wait_timeout` after `--timeout` milliseconds (default 10000, at most 120000):
```bash
orca computer wait --app com.apple.TextEdit --text "Saved" --json
orca computer wait --app com.apple.TextEdit --enabled "Continue" --json
orca computer wait --app com.apple.TextEdit --window-title "Save As" --json
```
`--text` matches element lines the same way as `get-app-state --query`. `--enabled` holds once elements containing the text exist and none of them is disabled. `--window-title` checks the window titles `list-windows` reports (on Windows, only the main window's). `wait` only reads the app and keeps checking while the app or window doesn't exist yet. `--enabled` needs a runtime whose provider marks disabled elements (`supports.observation.disabledState` in `capabilities`).
## Multi-window apps
@@ -75,7 +87,9 @@ orca computer perform-secondary-action --app <app> --element-index <i> --action
Prefer semantic actions (`click`, `set-value`, `perform-secondary-action`) over raw `type-text` or `press-key` — they target accessibility elements directly and survive focus changes that keyboard input doesn't.
On macOS, actions run in the background: the target app isn't brought forward, your frontmost app and key window stay put, and the pointer doesn't move, so you can keep working while an agent drives another window. Each action result reports `action.delivery` (`background` or `foreground`). Pass `--restore-window` only when an app ignores background input, such as drags in Chromium or Electron apps or games; it brings the app forward and uses the real pointer and keyboard. Popup menus and web `<select>` controls are set with `set-value` instead of a click. On Linux and Windows, clicks, scrolling, drags and keyboard input still bring the window forward.
`hotkey` and `press-key` refuse shortcuts that quit or close the app, log out, lock the screen, force-quit or end the session, such as `Cmd+Q`, `Shift+Cmd+Q`, `Ctrl+Cmd+Q` and `Option+Cmd+Esc` on macOS, `Alt+F4` and `Win+L` on Windows, and `Ctrl+Q`, `Alt+F4`, `Super+L` and `Ctrl+Alt+Delete` on Linux. The error code is `system_shortcut_blocked`. Pass `--allow-system-shortcut` to send one anyway.
On macOS, actions run in the background: the target app isn't brought forward, your frontmost app and key window stay put, and the pointer doesn't move, so you can keep working while an agent drives another window. Each action result reports `action.delivery` (`background` or `foreground`). Pass `--restore-window` only when an app ignores background input, such as drags in Chromium or Electron apps or games; it brings the app forward and uses the real pointer and keyboard. Popup menus and web `<select>` controls are set with `set-value` instead of a click. On Linux, clicks, scrolling, drags and keyboard input still bring the window forward. On Windows, element clicks, `set-value` (including sliders), element scrolls and secondary actions (`Invoke`, `Toggle`, `Select`, `Expand`, `Collapse`, `ScrollToVisible`) go through UI Automation when the control supports them, without moving the pointer or sending keys. Some apps still bring their own window forward when driven this way (WPF apps do for most of these), so `action.delivery` reports `foreground` whenever the target window came forward. Anything else brings the window forward.
When accessibility targeting fails, fall back carefully to coordinates:
@@ -0,0 +1,45 @@
import { createElement } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, expect, it, vi } from 'vitest'
import { SmartWorkspaceSourceRow } from './SmartWorkspaceSourceRow'
vi.mock('react-native', () => ({ Text: 'Text', View: 'View' }))
vi.mock('lucide-react-native', () => ({ GitBranch: 'Icon', Sparkles: 'Icon' }))
vi.mock('../theme/mobile-theme', () => ({ colors: {}, radii: {}, spacing: {} }))
vi.mock('../theme/themed-styles', () => ({ themedStyleSheet: (make: () => unknown) => make() }))
vi.mock('../theme/use-mobile-color-scheme', () => ({ useMobileColorScheme: () => 'dark' }))
vi.mock('../i18n/use-mobile-translation', () => ({
useMobileTranslation: () => (_key: string, fallback: string) => fallback
}))
vi.mock('./TaskProviderLogo', () => ({ TaskProviderLogo: () => null }))
vi.mock('./list/ListGroup', () => ({ ListRow: 'ListRow' }))
let renderer: ReactTestRenderer
afterEach(() => {
act(() => renderer?.unmount())
})
it('renders a natural remote label without a namespace subtitle and keeps collision qualification', async () => {
const onPress = vi.fn()
const row = {
kind: 'branch' as const,
value: 'branch-refs/remotes/origin/topic',
refName: 'refs/remotes/origin/topic',
localBranchName: 'topic'
}
await act(async () => {
renderer = create(createElement(SmartWorkspaceSourceRow, { row, onPress }))
})
expect(renderer.toJSON()).toMatchObject({ props: { title: 'origin/topic', subtitle: 'topic' } })
await act(async () => {
renderer.update(
createElement(SmartWorkspaceSourceRow, {
row: { ...row, label: 'refs/remotes/origin/topic' },
onPress
})
)
})
expect(renderer.toJSON()).toMatchObject({
props: { title: 'refs/remotes/origin/topic', subtitle: 'topic' }
})
})
@@ -1,3 +1,4 @@
import { branchRefLabel } from '../../../src/shared/git/refs/branch-ref-label'
import { Text, View } from 'react-native'
import { GitBranch, Sparkles } from 'lucide-react-native'
import type { SmartWorkspaceSourceRow as SourceRow } from '../../../src/shared/new-workspace/smart-workspace-source-results'
@@ -70,8 +71,9 @@ function resolveRowContent(row: SourceRow, t: Translate): RowContent {
case 'branch':
return {
icon: <GitBranch size={18} color={colors.textSecondary} />,
title: row.localBranchName || row.refName,
subtitle: row.refName
title: row.label ?? branchRefLabel(row.refName),
subtitle:
row.localBranchName !== branchRefLabel(row.refName) ? row.localBranchName : undefined
}
case 'linear':
return {
@@ -9,21 +9,6 @@ function ok(result: unknown): RpcResponse {
return { id: 'rpc', ok: true, result, _meta: { runtimeId: 'runtime-1' } }
}
function createClient(responses: (RpcResponse | Error)[]) {
return {
sendRequest: vi.fn<SendRequest>(async (method) => {
const response = responses.shift()
if (!response) {
throw new Error(`no scripted response for ${method}`)
}
if (response instanceof Error) {
throw response
}
return response
})
}
}
function activeTerminalState(activated: boolean) {
return {
activated,
@@ -92,14 +77,6 @@ describe('openMobileFileTap', () => {
.map(([, params]) => params)
}
it('opens the longest terminal reading that exists, as desktop does', async () => {
const opened = await openTerminalReadings(
['src/index.ts', 'src/index.ts.map', 'src/index.ts.map.bak'],
new Set(['src/index.ts', 'src/index.ts.map'])
)
expect(opened).toEqual([{ worktree: 'id:wt-1', relativePath: 'src/index.ts.map' }])
})
it('still checks the real path behind hundreds of hard-wrap guesses', async () => {
const guesses = Array.from({ length: 210 }, (_, index) => `src/file${index}.tssrc/next.ts`)
const opened = await openTerminalReadings(
@@ -108,94 +85,4 @@ describe('openMobileFileTap', () => {
)
expect(opened).toEqual([{ worktree: 'id:wt-1', relativePath: 'src/file19.ts' }])
})
it('does not navigate an absolute artifact after the user leaves the source terminal', async () => {
let resolveRequest: (value: RpcResponse) => void = () => {}
const client = {
sendRequest: vi.fn<SendRequest>(
() =>
new Promise((resolve) => {
resolveRequest = resolve
})
)
}
let activeTerminalHandle: string | null = 'terminal-1'
const pushPreviewRoute = vi.fn()
openMobileFileTap({
client,
hostId: 'host-1',
worktreeId: 'wt-1',
candidates: [{ pathText: '/tmp/result.json', line: null, column: null }],
terminalHandle: 'terminal-1',
pushPreviewRoute,
openBrowser: vi.fn(),
triggerOpenFeedback: vi.fn(),
fetchSessionTabs: vi.fn(),
getSessionTabs: () => [],
getActiveSessionTabId: () => null,
getActivationState: (activated) => ({
...activeTerminalState(activated),
activeTerminalHandle
}),
switchSessionTab: vi.fn(),
scheduleDelayedAction: vi.fn()
})
activeTerminalHandle = 'terminal-2'
resolveRequest(
ok({
worktree: 'wt-1',
relativePath: null,
absolutePath: '/tmp/result.json',
exists: true,
isDirectory: false,
openTarget: {
kind: 'absolute-file',
provider: 'local',
absolutePath: '/tmp/result.json',
grantId: 'grant-1'
}
})
)
await vi.advanceTimersByTimeAsync(0)
expect(pushPreviewRoute).not.toHaveBeenCalled()
})
it('does not report a stale failure after a newer tap supersedes it', async () => {
const client = createClient([
ok({
worktree: 'wt-1',
relativePath: null,
absolutePath: null,
exists: false,
isDirectory: false
})
])
const onOpenFailed = vi.fn()
openMobileFileTap({
client,
hostId: 'host-1',
worktreeId: 'wt-1',
candidates: [{ pathText: 'gone/missing.ts', line: null, column: null }],
pushPreviewRoute: vi.fn(),
openBrowser: vi.fn(),
triggerOpenFeedback: vi.fn(),
fetchSessionTabs: vi.fn(),
getSessionTabs: () => [],
getActiveSessionTabId: () => null,
getActivationState: (activated) => ({
...activeTerminalState(activated),
latestActivationSeq: 2
}),
switchSessionTab: vi.fn(),
scheduleDelayedAction: vi.fn(),
onOpenFailed
})
await vi.advanceTimersByTimeAsync(0)
expect(onOpenFailed).not.toHaveBeenCalled()
})
})
+4 -1
View File
@@ -3936,7 +3936,10 @@
"planAgentUnsupported": "Agent \"{{agent}}\" does not support AI commit messages.",
"planModelUnavailable": "Model \"{{model}}\" is not available for {{label}}.",
"planModelWithoutThinking": "Model \"{{model}}\" does not support a thinking effort level.",
"planThinkingLevelInvalid": "Thinking level \"{{level}}\" is not valid for {{model}}."
"planThinkingLevelInvalid": "Thinking level \"{{level}}\" is not valid for {{model}}.",
"commandTemplateEmptyDictationCleanup": "Command template is empty for dictation cleanup.",
"dictationCleanupAgentUnsupported": "Choose a supported agent for AI cleanup in Settings -> Voice -> Cleanup. Supported agents: {{agents}}, or Custom command.",
"agentCannotGenerateDictationCleanup": "Agent \"{{agent}}\" does not support dictation cleanup. Supported agents: {{agents}}, or Custom command."
},
"conflictActions": {
"resolveFile": "{{action}}: {{path}}",
@@ -1,17 +1,9 @@
import { describe, expect, it, vi } from 'vitest'
import {
coordinateHostStackNavigation,
navigateToHostStackRoute,
type HostStackNavigationState
} from './host-stack-navigation'
const TARGET = { name: '[hostId]/tasks', params: { hostId: 'host/one' } } as const
const OTHER_TARGET = {
name: '[hostId]/session/[worktreeId]',
params: { hostId: 'host/one', worktreeId: 'repo::/tmp/wt' }
} as const
// Remove listeners for real so teardown is tested instead of merely the active guard.
function navigationHarness(initialState: HostStackNavigationState | undefined) {
const stateListeners = new Set<() => void>()
let state = initialState
@@ -57,58 +49,6 @@ function committedHostState(hostIdParam: string): HostStackNavigationState {
}
describe('host stack navigation', () => {
it('stops listening and never replaces once canceled', () => {
const harness = navigationHarness({ index: 0, routes: [{ name: 'index' }] })
const controller = navigateToHostStackRoute(
harness.navigation,
{ push: vi.fn(), replace: vi.fn() },
'host/one',
TARGET
)
expect(harness.listenerCount()).toBe(1)
controller.cancel()
expect(harness.unsubscribe).toHaveBeenCalledTimes(1)
expect(harness.listenerCount()).toBe(0)
expect(controller.isActive()).toBe(false)
harness.setState(committedHostState('host/one'))
expect(harness.navigation.dispatch).not.toHaveBeenCalled()
})
it('retargets a still-pending transition to the same host instead of pushing twice', () => {
const harness = navigationHarness({ index: 0, routes: [{ name: 'index' }] })
const push = vi.fn()
const router = { push, replace: vi.fn() }
const pending = coordinateHostStackNavigation(
null,
harness.navigation,
router,
'host/one',
TARGET
)
const retargeted = coordinateHostStackNavigation(
pending,
harness.navigation,
router,
'host/one',
OTHER_TARGET
)
expect(retargeted).toBe(pending)
expect(push).toHaveBeenCalledTimes(1)
expect(harness.listenerCount()).toBe(1)
harness.setState(committedHostState('host/one'))
expect(harness.navigation.dispatch).toHaveBeenCalledTimes(1)
expect(harness.navigation.dispatch).toHaveBeenCalledWith(
expect.objectContaining({ payload: OTHER_TARGET })
)
})
describe('a session opened inside its host document', () => {
const SESSION = {
name: '[hostId]/session/[worktreeId]',
@@ -155,27 +95,5 @@ describe('host stack navigation', () => {
]
])
})
it('lets another screen tapped while the push commits take the list place', () => {
const harness = navigationHarness({ index: 0, routes: [{ name: 'index' }] })
const push = vi.fn()
const router = { push, replace: vi.fn() }
const pending = coordinateHostStackNavigation(
null,
harness.navigation,
router,
'host/one',
SESSION,
true
)
coordinateHostStackNavigation(pending, harness.navigation, router, 'host/one', TARGET)
harness.setState(committedHostState('host/one'))
expect(push).toHaveBeenCalledTimes(1)
expect(harness.navigation.dispatch.mock.calls).toEqual([
[{ type: 'REPLACE', target: '/h', source: 'host-index', payload: TARGET }]
])
})
})
})
@@ -1,3 +1,4 @@
import { legacyBaseRefSearchResult } from '../../../../src/shared/base-ref-search-result'
import type { GitHubWorkItem } from '../../../../src/shared/github/work-items/work-item-types'
import type { GitLabWorkItem } from '../../../../src/shared/gitlab-types'
import type { LinearIssue } from '../../../../src/shared/linear/issue-types'
@@ -124,8 +125,5 @@ export async function searchBranches(
{ timeoutMs: 30_000 }
)
const result = repoBaseRefSearchRead.interpret(reply)
return (
result.refDetails ??
(result.refs ?? []).map((refName) => ({ refName, localBranchName: refName }))
)
return result.refDetails ?? (result.refs ?? []).map(legacyBaseRefSearchResult)
}
@@ -43,14 +43,19 @@ export function MobileNativeChatUsageLimitStatus({
const { usageLimit, openAccounts } = useContext(MobileNativeChatNoticeContext)
const failure = readWholeAgentSessionFailureFact(notice.failure)
const resetsAt = failure?.kind === 'usageLimitReached' ? failure.usageLimit?.resetsAt : undefined
const resetPassed = useResetPassed(resetsAt)
const actions =
failure?.kind === 'usageLimitReached' &&
notice.usageLimitTurnItemId !== undefined &&
usageLimit?.turnItemId === notice.usageLimitTurnItemId
? usageLimit
: null
// The line names the reset Orca waits for; Continue still keys off the cut's own reset.
// Continue applies at the cut's own reset, or earlier once the host says the chat moved accounts.
const resetPassed = useResetPassed(
resetsAt !== undefined && actions?.continueAt !== undefined
? Math.min(resetsAt, actions.continueAt)
: resetsAt
)
// The line names the reset Orca waits for.
const shownAt = actions?.autoContinue ? (actions.continueAt ?? resetsAt) : resetsAt
const shownPassed = useResetPassed(shownAt)
if (failure?.kind !== 'usageLimitReached') {
@@ -0,0 +1,25 @@
import type { TextGenerationFailureCode } from '../../../src/shared/text-generation-failure-copy'
import { translate } from '../i18n/mobile-i18n'
export const DICTATION_CLEANUP_FAILURE_COPY = {
commandTemplateEmptyDictationCleanup: (values) =>
translate(
'sourceControl.textGenerationFailure.commandTemplateEmptyDictationCleanup',
'Command template is empty for dictation cleanup.',
values
),
dictationCleanupAgentUnsupported: (values) =>
translate(
'sourceControl.textGenerationFailure.dictationCleanupAgentUnsupported',
'Choose a supported agent for AI cleanup in Settings -> Voice -> Cleanup. Supported agents: {{agents}}, or Custom command.',
values
),
agentCannotGenerateDictationCleanup: (values) =>
translate(
'sourceControl.textGenerationFailure.agentCannotGenerateDictationCleanup',
'Agent "{{agent}}" does not support dictation cleanup. Supported agents: {{agents}}, or Custom command.',
values
)
} satisfies Partial<
Record<TextGenerationFailureCode, (values: Record<string, string | number>) => string>
>
@@ -1,3 +1,4 @@
import { legacyBaseRefSearchResult } from '../../../src/shared/base-ref-search-result'
import { translate } from '../i18n/mobile-i18n'
import { refusedRpcMessageOrFallback } from '../transport/rpc/rpc-refusal-message'
import type { UnvalidatedRpcRequestPort } from '../transport/rpc/unvalidated-rpc-request-port'
@@ -137,7 +138,7 @@ export async function searchMobilePrBaseRefs(
)
const result = repoBaseRefSearchRead.interpret(reply)
return normalizeCreateReviewBaseSearchResults(
result.refDetails ?? (result.refs ?? []).map((refName) => ({ refName, localBranchName: '' }))
result.refDetails ?? (result.refs ?? []).map(legacyBaseRefSearchResult)
)
}
@@ -1,57 +0,0 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { activateMobileUiLocale, mobileI18n } from '../i18n/mobile-i18n'
import { textGenerationErrorText } from './text-generation-failure-copy'
beforeEach(async () => {
mobileI18n.addResourceBundle('de', 'translation', {
'sourceControl.textGenerationFailure.cliFailedWithDetail':
'{{label}} fehlgeschlagen ({{exitCode}}): {{detail}}',
'sourceControl.textGenerationFailure.noStagedChanges': 'Keine Änderungen vorgemerkt.',
'sourceControl.textGenerationFailure.planModelUnavailable':
'Modell {{model}} für {{label}} nicht verfügbar.',
'sourceControl.textGenerationFailure.kimiConflictingOptions':
'Kimi: {{option}} und {{otherOption}} widersprechen sich.'
})
await activateMobileUiLocale('de')
})
afterEach(async () => {
await activateMobileUiLocale('en')
mobileI18n.removeResourceBundle('de', 'translation')
})
describe('textGenerationErrorText', () => {
it('translates coded failures and preserves agent output verbatim', () => {
expect(
textGenerationErrorText({
error: 'host error',
errorCode: 'cliFailedWithDetail',
errorParams: { label: 'Codex', exitCode: 0, detail: 'ignored' },
errorDetail: '{{label}}: $t(secret) <stderr>'
})
).toBe('Codex fehlgeschlagen (0): {{label}}: $t(secret) <stderr>')
expect(textGenerationErrorText({ error: 'host error', errorCode: 'noStagedChanges' })).toBe(
'Keine Änderungen vorgemerkt.'
)
})
it.each([
{},
{ errorCode: 'newerHostCode' },
{ errorCode: 'toString' },
{ errorCode: 42 },
{ errorCode: 'cliFailedWithDetail', errorParams: { label: 'Codex', exitCode: 1 } },
{
errorCode: 'cliFailedWithDetail',
errorParams: { label: 'Codex', exitCode: null },
errorDetail: 'detail'
},
{
errorCode: 'cliFailedWithDetail',
errorParams: { label: 'Codex', exitCode: 1, detail: 'not errorDetail' }
},
{ errorCode: 'agentCouldNotStart', errorParams: 'Codex' }
])('keeps the host error when the code or required values are unavailable: %j', (fields) => {
expect(textGenerationErrorText({ error: 'Host English', ...fields })).toBe('Host English')
})
})
@@ -5,6 +5,7 @@ import {
import { translate } from '../i18n/mobile-i18n'
import { AGENT_OUTPUT_FAILURE_COPY } from './agent-output-failure-copy'
import { TEXT_GENERATION_PLAN_FAILURE_COPY } from './text-generation-plan-failure-copy'
import { DICTATION_CLEANUP_FAILURE_COPY } from './dictation-cleanup-failure-copy'
type CopyValues = Record<string, string | number>
@@ -256,7 +257,8 @@ const COPY: Record<TextGenerationFailureCode, (values: CopyValues) => string> =
values
),
...TEXT_GENERATION_PLAN_FAILURE_COPY,
...AGENT_OUTPUT_FAILURE_COPY
...AGENT_OUTPUT_FAILURE_COPY,
...DICTATION_CLEANUP_FAILURE_COPY
}
function isTextGenerationFailureCode(code: unknown): code is TextGenerationFailureCode {
@@ -1,3 +1,4 @@
import { branchRefLabel } from '../../../../src/shared/git/refs/branch-ref-label'
import type { ConnectionPresentationModel } from '../screen-state/use-mobile-tasks-connection-presentation'
import { BottomDrawer } from '../../components/bottom-drawer/BottomDrawer'
import { View, Text } from 'react-native'
@@ -146,12 +147,14 @@ export function renderMobileTasksWorkspaceCreateDrawer(model: ConnectionPresenta
key="startFrom"
title={translate('tasks.workspaceCreateDrawer.startFrom', 'Start from')}
value={
workspaceBaseBranch?.refName ??
(workspaceBaseBranch ? branchRefLabel(workspaceBaseBranch.refName) : null) ??
translate('tasks.workspaceCreateDrawer.defaultBranch', 'Default branch')
}
navigates
onPress={() => {
setWorkspaceBaseBranchQuery(workspaceBaseBranch?.refName ?? '')
setWorkspaceBaseBranchQuery(
workspaceBaseBranch ? branchRefLabel(workspaceBaseBranch.refName) : ''
)
setShowWorkspaceBaseBranchPicker(true)
}}
/>
@@ -1,3 +1,4 @@
import { branchRefLabels, branchRefLabel } from '../../../../src/shared/git/refs/branch-ref-label'
import type { ConnectionPresentationModel } from '../screen-state/use-mobile-tasks-connection-presentation'
import { BottomDrawer } from '../../components/bottom-drawer/BottomDrawer'
import { View, Text, Pressable, ActivityIndicator } from 'react-native'
@@ -24,6 +25,7 @@ export function renderMobileTasksWorkspaceBaseBranchPicker(model: ConnectionPres
workspaceBaseBranchResults,
workspaceCreateDraft
} = model
const labels = branchRefLabels(workspaceBaseBranchResults.map((branch) => branch.refName))
return (
<BottomDrawer
visible={taskUiReady && workspaceCreateDraft != null && showWorkspaceBaseBranchPicker}
@@ -70,9 +72,9 @@ export function renderMobileTasksWorkspaceBaseBranchPicker(model: ConnectionPres
{workspaceBaseBranchResults.map((branch) => (
<ListRow
key={`${branch.refName}:${branch.localBranchName}`}
title={branch.refName}
title={labels.get(branch.refName) ?? branchRefLabel(branch.refName)}
subtitle={
branch.localBranchName !== branch.refName
branch.localBranchName !== branchRefLabel(branch.refName)
? translate(
'tasks.workspaceOptionPickers.branchName',
'Branch name: {{name}}',
@@ -1,3 +1,4 @@
import { legacyBaseRefSearchResult } from '../../../../src/shared/base-ref-search-result'
import type { WorkspaceCreateProjectionModel } from '../project-board/use-mobile-tasks-workspace-create-projection'
import type { SparsePreset } from '../../../../src/shared/worktree/create-types'
import { useEffect } from 'react'
@@ -146,8 +147,7 @@ export function useMobileTasksWorkspaceSourceEffects<Model extends WorkspaceSour
}
const result = repoBaseRefSearchRead.interpret(reply)
setWorkspaceBaseBranchResults(
result.refDetails ??
(result.refs ?? []).map((refName) => ({ refName, localBranchName: refName }))
result.refDetails ?? (result.refs ?? []).map(legacyBaseRefSearchResult)
)
})
.catch((err) => {
@@ -1,81 +0,0 @@
import { describe, expect, it } from 'vitest'
import { buildTerminalShortcutKey } from './terminal-accessory-keys'
describe('TERMINAL_ACCESSORY_KEYS', () => {
it('builds Ctrl, Alt, and Shift printable shortcut bytes', () => {
expect(buildTerminalShortcutKey({ key: 'c', modifiers: ['ctrl'] })).toEqual({
label: 'Ctrl+C',
bytes: '\x03',
accessibilityLabel: 'Ctrl C'
})
expect(buildTerminalShortcutKey({ key: 'k', modifiers: ['ctrl', 'alt'] })).toEqual({
label: 'Ctrl+Alt+K',
bytes: '\x1b\x0b',
accessibilityLabel: 'Ctrl Alt K'
})
expect(buildTerminalShortcutKey({ key: '1', modifiers: ['alt', 'shift'] })).toEqual({
label: 'Alt+Shift+1',
bytes: '\x1b!',
accessibilityLabel: 'Alt Shift 1'
})
})
it('builds custom Space shortcut bytes with terminal modifiers', () => {
expect(buildTerminalShortcutKey({ key: 'space', modifiers: [] })).toEqual({
label: 'Space',
bytes: ' ',
accessibilityLabel: 'Space'
})
expect(buildTerminalShortcutKey({ key: 'space', modifiers: ['ctrl'] })).toEqual({
label: 'Ctrl+Space',
bytes: '\x00',
accessibilityLabel: 'Ctrl Space'
})
expect(buildTerminalShortcutKey({ key: 'space', modifiers: ['alt'] })).toEqual({
label: 'Alt+Space',
bytes: '\x1b ',
accessibilityLabel: 'Alt Space'
})
})
it('builds modified special-key terminal sequences', () => {
expect(buildTerminalShortcutKey({ key: 'tab', modifiers: ['shift'] })).toEqual({
label: 'Shift+Tab',
bytes: '\x1b[Z',
accessibilityLabel: 'Shift Tab'
})
expect(buildTerminalShortcutKey({ key: 'enter', modifiers: [] })).toEqual({
label: 'Enter',
bytes: '\r',
accessibilityLabel: 'Enter'
})
expect(buildTerminalShortcutKey({ key: 'arrowRight', modifiers: ['ctrl', 'shift'] })).toEqual({
label: 'Ctrl+Shift+→',
bytes: '\x1b[1;6C',
accessibilityLabel: 'Ctrl Shift →'
})
expect(buildTerminalShortcutKey({ key: 'delete', modifiers: ['alt'] })).toEqual({
label: 'Alt+Del',
bytes: '\x1b[3;3~',
accessibilityLabel: 'Alt Del'
})
})
it('builds function-key terminal sequences', () => {
expect(buildTerminalShortcutKey({ key: 'f1', modifiers: [] })).toEqual({
label: 'F1',
bytes: '\x1bOP',
accessibilityLabel: 'F1'
})
expect(buildTerminalShortcutKey({ key: 'f5', modifiers: ['shift'] })).toEqual({
label: 'Shift+F5',
bytes: '\x1b[15;2~',
accessibilityLabel: 'Shift F5'
})
})
it('rejects control combinations that terminals cannot encode as control bytes', () => {
expect(buildTerminalShortcutKey({ key: '1', modifiers: ['ctrl'] })).toBeNull()
})
})
+42 -17
View File
@@ -135,8 +135,11 @@ def pid_of(node):
def has_state(node, state):
state_set = attempt(node.get_state_set)
return bool(state_set is not None and attempt(lambda: state_set.contains(state), False))
return state_set_contains(attempt(node.get_state_set), state)
def state_set_contains(state_set, state, default=False):
return bool(state_set is not None and attempt(lambda: state_set.contains(state), default))
class GeometryReader:
@@ -401,8 +404,17 @@ def accessible_id(node):
return str(attempt(node.get_accessible_id, "") or "")
def is_disabled(state_set):
# Why: toolkits set ENABLED and SENSITIVE on usable nodes; a node whose states can't be read is not called disabled.
usable = [getattr(Atspi.StateType, name, None) for name in ("ENABLED", "SENSITIVE")]
if state_set is None or None in usable:
return False
return not any(state_set_contains(state_set, state, True) for state in usable)
def record(node, index, path):
role = role_of(node)
state_set = attempt(node.get_state_set)
return {
"index": index,
"runtimeId": path,
@@ -412,7 +424,8 @@ def record(node, index, path):
"localizedControlType": role,
"className": str(attempt(node.get_toolkit_name, "") or ""),
"value": string_value(node),
"isSelected": has_state(node, Atspi.StateType.SELECTED),
"isSelected": state_set_contains(state_set, Atspi.StateType.SELECTED),
"isDisabled": is_disabled(state_set),
"nativeWindowHandle": 0,
"frame": None,
"actions": action_labels(node),
@@ -474,13 +487,19 @@ def render_accessibility_tree(root, root_path, compact_browser_tabs=False, geome
has_text = bool(item["name"] or item["automationId"] or item["value"])
return role in {"panel", "filler", "unknown", "section"} and not has_text and not meaningful_actions(item["actions"]) and summary is None and child_count <= 1
def walk_children(child_items, depth, path):
for position, (child_index, child) in enumerate(child_items):
if len(records) >= MAX_NODES or depth > MAX_DEPTH:
truncation["truncated"] = True
if depth > MAX_DEPTH:
truncation["maxDepthReached"] = True
# Marks where the walk stopped, so the agent can read that parent's subtree by index.
lines.append(("\t" * depth) + f"... {len(child_items) - position} more not shown (snapshot limit)")
return
walk(child, depth, path + [child_index])
def walk(node, depth, path):
nonlocal next_index
if len(records) >= MAX_NODES or depth > MAX_DEPTH:
truncation["truncated"] = True
if depth > MAX_DEPTH:
truncation["maxDepthReached"] = True
return
item = record(node, next_index, path)
role_key = (item["controlType"] or "").lower()
title = item["name"] or item["automationId"] or ""
@@ -492,15 +511,15 @@ def render_accessibility_tree(root, root_path, compact_browser_tabs=False, geome
if len(summary_values) >= 2 and is_plain_text_subtree(node):
generic_summary = " ".join(summary_values)
if should_elide(item, len(child_items), generic_summary):
for child_index, child in child_items:
walk(child, depth, path + [child_index])
walk_children(child_items, depth, path)
return
records.append(item)
next_index += 1
if geometry_nodes is not None:
geometry_nodes[id(item)] = node
role_label = item["localizedControlType"] or item["controlType"]
line = f'{item["index"]} {role_label} {sanitize_text(title)}'.rstrip()
traits = " (disabled)" if item["isDisabled"] else ""
line = f'{item["index"]} {role_label}{traits} {sanitize_text(title)}'.rstrip()
line += formatted_value(role_key, title, item["value"])
if generic_summary and generic_summary != title:
line += ", Text: " + sanitize_text(generic_summary)
@@ -515,8 +534,7 @@ def render_accessibility_tree(root, root_path, compact_browser_tabs=False, geome
if generic_summary or suppressed:
return
child_line_start = len(lines)
for child_index, child in child_items:
walk(child, depth + 1, path + [child_index])
walk_children(child_items, depth + 1, path)
if compact_browser_tabs:
compact_rendered_browser_tabs(records, lines, child_line_start, depth + 1)
@@ -1189,17 +1207,23 @@ def window_json(app, index, window):
}
def make_snapshot(query, include_screenshot, window_id=None, window_index=None, restore=False):
def make_snapshot(query, include_screenshot, window_id=None, window_index=None, restore=False, root=None):
app = find_app(query)
window_index, window = choose_window(app, window_id, window_index)
if restore:
restore_window(app, window)
window_index, window = choose_window(app, window_id, window_index)
bounds = screen_rect(window)
tree_root, root_path = window, [window_index]
if root is not None:
tree_root = find_element(app, root)
if tree_root is None:
raise RuntimeError(f"stale element: element {root.get('index')} is gone; run get-app-state again and use a fresh element index")
root_path = list(root.get("runtimeId") or [])
geometry_nodes = {}
records, lines, truncation = render_accessibility_tree(
window,
[window_index],
tree_root,
root_path,
compact_browser_tabs=is_browser_app(query, app),
geometry_nodes=geometry_nodes,
)
@@ -1264,7 +1288,7 @@ def handshake_response():
"supports": {
"apps": {"list": True, "bundleIds": False, "pids": True},
"windows": {"list": True, "targetById": False, "targetByIndex": True, "focus": False, "moveResize": False},
"observation": {"screenshot": has_screenshot, "annotatedScreenshot": False, "elementFrames": True, "ocr": False},
"observation": {"screenshot": has_screenshot, "annotatedScreenshot": False, "elementFrames": True, "ocr": False, "disabledState": True},
"actions": {
"click": True,
"typeText": True,
@@ -1861,6 +1885,7 @@ def run_operation(operation):
operation.get("windowId"),
operation.get("windowIndex"),
bool(operation.get("restoreWindow")),
operation.get("root"),
),
}
@@ -18,6 +18,8 @@ class FakeStateType:
SHOWING = 4
FOCUSED = 5
EDITABLE = 6
ENABLED = 7
SENSITIVE = 8
class FakeStateSet:
@@ -668,6 +670,19 @@ class RuntimeRenderTest(unittest.TestCase):
keys.assert_not_called()
paste.assert_not_called()
def test_tree_marks_controls_without_enabled_or_sensitive_state_disabled(self):
disabled = FakeAccessible("push button", "Continue")
disabled.get_state_set = lambda: FakeStateSet(FakeStateType.SHOWING)
enabled = FakeAccessible("push button", "Cancel")
enabled.get_state_set = lambda: FakeStateSet(FakeStateType.ENABLED, FakeStateType.SENSITIVE)
unreadable = FakeAccessible("push button", "Help")
root = FakeAccessible("frame", "Form", children=[disabled, enabled, unreadable])
with SnapshotFixture(root):
lines = runtime.make_snapshot("Fixture", False)["treeLines"]
self.assertIn("\t1 push button (disabled) Continue", lines)
self.assertIn("\t2 push button Cancel", lines)
self.assertIn("\t3 push button Help", lines)
def test_compacted_browser_records_keep_their_own_frames_and_indexes(self):
tabs = [FakeAccessible("page tab", f"Tab {i}", value="1" if i == 9 else "") for i in range(10)]
buttons = [FakeAccessible("button", f"Other {i}") for i in range(10)]
@@ -684,6 +699,26 @@ class RuntimeRenderTest(unittest.TestCase):
indexes = [item["index"] for item in snapshot["elements"]]
self.assertEqual(len(indexes), len(set(indexes)))
def test_cut_tree_marks_hidden_children_and_root_reads_them(self):
items = [FakeAccessible("button", f"A{i}") for i in range(3)]
root = FakeAccessible("frame", "Main", children=[
FakeAccessible("list", "Items", children=items), FakeAccessible("button", "After"),
])
with SnapshotFixture(root), patch.object(runtime, "MAX_NODES", 4):
snapshot = runtime.make_snapshot("Fixture", False)
self.assertEqual(snapshot["treeLines"], [
"0 frame Main",
"\t1 list Items",
"\t\t2 button A0",
"\t\t3 button A1",
"\t\t... 1 more not shown (snapshot limit)",
"\t... 1 more not shown (snapshot limit)",
])
items_record = next(item for item in snapshot["elements"] if item["name"] == "Items")
subtree = runtime.run_operation({"tool": "get_app_state", "app": "Fixture", "noScreenshot": True, "root": items_record})["snapshot"]
self.assertEqual(subtree["treeLines"], ["0 list Items", "\t1 button A0", "\t2 button A1", "\t3 button A2"])
self.assertEqual(subtree["elements"][-1]["runtimeId"], [0, 0, 2])
@@ -143,6 +143,12 @@ final class ElementRecord {
}
}
/// A snapshot that read one element's subtree; its elements also keep the window's earlier ones.
struct SnapshotScope {
let rootIndex: Int
let walkedIndexes: Set<Int>
}
struct Snapshot {
let id: String
let app: AppDescriptor
@@ -161,6 +167,7 @@ struct Snapshot {
let nextFreshElementIndex: Int
let truncated: Bool
let maxDepthReached: Bool
let scope: SnapshotScope?
/// On-screen windows of the app (menus and sheets included), so a new or closed window counts as a change.
let appWindowIds: [CGWindowID]
@@ -187,6 +194,7 @@ struct Snapshot {
nextFreshElementIndex: nextFreshElementIndex,
truncated: truncated,
maxDepthReached: maxDepthReached,
scope: scope,
appWindowIds: appWindowIds
)
}
@@ -262,9 +270,10 @@ final class Provider {
var action = try runAction()
// Why: only --restore-window activates the app or posts to the HID tap; every other route leaves the user's desktop alone.
action["delivery"] = isForegroundRequest(params) ? "foreground" : "background"
// Why: the action's currentSnapshot just cached this target's tree from before the action.
// Why: the action's currentSnapshot just cached this target's tree from before the action;
// a subtree read can't be compared with the whole-window read that follows.
let before = action["path"] as? String == "accessibility" && action["verification"] == nil
? try? cachedSnapshot(params: params)
? (try? cachedSnapshot(params: params)).flatMap { $0.scope == nil ? $0 : nil }
: nil
do {
let after = try observe(params: params)
@@ -315,12 +324,14 @@ final class Provider {
}
let namespace = snapshotNamespace(params)
pruneSnapshotCache()
let subtree = try requestedSubtree(params: params, app: app)
let snapshot = try buildSnapshot(
app: app,
includeScreenshot: params["noScreenshot"]?.bool != true,
windowId: windowId,
windowIndex: windowIndex,
windowId: subtree.map(\.base.windowId) ?? windowId,
windowIndex: subtree == nil ? windowIndex : nil,
restoreWindow: params["restoreWindow"]?.bool == true,
subtree: subtree,
previousSnapshot: { [snapshots] resolvedWindowId in
// Why: indexes carry over from this caller's own last view of exactly this window.
snapshots[namespacedSnapshotKey(namespace, snapshotCanonicalWindowIdKey(resolvedWindowId))]
@@ -339,6 +350,15 @@ final class Provider {
return snapshot
}
/// Resolves `rootElementIndex` against this caller's last snapshot of the window, whose indexes it extends.
private func requestedSubtree(params: [String: JSONValue], app: AppDescriptor) throws -> (root: ElementRecord, base: Snapshot)? {
guard let rootIndex = try optionalInteger(params, "rootElementIndex") else { return nil }
guard let base = try cachedSnapshot(params: params), base.app.pid == app.pid else {
throw ProviderError.coded("element_not_found", "--element-index needs a get-app-state snapshot of this app/window first")
}
return (try element(base, rootIndex), base)
}
private func rememberSnapshot(
query: String,
app: AppDescriptor,
@@ -416,19 +436,30 @@ final class Provider {
}
}
private func currentSnapshot(params: [String: JSONValue]) throws -> Snapshot {
private func currentSnapshot(params: [String: JSONValue], needsFocus: Bool = false) throws -> Snapshot {
pruneSnapshotCache()
let cached = try cachedSnapshot(params: params)
let requestedIndexes = try requestedElementIndexes(params)
let observeParams = params.merging(["noScreenshot": .bool(true)]) { _, replacement in replacement }
// Why: elements read with --element-index, focused ones included, may lie past the whole-window node limit,
// so only their subtree can re-find them.
if let scope = cached?.scope,
requestedIndexes.isEmpty ? needsFocus : requestedIndexes.allSatisfy(scope.walkedIndexes.contains),
let scoped = try? observe(params: observeParams.merging(["rootElementIndex": .number(Double(scope.rootIndex))]) { _, replacement in replacement }),
!requestedIndexes.isEmpty || scoped.focusedElementId != nil {
try validateRequestedElements(cached: cached, current: scoped, requestedIndexes: requestedIndexes)
return scoped
}
// Why: cached AX frames can be stale after a window move or resize, and
// stale geometry can turn an intended action into a misclick.
let snapshot = try observe(params: params.merging(["noScreenshot": .bool(true)]) { _, replacement in replacement })
try validateRequestedElements(cached: cached, current: snapshot, params: params)
let snapshot = try observe(params: observeParams)
try validateRequestedElements(cached: cached, current: snapshot, requestedIndexes: requestedIndexes)
return snapshot
}
private func currentKeyboardSnapshot(params: [String: JSONValue]) throws -> Snapshot {
// Why: keyboard actions need fresh focused-element state, never pixels.
try currentSnapshot(params: params.merging(["noScreenshot": .bool(true)]) { _, replacement in replacement })
try currentSnapshot(params: params.merging(["noScreenshot": .bool(true)]) { _, replacement in replacement }, needsFocus: true)
}
private func cachedSnapshot(params: [String: JSONValue]) throws -> Snapshot? {
@@ -473,17 +504,24 @@ final class Provider {
(isExplicitSnapshotNamespace(namespace) ? nil : snapshots[key])
}
private func validateRequestedElements(cached: Snapshot?, current: Snapshot, params: [String: JSONValue]) throws {
let requestedIndexes = try ["elementIndex", "fromElementIndex", "toElementIndex"].compactMap { key -> Int? in
private func requestedElementIndexes(_ params: [String: JSONValue]) throws -> [Int] {
try ["elementIndex", "fromElementIndex", "toElementIndex"].compactMap { key -> Int? in
guard params[key]?.number != nil else { return nil }
return try optionalInteger(params, key)
}
}
private func validateRequestedElements(cached: Snapshot?, current: Snapshot, requestedIndexes: [Int]) throws {
guard !requestedIndexes.isEmpty else { return }
guard let cached else {
throw ProviderError.coded("element_not_found", "element indexes require a fresh get-app-state snapshot for this app/window")
}
for index in requestedIndexes {
guard let expected = cached.elements[index], let actual = current.elements[index] else {
// Why: a subtree read also carries the window's earlier records, which prove nothing about the element now.
guard let expected = cached.elements[index],
let actual = current.elements[index],
current.scope?.walkedIndexes.contains(index) ?? true
else {
throw ProviderError.coded("element_not_found", "element \(index) is stale; run get-app-state again and use a fresh element index")
}
guard expected.signature == actual.signature else {
@@ -553,6 +591,7 @@ final class Provider {
"annotatedScreenshot": false,
"elementFrames": true,
"ocr": false,
"disabledState": true,
],
"actions": [
"click": true,
@@ -657,6 +696,7 @@ final class Provider {
windowId: CGWindowID?,
windowIndex: Int?,
restoreWindow: Bool,
subtree: (root: ElementRecord, base: Snapshot)?,
previousSnapshot: (CGWindowID) -> Snapshot?
) throws -> Snapshot {
guard accessibilityTrustedSettled() else {
@@ -702,11 +742,29 @@ final class Provider {
focused: focusedElement(appElement: appElement),
compactBrowserTabs: app.isKnownBrowser
)
renderer.render(window)
if let subtree {
guard let ancestors = ancestorChain(of: subtree.root.element, in: window) else {
throw ProviderError.coded("element_not_found", "element \(subtree.root.index) is no longer in this window; run get-app-state again and use a fresh element index")
}
renderer.render(subtree.root.element, ancestors: ancestors)
} else {
renderer.render(window)
}
if renderer.appStoppedResponding {
throw AccessibilityMessaging.appNotResponding(app.name)
}
let indexes = renderer.carryOverIndexes(from: previousSnapshot(capture.windowId))
let previous = subtree?.base ?? previousSnapshot(capture.windowId)
let indexes = renderer.carryOverIndexes(from: previous)
var elements = renderer.records
var elementOrder = indexes.order
if let subtree {
// Why: elements outside the subtree keep resolving, so the agent can still act on what the whole-window read showed.
// Re-reading the same subtree replaces its last walk, so rows scrolled away don't pile up.
let replaced = subtree.base.scope.flatMap { $0.rootIndex == subtree.root.index ? $0.walkedIndexes : nil } ?? []
let kept = subtree.base.elements.filter { !replaced.contains($0.key) && renderer.records[$0.key] == nil }
elements = kept.merging(renderer.records) { _, walked in walked }
elementOrder = subtree.base.elementOrder.filter { kept[$0] != nil } + indexes.order
}
let screenshot = includeScreenshot ? capture.screenshotPayload() : nil
let screenshotStatus: ScreenshotStatus = if screenshot != nil {
.captured
@@ -724,17 +782,18 @@ final class Provider {
windowBounds: capture.bounds,
windowId: capture.windowId,
windowLayer: capture.layer,
treeText: renderTreeText(app: app, title: title, bounds: capture.bounds, lines: renderer.lines, focused: renderer.focusedSummary),
treeText: renderTreeText(app: app, title: title, rootIndex: subtree?.root.index, lines: renderer.lines, focused: renderer.focusedSummary),
focusedElementId: renderer.focusedElementId,
screenshot: screenshot,
screenshotStatus: screenshotStatus,
screenshotScale: screenshotScale(screenshot: screenshot, bounds: capture.bounds),
screenshotEngine: capture.image?.engine,
elements: renderer.records,
elementOrder: indexes.order,
elements: elements,
elementOrder: elementOrder,
nextFreshElementIndex: indexes.nextFreshIndex,
truncated: renderer.truncated,
maxDepthReached: renderer.maxDepthReached,
scope: subtree.map { SnapshotScope(rootIndex: $0.root.index, walkedIndexes: Set(indexes.order)) },
appWindowIds: windowCandidates.map(\.windowId).sorted()
)
}
@@ -750,39 +809,43 @@ final class Provider {
"scale": payload.scale,
]
}
return [
"snapshot": [
"id": snapshot.id,
"app": [
"name": snapshot.app.name,
"bundleId": jsonNullable(snapshot.app.bundleId),
"pid": Int(snapshot.app.pid),
],
"window": [
"id": Int(snapshot.windowId),
"title": snapshot.windowTitle,
"x": Int(snapshot.windowBounds.origin.x.rounded()),
"y": Int(snapshot.windowBounds.origin.y.rounded()),
"width": Int(snapshot.windowBounds.width.rounded()),
"height": Int(snapshot.windowBounds.height.rounded()),
"isMinimized": false,
"isOffscreen": false,
"screenIndex": jsonNullable(screenIndex(for: snapshot.windowBounds)),
"platform": [
"layer": snapshot.windowLayer,
],
],
"coordinateSpace": "window",
"treeText": snapshot.treeText,
"elementCount": snapshot.elements.count,
"focusedElementId": snapshot.focusedElementId as Any,
"truncation": [
"truncated": snapshot.truncated,
"maxNodes": TreeRenderer.maxNodes,
"maxDepth": TreeRenderer.maxDepth,
"maxDepthReached": snapshot.maxDepthReached,
var snapshotPayload: [String: Any] = [
"id": snapshot.id,
"app": [
"name": snapshot.app.name,
"bundleId": jsonNullable(snapshot.app.bundleId),
"pid": Int(snapshot.app.pid),
],
"window": [
"id": Int(snapshot.windowId),
"title": snapshot.windowTitle,
"x": Int(snapshot.windowBounds.origin.x.rounded()),
"y": Int(snapshot.windowBounds.origin.y.rounded()),
"width": Int(snapshot.windowBounds.width.rounded()),
"height": Int(snapshot.windowBounds.height.rounded()),
"isMinimized": false,
"isOffscreen": false,
"screenIndex": jsonNullable(screenIndex(for: snapshot.windowBounds)),
"platform": [
"layer": snapshot.windowLayer,
],
],
"coordinateSpace": "window",
"treeText": snapshot.treeText,
"elementCount": snapshot.scope?.walkedIndexes.count ?? snapshot.elements.count,
"focusedElementId": snapshot.focusedElementId as Any,
"truncation": [
"truncated": snapshot.truncated,
"maxNodes": TreeRenderer.maxNodes,
"maxDepth": TreeRenderer.maxDepth,
"maxDepthReached": snapshot.maxDepthReached,
],
]
if let scope = snapshot.scope {
snapshotPayload["rootElementIndex"] = scope.rootIndex
}
return [
"snapshot": snapshotPayload,
"screenshot": screenshot,
"screenshotStatus": renderScreenshotStatus(snapshot.screenshotStatus, snapshot: snapshot),
]
@@ -813,6 +876,7 @@ final class Provider {
}
if let elementIndex = try optionalInteger(params, "elementIndex") {
let record = try element(snapshot, elementIndex)
try requireEnabled(record, snapshot: snapshot)
if !foreground {
try requireBackgroundClickAllowed(backgroundClickHit(record.element, snapshot: snapshot))
}
@@ -832,22 +896,20 @@ final class Provider {
actionName: actionName
)
}
if let point = center(record.localFrame, in: snapshot.windowBounds) {
try clickPointer(at: point, button: button, count: count, modifiers: modifiers, snapshot: snapshot, foreground: foreground, element: record.element)
guard unselectedRow else {
return actionMetadata(
path: "synthetic",
fallbackReason: "actionUnsupported",
verification: unverifiedAction(reason: "synthetic_input")
)
}
return rowClickMetadata(
try RowSelectionClick.confirm(record.element, ax: rowSelection),
let point = try pointerTarget(record, snapshot: snapshot)
try clickPointer(at: point, button: button, count: count, modifiers: modifiers, snapshot: snapshot, foreground: foreground, element: record.element)
guard unselectedRow else {
return actionMetadata(
path: "synthetic",
actionName: nil
fallbackReason: "actionUnsupported",
verification: unverifiedAction(reason: "synthetic_input")
)
}
throw ProviderError.coded("element_not_clickable", "element \(record.index) has no clickable frame")
return rowClickMetadata(
try RowSelectionClick.confirm(record.element, ax: rowSelection),
path: "synthetic",
actionName: nil
)
}
let point = try coordinatePoint(params: params, xKey: "x", yKey: "y", snapshot: snapshot)
try clickPointer(at: point, button: button, count: count, modifiers: modifiers, snapshot: snapshot, foreground: foreground)
@@ -873,6 +935,38 @@ final class Provider {
}
}
private func requireEnabled(_ record: ElementRecord, snapshot: Snapshot) throws {
let ax = AccessibilityActionability(pid: snapshot.app.pid)
let enabled = ElementActionability.waitUntilEnabled(record.element, ax: ax)
if ax.unanswered { throw AccessibilityMessaging.appNotResponding(snapshot.app.name) }
guard enabled else { throw notEnabledError(record) }
}
/// The screen point a pointer click on the element should use, once it is enabled, in view and on top there.
private func pointerTarget(_ record: ElementRecord, snapshot: Snapshot) throws -> CGPoint {
// Why: its own wait budget, so time spent enabling or trying AXPress cannot cut short the settle after a scroll.
let ax = AccessibilityActionability(pid: snapshot.app.pid)
let target = try ElementActionability.pointerTarget(record.element, windowFrame: snapshot.windowBounds, ax: ax)
if ax.unanswered { throw AccessibilityMessaging.appNotResponding(snapshot.app.name) }
switch target {
case let .ready(point):
return point
case .notEnabled:
throw notEnabledError(record)
case .noFrame:
throw ProviderError.coded("element_not_clickable", "element \(record.index) has no clickable frame; no click was sent")
case let .outOfView(scrolled):
let reason = scrolled ? "is still out of view after scrolling it into view" : "is out of view and cannot be scrolled into view"
throw ProviderError.coded("element_not_clickable", "element \(record.index) \(reason), so no click was sent; scroll its container, run get-app-state again and retry")
case let .covered(by: cover):
throw ProviderError.coded("element_not_clickable", "element \(record.index) is covered by \(describeElement(cover)), so no click was sent; close or finish what covers it, run get-app-state again and retry")
}
}
private func notEnabledError(_ record: ElementRecord) -> ProviderError {
.coded("element_not_enabled", "element \(record.index) is disabled, so no input was sent; do what enables it first, then run get-app-state and retry once its line no longer lists disabled")
}
private func performClickAction(record: ElementRecord, mouseButton: MouseButtonSelection) throws -> String? {
if mouseButton == .right {
return try performAction(record.element, "AXShowMenu") ? "AXShowMenu" : nil
@@ -893,6 +987,10 @@ final class Provider {
guard let action else {
throw ProviderError.coded("action_not_supported", "'\(requested)' is not a valid secondary action for element \(record.index)")
}
// Why: scrolling a control into view does not operate it.
if action != "AXScrollToVisible" {
try requireEnabled(record, snapshot: snapshot)
}
guard try performAction(record.element, action) else {
throw ProviderError.coded("accessibility_error", "AXUIElementPerformAction(\(action)) failed")
}
@@ -903,6 +1001,7 @@ final class Provider {
let snapshot = try currentSnapshot(params: params)
let record = try element(snapshot, try requiredInteger(params, "elementIndex"))
let expected = try requiredStringAllowingEmpty(params, "value")
try requireEnabled(record, snapshot: snapshot)
guard isSettable(record.element, kAXValueAttribute as String) else {
throw ProviderError.coded("value_not_settable", "element \(record.index) is not settable")
}
@@ -948,14 +1047,16 @@ final class Provider {
private func typeText(params: [String: JSONValue]) throws -> [String: Any] {
let snapshot = try currentKeyboardSnapshot(params: params)
let text = try requiredString(params, "text")
if let focused = focusedRecord(snapshot), let verification = try TextInput.replaceSelection(focused.element, with: text) {
let focused = focusedRecord(snapshot)?.element
if let focused, let verification = try TextInput.replaceSelection(focused, with: text) {
return actionMetadata(path: "accessibility", actionName: "AXReplaceSelection", verification: verification)
}
let insertion = TextInput.Insertion(into: focused, text: text)
try deliverKeys(try withTransportErrors { try BackgroundInputTransport.textEvents(text) }, snapshot: snapshot, params: params)
return actionMetadata(
path: "synthetic",
actionName: "typeText",
verification: unverifiedAction(reason: "synthetic_input")
verification: insertion?.verification() ?? unverifiedAction(reason: "synthetic_input")
)
}
@@ -990,17 +1091,19 @@ final class Provider {
private func pasteText(params: [String: JSONValue]) throws -> [String: Any] {
let snapshot = try currentKeyboardSnapshot(params: params)
let text = try requiredString(params, "text")
if let focused = focusedRecord(snapshot), let verification = try TextInput.replaceSelection(focused.element, with: text) {
let focused = focusedRecord(snapshot)?.element
if let focused, let verification = try TextInput.replaceSelection(focused, with: text) {
return actionMetadata(path: "accessibility", actionName: "AXReplaceSelection", verification: verification)
}
let pasteKeys = try Input.keyEvents("cmd+v")
let insertion = TextInput.Insertion(into: focused, text: text)
try Input.withPasteboardText(text) {
try deliverKeys(pasteKeys, snapshot: snapshot, params: params)
}
return actionMetadata(
path: "clipboard",
actionName: "paste",
verification: unverifiedAction(reason: "clipboard_paste")
verification: insertion?.verification() ?? unverifiedAction(reason: "clipboard_paste")
)
}
@@ -1425,6 +1528,18 @@ private func pointerRecipient(
return .focused(syntheticClickRecipient(pid: ownerPID, windowId: candidate.windowId))
}
/// The element's parents from `window` down, or nil when it is no longer inside `window`.
private func ancestorChain(of element: AXUIElement, in window: AXUIElement) -> [AXUIElement]? {
var chain: [AXUIElement] = []
var current = element
while !CFEqual(current, window) {
guard chain.count < 256, let parent = copyElement(current, kAXParentAttribute as String) else { return nil }
chain.append(parent)
current = parent
}
return chain.reversed()
}
private func containingWindow(_ element: AXUIElement) -> AXUIElement? {
var current = element
for _ in 0..<64 {
@@ -1980,6 +2095,94 @@ private final class AccessibilityRowSelection: RowSelectionAccessibility {
}
}
/// Once the app stops answering, later reads return nothing at once so a hung app costs one timeout, not dozens.
private final class AccessibilityActionability: ElementActionabilityAccessibility {
private let appElement: AXUIElement
// Why: wall time, since one slow AX read can take the full 3 s messaging timeout.
private let deadline = CFAbsoluteTimeGetCurrent() + 0.5
private(set) var unanswered = false
init(pid: pid_t) {
appElement = AXUIElementCreateApplication(pid)
}
func isEnabled(_ element: AXUIElement) -> Bool? {
read(element, kAXEnabledAttribute as String) as? Bool
}
func frame(of element: AXUIElement) -> CGRect? {
var point = CGPoint.zero
var size = CGSize.zero
guard let position = read(element, kAXPositionAttribute as String),
let extent = read(element, kAXSizeAttribute as String),
CFGetTypeID(position) == AXValueGetTypeID(),
CFGetTypeID(extent) == AXValueGetTypeID(),
AXValueGetValue(position as! AXValue, .cgPoint, &point),
AXValueGetValue(extent as! AXValue, .cgSize, &size)
else {
return nil
}
return CGRect(origin: point, size: size)
}
func role(of element: AXUIElement) -> String? {
read(element, kAXRoleAttribute as String) as? String
}
func parent(of element: AXUIElement) -> AXUIElement? {
guard let value = read(element, kAXParentAttribute as String), CFGetTypeID(value) == AXUIElementGetTypeID() else {
return nil
}
return (value as! AXUIElement)
}
func isSame(_ lhs: AXUIElement, _ rhs: AXUIElement) -> Bool {
CFEqual(lhs, rhs)
}
func isModal(_ window: AXUIElement) -> Bool {
read(window, kAXModalAttribute as String) as? Bool == true
}
/// Asks the target app itself: background input reaches it whatever other apps' windows are on top.
func element(at point: CGPoint) -> AXUIElement? {
guard !unanswered, Float(point.x).isFinite, Float(point.y).isFinite else { return nil }
var found: AXUIElement?
let start = CFAbsoluteTimeGetCurrent()
let result = AXUIElementCopyElementAtPosition(appElement, Float(point.x), Float(point.y), &found)
unanswered = AccessibilityMessaging.timedOut(result, since: start)
return result == .success ? found : nil
}
func scrollToVisible(_ element: AXUIElement) throws -> Bool {
try performAction(element, "AXScrollToVisible")
}
func waitBeforeRetry() -> Bool {
let interval = 0.05
guard !unanswered, CFAbsoluteTimeGetCurrent() + interval < deadline else { return false }
Thread.sleep(forTimeInterval: interval)
return true
}
private func read(_ element: AXUIElement, _ attribute: String) -> CFTypeRef? {
guard !unanswered else { return nil }
var value: CFTypeRef?
let start = CFAbsoluteTimeGetCurrent()
let result = AXUIElementCopyAttributeValue(element, attribute as CFString, &value)
unanswered = AccessibilityMessaging.timedOut(result, since: start)
return result == .success ? value : nil
}
}
private func describeElement(_ element: AXUIElement) -> String {
let role = stringAttribute(element, kAXRoleAttribute as String) ?? "an element"
guard let label = stringAttribute(element, kAXTitleAttribute as String) ?? stringAttribute(element, kAXDescriptionAttribute as String) else {
return role
}
return "\(role) \"\(preview(label, maxLength: 60))\""
}
private func frame(_ element: AXUIElement, windowBounds: CGRect) -> CGRect? {
var positionValue: CFTypeRef?
var sizeValue: CFTypeRef?
@@ -2054,15 +2257,18 @@ private func mouseButton(_ raw: String?) throws -> MouseButtonSelection {
}
}
private func renderTreeText(app: AppDescriptor, title: String, bounds: CGRect, lines: [String], focused: String?) -> String {
private func renderTreeText(app: AppDescriptor, title: String, rootIndex: Int?, lines: [String], focused: String?) -> String {
var output = [
"App=\(app.bundleId ?? app.name.replacingOccurrences(of: " ", with: "_")) (pid \(app.pid))",
"Window: \"\(sanitize(title))\", App: \(sanitize(app.name)).",
"",
]
if let rootIndex {
output.append("Showing element \(rootIndex) and its descendants.")
}
output.append("")
output.append(contentsOf: lines)
output.append("")
output.append(focused.map { "The focused UI element is \($0)." } ?? "No UI element is currently focused.")
output.append(focused.map { "The focused UI element is \($0)." } ?? (rootIndex == nil ? "No UI element is currently focused." : "No UI element inside this one is focused."))
return output.joined(separator: "\n")
}
@@ -2106,15 +2312,6 @@ private final class TreeRenderer {
func render(_ element: AXUIElement, depth: Int = 0, ancestors: [AXUIElement] = []) {
guard !reader.appStoppedResponding else { return }
guard nextIndex < Self.maxNodes else {
truncated = true
return
}
guard depth < Self.maxDepth else {
truncated = true
maxDepthReached = true
return
}
guard !ancestors.contains(where: { CFEqual($0, element) }) else { return }
let role = reader.stringAttribute(element, kAXRoleAttribute as String) ?? "AXUnknown"
@@ -2165,9 +2362,7 @@ private final class TreeRenderer {
webAreaDepth: webAreaDepth
)
if SnapshotRenderHeuristics.shouldElide(node) {
for child in children {
render(child, depth: depth, ancestors: ancestors + [element])
}
renderChildren(children, depth: depth, ancestors: ancestors + [element])
return
}
@@ -2190,9 +2385,8 @@ private final class TreeRenderer {
return
}
if compactBrowserTabs, let tabStripCompaction = tabStripCompaction(parent: node, children: children) {
for (childIndex, child) in children.enumerated() where tabStripCompaction.retainedIndexes.contains(childIndex) {
render(child, depth: depth + 1, ancestors: ancestors + [element])
}
let retained = children.enumerated().filter { tabStripCompaction.retainedIndexes.contains($0.offset) }.map(\.element)
renderChildren(retained, depth: depth + 1, ancestors: ancestors + [element])
lines.append(
String(repeating: "\t", count: depth + 1) +
"... \(tabStripCompaction.omittedCount) inactive browser tabs omitted"
@@ -2200,14 +2394,26 @@ private final class TreeRenderer {
return
}
let childLineStart = lines.count
for child in children {
render(child, depth: depth + 1, ancestors: ancestors + [element])
}
renderChildren(children, depth: depth + 1, ancestors: ancestors + [element])
if compactBrowserTabs {
compactRenderedBrowserTabs(parent: node, startLine: childLineStart, depth: depth + 1)
}
}
/// Stops at the node or depth limit with a note of how many children were left, so the agent can read that subtree.
private func renderChildren(_ children: [AXUIElement], depth: Int, ancestors: [AXUIElement]) {
for (position, child) in children.enumerated() {
// Why: browser-tab compaction drops records, so the limit counts what is kept, as on Linux and Windows.
guard records.count < Self.maxNodes, depth < Self.maxDepth else {
truncated = true
maxDepthReached = maxDepthReached || depth >= Self.maxDepth
lines.append(String(repeating: "\t", count: depth) + "... \(children.count - position) more not shown (snapshot limit)")
return
}
render(child, depth: depth, ancestors: ancestors)
}
}
private func tabStripCompaction(parent: SnapshotRenderNode, children: [AXUIElement]) -> SnapshotTabStripCompaction? {
let childNodes = children.map { child in
let role = reader.stringAttribute(child, kAXRoleAttribute as String) ?? "AXUnknown"
@@ -3094,6 +3300,49 @@ private enum TextInput {
return verifiedAction(property: "focusedText")
}
/// Text sent as keys or a paste: what the focused field should read once it lands.
struct Insertion {
let element: AXUIElement
let expected: String
/// Nil when the field can't prove the result: none focused, a secure field, no readable value and selection, or text a readback can't confirm.
init?(into element: AXUIElement?, text: String) {
guard let element,
!AXSnapshotReader().isSecureTextElement(element),
let current = rawStringAttribute(element, kAXValueAttribute as String),
// Why: settle re-reads the whole value every 25 ms; a terminal's scrollback or a long document is too costly.
current.utf16.count <= 64 * 1024
else {
return nil
}
let selection = TextInput.selectedTextRange(element).flatMap { range -> Range<Int>? in
range.location >= 0 && range.length >= 0 && range.length <= Int.max - range.location
? range.location..<(range.location + range.length) : nil
}
guard let expected = TextInsertionReadback.expectedValue(current: current, selection: selection, inserting: text) else {
return nil
}
self.element = element
self.expected = expected
}
/// Nil when the readback can't tell: the field stopped answering or was still changing at the cap.
func verification() -> [String: Any]? {
let outcome = TextInsertionReadback.settle(expected: expected) {
rawStringAttribute(element, kAXValueAttribute as String)
}
switch outcome {
case .landed:
return verifiedAction(property: "focusedText")
case .mismatch:
// Why: the field may hold part of the text, so the result never shows what it reads.
return unverifiedAction(reason: "text_mismatch")
case .undetermined:
return nil
}
}
}
static func selectAll(_ element: AXUIElement) -> Bool {
guard let current = rawStringAttribute(element, kAXValueAttribute as String) else {
return false
@@ -0,0 +1,209 @@
import CoreGraphics
/// The accessibility reads an element action needs before it sends input, so the policy runs against a fake tree in tests.
public protocol ElementActionabilityAccessibility {
associatedtype Element
/// AXEnabled; nil when the element does not publish it.
func isEnabled(_ element: Element) -> Bool?
/// Frame in global top-left screen points.
func frame(of element: Element) -> CGRect?
func role(of element: Element) -> String?
func parent(of element: Element) -> Element?
func isSame(_ lhs: Element, _ rhs: Element) -> Bool
/// AXModal: an app-modal window blocks input to the app's other windows.
func isModal(_ window: Element) -> Bool
/// The target app's own topmost element at a screen point; nil when the app cannot say.
func element(at point: CGPoint) -> Element?
/// Asks the app to scroll the element into view; false when the element does not offer that.
func scrollToVisible(_ element: Element) throws -> Bool
/// Pauses before the next check; false once the wait budget is spent.
func waitBeforeRetry() -> Bool
}
/// Checks that an element can take an action before any input is sent: it is enabled and, for pointer
/// input, it is in view (scrolled there if needed) and is what the app hit-tests under the click point.
public enum ElementActionability {
public enum PointerTarget<Element> {
case ready(CGPoint)
case notEnabled
case noFrame
/// Nothing of the element shows inside its window and scroll areas.
case outOfView(scrolled: Bool)
/// Another element is on top at every point tried.
case covered(by: Element)
}
static let maxAncestorDepth = 64
/// Waits briefly for a disabled element to enable; an element that publishes no AXEnabled counts as enabled.
public static func waitUntilEnabled<AX: ElementActionabilityAccessibility>(_ element: AX.Element, ax: AX) -> Bool {
while ax.isEnabled(element) == false {
guard ax.waitBeforeRetry() else { return false }
}
return true
}
/// Where a pointer click on the element lands, re-checked until it holds or the wait budget runs out.
public static func pointerTarget<AX: ElementActionabilityAccessibility>(
_ element: AX.Element,
windowFrame: CGRect,
ax: AX
) throws -> PointerTarget<AX.Element> {
var scrolled = false
var scrollTried = false
var settledFrame: CGRect?
var last: PointerTarget<AX.Element> = .noFrame
// Why: one scroll at most, so a target that keeps failing cannot scroll the user's view around.
func scrollOnce() throws -> Bool {
guard !scrollTried else { return false }
scrollTried = true
scrolled = try ax.scrollToVisible(element)
return scrolled
}
repeat {
guard ax.isEnabled(element) != false else {
last = .notEnabled
continue
}
guard let frame = ax.frame(of: element), frame.width > 0, frame.height > 0 else {
return .noFrame
}
// Why: a scroll can animate, and a click mid-animation lands where the element used to be.
if scrolled, settledFrame.map({ !framesMatch($0, frame) }) ?? true {
settledFrame = frame
last = .outOfView(scrolled: true)
continue
}
let (clip, ancestors) = clipRect(of: element, windowFrame: windowFrame, ax: ax)
let visible = frame.intersection(clip)
// Why: an element bigger than its viewport cannot be brought fully into view, so it is clicked where it shows.
let fits = frame.width <= clip.width && frame.height <= clip.height
if visible.isEmpty || (fits && !visible.contains(CGPoint(x: frame.midX, y: frame.midY))), try scrollOnce() {
last = .outOfView(scrolled: true)
continue
}
guard !visible.isEmpty else {
last = .outOfView(scrolled: scrolled)
if scrolled { continue }
return last
}
switch hitTarget(element, visible: visible, ancestors: ancestors, ax: ax) {
case let .direct(point):
return .ready(point)
case let .ancestorOnly(point):
// Why: a scroller not exposed as AXScrollArea (a web overflow div) can hide the element behind its own container.
guard try scrollOnce() else { return .ready(point) }
last = .outOfView(scrolled: true)
case let .covered(by: cover):
last = .covered(by: cover)
// Why: a table or sticky header inside the scroll area can cover a row that scrolling would clear.
_ = try scrollOnce()
}
} while ax.waitBeforeRetry()
return last
}
/// The part of the screen the element can show in (its window and every scroll area it sits in), plus its ancestors.
static func clipRect<AX: ElementActionabilityAccessibility>(
of element: AX.Element,
windowFrame: CGRect,
ax: AX
) -> (CGRect, [AX.Element]) {
var visible = windowFrame
var ancestors: [AX.Element] = []
var current = element
for _ in 0..<maxAncestorDepth {
guard let parent = ax.parent(of: current) else { break }
ancestors.append(parent)
let role = ax.role(of: parent)
if role == "AXScrollArea", let clip = ax.frame(of: parent) {
visible = visible.intersection(clip)
}
if role == "AXWindow" { break }
current = parent
}
return (visible, ancestors)
}
enum Hit<Element> {
/// The element, inside it, or a hit that shows nothing covers it.
case direct(CGPoint)
/// Only the element's own ancestors answered, as when it is see-through to hit tests.
case ancestorOnly(CGPoint)
case covered(by: Element)
}
static func hitTarget<AX: ElementActionabilityAccessibility>(
_ element: AX.Element,
visible: CGRect,
ancestors: [AX.Element],
ax: AX
) -> Hit<AX.Element> {
var ancestorPoint: CGPoint?
var coveredBy: AX.Element?
for point in candidatePoints(in: visible) {
guard let hit = ax.element(at: point) else { return .direct(point) }
switch owner(of: hit, element, ancestors: ancestors, ax: ax) {
case .clear:
return .direct(point)
case .ancestor:
ancestorPoint = ancestorPoint ?? point
case .cover:
coveredBy = coveredBy ?? hit
}
}
if let ancestorPoint { return .ancestorOnly(ancestorPoint) }
// SAFETY: candidatePoints is never empty, so a loop without a direct or ancestor hit recorded a cover.
return .covered(by: coveredBy!)
}
private enum HitOwner {
/// The element, inside it, or a hit that shows nothing of the target window is on top.
case clear
case ancestor
case cover
}
private static func owner<AX: ElementActionabilityAccessibility>(
of hit: AX.Element,
_ element: AX.Element,
ancestors: [AX.Element],
ax: AX
) -> HitOwner {
if ancestors.contains(where: { ax.isSame($0, hit) }) { return .ancestor }
var current = hit
for _ in 0..<maxAncestorDepth {
if ax.isSame(current, element) { return .clear }
// Why: reaching the element's own container first means the hit sits beside the element, on top of it.
if ancestors.contains(where: { ax.isSame($0, current) }) { return .cover }
switch ax.role(of: current) {
case "AXWindow":
// Why: the app hit-tests its topmost window, but background input is stamped with the target window,
// so only a modal window on top blocks it; the foreground fence checks other windows on top.
return ax.isModal(current) ? .cover : .clear
case "AXApplication":
// Why: the app found none of its windows there (hidden, minimized, another Space), which says nothing.
return .clear
default:
break
}
guard let parent = ax.parent(of: current) else { return .cover }
current = parent
}
return .cover
}
/// The centre first, then the middle of each quadrant, so a partly covered element is still reachable.
static func candidatePoints(in rect: CGRect) -> [CGPoint] {
let center = CGPoint(x: rect.midX, y: rect.midY)
let quarters = [(0.25, 0.25), (0.75, 0.25), (0.25, 0.75), (0.75, 0.75)].map {
CGPoint(x: rect.minX + rect.width * $0.0, y: rect.minY + rect.height * $0.1)
}
return [center] + quarters
}
private static func framesMatch(_ lhs: CGRect, _ rhs: CGRect) -> Bool {
abs(lhs.minX - rhs.minX) < 0.5 && abs(lhs.minY - rhs.minY) < 0.5
&& abs(lhs.width - rhs.width) < 0.5 && abs(lhs.height - rhs.height) < 0.5
}
}
@@ -0,0 +1,81 @@
import Foundation
/// Checks that text sent as keys or a paste landed: predict the field's value, then read it back.
public enum TextInsertionReadback {
public enum Outcome: Equatable {
case landed
case mismatch
/// The field stopped answering, or was still changing when the wait ran out.
case undetermined
}
/// The value a field should hold once `text` replaces its selection. `selection` is in UTF-16 offsets, as
/// AXSelectedTextRange reports it. Nil means a readback can't prove the result: a non-empty field with no
/// selection, a range outside the value or inside a character, text with control characters (Return or Tab
/// can submit, end editing or move focus instead of being stored), or a value the field already holds.
public static func expectedValue(current: String, selection: Range<Int>?, inserting text: String) -> String? {
guard !text.unicodeScalars.contains(where: { CharacterSet.controlCharacters.contains($0) }) else {
return nil
}
let units = Array(current.utf16)
let range: Range<Int>
if let selection {
guard selection.lowerBound >= 0, selection.upperBound <= units.count else {
return nil
}
range = selection
} else if units.isEmpty {
range = 0..<0
} else {
return nil
}
let prefix = Array(units[..<range.lowerBound])
let suffix = Array(units[range.upperBound...])
let before = String(decoding: prefix, as: UTF16.self)
let after = String(decoding: suffix, as: UTF16.self)
// Why: a boundary inside a surrogate pair decodes to U+FFFD, which no real field would read back.
guard Array(before.utf16) == prefix, Array(after.utf16) == suffix else {
return nil
}
let expected = before + text + after
return sameText(expected, current) ? nil : expected
}
/// Reads the field until it holds `expected`. Keys reach it through the app's event queue, so it can still be
/// filling after the last key is posted: each change restarts the quiet window, up to `capSeconds` in all.
public static func settle(
expected: String,
quietSeconds: Double = 0.5,
capSeconds: Double = 2,
intervalSeconds: Double = 0.025,
now: () -> Double = CFAbsoluteTimeGetCurrent,
sleep: (Double) -> Void = { Thread.sleep(forTimeInterval: $0) },
read: () -> String?
) -> Outcome {
let start = now()
var readback = read()
// Why: an AX read can block for seconds; the quiet window counts from the answer, not the ask.
var quietDeadline = now() + quietSeconds
while let current = readback, !sameText(current, expected) {
let time = now()
// Why: past the cap a field may still be filling or a read may have blocked through the quiet window; calling it a mismatch invites typing the rest twice.
guard time < start + capSeconds else {
return .undetermined
}
guard time < quietDeadline else {
return .mismatch
}
sleep(intervalSeconds)
readback = read()
if readback != current {
quietDeadline = now() + quietSeconds
}
}
return readback == nil ? .undetermined : .landed
}
// Why: Chromium contenteditables store typed trailing or repeated spaces as no-break spaces.
private static func sameText(_ lhs: String, _ rhs: String) -> Bool {
lhs.replacingOccurrences(of: "\u{00A0}", with: " ") == rhs.replacingOccurrences(of: "\u{00A0}", with: " ")
}
}
@@ -0,0 +1,221 @@
import CoreGraphics
import OrcaComputerUseMacOSCore
import XCTest
final class ElementActionabilityTests: XCTestCase {
private final class FakeTree: ElementActionabilityAccessibility {
struct Node {
var role: String
var parent: Int?
var frame: CGRect
var enabled: Bool? = true
var modal = false
/// Hides the parts of descendants outside its frame from hit tests, as a scroller does.
var clips = false
/// Where the node sits after AXScrollToVisible; nil when it offers no scroll.
var scrollsTo: CGRect?
}
var nodes: [Int: Node]
var retriesLeft = 5
var onRetry: (FakeTree) -> Void = { _ in }
private(set) var scrollRequests = 0
init(_ nodes: [Int: Node]) {
self.nodes = nodes
}
func isEnabled(_ element: Int) -> Bool? { nodes[element]?.enabled }
func frame(of element: Int) -> CGRect? { nodes[element]?.frame }
func role(of element: Int) -> String? { nodes[element]?.role }
func parent(of element: Int) -> Int? { nodes[element]?.parent }
func isSame(_ lhs: Int, _ rhs: Int) -> Bool { lhs == rhs }
func isModal(_ window: Int) -> Bool { nodes[window]?.modal == true }
/// The highest-numbered node under the point is on top.
func element(at point: CGPoint) -> Int? {
nodes.keys.filter { shows($0, at: point) }.max()
}
private func shows(_ id: Int, at point: CGPoint) -> Bool {
guard let node = nodes[id], node.frame.contains(point) else { return false }
var ancestor = node.parent
while let current = ancestor.flatMap({ nodes[$0] }) {
if current.clips, !current.frame.contains(point) { return false }
ancestor = current.parent
}
return true
}
func scrollToVisible(_ element: Int) throws -> Bool {
guard let target = nodes[element]?.scrollsTo else { return false }
scrollRequests += 1
nodes[element]?.frame = target
return true
}
func waitBeforeRetry() -> Bool {
guard retriesLeft > 0 else { return false }
retriesLeft -= 1
onRetry(self)
return true
}
}
private let window = CGRect(x: 0, y: 0, width: 400, height: 300)
/// A window with a scroll area showing y 0-200 and a button inside it.
private func scrollingWindow(button: FakeTree.Node) -> FakeTree {
FakeTree([
1: .init(role: "AXWindow", parent: nil, frame: window),
2: .init(role: "AXScrollArea", parent: 1, frame: CGRect(x: 0, y: 0, width: 400, height: 200), clips: true),
3: button,
])
}
func testADisabledElementIsRefusedWithoutAPoint() throws {
let tree = scrollingWindow(button: .init(role: "AXButton", parent: 2, frame: CGRect(x: 10, y: 10, width: 80, height: 20), enabled: false))
guard case .notEnabled = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("a disabled button must not get a click point")
}
XCTAssertFalse(ElementActionability.waitUntilEnabled(3, ax: tree))
}
func testAnElementThatEnablesWithinTheWaitIsClicked() {
let tree = scrollingWindow(button: .init(role: "AXButton", parent: 2, frame: CGRect(x: 10, y: 10, width: 80, height: 20), enabled: false))
tree.onRetry = { $0.nodes[3]?.enabled = true }
XCTAssertTrue(ElementActionability.waitUntilEnabled(3, ax: tree))
}
func testAnElementBelowTheScrolledAreaIsScrolledIntoViewThenClicked() throws {
let tree = scrollingWindow(button: .init(
role: "AXButton",
parent: 2,
frame: CGRect(x: 10, y: 250, width: 80, height: 20),
scrollsTo: CGRect(x: 10, y: 150, width: 80, height: 20)
))
guard case let .ready(point) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("the button should be clickable once scrolled into view")
}
XCTAssertEqual(tree.scrollRequests, 1)
XCTAssertEqual(point, CGPoint(x: 50, y: 160))
}
func testAnElementThatCannotBeScrolledIntoViewIsRefused() throws {
let tree = scrollingWindow(button: .init(role: "AXButton", parent: 2, frame: CGRect(x: 10, y: 250, width: 80, height: 20)))
guard case .outOfView(scrolled: false) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("a button clipped by its scroll area must not be clicked")
}
}
func testAnElementBiggerThanItsScrollAreaIsClickedWhereItShowsWithoutScrolling() throws {
let tree = scrollingWindow(button: .init(
role: "AXGroup",
parent: 2,
frame: CGRect(x: 0, y: 100, width: 400, height: 1000),
scrollsTo: CGRect(x: 0, y: 0, width: 400, height: 1000)
))
guard case let .ready(point) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("the visible part of the group should take the click")
}
XCTAssertEqual(tree.scrollRequests, 0)
XCTAssertEqual(point, CGPoint(x: 200, y: 150))
}
func testACoveredElementIsRefusedAndNamesWhatCoversIt() throws {
let tree = scrollingWindow(button: .init(role: "AXButton", parent: 2, frame: CGRect(x: 10, y: 10, width: 80, height: 20)))
tree.nodes[4] = .init(role: "AXSheet", parent: 1, frame: CGRect(x: 0, y: 0, width: 400, height: 100))
guard case let .covered(by: cover) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("a button under a sheet must not be clicked")
}
XCTAssertEqual(cover, 4)
}
func testARowUnderAStickyHeaderIsScrolledClearThenClicked() throws {
let tree = scrollingWindow(button: .init(
role: "AXRow",
parent: 2,
frame: CGRect(x: 0, y: 0, width: 100, height: 20),
scrollsTo: CGRect(x: 0, y: 40, width: 100, height: 20)
))
tree.nodes[4] = .init(role: "AXGroup", parent: 2, frame: CGRect(x: 0, y: 0, width: 400, height: 30))
guard case let .ready(point) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("the row should be clicked once scrolled out from under the header")
}
XCTAssertEqual(tree.scrollRequests, 1)
XCTAssertEqual(point, CGPoint(x: 50, y: 50))
}
func testAnotherWindowOfTheAppOnTopDoesNotCoverTheTarget() throws {
let tree = scrollingWindow(button: .init(role: "AXButton", parent: 2, frame: CGRect(x: 10, y: 10, width: 80, height: 20)))
tree.nodes[5] = .init(role: "AXWindow", parent: nil, frame: CGRect(x: 0, y: 0, width: 200, height: 200))
guard case .ready = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("background input goes to the target window even under another window of the app")
}
tree.nodes[5]?.modal = true
guard case .covered(by: 5) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("an app-modal window on top blocks input to the target window")
}
}
func testAPartlyCoveredElementIsClickedWhereItShows() throws {
let tree = scrollingWindow(button: .init(role: "AXButton", parent: 2, frame: CGRect(x: 0, y: 0, width: 100, height: 100)))
tree.nodes[4] = .init(role: "AXGroup", parent: 2, frame: CGRect(x: 0, y: 0, width: 60, height: 100))
guard case let .ready(point) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("the uncovered right half should take the click")
}
XCTAssertEqual(point, CGPoint(x: 75, y: 25))
}
func testAHitOnTheElementsOwnChildCountsAsTheElement() throws {
let tree = scrollingWindow(button: .init(role: "AXRow", parent: 2, frame: CGRect(x: 0, y: 0, width: 100, height: 20)))
tree.nodes[4] = .init(role: "AXStaticText", parent: 3, frame: CGRect(x: 0, y: 0, width: 100, height: 20))
guard case .ready = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("a hit on the row's own text is a hit on the row")
}
}
func testAnElementHiddenByAScrollerThatIsNotAScrollAreaIsScrolledIntoViewFirst() throws {
// A web overflow div shows as AXGroup (2), so only the window (1) answers below it.
let tree = FakeTree([
1: .init(role: "AXWindow", parent: nil, frame: window),
2: .init(role: "AXGroup", parent: 1, frame: CGRect(x: 0, y: 0, width: 400, height: 100), clips: true),
3: .init(
role: "AXLink",
parent: 2,
frame: CGRect(x: 10, y: 150, width: 80, height: 20),
scrollsTo: CGRect(x: 10, y: 50, width: 80, height: 20)
),
])
guard case let .ready(point) = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("the link should be clicked once scrolled into its container's view")
}
XCTAssertEqual(tree.scrollRequests, 1)
XCTAssertEqual(point, CGPoint(x: 50, y: 60))
}
func testAHitOnTheElementsAncestorMeansNothingCoversIt() throws {
// The group (9) is above the image (3) in hit order, as when the image ignores hit tests.
let tree = FakeTree([
1: .init(role: "AXWindow", parent: nil, frame: window),
3: .init(role: "AXImage", parent: 9, frame: CGRect(x: 10, y: 10, width: 20, height: 20)),
9: .init(role: "AXGroup", parent: 1, frame: window),
])
guard case .ready = try ElementActionability.pointerTarget(3, windowFrame: window, ax: tree) else {
return XCTFail("a hit on the element's own ancestor is not a covering element")
}
}
}
@@ -0,0 +1,86 @@
import XCTest
@testable import OrcaComputerUseMacOSCore
final class TextInsertionReadbackTests: XCTestCase {
func testInsertionReplacesTheSelectionInUTF16Offsets() {
XCTAssertEqual(
TextInsertionReadback.expectedValue(current: "a😀bcd", selection: 3..<5, inserting: "XY"),
"a😀XYd"
)
XCTAssertEqual(TextInsertionReadback.expectedValue(current: "", selection: nil, inserting: "hi"), "hi")
}
func testUnpredictableInsertionsReturnNil() {
XCTAssertNil(TextInsertionReadback.expectedValue(current: "abc", selection: nil, inserting: "d"))
XCTAssertNil(TextInsertionReadback.expectedValue(current: "abc", selection: 2..<4, inserting: "d"))
XCTAssertNil(TextInsertionReadback.expectedValue(current: "a😀", selection: 2..<2, inserting: "d"))
XCTAssertNil(TextInsertionReadback.expectedValue(current: "", selection: 0..<0, inserting: "send\n"))
XCTAssertNil(TextInsertionReadback.expectedValue(current: "", selection: 0..<0, inserting: "a\tb"))
XCTAssertNil(TextInsertionReadback.expectedValue(current: "hello", selection: 0..<5, inserting: "hello"))
}
func testFieldStillFillingPastTheQuietWindowLands() {
// One character every 0.4 s: each read is past the first 0.5 s window, but each change restarts it.
let reads = ["", "h", "he", "hel", "hell", "hello"]
XCTAssertEqual(settle(expected: "hello", reads: reads, secondsPerRead: 0.4), .landed)
}
func testSlowFirstReadStillGetsAQuietWindow() {
var clock = 0.0
var reads = ["h", "hello"][...]
let outcome = TextInsertionReadback.settle(
expected: "hello",
now: { clock },
sleep: { clock += $0 },
read: {
if reads.count == 2 { clock += 0.6 }
return reads.popFirst()
}
)
XCTAssertEqual(outcome, .landed)
}
func testReadBlockedPastTheCapIsUndetermined() {
var clock = 0.0
var reads = ["h", "h"][...]
let outcome = TextInsertionReadback.settle(
expected: "hello",
now: { clock },
sleep: { clock += $0 },
read: {
if reads.count == 1 { clock = 2.2 }
return reads.popFirst()
}
)
XCTAssertEqual(outcome, .undetermined)
}
func testContentEditableNoBreakSpacesLand() {
XCTAssertEqual(settle(expected: "a b ", reads: ["a \u{00A0}b\u{00A0}"], secondsPerRead: 0.025), .landed)
}
func testFieldThatDropsTheTextIsAMismatch() {
XCTAssertEqual(settle(expected: "hello", reads: Array(repeating: "", count: 100), secondsPerRead: 0.025), .mismatch)
}
func testFieldThatStopsAnsweringIsUndetermined() {
XCTAssertEqual(settle(expected: "hello", reads: ["", "h"], secondsPerRead: 0.025), .undetermined)
}
func testFieldStillFillingAtTheCapIsUndetermined() {
let reads = (0..<100).map { String(repeating: "a", count: $0) }
XCTAssertEqual(settle(expected: String(repeating: "a", count: 200), reads: reads, secondsPerRead: 0.1), .undetermined)
}
private func settle(expected: String, reads: [String], secondsPerRead: Double) -> TextInsertionReadback.Outcome {
var clock = 0.0
var remaining = reads[...]
return TextInsertionReadback.settle(
expected: expected,
now: { clock },
sleep: { _ in clock += secondsPerRead },
read: { remaining.popFirst() }
)
}
}
@@ -51,6 +51,10 @@ public static class OrcaDesktopWin32 {
}
return Foreground;
}
public static uint GetWindowThreadProcessId(IntPtr hwnd, out uint processId) {
processId = hwnd == new IntPtr(101) ? 4242u : 1u;
return 1;
}
public static bool SetCursorPos(int x, int y) {
Calls.Add("move:" + x + "," + y);
return true;
@@ -74,7 +78,7 @@ $functions = @(
"Get-OrcaRequiredNumber", "Get-OrcaPositiveInteger", "Get-OrcaPositiveNumber",
"Get-OrcaScreenPoint", "Get-OrcaElementScreenPoint", "Get-OrcaModifierVirtualKey",
"Get-OrcaClickModifierVirtualKeys", "Send-OrcaMouseClick", "Send-OrcaDrag", "Invoke-OrcaOperation",
"Assert-OrcaInputAllowed"
"Assert-OrcaInputAllowed", "Test-OrcaTargetTookForeground"
)
foreach ($definition in $ast.FindAll({ param($node) $node -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false)) {
if ($definition.Name -in $functions) { . ([scriptblock]::Create($definition.Extent.Text)) }
@@ -87,6 +91,7 @@ function Get-OrcaRootElement { $null }
function Get-OrcaWindowFrame { @{ x = [OrcaDesktopWin32]::WindowX; y = 200 } }
function Find-OrcaElement($RootElement, $Record) { $Record }
function Invoke-OrcaPrimaryAction($Element) { $null -ne $Element }
function Invoke-OrcaScrollPattern($Element, $RootElement, $Direction, $Pages) { $null -ne $Element }
function New-OrcaSnapshot { [pscustomobject]@{} }
foreach ($case in @(
@@ -112,6 +117,7 @@ foreach ($case in @(
if ($inputCalls.Count -eq 0) { throw "$($case.tool) did not send pointer input after activation" }
if ([OrcaDesktopWin32]::FocusReads -lt 2) { throw "$($case.tool) did not wait for activation" }
Assert-TestEqual $inputCalls[0] "move:505,206" "$($case.tool) geometry after delayed activation"
Assert-TestEqual $result.action.delivery "foreground" "$($case.tool) pointer delivery"
} else {
Assert-TestEqual $denied $true "$($case.tool) denied activation"
Assert-TestEqual $inputCalls.Count 0 "$($case.tool) denied activation sends no pointer or modifier input"
@@ -119,10 +125,18 @@ foreach ($case in @(
}
}
[OrcaDesktopWin32]::Reset($false)
$result = Invoke-OrcaOperation ([pscustomobject]@{ tool = "click"; app = "Fixture"; element = [pscustomobject]@{ index = 1 } })
Assert-TestEqual $result.action.path "accessibility" "pattern click path"
Assert-TestEqual ([OrcaDesktopWin32]::Calls.Count) 0 "pattern click bypasses activation and global input"
foreach ($case in @(
@{ tool = "click" },
@{ tool = "scroll"; direction = "down"; pages = 1 }
)) {
[OrcaDesktopWin32]::Reset($false)
$operation = [pscustomobject]@{ app = "Fixture"; element = [pscustomobject]@{ index = 1 } }
foreach ($key in $case.Keys) { $operation | Add-Member -NotePropertyName $key -NotePropertyValue $case[$key] }
$result = Invoke-OrcaOperation $operation
Assert-TestEqual $result.action.path "accessibility" "pattern $($case.tool) path"
Assert-TestEqual $result.action.delivery "background" "pattern $($case.tool) delivery"
Assert-TestEqual ([OrcaDesktopWin32]::Calls.Count) 0 "pattern $($case.tool) bypasses activation and global input"
}
foreach ($case in @(
@{ tool = "click"; element = [pscustomobject]@{ index = 1 } },
@{ tool = "click"; x = 5; y = 6; restoreWindow = $true },
@@ -137,4 +151,10 @@ foreach ($case in @(
if ($message -notlike "target_elevated:*") { throw "$($case.tool) elevated target expected target_elevated, received '$message'" }
Assert-TestEqual ([OrcaDesktopWin32]::Calls.Count) 0 "$($case.tool) elevated target sends no activation or input"
}
# Why: WPF activates its own window for most patterns; the result must say so rather than claim background.
[OrcaDesktopWin32]::Reset($false)
function Invoke-OrcaPrimaryAction($Element) { [OrcaDesktopWin32]::Foreground = [IntPtr]101; $true }
$result = Invoke-OrcaOperation ([pscustomobject]@{ tool = "click"; app = "Fixture"; element = [pscustomobject]@{ index = 1 } })
Assert-TestEqual $result.action.path "accessibility" "self-activating pattern click path"
Assert-TestEqual $result.action.delivery "foreground" "self-activating pattern click delivery"
Write-Output "windows-pointer-tests-ok"
+226 -31
View File
@@ -104,6 +104,9 @@ public static class OrcaDesktopWin32 {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint processId);
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int x, int y);
@@ -561,6 +564,14 @@ function Restore-OrcaWindow($Process) {
[void][OrcaDesktopWin32]::SetForegroundWindow([IntPtr]$Process.MainWindowHandle)
}
function Test-OrcaTargetTookForeground([IntPtr]$Before, $Process) {
$after = [OrcaDesktopWin32]::GetForegroundWindow()
if ($after -eq $Before) { return $false }
$owner = [uint32]0
[void][OrcaDesktopWin32]::GetWindowThreadProcessId($after, [ref]$owner)
$owner -eq $Process.Id
}
function Test-OrcaWindowFocused([IntPtr]$WindowHandle) {
[OrcaDesktopWin32]::GetForegroundWindow() -eq $WindowHandle
}
@@ -647,15 +658,50 @@ function Get-OrcaValueText($Element) {
}
}
function Get-OrcaActions($Element) {
function Get-OrcaRangeValueText($Element) {
try {
$pattern = $Element.GetCurrentPattern([Windows.Automation.RangeValuePattern]::Pattern)
([double]$pattern.Current.Value).ToString([Globalization.CultureInfo]::InvariantCulture)
} catch {
""
}
}
function Test-OrcaRangeValueWritable($Element) {
try {
-not $Element.GetCurrentPattern([Windows.Automation.RangeValuePattern]::Pattern).Current.IsReadOnly
} catch {
$false
}
}
function Get-OrcaExpandCollapseActions($Element) {
try {
$state = $Element.GetCurrentPattern([Windows.Automation.ExpandCollapsePattern]::Pattern).Current.ExpandCollapseState
} catch {
return @()
}
switch ($state) {
([Windows.Automation.ExpandCollapseState]::Collapsed) { return @("Expand") }
([Windows.Automation.ExpandCollapseState]::Expanded) { return @("Collapse") }
([Windows.Automation.ExpandCollapseState]::PartiallyExpanded) { return @("Expand", "Collapse") }
}
@()
}
function Get-OrcaActions($Element, $Patterns = $null) {
if ($null -eq $Patterns) { $Patterns = @($Element.GetSupportedPatterns()) }
$actions = New-Object System.Collections.Generic.List[string]
foreach ($pattern in $Element.GetSupportedPatterns()) {
foreach ($pattern in $Patterns) {
$name = [string]$pattern.ProgrammaticName
if ($name -like "InvokePatternIdentifiers.Pattern") { $actions.Add("Invoke") }
elseif ($name -like "TogglePatternIdentifiers.Pattern") { $actions.Add("Toggle") }
elseif ($name -like "SelectionItemPatternIdentifiers.Pattern") { $actions.Add("Select") }
elseif ($name -like "ScrollPatternIdentifiers.Pattern") { $actions.Add("Scroll") }
elseif ($name -like "ValuePatternIdentifiers.Pattern") { $actions.Add("SetValue") }
elseif ($name -like "RangeValuePatternIdentifiers.Pattern") { if (Test-OrcaRangeValueWritable $Element) { $actions.Add("SetValue") } }
elseif ($name -like "ExpandCollapsePatternIdentifiers.Pattern") { foreach ($action in @(Get-OrcaExpandCollapseActions $Element)) { $actions.Add($action) } }
elseif ($name -like "ScrollItemPatternIdentifiers.Pattern") { $actions.Add("ScrollToVisible") }
}
@($actions | Select-Object -Unique)
}
@@ -751,6 +797,11 @@ function Test-OrcaPlainTextSubtree($Element, [int]$MaxDepth = 4) {
function New-OrcaElementRecord($Element, [int]$Index, $WindowFrame) {
$controlType = try { [string]$Element.Current.ControlType.ProgrammaticName } catch { "" }
$nativeWindowHandle = try { [int64]$Element.Current.NativeWindowHandle } catch { 0 }
$patterns = @($Element.GetSupportedPatterns())
$value = Get-OrcaValueText $Element
if ([string]::IsNullOrEmpty($value) -and $patterns -contains [Windows.Automation.RangeValuePattern]::Pattern) {
$value = Get-OrcaRangeValueText $Element
}
[pscustomobject]@{
index = $Index
runtimeId = @(Get-OrcaRuntimeId $Element)
@@ -759,14 +810,19 @@ function New-OrcaElementRecord($Element, [int]$Index, $WindowFrame) {
controlType = $controlType
localizedControlType = Get-OrcaProperty $Element "LocalizedControlType"
className = Get-OrcaProperty $Element "ClassName"
value = Get-OrcaValueText $Element
value = $value
isSelected = Test-OrcaElementSelected $Element
isDisabled = Test-OrcaElementDisabled $Element
nativeWindowHandle = $nativeWindowHandle
frame = Get-OrcaElementFrame $Element $WindowFrame
actions = @(Get-OrcaActions $Element)
actions = @(Get-OrcaActions $Element $patterns)
}
}
function Test-OrcaElementDisabled($Element) {
try { return -not [bool]$Element.Current.IsEnabled } catch { return $false }
}
function Test-OrcaElementSelected($Element) {
try {
$pattern = $Element.GetCurrentPattern([Windows.Automation.SelectionItemPattern]::Pattern)
@@ -789,12 +845,20 @@ function Render-OrcaTree($RootElement, $WindowFrame, [bool]$CompactBrowserTabs =
# Tab compaction shrinks records mid-walk, so $records.Count would reuse retained indexes.
$nextIndex = [ref]0
function Visit-OrcaNode($Node, [int]$Depth) {
if ($records.Count -ge $MaxNodes -or $Depth -gt $MaxDepth) {
$truncation.truncated = $true
if ($Depth -gt $MaxDepth) { $truncation.maxDepthReached = $true }
return
function Visit-OrcaChildren($Children, [int]$Depth) {
for ($i = 0; $i -lt $Children.Count; $i++) {
if ($records.Count -ge $MaxNodes -or $Depth -gt $MaxDepth) {
$truncation.truncated = $true
if ($Depth -gt $MaxDepth) { $truncation.maxDepthReached = $true }
# Marks where the walk stopped, so the agent can read that parent's subtree by index.
$lines.Add(("`t" * $Depth) + "... $($Children.Count - $i) more not shown (snapshot limit)")
return
}
Visit-OrcaNode $Children.Item($i) $Depth
}
}
function Visit-OrcaNode($Node, [int]$Depth) {
$identity = try { (@($Node.GetRuntimeId()) -join ".") } catch { [Guid]::NewGuid().ToString() }
if (-not $seen.Add($identity)) { return }
@@ -815,16 +879,15 @@ function Render-OrcaTree($RootElement, $WindowFrame, [bool]$CompactBrowserTabs =
}
}
if (($roleKey -in @("pane", "group", "custom", "unknown")) -and [string]::IsNullOrWhiteSpace($title) -and [string]::IsNullOrWhiteSpace($record.value) -and $meaningfulActions.Count -eq 0 -and $null -eq $genericSummary -and $children.Count -le 1) {
for ($i = 0; $i -lt $children.Count; $i++) {
Visit-OrcaNode $children.Item($i) $Depth
}
Visit-OrcaChildren $children $Depth
return
}
$records.Add($record)
$nextIndex.Value++
$line = "$($record.index) $role $(Format-OrcaSnapshotText $title)".TrimEnd()
$traits = if ($record.isDisabled) { " (disabled)" } else { "" }
$line = "$($record.index) $role$traits $(Format-OrcaSnapshotText $title)".TrimEnd()
$line += Format-OrcaValueSegment $roleKey $title $record.value
if (-not [string]::IsNullOrWhiteSpace($genericSummary) -and $genericSummary -ne $title) {
$line += ", Text: " + (Format-OrcaSnapshotText $genericSummary)
@@ -841,9 +904,7 @@ function Render-OrcaTree($RootElement, $WindowFrame, [bool]$CompactBrowserTabs =
if (-not [string]::IsNullOrWhiteSpace($genericSummary) -or (Test-OrcaSuppressChildren $roleKey $title $record.value $genericSummary)) { return }
$childLineStart = $lines.Count
for ($i = 0; $i -lt $children.Count; $i++) {
Visit-OrcaNode $children.Item($i) ($Depth + 1)
}
Visit-OrcaChildren $children ($Depth + 1)
if ($CompactBrowserTabs) {
Compress-OrcaRenderedBrowserTabs $records $lines $childLineStart ($Depth + 1)
}
@@ -1019,14 +1080,21 @@ function Get-OrcaScreenshot([bool]$IncludeScreenshot, $WindowFrame, [IntPtr]$Win
}
}
function New-OrcaSnapshot([string]$Query, [bool]$IncludeScreenshot, $WindowId = $null, $WindowIndex = $null, [bool]$RestoreWindow = $false) {
function New-OrcaSnapshot([string]$Query, [bool]$IncludeScreenshot, $WindowId = $null, $WindowIndex = $null, [bool]$RestoreWindow = $false, $TreeRoot = $null) {
$process = Find-OrcaProcess $Query
Assert-OrcaWindowTarget $process $WindowId $WindowIndex
# Root first: its hang probe must run before ShowWindow, which blocks on a hung window.
$root = Get-OrcaRootElement $process
if ($RestoreWindow) { Restore-OrcaWindow $process }
$windowFrame = Get-OrcaWindowFrame $process $root
$tree = Render-OrcaTree $root $windowFrame (Test-OrcaBrowserProcess $process)
$walkRoot = $root
if ($null -ne $TreeRoot) {
$walkRoot = Find-OrcaElement $root $TreeRoot
if ($null -eq $walkRoot) {
throw "stale element: element $($TreeRoot.index) is gone; run get-app-state again and use a fresh element index"
}
}
$tree = Render-OrcaTree $walkRoot $windowFrame (Test-OrcaBrowserProcess $process)
$screenshot = Get-OrcaScreenshot $IncludeScreenshot $windowFrame ([IntPtr]$process.MainWindowHandle)
[pscustomobject]@{
@@ -1099,7 +1167,7 @@ function Get-OrcaHandshake {
supports = [pscustomobject]@{
apps = [pscustomobject]@{ list = $true; bundleIds = $false; pids = $true }
windows = [pscustomobject]@{ list = $true; targetById = $true; targetByIndex = $true; focus = $false; moveResize = $false }
observation = [pscustomobject]@{ screenshot = $true; annotatedScreenshot = $false; elementFrames = $true; ocr = $false }
observation = [pscustomobject]@{ screenshot = $true; annotatedScreenshot = $false; elementFrames = $true; ocr = $false; disabledState = $true }
actions = [pscustomobject]@{
click = $true
typeText = $true
@@ -1158,7 +1226,8 @@ function Invoke-OrcaPrimaryAction($Element) {
function Invoke-OrcaNamedAction($Element, [string]$Action) {
$wanted = ""
if ($null -ne $Action) { $wanted = $Action.Trim().ToLowerInvariant() }
# Why: accept the rendered name ("ScrollToVisible") and macOS's spaced form ("scroll to visible").
if ($null -ne $Action) { $wanted = ($Action -replace "\s+", "").ToLowerInvariant() }
switch ($wanted) {
"invoke" {
$pattern = $Element.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern)
@@ -1175,21 +1244,128 @@ function Invoke-OrcaNamedAction($Element, [string]$Action) {
$pattern.Toggle()
return $true
}
"expand" {
$pattern = $Element.GetCurrentPattern([Windows.Automation.ExpandCollapsePattern]::Pattern)
$pattern.Expand()
return $true
}
"collapse" {
$pattern = $Element.GetCurrentPattern([Windows.Automation.ExpandCollapsePattern]::Pattern)
$pattern.Collapse()
return $true
}
"scrolltovisible" {
$pattern = $Element.GetCurrentPattern([Windows.Automation.ScrollItemPattern]::Pattern)
$pattern.ScrollIntoView()
return $true
}
default {
return $false
}
}
}
function Test-OrcaRangeValueMatches([string]$Actual, [double]$Expected) {
# Why: allow float32 rounding (0.1 reads back 0.100000001), but cap it so a snapped neighbour never verifies at any size.
$actualNumber = 0.0
[double]::TryParse($Actual, [Globalization.NumberStyles]::Float, [Globalization.CultureInfo]::InvariantCulture, [ref]$actualNumber) -and
[Math]::Abs($actualNumber - $Expected) -le [Math]::Min(1e-6 * [Math]::Max(1.0, [Math]::Abs($Expected)), 1e-3)
}
function Set-OrcaElementValue($Element, [string]$Value) {
try {
$pattern = $Element.GetCurrentPattern([Windows.Automation.ValuePattern]::Pattern)
if (-not $pattern.Current.IsReadOnly) {
$pattern.SetValue($Value)
return $true
return [pscustomobject]@{ verification = $null }
}
} catch {}
$false
if (-not (Test-OrcaRangeValueWritable $Element)) { return $null }
$range = $Element.GetCurrentPattern([Windows.Automation.RangeValuePattern]::Pattern)
$culture = [Globalization.CultureInfo]::InvariantCulture
$number = 0.0
if (-not [double]::TryParse($Value, [Globalization.NumberStyles]::Float, $culture, [ref]$number) -or [double]::IsNaN($number)) {
throw "value must be a number for this range control"
}
$minimum = [double]$range.Current.Minimum
$maximum = [double]$range.Current.Maximum
if ($number -lt $minimum -or $number -gt $maximum) {
throw "value $Value is outside this range control's $($minimum.ToString($culture))..$($maximum.ToString($culture))"
}
$range.SetValue($number)
# Why: Chromium applies the write asynchronously, so poll briefly like macOS's settled readback.
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
while ($true) {
$actual = Get-OrcaRangeValueText $Element
$matched = Test-OrcaRangeValueMatches $actual $number
if ($matched -or $stopwatch.ElapsedMilliseconds -ge 500) { break }
Start-Sleep -Milliseconds 25
}
$verification = if ($matched) {
[pscustomobject]@{ state = "verified"; property = "value"; expected = $Value; actualPreview = $actual }
} elseif ([string]::IsNullOrEmpty($actual)) {
# Why: a failed read is not evidence the write failed; only a read-back number can contradict it.
[pscustomobject]@{ state = "unverified"; reason = "readback_unsupported"; expected = $Value }
} else {
[pscustomobject]@{ state = "unverified"; reason = "value_mismatch"; expected = $Value; actualPreview = $actual }
}
[pscustomobject]@{ verification = $verification }
}
function Get-OrcaScrollPattern($Element, $RootElement, [bool]$Vertical) {
$rootId = Get-OrcaRuntimeId $RootElement
$current = $Element
# Why: an item's ScrollPattern lives on its list or viewport, the same container a wheel at its center would scroll.
while ($null -ne $current) {
try {
$pattern = $current.GetCurrentPattern([Windows.Automation.ScrollPattern]::Pattern)
$scrollable = if ($Vertical) { $pattern.Current.VerticallyScrollable } else { $pattern.Current.HorizontallyScrollable }
if ($scrollable) { return $pattern }
} catch {}
if (Test-OrcaSameRuntimeId (Get-OrcaRuntimeId $current) $rootId) { break }
$current = try { [Windows.Automation.TreeWalker]::RawViewWalker.GetParent($current) } catch { $null }
}
$null
}
function Get-OrcaScrollPercent($Pattern, [bool]$Vertical) {
try {
if ($Vertical) { return [double]$Pattern.Current.VerticalScrollPercent }
[double]$Pattern.Current.HorizontalScrollPercent
} catch {
$null
}
}
function Invoke-OrcaScrollPattern($Element, $RootElement, [string]$Direction, [double]$Pages) {
# Why: ScrollPattern moves in whole pages; fractional pages keep the wheel, as on macOS.
if ($null -eq $Element -or $Pages -ne [Math]::Floor($Pages)) { return $false }
$vertical = $Direction -in @("up", "down")
$pattern = Get-OrcaScrollPattern $Element $RootElement $vertical
if ($null -eq $pattern) { return $false }
$amount = if ($Direction -in @("down", "right")) { [Windows.Automation.ScrollAmount]::LargeIncrement } else { [Windows.Automation.ScrollAmount]::LargeDecrement }
$none = [Windows.Automation.ScrollAmount]::NoAmount
# Why: without a readable position the loop can't tell the end of the content, so the wheel handles it.
$before = Get-OrcaScrollPercent $pattern $vertical
if ($null -eq $before) { return $false }
for ($page = 0; $page -lt $Pages; $page++) {
try {
if ($vertical) { $pattern.Scroll($none, $amount) } else { $pattern.Scroll($amount, $none) }
} catch {
# Why: a refusal before any page moved falls back to the wheel; after that it is the end of the content.
return $page -gt 0
}
# Why: WPF and Chromium move the viewport after Scroll returns; an unmoved or unreadable percent after the wait is the end.
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
while ($true) {
$after = Get-OrcaScrollPercent $pattern $vertical
if ($after -ne $before -or $stopwatch.ElapsedMilliseconds -ge 500) { break }
Start-Sleep -Milliseconds 25
}
if ($null -eq $after -or $after -eq $before) { break }
$before = $after
}
$true
}
function Get-OrcaRequiredNumber($Value, [string]$Name) {
@@ -1446,7 +1622,7 @@ function Invoke-OrcaOperation($Operation) {
return [pscustomobject]@{ ok = $true; app = $list.app; windows = @($list.windows) }
}
if ($Operation.tool -eq "get_app_state") {
return [pscustomobject]@{ ok = $true; snapshot = New-OrcaSnapshot $Operation.app $includeScreenshot $Operation.windowId $Operation.windowIndex ([bool]$Operation.restoreWindow) }
return [pscustomobject]@{ ok = $true; snapshot = New-OrcaSnapshot $Operation.app $includeScreenshot $Operation.windowId $Operation.windowIndex ([bool]$Operation.restoreWindow) $Operation.root }
}
$process = Find-OrcaProcess $Operation.app
@@ -1462,6 +1638,8 @@ function Invoke-OrcaOperation($Operation) {
if ($Operation.tool -in @("type_text", "press_key", "hotkey", "paste_text")) {
Assert-OrcaKeyboardFocus $handle $Operation
}
# Why: pattern paths need an element; reading the foreground only then keeps coordinate input untouched.
$foregroundBefore = if ($null -ne $element) { [OrcaDesktopWin32]::GetForegroundWindow() } else { [IntPtr]::Zero }
$action = $null
switch ($Operation.tool) {
@@ -1491,7 +1669,8 @@ function Invoke-OrcaOperation($Operation) {
$action = [pscustomobject]@{ path = "accessibility"; actionName = $Operation.action; fallbackReason = $null }
}
"scroll" {
$delta = 120 * [int][Math]::Ceiling((Get-OrcaPositiveNumber $Operation.pages "pages"))
$pages = Get-OrcaPositiveNumber $Operation.pages "pages"
$delta = 120 * [int][Math]::Ceiling($pages)
$mouseEvent = $MouseEvents.Wheel
if ($Operation.direction -eq "down") {
$delta = -1 * $delta
@@ -1503,12 +1682,18 @@ function Invoke-OrcaOperation($Operation) {
} elseif ($Operation.direction -ne "up") {
throw "unsupported scroll direction: $($Operation.direction)"
}
$windowFrame = Restore-OrcaPointerWindow $process $root
$point = Get-OrcaElementScreenPoint $element
if ($null -eq $point) { $point = Get-OrcaScreenPoint $Operation $windowFrame }
[void][OrcaDesktopWin32]::SetCursorPos([int]$point.x, [int]$point.y)
[OrcaDesktopWin32]::mouse_event($mouseEvent, 0, 0, $delta, [UIntPtr]::Zero)
$action = [pscustomobject]@{ path = "synthetic"; actionName = "scroll"; fallbackReason = $null }
if (Invoke-OrcaScrollPattern $element $root $Operation.direction $pages) {
$action = [pscustomobject]@{ path = "accessibility"; actionName = "scroll"; fallbackReason = $null }
} else {
# Why: the wheel scrolls whatever is under the pointer, so the window must be on top.
$windowFrame = Restore-OrcaPointerWindow $process $root
$point = Get-OrcaElementScreenPoint $element
if ($null -eq $point) { $point = Get-OrcaScreenPoint $Operation $windowFrame }
[void][OrcaDesktopWin32]::SetCursorPos([int]$point.x, [int]$point.y)
[OrcaDesktopWin32]::mouse_event($mouseEvent, 0, 0, $delta, [UIntPtr]::Zero)
$fallbackReason = if ($null -ne $element) { "actionUnsupported" } else { $null }
$action = [pscustomobject]@{ path = "synthetic"; actionName = "scroll"; fallbackReason = $fallbackReason }
}
}
"drag" {
$windowFrame = Restore-OrcaPointerWindow $process $root
@@ -1548,15 +1733,25 @@ function Invoke-OrcaOperation($Operation) {
$action = [pscustomobject]@{ path = "clipboard"; actionName = "paste"; fallbackReason = $null; verification = [pscustomobject]@{ state = "unverified"; reason = "clipboard_paste" } }
}
"set_value" {
if ($null -eq $element -or -not (Set-OrcaElementValue $element ([string]$Operation.value))) {
$written = if ($null -ne $element) { Set-OrcaElementValue $element ([string]$Operation.value) } else { $null }
if ($null -eq $written) {
throw "element value is not settable"
}
$action = [pscustomobject]@{ path = "accessibility"; actionName = "setValue"; fallbackReason = $null }
if ($null -ne $written.verification) {
$action | Add-Member -NotePropertyName verification -NotePropertyValue $written.verification
}
}
default {
throw "unsupported tool: $($Operation.tool)"
}
}
# Why: input paths raise the target; WPF also activates its own window for most patterns, so those are measured.
$delivery = "foreground"
if ($action.path -eq "accessibility" -and -not [bool]$Operation.restoreWindow -and -not (Test-OrcaTargetTookForeground $foregroundBefore $process)) {
$delivery = "background"
}
$action | Add-Member -NotePropertyName delivery -NotePropertyValue $delivery
try {
try {
+32 -4
View File
@@ -46,6 +46,28 @@ In a large window, look for one control with `get-app-state --query <text>`: it
ORCA computer get-app-state --app com.apple.finder --query Downloads --json
```
A snapshot reads at most `truncation.maxNodes` elements and `maxDepth` levels. When it stops early, `truncation.truncated` is true and each cut-off place shows a `... N more not shown (snapshot limit)` line, indented like the children it stands for. To read them, pass the parent element's index (the nearest line above with less indentation) as `get-app-state --element-index <n>`: it reads only that element and its descendants, with the full limit. Elements already shown keep their indexes and hidden ones get new ones, and you can act on them. Action results show the whole window again, so read the subtree again before acting on another hidden element.
```text
ORCA computer get-app-state --app com.apple.Safari --element-index 312 --json
```
## Waiting
Never `sleep` between actions. When the UI changes on its own after an action (a save finishes, a dialog opens, a button becomes clickable), wait for the change with `wait`. It returns as soon as the condition holds and prints the matching elements or windows; it fails with `wait_timeout` if the condition does not hold in time (default 10 s, `--timeout <ms>` up to 120000).
```text
ORCA computer wait --app <app> --text "Saved" --json
ORCA computer wait --app <app> --enabled "Continue" --json
ORCA computer wait --app <app> --window-title "Save As" --json
```
- `--text <text>`: an element line contains the text (case-insensitive, like `--query`).
- `--enabled <text>`: an element contains the text and none of the elements containing it is disabled. Use text only the intended control shows; a label that repeats the button text also has to be enabled.
- `--window-title <text>`: one of the app's windows has the text in its title, as `list-windows` reports them. Then target that window with its `--window-id` or `--window-index`. On Windows, `list-windows` reports only the app's main window, so wait for a dialog with `--text` instead.
`wait` only reads the app; it never acts, raises or restores a window. The app or window may be missing at first; `wait` keeps checking until it appears. Element indexes in the output come from a fresh tree, so you can act on them next.
## App Selectors
Prefer bundle IDs from `list-apps`; names are acceptable when unambiguous. Use `pid:<number>` only when bundle ID or name matching is ambiguous.
@@ -67,6 +89,7 @@ ORCA computer list-apps --json
ORCA computer list-windows --app <app> --json
ORCA computer get-app-state --app <app> --json
ORCA computer get-app-state --app <app> --restore-window --json
ORCA computer wait --app <app> (--text <text> | --enabled <text> | --window-title <text>) [--timeout <ms>] --json
ORCA computer click --app <app> --element-index <index> --json
ORCA computer click --app <app> --x 100 --y 100 --json
ORCA computer click --app <app> --x 100 --y 100 --modifiers CmdOrCtrl+Shift --json
@@ -99,12 +122,14 @@ printf '%s' "$TEXT" | ORCA computer set-value --app <app> --element-index <index
- `unverified (accessibility action unasserted)` means the accessibility call succeeded but no post-state assertion was made.
- `unverified (suspected noop)` means the accessibility call succeeded but the window's tree and the app's windows were unchanged about a second later. Web and Electron controls often ignore it. Do not repeat the same element click; if the effect you expect would show in the window, retry once with `click --x --y` at the control from a fresh screenshot. If the effect lives elsewhere (clipboard, another app), check there first.
- `unverified (synthetic input)` means input was fired into the void and is unverifiable.
- `unverified (text mismatch)` means typed or pasted text was read back and the focused field does not hold what inserting it should produce: it may be missing, partly entered, reformatted or autocompleted, or taken by a control that does not store it (terminals and canvas editors leave their input field empty). Do not type it again blindly, or it may land twice; check a fresh screenshot or `get-app-state` first.
- Missing verification metadata is unverified, including responses from older runtimes.
- Never report an unverified action as success. If it could have sent, submitted, bought, or deleted something, say the effect is unproven.
- Prefer semantic actions: `set-value` for editable fields, `click` for controls, and `perform-secondary-action` only for listed action names.
- After any UI-changing action, use the returned state or rerun `get-app-state` before choosing the next element index.
- Use `type-text` only after focusing a field and confirming the app has a focused text receiver; synthetic keyboard delivery is reported as unverified, so inspect the returned state before assuming text landed.
- Use `type-text` only after focusing a field and confirming the app has a focused text receiver; unless the result says `verified focusedText`, inspect the returned state before assuming text landed.
- Use `press-key` for single/navigation keys such as Return, Escape, Tab, and arrows. Use `hotkey` only for one modifier chord plus one key, such as `CmdOrCtrl+A` or `CmdOrCtrl+Shift+P`; prefer `CmdOrCtrl+...` for cross-platform combos.
- Shortcuts that quit or close the app, log out, lock the screen, force-quit or end the session (such as `Cmd+Q` on macOS, `Alt+F4` on Windows and Linux, `Ctrl+Q` on Linux) are refused with `system_shortcut_blocked`. The error says what the shortcut would do; reach that goal another way, such as the window's own close button or menu item. Add `--allow-system-shortcut` only when the user asked for that exact shortcut.
- Use `click --modifiers <chord>` for modifier-clicks. Never synthesize separate modifier-down and modifier-up commands around a click; interruption can leave a modifier logically held.
- Coordinates are window-local; use coordinates from the latest screenshot/state for the same target window.
@@ -123,7 +148,7 @@ Do not pass `--restore-window` by default. Use it only when foreground input is
Popup menus and web `<select>` controls: set the option with `set-value` on the popup element. Background clicks on them are refused because they open the menu off screen or wedge the app's input.
On Linux and Windows, clicks, scrolling, drags and keyboard input still bring the target window forward.
On Linux, clicks, scrolling, drags and keyboard input still bring the target window forward. On Windows, these go through UI Automation when the control supports them, without moving the pointer or sending keys: element clicks, `set-value` (including sliders), element scrolls by whole `--pages`, and secondary actions such as `Invoke`, `Toggle`, `Select`, `Expand`, `Collapse` and `ScrollToVisible` (the last brings a list or tree item into view). Some apps bring their own window forward when driven this way (WPF apps do for most of these), so read `action.delivery`: `background` means the user's foreground window stayed put, `foreground` means the target came forward. Everything else brings the window forward and reports `foreground`.
## Screenshots
@@ -157,7 +182,7 @@ ORCA computer set-value --app com.microsoft.edgemac --element-index <addressBarI
ORCA computer press-key --app com.microsoft.edgemac --key Return --json
```
Spotify: refresh after playback clicks; the UI often changes asynchronously.
Spotify: the UI often changes asynchronously after playback clicks; `wait --text` for the change instead of re-reading in a loop.
Slack: the accessibility tree may be shallow while the screenshot contains useful information. Reading visible Slack UI is fine when requested; sending messages or triggering workflows still needs explicit permission.
@@ -165,6 +190,7 @@ Slack: the accessibility tree may be shallow while the screenshot contains usefu
- `app_not_found`: run `list-apps` and retry with the bundle ID. If the target is a web app such as Gmail, choose the desktop browser app/window that contains it; do not retry `ORCA computer ... --app Gmail` unchanged because `orca computer` app selectors refer to desktop apps, not website names.
- `app_blocked`: stop; the target is intentionally blocked from computer-use.
- `system_shortcut_blocked`: the error message says what the shortcut would do. Reach the same goal with a semantic action, such as a button or menu item, or ask the user; retry with `--allow-system-shortcut` only when the user asked for that exact shortcut.
- `window_not_found` / `window_stale`: run `list-windows`, choose a current selector, then rerun `get-app-state`.
- `background_unavailable`: for a popup or `<select>`, use `set-value` on it; otherwise retry once with `--restore-window` after telling the user it will take over their screen.
- `window_not_focused`: retry once with `--restore-window`; if the message says restore was already requested, stop retrying restore and bring the app forward manually or check permissions. For editable fields prefer `set-value`, then inspect before assuming keyboard input worked.
@@ -172,9 +198,11 @@ Slack: the accessibility tree may be shallow while the screenshot contains usefu
- `unsupported_capability`: the provider or desktop environment cannot do that action; use a semantic alternative or install the missing dependency if the message names one.
- `action_not_supported`: inspect the element's listed actions and retry with one of those names, or use click/set-value when appropriate.
- `value_not_settable`: the element cannot accept direct value writes; focus it and use keyboard input only when the returned state can be inspected.
- `element_not_clickable`: the element has no actionable frame; use a parent/child element with a frame or choose window-local coordinates from the latest screenshot.
- `element_not_clickable`: no click was sent. If the message says the element is covered, deal with what covers it (a dialog, sheet or popover), then click again from a fresh `get-app-state`; never click by coordinates to get past the cover. If it is out of view, scroll its container first. Otherwise the element has no actionable frame; use a parent/child element with a frame or choose window-local coordinates from the latest screenshot.
- `element_not_enabled`: the element is disabled (its line lists `disabled`), so nothing was sent. Do what enables it first, then act once a fresh `get-app-state` no longer lists it as disabled.
- `invalid_argument`: fix the command flags; do not retry the same command unchanged.
- `action_timeout`: inspect current state before retrying, then use a simpler semantic action or `--no-screenshot` if observation is slow.
- `wait_timeout`: the condition did not hold in time. Run `get-app-state` to see what the app shows; wait again with a longer `--timeout` only if it is still working, otherwise match text the tree actually shows.
- `verification_failed`: the write was read back and the element holds a different value, so the action failed. Run `get-app-state` to see which field changed. For editable text, click the intended field and confirm focus, select all (`cmd+a` on macOS, `ctrl+a` on Windows/Linux), then use `type-text` and inspect the resulting value instead of repeating `set-value`.
- `screenshot_failed`: use `--no-screenshot` if tree state is enough; if the message names Screen Recording or screenshots permission, run `ORCA computer permissions --id screenshots --json`.
- `accessibility_error`: run `ORCA computer capabilities --json`; if the message names Accessibility permission, run `ORCA computer permissions --id accessibility --json`.
@@ -107,27 +107,3 @@ it('Windows automatic timeout joins tracked tree lifetime beyond the caller wait
expect(spawn.mock.calls.every(([spec]) => spec.detached === false)).toBe(true)
expect(vi.getTimerCount()).toBe(0)
})
it('asynchronous spawn error releases readers before synchronous fallback failure and final refusal', async () => {
const child = probe()
spawn
.mockImplementationOnce(() => {
queueMicrotask(() => child.emit('error', new Error('ENOENT')))
return child
})
.mockImplementationOnce(() => {
throw new Error('unlaunchable fallback')
})
const owner = session()
await expect(resolveOpenCodeLoginCommand({}, owner)).rejects.toThrow(
'Install alongside your existing CLI'
)
expect(spawn).toHaveBeenCalledTimes(2)
expect(child.stdout.destroyed && child.stderr.destroyed && child.stdin.destroyed).toBe(true)
expect(owner.child).toBeNull()
expect(owner.stopPhase).toBeUndefined()
expect(signalTree).not.toHaveBeenCalled()
child.emit('error', new Error('late error'))
child.emit('exit', 0)
child.emit('close', 0)
})
+10 -2
View File
@@ -145,24 +145,32 @@ export async function getComputerTextActionFlags(flags: Map<string, string | boo
export function getComputerKeyActionFlags(flags: Map<string, string | boolean>): {
key: string
allowSystemShortcut?: boolean
} {
const key = getRequiredStringFlag(flags, 'key')
const message = computerUsePressKeyValidationMessage(key)
if (message) {
throw new RuntimeClientError('invalid_argument', message)
}
return { key }
return {
key,
...(flags.get('allow-system-shortcut') === true ? { allowSystemShortcut: true } : {})
}
}
export function getComputerHotkeyActionFlags(flags: Map<string, string | boolean>): {
key: string
allowSystemShortcut?: boolean
} {
const key = getRequiredStringFlag(flags, 'key')
const message = computerUseHotkeyValidationMessage(key)
if (message) {
throw new RuntimeClientError('invalid_argument', message)
}
return { key }
return {
key,
...(flags.get('allow-system-shortcut') === true ? { allowSystemShortcut: true } : {})
}
}
export async function getComputerSetValueActionFlags(
+1 -1
View File
@@ -31,7 +31,7 @@ export function formatGetAppState(result: ComputerSnapshotResult): string {
? ''
: ` @ ${result.snapshot.window.x},${result.snapshot.window.y}`
const truncation = result.snapshot.truncation?.truncated
? ` Truncated: yes (max nodes ${result.snapshot.truncation.maxNodes ?? 'unknown'}, max depth ${result.snapshot.truncation.maxDepth ?? 'unknown'})`
? ` Truncated: yes (max nodes ${result.snapshot.truncation.maxNodes ?? 'unknown'}, max depth ${result.snapshot.truncation.maxDepth ?? 'unknown'}); read cut-off children with --element-index <their parent's index>`
: ' Truncated: no'
return [
`${app.name} (pid ${app.pid}${bundle})`,
@@ -0,0 +1,14 @@
import { describe, expect, it } from 'vitest'
import { isComputerTreeElementDisabled } from './computer-tree-query'
describe('isComputerTreeElementDisabled', () => {
it.each([
['12 (disabled) File', true],
['\t3 push button (selected, disabled, settable) Save', true],
['4 action (primary) (disabled) Continue', true],
['5 push button (selected) Save (beta)', false],
['6 push button Continue, Description: Next step', false]
])('reads %s as disabled=%s', (line, disabled) => {
expect(isComputerTreeElementDisabled({ index: 0, depth: 0, lines: [line] })).toBe(disabled)
})
})
+18 -3
View File
@@ -13,9 +13,7 @@ export type ComputerTreeQuery = {
export function queryComputerTreeText(treeText: string, options: ComputerTreeQuery): string {
const { header, elements, footer } = parseComputerTreeText(treeText)
const needle = options.query?.toLowerCase()
const candidates = needle
? elements.filter((element) => elementText(element).toLowerCase().includes(needle))
: elements
const candidates = needle ? computerTreeElementsMatching(elements, needle) : elements
const shown =
options.maxElements === undefined ? candidates : candidates.slice(0, options.maxElements)
const shownSet = new Set(shown)
@@ -33,6 +31,23 @@ export function queryComputerTreeText(treeText: string, options: ComputerTreeQue
return joinComputerTreeText(header, note ? [note, ...body] : body, footer)
}
// Case-insensitive, like --query, over each element's line without its index.
export function computerTreeElementsMatching(
elements: ComputerTreeElement[],
query: string
): ComputerTreeElement[] {
const needle = query.toLowerCase()
return elements.filter((element) => elementText(element).toLowerCase().includes(needle))
}
// Providers render traits after the role, whose own text may hold parentheses: `12 button (selected, disabled) Save`.
const DISABLED_TRAIT =
/\((?:(?:selected|expanded|settable), )*disabled(?:, (?:selected|expanded|settable))*\)/u
export function isComputerTreeElementDisabled(element: ComputerTreeElement): boolean {
return DISABLED_TRAIT.test(element.lines[0])
}
function elementText(element: ComputerTreeElement): string {
return element.lines[0].trimStart().replace(/^\d+ ?/u, '')
}
+73
View File
@@ -0,0 +1,73 @@
import {
COMPUTER_WAIT_DEFAULT_TIMEOUT_MS,
COMPUTER_WAIT_MAX_TIMEOUT_MS
} from '../../shared/computer-wait-timeout'
import {
formatComputerWaitSnapshot,
formatComputerWaitWindows,
waitForComputerSnapshot,
waitForComputerWindowTitle,
type ComputerWaitCondition
} from './computer-wait'
import type { CommandHandler } from '../dispatch/dispatch'
import {
getOptionalPositiveIntegerFlag,
getOptionalStringFlag,
getRequiredStringFlag
} from '../arguments/flags'
import { printResult } from '../output/command-result-output'
import { RuntimeClientError } from '../runtime/types'
import { getComputerCommandTarget } from './computer-command-target'
import { getComputerWindowTargetFlags } from './computer-action-flags'
export const runComputerWait: CommandHandler = async ({ flags, client, cwd, json }) => {
const condition = getComputerWaitCondition(flags)
const timeoutMs = getComputerWaitTimeoutMs(flags)
const windowTarget = getComputerWindowTargetFlags(flags)
if (condition.kind === 'window-title') {
if (Object.keys(windowTarget).length > 0) {
throw new RuntimeClientError(
'invalid_argument',
"--window-title waits across all of the app's windows; drop --window-id and --window-index"
)
}
const app = getRequiredStringFlag(flags, 'app')
const result = await waitForComputerWindowTitle(client, condition, app, timeoutMs)
printResult(result, json, formatComputerWaitWindows)
return
}
const target = await getComputerCommandTarget(flags, cwd, client)
const result = await waitForComputerSnapshot(
client,
condition,
{ ...target, ...windowTarget },
timeoutMs
)
printResult(result, json, formatComputerWaitSnapshot)
}
function getComputerWaitCondition(flags: Map<string, string | boolean>): ComputerWaitCondition {
const conditions = (['text', 'enabled', 'window-title'] as const).flatMap((kind) => {
const value = getOptionalStringFlag(flags, kind)
return value === undefined ? [] : [{ kind, value }]
})
if (conditions.length !== 1) {
throw new RuntimeClientError(
'invalid_argument',
'Pass exactly one of --text <text>, --enabled <text> or --window-title <text>'
)
}
return conditions[0]
}
function getComputerWaitTimeoutMs(flags: Map<string, string | boolean>): number {
const timeoutMs =
getOptionalPositiveIntegerFlag(flags, 'timeout') ?? COMPUTER_WAIT_DEFAULT_TIMEOUT_MS
if (timeoutMs > COMPUTER_WAIT_MAX_TIMEOUT_MS) {
throw new RuntimeClientError(
'invalid_argument',
`--timeout must be at most ${COMPUTER_WAIT_MAX_TIMEOUT_MS} ms`
)
}
return timeoutMs
}
+166
View File
@@ -0,0 +1,166 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const callMock = vi.fn()
type RuntimeClientModule = typeof RuntimeClientExports
vi.mock('../runtime/client', async (importOriginal) => ({
...(await importOriginal<RuntimeClientModule>()),
RuntimeClient: class {
call = callMock
getCliStatus = vi.fn()
openOrca = vi.fn()
}
}))
import { main } from '../index'
import type * as RuntimeClientExports from '../runtime/client'
import { RuntimeRpcFailureError } from '../runtime/types'
import { okFixture, queueFixtures } from '../runtime/fixtures/runtime-rpc-fixtures'
describe('orca computer wait', () => {
beforeEach(() => {
callMock.mockReset()
vi.spyOn(console, 'log').mockImplementation(() => {})
vi.spyOn(console, 'error').mockImplementation(() => {})
process.exitCode = undefined
})
afterEach(() => {
vi.restoreAllMocks()
})
it('polls until the text appears, waiting out a window that is not open yet', async () => {
callMock.mockRejectedValueOnce(
new RuntimeRpcFailureError({
id: 'req_0',
ok: false,
error: { code: 'window_not_found', message: 'no window' },
_meta: { runtimeId: 'runtime-1' }
})
)
queueFixtures(
callMock,
okFixture('req_1', snapshot('0 window Editor\n\t1 text Saving…')),
okFixture('req_2', snapshot('0 window Editor\n\t1 text All changes saved\n\t2 button Close'))
)
await run('--text', 'saved')
expect(callMock).toHaveBeenCalledTimes(3)
expect(callMock).toHaveBeenLastCalledWith(
'computer.getAppState',
{ session: 'manual', app: 'TextEdit', noScreenshot: true },
expect.anything()
)
const output = JSON.parse(vi.mocked(console.log).mock.calls[0][0])
expect(output.result.wait).toMatchObject({ kind: 'text', value: 'saved' })
expect(output.result.snapshot.treeText).toContain('1 text All changes saved')
expect(output.result.snapshot.treeText).not.toContain('2 button Close')
})
it('waits until every element containing the text is enabled', async () => {
queueFixtures(
callMock,
okFixture('req_caps', capabilities(true)),
okFixture(
'req_1',
snapshot('0 window Form\n\t1 text Press Continue\n\t2 button (disabled) Continue')
),
okFixture('req_2', snapshot('0 window Form\n\t1 text Press Continue\n\t2 button Continue'))
)
await run('--enabled', 'Continue')
expect(callMock).toHaveBeenCalledTimes(3)
expect(process.exitCode).toBeUndefined()
})
it('refuses --enabled on a provider that does not mark disabled elements', async () => {
queueFixtures(callMock, okFixture('req_caps', capabilities(undefined)))
await run('--enabled', 'Continue')
expect(callMock).toHaveBeenCalledTimes(1)
expect(process.exitCode).toBe(1)
expect(errorOutput()).toContain('unsupported_capability')
})
it('fails with wait_timeout and what it last saw', async () => {
callMock.mockResolvedValue(okFixture('req_1', snapshot('0 window Editor\n\t1 text Saving…')))
await run('--text', 'saved', '--timeout', '1')
expect(process.exitCode).toBe(1)
const error = errorOutput()
expect(error).toContain('wait_timeout')
expect(error).toContain('no element contains \\"saved\\"')
})
it('waits for a window title across the app windows', async () => {
queueFixtures(
callMock,
okFixture('req_1', windows(['Untitled'])),
okFixture('req_2', windows(['Untitled', 'Save As']))
)
await run('--window-title', 'save as')
expect(callMock).toHaveBeenLastCalledWith(
'computer.listWindows',
{ app: 'TextEdit' },
expect.anything()
)
const output = JSON.parse(vi.mocked(console.log).mock.calls[0][0])
expect(output.result.windows.map((window: { title: string }) => window.title)).toEqual([
'Save As'
])
})
})
async function run(...args: string[]): Promise<void> {
await main(
['computer', 'wait', '--session', 'manual', '--app', 'TextEdit', ...args, '--json'],
'/tmp/repo'
)
}
function errorOutput(): string {
return vi
.mocked(console.log)
.mock.calls.map((call) => String(call[0]))
.join('\n')
}
function snapshot(treeText: string) {
return {
snapshot: {
id: 'snap',
app: { name: 'TextEdit', bundleId: 'com.apple.TextEdit', pid: 7 },
window: { title: 'Editor', width: 800, height: 600 },
coordinateSpace: 'window',
treeText: `App=com.apple.TextEdit (pid 7)\nWindow: "Editor"\n\n${treeText}`,
elementCount: 3,
focusedElementId: null
},
screenshot: null,
screenshotStatus: { state: 'skipped', reason: 'no_screenshot_flag' }
}
}
function capabilities(disabledState: boolean | undefined) {
return {
platform: 'linux',
provider: 'orca-computer-use-linux',
providerVersion: '1',
protocolVersion: 1,
supports: { observation: { screenshot: true, disabledState } }
}
}
function windows(titles: string[]) {
return {
app: { name: 'TextEdit', bundleId: 'com.apple.TextEdit', pid: 7 },
windows: titles.map((title, index) => ({ title, index, id: index, width: 800, height: 600 }))
}
}
+229
View File
@@ -0,0 +1,229 @@
import type {
ComputerListWindowsResult,
ComputerProviderCapabilities,
ComputerSnapshotResult,
ComputerWindowListWindow
} from '../../shared/computer-use-runtime-types'
import { parseComputerTreeText } from '../../shared/computer-use-tree-text'
import {
computerTreeElementsMatching,
isComputerTreeElementDisabled,
queryComputerTreeText
} from './computer-tree-query'
import { cliErrorCode } from '../output/cli-error'
import { formatGetAppState, formatListWindows } from './computer-format'
import type { RuntimeClient } from '../runtime/client'
import { RuntimeClientError } from '../runtime/types'
import type { RuntimeRpcSuccess } from '../../shared/runtime-rpc-envelope'
export type ComputerWaitCondition =
| { kind: 'text'; value: string }
| { kind: 'enabled'; value: string }
| { kind: 'window-title'; value: string }
type ComputerTreeWaitCondition = Exclude<ComputerWaitCondition, { kind: 'window-title' }>
export type ComputerWaitSummary = ComputerWaitCondition & { elapsedMs: number }
export type ComputerWaitSnapshotResult = ComputerSnapshotResult & { wait: ComputerWaitSummary }
export type ComputerWaitWindowsResult = ComputerListWindowsResult & { wait: ComputerWaitSummary }
const POLL_INTERVAL_MS = 250
// Why: a read started near the deadline still gets long enough to answer for a large window.
const MIN_READ_TIMEOUT_MS = 2_000
// Why: the app or window may not exist yet; waiting for it to appear is part of the wait.
const NOT_YET_CODES = new Set(['app_not_found', 'window_not_found', 'window_stale'])
type Poll<T> = {
call: (timeoutMs: number) => Promise<RuntimeRpcSuccess<T>>
check: (result: T) => string | null
}
// Polls the same reads every provider and runtime version serves, so the wait needs no host support.
export async function waitForComputerSnapshot(
client: RuntimeClient,
condition: ComputerTreeWaitCondition,
params: Record<string, unknown>,
timeoutMs: number
): Promise<RuntimeRpcSuccess<ComputerWaitSnapshotResult>> {
const startedAt = Date.now()
if (condition.kind === 'enabled') {
await assertDisabledStateSupported(client, Math.max(timeoutMs, MIN_READ_TIMEOUT_MS))
}
const { response, elapsedMs } = await pollUntil(condition, startedAt, timeoutMs, {
call: (readTimeoutMs) =>
client.call<ComputerSnapshotResult>(
'computer.getAppState',
{ ...params, noScreenshot: true },
{ timeoutMs: readTimeoutMs }
),
check: (result) => snapshotMiss(condition, result.snapshot.treeText)
})
const { snapshot } = response.result
return {
...response,
result: {
...response.result,
snapshot: {
...snapshot,
treeText: queryComputerTreeText(snapshot.treeText, { query: condition.value })
},
wait: { ...condition, elapsedMs }
}
}
}
export async function waitForComputerWindowTitle(
client: RuntimeClient,
condition: Extract<ComputerWaitCondition, { kind: 'window-title' }>,
app: string,
timeoutMs: number
): Promise<RuntimeRpcSuccess<ComputerWaitWindowsResult>> {
const { response, elapsedMs } = await pollUntil(condition, Date.now(), timeoutMs, {
call: (readTimeoutMs) =>
client.call<ComputerListWindowsResult>(
'computer.listWindows',
{ app },
{ timeoutMs: readTimeoutMs }
),
check: (result) => windowTitleMiss(result.windows, condition.value)
})
return {
...response,
result: {
...response.result,
windows: matchingWindows(response.result.windows, condition.value),
wait: { ...condition, elapsedMs }
}
}
}
function snapshotMiss(condition: ComputerTreeWaitCondition, treeText: string): string | null {
const matches = computerTreeElementsMatching(
parseComputerTreeText(treeText).elements,
condition.value
)
if (matches.length === 0) {
return `no element contains "${condition.value}"`
}
if (condition.kind === 'text') {
return null
}
const disabled = matches.filter(isComputerTreeElementDisabled)
if (disabled.length === 0) {
return null
}
return `${disabled.length} of ${matches.length} matching elements are disabled: ${disabled
.slice(0, 3)
.map((element) => element.lines[0].trim())
.join(' | ')}`
}
function windowTitleMiss(windows: ComputerWindowListWindow[], title: string): string | null {
if (matchingWindows(windows, title).length > 0) {
return null
}
if (windows.length > 0 && windows.every((window) => window.title === '')) {
return 'every window title is empty (on macOS, window titles need the Screen Recording permission)'
}
return `its windows are ${windows.map((window) => `"${window.title}"`).join(', ') || 'none'}`
}
function matchingWindows(
windows: ComputerWindowListWindow[],
title: string
): ComputerWindowListWindow[] {
const needle = title.toLowerCase()
return windows.filter((window) => window.title.toLowerCase().includes(needle))
}
async function assertDisabledStateSupported(
client: RuntimeClient,
readTimeoutMs: number
): Promise<void> {
const { result } = await client.call<ComputerProviderCapabilities>(
'computer.capabilities',
{},
{ timeoutMs: readTimeoutMs }
)
if (result.supports.observation.disabledState !== true) {
// Why: without the trait every element reads as enabled, so the wait would pass at once.
throw new RuntimeClientError(
'unsupported_capability',
`The ${result.provider} computer-use provider on this host does not report disabled elements, so --enabled cannot be checked. Update Orca on that host, or wait with --text instead.`
)
}
}
async function pollUntil<T>(
condition: ComputerWaitCondition,
startedAt: number,
timeoutMs: number,
poll: Poll<T>
): Promise<{ response: RuntimeRpcSuccess<T>; elapsedMs: number }> {
for (;;) {
let miss: string
try {
const remainingMs = timeoutMs - (Date.now() - startedAt)
const response = await poll.call(Math.max(remainingMs, MIN_READ_TIMEOUT_MS))
const result = poll.check(response.result)
if (result === null) {
return { response, elapsedMs: Date.now() - startedAt }
}
miss = result
} catch (error) {
const code = cliErrorCode(error)
if (code === 'runtime_timeout' && Date.now() - startedAt >= timeoutMs) {
miss = 'the last read did not answer before the deadline'
} else if (code && NOT_YET_CODES.has(code)) {
miss = `${code}: ${error instanceof Error ? error.message : String(error)}`
} else {
throw error
}
}
const remainingMs = timeoutMs - (Date.now() - startedAt)
if (remainingMs <= 0) {
throw waitTimeoutError(condition, timeoutMs, miss)
}
await new Promise((resolve) => setTimeout(resolve, Math.min(POLL_INTERVAL_MS, remainingMs)))
}
}
function waitTimeoutError(
condition: ComputerWaitCondition,
timeoutMs: number,
lastSeen: string
): RuntimeClientError {
const goal =
condition.kind === 'text'
? `an element containing "${condition.value}"`
: condition.kind === 'enabled'
? `elements containing "${condition.value}" to be enabled`
: `a window titled "${condition.value}"`
return new RuntimeClientError(
'wait_timeout',
`Timed out after ${timeoutMs} ms waiting for ${goal}; last check: ${lastSeen}.`,
{
nextSteps: [
'Run `orca computer get-app-state --app <app> --json` to see what the app shows now.',
'If the app is still working, wait again with a longer --timeout; otherwise match text the tree actually shows.',
...(condition.kind === 'enabled'
? ['Every matching element must be enabled, so use text only the intended control shows.']
: [])
]
}
)
}
export function formatComputerWaitSnapshot(result: ComputerWaitSnapshotResult): string {
return `${waitHeadline(result.wait)}\n${formatGetAppState(result)}`
}
export function formatComputerWaitWindows(result: ComputerWaitWindowsResult): string {
return `${waitHeadline(result.wait)}\n${formatListWindows(result)}`
}
function waitHeadline(wait: ComputerWaitSummary): string {
return `Condition --${wait.kind} "${wait.value}" held after ${wait.elapsedMs} ms.`
}
+16 -1
View File
@@ -7,11 +7,13 @@ import type {
} from '../../shared/computer-use-runtime-types'
import type { CommandHandler } from '../dispatch/dispatch'
import {
getOptionalNonNegativeIntegerFlag,
getOptionalPositiveIntegerFlag,
getOptionalStringFlag,
getRequiredStringFlag
} from '../arguments/flags'
import { queryComputerTreeText } from './computer-tree-query'
import { runComputerWait } from './computer-wait-command'
import { RuntimeClientError } from '../runtime/types'
import {
formatComputerAction,
@@ -84,17 +86,30 @@ export const COMPUTER_HANDLERS: Record<string, CommandHandler> = {
const observeFlags = getComputerObserveFlags(flags)
const query = getOptionalStringFlag(flags, 'query')
const maxElements = getOptionalPositiveIntegerFlag(flags, 'max-elements')
const rootElementIndex = getOptionalNonNegativeIntegerFlag(flags, 'element-index')
const target = await getComputerCommandTarget(flags, cwd, client)
const result = await client.call<ComputerSnapshotResult>('computer.getAppState', {
...target,
...observeFlags
...observeFlags,
...(rootElementIndex === undefined ? {} : { rootElementIndex })
})
// Why: older runtimes drop the param and return the whole window, which would look like the subtree.
if (
rootElementIndex !== undefined &&
result.result.snapshot.rootElementIndex !== rootElementIndex
) {
throw new RuntimeClientError(
'unsupported_capability',
'This Orca runtime cannot read one element subtree; update Orca, or run get-app-state without --element-index'
)
}
if (query !== undefined || maxElements !== undefined) {
const { snapshot } = result.result
snapshot.treeText = queryComputerTreeText(snapshot.treeText, { query, maxElements })
}
printResult(result, json, formatGetAppState)
},
'computer wait': runComputerWait,
'computer click': async ({ flags, client, cwd, json }) => {
assertComputerAppFlag(flags)
const observeFlags = getComputerActionObserveFlags(flags)
@@ -1,3 +1,5 @@
import { COMPUTER_WAIT_DEFAULT_TIMEOUT_MS } from '../../shared/computer-wait-timeout'
// File focus differs from terminal create's shared --focus help.
const FILE_OPEN_FOCUS_HELP =
"--focus Bring the user to the file (switches Orca's window to its worktree)"
@@ -17,9 +19,19 @@ const COMMAND_SCOPED_FLAG_HELP: Record<string, Record<string, string>> = {
key: '--key <key> Opaque key from reference list; repeat for several'
},
'computer get-app-state': {
'element-index':
'--element-index <n> Read only this element and its descendants, including any the window snapshot cut off',
query:
'--query <text> Show only elements whose line contains this text, with their ancestors'
},
'computer wait': {
text: '--text <text> Wait until an element line contains this text',
enabled:
'--enabled <text> Wait until elements containing this text exist and none is disabled',
'window-title':
"--window-title <text> Wait until one of the app's windows has this in its title",
timeout: `--timeout <ms> How long to wait before failing with wait_timeout (default ${COMPUTER_WAIT_DEFAULT_TIMEOUT_MS})`
},
'reference find': {
query: '--query <url-or-key> Full URL or native issue key such as STA-1234',
repo: '--repo <selector> Filter by workspace repository membership',
+2
View File
@@ -10,6 +10,8 @@ export const FLAG_HELP_TEXT: Record<string, string> = {
action: '--action <name> Secondary accessibility action name',
activate: '--activate Reveal the new worktree in the Orca app',
app: '--app <app> App name, bundle ID, or pid:N',
'allow-system-shortcut':
'--allow-system-shortcut Send a quit, log out or lock shortcut that is refused by default',
direction:
'--direction <dir> Direction: up|down|left|right for scroll, horizontal|vertical for split',
'display-name': '--display-name <name> Override the Orca display name',
@@ -186,6 +186,7 @@ export const ROOT_HELP_TEXT_PRIMARY = [
' computer list-apps List running apps available to computer-use',
' computer list-windows List visible windows for a target app',
' computer get-app-state Capture a compact accessibility snapshot of an app',
' computer wait Wait until an app shows text, enables a control, or opens a window',
' computer click Click an app element or window coordinate',
' computer perform-secondary-action Run an advertised accessibility action',
' computer scroll Scroll an app element',
@@ -187,6 +187,7 @@ export const HANDLER_GROUPS: readonly HandlerGroup[] = [
'computer permissions',
'computer list-windows',
'computer get-app-state',
'computer wait',
'computer click',
'computer perform-secondary-action',
'computer scroll',
@@ -4,9 +4,22 @@ import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { printResult } from './command-result-output'
import { formatRepoRefs } from '../projects/repo-format'
let testScreenshotDir: string | null = null
it('prints readable branches while distinguishing colliding action identities', () => {
expect(
formatRepoRefs({
refs: ['refs/heads/topic', 'refs/heads/origin/main', 'refs/remotes/origin/main'],
truncated: false
})
).toBe('topic\nrefs/heads/origin/main\nrefs/remotes/origin/main')
expect(
formatRepoRefs({ refs: ['origin/main', 'refs/remotes/origin/main'], truncated: false })
).toBe('origin/main\norigin/main')
})
afterEach(() => {
vi.restoreAllMocks()
delete process.env.ORCA_COMPUTER_SCREENSHOT_TMPDIR
+4 -1
View File
@@ -1,3 +1,4 @@
import { branchRefLabels } from '../../shared/git/refs/branch-ref-label'
import type {
RuntimeRepoList,
RuntimeRepoSearchRefs
@@ -28,5 +29,7 @@ export function formatRepoRefs(result: RuntimeRepoSearchRefs): string {
if (result.refs.length === 0) {
return 'No refs found.'
}
return result.truncated ? `${result.refs.join('\n')}\n\ntruncated: yes` : result.refs.join('\n')
const labels = branchRefLabels(result.refs)
const text = result.refs.map((ref) => labels.get(ref) ?? ref).join('\n')
return result.truncated ? `${text}\n\ntruncated: yes` : text
}
@@ -7,7 +7,7 @@ const { spawnMock, reclaimStaleLockMock, printReclaimResultMock } = vi.hoisted((
}))
vi.mock('node:child_process', () => ({ spawn: spawnMock }))
vi.mock('../../main/orcad/orcad-stale-lock-reclaim.js', () => ({
vi.mock('../../main/orcad/instance-lock/orcad-stale-lock-reclaim.js', () => ({
reclaimStaleOrcadInstanceLock: reclaimStaleLockMock,
printOrcadStaleLockReclaimResult: printReclaimResultMock
}))
+1 -1
View File
@@ -98,7 +98,7 @@ export const CORE_HANDLERS: Record<string, CommandHandler> = {
}
// Why lazy: only this mode needs orcad's lock code, and every other command skips loading it.
const { printOrcadStaleLockReclaimResult, reclaimStaleOrcadInstanceLock } =
await import('../../main/orcad/orcad-stale-lock-reclaim.js')
await import('../../main/orcad/instance-lock/orcad-stale-lock-reclaim.js')
const result = await reclaimStaleOrcadInstanceLock(
typeof dataRoot === 'string' ? resolve(dataRoot) : resolveLaunchUserDataPath(),
// This CLI's own binary is no command to give a user; `orca serve` is.
+2
View File
@@ -6,6 +6,7 @@ import type {
import { RemoteRuntimeClientError } from '../../shared/remote-runtime/remote-runtime-client-error'
import { AGENT_LAUNCH_RUNTIME_CAPABILITY } from '../../shared/agent-launch/contracts/agent-launch-runtime-capability'
import { AGENT_SESSION_RENAME_ONLY_CLIENT_CAPABILITY } from '../../shared/agent-session/structured-agent-session-surface-capabilities'
import { REPO_SEARCH_QUALIFIED_REFS_RUNTIME_CAPABILITY } from '../../shared/worktree-runtime-capabilities'
import { sendRemoteRuntimeRequestOnSocket } from '../../shared/remote-runtime/requests/remote-runtime-request-socket'
import type { RuntimeStatus } from '../../shared/runtime-types'
import { RuntimeClientError, type RuntimeRpcResponse } from './types'
@@ -13,6 +14,7 @@ import { RuntimeClientError, type RuntimeRpcResponse } from './types'
// Paired CLI callers are not exempt from the host's agent.launch or chat rename gates like the local socket is.
const CLI_CLIENT_CAPABILITIES = [
AGENT_LAUNCH_RUNTIME_CAPABILITY,
REPO_SEARCH_QUALIFIED_REFS_RUNTIME_CAPABILITY,
AGENT_SESSION_RENAME_ONLY_CLIENT_CAPABILITY
] as const
+1 -1
View File
@@ -8,7 +8,7 @@ import { DeviceRegistry } from '../../main/runtime/rpc/server/pairing/device-reg
import {
acquireOrcadInstanceLock,
ORCAD_LOCK_FILE_NAME
} from '../../main/orcad/orcad-instance-lock'
} from '../../main/orcad/instance-lock/orcad-instance-lock'
import {
ensureHostInstanceIdentity,
hostInstanceIdFromEnv
+1 -1
View File
@@ -10,7 +10,7 @@ const RESET_WARNING =
export async function resetServeHostIdentity(userDataPath: string): Promise<void> {
// Lazy: only this command needs orcad's lock code.
const { resetHostIdentityUnderLock } =
await import('../../main/orcad/orcad-host-identity-reset.js')
await import('../../main/orcad/profile-state/orcad-host-identity-reset.js')
const result = resetHostIdentityUnderLock(userDataPath)
if (result.status === 'missing') {
throw new RuntimeClientError('not_found', `No Orca data at ${userDataPath}; nothing to reset.`)
+32 -4
View File
@@ -1065,6 +1065,28 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"ORCA computer get-app-state --app com.apple.finder --query Downloads --json",
"```",
"",
"A snapshot reads at most `truncation.maxNodes` elements and `maxDepth` levels. When it stops early, `truncation.truncated` is true and each cut-off place shows a `... N more not shown (snapshot limit)` line, indented like the children it stands for. To read them, pass the parent element's index (the nearest line above with less indentation) as `get-app-state --element-index <n>`: it reads only that element and its descendants, with the full limit. Elements already shown keep their indexes and hidden ones get new ones, and you can act on them. Action results show the whole window again, so read the subtree again before acting on another hidden element.",
"",
"```text",
"ORCA computer get-app-state --app com.apple.Safari --element-index 312 --json",
"```",
"",
"## Waiting",
"",
"Never `sleep` between actions. When the UI changes on its own after an action (a save finishes, a dialog opens, a button becomes clickable), wait for the change with `wait`. It returns as soon as the condition holds and prints the matching elements or windows; it fails with `wait_timeout` if the condition does not hold in time (default 10 s, `--timeout <ms>` up to 120000).",
"",
"```text",
"ORCA computer wait --app <app> --text \"Saved\" --json",
"ORCA computer wait --app <app> --enabled \"Continue\" --json",
"ORCA computer wait --app <app> --window-title \"Save As\" --json",
"```",
"",
"- `--text <text>`: an element line contains the text (case-insensitive, like `--query`).",
"- `--enabled <text>`: an element contains the text and none of the elements containing it is disabled. Use text only the intended control shows; a label that repeats the button text also has to be enabled.",
"- `--window-title <text>`: one of the app's windows has the text in its title, as `list-windows` reports them. Then target that window with its `--window-id` or `--window-index`. On Windows, `list-windows` reports only the app's main window, so wait for a dialog with `--text` instead.",
"",
"`wait` only reads the app; it never acts, raises or restores a window. The app or window may be missing at first; `wait` keeps checking until it appears. Element indexes in the output come from a fresh tree, so you can act on them next.",
"",
"## App Selectors",
"",
"Prefer bundle IDs from `list-apps`; names are acceptable when unambiguous. Use `pid:<number>` only when bundle ID or name matching is ambiguous.",
@@ -1086,6 +1108,7 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"ORCA computer list-windows --app <app> --json",
"ORCA computer get-app-state --app <app> --json",
"ORCA computer get-app-state --app <app> --restore-window --json",
"ORCA computer wait --app <app> (--text <text> | --enabled <text> | --window-title <text>) [--timeout <ms>] --json",
"ORCA computer click --app <app> --element-index <index> --json",
"ORCA computer click --app <app> --x 100 --y 100 --json",
"ORCA computer click --app <app> --x 100 --y 100 --modifiers CmdOrCtrl+Shift --json",
@@ -1118,12 +1141,14 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
" - `unverified (accessibility action unasserted)` means the accessibility call succeeded but no post-state assertion was made.",
" - `unverified (suspected noop)` means the accessibility call succeeded but the window's tree and the app's windows were unchanged about a second later. Web and Electron controls often ignore it. Do not repeat the same element click; if the effect you expect would show in the window, retry once with `click --x --y` at the control from a fresh screenshot. If the effect lives elsewhere (clipboard, another app), check there first.",
" - `unverified (synthetic input)` means input was fired into the void and is unverifiable.",
" - `unverified (text mismatch)` means typed or pasted text was read back and the focused field does not hold what inserting it should produce: it may be missing, partly entered, reformatted or autocompleted, or taken by a control that does not store it (terminals and canvas editors leave their input field empty). Do not type it again blindly, or it may land twice; check a fresh screenshot or `get-app-state` first.",
" - Missing verification metadata is unverified, including responses from older runtimes.",
" - Never report an unverified action as success. If it could have sent, submitted, bought, or deleted something, say the effect is unproven.",
"- Prefer semantic actions: `set-value` for editable fields, `click` for controls, and `perform-secondary-action` only for listed action names.",
"- After any UI-changing action, use the returned state or rerun `get-app-state` before choosing the next element index.",
"- Use `type-text` only after focusing a field and confirming the app has a focused text receiver; synthetic keyboard delivery is reported as unverified, so inspect the returned state before assuming text landed.",
"- Use `type-text` only after focusing a field and confirming the app has a focused text receiver; unless the result says `verified focusedText`, inspect the returned state before assuming text landed.",
"- Use `press-key` for single/navigation keys such as Return, Escape, Tab, and arrows. Use `hotkey` only for one modifier chord plus one key, such as `CmdOrCtrl+A` or `CmdOrCtrl+Shift+P`; prefer `CmdOrCtrl+...` for cross-platform combos.",
"- Shortcuts that quit or close the app, log out, lock the screen, force-quit or end the session (such as `Cmd+Q` on macOS, `Alt+F4` on Windows and Linux, `Ctrl+Q` on Linux) are refused with `system_shortcut_blocked`. The error says what the shortcut would do; reach that goal another way, such as the window's own close button or menu item. Add `--allow-system-shortcut` only when the user asked for that exact shortcut.",
"- Use `click --modifiers <chord>` for modifier-clicks. Never synthesize separate modifier-down and modifier-up commands around a click; interruption can leave a modifier logically held.",
"- Coordinates are window-local; use coordinates from the latest screenshot/state for the same target window.",
"",
@@ -1142,7 +1167,7 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"",
"Popup menus and web `<select>` controls: set the option with `set-value` on the popup element. Background clicks on them are refused because they open the menu off screen or wedge the app's input.",
"",
"On Linux and Windows, clicks, scrolling, drags and keyboard input still bring the target window forward.",
"On Linux, clicks, scrolling, drags and keyboard input still bring the target window forward. On Windows, these go through UI Automation when the control supports them, without moving the pointer or sending keys: element clicks, `set-value` (including sliders), element scrolls by whole `--pages`, and secondary actions such as `Invoke`, `Toggle`, `Select`, `Expand`, `Collapse` and `ScrollToVisible` (the last brings a list or tree item into view). Some apps bring their own window forward when driven this way (WPF apps do for most of these), so read `action.delivery`: `background` means the user's foreground window stayed put, `foreground` means the target came forward. Everything else brings the window forward and reports `foreground`.",
"",
"## Screenshots",
"",
@@ -1176,7 +1201,7 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"ORCA computer press-key --app com.microsoft.edgemac --key Return --json",
"```",
"",
"Spotify: refresh after playback clicks; the UI often changes asynchronously.",
"Spotify: the UI often changes asynchronously after playback clicks; `wait --text` for the change instead of re-reading in a loop.",
"",
"Slack: the accessibility tree may be shallow while the screenshot contains useful information. Reading visible Slack UI is fine when requested; sending messages or triggering workflows still needs explicit permission.",
"",
@@ -1184,6 +1209,7 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"",
"- `app_not_found`: run `list-apps` and retry with the bundle ID. If the target is a web app such as Gmail, choose the desktop browser app/window that contains it; do not retry `ORCA computer ... --app Gmail` unchanged because `orca computer` app selectors refer to desktop apps, not website names.",
"- `app_blocked`: stop; the target is intentionally blocked from computer-use.",
"- `system_shortcut_blocked`: the error message says what the shortcut would do. Reach the same goal with a semantic action, such as a button or menu item, or ask the user; retry with `--allow-system-shortcut` only when the user asked for that exact shortcut.",
"- `window_not_found` / `window_stale`: run `list-windows`, choose a current selector, then rerun `get-app-state`.",
"- `background_unavailable`: for a popup or `<select>`, use `set-value` on it; otherwise retry once with `--restore-window` after telling the user it will take over their screen.",
"- `window_not_focused`: retry once with `--restore-window`; if the message says restore was already requested, stop retrying restore and bring the app forward manually or check permissions. For editable fields prefer `set-value`, then inspect before assuming keyboard input worked.",
@@ -1191,9 +1217,11 @@ const ORCA_COMPUTER_USE_MARKDOWN = [
"- `unsupported_capability`: the provider or desktop environment cannot do that action; use a semantic alternative or install the missing dependency if the message names one.",
"- `action_not_supported`: inspect the element's listed actions and retry with one of those names, or use click/set-value when appropriate.",
"- `value_not_settable`: the element cannot accept direct value writes; focus it and use keyboard input only when the returned state can be inspected.",
"- `element_not_clickable`: the element has no actionable frame; use a parent/child element with a frame or choose window-local coordinates from the latest screenshot.",
"- `element_not_clickable`: no click was sent. If the message says the element is covered, deal with what covers it (a dialog, sheet or popover), then click again from a fresh `get-app-state`; never click by coordinates to get past the cover. If it is out of view, scroll its container first. Otherwise the element has no actionable frame; use a parent/child element with a frame or choose window-local coordinates from the latest screenshot.",
"- `element_not_enabled`: the element is disabled (its line lists `disabled`), so nothing was sent. Do what enables it first, then act once a fresh `get-app-state` no longer lists it as disabled.",
"- `invalid_argument`: fix the command flags; do not retry the same command unchanged.",
"- `action_timeout`: inspect current state before retrying, then use a simpler semantic action or `--no-screenshot` if observation is slow.",
"- `wait_timeout`: the condition did not hold in time. Run `get-app-state` to see what the app shows; wait again with a longer `--timeout` only if it is still working, otherwise match text the tree actually shows.",
"- `verification_failed`: the write was read back and the element holds a different value, so the action failed. Run `get-app-state` to see which field changed. For editable text, click the intended field and confirm focus, select all (`cmd+a` on macOS, `ctrl+a` on Windows/Linux), then use `type-text` and inspect the resulting value instead of repeating `set-value`.",
"- `screenshot_failed`: use `--no-screenshot` if tree state is enough; if the message names Screen Recording or screenshots permission, run `ORCA computer permissions --id screenshots --json`.",
"- `accessibility_error`: run `ORCA computer capabilities --json`; if the message names Accessibility permission, run `ORCA computer permissions --id accessibility --json`.",
+29 -6
View File
@@ -1,5 +1,9 @@
import type { CommandSpec } from '../discovery/command-spec'
import { CLI_GLOBAL_FLAGS as GLOBAL_FLAGS } from '../../shared/cli-argument-boundary'
import {
COMPUTER_WAIT_DEFAULT_TIMEOUT_MS,
COMPUTER_WAIT_MAX_TIMEOUT_MS
} from '../../shared/computer-wait-timeout'
const COMPUTER_FLAGS = [...GLOBAL_FLAGS, 'worktree', 'session', 'app']
const COMPUTER_WINDOW_TARGET_FLAGS = ['window-id', 'window-index']
@@ -40,8 +44,27 @@ export const COMPUTER_COMMAND_SPECS: CommandSpec[] = [
path: ['computer', 'get-app-state'],
summary: 'Capture a compact accessibility snapshot of an app',
usage:
'orca computer get-app-state --app <name|bundle|pid:N> [--window-id <id> | --window-index <n>] [--worktree <selector> | --session <id>] [--query <text>] [--max-elements <n>] [--restore-window] [--no-screenshot] [--json]',
allowedFlags: [...COMPUTER_OBSERVE_FLAGS, 'query', 'max-elements']
'orca computer get-app-state --app <name|bundle|pid:N> [--window-id <id> | --window-index <n>] [--worktree <selector> | --session <id>] [--element-index <n>] [--query <text>] [--max-elements <n>] [--restore-window] [--no-screenshot] [--json]',
allowedFlags: [...COMPUTER_OBSERVE_FLAGS, 'element-index', 'query', 'max-elements']
},
{
path: ['computer', 'wait'],
summary: 'Wait until an app shows text, enables a control, or opens a window',
usage:
'orca computer wait --app <name|bundle|pid:N> (--text <text> | --enabled <text> | --window-title <text>) [--timeout <ms>] [--window-id <id> | --window-index <n>] [--worktree <selector> | --session <id>] [--json]',
allowedFlags: [
...COMPUTER_FLAGS,
...COMPUTER_WINDOW_TARGET_FLAGS,
'text',
'enabled',
'window-title',
'timeout'
],
notes: [
'Polls the accessibility tree (or, for --window-title, the window list) until the condition holds, then prints the matching elements or windows. Matching is a case-insensitive substring, like get-app-state --query.',
'--enabled holds once an element contains the text and no element containing it is disabled.',
`--timeout defaults to ${COMPUTER_WAIT_DEFAULT_TIMEOUT_MS} ms (at most ${COMPUTER_WAIT_MAX_TIMEOUT_MS}); on timeout the command fails with wait_timeout.`
]
},
{
path: ['computer', 'click'],
@@ -98,15 +121,15 @@ export const COMPUTER_COMMAND_SPECS: CommandSpec[] = [
path: ['computer', 'press-key'],
summary: 'Press a single key such as Return or Escape',
usage:
'orca computer press-key --app <app> --key <key> [--window-id <id> | --window-index <n>] [--restore-window] [--no-screenshot] [--full-tree] [--json]',
allowedFlags: [...COMPUTER_ACTION_FLAGS, 'key']
'orca computer press-key --app <app> --key <key> [--window-id <id> | --window-index <n>] [--allow-system-shortcut] [--restore-window] [--no-screenshot] [--full-tree] [--json]',
allowedFlags: [...COMPUTER_ACTION_FLAGS, 'key', 'allow-system-shortcut']
},
{
path: ['computer', 'hotkey'],
summary: 'Press a platform-aware key combination',
usage:
'orca computer hotkey --app <app> --key <key-combo> [--window-id <id> | --window-index <n>] [--restore-window] [--no-screenshot] [--full-tree] [--json]',
allowedFlags: [...COMPUTER_ACTION_FLAGS, 'key']
'orca computer hotkey --app <app> --key <key-combo> [--window-id <id> | --window-index <n>] [--allow-system-shortcut] [--restore-window] [--no-screenshot] [--full-tree] [--json]',
allowedFlags: [...COMPUTER_ACTION_FLAGS, 'key', 'allow-system-shortcut']
},
{
path: ['computer', 'paste-text'],
@@ -1,30 +0,0 @@
import { describe, expect, it } from 'vitest'
import { shouldUseRendererBackedCodexTerminal } from './codex-command-classification'
describe('shouldUseRendererBackedCodexTerminal', () => {
it('keeps one-shot Codex commands on the background path', () => {
expect(shouldUseRendererBackedCodexTerminal('codex exec summarize')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex -m gpt-5 review')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex login status')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex login --with-api-key')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex cloud list --json')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex -c active=cloud cloud list --json')).toBe(
false
)
expect(shouldUseRendererBackedCodexTerminal('codex cloud --enable foo list --json')).toBe(false)
expect(
shouldUseRendererBackedCodexTerminal(
'env -u DEBUG CODEX_HOME=/tmp/codex codex exec summarize'
)
).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex cloud exec "fix it"')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex cloud --version')).toBe(false)
expect(shouldUseRendererBackedCodexTerminal('codex --help')).toBe(false)
})
it('reads --no-daemon as a flag, not the subcommand', () => {
expect(shouldUseRendererBackedCodexTerminal('codex --no-daemon resume --last')).toBe(true)
expect(shouldUseRendererBackedCodexTerminal('codex --no-daemon exec summarize')).toBe(false)
})
})
@@ -38,7 +38,9 @@ vi.mock('node:fs/promises', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
mkdir: mocks.mkdir
}))
vi.mock('../orcad/orcad-data-root-locality', () => ({ orcadDataRootIsOnLocalDisk: () => true }))
vi.mock('../orcad/instance-lock/orcad-data-root-locality', () => ({
orcadDataRootIsOnLocalDisk: () => true
}))
vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
@@ -0,0 +1,86 @@
import { describe, expect, it } from 'vitest'
import { KIMI_ACP_DIALECT } from './kimi-dialect'
const normalize = KIMI_ACP_DIALECT.normalizeToolUpdate!
const text = (value: string) => ({
type: 'content' as const,
content: { type: 'text' as const, text: value }
})
// Payloads recorded from Kimi Code 2.6.0 over `kimi acp`.
describe('KIMI_ACP_DIALECT.normalizeToolUpdate', () => {
it('reads a failed command as output and exit code', () => {
const output = 'hello-from-kimi\nCommand failed with exit code: 3.'
const update = normalize({
toolCallId: '0:call_1',
status: 'failed',
content: [text(output)],
rawOutput: output
})
expect(update.rawOutput).toEqual({ stdout: 'hello-from-kimi', exitCode: 3 })
expect(update.content).toEqual([])
})
it('reads a silent failed command as empty output', () => {
const output = 'Process exited with code 4\nCommand failed with exit code: 4.'
const update = normalize({
toolCallId: '0:call_1',
status: 'failed',
content: [text(output)],
rawOutput: output
})
expect(update.rawOutput).toEqual({ stdout: '', exitCode: 4 })
})
it('reads a silent successful command as empty output', () => {
const output = 'Command executed successfully.'
const update = normalize({
toolCallId: '0:call_1',
status: 'completed',
content: [text(output)],
rawOutput: output
})
expect(update.rawOutput).toEqual({ stdout: '', exitCode: 0 })
})
it('keeps successful output that ends like a failure', () => {
const output = 'log\nCommand failed with exit code: 3.'
const update = normalize({
toolCallId: '0:call_1',
status: 'completed',
content: [text(output)],
rawOutput: output
})
expect(update.rawOutput).toBe(output)
})
it('drops the streamed arguments a running call shows as text', () => {
const update = normalize({
toolCallId: '0:call_1',
status: 'in_progress',
rawInput: { command: 'echo hi' },
content: [text('{"command":"echo hi"}')]
})
expect(update.content).toEqual([])
})
})
describe('KIMI_ACP_DIALECT.request', () => {
it('describes an approval with the action Kimi asks about', () => {
const presentation = KIMI_ACP_DIALECT.request!('session/request_permission', {
sessionId: 'session_1',
options: [{ optionId: 'approve_once', name: 'Approve once', kind: 'allow_once' }],
toolCall: {
toolCallId: '0:call_1',
title: 'Bash',
content: [text('Requesting approval to Running: rm -rf build')]
}
})
expect(presentation?.body).toMatchObject({
kind: 'approval',
title: 'Bash',
description: 'Running: rm -rf build'
})
})
})
+79
View File
@@ -0,0 +1,79 @@
import type { ToolCallUpdate } from '../generated/acp-protocol.generated'
import { readAcpPermissionRequest } from '../protocol/acp-permission-requests'
import { acpPermissionPresentation } from '../requests/acp-timeline-requests'
import type { AcpDialect, AcpRequestPresentation } from './acp-dialect'
const SHELL_FAILURE = /^(?:([\s\S]*)\n)?Command failed with exit code: (-?\d+)\.$/u
const SHELL_SILENT_SUCCESS = 'Command executed successfully.'
// Kimi's Bash result is one string: output, then a failure line on a non-zero exit.
function shellResult(
output: string,
status: ToolCallUpdate['status']
): { stdout: string; exitCode: number } | null {
if (status === 'completed') {
return output === SHELL_SILENT_SUCCESS ? { stdout: '', exitCode: 0 } : null
}
const failure = status === 'failed' ? SHELL_FAILURE.exec(output) : null
if (!failure) {
return null
}
const exitCode = Number(failure[2])
const stdout = failure[1] ?? ''
return { stdout: stdout === `Process exited with code ${exitCode}` ? '' : stdout, exitCode }
}
function normalizeToolUpdate(update: ToolCallUpdate): ToolCallUpdate {
// A running call's text is its streamed arguments, not output.
if (update.status === 'pending' || update.status === 'in_progress') {
return update.content
? {
...update,
content: update.content.filter(
(block) => !(block.type === 'content' && block.content.type === 'text')
)
}
: update
}
const output = update.rawOutput
const shell = typeof output === 'string' ? shellResult(output, update.status) : null
if (!shell) {
return update
}
return {
...update,
rawOutput: shell,
content: update.content?.filter(
(block) =>
!(
block.type === 'content' &&
block.content.type === 'text' &&
block.content.text === output
)
)
}
}
const APPROVAL_ACTION = /^Requesting approval to (.+)$/su
const ACTION_MAX_CHARS = 512
// Approvals are titled with the bare tool name; the command or path is only in this action line.
function approvalRequest(method: string, params: unknown): AcpRequestPresentation | undefined {
const request =
method === 'session/request_permission' ? readAcpPermissionRequest(params, () => {}) : null
const action = request?.toolCall.content
?.map((block) =>
block.type === 'content' && block.content.type === 'text'
? APPROVAL_ACTION.exec(block.content.text)?.[1]?.trim()
: undefined
)
.find(Boolean)
return action ? acpPermissionPresentation(params, action.slice(0, ACTION_MAX_CHARS)) : undefined
}
export const KIMI_ACP_DIALECT: AcpDialect = {
// Without forms, Kimi drops every question after the first and offers no free-text answer.
clientCapabilities: { elicitation: { form: {} } },
normalizeToolUpdate,
request: approvalRequest
}
+3 -1
View File
@@ -28,6 +28,7 @@ import { OMP_SESSION_HISTORY } from '../../omp/omp-session-history'
import { OMP_TRANSCRIPT_IMPORT } from '../../omp/omp-transcript-import'
import { ANTIGRAVITY_LAUNCH_SPEC } from '../../antigravity/antigravity-acp-launch-spec'
import { COPILOT_LAUNCH_SPEC } from '../../copilot/copilot-acp-launch-spec'
import { KIMI_LAUNCH_SPEC } from '../../kimi/kimi-acp-launch-spec'
import type { AcpLaunchSpec } from './acp-launch-contract'
const GROK_LAUNCH_SPEC: AcpLaunchSpec = {
@@ -156,7 +157,8 @@ export const ACP_LAUNCH_SPECS: readonly AcpLaunchSpec[] = [
OPENCODE2_LAUNCH_SPEC,
OMP_LAUNCH_SPEC,
ANTIGRAVITY_LAUNCH_SPEC,
COPILOT_LAUNCH_SPEC
COPILOT_LAUNCH_SPEC,
KIMI_LAUNCH_SPEC
]
export function acpLaunchSpecFor(agent: string): AcpLaunchSpec | null {
@@ -0,0 +1,115 @@
import { afterEach, expect, it } from 'vitest'
import { readAgentJournalTurn } from '../../../shared/agent-session/lifecycle/agent-session-turn-record'
import { closeProviderTimelineRigs } from '../../native-chat/agent-session-timeline/provider-timeline-assembler-test-support'
import {
HOST_TEST_SESSION as SESSION,
hostTestAttachParams
} from '../../native-chat/agent-session-wire/host/testing/structured-agent-session-host-test-data'
import {
createRestTestRig,
REST_TEST_CALLER,
restTestSend,
sweepOnce,
type RestTestRig
} from '../../native-chat/agent-session-wire/host/testing/structured-agent-session-rest-test-rig'
import { StructuredAgentRegistry } from '../../native-chat/agent-session-wire/providers/structured-agent-registry'
import { STRUCTURED_AGENT_SESSION_IDLE_MS as IDLE_MS } from '../../native-chat/agent-session-wire/termination/structured-agent-session-idle-sweep'
import { acpLaunchSpecFor } from '../launch/acp-launch-registry'
import { readAcpFixture } from '../timeline/testing/acp-timeline-fixture.test-support'
import { acpStructuredAgentDefinition } from './acp-structured-agent-definitions'
import { openAcpAdapterRig, waitFor } from './testing/acp-structured-adapter.test-support'
import { GrokFixtureReplay } from './testing/acp-structured-fixture-replay.test-support'
afterEach(closeProviderTimelineRigs)
async function openChat(agent: 'omp' | 'grok', replay?: GrokFixtureReplay) {
const spec = acpLaunchSpecFor(agent)!
let hostRig: RestTestRig | undefined
const acp = await openAcpAdapterRig({
spec,
script: (scripted) => {
if (replay) {
replay.attach(scripted)
} else {
scripted.on('session/prompt', (frame) => scripted.reply(frame, { stopReason: 'end_turn' }))
}
},
deps: { onEvent: (event) => hostRig?.host.handleAdapterEvent(event) }
})
const rig = await createRestTestRig({
adapter: acp.adapter,
agents: new StructuredAgentRegistry([
{ definition: acpStructuredAgentDefinition(spec), adapter: acp.adapter }
])
})
hostRig = rig
rig.host.collaboratorsForTests().lifetime.idleSweep.dispose()
const attached = await rig.host.attach(
REST_TEST_CALLER,
hostTestAttachParams(null, {
provider: agent,
agent,
accountHome: {
variable: agent === 'omp' ? 'PI_CODING_AGENT_DIR' : 'GROK_HOME',
path: rig.root
},
providerHandle: undefined
})
)
expect(attached).toMatchObject({ ok: true })
return { rig, acp }
}
async function sendAndFinish(rig: RestTestRig, text: string, completed: number) {
expect(await rig.host.send(REST_TEST_CALLER, restTestSend(text))).toMatchObject({ ok: true })
await waitFor(async () => {
const turns = (await rig.host.journalSnapshot(SESSION)).items.flatMap(
(item) => readAgentJournalTurn(item.body) ?? []
)
expect(turns).toHaveLength(completed)
expect(turns.every((turn) => turn.state === 'completed')).toBe(true)
})
}
it('retains an aged OMP child after recorded parent completion, accepts another send, and closes explicitly', async () => {
const replay = new GrokFixtureReplay(await readAcpFixture('omp-v17-reply-without-thought'))
const { rig, acp } = await openChat('omp', replay)
try {
await sendAndFinish(rig, 'First question', 1)
const child = acp.child()
rig.clock.now += IDLE_MS + 1
await sweepOnce(rig.host)
expect(child.exited).toBe(false)
expect(rig.host.hasSession(SESSION)).toBe(true)
// Completion uncertainty remains uncertainty even long after the normal idle window.
rig.clock.now += 24 * 60 * 60_000
await sweepOnce(rig.host)
expect(child.exited).toBe(false)
await sendAndFinish(rig, 'Follow-up question', 2)
expect(replay.awaiting).toBeNull()
expect(acp.child()).toBe(child)
await rig.host.close(SESSION, 'user-close')
expect(child.exited).toBe(true)
expect(rig.host.hasSession(SESSION)).toBe(false)
} finally {
await acp.adapter.closeAll()
await rig.dispose()
}
})
it('still retires an idle ACP child whose provider has no extra idle confirmation', async () => {
const { rig, acp } = await openChat('grok')
try {
await sendAndFinish(rig, 'First question', 1)
const child = acp.child()
rig.clock.now += IDLE_MS + 1
await sweepOnce(rig.host)
expect(child.exited).toBe(true)
expect(rig.host.hasSession(SESSION)).toBe(false)
} finally {
await acp.adapter.closeAll()
await rig.dispose()
}
})
@@ -222,6 +222,14 @@ export class AcpStructuredSessionAdapter implements SessionAdapter {
return session ? childState.isAcpReadySession(session) && session.turns.running : false
}
confirmIdle: NonNullable<SessionAdapter['confirmIdle']> = (sessionId) => {
const session = this.children.sessions.get(sessionId)
// OMP cannot prove that a finished parent has no background work or pending results.
return session?.spec.agent === 'omp' && !session.connection.exited
? Promise.resolve('unknown')
: undefined
}
holdsLiveProviderProcess = (sessionId: string, generation: string): boolean => {
const session = this.children.sessions.get(sessionId)
return session?.acquisitionGeneration === generation && !session.connection.exited
@@ -1,315 +0,0 @@
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { PANE } from '../server.test-fixtures'
import { makePaneKey } from '../../../../../shared/workspace-layout/stable-pane-id'
import {
readHookRootEvidence,
type HookPaneRoot
} from '../../../../../shared/agent-hook-listener/presence/hook-process-root-evidence'
import type { AgentHookRelayEnvelope } from '../../../../../shared/agent-hook-listener/transport/agent-hook-relay'
import { RelayAgentHookServer } from '../../../../../wsl-guest/agent-hook-server'
import { startOrcadAgentHookServer } from '../../../../orcad/orcad-managed-agent-hooks'
import {
NOW,
CLAUDE,
NESTED,
BACKGROUND,
io,
probe,
paths,
attempts,
capture,
launchServer,
runningPane,
hook,
settled,
registerRootTestHarness,
type Proc
} from './server-hook-root.test-fixtures'
vi.mock('../../../../telemetry/client', () => ({ track: vi.fn() }))
vi.mock('../../../../telemetry/cohort-classifier', () => ({ getCohortAtEmit: () => ({}) }))
vi.mock('../../../../../shared/agent-status/process/agent-process-presence-probe', () => ({
probeAgentProcessPresence: vi.fn()
}))
registerRootTestHarness()
beforeEach(() => {
// Replay's answer deadline runs on the monotonic clock and its timers, so both are faked.
vi.useFakeTimers({ toFake: ['Date', 'performance', 'setTimeout', 'clearTimeout'] })
vi.setSystemTime(NOW)
})
const ROOT_ANSWER: HookPaneRoot = { pid: 100, incarnation: 'inc-1' }
const paneOf = (index: number) =>
makePaneKey(`tab-${index + 2}`, `${String(index).padStart(8, '0')}-0000-4000-8000-000000000000`)
function spooled(
paneKey: string,
pid: number | null,
payload: Record<string, unknown>
): Record<string, unknown> {
return {
paneKey,
tabId: paneKey.split(':')[0],
worktreeId: 'wt-1',
source: 'claude',
receivedAt: NOW,
...(pid === null ? {} : { agentProcess: JSON.stringify(capture(pid)) }),
payload
}
}
/** Hooks that could not reach Orca while it was down, in the order they were written. */
function spoolDir(records: Record<string, unknown>[]): string {
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-root-replay-'))
paths.push(userDataPath)
const dir = join(userDataPath, 'agent-hooks', 'spool')
mkdirSync(dir, { recursive: true })
writeFileSync(join(dir, 'panes.jsonl'), `${records.map((r) => JSON.stringify(r)).join('\n')}\n`)
return userDataPath
}
/** The PTY owner answers `held` panes only once released, as a slow host or cold inventory does;
* every other pane in `ms` ms. Resolves `requested` with the first read. */
function rootAnswers(held: (paneKey: string) => boolean, ms = 20) {
let release = (): void => {}
const named = new Promise<HookPaneRoot>((resolve) => {
release = () => resolve(ROOT_ANSWER)
})
const requested = Promise.withResolvers<void>()
io.resolveRoot.mockImplementation((paneKey) => {
requested.resolve()
if (held(paneKey)) {
return named
}
// ast-grep-ignore: test-no-real-time-wait -- fake timers drive this simulated read delay
return new Promise((resolve) => setTimeout(() => resolve(ROOT_ANSWER), ms))
})
return { release, requested: requested.promise }
}
describe('startup spool replay of panes without a proven owner', () => {
it.each([[6], [60]])(
'replays %i panes within one answer allowance, binds, then heals them with no hook',
async (count) => {
const panes = [...Array.from({ length: count - 1 }, (_, index) => paneOf(index)), PANE]
const userDataPath = spoolDir(
panes.flatMap((paneKey, index) => [
spooled(paneKey, 49969, {
hook_event_name: 'UserPromptSubmit',
session_id: `s-${index}`,
prompt: `task ${index}`
}),
spooled(paneKey, 49969, {
hook_event_name: 'PostToolUse',
session_id: `s-${index}`,
tool_name: 'Bash'
})
])
)
runningPane(49969, CLAUDE)
const { release, requested } = rootAnswers(() => true)
const startedAt = performance.now()
const { server, started } = launchServer(userDataPath)
await requested
await vi.advanceTimersByTimeAsync(500)
await started
// One allowance for the whole drain; each pane's second record joined its pending read.
expect(performance.now() - startedAt).toBe(500)
expect(attempts()).toBe(count)
panes.forEach((paneKey, index) => {
expect(server.row(paneKey)).toMatchObject({ state: 'working', prompt: `task ${index}` })
expect(server.presence(paneKey)).toMatchObject({ process: capture(49969), fallback: true })
})
// The drain's deadline is past; the late answers settle on real timers.
vi.useRealTimers()
release()
await settled(count)
for (const paneKey of panes) {
expect(server.presence(paneKey)).toMatchObject({ process: capture(49969) })
expect(server.presence(paneKey)?.fallback).toBeUndefined()
}
// The bound listener answers the healed owner's live hook, which buys no new read.
await hook(server, 'PostToolUse', { session: `s-${count - 1}` })
expect(attempts()).toBe(count)
}
)
it('keeps a live hook on an already bound server to the same allowance when hooks turn on', async () => {
const panes = [...Array.from({ length: 5 }, (_, index) => paneOf(index)), PANE]
const userDataPath = spoolDir(
panes.map((paneKey) =>
spooled(paneKey, 49969, { hook_event_name: 'UserPromptSubmit', prompt: 'task' })
)
)
runningPane(49969, CLAUDE)
const { release, requested } = rootAnswers(() => true)
const { server, started } = launchServer(userDataPath, {
start: (target) =>
target.start({ env: 'production', userDataPath, statusHooksEnabled: false })
})
await started
expect(attempts()).toBe(0)
const startedAt = performance.now()
server.setStatusHooksEnabled(true)
// A live hook arriving during the first initialization waits for its replay.
const live = hook(server, 'PostToolUse', { session: 'live' })
await requested
await vi.advanceTimersByTimeAsync(500)
await live
expect(performance.now() - startedAt).toBe(500)
expect(attempts()).toBe(6)
vi.useRealTimers()
release()
await settled(6)
expect(server.presence()?.fallback).toBeUndefined()
})
it('hands an answer after the spent allowance to the host, which heals and retires once', async () => {
const [slow, healed, exiting] = [paneOf(0), paneOf(1), paneOf(2)]
const userDataPath = spoolDir([
spooled(slow, 49969, { hook_event_name: 'UserPromptSubmit', session_id: 'a', prompt: 'A' }),
spooled(healed, null, { hook_event_name: 'UserPromptSubmit', session_id: 'b', prompt: 'B' }),
spooled(healed, 49969, {
hook_event_name: 'PostToolUse',
session_id: 'b',
tool_name: 'Bash'
}),
spooled(exiting, null, { hook_event_name: 'UserPromptSubmit', session_id: 'c', prompt: 'C' }),
spooled(exiting, 49969, {
hook_event_name: 'PostToolUse',
session_id: 'c',
tool_name: 'Bash'
}),
// The final exit joins the pending read; it is owed once that read proves the root.
spooled(exiting, 49969, {
hook_event_name: 'SessionEnd',
session_id: 'c',
reason: 'prompt_input_exit'
})
])
runningPane(49969, CLAUDE)
const { release, requested } = rootAnswers((paneKey) => paneKey === slow)
const { server, started } = launchServer(userDataPath)
await requested
await vi.advanceTimersByTimeAsync(500)
await started
expect(server.presence(healed)).toEqual({ agent: 'claude', session: 'b' })
// Both answers arrive well before either pair's own 500 ms would have ended.
await vi.advanceTimersByTimeAsync(20)
expect(server.presence(healed)).toMatchObject({ process: capture(49969), session: 'b' })
expect(server.row(healed)).toMatchObject({ prompt: 'B' })
expect(server.presence(exiting)).toMatchObject({ process: capture(49969), ended: true })
expect(server.exits).toBe(1)
vi.useRealTimers()
release()
await settled(3)
expect(server.exits).toBe(1)
})
it.each<[string, Proc[], number]>([
['nested run', NESTED, 49980],
['background agent beside the pane’s own', [BACKGROUND], 49990]
])(
'refuses a %s whose answer fits the allowance, and again from cached evidence once it is spent',
async (_name, procs, pid) => {
const slow = paneOf(0)
const userDataPath = spoolDir([
spooled(PANE, null, {
hook_event_name: 'UserPromptSubmit',
session_id: 'parent',
prompt: 'Parent task'
}),
spooled(PANE, pid, {
hook_event_name: 'UserPromptSubmit',
session_id: 'child',
prompt: 'Child task'
}),
spooled(slow, 49969, { hook_event_name: 'UserPromptSubmit', session_id: 'a', prompt: 'A' }),
spooled(PANE, pid, {
hook_event_name: 'UserPromptSubmit',
session_id: 'child',
prompt: 'Child again'
})
])
runningPane(49969, CLAUDE, ...procs)
const { release, requested } = rootAnswers((paneKey) => paneKey === slow)
const startedAt = performance.now()
const { server, started } = launchServer(userDataPath)
await requested
await vi.advanceTimersByTimeAsync(500)
await started
expect(performance.now() - startedAt).toBe(500)
expect(server.row()).toMatchObject({ prompt: 'Parent task' })
expect(server.presence()).toEqual({ agent: 'claude', session: 'parent' })
release()
}
)
})
describe('WSL relay startup spool replay', () => {
it.each([[6], [60]])(
'replays %i panes within one answer allowance before binding, then forwards each heal',
async (count) => {
const panes = Array.from({ length: count }, (_, index) => paneOf(index))
const endpointDir = join(
spoolDir(
panes.map((paneKey) =>
spooled(paneKey, 49969, { hook_event_name: 'UserPromptSubmit', prompt: 'task' })
)
),
'agent-hooks'
)
runningPane(49969, CLAUDE)
probe.mockResolvedValue('live')
const { release, requested } = rootAnswers(() => true)
const forward = vi.fn<(event: AgentHookRelayEnvelope) => void>()
const relay = new RelayAgentHookServer({
endpointDir,
forward,
readHookRootEvidence: (request) => readHookRootEvidence(request, io)
})
try {
const startedAt = performance.now()
const started = relay.start()
await requested
await vi.advanceTimersByTimeAsync(500)
await started
expect(performance.now() - startedAt).toBe(500)
expect(relay.getCoordinates().port).toBeGreaterThan(0)
expect(attempts()).toBe(count)
vi.useRealTimers()
forward.mockClear()
release()
await vi.waitFor(() => {
const healed = forward.mock.calls
.map(([event]) => event)
.filter((event) => event.agentPresence?.process && !event.agentPresence.fallback)
expect(new Set(healed.map((event) => event.paneKey)).size).toBe(count)
})
} finally {
relay.stop()
}
}
)
})
describe.skipIf(process.platform === 'win32')('orcad startup', () => {
it('installs its pane-root reader before replay, so a pane it cannot bind stays a fallback', async () => {
const userDataPath = spoolDir([
spooled(PANE, 49969, { hook_event_name: 'UserPromptSubmit', prompt: 'task' })
])
runningPane(49969, CLAUDE)
// Before the daemon provider is installed, the local provider owns no PTY for this pane.
const { server, started } = launchServer(userDataPath, {
reader: false,
start: (target) => startOrcadAgentHookServer(target, { env: 'production', userDataPath })
})
await started
expect(server.presence()).toMatchObject({ process: capture(49969), fallback: true })
})
})
@@ -42,7 +42,8 @@ afterEach(async () => {
})
it('orcad resolves no roots while disabled and discovers late roots when enabled', async () => {
const { installOrcadSessionSearchService } = await import('../orcad/orcad-session-search')
const { installOrcadSessionSearchService } =
await import('../orcad/host-runtime/orcad-session-search')
installed = await installOrcadSessionSearchService({
userDataPath: harness.root,
getSettings: () => ({ aiVaultSearch: { enabled: false, historyDays: null } })
@@ -1,18 +0,0 @@
import type { AiVaultSession } from '../../../shared/ai-vault/contracts/ai-vault-types'
import { CONVERSATION_NAME_PROMPT_OPENING } from '../../../shared/source-control/ai/generation/conversation-name-generation'
const MAX_NAME_REQUEST_MESSAGES = 6
/** CLI naming runs share chat folders; keep sessions with user follow-ups visible (#29973). */
export function isConversationNameRequestSession(session: AiVaultSession): boolean {
if (session.previewMessagesTruncated || session.messageCount > MAX_NAME_REQUEST_MESSAGES) {
return false
}
const [request, ...followUps] = session.previewMessages.filter(
(message) => message.role === 'user'
)
return (
followUps.length === 0 &&
request?.text.trimStart().startsWith(CONVERSATION_NAME_PROMPT_OPENING) === true
)
}
@@ -1,5 +1,5 @@
import { yieldToEventLoop } from '../../../shared/event-loop-yield'
import { isConversationNameRequestSession } from './conversation-name-request-sessions'
import { isTextTaskRequestSession } from './text-task-request-sessions'
import { candidateFileTime } from '../scanners/antigravity/antigravity-transcript-candidates'
import {
aiVaultAgentLabel,
@@ -107,7 +107,7 @@ export async function parseSessionCandidates(args: {
}
if (
result.session &&
!isConversationNameRequestSession(result.session) &&
!isTextTaskRequestSession(result.session) &&
(!args.admitSession || args.admitSession(result.session))
) {
if (args.listed === false) {
@@ -0,0 +1,22 @@
import type { AiVaultSession } from '../../../shared/ai-vault/contracts/ai-vault-types'
import { DICTATION_CLEANUP_PROMPT_OPENING } from '../../../shared/dictation-cleanup'
import { CONVERSATION_NAME_PROMPT_OPENING } from '../../../shared/source-control/ai/generation/conversation-name-generation'
const MAX_TEXT_TASK_REQUEST_MESSAGES = 6
/** One-shot CLI runs (chat naming, dictation cleanup) aren't conversations; sessions with user follow-ups stay visible (#29973). */
export function isTextTaskRequestSession(session: AiVaultSession): boolean {
if (session.previewMessagesTruncated || session.messageCount > MAX_TEXT_TASK_REQUEST_MESSAGES) {
return false
}
const [request, ...followUps] = session.previewMessages.filter(
(message) => message.role === 'user'
)
const text = request?.text.trimStart()
return (
followUps.length === 0 &&
text !== undefined &&
(text.startsWith(CONVERSATION_NAME_PROMPT_OPENING) ||
text.startsWith(DICTATION_CLEANUP_PROMPT_OPENING))
)
}
@@ -14,7 +14,7 @@ import {
resolveWorkerThreadEntryPath
} from '../worker-threads/worker-thread-entry-path'
import { ManagedOrcadEventWindow } from '../managed-server/lifecycle/orcad-managed-event-window'
import { ORCAD_SHUTDOWN_DEADLINE_MS } from '../orcad/orcad-stop-deadlines'
import { ORCAD_SHUTDOWN_DEADLINE_MS } from '../orcad/host-lifecycle/managed-stop/orcad-stop-deadlines'
import {
createBackendDesktopCapabilities,
trustsBackendRenderer,
+3 -3
View File
@@ -7,9 +7,9 @@ import { agentTokenUsageSchema } from '../../shared/telemetry-agent-token-usage-
import { backendMessagePort, type BackendNativePort } from './backend-message-port'
import { createDesktopBackendEnvironment } from './node-service-environment'
import { BackendServiceLifetime, activateBackendServices } from './service-composition'
import { acquireOrcadInstanceLock } from '../orcad/orcad-instance-lock'
import { OrcadInstanceLockError } from '../orcad/orcad-data-root-privacy'
import { ORCAD_SHUTDOWN_DEADLINE_MS } from '../orcad/orcad-stop-deadlines'
import { acquireOrcadInstanceLock } from '../orcad/instance-lock/orcad-instance-lock'
import { OrcadInstanceLockError } from '../orcad/instance-lock/orcad-data-root-privacy'
import { ORCAD_SHUTDOWN_DEADLINE_MS } from '../orcad/host-lifecycle/managed-stop/orcad-stop-deadlines'
import { clearWindowsStdHandleInheritance } from '../startup/windows-startup/windows-std-handle-inheritance'
import { installWindowsIsolatedSpawner } from '../startup/windows-startup/windows-isolated-spawner'
import { dropE2eSpawnLogOutsideE2e } from '../startup/testing/e2e-spawn-log-env'
+1 -1
View File
@@ -1,4 +1,4 @@
import { startOrcadEventLoopWatchdog } from '../orcad/orcad-event-loop-watchdog'
import { startOrcadEventLoopWatchdog } from '../orcad/diagnostics/orcad-event-loop-watchdog'
export type BackendServiceCleanup = (state: { failed: boolean }) => void | Promise<void>
@@ -91,13 +91,9 @@ export abstract class AgentBrowserBridgeKeyCommands extends AgentBrowserBridgeCa
if (typeof step === 'string') {
// Text no key types (emoji, controls) goes in like a paste, between the keys around it.
await flush()
const route = await routePageTextInsertion(wc, { text: step }, send, guardFocus)
try {
assertExpectedPageUrlForStep()
await route.deliver({ text: step })
} finally {
route.release()
}
const route = await routePageTextInsertion(wc, send)
assertExpectedPageUrlForStep()
await route.deliver({ text: step })
continue
}
const event = {
@@ -1,9 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
import {
BROWSER_TEXT_INSERT_CHUNK_BYTES,
splitBrowserTextInsertionChunks
} from '../../../../shared/browser-text-insertion-chunks'
import { insertTextThroughCdp } from './browser-text-insertion'
import { describe, expect, it } from 'vitest'
import { splitBrowserTextInsertionChunks } from '../../../../shared/browser-text-insertion-chunks'
describe('browser text insertion chunking', () => {
it('keeps a single multibyte character intact when the byte cap is smaller', () => {
@@ -12,17 +8,4 @@ describe('browser text insertion chunking', () => {
expect(chunks).toEqual(['😀', 'a'])
expect(chunks.join('')).toBe('😀a')
})
it('sends bounded CDP insertText chunks in order', async () => {
const sender = vi.fn().mockResolvedValue({})
const text = 'x'.repeat(BROWSER_TEXT_INSERT_CHUNK_BYTES + 3)
await insertTextThroughCdp(sender, text, { yieldBetweenChunks: false })
expect(sender).toHaveBeenCalledTimes(2)
expect(sender).toHaveBeenNthCalledWith(1, 'Input.insertText', {
text: 'x'.repeat(BROWSER_TEXT_INSERT_CHUNK_BYTES)
})
expect(sender).toHaveBeenNthCalledWith(2, 'Input.insertText', { text: 'xxx' })
})
})
@@ -4,7 +4,7 @@ import type { CdpClientResponseWriter } from '../transport/cdp-client-response-w
import type { CdpDebuggerChannel } from '../debugger/cdp-debugger-channel'
import type { TextInsertionRoute } from './guest-direct-key-input'
/** Replay DOM.focus before insertion because native focusing can blur the target. */
/** Replay DOM.focus before insertion so pipelined inserts use the resolved element. */
export class CdpDomFocusReplay {
private pendingDomFocusBySession = new Map<
string | undefined,
@@ -72,7 +72,7 @@ export class CdpDomFocusReplay {
return pendingFocus
}
/** Choose the route before replay: native fallback focus can blur the target. */
/** Choose a page-bound route before replaying the selected element. */
async insertText(
client: WebSocket,
clientId: number,
@@ -97,18 +97,14 @@ export class CdpDomFocusReplay {
this.responder.sendError(clientId, err instanceof Error ? err.message : String(err), client)
return
}
try {
await this.replayAndDeliver(
client,
clientId,
params,
effectiveSessionId,
pendingFocusParams,
route
)
} finally {
route.release()
}
await this.replayAndDeliver(
client,
clientId,
params,
effectiveSessionId,
pendingFocusParams,
route
)
}
private async replayAndDeliver(

Some files were not shown because too many files have changed in this diff Show More