@burdenoff/ui-engine 0.0.0-stage → 2026.1127.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +62 -2
- package/dist/capture.d.ts +118 -0
- package/dist/capture.js +14 -0
- package/dist/index-05zgh18g.js +210 -0
- package/dist/index-3v887c75.js +52 -0
- package/dist/index-c6pmt2rg.js +213 -0
- package/dist/index-phd8yhyg.js +224 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +62 -0
- package/dist/recording.d.ts +214 -0
- package/dist/recording.js +28 -0
- package/dist/redact-credentials.d.ts +39 -0
- package/dist/replay.d.ts +144 -0
- package/dist/replay.js +20 -0
- package/dist/resolve.d.ts +43 -0
- package/dist/resolve.js +10 -0
- package/package.json +94 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Burdenoff Consultancy Services Private Limited,
|
|
4
|
+
Algoshred Technologies Private Limited,
|
|
5
|
+
and all its sister companies.
|
|
6
|
+
|
|
7
|
+
Maintainer: Vignesh T.V <https://github.com/tvvignesh>
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is furnished
|
|
14
|
+
to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @burdenoff/ui-engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The shared, browser-safe UI automation engine behind FluidGrids RPA ("Use Browser") and BotManor Stewards teach mode. It holds the recorded-step format, capture-time masking, target resolution and the replay planner, and it runs unchanged in a browser extension (MV3), a bundled web app, Bun and Node.
|
|
4
|
+
|
|
5
|
+
FluidGrids owns this package; changes that touch the recording format, masking or fingerprints also need a Stewards reviewer.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @burdenoff/ui-engine zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`zod` (`^4.6.6`) is a peer dependency, so an app that already uses zod 4 ships a single copy. The only runtime dependency is `@noble/hashes` (pure JavaScript sha256).
|
|
14
|
+
|
|
15
|
+
## Modules
|
|
16
|
+
|
|
17
|
+
Each module is a subpath export, and the root entry re-exports all of them.
|
|
18
|
+
|
|
19
|
+
| Import | What it holds |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `@burdenoff/ui-engine/recording` | Recording v1 schema (`recordingSchema`, `recordedStepSchema`, `recordedTargetSchema`), `targetFingerprint`, `parseRecording`, `RecordingError`, `sha256Hex` |
|
|
22
|
+
| `@burdenoff/ui-engine/capture` | `captureRecording` (turns recorder events into a masked recording), `maskUrl`, `redactCredentials`, `REDACTED` |
|
|
23
|
+
| `@burdenoff/ui-engine/resolve` | `readSnapshotNodes` (array, `{ nodes }` or `{ elements }` snapshots), `resolveTarget` (exact role and label match, `nth` among equals) |
|
|
24
|
+
| `@burdenoff/ui-engine/replay` | The pure replay planner: `replayStateFrom`, `planReplay`, `afterReplayCall`, `finishFallback`, `markFallbackAsked`, `replayReasons`, `readReplayState` |
|
|
25
|
+
|
|
26
|
+
## Compatibility with Stewards
|
|
27
|
+
|
|
28
|
+
The modules were copied from `wspace-botmanor-svc` `src/modules/stewards/teach/` at commit `6558d8b` (BOFF-16873). The differences are:
|
|
29
|
+
|
|
30
|
+
- sha256 comes from `@noble/hashes` instead of `node:crypto`, with byte-identical output;
|
|
31
|
+
- `canAuthorSavedSteps` stays in Stewards, because it is an access rule of that service;
|
|
32
|
+
- the replay tool-call and chat-message types are local structural copies, and `planReplay`, `afterReplayCall` take optional `ReplayOptions` (tool names and call-id prefix) whose defaults reproduce the Stewards calls exactly;
|
|
33
|
+
- `readSnapshotNodes` also reads the `{ elements }` snapshot that the browser desk returns.
|
|
34
|
+
- `captureRecording` trims labels before taking the fingerprint (the schema trims them on parse, so an untrimmed label used to fail its own fingerprint check), and removes every value it masked from the recording's other text: intents, labels, window titles and plain typed text (a plain typed text that contains one becomes a masked step). Values shorter than four characters are not searched for.
|
|
35
|
+
|
|
36
|
+
- A navigation URL that holds a value masked elsewhere in the same demonstration, as written or percent-encoded, loses its query and fragment, or its path when the value is in the path.
|
|
37
|
+
- `maskUrl` also cuts a reset-style link after its reset segment (`/reset/<token>` becomes `/reset`) and drops a path or fragment that holds a recognisable credential. The sensitive values a URL loses (user info, the values of secret-looking parameters, every query value of a reset-style link, and the path segments cut from it) are masked in the rest of the recording too, so a code from a verification link does not survive in an intent or a label.
|
|
38
|
+
- `parseRecording` refuses a recording whose stored text (intent, target labels, typed text, URL, window app and title) still holds a recognisable credential, with `RecordingError` code `CREDENTIAL_IN_RECORDING`. The Stewards copy documented this check but did not perform it.
|
|
39
|
+
|
|
40
|
+
Recordings that capture produces, in either copy, still parse here, and the golden fingerprints are unchanged.
|
|
41
|
+
|
|
42
|
+
`tests/golden/stewards-6558d8b.json` was generated by running the Stewards code itself. The golden tests prove the fingerprints and a captured recording are identical, so a recording saved by either side parses on the other.
|
|
43
|
+
|
|
44
|
+
## Browser safety
|
|
45
|
+
|
|
46
|
+
Nothing under `src/` may import a Node built-in. ESLint enforces this, `tests/browser-safe.test.ts` checks every source file, and `bun run check:browser-safe` (a `boff sanity` extra step) checks the built `dist/` for Node built-ins and for any bare import other than `zod` and `@noble/hashes`.
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
bun install
|
|
52
|
+
bun run sanity # format, lint, typecheck, build, tests with the coverage gate, browser-safety check
|
|
53
|
+
bun test # unit tests only
|
|
54
|
+
bun run build # dist/ (ESM, browser target) and .d.ts files
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Release
|
|
58
|
+
|
|
59
|
+
Every push to `main` publishes the next CalVer version (`YYYY.MDD.PATCH`) to npm through `.github/workflows/release.yml`, which calls the shared `node-lib-release.yml` from `algoshred/ci-workflows`. A pushed CalVer tag publishes exactly that version. Pull requests must pass the `PR Gate` check.
|
|
60
|
+
|
|
61
|
+
## Licence
|
|
62
|
+
|
|
63
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teach-mode capture with masking (BOFF-16214, plan 5.7).
|
|
3
|
+
*
|
|
4
|
+
* Copied from wspace-botmanor-svc `src/modules/stewards/teach/capture.ts` at
|
|
5
|
+
* 6558d8b (BOFF-16873). This module also re-exports `redactCredentials` and
|
|
6
|
+
* `REDACTED`. Changes from that file, none of which alters a recording
|
|
7
|
+
* the Stewards copy accepts:
|
|
8
|
+
*
|
|
9
|
+
* - labels are trimmed before the fingerprint is taken. The recording schema
|
|
10
|
+
* trims them when it parses, so an untrimmed label used to fail its own
|
|
11
|
+
* fingerprint check and the whole demonstration was refused;
|
|
12
|
+
* - every value masked at capture is also removed from the other text the
|
|
13
|
+
* recording keeps (intents, labels, window titles, plain typed text and
|
|
14
|
+
* navigation URLs), because `redactCredentials` cannot recognise an
|
|
15
|
+
* arbitrary password or a bare one-time code by its shape.
|
|
16
|
+
* - a reset-style link loses the path after its reset segment (`/reset/<token>`
|
|
17
|
+
* kept `<token>` before), and a path holding a recognisable credential is
|
|
18
|
+
* dropped.
|
|
19
|
+
*
|
|
20
|
+
* The recorder (Track C, BOFF-16146 C4) sends the events of a person's
|
|
21
|
+
* demonstration. This turns them into saved steps and masks at capture time,
|
|
22
|
+
* so nothing secret ever reaches storage:
|
|
23
|
+
*
|
|
24
|
+
* - text typed into a password, one-time-code, card or similar field is never
|
|
25
|
+
* kept. With a vault reference the step becomes `secret_fill`; without one it
|
|
26
|
+
* is kept as a masked `type` step that always falls back to the model;
|
|
27
|
+
* - typed text that looks like a credential or a one-time code is masked too;
|
|
28
|
+
* - a URL that carries a token, code, signature or reset link loses its query
|
|
29
|
+
* and fragment, a reset link also loses the path after its reset segment,
|
|
30
|
+
* and a path holding a recognisable credential is dropped; the sensitive
|
|
31
|
+
* values it lost are masked in the rest of the recording too;
|
|
32
|
+
* - credential-like fragments in labels and intents are replaced, and so is
|
|
33
|
+
* any value masked elsewhere in the same demonstration; a navigation URL
|
|
34
|
+
* that holds such a value loses its query and fragment, or its path;
|
|
35
|
+
* - a screenshot is referenced only when the recorder masked it.
|
|
36
|
+
*
|
|
37
|
+
* `capturedSecrets` lists every raw value that was masked, so a caller (and
|
|
38
|
+
* the tests) can assert none of them appears in the stored recording.
|
|
39
|
+
*/
|
|
40
|
+
import { REDACTED, redactCredentials } from './redact-credentials.js';
|
|
41
|
+
import { type Recording } from './recording.js';
|
|
42
|
+
export { REDACTED, redactCredentials };
|
|
43
|
+
/** The element a recorder event acted on, as the accessibility tree described it. */
|
|
44
|
+
export interface RecorderElement {
|
|
45
|
+
app?: string;
|
|
46
|
+
window?: string;
|
|
47
|
+
role: string;
|
|
48
|
+
name: string;
|
|
49
|
+
nth?: number;
|
|
50
|
+
/** The HTML input type or native field kind, when known (`password`, `text`, …). */
|
|
51
|
+
inputType?: string;
|
|
52
|
+
/** The HTML autocomplete hint, when known (`one-time-code`, `current-password`, `cc-number`, …). */
|
|
53
|
+
autocomplete?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface RecorderScreenshot {
|
|
56
|
+
ref: string;
|
|
57
|
+
/** The recorder boxed out secret fields before uploading. Unmasked screenshots are never referenced. */
|
|
58
|
+
masked: boolean;
|
|
59
|
+
}
|
|
60
|
+
export type RecorderEvent = {
|
|
61
|
+
type: 'click';
|
|
62
|
+
element: RecorderElement;
|
|
63
|
+
button?: 'left' | 'right';
|
|
64
|
+
count?: 1 | 2;
|
|
65
|
+
intent?: string;
|
|
66
|
+
screenshot?: RecorderScreenshot;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'type';
|
|
69
|
+
element?: RecorderElement;
|
|
70
|
+
text: string;
|
|
71
|
+
/** The vault entry the person chose for this field, when it is a secret field. */
|
|
72
|
+
secretRef?: string;
|
|
73
|
+
/** The page origin the secret belongs to (required with `secretRef`). */
|
|
74
|
+
origin?: string;
|
|
75
|
+
intent?: string;
|
|
76
|
+
screenshot?: RecorderScreenshot;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'key';
|
|
79
|
+
keys: string[];
|
|
80
|
+
intent?: string;
|
|
81
|
+
screenshot?: RecorderScreenshot;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'scroll';
|
|
84
|
+
element?: RecorderElement;
|
|
85
|
+
dx: number;
|
|
86
|
+
dy: number;
|
|
87
|
+
intent?: string;
|
|
88
|
+
screenshot?: RecorderScreenshot;
|
|
89
|
+
} | {
|
|
90
|
+
type: 'navigate';
|
|
91
|
+
url: string;
|
|
92
|
+
intent?: string;
|
|
93
|
+
screenshot?: RecorderScreenshot;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'focus_window';
|
|
96
|
+
app: string;
|
|
97
|
+
title?: string;
|
|
98
|
+
intent?: string;
|
|
99
|
+
screenshot?: RecorderScreenshot;
|
|
100
|
+
};
|
|
101
|
+
export interface CaptureResult {
|
|
102
|
+
recording: Recording;
|
|
103
|
+
/** Steps whose typed value was masked and that will always fall back to the model. */
|
|
104
|
+
maskedStepIds: string[];
|
|
105
|
+
/** Raw values that were masked (kept in memory only, for checks; never store this). */
|
|
106
|
+
capturedSecrets: string[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Drop the query and fragment of a URL that carries a secret or is a
|
|
110
|
+
* reset-style link. A reset-style link also loses the path after its reset
|
|
111
|
+
* segment, and a path that holds a recognisable credential is dropped whole.
|
|
112
|
+
*/
|
|
113
|
+
export declare function maskUrl(raw: string): {
|
|
114
|
+
url: string;
|
|
115
|
+
masked: boolean;
|
|
116
|
+
};
|
|
117
|
+
/** Build saved steps from a demonstration, masking at capture. Throws RecordingError on an unusable result. */
|
|
118
|
+
export declare function captureRecording(events: readonly RecorderEvent[]): CaptureResult;
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
maskUrl2,
|
|
3
|
+
captureRecording2
|
|
4
|
+
} from "./index-phd8yhyg.js";
|
|
5
|
+
import {
|
|
6
|
+
REDACTED2,
|
|
7
|
+
redactCredentials2
|
|
8
|
+
} from "./index-c6pmt2rg.js";
|
|
9
|
+
export {
|
|
10
|
+
REDACTED2 as REDACTED,
|
|
11
|
+
captureRecording2 as captureRecording,
|
|
12
|
+
maskUrl2 as maskUrl,
|
|
13
|
+
redactCredentials2 as redactCredentials
|
|
14
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RecordingError2,
|
|
3
|
+
parseRecording2
|
|
4
|
+
} from "./index-c6pmt2rg.js";
|
|
5
|
+
import {
|
|
6
|
+
readSnapshotNodes2,
|
|
7
|
+
resolveTarget2
|
|
8
|
+
} from "./index-3v887c75.js";
|
|
9
|
+
|
|
10
|
+
// src/replay.ts
|
|
11
|
+
var CALL_PREFIX = "replay-";
|
|
12
|
+
var SNAPSHOT_SUFFIX = "-snapshot";
|
|
13
|
+
var ACT_SUFFIX = "-act";
|
|
14
|
+
function defaultToolName(kind) {
|
|
15
|
+
return `desk_${kind}`;
|
|
16
|
+
}
|
|
17
|
+
function callPrefixOf(options) {
|
|
18
|
+
return options?.callPrefix ?? CALL_PREFIX;
|
|
19
|
+
}
|
|
20
|
+
function toolNameOf(options) {
|
|
21
|
+
return options?.toolName ?? defaultToolName;
|
|
22
|
+
}
|
|
23
|
+
function stepAt(state) {
|
|
24
|
+
return state.recording.steps[state.cursor];
|
|
25
|
+
}
|
|
26
|
+
function needsTarget(step) {
|
|
27
|
+
return "target" in step && step.target !== undefined;
|
|
28
|
+
}
|
|
29
|
+
function call(id, name, args) {
|
|
30
|
+
return { id, type: "function", function: { name, arguments: JSON.stringify(args) } };
|
|
31
|
+
}
|
|
32
|
+
function actionArguments(step, ref) {
|
|
33
|
+
const at = ref ? { ref } : {};
|
|
34
|
+
switch (step.action) {
|
|
35
|
+
case "click":
|
|
36
|
+
return { ...at, button: step.button, count: step.count };
|
|
37
|
+
case "type":
|
|
38
|
+
return { ...at, text: step.text ?? "" };
|
|
39
|
+
case "secret_fill":
|
|
40
|
+
return { ...at, secretRef: step.secretRef, expectedOrigin: step.expectedOrigin };
|
|
41
|
+
case "key":
|
|
42
|
+
return { keys: step.keys };
|
|
43
|
+
case "scroll":
|
|
44
|
+
return { ...at, dx: step.dx, dy: step.dy };
|
|
45
|
+
case "navigate":
|
|
46
|
+
return { url: step.url };
|
|
47
|
+
case "focus_window":
|
|
48
|
+
return { app: step.app, ...step.title ? { title: step.title } : {} };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function replayStateFrom2(context) {
|
|
52
|
+
if (!context || typeof context !== "object" || Array.isArray(context))
|
|
53
|
+
return null;
|
|
54
|
+
const replay = context.replay;
|
|
55
|
+
if (replay === undefined || replay === null)
|
|
56
|
+
return null;
|
|
57
|
+
if (typeof replay !== "object" || Array.isArray(replay)) {
|
|
58
|
+
throw new RecordingError2("INVALID_RECORDING", "The run replay settings are not an object.");
|
|
59
|
+
}
|
|
60
|
+
const record = replay;
|
|
61
|
+
const recording = parseRecording2(record.recording);
|
|
62
|
+
return {
|
|
63
|
+
recording,
|
|
64
|
+
source: {
|
|
65
|
+
playbookId: typeof record.playbookId === "string" ? record.playbookId : null,
|
|
66
|
+
version: typeof record.version === "number" ? record.version : null
|
|
67
|
+
},
|
|
68
|
+
cursor: 0,
|
|
69
|
+
snapshot: null,
|
|
70
|
+
snapshotFor: null,
|
|
71
|
+
fallback: null,
|
|
72
|
+
replayed: 0,
|
|
73
|
+
fallbacks: 0,
|
|
74
|
+
awaiting: null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function readReplayState2(value) {
|
|
78
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
79
|
+
return null;
|
|
80
|
+
const record = value;
|
|
81
|
+
let recording;
|
|
82
|
+
try {
|
|
83
|
+
recording = parseRecording2(record.recording);
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const cursor = typeof record.cursor === "number" && Number.isInteger(record.cursor) ? record.cursor : 0;
|
|
88
|
+
const fallback = record.fallback;
|
|
89
|
+
const source = record.source ?? {};
|
|
90
|
+
return {
|
|
91
|
+
recording,
|
|
92
|
+
source: {
|
|
93
|
+
playbookId: typeof source.playbookId === "string" ? source.playbookId : null,
|
|
94
|
+
version: typeof source.version === "number" ? source.version : null
|
|
95
|
+
},
|
|
96
|
+
cursor: Math.max(0, Math.min(cursor, recording.steps.length)),
|
|
97
|
+
snapshot: record.snapshot === null || record.snapshot === undefined ? null : readSnapshotNodes2(record.snapshot),
|
|
98
|
+
snapshotFor: typeof record.snapshotFor === "number" ? record.snapshotFor : null,
|
|
99
|
+
fallback: fallback && typeof fallback.index === "number" && typeof fallback.reason === "string" ? { index: fallback.index, reason: fallback.reason, asked: fallback.asked === true } : null,
|
|
100
|
+
replayed: typeof record.replayed === "number" ? record.replayed : 0,
|
|
101
|
+
fallbacks: typeof record.fallbacks === "number" ? record.fallbacks : 0,
|
|
102
|
+
awaiting: typeof record.awaiting === "string" ? record.awaiting : null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function fallbackPlan(state, step, reason) {
|
|
106
|
+
const next = {
|
|
107
|
+
...state,
|
|
108
|
+
fallback: { index: state.cursor, reason, asked: false },
|
|
109
|
+
snapshot: null,
|
|
110
|
+
snapshotFor: null,
|
|
111
|
+
awaiting: null
|
|
112
|
+
};
|
|
113
|
+
const position = `${state.cursor + 1} of ${state.recording.steps.length}`;
|
|
114
|
+
return {
|
|
115
|
+
kind: "fallback",
|
|
116
|
+
state: next,
|
|
117
|
+
reasons: [`replay:fallback:${step.id}:${reason}`],
|
|
118
|
+
message: {
|
|
119
|
+
role: "user",
|
|
120
|
+
content: `Saved step ${position} could not be replayed (${reason}). Do this one step yourself with the desk tools, ` + `then stop; the remaining saved steps continue after it. The step: ${step.intent}`
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function planReplay2(state, options) {
|
|
125
|
+
const prefix = callPrefixOf(options);
|
|
126
|
+
const toolName = toolNameOf(options);
|
|
127
|
+
const step = stepAt(state);
|
|
128
|
+
if (!step) {
|
|
129
|
+
return {
|
|
130
|
+
kind: "done",
|
|
131
|
+
state,
|
|
132
|
+
output: state.fallbacks === 0 ? `Replayed ${state.replayed} saved step(s) with no model call.` : `Replayed ${state.replayed} saved step(s); ${state.fallbacks} step(s) needed the model.`
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (step.action === "type" && step.masked)
|
|
136
|
+
return fallbackPlan(state, step, "masked-input");
|
|
137
|
+
let ref = null;
|
|
138
|
+
if (needsTarget(step) && "target" in step && step.target) {
|
|
139
|
+
if (state.snapshotFor !== state.cursor) {
|
|
140
|
+
const snapshot = call(`${prefix}${step.id}${SNAPSHOT_SUFFIX}`, toolName("snapshot"), {});
|
|
141
|
+
return {
|
|
142
|
+
kind: "call",
|
|
143
|
+
state: { ...state, awaiting: snapshot.id },
|
|
144
|
+
call: snapshot,
|
|
145
|
+
reasons: [`replay:snapshot:${step.id}`]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const found = resolveTarget2(step.target, state.snapshot);
|
|
149
|
+
if (!found.resolved)
|
|
150
|
+
return fallbackPlan(state, step, found.reason);
|
|
151
|
+
ref = found.ref;
|
|
152
|
+
}
|
|
153
|
+
const act = call(`${prefix}${step.id}${ACT_SUFFIX}`, toolName(step.action), actionArguments(step, ref));
|
|
154
|
+
return { kind: "call", state: { ...state, awaiting: act.id }, call: act, reasons: [`replay:step:${step.id}`] };
|
|
155
|
+
}
|
|
156
|
+
var RAN = new Set(["ALLOWED", "APPROVED"]);
|
|
157
|
+
function afterReplayCall2(state, callId, outcome, options) {
|
|
158
|
+
const step = stepAt(state);
|
|
159
|
+
if (!step || callId !== state.awaiting)
|
|
160
|
+
return { state };
|
|
161
|
+
if (callId === `${callPrefixOf(options)}${step.id}${SNAPSHOT_SUFFIX}`) {
|
|
162
|
+
if (!RAN.has(outcome.verdict))
|
|
163
|
+
return fallbackPlan(state, step, "snapshot-failed");
|
|
164
|
+
return {
|
|
165
|
+
state: { ...state, snapshot: readSnapshotNodes2(outcome.data), snapshotFor: state.cursor, awaiting: null }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (!RAN.has(outcome.verdict) && outcome.verdict !== "SKIPPED" && outcome.verdict !== "BLOCKED_DRY_RUN") {
|
|
169
|
+
return fallbackPlan(state, step, outcome.verdict === "FAILED" ? "action-failed" : "action-refused");
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
state: {
|
|
173
|
+
...state,
|
|
174
|
+
cursor: state.cursor + 1,
|
|
175
|
+
replayed: state.replayed + 1,
|
|
176
|
+
snapshot: null,
|
|
177
|
+
snapshotFor: null,
|
|
178
|
+
awaiting: null
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function finishFallback2(state) {
|
|
183
|
+
if (!state.fallback)
|
|
184
|
+
return state;
|
|
185
|
+
return {
|
|
186
|
+
...state,
|
|
187
|
+
cursor: state.fallback.index + 1,
|
|
188
|
+
fallback: null,
|
|
189
|
+
fallbacks: state.fallbacks + 1,
|
|
190
|
+
snapshot: null,
|
|
191
|
+
snapshotFor: null
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function markFallbackAsked2(state) {
|
|
195
|
+
return state.fallback ? { ...state, fallback: { ...state.fallback, asked: true } } : state;
|
|
196
|
+
}
|
|
197
|
+
function replayReasons2(state, callId) {
|
|
198
|
+
if (!state)
|
|
199
|
+
return [];
|
|
200
|
+
const step = stepAt(state);
|
|
201
|
+
if (step && callId !== null && callId === state.awaiting) {
|
|
202
|
+
return [callId.endsWith(SNAPSHOT_SUFFIX) ? `replay:snapshot:${step.id}` : `replay:step:${step.id}`];
|
|
203
|
+
}
|
|
204
|
+
if (!state.fallback)
|
|
205
|
+
return [];
|
|
206
|
+
const replaced = state.recording.steps[state.fallback.index];
|
|
207
|
+
return replaced ? [`replay:fallback:${replaced.id}:${state.fallback.reason}`] : [];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { replayStateFrom2, readReplayState2, planReplay2, afterReplayCall2, finishFallback2, markFallbackAsked2, replayReasons2 };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/resolve.ts
|
|
2
|
+
var MAX_SNAPSHOT_NODES2 = 2000;
|
|
3
|
+
var MAX_FIELD = 512;
|
|
4
|
+
function text(value) {
|
|
5
|
+
return typeof value === "string" && value.length > 0 ? value.slice(0, MAX_FIELD) : undefined;
|
|
6
|
+
}
|
|
7
|
+
function snapshotList(snapshot) {
|
|
8
|
+
if (Array.isArray(snapshot))
|
|
9
|
+
return snapshot;
|
|
10
|
+
if (!snapshot || typeof snapshot !== "object")
|
|
11
|
+
return [];
|
|
12
|
+
if ("nodes" in snapshot && Array.isArray(snapshot.nodes))
|
|
13
|
+
return snapshot.nodes;
|
|
14
|
+
if ("elements" in snapshot && Array.isArray(snapshot.elements))
|
|
15
|
+
return snapshot.elements;
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
function readSnapshotNodes2(snapshot) {
|
|
19
|
+
const list = snapshotList(snapshot);
|
|
20
|
+
const nodes = [];
|
|
21
|
+
for (const item of list) {
|
|
22
|
+
if (nodes.length >= MAX_SNAPSHOT_NODES2)
|
|
23
|
+
break;
|
|
24
|
+
if (!item || typeof item !== "object")
|
|
25
|
+
continue;
|
|
26
|
+
const record = item;
|
|
27
|
+
const ref = text(record.ref);
|
|
28
|
+
const role = text(record.role);
|
|
29
|
+
const name = typeof record.name === "string" ? record.name.slice(0, MAX_FIELD) : undefined;
|
|
30
|
+
if (!ref || !role || name === undefined)
|
|
31
|
+
continue;
|
|
32
|
+
const app = text(record.app);
|
|
33
|
+
const window = text(record.window);
|
|
34
|
+
nodes.push({ ref, role, name, ...app ? { app } : {}, ...window ? { window } : {} });
|
|
35
|
+
}
|
|
36
|
+
return nodes;
|
|
37
|
+
}
|
|
38
|
+
function same(a, b) {
|
|
39
|
+
const norm = (value) => value.normalize("NFKC").replace(/\s+/g, " ").trim().toLowerCase();
|
|
40
|
+
return norm(a ?? "") === norm(b ?? "");
|
|
41
|
+
}
|
|
42
|
+
function resolveTarget2(target, nodes) {
|
|
43
|
+
if (!nodes)
|
|
44
|
+
return { resolved: false, reason: "no-snapshot" };
|
|
45
|
+
const matches = nodes.filter((node) => same(node.role, target.role) && same(node.name, target.name) && (target.app === undefined || same(node.app, target.app)) && (target.window === undefined || same(node.window, target.window)));
|
|
46
|
+
if (matches.length === 0)
|
|
47
|
+
return { resolved: false, reason: "not-found" };
|
|
48
|
+
const match = matches[target.nth];
|
|
49
|
+
return match ? { resolved: true, ref: match.ref } : { resolved: false, reason: "fewer-matches" };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { MAX_SNAPSHOT_NODES2, readSnapshotNodes2, resolveTarget2 };
|