Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .fallowrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"scripts/check-provider-plugin.mjs",
"scripts/check-affected/command.ts",
"packages/provider-testmu/test/package-smoke.mjs",
"packages/maestro/test/package-artifact.test.mjs",
"packages/maestro/test/packed-clickability.mjs",
Comment thread
thymikee marked this conversation as resolved.
Resolved
"packages/maestro/test/packed-screen-origin.mjs",
"packages/maestro/test/package-test-support.mjs",
"packages/maestro/tsdown.config.ts",
"packages/maestro/src/plugin.ts",
"packages/provider-testmu/tsdown.config.ts",
"packages/provider-revyl/test/package-smoke.mjs",
"packages/provider-revyl/tsdown.config.ts",
Expand Down Expand Up @@ -150,8 +156,8 @@
"exports": ["*"]
},
{
// A published provider package's default export is its plugin contract; the plugin loader imports the installed package's resolved entry at runtime and reads `default`.
"file": "packages/provider-*/src/index.ts",
// A published plugin's default export is its contract; the plugin loader imports the installed package's resolved entry at runtime and reads `default`.
"file": "packages/{provider-*/src/index,maestro/src/plugin}.ts",
"exports": ["default"]
},
{
Expand Down Expand Up @@ -281,7 +287,7 @@
},
{
// Tool config default exports, loaded by the tool rather than imported.
"file": "{oxlint.config.ts,tsdown.config.ts,packages/provider-*/tsdown.config.ts,packages/proxy/tsdown.config.ts,vitest.mutation.config.ts}",
"file": "{oxlint.config.ts,tsdown.config.ts,packages/provider-*/tsdown.config.ts,packages/maestro/tsdown.config.ts,packages/proxy/tsdown.config.ts,vitest.mutation.config.ts}",
"exports": ["default"]
},
{
Expand Down
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,28 @@ jobs:
uses: ./.github/actions/run-gate
with: { gate: build }

- name: Verify the core and standalone Maestro packages
uses: ./.github/actions/run-gate
with: { gate: package }

- name: Verify emitted chunk ownership
uses: ./.github/actions/run-gate
with: { gate: bundle-owner-files }

# The build runs on the default toolchain Node and the package is verified on the minimum
- name: Setup Node.js 22.13
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: '22.13.0'

- name: Verify the repository build on Node.js 22.13
uses: ./.github/actions/run-gate
with: { gate: build }

- name: Verify development packaging on Node.js 22.13
uses: ./.github/actions/run-gate
with: { gate: package }

# The build runs on the development floor and the package is verified on the minimum
# supported Node, so this job covers what a user on `engines.node` floor actually installs.
- name: Setup Node.js 22.12
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
Expand All @@ -118,7 +135,7 @@ jobs:
#
# Runs the script directly rather than through `pnpm check:package`: the repo's pinned pnpm
# requires Node >= 22.13 and refuses to start on the 22.12 floor this job exists to cover. The
# gate itself only needs `node` and `npm`, so it is the package.json script minus the launcher.
# root-package probe only needs `node` and `npm`. The full package gate runs above.
- name: Verify the published package on Node.js 22.12
run: node --experimental-strip-types scripts/check-package.ts

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"depgraph:test": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/depgraph/model.test.ts scripts/depgraph/entries.test.ts scripts/depgraph/import-graph.test.ts scripts/depgraph/affected.test.ts scripts/depgraph/structure-summary.test.ts tools/depgraph-view/*.test.mjs",
"check:production-exports": "fallow dead-code --config fallow-production-exports.json --production --unused-exports --fail-on-issues",
"check:bundle-owner-files": "node --experimental-strip-types scripts/check-bundle-owner-files.ts",
"check:package": "node --experimental-strip-types scripts/check-package.ts",
"check:package": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test packages/maestro/test/package-artifact.test.mjs && node --experimental-strip-types scripts/check-package.ts",
"check:command-docs": "vitest run --project unit-core test/repo-guards/command-doc-coverage.test.ts",
"check:adr-citations": "vitest run --project unit-core test/repo-guards/adr-citations.test.ts",
"check:capabilities-matrix": "vitest run --project unit-core test/repo-guards/capability-matrix.test.ts",
Expand Down Expand Up @@ -373,6 +373,7 @@
"tsdown": "^0.22.14",
"typescript": "^7.0.2",
"undici": "7.30.1",
"unrun": "0.3.1",
"vite": "^8.3.5",
"vitest": "5.0.4",
"yaml": "^2.9.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/contracts/src/host-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ export type HostDiagnostics = Readonly<{
context: HostDiagnosticsContext,
): Promise<DoctorCheck | undefined>;
}>;

/** The severity an event is recorded with. */
export type DiagnosticLevel = 'info' | 'warn' | 'error' | 'debug';

/** A diagnostic handed to the host that owns the request log and redaction. */
export type DiagnosticEventInput = {
level?: DiagnosticLevel;
phase: string;
durationMs?: number;
data?: Record<string, unknown>;
};
3 changes: 2 additions & 1 deletion packages/contracts/src/platform-runtime-use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RuntimeUseInput<
* Runtime validation keeps declarations built from dynamic data fail-closed too.
*/
export function runtimeUse<Operations extends object>() {
return <
const define = <
const Required extends readonly RuntimeOperationKey<Operations>[],
const Preferred extends readonly Exclude<RuntimeOperationKey<Operations>, Required[number]>[] =
readonly [],
Expand Down Expand Up @@ -68,6 +68,7 @@ export function runtimeUse<Operations extends object>() {
conditional.length === 0 ? { required, preferred } : { required, preferred, conditional },
) as RuntimeUse<Operations, Required, Preferred, Conditional>;
};
return define;
}

function freezeUniqueKeys<Keys extends readonly string[]>(keys: Keys, label: string): Keys {
Expand Down
9 changes: 8 additions & 1 deletion packages/contracts/src/replay-backend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DiagnosticEventInput } from './host-diagnostics.ts';
import type { SnapshotClickabilityEvidence } from './snapshot-private-evidence.ts';
import type { DaemonError } from '@agent-device/kernel/errors';
import type { DaemonResponse, SessionRuntimeHints } from '@agent-device/kernel/contracts';
import type { DeviceInfo } from '@agent-device/kernel/device';
Expand Down Expand Up @@ -230,6 +232,11 @@ export type ReplayBackendDeviceBinding = Readonly<{
* session policy is a member; stateless workspace packages stay direct imports of the plugin.
*/
export type ReplayBackendHost = Readonly<{
emitDiagnostic(event: DiagnosticEventInput): void;
/** Reads capture-local facts from the host's private evidence owner, without wire fields. */
readSnapshotClickabilityEvidence(owner: object): SnapshotClickabilityEvidence | undefined;
/** Refuses capture-derived input when the host has no established screen origin. */
assertSnapshotScreenOrigin(owner: object, label: string): Promise<void>;
/** Appends one record to the run's trace file, if any; failures are diagnostics, never thrown. */
appendTraceEvent(tracePath: string | undefined, event: Record<string, unknown>): void;
/** The `AD_*` variables every replay run is seeded with. */
Expand Down Expand Up @@ -269,5 +276,5 @@ export type ReplayBackendDeclaration<TId extends string = string> = Readonly<{
}>;

export type ReplayBackendPlugin<TId extends string = string> = Readonly<{
create(host: ReplayBackendHost): ReplayBackend<TId>;
create(host: ReplayBackendHost): ReplayBackend<TId> | Promise<ReplayBackend<TId>>;
}>;
47 changes: 36 additions & 11 deletions packages/maestro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
"name": "@agent-device/maestro",
"version": "0.0.0",
"private": true,
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/callstack/agent-device.git",
"directory": "packages/maestro"
},
"sideEffects": false,
"type": "module",
"description": "Private Maestro compatibility engine for agent-device.",
"dependencies": {
"@agent-device/ad-script": "workspace:*",
"@agent-device/capture-kit": "workspace:*",
"@agent-device/contracts": "workspace:*",
"@agent-device/host-kit": "workspace:*",
"@agent-device/kernel": "workspace:*",
"@agent-device/provision-kit": "workspace:*",
"@agent-device/selectors": "workspace:*"
},
"description": "Optional Maestro compatibility engine plugin for agent-device.",
Comment thread
thymikee marked this conversation as resolved.
Resolved
"exports": {
".": {
"types": "./src/index.ts",
Expand All @@ -30,10 +27,38 @@
"./run-script-http": {
"types": "./src/daemon-port/run-script-http.ts",
"default": "./src/daemon-port/run-script-http.ts"
},
"./agent-device": {
"types": "./src/plugin.ts",
"default": "./src/plugin.ts"
}
},
"devDependencies": {
"undici": "7.30.1",
"yaml": "^2.9.0"
"yaml": "^2.9.0",
"@agent-device/ad-script": "workspace:*",
"@agent-device/capture-kit": "workspace:*",
"@agent-device/contracts": "workspace:*",
"@agent-device/host-kit": "workspace:*",
"@agent-device/kernel": "workspace:*",
"@agent-device/provision-kit": "workspace:*",
"@agent-device/selectors": "workspace:*",
"agent-device": "workspace:*"
},
"scripts": {
"build": "tsdown --config tsdown.config.ts",
"prepack": "pnpm build"
},
"files": [
"dist"
],
"publishConfig": {
"exports": {
"./agent-device": {
"types": "./dist/agent-device.d.mts",
"import": "./dist/agent-device.mjs"
}
},
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { CommandFlags } from '@agent-device/contracts/command';
import {
assertSnapshotScreenOrigin,
readSnapshotClickabilityEvidence,
} from '@agent-device/contracts/capture';
import { formatRole } from '@agent-device/kernel/snapshot';
import type { SnapshotNode } from '@agent-device/kernel/snapshot';
import type { SnapshotState } from '@agent-device/contracts/snapshot-model';
Expand All @@ -21,8 +25,13 @@ export function makeSnapshot(
/** The daemon-owned half of the port options: the runtime envelope flags and the network origin. */
export function makeRuntimeEnvelope(
overrides: { flags?: CommandFlags; publicNetworkOnly?: boolean } = {},
): Pick<CreateDaemonMaestroRuntimeOperationsOptions, 'flags' | 'publicNetworkOnly'> {
): Pick<
CreateDaemonMaestroRuntimeOperationsOptions,
'flags' | 'publicNetworkOnly' | 'readSnapshotClickabilityEvidence' | 'assertSnapshotScreenOrigin'
> {
return {
readSnapshotClickabilityEvidence,
assertSnapshotScreenOrigin,
publicNetworkOnly: false,
...overrides,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppError } from '@agent-device/kernel/errors';
import type { SnapshotState } from '@agent-device/contracts/snapshot-model';
import { copySnapshotClickabilityEvidence } from '@agent-device/contracts/capture';
import { attachSnapshotClickabilityEvidence } from '@agent-device/contracts/capture';
import {
MAESTRO_RUNTIME_ADAPTER_POLICY,
type MaestroObservationIdentity,
Expand Down Expand Up @@ -36,7 +36,9 @@ export function createDaemonMaestroSnapshotSource(
if (!data || !Array.isArray(data.nodes)) {
throw new AppError('COMMAND_FAILED', 'Maestro snapshot did not return node data.');
}
const snapshot = copySnapshotClickabilityEvidence(data, data as SnapshotState);
const snapshot = data as SnapshotState;
const clickability = options.readSnapshotClickabilityEvidence(data);
if (clickability) attachSnapshotClickabilityEvidence(snapshot, clickability);
cached = { generation: context.generation, snapshot };
return snapshot;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { CommandFlags } from '@agent-device/contracts/command';
import type { ReplayBackendHost } from '@agent-device/contracts/replay-backend';
import path from 'node:path';
import type {
MaestroObservation,
Expand All @@ -22,7 +23,10 @@ export type MaestroDaemonOperationInvoke = (
request: MaestroDaemonOperationRequest,
) => Promise<DaemonResponse>;

export type CreateDaemonMaestroRuntimeOperationsOptions = {
export type CreateDaemonMaestroRuntimeOperationsOptions = Pick<
ReplayBackendHost,
'readSnapshotClickabilityEvidence' | 'assertSnapshotScreenOrigin'
> & {
readonly invoke: MaestroDaemonOperationInvoke;
/** The runtime envelope every operation carries: platform, target, device, and recording flags. */
readonly flags?: CommandFlags;
Expand Down
4 changes: 2 additions & 2 deletions packages/maestro/src/daemon-port/daemon-runtime-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@agent-device/maestro';
import { registerDiagnosticSensitiveValue } from '@agent-device/host-kit/diagnostics';
import { AppError } from '@agent-device/kernel/errors';
import { assertSnapshotScreenOrigin } from '@agent-device/contracts/capture';
import { stripUndefined } from '@agent-device/kernel/record';
import { executeRunScriptFile } from './run-script-execution.ts';
import { captureMaestroComparisonScreenshot } from './maestro-comparison-screenshot.ts';
Expand Down Expand Up @@ -301,7 +300,8 @@ function createDaemonMaestroRuntimeParts(options: CreateDaemonMaestroRuntimeOper
input.durationMs,
platform,
);
if (gesture) await assertSnapshotScreenOrigin(snapshot.nodes, 'Maestro scroll target');
if (gesture)
await options.assertSnapshotScreenOrigin(snapshot.nodes, 'Maestro scroll target');
await invokeMutation(
gesture
? { kind: 'swipe', ...gesture }
Expand Down
3 changes: 1 addition & 2 deletions packages/maestro/src/daemon-port/daemon-runtime-tap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AppError, asAppError } from '@agent-device/kernel/errors';
import { assertSnapshotScreenOrigin } from '@agent-device/contracts/capture';
import { INTERACTION_ERROR_REASONS } from '@agent-device/selectors/interaction-error';
import type { Rect } from '@agent-device/kernel/snapshot';
import {
Expand Down Expand Up @@ -52,7 +51,7 @@ export async function resolveDaemonMaestroTarget(params: {
{ context, snapshot: snapshots.capture, dependencies: options.dependencies },
deadline,
);
await assertSnapshotScreenOrigin(currentSnapshot.nodes, 'Maestro selector target');
await options.assertSnapshotScreenOrigin(currentSnapshot.nodes, 'Maestro selector target');
const match = resolveTypedMaestroTarget({
query: input,
context,
Expand Down
13 changes: 7 additions & 6 deletions packages/maestro/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ describe('@agent-device/maestro facade', () => {
test('keeps the plugin and helper off the engine entry and declares pure modules', () => {
const manifest = JSON.parse(
fs.readFileSync(path.join(import.meta.dirname, '../package.json'), 'utf8'),
) as { exports: Record<string, unknown>; sideEffects?: boolean };
// The runScript HTTP helper is a subpath, not part of the engine entry, and the replay
// backend plugin (#3377) is the only other way in: its engine-free declaration lets help list
// the backend without evaluating the engine. This pins the surface;
// scripts/__tests__/eager-closure-budgets.test.ts is what keeps `.` from starting to evaluate
// host-kit, capture-kit, or provision-kit.
) as {
exports: Record<string, unknown>;
publishConfig: { exports: Record<string, unknown> };
sideEffects?: boolean;
};
expect(Object.keys(manifest.exports)).toEqual([
'.',
'./replay-backend',
'./replay-backend-declaration',
'./run-script-http',
'./agent-device',
]);
expect(Object.keys(manifest.publishConfig.exports)).toEqual(['./agent-device']);
expect(manifest.sideEffects).toBe(false);
});
});
Loading
Loading