playwright-intelligence-engine 0.0.0-stage → 2.0.0

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 (353) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +229 -3
  3. package/bin/pw-intel.js +37 -0
  4. package/dist/authoring/author.d.ts +83 -0
  5. package/dist/authoring/author.d.ts.map +1 -0
  6. package/dist/authoring/generation-contract.d.ts +90 -0
  7. package/dist/authoring/generation-contract.d.ts.map +1 -0
  8. package/dist/authoring/hybrid-author.d.ts +6 -0
  9. package/dist/authoring/hybrid-author.d.ts.map +1 -0
  10. package/dist/authoring/index.d.ts +7 -0
  11. package/dist/authoring/index.d.ts.map +1 -0
  12. package/dist/authoring/llm-author.d.ts +28 -0
  13. package/dist/authoring/llm-author.d.ts.map +1 -0
  14. package/dist/authoring/naming/index.d.ts +4 -0
  15. package/dist/authoring/naming/index.d.ts.map +1 -0
  16. package/dist/authoring/naming/name-plan.d.ts +45 -0
  17. package/dist/authoring/naming/name-plan.d.ts.map +1 -0
  18. package/dist/authoring/naming/name-planner.d.ts +25 -0
  19. package/dist/authoring/naming/name-planner.d.ts.map +1 -0
  20. package/dist/authoring/naming/naming-linter.d.ts +20 -0
  21. package/dist/authoring/naming/naming-linter.d.ts.map +1 -0
  22. package/dist/authoring/template-author.d.ts +6 -0
  23. package/dist/authoring/template-author.d.ts.map +1 -0
  24. package/dist/cli/index.d.ts +2 -0
  25. package/dist/cli/index.d.ts.map +1 -0
  26. package/dist/collectors/collector-interface.d.ts +7 -0
  27. package/dist/collectors/collector-interface.d.ts.map +1 -0
  28. package/dist/collectors/environment-collector.d.ts +12 -0
  29. package/dist/collectors/environment-collector.d.ts.map +1 -0
  30. package/dist/collectors/error-collector.d.ts +18 -0
  31. package/dist/collectors/error-collector.d.ts.map +1 -0
  32. package/dist/collectors/git-diff-collector.d.ts +20 -0
  33. package/dist/collectors/git-diff-collector.d.ts.map +1 -0
  34. package/dist/collectors/live-browser-collector.d.ts +45 -0
  35. package/dist/collectors/live-browser-collector.d.ts.map +1 -0
  36. package/dist/collectors/network-collector.d.ts +28 -0
  37. package/dist/collectors/network-collector.d.ts.map +1 -0
  38. package/dist/collectors/static-ast-collector.d.ts +32 -0
  39. package/dist/collectors/static-ast-collector.d.ts.map +1 -0
  40. package/dist/collectors/trace-collector.d.ts +12 -0
  41. package/dist/collectors/trace-collector.d.ts.map +1 -0
  42. package/dist/config/project-config.d.ts +33 -0
  43. package/dist/config/project-config.d.ts.map +1 -0
  44. package/dist/core/errors/engine-errors.d.ts +34 -0
  45. package/dist/core/errors/engine-errors.d.ts.map +1 -0
  46. package/dist/core/types/diagnostic-context.d.ts +151 -0
  47. package/dist/core/types/diagnostic-context.d.ts.map +1 -0
  48. package/dist/core/types/repair-evidence.d.ts +56 -0
  49. package/dist/core/types/repair-evidence.d.ts.map +1 -0
  50. package/dist/core/version.d.ts +13 -0
  51. package/dist/core/version.d.ts.map +1 -0
  52. package/dist/diagnostics/diagnostic-contract.d.ts +52 -0
  53. package/dist/diagnostics/diagnostic-contract.d.ts.map +1 -0
  54. package/dist/diagnostics/diagnostic-report.d.ts +11 -0
  55. package/dist/diagnostics/diagnostic-report.d.ts.map +1 -0
  56. package/dist/diagnostics/evidence-correlator.d.ts +22 -0
  57. package/dist/diagnostics/evidence-correlator.d.ts.map +1 -0
  58. package/dist/diagnostics/external-failure-evidence.d.ts +18 -0
  59. package/dist/diagnostics/external-failure-evidence.d.ts.map +1 -0
  60. package/dist/diagnostics/failure-category.d.ts +4 -0
  61. package/dist/diagnostics/failure-category.d.ts.map +1 -0
  62. package/dist/diagnostics/failure-classifier.d.ts +58 -0
  63. package/dist/diagnostics/failure-classifier.d.ts.map +1 -0
  64. package/dist/evaluation/evaluation-scorecard.d.ts +72 -0
  65. package/dist/evaluation/evaluation-scorecard.d.ts.map +1 -0
  66. package/dist/evaluation/repository-inspector.d.ts +21 -0
  67. package/dist/evaluation/repository-inspector.d.ts.map +1 -0
  68. package/dist/evaluation/repository-runner.d.ts +24 -0
  69. package/dist/evaluation/repository-runner.d.ts.map +1 -0
  70. package/dist/evidence/evidence-model.d.ts +88 -0
  71. package/dist/evidence/evidence-model.d.ts.map +1 -0
  72. package/dist/evidence/evidence-normalizer.d.ts +19 -0
  73. package/dist/evidence/evidence-normalizer.d.ts.map +1 -0
  74. package/dist/evidence/evidence-redactor.d.ts +37 -0
  75. package/dist/evidence/evidence-redactor.d.ts.map +1 -0
  76. package/dist/framework/config-adapter.d.ts +28 -0
  77. package/dist/framework/config-adapter.d.ts.map +1 -0
  78. package/dist/gate/index.d.ts +21 -0
  79. package/dist/gate/index.d.ts.map +1 -0
  80. package/dist/gate/oracle.d.ts +26 -0
  81. package/dist/gate/oracle.d.ts.map +1 -0
  82. package/dist/gate/quality.d.ts +27 -0
  83. package/dist/gate/quality.d.ts.map +1 -0
  84. package/dist/gate/safety.d.ts +28 -0
  85. package/dist/gate/safety.d.ts.map +1 -0
  86. package/dist/generator/architecture-generator.d.ts +55 -0
  87. package/dist/generator/architecture-generator.d.ts.map +1 -0
  88. package/dist/generator/assertion-quality-gate.d.ts +18 -0
  89. package/dist/generator/assertion-quality-gate.d.ts.map +1 -0
  90. package/dist/generator/candidate-writer.d.ts +34 -0
  91. package/dist/generator/candidate-writer.d.ts.map +1 -0
  92. package/dist/generator/test-generator.d.ts +26 -0
  93. package/dist/generator/test-generator.d.ts.map +1 -0
  94. package/dist/governance/audit-log.d.ts +23 -0
  95. package/dist/governance/audit-log.d.ts.map +1 -0
  96. package/dist/governance/governance-policy.d.ts +24 -0
  97. package/dist/governance/governance-policy.d.ts.map +1 -0
  98. package/dist/governance/team-dashboard.d.ts +51 -0
  99. package/dist/governance/team-dashboard.d.ts.map +1 -0
  100. package/dist/governance/workflow-audit.d.ts +13 -0
  101. package/dist/governance/workflow-audit.d.ts.map +1 -0
  102. package/dist/index.d.ts +90 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +20318 -0
  105. package/dist/integrations/ci-summary.d.ts +14 -0
  106. package/dist/integrations/ci-summary.d.ts.map +1 -0
  107. package/dist/integrations/playwright-report-adapter.d.ts +22 -0
  108. package/dist/integrations/playwright-report-adapter.d.ts.map +1 -0
  109. package/dist/integrations/quality-gate.d.ts +35 -0
  110. package/dist/integrations/quality-gate.d.ts.map +1 -0
  111. package/dist/integrations/sarif-report.d.ts +48 -0
  112. package/dist/integrations/sarif-report.d.ts.map +1 -0
  113. package/dist/intelligence/autonomous-repair-workflow.d.ts +31 -0
  114. package/dist/intelligence/autonomous-repair-workflow.d.ts.map +1 -0
  115. package/dist/intelligence/business-intent.d.ts +58 -0
  116. package/dist/intelligence/business-intent.d.ts.map +1 -0
  117. package/dist/intelligence/evidence-bundle.d.ts +364 -0
  118. package/dist/intelligence/evidence-bundle.d.ts.map +1 -0
  119. package/dist/intelligence/failure-clustering.d.ts +38 -0
  120. package/dist/intelligence/failure-clustering.d.ts.map +1 -0
  121. package/dist/intelligence/generation-agent.d.ts +120 -0
  122. package/dist/intelligence/generation-agent.d.ts.map +1 -0
  123. package/dist/intelligence/generation-verifier.d.ts +151 -0
  124. package/dist/intelligence/generation-verifier.d.ts.map +1 -0
  125. package/dist/intelligence/llm-proposal.d.ts +377 -0
  126. package/dist/intelligence/llm-proposal.d.ts.map +1 -0
  127. package/dist/intelligence/locator-disambiguation-engine.d.ts +38 -0
  128. package/dist/intelligence/locator-disambiguation-engine.d.ts.map +1 -0
  129. package/dist/intelligence/model-contract.d.ts +86 -0
  130. package/dist/intelligence/model-contract.d.ts.map +1 -0
  131. package/dist/intelligence/model-provider.d.ts +75 -0
  132. package/dist/intelligence/model-provider.d.ts.map +1 -0
  133. package/dist/intelligence/project-intelligence.d.ts +22 -0
  134. package/dist/intelligence/project-intelligence.d.ts.map +1 -0
  135. package/dist/intelligence/repair-agent.d.ts +46 -0
  136. package/dist/intelligence/repair-agent.d.ts.map +1 -0
  137. package/dist/intelligence/repository-profile.d.ts +131 -0
  138. package/dist/intelligence/repository-profile.d.ts.map +1 -0
  139. package/dist/intelligence/suite-intelligence.d.ts +59 -0
  140. package/dist/intelligence/suite-intelligence.d.ts.map +1 -0
  141. package/dist/intelligence/test-intelligence.d.ts +44 -0
  142. package/dist/intelligence/test-intelligence.d.ts.map +1 -0
  143. package/dist/intelligence/trace-proposal-workflow.d.ts +30 -0
  144. package/dist/intelligence/trace-proposal-workflow.d.ts.map +1 -0
  145. package/dist/intelligence/verified-llm-repair-workflow.d.ts +21 -0
  146. package/dist/intelligence/verified-llm-repair-workflow.d.ts.map +1 -0
  147. package/dist/intelligence/workflow-planner.d.ts +278 -0
  148. package/dist/intelligence/workflow-planner.d.ts.map +1 -0
  149. package/dist/mcp/server.d.ts +32 -0
  150. package/dist/mcp/server.d.ts.map +1 -0
  151. package/dist/memory/stability-ledger.d.ts +46 -0
  152. package/dist/memory/stability-ledger.d.ts.map +1 -0
  153. package/dist/perception/app-model.d.ts +55 -0
  154. package/dist/perception/app-model.d.ts.map +1 -0
  155. package/dist/perception/crawler.d.ts +18 -0
  156. package/dist/perception/crawler.d.ts.map +1 -0
  157. package/dist/perception/index.d.ts +3 -0
  158. package/dist/perception/index.d.ts.map +1 -0
  159. package/dist/repair/approval-service.d.ts +139 -0
  160. package/dist/repair/approval-service.d.ts.map +1 -0
  161. package/dist/repair/assertion-hasher.d.ts +62 -0
  162. package/dist/repair/assertion-hasher.d.ts.map +1 -0
  163. package/dist/repair/ast-patcher.d.ts +36 -0
  164. package/dist/repair/ast-patcher.d.ts.map +1 -0
  165. package/dist/repair/browser-operation-executor.d.ts +27 -0
  166. package/dist/repair/browser-operation-executor.d.ts.map +1 -0
  167. package/dist/repair/diff-allowlist.d.ts +74 -0
  168. package/dist/repair/diff-allowlist.d.ts.map +1 -0
  169. package/dist/repair/intent-validator.d.ts +157 -0
  170. package/dist/repair/intent-validator.d.ts.map +1 -0
  171. package/dist/repair/repair-operations.d.ts +40 -0
  172. package/dist/repair/repair-operations.d.ts.map +1 -0
  173. package/dist/repair/repair-planner.d.ts +98 -0
  174. package/dist/repair/repair-planner.d.ts.map +1 -0
  175. package/dist/repair/repair-workflow.d.ts +42 -0
  176. package/dist/repair/repair-workflow.d.ts.map +1 -0
  177. package/dist/repair/safe-operation-compiler.d.ts +15 -0
  178. package/dist/repair/safe-operation-compiler.d.ts.map +1 -0
  179. package/dist/repair/source-mapper.d.ts +19 -0
  180. package/dist/repair/source-mapper.d.ts.map +1 -0
  181. package/dist/repair/statement-patcher.d.ts +75 -0
  182. package/dist/repair/statement-patcher.d.ts.map +1 -0
  183. package/dist/repair/verification-gates.d.ts +25 -0
  184. package/dist/repair/verification-gates.d.ts.map +1 -0
  185. package/dist/repair/workflow-plan.d.ts +35 -0
  186. package/dist/repair/workflow-plan.d.ts.map +1 -0
  187. package/dist/repair/workspace-promoter.d.ts +43 -0
  188. package/dist/repair/workspace-promoter.d.ts.map +1 -0
  189. package/dist/reproduce/diagnostic-rerunner.d.ts +40 -0
  190. package/dist/reproduce/diagnostic-rerunner.d.ts.map +1 -0
  191. package/dist/reproduce/direct-browser-investigator.d.ts +41 -0
  192. package/dist/reproduce/direct-browser-investigator.d.ts.map +1 -0
  193. package/dist/reproduce/interactive-workflow-runner.d.ts +43 -0
  194. package/dist/reproduce/interactive-workflow-runner.d.ts.map +1 -0
  195. package/dist/sandbox/dependency-strategy.d.ts +45 -0
  196. package/dist/sandbox/dependency-strategy.d.ts.map +1 -0
  197. package/dist/sandbox/execution-runner.d.ts +81 -0
  198. package/dist/sandbox/execution-runner.d.ts.map +1 -0
  199. package/dist/sandbox/worktree-manager.d.ts +51 -0
  200. package/dist/sandbox/worktree-manager.d.ts.map +1 -0
  201. package/dist/selector/abstention-policy.d.ts +34 -0
  202. package/dist/selector/abstention-policy.d.ts.map +1 -0
  203. package/dist/selector/candidate-extractor.d.ts +71 -0
  204. package/dist/selector/candidate-extractor.d.ts.map +1 -0
  205. package/dist/selector/live-locator-verifier.d.ts +28 -0
  206. package/dist/selector/live-locator-verifier.d.ts.map +1 -0
  207. package/dist/selector/repair-candidate-ranker.d.ts +10 -0
  208. package/dist/selector/repair-candidate-ranker.d.ts.map +1 -0
  209. package/dist/selector/selector-scorer.d.ts +43 -0
  210. package/dist/selector/selector-scorer.d.ts.map +1 -0
  211. package/dist/trace/adapters/adapter-registry.d.ts +18 -0
  212. package/dist/trace/adapters/adapter-registry.d.ts.map +1 -0
  213. package/dist/trace/adapters/trace-adapter.d.ts +21 -0
  214. package/dist/trace/adapters/trace-adapter.d.ts.map +1 -0
  215. package/dist/trace/adapters/unknown-adapter.d.ts +10 -0
  216. package/dist/trace/adapters/unknown-adapter.d.ts.map +1 -0
  217. package/dist/trace/adapters/v10-adapter.d.ts +10 -0
  218. package/dist/trace/adapters/v10-adapter.d.ts.map +1 -0
  219. package/dist/trace/adapters/v4-adapter.d.ts +11 -0
  220. package/dist/trace/adapters/v4-adapter.d.ts.map +1 -0
  221. package/dist/trace/adapters/v8-adapter.d.ts +10 -0
  222. package/dist/trace/adapters/v8-adapter.d.ts.map +1 -0
  223. package/dist/trace/adapters/v9-adapter.d.ts +10 -0
  224. package/dist/trace/adapters/v9-adapter.d.ts.map +1 -0
  225. package/dist/trace/archive-reader.d.ts +44 -0
  226. package/dist/trace/archive-reader.d.ts.map +1 -0
  227. package/dist/trace/snapshot-resolver.d.ts +55 -0
  228. package/dist/trace/snapshot-resolver.d.ts.map +1 -0
  229. package/dist/trace/trace-parser.d.ts +50 -0
  230. package/dist/trace/trace-parser.d.ts.map +1 -0
  231. package/dist/trace/version-detector.d.ts +20 -0
  232. package/dist/trace/version-detector.d.ts.map +1 -0
  233. package/package.json +76 -6
  234. package/skills/README.md +20 -0
  235. package/skills/pie-failure-investigation/SKILL.md +16 -0
  236. package/skills/pie-quality-engineer/SKILL.md +66 -0
  237. package/skills/pie-release-readiness/SKILL.md +22 -0
  238. package/skills/pie-repair-review/SKILL.md +21 -0
  239. package/skills/pie-trace-to-repair/SKILL.md +35 -0
  240. package/src/authoring/author.ts +81 -0
  241. package/src/authoring/generation-contract.ts +283 -0
  242. package/src/authoring/hybrid-author.ts +115 -0
  243. package/src/authoring/index.ts +7 -0
  244. package/src/authoring/llm-author.ts +282 -0
  245. package/src/authoring/naming/index.ts +4 -0
  246. package/src/authoring/naming/name-plan.ts +28 -0
  247. package/src/authoring/naming/name-planner.ts +339 -0
  248. package/src/authoring/naming/naming-linter.ts +292 -0
  249. package/src/authoring/template-author.ts +39 -0
  250. package/src/cli/index.ts +1172 -0
  251. package/src/collectors/collector-interface.ts +8 -0
  252. package/src/collectors/environment-collector.ts +103 -0
  253. package/src/collectors/error-collector.ts +177 -0
  254. package/src/collectors/git-diff-collector.ts +190 -0
  255. package/src/collectors/live-browser-collector.ts +412 -0
  256. package/src/collectors/network-collector.ts +90 -0
  257. package/src/collectors/static-ast-collector.ts +226 -0
  258. package/src/collectors/trace-collector.ts +66 -0
  259. package/src/config/project-config.ts +114 -0
  260. package/src/core/errors/engine-errors.ts +90 -0
  261. package/src/core/types/diagnostic-context.ts +94 -0
  262. package/src/core/types/repair-evidence.ts +45 -0
  263. package/src/core/version.ts +25 -0
  264. package/src/diagnostics/diagnostic-contract.ts +79 -0
  265. package/src/diagnostics/diagnostic-report.ts +204 -0
  266. package/src/diagnostics/evidence-correlator.ts +117 -0
  267. package/src/diagnostics/external-failure-evidence.ts +72 -0
  268. package/src/diagnostics/failure-category.ts +40 -0
  269. package/src/diagnostics/failure-classifier.ts +701 -0
  270. package/src/evaluation/evaluation-scorecard.ts +198 -0
  271. package/src/evaluation/repository-inspector.ts +143 -0
  272. package/src/evaluation/repository-runner.ts +197 -0
  273. package/src/evidence/evidence-model.ts +76 -0
  274. package/src/evidence/evidence-normalizer.ts +322 -0
  275. package/src/evidence/evidence-redactor.ts +218 -0
  276. package/src/framework/config-adapter.ts +131 -0
  277. package/src/gate/index.ts +43 -0
  278. package/src/gate/oracle.ts +69 -0
  279. package/src/gate/quality.ts +101 -0
  280. package/src/gate/safety.ts +94 -0
  281. package/src/generator/architecture-generator.ts +582 -0
  282. package/src/generator/assertion-quality-gate.ts +88 -0
  283. package/src/generator/candidate-writer.ts +288 -0
  284. package/src/generator/test-generator.ts +52 -0
  285. package/src/governance/audit-log.ts +115 -0
  286. package/src/governance/governance-policy.ts +72 -0
  287. package/src/governance/team-dashboard.ts +189 -0
  288. package/src/governance/workflow-audit.ts +72 -0
  289. package/src/index.ts +107 -0
  290. package/src/integrations/ci-summary.ts +37 -0
  291. package/src/integrations/playwright-report-adapter.ts +173 -0
  292. package/src/integrations/quality-gate.ts +95 -0
  293. package/src/integrations/sarif-report.ts +110 -0
  294. package/src/intelligence/autonomous-repair-workflow.ts +139 -0
  295. package/src/intelligence/business-intent.ts +163 -0
  296. package/src/intelligence/evidence-bundle.ts +300 -0
  297. package/src/intelligence/failure-clustering.ts +134 -0
  298. package/src/intelligence/generation-agent.ts +561 -0
  299. package/src/intelligence/generation-verifier.ts +1115 -0
  300. package/src/intelligence/llm-proposal.ts +519 -0
  301. package/src/intelligence/locator-disambiguation-engine.ts +331 -0
  302. package/src/intelligence/model-contract.ts +205 -0
  303. package/src/intelligence/model-provider.ts +348 -0
  304. package/src/intelligence/project-intelligence.ts +140 -0
  305. package/src/intelligence/repair-agent.ts +297 -0
  306. package/src/intelligence/repository-profile.ts +796 -0
  307. package/src/intelligence/suite-intelligence.ts +305 -0
  308. package/src/intelligence/test-intelligence.ts +136 -0
  309. package/src/intelligence/trace-proposal-workflow.ts +318 -0
  310. package/src/intelligence/verified-llm-repair-workflow.ts +48 -0
  311. package/src/intelligence/workflow-planner.ts +966 -0
  312. package/src/mcp/server.ts +970 -0
  313. package/src/memory/stability-ledger.ts +243 -0
  314. package/src/perception/app-model.ts +32 -0
  315. package/src/perception/crawler.ts +263 -0
  316. package/src/perception/index.ts +3 -0
  317. package/src/repair/approval-service.ts +541 -0
  318. package/src/repair/assertion-hasher.ts +386 -0
  319. package/src/repair/ast-patcher.ts +223 -0
  320. package/src/repair/browser-operation-executor.ts +263 -0
  321. package/src/repair/diff-allowlist.ts +612 -0
  322. package/src/repair/intent-validator.ts +761 -0
  323. package/src/repair/repair-operations.ts +65 -0
  324. package/src/repair/repair-planner.ts +467 -0
  325. package/src/repair/repair-workflow.ts +241 -0
  326. package/src/repair/safe-operation-compiler.ts +68 -0
  327. package/src/repair/source-mapper.ts +156 -0
  328. package/src/repair/statement-patcher.ts +544 -0
  329. package/src/repair/verification-gates.ts +46 -0
  330. package/src/repair/workflow-plan.ts +59 -0
  331. package/src/repair/workspace-promoter.ts +313 -0
  332. package/src/reproduce/diagnostic-rerunner.ts +287 -0
  333. package/src/reproduce/direct-browser-investigator.ts +208 -0
  334. package/src/reproduce/interactive-workflow-runner.ts +828 -0
  335. package/src/sandbox/dependency-strategy.ts +215 -0
  336. package/src/sandbox/execution-runner.ts +408 -0
  337. package/src/sandbox/worktree-manager.ts +287 -0
  338. package/src/selector/abstention-policy.ts +175 -0
  339. package/src/selector/candidate-extractor.ts +343 -0
  340. package/src/selector/live-locator-verifier.ts +139 -0
  341. package/src/selector/repair-candidate-ranker.ts +92 -0
  342. package/src/selector/selector-scorer.ts +344 -0
  343. package/src/trace/adapters/adapter-registry.ts +49 -0
  344. package/src/trace/adapters/trace-adapter.ts +28 -0
  345. package/src/trace/adapters/unknown-adapter.ts +50 -0
  346. package/src/trace/adapters/v10-adapter.ts +39 -0
  347. package/src/trace/adapters/v4-adapter.ts +31 -0
  348. package/src/trace/adapters/v8-adapter.ts +42 -0
  349. package/src/trace/adapters/v9-adapter.ts +39 -0
  350. package/src/trace/archive-reader.ts +246 -0
  351. package/src/trace/snapshot-resolver.ts +308 -0
  352. package/src/trace/trace-parser.ts +467 -0
  353. package/src/trace/version-detector.ts +81 -0
@@ -0,0 +1,282 @@
1
+ import { Project } from 'ts-morph';
2
+ import {
3
+ Author,
4
+ AuthorInput,
5
+ CandidateChange,
6
+ FullCodeGenerationInput,
7
+ FullCodeGenerationProvider,
8
+ } from './author.js';
9
+ import { HybridAuthor } from './hybrid-author.js';
10
+ import {
11
+ buildTierL2SystemPrompt,
12
+ FullGenerationProposal,
13
+ normalizeProposalPath,
14
+ validateFullGenerationProposal,
15
+ } from './generation-contract.js';
16
+ import type { NamePlan, SymbolEntry } from './naming/name-plan.js';
17
+ import { NamePlanner } from './naming/name-planner.js';
18
+ import { toClassName, toSlug } from '../generator/architecture-generator.js';
19
+
20
+ export interface OpenAiCompatibleFullCodeProviderOptions {
21
+ endpoint: string;
22
+ model: string;
23
+ apiKey?: string | undefined;
24
+ timeoutMs?: number | undefined;
25
+ fetchImpl?: typeof fetch | undefined;
26
+ }
27
+
28
+ /**
29
+ * Provider-neutral Tier-L2 full-code Playwright generation transport.
30
+ */
31
+ export class OpenAiCompatibleFullCodeProvider implements FullCodeGenerationProvider {
32
+ public constructor(private readonly options: OpenAiCompatibleFullCodeProviderOptions) {}
33
+
34
+ public async generate(input: FullCodeGenerationInput): Promise<unknown> {
35
+ const controller = new AbortController();
36
+ const timeout = setTimeout(() => controller.abort(), this.options.timeoutMs ?? 90_000);
37
+ try {
38
+ const response = await (this.options.fetchImpl ?? fetch)(this.options.endpoint, {
39
+ method: 'POST',
40
+ signal: controller.signal,
41
+ headers: {
42
+ 'content-type': 'application/json',
43
+ ...(this.options.apiKey ? { authorization: `Bearer ${this.options.apiKey}` } : {}),
44
+ },
45
+ body: JSON.stringify({
46
+ model: this.options.model,
47
+ temperature: 0.1,
48
+ response_format: { type: 'json_object' },
49
+ messages: [
50
+ { role: 'system', content: buildTierL2SystemPrompt() },
51
+ { role: 'user', content: JSON.stringify(input) },
52
+ ],
53
+ }),
54
+ });
55
+ if (!response.ok) {
56
+ throw new Error(`Tier-L2 generation model endpoint returned HTTP ${response.status}`);
57
+ }
58
+ const payload = (await response.json()) as {
59
+ choices?: Array<{ message?: { content?: string | Array<{ text?: string }> | null } }>;
60
+ output_text?: string;
61
+ };
62
+ const content =
63
+ payload.output_text ??
64
+ (typeof payload.choices?.[0]?.message?.content === 'string'
65
+ ? payload.choices[0].message.content
66
+ : payload.choices?.[0]?.message?.content?.map((part) => part.text ?? '').join(''));
67
+ if (!content) {
68
+ throw new Error('Tier-L2 generation model returned empty content');
69
+ }
70
+ return content;
71
+ } finally {
72
+ clearTimeout(timeout);
73
+ }
74
+ }
75
+ }
76
+
77
+ export function configuredFullCodeProvider(): FullCodeGenerationProvider | undefined {
78
+ const liveAllowed = !process.env.VITEST || process.env.PIE_LIVE_LLM_TESTS === '1';
79
+ if (!liveAllowed) return undefined;
80
+ const apiKey = process.env.PIE_LLM_API_KEY ?? process.env.OPENAI_API_KEY ?? process.env.DEEPSEEK_API_KEY;
81
+ const endpoint = process.env.PIE_LLM_ENDPOINT ?? (process.env.OPENAI_API_KEY ? 'https://api.openai.com/v1/chat/completions' : (apiKey ? 'https://api.deepseek.com/chat/completions' : undefined));
82
+ const model = process.env.PIE_LLM_MODEL ?? (process.env.OPENAI_API_KEY ? 'gpt-4o' : (apiKey ? 'deepseek-chat' : undefined));
83
+ if (!endpoint || !model) return undefined;
84
+ return new OpenAiCompatibleFullCodeProvider({
85
+ endpoint,
86
+ model,
87
+ ...(apiKey ? { apiKey } : {}),
88
+ });
89
+ }
90
+
91
+ function inferRoleSuffix(propertyName: string): string {
92
+ const lower = propertyName.toLowerCase();
93
+ if (lower.includes('input') || lower.includes('field')) return 'textbox';
94
+ if (lower.includes('button') || lower.includes('btn')) return 'button';
95
+ if (lower.includes('checkbox')) return 'checkbox';
96
+ if (lower.includes('select')) return 'combobox';
97
+ return 'locator';
98
+ }
99
+
100
+ function extractNamePlanFromGeneratedFiles(featureName: string, proposal: FullGenerationProposal): NamePlan {
101
+ const rawBase = toClassName(featureName);
102
+ let pageClassName = rawBase.endsWith('Page') ? rawBase : `${rawBase}Page`;
103
+ const symbols: SymbolEntry[] = [];
104
+
105
+ try {
106
+ const project = new Project({ useInMemoryFileSystem: true });
107
+ for (const file of proposal.files) {
108
+ if (!/\.tsx?$/i.test(file.path)) continue;
109
+ const sf = project.createSourceFile(file.path, file.content, { overwrite: true });
110
+ const classes = sf.getClasses();
111
+ const pageClass = classes.find((c) => c.getName()?.endsWith('Page')) ?? classes[0];
112
+ if (!pageClass) continue;
113
+ const clsName = pageClass.getName();
114
+ if (clsName) {
115
+ pageClassName = clsName.endsWith('Page') ? clsName : `${clsName}Page`;
116
+ }
117
+ const props = pageClass
118
+ .getProperties()
119
+ .map((p) => p.getName())
120
+ .filter((p) => p !== 'page');
121
+ const methods = pageClass.getMethods().filter((m) => m.getName() !== 'goto');
122
+ const usedPropNames = new Set<string>();
123
+
124
+ for (let i = 0; i < methods.length; i += 1) {
125
+ const methodDecl = methods[i]!;
126
+ const method = methodDecl.getName();
127
+ const bodyText = methodDecl.getBodyText() ?? '';
128
+ const matchedProp = props.find((p) => !usedPropNames.has(p) && new RegExp(`\\bthis\\.${p}\\b`).test(bodyText));
129
+ const property = matchedProp ?? `${method}Locator`;
130
+ usedPropNames.add(property);
131
+ const verbMatch = method.match(/^([a-z]+)/);
132
+ symbols.push({
133
+ ref: `ast-${i + 1}`,
134
+ role: inferRoleSuffix(property),
135
+ property,
136
+ method,
137
+ verb: verbMatch?.[1] ?? 'click',
138
+ confidence: 0.9,
139
+ source: 'llm',
140
+ assumptions: [],
141
+ });
142
+ }
143
+ if (symbols.length > 0) break;
144
+ }
145
+ } catch {
146
+ // Fallback below if AST extraction fails
147
+ }
148
+
149
+ const pageVariable = pageClassName[0]!.toLowerCase() + pageClassName.slice(1);
150
+ return {
151
+ planVersion: '1',
152
+ pageClassName,
153
+ pageVariable,
154
+ symbols,
155
+ assumptions: proposal.assumptions.map((a) => a.description),
156
+ };
157
+ }
158
+
159
+ export interface LlmAuthorOptions {
160
+ provider?: FullCodeGenerationProvider | undefined;
161
+ }
162
+
163
+ export class LlmAuthor implements Author {
164
+ public readonly kind = 'llm';
165
+ private readonly hybridFallback = new HybridAuthor();
166
+
167
+ public constructor(private readonly options: LlmAuthorOptions = {}) {}
168
+
169
+ public async propose(input: AuthorInput): Promise<CandidateChange> {
170
+ const provider = input.fullCodeProvider ?? this.options.provider ?? configuredFullCodeProvider();
171
+ if (!provider) {
172
+ const hybridChange = await this.hybridFallback.propose(input);
173
+ return {
174
+ ...hybridChange,
175
+ authorKind: 'llm',
176
+ fullCodeAuthoring: false,
177
+ usedFallback: true,
178
+ status: 'GENERATE',
179
+ rationale: 'No Tier-L2 full-code provider configured; fell back to deterministic HybridAuthor.',
180
+ };
181
+ }
182
+
183
+ const generationInput: FullCodeGenerationInput = {
184
+ featureName: input.featureName,
185
+ mode: input.mode,
186
+ baseUrl: input.baseUrl,
187
+ requirements: input.requirements,
188
+ steps: input.steps,
189
+ profile: input.profile,
190
+ existingFiles: input.existingFiles,
191
+ exemplars: input.exemplars,
192
+ contextPacket: input.contextPacket,
193
+ workflowPlan: input.workflowPlan,
194
+ explorationBundle: input.explorationBundle,
195
+ scenarios: input.scenarios,
196
+ existingFileSnapshots: input.existingFileSnapshots,
197
+ allowedEvidenceIds: input.allowedEvidenceIds,
198
+ feedback: input.feedback,
199
+ };
200
+
201
+ let rawProposal: unknown;
202
+ try {
203
+ rawProposal = await provider.generate(generationInput);
204
+ } catch (error) {
205
+ const hybridChange = await this.hybridFallback.propose(input);
206
+ return {
207
+ ...hybridChange,
208
+ authorKind: 'llm',
209
+ fullCodeAuthoring: false,
210
+ usedFallback: true,
211
+ status: 'GENERATE',
212
+ validationErrors: [`Tier-L2 provider failed (${error instanceof Error ? error.message : String(error)}); fell back to HybridAuthor.`],
213
+ rationale: `Tier-L2 provider unavailable; fell back to HybridAuthor (${error instanceof Error ? error.message : String(error)}).`,
214
+ };
215
+ }
216
+
217
+ const validation = validateFullGenerationProposal(rawProposal, {
218
+ allowedEvidenceIds: input.allowedEvidenceIds ? new Set(input.allowedEvidenceIds) : undefined,
219
+ existingFiles: input.existingFiles ? new Set(input.existingFiles) : undefined,
220
+ requireEvidenceReferences: input.requireEvidenceReferences,
221
+ });
222
+
223
+ if (!validation.isValid || !validation.proposal) {
224
+ return {
225
+ files: [],
226
+ symbols: NamePlanner.planNames(input.featureName, input.steps ?? [], { source: 'llm' }),
227
+ rationale: `Tier-L2 proposal rejected by contract validation: ${validation.errors.join('; ')}`,
228
+ authorKind: 'llm',
229
+ featureName: input.featureName,
230
+ slug: toSlug(input.featureName),
231
+ mode: input.mode,
232
+ status: 'ABSTAIN',
233
+ fullCodeAuthoring: true,
234
+ usedFallback: false,
235
+ validationErrors: validation.errors,
236
+ };
237
+ }
238
+
239
+ const proposal = validation.proposal;
240
+ if (proposal.status !== 'GENERATE') {
241
+ return {
242
+ files: [],
243
+ symbols: NamePlanner.planNames(input.featureName, input.steps ?? [], { source: 'llm' }),
244
+ rationale: proposal.summary,
245
+ authorKind: 'llm',
246
+ featureName: input.featureName,
247
+ slug: toSlug(input.featureName),
248
+ mode: input.mode,
249
+ status: proposal.status,
250
+ fullCodeAuthoring: true,
251
+ usedFallback: false,
252
+ proposal,
253
+ assumptions: proposal.assumptions.map((a) => a.description),
254
+ requiredClarifications: proposal.requiredClarifications,
255
+ };
256
+ }
257
+
258
+ const symbols = extractNamePlanFromGeneratedFiles(input.featureName, proposal);
259
+ return {
260
+ files: proposal.files.map((f) => ({
261
+ relativePath: normalizeProposalPath(f.path),
262
+ content: f.content,
263
+ purpose: f.rationale,
264
+ action: f.action === 'modify' ? 'MODIFY' : 'CREATE',
265
+ rationale: f.rationale,
266
+ evidenceReferences: f.evidenceReferences,
267
+ scenarioIds: f.scenarioIds,
268
+ })),
269
+ symbols,
270
+ rationale: proposal.summary,
271
+ authorKind: 'llm',
272
+ featureName: input.featureName,
273
+ slug: toSlug(input.featureName),
274
+ mode: input.mode,
275
+ status: 'GENERATE',
276
+ fullCodeAuthoring: true,
277
+ usedFallback: false,
278
+ proposal,
279
+ assumptions: proposal.assumptions.map((a) => a.description),
280
+ };
281
+ }
282
+ }
@@ -0,0 +1,4 @@
1
+ export * from './name-plan.js';
2
+ export * from './name-planner.js';
3
+ export * from './naming-linter.js';
4
+
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+
3
+ export const SymbolSourceSchema = z.enum(['llm', 'heuristic']);
4
+ export type SymbolSource = z.infer<typeof SymbolSourceSchema>;
5
+
6
+ export const SymbolEntrySchema = z.object({
7
+ ref: z.string().min(1),
8
+ role: z.string().optional(),
9
+ accessibleName: z.string().optional(),
10
+ property: z.string().min(1),
11
+ method: z.string().min(1),
12
+ verb: z.string().min(1),
13
+ confidence: z.number().min(0).max(1),
14
+ source: SymbolSourceSchema,
15
+ assumptions: z.array(z.string()).default([]),
16
+ frame: z.string().optional(),
17
+ });
18
+ export type SymbolEntry = z.infer<typeof SymbolEntrySchema>;
19
+
20
+ export const NamePlanSchema = z.object({
21
+ planVersion: z.literal('1').default('1'),
22
+ pageClassName: z.string().min(1),
23
+ pageVariable: z.string().min(1),
24
+ symbols: z.array(SymbolEntrySchema),
25
+ assumptions: z.array(z.string()).default([]),
26
+ });
27
+ export type NamePlan = z.infer<typeof NamePlanSchema>;
28
+
@@ -0,0 +1,339 @@
1
+ import type { GeneratedStep } from '../../generator/test-generator.js';
2
+ import type { NamePlan, SymbolEntry } from './name-plan.js';
3
+
4
+ const RESERVED_WORDS = new Set([
5
+ 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
6
+ 'else', 'export', 'extends', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
7
+ 'new', 'return', 'super', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while',
8
+ 'with', 'yield', 'enum', 'implements', 'interface', 'let', 'package', 'private', 'protected',
9
+ 'public', 'static', 'await', 'abstract', 'boolean', 'byte', 'char', 'double', 'final', 'float',
10
+ 'goto', 'int', 'long', 'native', 'short', 'synchronized', 'throws', 'transient', 'volatile',
11
+ 'page', 'constructor', 'click', 'fill', 'expect', 'locator', 'waitFor', 'reload', 'close',
12
+ ]);
13
+
14
+ const ROLE_SUFFIXES: Record<string, string> = {
15
+ button: 'Button',
16
+ textbox: 'Input',
17
+ input: 'Input',
18
+ searchbox: 'SearchInput',
19
+ link: 'Link',
20
+ checkbox: 'Checkbox',
21
+ combobox: 'Select',
22
+ listbox: 'Select',
23
+ select: 'Select',
24
+ cell: 'Cell',
25
+ heading: 'Heading',
26
+ dialog: 'Dialog',
27
+ status: 'Status',
28
+ tab: 'Tab',
29
+ radio: 'Radio',
30
+ };
31
+
32
+ const ARTICLES = new Set(['a', 'an', 'the']);
33
+
34
+ export function stripArticles(text: string): string {
35
+ const words = text.trim().split(/\s+/);
36
+ const filtered = words.filter((w) => !ARTICLES.has(w.toLowerCase()));
37
+ return filtered.length > 0 ? filtered.join(' ') : text.trim();
38
+ }
39
+
40
+ export function toPascalCase(text: string): string {
41
+ const words = text
42
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
43
+ .match(/[A-Za-z0-9]+/g);
44
+ if (!words || words.length === 0) return 'Element';
45
+ return words.map((w) => w[0]!.toUpperCase() + w.slice(1).toLowerCase()).join('');
46
+ }
47
+
48
+ export function toCamelCase(text: string): string {
49
+ const pascal = toPascalCase(text);
50
+ if (!pascal) return 'element';
51
+ return pascal[0]!.toLowerCase() + pascal.slice(1);
52
+ }
53
+
54
+ export function sanitizeIdentifier(identifier: string, suffixFallback = 'Element'): string {
55
+ let cleaned = identifier.replace(/[^a-zA-Z0-9_$]/g, '');
56
+ if (!cleaned || /^[0-9]/.test(cleaned)) {
57
+ cleaned = `${suffixFallback.toLowerCase()}${cleaned}`;
58
+ }
59
+ if (RESERVED_WORDS.has(cleaned.toLowerCase())) {
60
+ cleaned = `${cleaned}${suffixFallback}`;
61
+ }
62
+ return cleaned;
63
+ }
64
+
65
+ export function extractPageName(featureOrTitle: string): { className: string; variable: string } {
66
+ const lower = featureOrTitle.toLowerCase();
67
+ let canonicalName: string | undefined;
68
+
69
+ if (/\b(login|log\s*in|sign\s*in|auth|authenticate)\b/i.test(lower)) {
70
+ canonicalName = 'LoginPage';
71
+ } else if (/\b(register|sign\s*up|registration|signup)\b/i.test(lower)) {
72
+ canonicalName = 'RegisterPage';
73
+ } else if (/\b(checkout|pay|payment)\b/i.test(lower)) {
74
+ canonicalName = 'CheckoutPage';
75
+ } else if (/\b(cart|basket)\b/i.test(lower)) {
76
+ canonicalName = 'CartPage';
77
+ } else if (/\b(dashboard|home)\b/i.test(lower)) {
78
+ canonicalName = 'DashboardPage';
79
+ } else if (/\b(profile|account|setting)\b/i.test(lower)) {
80
+ canonicalName = 'ProfilePage';
81
+ } else if (/\b(product|catalog|search)\b/i.test(lower)) {
82
+ canonicalName = 'ProductsPage';
83
+ } else if (/\b(admin)\b/i.test(lower)) {
84
+ canonicalName = 'AdminPage';
85
+ }
86
+
87
+ if (canonicalName) {
88
+ const variable = canonicalName[0]!.toLowerCase() + canonicalName.slice(1);
89
+ return { className: canonicalName, variable };
90
+ }
91
+
92
+ // Strip common testing / scenario noise
93
+ let cleaned = featureOrTitle
94
+ .replace(/\b(should|complete|workflow|flow|spec|test|sanity|suite|journey|scenario)\b/gi, '')
95
+ .replace(/\b(with|for|and|using|valid|invalid|empty|wrong|credentials)\b/gi, '')
96
+ .replace(/\b(user|admin|customer|client)\b/gi, '')
97
+ .trim();
98
+
99
+ // If stripping left empty or too short, revert to original
100
+ if (!cleaned || cleaned.length < 3) {
101
+ cleaned = featureOrTitle;
102
+ }
103
+
104
+ const words = cleaned
105
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
106
+ .match(/[A-Za-z0-9]+/g) ?? ['Feature'];
107
+ // Keep meaningful domain words up to 3 words
108
+ const domainWords = words.slice(0, 3);
109
+ let baseName = domainWords.map((w) => w[0]!.toUpperCase() + w.slice(1).toLowerCase()).join('');
110
+
111
+ if (!baseName.endsWith('Page')) {
112
+ baseName = `${baseName}Page`;
113
+ }
114
+
115
+ const className = sanitizeIdentifier(baseName, 'Page');
116
+ const variable = className[0]!.toLowerCase() + className.slice(1);
117
+ return { className, variable };
118
+ }
119
+
120
+ export function derivePropertyIdentifier(step: GeneratedStep, roleSuffix: string): { property: string; isFallback: boolean } {
121
+ const rawName = step.name ?? step.placeholder ?? step.selector;
122
+ if (rawName) {
123
+ const stripped = stripArticles(rawName);
124
+ const words = stripped
125
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
126
+ .match(/[A-Za-z0-9]+/g);
127
+ if (words && words.length > 0) {
128
+ const base = toCamelCase(stripped);
129
+ const lowerBase = base.toLowerCase();
130
+ const lowerSuffix = roleSuffix.toLowerCase();
131
+ let property = base;
132
+ if (!lowerBase.endsWith(lowerSuffix)) {
133
+ if (lowerSuffix === 'searchinput' && lowerBase.endsWith('search')) {
134
+ property = `${base}Input`;
135
+ } else {
136
+ property = `${base}${roleSuffix}`;
137
+ }
138
+ }
139
+ return { property: sanitizeIdentifier(property, roleSuffix), isFallback: false };
140
+ }
141
+ }
142
+
143
+ // Fallback when no semantic name exists
144
+ const role = step.role ?? (step.action === 'fill' ? 'textbox' : 'button');
145
+ const roleBase = toCamelCase(role);
146
+ let fallbackBase = roleBase;
147
+ if (roleBase.toLowerCase() === roleSuffix.toLowerCase()) {
148
+ fallbackBase = role === 'button' ? 'action' : 'input';
149
+ }
150
+ const fallback = sanitizeIdentifier(`${fallbackBase}${roleSuffix}`, roleSuffix);
151
+ return { property: fallback, isFallback: true };
152
+ }
153
+
154
+ export function deriveMethodIdentifier(step: GeneratedStep, propertyName: string): { method: string; verb: string } {
155
+ const rawName = step.name ?? step.placeholder ?? step.selector;
156
+ const stripped = rawName ? stripArticles(rawName) : '';
157
+ const pascalTarget = stripped ? toPascalCase(stripped) : toPascalCase(propertyName);
158
+
159
+ const formatWithVerb = (verb: string, target: string): string => {
160
+ const lowerVerb = verb.toLowerCase();
161
+ const lowerTarget = target.toLowerCase();
162
+ if (lowerTarget.startsWith(lowerVerb)) {
163
+ const remainder = target.slice(verb.length);
164
+ return sanitizeIdentifier(remainder.length > 0 ? `${verb}${remainder}` : verb, 'Action');
165
+ }
166
+ return sanitizeIdentifier(`${verb}${target}`, 'Action');
167
+ };
168
+
169
+ if (step.action === 'press') {
170
+ return {
171
+ method: formatWithVerb('press', pascalTarget || 'Key'),
172
+ verb: 'press',
173
+ };
174
+ }
175
+
176
+ if (step.action === 'fill') {
177
+ return {
178
+ method: formatWithVerb('fill', pascalTarget),
179
+ verb: 'fill',
180
+ };
181
+ }
182
+
183
+ if (step.action === 'click') {
184
+ const lower = (rawName ?? '').toLowerCase();
185
+ const roleLower = (step.role ?? '').toLowerCase();
186
+ if (roleLower === 'link' || roleLower === 'tab' || /\b(open|goto|go\s*to|home|back|nav|view|plans|settings)\b/.test(lower)) {
187
+ return { method: formatWithVerb('open', pascalTarget), verb: 'open' };
188
+ }
189
+ if (/\b(sign\s*in|log\s*in|login|signin)\b/.test(lower)) {
190
+ return { method: sanitizeIdentifier('signIn', 'Action'), verb: 'signIn' };
191
+ }
192
+ if (/\b(sign\s*up|register)\b/.test(lower)) {
193
+ return { method: sanitizeIdentifier('signUp', 'Action'), verb: 'signUp' };
194
+ }
195
+ if (/\b(submit|send|confirm|save|apply|checkout)\b/.test(lower)) {
196
+ return { method: formatWithVerb('submit', pascalTarget), verb: 'submit' };
197
+ }
198
+ return {
199
+ method: formatWithVerb('click', pascalTarget),
200
+ verb: 'click',
201
+ };
202
+ }
203
+
204
+ if (step.action === 'assert-visible') {
205
+ return {
206
+ method: sanitizeIdentifier(`expect${pascalTarget}Visible`, 'Action'),
207
+ verb: 'expectVisible',
208
+ };
209
+ }
210
+
211
+ if (step.action === 'assert-text') {
212
+ return {
213
+ method: sanitizeIdentifier(`expect${pascalTarget}Text`, 'Action'),
214
+ verb: 'expectText',
215
+ };
216
+ }
217
+
218
+ if (step.action === 'assert-count') {
219
+ return {
220
+ method: sanitizeIdentifier(`expect${pascalTarget}Count`, 'Action'),
221
+ verb: 'expectCount',
222
+ };
223
+ }
224
+
225
+ if (step.action === 'assert-value') {
226
+ return {
227
+ method: sanitizeIdentifier(`expect${pascalTarget}Value`, 'Action'),
228
+ verb: 'expectValue',
229
+ };
230
+ }
231
+
232
+ return {
233
+ method: sanitizeIdentifier(`perform${pascalTarget}`, 'Action'),
234
+ verb: 'perform',
235
+ };
236
+ }
237
+
238
+ export class NamePlanner {
239
+ public static planNames(
240
+ featureOrTitle: string,
241
+ steps: GeneratedStep[],
242
+ options?: { existingPageClassName?: string; source?: 'llm' | 'heuristic' }
243
+ ): NamePlan {
244
+ const assumptions: string[] = [];
245
+ const source = options?.source ?? 'heuristic';
246
+ const page = options?.existingPageClassName
247
+ ? { className: options.existingPageClassName, variable: options.existingPageClassName[0]!.toLowerCase() + options.existingPageClassName.slice(1) }
248
+ : extractPageName(featureOrTitle);
249
+
250
+ const symbols: SymbolEntry[] = [];
251
+ const usedProperties = new Set<string>();
252
+ const usedMethods = new Set<string>();
253
+
254
+ const disambiguationQualifiers = ['primary', 'secondary', 'confirm', 'alternate', 'detail', 'modal', 'auxiliary'];
255
+
256
+ steps.forEach((step, idx) => {
257
+ const ref = `step-${idx + 1}`;
258
+ // Grounding rule: a step with no accessible name AND no selector has no
259
+ // DOM identity. Never invent a symbol for it (a navigate step must not
260
+ // silently become a synthetic "button").
261
+ if (!step.name && !step.selector) {
262
+ if (step.action !== 'navigate') {
263
+ assumptions.push(`Step ${ref} (${step.action}) has no accessible name or selector and was skipped as ungrounded.`);
264
+ }
265
+ return;
266
+ }
267
+ const role = step.role ?? (step.action === 'fill' ? 'textbox' : step.action === 'click' ? 'button' : undefined);
268
+ const roleSuffix = ROLE_SUFFIXES[role?.toLowerCase() ?? ''] ?? (step.action === 'fill' ? 'Input' : 'Button');
269
+
270
+ const propResult = derivePropertyIdentifier(step, roleSuffix);
271
+ let property = propResult.property;
272
+
273
+ if (propResult.isFallback) {
274
+ assumptions.push(`Step ${ref} has no accessible name; generated generic semantic property '${property}'`);
275
+ }
276
+
277
+ // Disambiguate property collisions using semantic qualifiers, NEVER by bare index numbers
278
+ if (usedProperties.has(property)) {
279
+ let disambiguated = false;
280
+ for (const qualifier of disambiguationQualifiers) {
281
+ const candidate = `${qualifier}${property[0]!.toUpperCase()}${property.slice(1)}`;
282
+ if (!usedProperties.has(candidate)) {
283
+ assumptions.push(`Property name collision for '${property}'; disambiguated to '${candidate}'`);
284
+ property = candidate;
285
+ disambiguated = true;
286
+ break;
287
+ }
288
+ }
289
+ if (!disambiguated) {
290
+ property = `${property}Alt`;
291
+ }
292
+ }
293
+ usedProperties.add(property);
294
+
295
+ const methodResult = deriveMethodIdentifier(step, property);
296
+ let method = methodResult.method;
297
+
298
+ // Disambiguate method collisions
299
+ if (usedMethods.has(method)) {
300
+ let disambiguated = false;
301
+ for (const qualifier of disambiguationQualifiers) {
302
+ const candidate = `${methodResult.verb}${qualifier[0]!.toUpperCase()}${qualifier.slice(1)}`;
303
+ if (!usedMethods.has(candidate)) {
304
+ assumptions.push(`Method name collision for '${method}'; disambiguated to '${candidate}'`);
305
+ method = candidate;
306
+ disambiguated = true;
307
+ break;
308
+ }
309
+ }
310
+ if (!disambiguated) {
311
+ method = `${method}Alt`;
312
+ }
313
+ }
314
+ usedMethods.add(method);
315
+
316
+ const frame = step.frame ?? step.frameSelector;
317
+ symbols.push({
318
+ ref,
319
+ role: step.role,
320
+ accessibleName: step.name,
321
+ property,
322
+ method,
323
+ verb: methodResult.verb,
324
+ confidence: propResult.isFallback ? 0.75 : 0.95,
325
+ source,
326
+ assumptions: [],
327
+ ...(frame ? { frame } : {}),
328
+ });
329
+ });
330
+
331
+ return {
332
+ planVersion: '1',
333
+ pageClassName: page.className,
334
+ pageVariable: page.variable,
335
+ symbols,
336
+ assumptions,
337
+ };
338
+ }
339
+ }