gz-laya-pilot 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/NOTICE.md +20 -2
  2. package/README.md +54 -2
  3. package/dist/agent/bridge.d.ts +21 -0
  4. package/dist/agent/bridge.js +158 -0
  5. package/dist/agent/bridge.js.map +1 -0
  6. package/dist/agent/report.d.ts +54 -0
  7. package/dist/agent/report.js +100 -0
  8. package/dist/agent/report.js.map +1 -0
  9. package/dist/agent/run.d.ts +19 -0
  10. package/dist/agent/run.js +121 -0
  11. package/dist/agent/run.js.map +1 -0
  12. package/dist/agent/schema.d.ts +42 -0
  13. package/dist/agent/schema.js +9 -0
  14. package/dist/agent/schema.js.map +1 -0
  15. package/dist/agent/worker.d.ts +1 -0
  16. package/dist/agent/worker.js +102 -0
  17. package/dist/agent/worker.js.map +1 -0
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.js +7 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -1
  24. package/package.json +14 -6
  25. package/src/agent/bridge.ts +180 -0
  26. package/src/agent/report.ts +139 -0
  27. package/src/agent/run.ts +136 -0
  28. package/src/agent/schema.ts +38 -0
  29. package/src/agent/worker.ts +114 -0
  30. package/src/cli.ts +5 -0
  31. package/src/index.ts +3 -0
  32. package/vendor/.gitattributes +5 -0
  33. package/vendor/UPSTREAM.json +168 -0
  34. package/vendor/laya-pilot/LICENSE +21 -0
  35. package/vendor/laya-pilot/README.en.md +116 -0
  36. package/vendor/laya-pilot/README.md +116 -0
  37. package/vendor/laya-pilot/ROADMAP.md +21 -0
  38. package/vendor/laya-pilot/config.example.json +14 -0
  39. package/vendor/laya-pilot/docs/architecture.md +21 -0
  40. package/vendor/laya-pilot/docs/browser-use-evaluation.md +32 -0
  41. package/vendor/laya-pilot/docs/demo.png +0 -0
  42. package/vendor/laya-pilot/docs/local-runtime.md +88 -0
  43. package/vendor/laya-pilot/docs/pr1-selection.md +33 -0
  44. package/vendor/laya-pilot/docs/retry-policy.md +14 -0
  45. package/vendor/laya-pilot/examples/demo-cases.xlsx +0 -0
  46. package/vendor/laya-pilot/examples/demo-server.mjs +19 -0
  47. package/vendor/laya-pilot/examples/demo.html +733 -0
  48. package/vendor/laya-pilot/lib/auth-state.mjs +141 -0
  49. package/vendor/laya-pilot/lib/browser-provider.mjs +43 -0
  50. package/vendor/laya-pilot/lib/diagnostics.mjs +210 -0
  51. package/vendor/laya-pilot/lib/discovery.mjs +474 -0
  52. package/vendor/laya-pilot/lib/dom.mjs +539 -0
  53. package/vendor/laya-pilot/lib/engine.mjs +879 -0
  54. package/vendor/laya-pilot/lib/form.mjs +377 -0
  55. package/vendor/laya-pilot/lib/language.mjs +273 -0
  56. package/vendor/laya-pilot/lib/model.mjs +271 -0
  57. package/vendor/laya-pilot/lib/page-capabilities.mjs +356 -0
  58. package/vendor/laya-pilot/lib/page-exploration.mjs +372 -0
  59. package/vendor/laya-pilot/lib/page-session.mjs +69 -0
  60. package/vendor/laya-pilot/lib/pending-writes.mjs +50 -0
  61. package/vendor/laya-pilot/lib/planner.mjs +127 -0
  62. package/vendor/laya-pilot/lib/project-config.mjs +95 -0
  63. package/vendor/laya-pilot/lib/readiness.mjs +179 -0
  64. package/vendor/laya-pilot/lib/related-records.mjs +328 -0
  65. package/vendor/laya-pilot/lib/replay-model.mjs +44 -0
  66. package/vendor/laya-pilot/lib/run-state.mjs +133 -0
  67. package/vendor/laya-pilot/lib/test-data.mjs +128 -0
  68. package/vendor/laya-pilot/lib/workflow-policy.mjs +68 -0
  69. package/vendor/laya-pilot/lib/workflow.mjs +2321 -0
  70. package/vendor/laya-pilot/lib/workflow_excel.py +462 -0
  71. package/vendor/laya-pilot/requirements-local.txt +2 -0
  72. package/vendor/laya-pilot/requirements.txt +1 -0
  73. package/vendor/laya-pilot/runner.mjs +452 -0
  74. package/vendor/laya-pilot/tests/api.test.mjs +98 -0
  75. package/vendor/laya-pilot/tests/browser/runtime.test.mjs +847 -0
  76. package/vendor/laya-pilot/tests/config.test.mjs +109 -0
  77. package/vendor/laya-pilot/tests/diagnostics.test.mjs +91 -0
  78. package/vendor/laya-pilot/tests/discovery.test.mjs +76 -0
  79. package/vendor/laya-pilot/tests/fixtures/local-model/laya.py +28 -0
  80. package/vendor/laya-pilot/tests/fixtures/local-model/torch.py +5 -0
  81. package/vendor/laya-pilot/tests/guards.test.mjs +43 -0
  82. package/vendor/laya-pilot/tests/language.test.mjs +39 -0
  83. package/vendor/laya-pilot/tests/planner.test.mjs +129 -0
  84. package/vendor/laya-pilot/tests/readiness.test.mjs +118 -0
  85. package/vendor/laya-pilot/tests/real-model.smoke.mjs +74 -0
  86. package/vendor/laya-pilot/tests/replay-model.test.mjs +90 -0
  87. package/vendor/laya-pilot/tests/retries.test.mjs +270 -0
  88. package/vendor/laya-pilot/tests/run-state.test.mjs +162 -0
  89. package/vendor/laya-pilot/tests/selected-pr1.test.mjs +309 -0
  90. package/vendor/laya-pilot/tests/test-data.test.mjs +83 -0
  91. package/vendor/laya-pilot/tests/test_workflow_excel.py +162 -0
  92. package/vendor/laya-pilot/tests/worker_test.py +33 -0
  93. package/vendor/laya-pilot/tests/workflow.test.mjs +98 -0
  94. package/vendor/laya-pilot/worker.py +135 -0
  95. package/vendor/patches/0001-native-field-recipes.patch +3009 -0
@@ -0,0 +1,136 @@
1
+ import { fork, execFile } from 'node:child_process';
2
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import { existsSync } from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import path from 'node:path';
6
+ import { testUrl, type AgentStatus } from './schema.js';
7
+ import { projectReport, type UpstreamReport } from './report.js';
8
+
9
+ export interface AgentOptions {
10
+ url: string;
11
+ outputDir: string;
12
+ python: string;
13
+ model: string;
14
+ workbook?: string;
15
+ allowWrite?: boolean;
16
+ headed?: boolean;
17
+ channel?: string;
18
+ authState?: string;
19
+ authCheck?: string;
20
+ manualLogin?: boolean;
21
+ signal?: AbortSignal;
22
+ timeout?: number;
23
+ onProgress?: (status: AgentStatus) => void;
24
+ }
25
+ /** Functional npm facade over the pinned upstream generate/execute workflow. No second planner. */
26
+ export async function runAgent(options: AgentOptions): Promise<AgentStatus> {
27
+ options.signal?.throwIfAborted();
28
+ const url = testUrl(options.url),
29
+ outputDir = path.resolve(options.outputDir);
30
+ if (!existsSync(options.python) || !existsSync(options.model))
31
+ throw Error('请配置可用的本地 Laya Python 和模型路径');
32
+ if (options.authState && !options.authCheck)
33
+ throw Error('复用登录态需要 authCheck 校验登录成功页面');
34
+ await mkdir(outputDir, { recursive: true });
35
+ if (existsSync(path.join(outputDir, 'checkpoint.json')))
36
+ throw Error('输出目录已有运行记录,请使用新的目录');
37
+ const mode = options.workbook ? 'replay' : 'explore';
38
+ let last: AgentStatus = {
39
+ state: 'running',
40
+ mode,
41
+ message: '正在启动上游 LayaPilot',
42
+ cases: [],
43
+ decisions: 0,
44
+ };
45
+ options.onProgress?.(last);
46
+ const child = fork(fileURLToPath(new URL('./worker.js', import.meta.url)), [], {
47
+ execArgv: [],
48
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
49
+ ...{ windowsHide: true },
50
+ env: {
51
+ ...process.env,
52
+ PYTHONIOENCODING: 'utf-8',
53
+ PYTHONUTF8: '1',
54
+ PYTHONDONTWRITEBYTECODE: '1',
55
+ HF_HUB_OFFLINE: '1',
56
+ },
57
+ });
58
+ let stopped = false,
59
+ finished = false,
60
+ diagnostic = '',
61
+ stopping: ReturnType<typeof setTimeout> | undefined;
62
+ const stop = () => {
63
+ if (stopped) return;
64
+ stopped = true;
65
+ if (child.connected) child.send({ type: 'stop' }, () => {});
66
+ stopping = setTimeout(() => {
67
+ if (child.exitCode !== null || !child.pid) return;
68
+ if (process.platform === 'win32')
69
+ execFile(
70
+ 'taskkill',
71
+ ['/PID', String(child.pid), '/T', '/F'],
72
+ { windowsHide: true },
73
+ () => {},
74
+ );
75
+ else child.kill('SIGKILL');
76
+ }, 20000);
77
+ };
78
+ options.signal?.addEventListener('abort', stop, { once: true });
79
+ const timeout = setTimeout(stop, options.timeout ?? 12 * 60 * 1000);
80
+ const readProgress = async () => {
81
+ try {
82
+ const report = JSON.parse(
83
+ await readFile(path.join(outputDir, 'checkpoint.json'), 'utf8'),
84
+ ) as UpstreamReport;
85
+ if (finished) return;
86
+ last = projectReport(report, mode, false);
87
+ options.onProgress?.(last);
88
+ } catch {
89
+ /* Atomic checkpoint may not exist until startup completes. */
90
+ }
91
+ };
92
+ const polling = setInterval(() => void readProgress(), 1000);
93
+ child.stdout?.on('data', (chunk) => {
94
+ const message = chunk.toString().trim();
95
+ if (message && !message.startsWith('RESULT '))
96
+ options.onProgress?.({ ...last, message: message.slice(-1000) });
97
+ });
98
+ child.stderr?.on('data', (chunk) => {
99
+ diagnostic = (diagnostic + chunk.toString()).slice(-1000);
100
+ });
101
+ child.on('message', (message: { error?: string }) => {
102
+ if (message.error) diagnostic = message.error;
103
+ });
104
+ try {
105
+ const exited = new Promise<number | null>((resolve, reject) => {
106
+ child.once('error', reject);
107
+ child.once('exit', resolve);
108
+ });
109
+ child.send({
110
+ type: 'run',
111
+ options: { ...options, url, outputDir, signal: undefined, onProgress: undefined },
112
+ });
113
+ if (options.signal?.aborted) stop();
114
+ const code = await exited;
115
+ finished = true;
116
+ clearInterval(polling);
117
+ let report: UpstreamReport;
118
+ try {
119
+ report = JSON.parse(await readFile(path.join(outputDir, 'results.json'), 'utf8'));
120
+ } catch {
121
+ report = { results: [], exitCode: code ?? 1, error: diagnostic || '上游执行未生成报告' };
122
+ }
123
+ last = projectReport(report, mode, true);
124
+ if (stopped) last.state = 'stopped';
125
+ if (existsSync(path.join(outputDir, 'trace.zip'))) last.trace = 'trace.zip';
126
+ await writeFile(path.join(outputDir, 'assistant-status.json'), JSON.stringify(last, null, 2));
127
+ options.onProgress?.(last);
128
+ return last;
129
+ } finally {
130
+ finished = true;
131
+ clearInterval(polling);
132
+ clearTimeout(timeout);
133
+ clearTimeout(stopping);
134
+ options.signal?.removeEventListener('abort', stop);
135
+ }
136
+ }
@@ -0,0 +1,38 @@
1
+ /** UI projection of upstream reports. Execution and workbook grammar remain upstream-owned. */
2
+ export interface CaseEvidence {
3
+ id: string;
4
+ title: string;
5
+ operation?: string;
6
+ state: 'passed' | 'failed' | 'skipped';
7
+ reason: string;
8
+ assertions: { step: number; expected: string; actual: string; passed: boolean }[];
9
+ screenshot?: string;
10
+ errors: string[];
11
+ cleanup?: string;
12
+ }
13
+ export interface AgentStatus {
14
+ id?: string;
15
+ state: 'idle' | 'running' | 'passed' | 'partial' | 'failed' | 'stopped';
16
+ mode: 'explore' | 'replay';
17
+ message: string;
18
+ cases: CaseEvidence[];
19
+ decisions: number;
20
+ workbook?: string;
21
+ trace?: string;
22
+ coverage?: {
23
+ states: string[];
24
+ gaps: { state: string; role: string; name: string; reason: string }[];
25
+ };
26
+ }
27
+ export interface AgentCapabilities {
28
+ configured: boolean;
29
+ message: string;
30
+ targets: string[];
31
+ }
32
+ export function testUrl(value: unknown): string {
33
+ if (typeof value !== 'string' || value.length > 2000) throw Error('测试地址格式错误');
34
+ const url = new URL(value);
35
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
36
+ throw Error('测试地址必须为不含凭据的 HTTP(S) 地址');
37
+ return url.href;
38
+ }
@@ -0,0 +1,114 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import path from 'node:path';
3
+ import { spawn } from 'node:child_process';
4
+ import type { AgentOptions } from './run.js';
5
+ import type { UpstreamReport } from './report.js';
6
+
7
+ const root = fileURLToPath(new URL('../../vendor/laya-pilot/', import.meta.url));
8
+ let started = false,
9
+ cancelled = false;
10
+ process.on('disconnect', () => {
11
+ cancelled = true;
12
+ });
13
+ process.on('message', async (message: { type: string; options?: AgentOptions }) => {
14
+ if (message.type === 'stop') {
15
+ cancelled = true;
16
+ return;
17
+ }
18
+ if (started || !message.options) return;
19
+ started = true;
20
+ const options = message.options;
21
+ const timer = setInterval(() => {
22
+ if (cancelled && process.listenerCount('SIGTERM')) process.emit('SIGTERM');
23
+ }, 200);
24
+ try {
25
+ // Import exact vendored upstream source; the npm facade owns configuration, not workflow logic.
26
+ const upstream = (await import(
27
+ new URL('../../vendor/laya-pilot/lib/workflow.mjs', import.meta.url).href
28
+ )) as {
29
+ validateWorkflow: (file: unknown) => { moduleUrl: string };
30
+ runWorkflow: (
31
+ config: Record<string, unknown>,
32
+ mode: string,
33
+ secret: () => Promise<string>,
34
+ root: string,
35
+ ) => Promise<UpstreamReport>;
36
+ };
37
+ if (cancelled) throw Error('任务已取消');
38
+ if (options.workbook) {
39
+ const workbook = await new Promise<unknown>((resolve, reject) => {
40
+ const child = spawn(options.python, [path.join(root, 'lib/workflow_excel.py'), 'read'], {
41
+ windowsHide: true,
42
+ stdio: ['pipe', 'pipe', 'pipe'],
43
+ timeout: 60000,
44
+ });
45
+ let output = '',
46
+ error = '';
47
+ child.stdout.on('data', (chunk) => {
48
+ output += chunk;
49
+ });
50
+ child.stderr.on('data', (chunk) => {
51
+ error = (error + chunk).slice(-1000);
52
+ });
53
+ child.on('error', reject);
54
+ child.stdin.on('error', reject);
55
+ child.once('close', (code) => {
56
+ if (code) reject(Error(error));
57
+ else {
58
+ try {
59
+ resolve(JSON.parse(output));
60
+ } catch {
61
+ reject(Error('Excel 元数据无效'));
62
+ }
63
+ }
64
+ });
65
+ child.stdin.end(JSON.stringify({ path: options.workbook }));
66
+ });
67
+ const saved = upstream.validateWorkflow(workbook);
68
+ const target = new URL(options.url);
69
+ target.search = '';
70
+ target.hash = '';
71
+ if (new URL(saved.moduleUrl).href !== target.href)
72
+ throw Error('Excel 入口与宿主授权地址不一致');
73
+ }
74
+ const summary = await upstream.runWorkflow(
75
+ {
76
+ url: options.url,
77
+ out: options.outputDir,
78
+ caseFile: options.workbook ?? path.join(options.outputDir, 'cases.xlsx'),
79
+ python: options.python,
80
+ model: options.model,
81
+ provider: 'local',
82
+ browserProvider: 'playwright',
83
+ browserChannel: options.channel ?? 'chrome',
84
+ headless: !options.headed,
85
+ readOnly: !options.allowWrite,
86
+ allowWrite: options.allowWrite === true,
87
+ authState: options.authState ?? '',
88
+ authCheck: options.authCheck ?? '',
89
+ manualLogin: options.manualLogin ?? false,
90
+ pageTimeout: 18000,
91
+ assertTimeout: 4000,
92
+ delay: 180,
93
+ maxSteps: 100,
94
+ minProbability: 0.68,
95
+ minMargin: 0.18,
96
+ data: {},
97
+ cases: [],
98
+ },
99
+ options.workbook ? 'execute' : 'generate',
100
+ async () => {
101
+ throw Error('请在宿主配置登录态或使用手动登录');
102
+ },
103
+ root,
104
+ );
105
+ process.exitCode = summary.exitCode ?? 1;
106
+ } catch (error) {
107
+ if (process.connected)
108
+ process.send?.({ error: error instanceof Error ? error.message : String(error) });
109
+ process.exitCode = 1;
110
+ } finally {
111
+ clearInterval(timer);
112
+ process.disconnect?.();
113
+ }
114
+ });
package/src/cli.ts ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // Preserve all upstream CLI modes and workbook behavior; use UTF-8 for Windows Python IPC.
3
+ process.env.PYTHONIOENCODING = 'utf-8';
4
+ process.env.PYTHONUTF8 = '1';
5
+ await import(new URL('../vendor/laya-pilot/runner.mjs', import.meta.url).href);
package/src/index.ts CHANGED
@@ -5,3 +5,6 @@ export { openBrowser } from './browser.js';
5
5
  export { waitForReady } from './readiness.js';
6
6
  export { createApiDecision, decodeDecision, type Decision, type Decide } from './decision.js';
7
7
  export { chooseStep } from './planner.js';
8
+ export { runAgent, type AgentOptions } from './agent/run.js';
9
+ export { createAgentBridge, type AgentBridgeOptions, type AgentBridgeTarget } from './agent/bridge.js';
10
+ export type { AgentStatus, AgentCapabilities } from './agent/schema.js';
@@ -0,0 +1,5 @@
1
+ # Preserve upstream Git blob bytes for provenance checks on every platform.
2
+ laya-pilot/** -text
3
+ patches/** text eol=lf
4
+ patches/*.patch whitespace=-blank-at-eol
5
+ UPSTREAM.json text eol=lf
@@ -0,0 +1,168 @@
1
+ {
2
+ "repository": "https://github.com/anthonyli/laya-pilot",
3
+ "commit": "9f1bb801e0ca5eb4ded82413ab112ab0da0716d8",
4
+ "modifications": [
5
+ {
6
+ "path": "lib/workflow-policy.mjs",
7
+ "originalSha256": "65053ef4ef9a5dd94000f8386a0fd6ae6015b59a4f4e4858a8447a42087f8dc0",
8
+ "sha256": "08617071f8e033b170b9417d669f30a54604bacb78607b3b65145ee64b2a2cc1",
9
+ "reason": "Allow only validated filter discovery recipes in read-only replay; retain all form and write restrictions.",
10
+ "patch": "patches/0001-native-field-recipes.patch"
11
+ },
12
+ {
13
+ "path": "lib/browser-provider.mjs",
14
+ "originalSha256": "2f0e9945d094330ef17d64bc6f1210ce432d3324fad3192fee9d2de54cf5f246",
15
+ "sha256": "db92685794ffe621215b6acddbe408cb2e2e533003f81ad8ddd776764f9ce2da",
16
+ "reason": "Reuse one headless verification browser started before the visible browser, creating and closing a fresh context for every persistence read; keep pre-write authentication isolated and avoid repeated Chrome process activation on Windows.",
17
+ "patch": "patches/0001-native-field-recipes.patch"
18
+ },
19
+ {
20
+ "path": "lib/test-data.mjs",
21
+ "originalSha256": "095844509822929af0ce08145bdbf4adc1d8c5931bda8339d5ad67713c63a792",
22
+ "sha256": "d3b911057dd78ae0cb6d712e6a315f0ebf8d3c1ecd32dc442dc371722fa5ce35",
23
+ "reason": "Use observed native constraints for numeric/email recipes; classify record identity by its label while retaining length hints as evidence. Preserve all model refusals and confidence thresholds.",
24
+ "patch": "patches/0001-native-field-recipes.patch"
25
+ },
26
+ {
27
+ "path": "lib/workflow.mjs",
28
+ "originalSha256": "f217c11514ae4e6b32fa326c5fb1fbfc7c03a6322997e84f710c76d17ec7a4c2",
29
+ "sha256": "8136dc3ff138816c9ea32ecae02f8866de51d27d26d354272638cd1c8697dc10",
30
+ "reason": "Extend the existing workflow with bounded semantic tree expansion, standalone editors, continuous CRUD and inline detail exploration. Reuse required validation within creation, verify filtered results, traverse linked detail tabs, retain isolated persistence reads and reject legacy host reloads. Replay the same bounded steps with original write guards and confidence thresholds.",
31
+ "patch": "patches/0001-native-field-recipes.patch"
32
+ },
33
+ {
34
+ "path": "lib/run-state.mjs",
35
+ "originalSha256": "797e66729f58cda47c7f5465d391df68878716a8e7c695bd8077aa346d83beb5",
36
+ "sha256": "356622fc6e099087df9da3047755adb7fddf51512ef762a989f767bf51c37dc1",
37
+ "reason": "Bounded retry for transient Windows atomic-rename locks; retain the last complete checkpoint and surface persistent or unrelated storage errors.",
38
+ "patch": "patches/0001-native-field-recipes.patch"
39
+ },
40
+ {
41
+ "path": "lib/dom.mjs",
42
+ "originalSha256": "3a167f1b4aec92e511f4b56e16e76dac98279b498e86f735192ace61ba5a46f7",
43
+ "sha256": "ddecd75e9c9f0a82509f651750f3c30fa70d075abc819f289836ad900a992f96",
44
+ "reason": "Observe semantic regions, expansion state and tree record context; scope activated standalone editors and exclude controls fully clipped by overflow-hidden ancestors while retaining scrollable content.",
45
+ "patch": "patches/0001-native-field-recipes.patch"
46
+ },
47
+ {
48
+ "path": "lib/form.mjs",
49
+ "originalSha256": "a7185ef21214555fba22eb481301924eeae3a4aad371b60f5793adf777543a27",
50
+ "sha256": "e96d11de7dc723bafbbc0480b06d81f28c5c0029361ac0e2097cd101bcc03fe7",
51
+ "reason": "Reuse form inspection for an explicitly activated standalone editor and recognize Ant Design 6 selected values without treating search text as selection.",
52
+ "patch": "patches/0001-native-field-recipes.patch"
53
+ },
54
+ {
55
+ "path": "lib/discovery.mjs",
56
+ "originalSha256": "3706e326918286b73de9ea56c6cc23e7c6a1df788977207a39ea111e8a438a30",
57
+ "sha256": "4a20962504b93a63fa50b112af261cbfced3b05ef5d301ad09fb1f68bac83adf",
58
+ "reason": "Bind filters to the same business region, support semantic record trees and standalone editors; normalize and restore observed form/filter state in place in both generation and replay, stopping on uncertain restoration instead of reloading the host.",
59
+ "patch": "patches/0001-native-field-recipes.patch"
60
+ },
61
+ {
62
+ "path": "lib/workflow_excel.py",
63
+ "originalSha256": "118ce4c93689d677febbbfafafc3a587e6de40702c1b2b7d4fa4351ead9c3988",
64
+ "sha256": "39ce16199c3309262fadb70e520166f504821e7a5e89812d244d307e6d1c5b29",
65
+ "reason": "Keep the existing 17-column case workbook, describe query/detail/tab/disclosure and persistence assertions, and round-trip exploration states and unverified entries through an additional coverage sheet and metadata.",
66
+ "patch": "patches/0001-native-field-recipes.patch"
67
+ },
68
+ {
69
+ "path": "tests/retries.test.mjs",
70
+ "originalSha256": "93d27d572c2376bf7e6d6b43a61f4835b5ab1a4f7d408836b91025e7014732f2",
71
+ "sha256": "a1206233356a22360b07954cf047f045ec818a6033e3f6e3f1c290a0069c727f",
72
+ "reason": "Adapt page/model doubles to the extended editor and record lookup contract; retain write verification and bounded retry assertions.",
73
+ "patch": "patches/0001-native-field-recipes.patch"
74
+ },
75
+ {
76
+ "path": "tests/selected-pr1.test.mjs",
77
+ "originalSha256": "78c7c180e59f284bbcffcb737ef100b4a028c83a36a0b0f1c7b97fe51c5564de",
78
+ "sha256": "923ed120cf86dbe70f68f4f45ba1196728312b4b05a75afdb531564825956fe6",
79
+ "reason": "Adapt the creation test double to the editor contract and model selector; continue asserting fresh references and second-entry recovery.",
80
+ "patch": "patches/0001-native-field-recipes.patch"
81
+ }
82
+ ],
83
+ "files": {
84
+ "LICENSE": "5f28e43cb8fce117b5d717739e791792ab76b0670af5a209b88472af8fd3ae7d",
85
+ "README.md": "70aa46fc5d1c0d5cd142b871cde43921d1eed7838ea7b47aec400904825811ba",
86
+ "examples/demo-cases.xlsx": "c3d7ae08b3ba563bb6005eae815e30f7d06b5cbf27ae1cbab9c06e6373560622",
87
+ "examples/demo-server.mjs": "a5cef20ce9fdcd528671d2ef2430db6cb17c70096c1b8170dbbf4658ea7bd5d4",
88
+ "examples/demo.html": "97daeed34a2326fcca4afda4f32e19973f530d5a81489a71fd6926eb086d0a29",
89
+ "lib/auth-state.mjs": "046c1b6deeb8cd0dc1b77b9f717724ead7c54016df8c779dea68d21c091d55e0",
90
+ "lib/browser-provider.mjs": "2f0e9945d094330ef17d64bc6f1210ce432d3324fad3192fee9d2de54cf5f246",
91
+ "lib/diagnostics.mjs": "cc4a9410703d5aca78cef5f51fabefad5753352ecb0d8d85715a6b596e1bafe5",
92
+ "lib/discovery.mjs": "3706e326918286b73de9ea56c6cc23e7c6a1df788977207a39ea111e8a438a30",
93
+ "lib/dom.mjs": "3a167f1b4aec92e511f4b56e16e76dac98279b498e86f735192ace61ba5a46f7",
94
+ "lib/engine.mjs": "abebd29d4ab5063a93b5d67e5e57851e90d827849bc948b377377102a6b311b1",
95
+ "lib/form.mjs": "a7185ef21214555fba22eb481301924eeae3a4aad371b60f5793adf777543a27",
96
+ "lib/language.mjs": "60a0e60ce5897f188e3d2f468177455c98fc168bb9010c2a395f759800660ad2",
97
+ "lib/model.mjs": "257ec5a51813c0ed681817a8b6f142a36bc54004deeb9286640b318790026f0e",
98
+ "lib/pending-writes.mjs": "b5e9e211af48c06e6d886ef478b396c695f80c8858f915ea82b9858c4829c043",
99
+ "lib/planner.mjs": "727ee50568a2116ba306eb689d8d86a6ce7e9223fe3a690f3c21e3493127872d",
100
+ "lib/project-config.mjs": "105ebf5d5f9d15efb11c0b69b19570fcea36e6e186061b7dd3184d21bffbf2a6",
101
+ "lib/readiness.mjs": "582b7e56cf022f68c43876f73caf5e7b4cefcac507840eaa406b8c439591107a",
102
+ "lib/replay-model.mjs": "7b39d0afa860d8a642f6520ba71ffdc7b85899426f623786361d376d390dbdee",
103
+ "lib/run-state.mjs": "797e66729f58cda47c7f5465d391df68878716a8e7c695bd8077aa346d83beb5",
104
+ "lib/test-data.mjs": "095844509822929af0ce08145bdbf4adc1d8c5931bda8339d5ad67713c63a792",
105
+ "lib/workflow-policy.mjs": "65053ef4ef9a5dd94000f8386a0fd6ae6015b59a4f4e4858a8447a42087f8dc0",
106
+ "lib/workflow.mjs": "f217c11514ae4e6b32fa326c5fb1fbfc7c03a6322997e84f710c76d17ec7a4c2",
107
+ "lib/workflow_excel.py": "118ce4c93689d677febbbfafafc3a587e6de40702c1b2b7d4fa4351ead9c3988",
108
+ "requirements-local.txt": "d8f05ac9ae4f60b94658ef79f26ddee7e31d2df8c12348b0b50895bd833f6a46",
109
+ "requirements.txt": "9bba605fd7b6ea23038de15e5a1ae6714b3d3fb14ed2d6e6bedbfb0665ca2122",
110
+ "runner.mjs": "9ff9cc0837091172facf8c3460ac2b25b1d00d7847c27332f2891ae0cbb6cde8",
111
+ "tests/api.test.mjs": "30d0d5cffe09483b143acf6fcb603bdc8743871cc7c528b299f5dc330cd94089",
112
+ "tests/browser/runtime.test.mjs": "a49bc2f0893854ef4ed461213a284b7b58abb78f238ef8b82dc94d0b6b8d2404",
113
+ "tests/config.test.mjs": "3bdbe8909209d39b9527be8379e6389d319b88da4f26f6237166b086b5ce1e61",
114
+ "tests/diagnostics.test.mjs": "8ccc54268f32d725ea797b4cbc879b323fae0b6992cebe982d5017896c710417",
115
+ "tests/discovery.test.mjs": "8fca697a5ca410068b42c9197eff53cbc31cc64d8a8e4bf6d870cdfced90f7f2",
116
+ "tests/fixtures/local-model/laya.py": "d377f03ff7cbc9e3bb5d93454f23df871e5a07b0f0bd198774ec55c4caf7200f",
117
+ "tests/fixtures/local-model/torch.py": "278c5c9eebb641292e5c4a925039c1ad2455328d83263387c1802b0441b16d1f",
118
+ "tests/guards.test.mjs": "29970a179c6b7657e5b3d71b67c3ba3d37ae22fd5a448b2de1ccca3ac913fdf7",
119
+ "tests/language.test.mjs": "bb37face3359ce1807613c5668a4493cbce374221223c3c935744fe08dc03a50",
120
+ "tests/planner.test.mjs": "227d8bb078a0625c9cf4f8525fbff6ac2efea5d17c45e79ab4466e35b0a7465f",
121
+ "tests/readiness.test.mjs": "a42b102aaf5c3526fa6b28f52e6594f8b7a83be07083bbc124a1180871f7f1a7",
122
+ "tests/real-model.smoke.mjs": "e0751db4e9e15fb74d53f4425430dbe87abfb0c78f862c4b3350e756e98567a4",
123
+ "tests/replay-model.test.mjs": "d8f7ed075792f51f69ca775d1174bc05cc7aaf25e79322aa9140ce933e3558eb",
124
+ "tests/retries.test.mjs": "93d27d572c2376bf7e6d6b43a61f4835b5ab1a4f7d408836b91025e7014732f2",
125
+ "tests/run-state.test.mjs": "f3aaf1ce4e63df7469d7bfaba20079e8abcd41724e90380c0d67462850312337",
126
+ "tests/selected-pr1.test.mjs": "78c7c180e59f284bbcffcb737ef100b4a028c83a36a0b0f1c7b97fe51c5564de",
127
+ "tests/test-data.test.mjs": "9d3e5f3deb8bbb6088c4410c513134e06929bdb36aa7bc23f76808af19e92c78",
128
+ "tests/test_workflow_excel.py": "9bc64b4de0f06a0f76e69f71e267ae2d7f8fa46f9e8c613cab8c38982f498f1a",
129
+ "tests/worker_test.py": "fb716ccbdf15dbf70a2fed853ec3c879c49f80f4bcda39da0bce8c0b6719e0d7",
130
+ "tests/workflow.test.mjs": "6b881b894f583b2751ea227fb1bb6c21161044a158b9d17516502f15e926b21c",
131
+ "worker.py": "4ad4cb32bb84177d8c4da5be77e33b5b95a72d2581ae2745f159772ecb2f51b4",
132
+ "README.en.md": "487eb4d8b3226f2bd6c907931f665280d9397a361d5fbe13292d51c3549b9301",
133
+ "ROADMAP.md": "833b1e2e09318503314861d8bb632065c7b70951414b8d310c69dd8ea52454e6",
134
+ "config.example.json": "3d256ba55c7d326edb704699aa69fcba98d380e0781586f5aa4225e91205f752",
135
+ "docs/architecture.md": "7c3fe4c42e1e7da3f543e87f5292b527470aafe6c7bad25668b60e8916f08162",
136
+ "docs/browser-use-evaluation.md": "d1042595378b0907172edcb6632e3b91268c7d7ac1c1d4d538e146a042fcc538",
137
+ "docs/demo.png": "904dc7b63c73cc3cc374bd29aa62c8296e8c0bae63a2cbcde09881d686a7bf9c",
138
+ "docs/local-runtime.md": "b73412bd35521992299424c3f838afb9bf4b7a4b8543dc669faaf9b2e063728c",
139
+ "docs/pr1-selection.md": "6dcd5a38c723baea3436055fe2aaae0e597215d3ab1dabf8e46eae4016e883b1",
140
+ "docs/retry-policy.md": "0361bc960a585dd14dac2a0902f90195e9724bae8ff0a7f6bb0635025bab7c5d"
141
+ },
142
+ "additions": [
143
+ {
144
+ "path": "lib/page-capabilities.mjs",
145
+ "sha256": "661f5da6956bd2dc42c5ea76940d660092007e3a7ddf7d46e82364ec2562c227",
146
+ "reason": "Functional, bounded standard-semantic page helpers called only by the upstream workflow; no business selectors or second planner.",
147
+ "patch": "patches/0001-native-field-recipes.patch"
148
+ },
149
+ {
150
+ "path": "lib/page-session.mjs",
151
+ "sha256": "2a283084cded55e3e1ebe7b0ce92c9f30b43fe37fb595a50c7d28351505f8cee",
152
+ "reason": "Functional, bounded standard-semantic page helpers called only by the upstream workflow; no business selectors or second planner.",
153
+ "patch": "patches/0001-native-field-recipes.patch"
154
+ },
155
+ {
156
+ "path": "lib/page-exploration.mjs",
157
+ "sha256": "382807d5007d8e1620f0153e18fcf8afad3d222642ecc1cf8f25bdef03e567ef",
158
+ "reason": "Functional, bounded standard-semantic page helpers called only by the upstream workflow; no business selectors or second planner.",
159
+ "patch": "patches/0001-native-field-recipes.patch"
160
+ },
161
+ {
162
+ "path": "lib/related-records.mjs",
163
+ "sha256": "19bde995ef68cad3d938a9bed7be57882e78bf4bc741c02120cf77821aa4a46e",
164
+ "reason": "Functional, bounded standard-semantic page helpers called only by the upstream workflow; no business selectors or second planner.",
165
+ "patch": "patches/0001-native-field-recipes.patch"
166
+ }
167
+ ]
168
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LayaPilot contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,116 @@
1
+ # LayaPilot · Browser Test Automation for Enterprise Admin Applications
2
+
3
+ [中文](README.md) · [Local runtime guide (中文)](docs/local-runtime.md) · [Architecture and extension points](docs/architecture.md) · [Roadmap](ROADMAP.en.md)
4
+
5
+ Generate **replayable Excel test cases for enterprise admin applications** from a live browser page, or execute an existing natural-language Excel workbook. The focus is on tables, filters, forms and CRUD flows in modules such as user and customer management. Accuracy, speed and stability guide the implementation, with local or intranet inference preferred.
6
+
7
+ The current implementation uses Playwright for browser control and either local Laya or a compatible decision API to interpret fields, select options and ground execution targets. Assertions inspect the resulting page; a model choice alone never counts as a passing test.
8
+
9
+ Generation retains CRUD templates while Laya selects field data strategies and option groups. Equivalent options use a stable order; explicit `--data` values override generation. The default `discover` operation then evaluates extra candidates grounded in observed controls and constraints: empty search, filter reset, cancelling creation, email format and numeric bounds. Only executed, verified cases enter the replay workbook. This bounded discovery does not infer arbitrary business requirements; unsupported observed workflows remain in the report.
10
+
11
+ Replay preserves recorded steps, values and expected results. Laya grounds clicks, text, date and select fields against the live page, including unique matches. Identical decisions can use the in-process cache. Rejected, low-confidence or different choices stop the step rather than changing test data. Saved text, dates and option paths are bound exactly after field matching. Pure assertions do not need model decisions.
12
+
13
+ Both generation and replay write `runs/<run>/执行结果.xlsx`. Generation results are labelled as generation-time validation and retain failed or skipped attempts. `results.json` links this workbook through `resultFile`; decision phases `form-field`, `form-option`, `test-discovery` and `replay-target` distinguish generation and replay decisions. Model loading, inference calls and cache hits are reported separately.
14
+
15
+ This public project includes a local demo, without company-specific adapters, internal URLs, accounts, or gateway settings. **Only the Playwright browser driver and the Laya decision protocol are implemented today.** browser-use and Jev API are listed in the [Roadmap](ROADMAP.en.md), not available backends yet.
16
+
17
+ Generation/replay supports `--operations create,delete` or `--read-only` to limit scope. The local model preloads by default alongside browser setup, with a readiness gate before testing; `--lazy-model` opts into loading on demand. `--auth-state .auth/tester.json --auth-check '#authenticated-user'` persists cookies, localStorage and IndexedDB after a unique authenticated-page marker passes; add `--auth-session-storage` when required. State is bound to origin and account, and expiry fails or reauthenticates explicitly.
18
+
19
+ Workflow runs save an atomic `checkpoint.json` and `progress.ndjson`, preserve partial results on SIGINT/SIGTERM, and return nonzero on failure or empty coverage. Uncertain writes are never blindly resent. Checkpoints support reconciliation, not automatic resume. See the [runtime guide](docs/local-runtime.md) for boundaries and the [Browser Use evaluation](docs/browser-use-evaluation.md) for the current adoption decision.
20
+
21
+ ![Customer management page in the public demo](docs/demo.png)
22
+
23
+ ## Introduction video
24
+
25
+ https://github.com/user-attachments/assets/940b2562-41ff-47ed-a6e0-e179d4d0847d
26
+
27
+ [Watch on YouTube](https://www.youtube.com/watch?v=aIZEEcTGM0w)
28
+
29
+ ## Features
30
+
31
+ | Entry point | What it does | Outputs |
32
+ | ----------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------ |
33
+ | `--mode generate` | Explores tabs, tables, filters, form validation, and supported CRUD actions | 17-column XLSX, report, browser evidence |
34
+ | `--mode execute` | Re-discovers DOM controls and replays a generated workbook | Separate `执行结果.xlsx`, report, evidence |
35
+ | `--excel` | Executes supported steps from an existing workbook; selects source rows marked `pass` by default | JSON, CSV and Markdown reports |
36
+
37
+ Only flows that completed with a page assertion are written to a generated workbook. The visible steps and expected results follow the 17-column template; a hidden sheet holds structured replay steps. If the visible case changes without its replay steps, execution stops. Failures capture the failed step, page and console errors, HTTP 4xx/5xx events, and screenshots. Approval, multi-user permissions, file import, and arbitrary websites or prose cases are not universally supported.
38
+
39
+ ## Requirements and local Laya
40
+
41
+ - Node.js **20+**, Python **3.10+** (3.11 or 3.12 recommended), and Playwright Chromium. Use `node runner.mjs` on macOS, Linux or Windows; `run.sh` is a macOS/Linux convenience script.
42
+ - **We recommend installing official Laya locally** with the [`convaiinnovations/laya-multilingual`](https://huggingface.co/convaiinnovations/laya-multilingual) checkpoint for both Chinese and English pages. The first run downloads model files. Later runs can use the cache or a directory supplied through `LAYA_MODEL`. Do not commit weights.
43
+ - **Practical recommendation, not an official minimum:** at least 4 CPU cores, **16 GB RAM**, and **5 GB free disk space** for local model + browser use; a discrete GPU is not required. We verified CPU operation on an Apple Silicon M4 with 16 GB RAM: the local model directory was about 647 MB and one initial load took about 27 seconds. Your machine may differ. API mode does not load Laya locally but still needs Node, a browser, Python, and `openpyxl`.
44
+
45
+ ```bash
46
+ git clone <your-repository-url> laya-pilot
47
+ cd laya-pilot
48
+ npm install
49
+ npx playwright install chromium
50
+ python3.11 -m venv .venv
51
+ .venv/bin/python -m pip install -r requirements-local.txt
52
+ ```
53
+
54
+ On Windows, pass `.venv\Scripts\python.exe` with `--python`. For API-only use, install `requirements.txt` instead of `requirements-local.txt`. Consult the [official model card](https://huggingface.co/convaiinnovations/laya-multilingual) and [official Python project](https://github.com/NandhaKishorM/laya) for current Laya installation guidance.
55
+
56
+ ## Try the demo
57
+
58
+ Start the demo in one terminal and run cases in another. Customer data lives in browser localStorage, and some DOM IDs change on every visit.
59
+
60
+ ```bash
61
+ npm run demo
62
+ ./run.sh --mode generate --url http://127.0.0.1:8765/customers \
63
+ --case-file generated-cases/customers.xlsx
64
+ ./run.sh --mode execute --case-file generated-cases/customers.xlsx \
65
+ --url http://127.0.0.1:8765/customers
66
+ ```
67
+
68
+ The browser is visible by default; add `--headless` when ready. To try an existing workbook, use `./run.sh --excel examples/demo-cases.xlsx --url http://127.0.0.1:8765/customers`. Generation performs real create, edit and delete operations, so use a dedicated test environment.
69
+
70
+ ## Configure your system
71
+
72
+ Copy [`config.example.json`](config.example.json) to `config.local.json` and set your test URL and runtime options. Copy [`.env.example`](.env.example) to `.env.local` for local passwords and API keys. Both local files are ignored by Git. The launcher reads `.env.local` without executing shell code. CLI arguments override shell variables, which override `.env.local`, which overrides the JSON file. Passwords and API keys are accepted **only through environment variables, `.env.local`, or a hidden terminal prompt**, never through the JSON config.
73
+
74
+ ```bash
75
+ ./run.sh --mode generate --config config.local.json --manual-login
76
+ ./run.sh --mode execute --config config.local.json \
77
+ --case-file generated-cases/customers.xlsx
78
+ ```
79
+
80
+ For automatic login, pass `--user` or `TEST_USER`; supply the password through `TEST_PASSWORD` (optionally in `.env.local`) or the hidden prompt. API mode requires `LAYA_API_BASE`, `LAYA_API_MODEL`, and `LAYA_API_KEY`:
81
+
82
+ ```bash
83
+ export LAYA_API_BASE='https://your-gateway.example/v1'
84
+ export LAYA_API_MODEL='your-decision-model'
85
+ export LAYA_API_KEY='your-secret-key'
86
+ ./run.sh --mode generate --provider api --url 'https://your-test-app.example/module' --manual-login
87
+ ```
88
+
89
+ Local mode defaults to `convaiinnovations/laya-multilingual`; set `LAYA_MODEL=/path/to/model` and `LAYA_PYTHON=/path/to/python` to override it. The browser defaults to Playwright's bundled Chromium; `--browser-channel chrome` uses a separately installed Chrome. `--browser-provider` currently accepts only `playwright` and rejects unsupported values. `--template-excel` can supply a matching 17-column workbook; otherwise the tool creates one without relying on a personal file.
90
+
91
+ Run artifacts go to ignored `runs/` and generated workbooks to ignored `generated-cases/`. Reports and workbooks may contain test URLs, page text or test data; review them before sharing. Run `./run.sh --help` for CLI options.
92
+
93
+ ## Development and limitations
94
+
95
+ Code uses four-space indentation, UTF-8, LF line endings, and a 100-column wrapping target. Prettier formats JS, JSON, HTML, and Markdown; Ruff formats Python. Formatter versions are pinned, and formatting does not apply lint fixes.
96
+
97
+ Development requires Node.js and uv. After `npm install`, run:
98
+
99
+ ```bash
100
+ npm run format # Format the repository
101
+ npm run format:check # Check formatting before a commit or in CI
102
+ ```
103
+
104
+ On its first run, `uv tool run` obtains the pinned Ruff version and caches it for later use. Local model dependencies are not required. Runtime output, local configuration, and dependency directories are excluded; npm manages `package-lock.json`.
105
+
106
+ `.editorconfig` supplies basic editor conventions; it does not reformat existing files. For formatting on save, install the Prettier and Ruff editor extensions and enable formatting on save for the corresponding languages.
107
+
108
+ ```bash
109
+ npm test
110
+ python3 -m unittest discover -s tests -p 'test_*.py'
111
+ LAYA_TEST_PYTHON=/path/to/python-with-openpyxl npm run test:browser
112
+ ```
113
+
114
+ Control discovery uses DOM, labels, ARIA roles and some common component classes. It re-observes dynamic DOM, but Canvas controls, closed Shadow DOM, unlabeled custom widgets, and cross-account workflows need adapters. See the [architecture guide](docs/architecture.md) for extension points and current boundaries.
115
+
116
+ MIT License. Laya, Playwright and model weights have their own licenses.