preflite 1.0.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.
Files changed (138) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +144 -0
  3. package/dist/adapter-spi/artifact/index.js +1 -0
  4. package/dist/adapter-spi/command/index.js +1 -0
  5. package/dist/adapter-spi/install/index.js +1 -0
  6. package/dist/adapter-spi/lifecycle/index.js +1 -0
  7. package/dist/adapter-spi/resource/index.js +1 -0
  8. package/dist/adapter-spi/snapshot/index.js +1 -0
  9. package/dist/application/agent/AgentCommandPollLoop.js +48 -0
  10. package/dist/application/agent/AgentRuntimeService.js +27 -0
  11. package/dist/application/app-package/AppPackageApplicationService.js +97 -0
  12. package/dist/application/artifact/ArtifactApplicationService.js +13 -0
  13. package/dist/application/debug/DebugApplicationService.js +117 -0
  14. package/dist/application/health/HealthMetricsService.js +47 -0
  15. package/dist/application/lease/LeaseApplicationService.js +79 -0
  16. package/dist/application/query/ObservationQueryService.js +48 -0
  17. package/dist/application/reporter/ReporterApplicationService.js +41 -0
  18. package/dist/application/resource/ResourceOccupationReleaseService.js +49 -0
  19. package/dist/application/resource/ResourceRegistryService.js +113 -0
  20. package/dist/application/session/SessionApplicationService.js +39 -0
  21. package/dist/application/task/TaskApplicationService.js +378 -0
  22. package/dist/client/agentAppPackageClient.js +91 -0
  23. package/dist/domain/agent/AgentNode.js +12 -0
  24. package/dist/domain/agent/AgentRuntime.js +6 -0
  25. package/dist/domain/artifact/ArtifactPipeline.js +6 -0
  26. package/dist/domain/artifact/ArtifactRef.js +12 -0
  27. package/dist/domain/event/AgentEvent.js +10 -0
  28. package/dist/domain/event/Reporter.js +6 -0
  29. package/dist/domain/health/HealthMetrics.js +8 -0
  30. package/dist/domain/lease/Lease.js +28 -0
  31. package/dist/domain/lease/LeaseManager.js +6 -0
  32. package/dist/domain/repositories/index.js +1 -0
  33. package/dist/domain/resource/DeviceDetails.js +23 -0
  34. package/dist/domain/resource/DeviceResource.js +16 -0
  35. package/dist/domain/resource/ResourceRegistry.js +6 -0
  36. package/dist/domain/runtime/interfaces.js +1 -0
  37. package/dist/domain/session/BaseSession.js +16 -0
  38. package/dist/domain/session/DebugSession.js +3 -0
  39. package/dist/domain/session/ExecutionSession.js +3 -0
  40. package/dist/domain/session/SessionManager.js +8 -0
  41. package/dist/domain/task/TaskRecord.js +14 -0
  42. package/dist/domain/task/TaskSpec.js +12 -0
  43. package/dist/infrastructure/adapters/AdapterRegistry.js +10 -0
  44. package/dist/infrastructure/adapters/BridgeAdapters.js +6 -0
  45. package/dist/infrastructure/adapters/android/AndroidResourceAdapter.js +51 -0
  46. package/dist/infrastructure/adapters/deviceDetailsProbe.js +229 -0
  47. package/dist/infrastructure/adapters/harmony/HarmonyResourceAdapter.js +40 -0
  48. package/dist/infrastructure/adapters/ios/IOSResourceAdapter.js +182 -0
  49. package/dist/infrastructure/adapters/real/ShellCommandAndSnapshot.js +41 -0
  50. package/dist/infrastructure/airtest/AirtestRuntime.js +168 -0
  51. package/dist/infrastructure/app-package/AppPackageUrlCache.js +191 -0
  52. package/dist/infrastructure/app-package/appPackageDownloadDir.js +13 -0
  53. package/dist/infrastructure/bootstrap/BuildRuntimeContext.js +88 -0
  54. package/dist/infrastructure/cache/DirCapacityWatchdog.js +150 -0
  55. package/dist/infrastructure/config/agentConfigFile.js +96 -0
  56. package/dist/infrastructure/device/DeviceAppPackageOps.js +146 -0
  57. package/dist/infrastructure/ios/IOSWdaWatchdog.js +207 -0
  58. package/dist/infrastructure/live-debug/LiveDebugSessionManager.js +74 -0
  59. package/dist/infrastructure/live-debug/RuntimeLiveDebugAdapters.js +19 -0
  60. package/dist/infrastructure/midscene/DebugRuntimeImpl.js +533 -0
  61. package/dist/infrastructure/midscene/MidsceneRuntimeMock.js +22 -0
  62. package/dist/infrastructure/midscene/MidsceneRuntimeReal.js +552 -0
  63. package/dist/infrastructure/midscene/executionDumpWatcher.js +219 -0
  64. package/dist/infrastructure/midscene/videoRecorder.js +365 -0
  65. package/dist/infrastructure/midscene/zipReportDir.js +36 -0
  66. package/dist/infrastructure/persistence/InMemoryRepositories.js +94 -0
  67. package/dist/infrastructure/resilience/DeliveryIdDeduper.js +26 -0
  68. package/dist/infrastructure/system/CommandRunner.js +128 -0
  69. package/dist/infrastructure/transport/http/AgentEventHttpIngestClient.js +52 -0
  70. package/dist/infrastructure/transport/http/CallbackOutboxStore.js +106 -0
  71. package/dist/infrastructure/transport/http/PlatformCallbackClient.js +113 -0
  72. package/dist/infrastructure/transport/http/PlatformCommandPollClient.js +89 -0
  73. package/dist/infrastructure/transport/http/ResilientPlatformCallbackClient.js +117 -0
  74. package/dist/infrastructure/transport/midscenePaths.js +28 -0
  75. package/dist/infrastructure/transport/ws/ResilientWsOrHttpEventPublisher.js +29 -0
  76. package/dist/infrastructure/transport/ws/WsClient.js +182 -0
  77. package/dist/infrastructure/transport/ws/WsEventPublisher.js +36 -0
  78. package/dist/interfaces/http/HttpServer.js +227 -0
  79. package/dist/interfaces/websocket/AgentWsGateway.js +227 -0
  80. package/dist/main.js +368 -0
  81. package/dist/mcp/agentHttpClient.js +82 -0
  82. package/dist/mcp/agentRuntime.js +184 -0
  83. package/dist/mcp/cli.js +36 -0
  84. package/dist/mcp/doctor.js +124 -0
  85. package/dist/mcp/evidence.js +57 -0
  86. package/dist/mcp/exploration/index.js +129 -0
  87. package/dist/mcp/exploration/sessionManager.js +122 -0
  88. package/dist/mcp/exploration/tools-atomic.js +34 -0
  89. package/dist/mcp/exploration/tools-intelligent.js +33 -0
  90. package/dist/mcp/exploration/tools-session.js +276 -0
  91. package/dist/mcp/exploration/types.js +1 -0
  92. package/dist/mcp/flowStepEvents.js +114 -0
  93. package/dist/mcp/liveViewer.js +156 -0
  94. package/dist/mcp/reportReader.js +157 -0
  95. package/dist/mcp/runManager.js +161 -0
  96. package/dist/mcp/runSummary.js +72 -0
  97. package/dist/mcp/runtimeInstall.js +44 -0
  98. package/dist/mcp/server.js +260 -0
  99. package/dist/mcp/setup.js +185 -0
  100. package/dist/mcp/types.js +1 -0
  101. package/dist/mcp/userConfig.js +45 -0
  102. package/dist/mcp/visual-flow/codegen.js +576 -0
  103. package/dist/mcp/visual-flow/index.js +14 -0
  104. package/dist/mcp/visual-flow/types.js +5 -0
  105. package/dist/mcp/visual-flow/validate.js +617 -0
  106. package/dist/protocol-contracts/commands/envelope.js +24 -0
  107. package/dist/protocol-contracts/commands/index.js +1 -0
  108. package/dist/protocol-contracts/dto/index.js +1 -0
  109. package/dist/protocol-contracts/events/index.js +1 -0
  110. package/dist/protocol-contracts/queries/index.js +1 -0
  111. package/dist/shared-kernel/enums/index.js +70 -0
  112. package/dist/shared-kernel/errors/index.js +21 -0
  113. package/dist/shared-kernel/ids/index.js +18 -0
  114. package/dist/shared-kernel/time/index.js +3 -0
  115. package/dist/shared-kernel/value-objects/index.js +1 -0
  116. package/dist/utils/appPackageLocalPath.js +75 -0
  117. package/dist/utils/deviceResourceRouting.js +24 -0
  118. package/dist/utils/harmonyAgentDebugDevice.js +60 -0
  119. package/dist/utils/harmonyHdcDeviceId.js +134 -0
  120. package/dist/utils/iosAgentDebugDevice.js +72 -0
  121. package/dist/utils/iosMjpegCapture.js +90 -0
  122. package/dist/utils/liveDebugForegroundParse.js +71 -0
  123. package/dist/utils/midscene-device-session.js +353 -0
  124. package/dist/utils/midscene-task-cache-env.js +15 -0
  125. package/dist/utils/midsceneReportConstants.js +49 -0
  126. package/dist/utils/seedMidsceneTaskCache.js +61 -0
  127. package/dist/utils/task-runners/context/androidTaskRunnerContext.js +1 -0
  128. package/dist/utils/task-runners/context/harmonyTaskRunnerContext.js +1 -0
  129. package/dist/utils/task-runners/context/iosTaskRunnerContext.js +1 -0
  130. package/dist/utils/task-runners/runAndroidNativeAppTask.js +29 -0
  131. package/dist/utils/task-runners/runHarmonyNativeAppTask.js +36 -0
  132. package/dist/utils/task-runners/runIosNativeAppTask.js +30 -0
  133. package/dist/utils/task-runners/taskAppPackage.js +20 -0
  134. package/dist/utils/wrapper/resolveTaskRunnerImport.js +11 -0
  135. package/dist/utils/wrapper/wrapAndroidTaskScript.js +38 -0
  136. package/dist/utils/wrapper/wrapHarmonyTaskScript.js +42 -0
  137. package/dist/utils/wrapper/wrapIosTaskScript.js +30 -0
  138. package/package.json +46 -0
@@ -0,0 +1,42 @@
1
+ import { resolveTaskRunnerImportUrl } from './resolveTaskRunnerImport.js';
2
+ function targetToRunnerArgs(target) {
3
+ return {
4
+ deviceId: target.deviceId,
5
+ hdcTconnHost: target.hdcTconnHost,
6
+ hdcTconnPort: target.hdcTconnPort,
7
+ hdcPath: target.hdcPath,
8
+ };
9
+ }
10
+ /**
11
+ * 鸿蒙任务执行:生成薄层脚本,实际模版见 {@link runHarmonyNativeAppTask}。
12
+ */
13
+ export function wrapHarmonyTaskScript(userScript, target) {
14
+ const body = userScript.trim();
15
+ const indented = body
16
+ ? body.split(/\r?\n/).map((line) => ` ${line}`).join('\n')
17
+ : ' // (用例脚本为空)';
18
+ const t = targetToRunnerArgs(target);
19
+ const deviceIdLiteral = JSON.stringify(t.deviceId);
20
+ const hostLiteral = typeof t.hdcTconnHost === 'string' && t.hdcTconnHost.trim()
21
+ ? JSON.stringify(t.hdcTconnHost.trim())
22
+ : 'undefined';
23
+ const portLiteral = Number.isFinite(t.hdcTconnPort) && (t.hdcTconnPort ?? 0) > 0
24
+ ? JSON.stringify(Math.floor(t.hdcTconnPort))
25
+ : 'undefined';
26
+ const hdcPathLiteral = typeof t.hdcPath === 'string' && t.hdcPath.trim() ? JSON.stringify(t.hdcPath.trim()) : 'undefined';
27
+ const runnerImportUrlLiteral = JSON.stringify(resolveTaskRunnerImportUrl('runHarmonyNativeAppTask'));
28
+ return `import { runHarmonyNativeAppTask } from ${runnerImportUrlLiteral};
29
+
30
+ Promise.resolve(
31
+ runHarmonyNativeAppTask(
32
+ { deviceId: ${deviceIdLiteral}, hdcTconnHost: ${hostLiteral}, hdcTconnPort: ${portLiteral}, hdcPath: ${hdcPathLiteral} },
33
+ async ({ agent, page, sleep, installApp, uninstallApp }) => {
34
+ ${indented}
35
+ },
36
+ ),
37
+ ).catch((e) => {
38
+ console.error(e);
39
+ process.exit(1);
40
+ });
41
+ `;
42
+ }
@@ -0,0 +1,30 @@
1
+ import { resolveTaskRunnerImportUrl } from './resolveTaskRunnerImport.js';
2
+ /**
3
+ * iOS 任务执行:生成薄层脚本,实际模版见 {@link runIosNativeAppTask}(可维护的真实 TS)。
4
+ */
5
+ export function wrapIosTaskScript(userScript, target) {
6
+ const body = userScript.trim();
7
+ const indented = body
8
+ ? body.split(/\r?\n/).map((line) => ` ${line}`).join('\n')
9
+ : ' // (用例脚本为空)';
10
+ const wdaHostLiteral = JSON.stringify(target.wdaHost);
11
+ const wdaPortLiteral = JSON.stringify(target.wdaPort);
12
+ const deviceIdLiteral = typeof target.deviceId === 'string' && target.deviceId.trim()
13
+ ? JSON.stringify(target.deviceId.trim())
14
+ : 'undefined';
15
+ const runnerImportUrlLiteral = JSON.stringify(resolveTaskRunnerImportUrl('runIosNativeAppTask'));
16
+ return `import { runIosNativeAppTask } from ${runnerImportUrlLiteral};
17
+
18
+ Promise.resolve(
19
+ runIosNativeAppTask(
20
+ { wdaHost: ${wdaHostLiteral}, wdaPort: ${wdaPortLiteral}, deviceId: ${deviceIdLiteral} },
21
+ async ({ agent, page, sleep, installApp, uninstallApp }) => {
22
+ ${indented}
23
+ },
24
+ ),
25
+ ).catch((e) => {
26
+ console.error(e);
27
+ process.exit(1);
28
+ });
29
+ `;
30
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "preflite",
3
+ "version": "1.0.1",
4
+ "description": "Preflight — Local mobile AI testing via MCP. AI-assisted testing on real Android/iOS/Harmony devices.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "bin": {
8
+ "preflite": "dist/mcp/cli.js"
9
+ },
10
+ "files": [
11
+ "dist/",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20.11.0"
17
+ },
18
+ "scripts": {
19
+ "mcp": "tsx src/mcp/cli.ts",
20
+ "mcp:setup": "tsx src/mcp/cli.ts setup",
21
+ "build": "tsc -p tsconfig.build.json",
22
+ "check": "tsc -p tsconfig.json --noEmit",
23
+ "test": "tsx --test src/tests/**/*.test.ts",
24
+ "start": "node dist/main.js"
25
+ },
26
+ "dependencies": {
27
+ "@midscene/android": "^1.7.5",
28
+ "@midscene/harmony": "^1.7.5",
29
+ "@midscene/ios": "^1.7.5",
30
+ "@modelcontextprotocol/sdk": "^1.17.5",
31
+ "koa": "^2.15.4",
32
+ "lodash": "^4.17.21",
33
+ "sharp": "^0.33.5",
34
+ "tsx": "^4.20.6",
35
+ "ws": "^8.18.3",
36
+ "yaml": "^2.8.1",
37
+ "zod": "^3.25.76"
38
+ },
39
+ "devDependencies": {
40
+ "@types/koa": "^3.0.2",
41
+ "@types/lodash": "^4.17.24",
42
+ "@types/node": "^20.17.57",
43
+ "@types/ws": "^8.18.1",
44
+ "typescript": "^5.9.3"
45
+ }
46
+ }