simplify3x-connect 0.0.0-stage → 0.28.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.
- package/LICENSE +21 -0
- package/README.md +117 -3
- package/dist/acText.d.ts +12 -0
- package/dist/acText.d.ts.map +1 -0
- package/dist/acText.js +44 -0
- package/dist/acText.js.map +1 -0
- package/dist/adapters/factory.d.ts +25 -0
- package/dist/adapters/factory.d.ts.map +1 -0
- package/dist/adapters/factory.js +55 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/adapters/http.d.ts +62 -0
- package/dist/adapters/http.d.ts.map +1 -0
- package/dist/adapters/http.js +138 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/remoteMcp/adapter.d.ts +112 -0
- package/dist/adapters/remoteMcp/adapter.d.ts.map +1 -0
- package/dist/adapters/remoteMcp/adapter.js +259 -0
- package/dist/adapters/remoteMcp/adapter.js.map +1 -0
- package/dist/adapters/simplifyqa/adapter.d.ts +1390 -0
- package/dist/adapters/simplifyqa/adapter.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/adapter.js +9126 -0
- package/dist/adapters/simplifyqa/adapter.js.map +1 -0
- package/dist/adapters/simplifyqa/apiFailureReason.d.ts +11 -0
- package/dist/adapters/simplifyqa/apiFailureReason.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/apiFailureReason.js +35 -0
- package/dist/adapters/simplifyqa/apiFailureReason.js.map +1 -0
- package/dist/adapters/simplifyqa/desktopConditions.d.ts +50 -0
- package/dist/adapters/simplifyqa/desktopConditions.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/desktopConditions.js +95 -0
- package/dist/adapters/simplifyqa/desktopConditions.js.map +1 -0
- package/dist/adapters/simplifyqa/executionFailures.d.ts +59 -0
- package/dist/adapters/simplifyqa/executionFailures.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/executionFailures.js +641 -0
- package/dist/adapters/simplifyqa/executionFailures.js.map +1 -0
- package/dist/adapters/simplifyqa/failureCategory.d.ts +26 -0
- package/dist/adapters/simplifyqa/failureCategory.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/failureCategory.js +208 -0
- package/dist/adapters/simplifyqa/failureCategory.js.map +1 -0
- package/dist/adapters/simplifyqa/failureReport.d.ts +50 -0
- package/dist/adapters/simplifyqa/failureReport.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/failureReport.js +383 -0
- package/dist/adapters/simplifyqa/failureReport.js.map +1 -0
- package/dist/adapters/simplifyqa/failureTypes.d.ts +193 -0
- package/dist/adapters/simplifyqa/failureTypes.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/failureTypes.js +8 -0
- package/dist/adapters/simplifyqa/failureTypes.js.map +1 -0
- package/dist/adapters/simplifyqa/flow.d.ts +58 -0
- package/dist/adapters/simplifyqa/flow.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/flow.js +335 -0
- package/dist/adapters/simplifyqa/flow.js.map +1 -0
- package/dist/adapters/simplifyqa/functionMatch.d.ts +53 -0
- package/dist/adapters/simplifyqa/functionMatch.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/functionMatch.js +110 -0
- package/dist/adapters/simplifyqa/functionMatch.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/apply.d.ts +59 -0
- package/dist/adapters/simplifyqa/heal/apply.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/apply.js +213 -0
- package/dist/adapters/simplifyqa/heal/apply.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/diagnose.d.ts +24 -0
- package/dist/adapters/simplifyqa/heal/diagnose.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/diagnose.js +211 -0
- package/dist/adapters/simplifyqa/heal/diagnose.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/index.d.ts +37 -0
- package/dist/adapters/simplifyqa/heal/index.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/index.js +83 -0
- package/dist/adapters/simplifyqa/heal/index.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/plan.d.ts +67 -0
- package/dist/adapters/simplifyqa/heal/plan.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/plan.js +338 -0
- package/dist/adapters/simplifyqa/heal/plan.js.map +1 -0
- package/dist/adapters/simplifyqa/heal/store.d.ts +10 -0
- package/dist/adapters/simplifyqa/heal/store.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/heal/store.js +40 -0
- package/dist/adapters/simplifyqa/heal/store.js.map +1 -0
- package/dist/adapters/simplifyqa/mapLimit.d.ts +3 -0
- package/dist/adapters/simplifyqa/mapLimit.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/mapLimit.js +14 -0
- package/dist/adapters/simplifyqa/mapLimit.js.map +1 -0
- package/dist/adapters/simplifyqa/mapper.d.ts +159 -0
- package/dist/adapters/simplifyqa/mapper.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/mapper.js +1767 -0
- package/dist/adapters/simplifyqa/mapper.js.map +1 -0
- package/dist/adapters/simplifyqa/planTree.d.ts +31 -0
- package/dist/adapters/simplifyqa/planTree.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/planTree.js +110 -0
- package/dist/adapters/simplifyqa/planTree.js.map +1 -0
- package/dist/adapters/simplifyqa/searchEngine.d.ts +254 -0
- package/dist/adapters/simplifyqa/searchEngine.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/searchEngine.js +1248 -0
- package/dist/adapters/simplifyqa/searchEngine.js.map +1 -0
- package/dist/adapters/simplifyqa/searchRegistry.d.ts +117 -0
- package/dist/adapters/simplifyqa/searchRegistry.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/searchRegistry.js +1664 -0
- package/dist/adapters/simplifyqa/searchRegistry.js.map +1 -0
- package/dist/adapters/simplifyqa/searchResolve.d.ts +84 -0
- package/dist/adapters/simplifyqa/searchResolve.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/searchResolve.js +319 -0
- package/dist/adapters/simplifyqa/searchResolve.js.map +1 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.d.ts +25 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.js +89 -0
- package/dist/adapters/simplifyqa/stepDiagnostics.js.map +1 -0
- package/dist/adapters/simplifyqa/stepRules.d.ts +91 -0
- package/dist/adapters/simplifyqa/stepRules.d.ts.map +1 -0
- package/dist/adapters/simplifyqa/stepRules.js +228 -0
- package/dist/adapters/simplifyqa/stepRules.js.map +1 -0
- package/dist/adapters/types.d.ts +514 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/walnut/actionTypes.d.ts +16 -0
- package/dist/adapters/walnut/actionTypes.d.ts.map +1 -0
- package/dist/adapters/walnut/actionTypes.js +178 -0
- package/dist/adapters/walnut/actionTypes.js.map +1 -0
- package/dist/adapters/walnut/adapter.d.ts +235 -0
- package/dist/adapters/walnut/adapter.d.ts.map +1 -0
- package/dist/adapters/walnut/adapter.js +1120 -0
- package/dist/adapters/walnut/adapter.js.map +1 -0
- package/dist/adapters/walnut/mapper.d.ts +55 -0
- package/dist/adapters/walnut/mapper.d.ts.map +1 -0
- package/dist/adapters/walnut/mapper.js +364 -0
- package/dist/adapters/walnut/mapper.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +38 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +109 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +272 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +105 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +255 -0
- package/dist/connection.js.map +1 -0
- package/dist/domain/heal.d.ts +163 -0
- package/dist/domain/heal.d.ts.map +1 -0
- package/dist/domain/heal.js +55 -0
- package/dist/domain/heal.js.map +1 -0
- package/dist/domain/types.d.ts +1328 -0
- package/dist/domain/types.d.ts.map +1 -0
- package/dist/domain/types.js +8 -0
- package/dist/domain/types.js.map +1 -0
- package/dist/domain/validate.d.ts +3 -0
- package/dist/domain/validate.d.ts.map +1 -0
- package/dist/domain/validate.js +67 -0
- package/dist/domain/validate.js.map +1 -0
- package/dist/drafts/apiPatch.d.ts +9 -0
- package/dist/drafts/apiPatch.d.ts.map +1 -0
- package/dist/drafts/apiPatch.js +27 -0
- package/dist/drafts/apiPatch.js.map +1 -0
- package/dist/drafts/bulk.d.ts +24 -0
- package/dist/drafts/bulk.d.ts.map +1 -0
- package/dist/drafts/bulk.js +44 -0
- package/dist/drafts/bulk.js.map +1 -0
- package/dist/drafts/duplicate.d.ts +12 -0
- package/dist/drafts/duplicate.d.ts.map +1 -0
- package/dist/drafts/duplicate.js +59 -0
- package/dist/drafts/duplicate.js.map +1 -0
- package/dist/drafts/store.d.ts +91 -0
- package/dist/drafts/store.d.ts.map +1 -0
- package/dist/drafts/store.js +244 -0
- package/dist/drafts/store.js.map +1 -0
- package/dist/gateway.d.ts +37 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +71 -0
- package/dist/gateway.js.map +1 -0
- package/dist/httpMain.d.ts +3 -0
- package/dist/httpMain.d.ts.map +1 -0
- package/dist/httpMain.js +20 -0
- package/dist/httpMain.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/initAgents.d.ts +2 -0
- package/dist/initAgents.d.ts.map +1 -0
- package/dist/initAgents.js +508 -0
- package/dist/initAgents.js.map +1 -0
- package/dist/log.d.ts +17 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +49 -0
- package/dist/log.js.map +1 -0
- package/dist/mcpResult.d.ts +39 -0
- package/dist/mcpResult.d.ts.map +1 -0
- package/dist/mcpResult.js +19 -0
- package/dist/mcpResult.js.map +1 -0
- package/dist/mount.d.ts +33 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +213 -0
- package/dist/mount.js.map +1 -0
- package/dist/paramTokens.d.ts +18 -0
- package/dist/paramTokens.d.ts.map +1 -0
- package/dist/paramTokens.js +50 -0
- package/dist/paramTokens.js.map +1 -0
- package/dist/projectStore.d.ts +5 -0
- package/dist/projectStore.d.ts.map +1 -0
- package/dist/projectStore.js +60 -0
- package/dist/projectStore.js.map +1 -0
- package/dist/requestConnection.d.ts +22 -0
- package/dist/requestConnection.d.ts.map +1 -0
- package/dist/requestConnection.js +50 -0
- package/dist/requestConnection.js.map +1 -0
- package/dist/serve.d.ts +10 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +37 -0
- package/dist/serve.js.map +1 -0
- package/dist/server.d.ts +41 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +370 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/actionCatalog.d.ts +24 -0
- package/dist/tools/actionCatalog.d.ts.map +1 -0
- package/dist/tools/actionCatalog.js +56 -0
- package/dist/tools/actionCatalog.js.map +1 -0
- package/dist/tools/attachment.tools.d.ts +15 -0
- package/dist/tools/attachment.tools.d.ts.map +1 -0
- package/dist/tools/attachment.tools.js +104 -0
- package/dist/tools/attachment.tools.js.map +1 -0
- package/dist/tools/backlog.tools.d.ts +13 -0
- package/dist/tools/backlog.tools.d.ts.map +1 -0
- package/dist/tools/backlog.tools.js +690 -0
- package/dist/tools/backlog.tools.js.map +1 -0
- package/dist/tools/connection.tools.d.ts +16 -0
- package/dist/tools/connection.tools.d.ts.map +1 -0
- package/dist/tools/connection.tools.js +120 -0
- package/dist/tools/connection.tools.js.map +1 -0
- package/dist/tools/defects.tools.d.ts +7 -0
- package/dist/tools/defects.tools.d.ts.map +1 -0
- package/dist/tools/defects.tools.js +108 -0
- package/dist/tools/defects.tools.js.map +1 -0
- package/dist/tools/discovery.tools.d.ts +23 -0
- package/dist/tools/discovery.tools.d.ts.map +1 -0
- package/dist/tools/discovery.tools.js +1746 -0
- package/dist/tools/discovery.tools.js.map +1 -0
- package/dist/tools/executionPlan.tools.d.ts +14 -0
- package/dist/tools/executionPlan.tools.d.ts.map +1 -0
- package/dist/tools/executionPlan.tools.js +184 -0
- package/dist/tools/executionPlan.tools.js.map +1 -0
- package/dist/tools/failure.tools.d.ts +14 -0
- package/dist/tools/failure.tools.d.ts.map +1 -0
- package/dist/tools/failure.tools.js +65 -0
- package/dist/tools/failure.tools.js.map +1 -0
- package/dist/tools/formulas.tools.d.ts +7 -0
- package/dist/tools/formulas.tools.d.ts.map +1 -0
- package/dist/tools/formulas.tools.js +84 -0
- package/dist/tools/formulas.tools.js.map +1 -0
- package/dist/tools/functionReuse.d.ts +77 -0
- package/dist/tools/functionReuse.d.ts.map +1 -0
- package/dist/tools/functionReuse.js +384 -0
- package/dist/tools/functionReuse.js.map +1 -0
- package/dist/tools/gapAnalysis.tools.d.ts +31 -0
- package/dist/tools/gapAnalysis.tools.d.ts.map +1 -0
- package/dist/tools/gapAnalysis.tools.js +287 -0
- package/dist/tools/gapAnalysis.tools.js.map +1 -0
- package/dist/tools/heal.tools.d.ts +20 -0
- package/dist/tools/heal.tools.d.ts.map +1 -0
- package/dist/tools/heal.tools.js +268 -0
- package/dist/tools/heal.tools.js.map +1 -0
- package/dist/tools/impactAnalysis.tools.d.ts +17 -0
- package/dist/tools/impactAnalysis.tools.d.ts.map +1 -0
- package/dist/tools/impactAnalysis.tools.js +352 -0
- package/dist/tools/impactAnalysis.tools.js.map +1 -0
- package/dist/tools/markdown.d.ts +13 -0
- package/dist/tools/markdown.d.ts.map +1 -0
- package/dist/tools/markdown.js +145 -0
- package/dist/tools/markdown.js.map +1 -0
- package/dist/tools/objects.tools.d.ts +7 -0
- package/dist/tools/objects.tools.d.ts.map +1 -0
- package/dist/tools/objects.tools.js +458 -0
- package/dist/tools/objects.tools.js.map +1 -0
- package/dist/tools/pipeline.tools.d.ts +11 -0
- package/dist/tools/pipeline.tools.d.ts.map +1 -0
- package/dist/tools/pipeline.tools.js +100 -0
- package/dist/tools/pipeline.tools.js.map +1 -0
- package/dist/tools/preference.tools.d.ts +15 -0
- package/dist/tools/preference.tools.d.ts.map +1 -0
- package/dist/tools/preference.tools.js +114 -0
- package/dist/tools/preference.tools.js.map +1 -0
- package/dist/tools/privileges.tools.d.ts +65 -0
- package/dist/tools/privileges.tools.d.ts.map +1 -0
- package/dist/tools/privileges.tools.js +186 -0
- package/dist/tools/privileges.tools.js.map +1 -0
- package/dist/tools/project.tools.d.ts +13 -0
- package/dist/tools/project.tools.d.ts.map +1 -0
- package/dist/tools/project.tools.js +199 -0
- package/dist/tools/project.tools.js.map +1 -0
- package/dist/tools/query.tools.d.ts +23 -0
- package/dist/tools/query.tools.d.ts.map +1 -0
- package/dist/tools/query.tools.js +368 -0
- package/dist/tools/query.tools.js.map +1 -0
- package/dist/tools/recording.tools.d.ts +58 -0
- package/dist/tools/recording.tools.d.ts.map +1 -0
- package/dist/tools/recording.tools.js +1050 -0
- package/dist/tools/recording.tools.js.map +1 -0
- package/dist/tools/recordingNames.d.ts +3 -0
- package/dist/tools/recordingNames.d.ts.map +1 -0
- package/dist/tools/recordingNames.js +16 -0
- package/dist/tools/recordingNames.js.map +1 -0
- package/dist/tools/report.tools.d.ts +12 -0
- package/dist/tools/report.tools.d.ts.map +1 -0
- package/dist/tools/report.tools.js +104 -0
- package/dist/tools/report.tools.js.map +1 -0
- package/dist/tools/run.tools.d.ts +25 -0
- package/dist/tools/run.tools.d.ts.map +1 -0
- package/dist/tools/run.tools.js +1295 -0
- package/dist/tools/run.tools.js.map +1 -0
- package/dist/tools/schemas.d.ts +860 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +220 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/storySync.tools.d.ts +167 -0
- package/dist/tools/storySync.tools.d.ts.map +1 -0
- package/dist/tools/storySync.tools.js +678 -0
- package/dist/tools/storySync.tools.js.map +1 -0
- package/dist/tools/suiteManage.tools.d.ts +14 -0
- package/dist/tools/suiteManage.tools.d.ts.map +1 -0
- package/dist/tools/suiteManage.tools.js +112 -0
- package/dist/tools/suiteManage.tools.js.map +1 -0
- package/dist/tools/tasks.tools.d.ts +7 -0
- package/dist/tools/tasks.tools.d.ts.map +1 -0
- package/dist/tools/tasks.tools.js +101 -0
- package/dist/tools/tasks.tools.js.map +1 -0
- package/dist/tools/tcEditPublisher.d.ts +29 -0
- package/dist/tools/tcEditPublisher.d.ts.map +1 -0
- package/dist/tools/tcEditPublisher.js +61 -0
- package/dist/tools/tcEditPublisher.js.map +1 -0
- package/dist/tools/testCaseLint.d.ts +5 -0
- package/dist/tools/testCaseLint.d.ts.map +1 -0
- package/dist/tools/testCaseLint.js +112 -0
- package/dist/tools/testCaseLint.js.map +1 -0
- package/dist/tools/testPlan.tools.d.ts +12 -0
- package/dist/tools/testPlan.tools.d.ts.map +1 -0
- package/dist/tools/testPlan.tools.js +104 -0
- package/dist/tools/testPlan.tools.js.map +1 -0
- package/dist/tools/testcase.tools.d.ts +86 -0
- package/dist/tools/testcase.tools.d.ts.map +1 -0
- package/dist/tools/testcase.tools.js +1591 -0
- package/dist/tools/testcase.tools.js.map +1 -0
- package/dist/tools/testdata.tools.d.ts +7 -0
- package/dist/tools/testdata.tools.d.ts.map +1 -0
- package/dist/tools/testdata.tools.js +636 -0
- package/dist/tools/testdata.tools.js.map +1 -0
- package/dist/tools/xlsx.d.ts +8 -0
- package/dist/tools/xlsx.d.ts.map +1 -0
- package/dist/tools/xlsx.js +113 -0
- package/dist/tools/xlsx.js.map +1 -0
- package/dist/vendor/actionSignatures.d.ts +117 -0
- package/dist/vendor/actionSignatures.d.ts.map +1 -0
- package/dist/vendor/actionSignatures.js +420 -0
- package/dist/vendor/actionSignatures.js.map +1 -0
- package/dist/vendor/logger.d.ts +43 -0
- package/dist/vendor/logger.d.ts.map +1 -0
- package/dist/vendor/logger.js +184 -0
- package/dist/vendor/logger.js.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/dist/version.js.map +1 -0
- package/dist/versionName.d.ts +21 -0
- package/dist/versionName.d.ts.map +1 -0
- package/dist/versionName.js +48 -0
- package/dist/versionName.js.map +1 -0
- package/package.json +62 -6
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { ok, err } from '../mcpResult.js';
|
|
4
|
+
import { log } from '../log.js';
|
|
5
|
+
import { rememberRecordingName } from './recordingNames.js';
|
|
6
|
+
// One-shot confirm tokens for core_close_session. Minted on refusal, redeemed on the follow-up call,
|
|
7
|
+
// short TTL. Stops the LLM from self-authorising a discard: it must return the EXACT nonce the tool
|
|
8
|
+
// just handed it, which only happens if it goes back to the user, hears "close anyway", then calls
|
|
9
|
+
// again with the token. Process-scoped — matches DraftStore's lifetime.
|
|
10
|
+
const CLOSE_NONCE_TTL_MS = 5 * 60000;
|
|
11
|
+
const closeNonces = new Map();
|
|
12
|
+
function mintCloseNonce() {
|
|
13
|
+
const nonce = randomBytes(12).toString('base64url');
|
|
14
|
+
closeNonces.set(nonce, Date.now() + CLOSE_NONCE_TTL_MS);
|
|
15
|
+
return nonce;
|
|
16
|
+
}
|
|
17
|
+
/** Single-use: if valid & unexpired, delete + return true. Also opportunistically prunes expired entries. */
|
|
18
|
+
function redeemCloseNonce(nonce) {
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
for (const [n, exp] of closeNonces)
|
|
21
|
+
if (exp < now)
|
|
22
|
+
closeNonces.delete(n);
|
|
23
|
+
const exp = closeNonces.get(nonce);
|
|
24
|
+
if (exp === undefined)
|
|
25
|
+
return false;
|
|
26
|
+
closeNonces.delete(nonce);
|
|
27
|
+
return exp >= now;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Bridges the product MCP's AGENT-BOUND recording surface (recording_start, browser_*, verify_*,
|
|
31
|
+
* control_flow_marker, generate_test_steps, recording_steps/save/discard, ...) through the Common
|
|
32
|
+
* MCP, so the client drives recording through the ONE door instead of connecting to the agent
|
|
33
|
+
* directly. Common cannot implement these (they need the product's real browser); it FORWARDS each
|
|
34
|
+
* call verbatim via `adapter.callRaw` and relays the result.
|
|
35
|
+
*
|
|
36
|
+
* The set is mirrored DYNAMICALLY from the product's own advertised tools (real names + descriptions,
|
|
37
|
+
* so it never drifts), minus the provider-ops Common already wraps as its own client tools. It runs
|
|
38
|
+
* async once the connection is live; registerTool emits tools/list_changed so the client picks the
|
|
39
|
+
* proxies up (a /mcp reconnect also surfaces them).
|
|
40
|
+
*
|
|
41
|
+
* DELIBERATELY ROUGH (fix later, per plan): input schemas are permissive (the agent validates
|
|
42
|
+
* strictly) rather than mirrored exactly; and recording_save creates a draft in the AGENT's store,
|
|
43
|
+
* which Common's tc_save cannot see -- persisting a recorded test still needs a draft->tc_save bridge.
|
|
44
|
+
*/
|
|
45
|
+
/** Agent provider-ops Common already exposes as its own client tools -- NOT re-proxied. */
|
|
46
|
+
const PROVIDER_OPS = new Set([
|
|
47
|
+
'info', 'list_projects', 'list_testcases', 'get_testcase', 'actions_catalog',
|
|
48
|
+
'create_testcase', 'update_testcase', 'list_cloud_runners', 'start_run', 'get_run', 'stop_run',
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* The ONLY agent tools re-exposed to the client: the technology SUB-AGENT tools. Each is a DELEGATED
|
|
52
|
+
* sub-agent (goal in; its own LLM loop over internal browser + recording tools; a saved draft out).
|
|
53
|
+
* The granular tools (browser_*, recording_*, verify_*, store_run_variable, control_flow_marker,
|
|
54
|
+
* generate_test_steps, qa_select_technology, qa_technology_status) stay INTERNAL to the sub-agents on
|
|
55
|
+
* the product agent and are NOT proxied -- the client drives everything through web / android /
|
|
56
|
+
* mainframe / db plus the lifecycle provider-ops. This is the "one door, smartness downstream" surface.
|
|
57
|
+
*/
|
|
58
|
+
const TECHNOLOGY_SUBAGENTS = new Set(['web', 'android', 'ios', 'mainframe', 'db']);
|
|
59
|
+
/**
|
|
60
|
+
* The POLL half of a delegated recording. A delegated recorder is non-blocking — `web`/`mainframe`
|
|
61
|
+
* return a sessionId and record in the background — so its `*_status` tool is as much part of the
|
|
62
|
+
* client surface as the recorder itself, and each one needs the DRAFT BRIDGE (see
|
|
63
|
+
* registerDelegatedStatus). Without its status tool a technology can START a recording that can never
|
|
64
|
+
* be collected: the assembled draft stays in the AGENT's store, which Common's tc_save cannot see.
|
|
65
|
+
*
|
|
66
|
+
* Keep this in lockstep with the recorders in TECHNOLOGY_SUBAGENTS that are non-blocking. `db` is
|
|
67
|
+
* absent because it is still a declared scaffold with no delegated loop to poll.
|
|
68
|
+
*/
|
|
69
|
+
const DELEGATED_STATUS_TOOLS = new Set([
|
|
70
|
+
'web_status', 'mainframe_status', 'android_status', 'ios_status',
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* Read-only ENVIRONMENT-DISCOVERY tools a sub-agent exposes so the client can answer "what can I
|
|
74
|
+
* record against?" before it records. Proxied verbatim (no draft bridge — they return no test case).
|
|
75
|
+
*
|
|
76
|
+
* `android_devices` is the first, and it is not optional convenience: `android({ packageName })`
|
|
77
|
+
* requires an exact package id (`in.redbus.android`), which is derivable from nothing — not from the
|
|
78
|
+
* app's display name, and not from the user, who does not know it either. Without this tool in the
|
|
79
|
+
* filter the model has a required argument it cannot obtain, which is how the mainframe `appPath`
|
|
80
|
+
* failure started. Web and mainframe need no equivalent: a browser takes a URL the user already has,
|
|
81
|
+
* and an emulator session file is a path they can point at.
|
|
82
|
+
*
|
|
83
|
+
* `ios_devices` is the same argument twice over: `ios({ bundleId })` needs a bundle id, which is no
|
|
84
|
+
* more derivable than a package name ("Settings" is com.apple.Preferences), and a udid is a 40-char
|
|
85
|
+
* string nobody can type from memory. Note the name: the QA-surface tool is `ios_devices`, matching
|
|
86
|
+
* `android_devices`. The agent's INTERNAL loop has a separate `ios_list_devices` among its 49 tools —
|
|
87
|
+
* different namespace, not proxied, and not what belongs here.
|
|
88
|
+
*/
|
|
89
|
+
const DISCOVERY_TOOLS = new Set(['android_devices', 'ios_devices']);
|
|
90
|
+
/**
|
|
91
|
+
* Control tools for an IN-FLIGHT delegated recording: pause it, carry on, or abandon it. Proxied
|
|
92
|
+
* VERBATIM — no draft bridge, deliberately. A pause returns the steps so far for REVIEW, not a
|
|
93
|
+
* saveable draft; re-homing a partial into Common's DraftStore would invite saving a half-finished
|
|
94
|
+
* recording, which the "never auto-save" rule exists to prevent. The real draft still arrives the
|
|
95
|
+
* usual way, at `*_status` "done".
|
|
96
|
+
*
|
|
97
|
+
* Without these on the client surface a recording can be STARTED but never stopped: the only escape
|
|
98
|
+
* from one that has gone wrong is restarting the agent, which drops every other session with it.
|
|
99
|
+
*
|
|
100
|
+
* Additive, like every set above it — an agent that does not advertise these simply never matches.
|
|
101
|
+
*/
|
|
102
|
+
const RECORDING_CONTROL_TOOLS = new Set([
|
|
103
|
+
'android_recording_stop', 'android_recording_resume', 'android_recording_discard',
|
|
104
|
+
'web_recording_stop', 'web_recording_resume', 'web_recording_discard',
|
|
105
|
+
'mainframe_recording_stop', 'mainframe_recording_resume', 'mainframe_recording_discard',
|
|
106
|
+
'ios_recording_stop', 'ios_recording_resume', 'ios_recording_discard',
|
|
107
|
+
]);
|
|
108
|
+
/** Permissive input: accept any object; the product MCP is the strict validator. */
|
|
109
|
+
const PASSTHROUGH_INPUT = z.record(z.string(), z.unknown());
|
|
110
|
+
/**
|
|
111
|
+
* Appended to core_activate_technology's description so the model ASKS the user which recording mode
|
|
112
|
+
* they want before starting a WEB recording (the agent accepts `recordingMode` on that tool). Without
|
|
113
|
+
* this the recording silently defaults to HYBRID and the user is never offered AI-only.
|
|
114
|
+
*/
|
|
115
|
+
const RECORDING_MODE_PROMPT = '\n\nWEB recordings run in one of two modes — make sure you know which the user wants:\n' +
|
|
116
|
+
' • "AI-only" (default) — record ONLY the AI-driven steps (clean; the browser recording extension is NOT loaded), or\n' +
|
|
117
|
+
' • "AI + Manual" — ALSO capture the user\'s OWN manual clicks in the browser alongside the AI steps.\n' +
|
|
118
|
+
'If the user ALREADY named the mode in their request (e.g. "AI-only", "AI + Manual"), use it — do NOT re-ask. ' +
|
|
119
|
+
'Otherwise ASK "AI-only or AI + Manual?"; if they have no preference, use AI-only.\n' +
|
|
120
|
+
'Pass their choice as recordingMode: "AI" or "HYBRID" ("AI + Manual" maps to "HYBRID"), plus a matching recordingModeAskedUser.\n' +
|
|
121
|
+
'NOTE: ANDROID / IOS recordings are ALWAYS AI-only — do NOT ask or offer AI + Manual for mobile (it is a browser-extension feature). ' +
|
|
122
|
+
'Set recordingMode="AI" and recordingModeAskedUser="AI" automatically for mobile.';
|
|
123
|
+
/** Canonicalise a recording-mode string (the user/agent may phrase it many ways) to the backend
|
|
124
|
+
* enum sense. "AI"/"AI-only" -> 'ai'; "HYBRID"/"AI + Manual"/"manual" -> 'hybrid'; else -> ''. */
|
|
125
|
+
function canonRecordingMode(s) {
|
|
126
|
+
if (typeof s !== 'string')
|
|
127
|
+
return '';
|
|
128
|
+
const v = s.toLowerCase().replace(/[\s_+&-]/g, '');
|
|
129
|
+
if (v === 'ai' || v === 'aionly')
|
|
130
|
+
return 'ai';
|
|
131
|
+
if (v === 'hybrid' || v === 'manual' || v === 'aimanual' || v === 'aiplusmanual')
|
|
132
|
+
return 'hybrid';
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Per-technology wording + extra input fields for the two delegated recorders. Everything else about
|
|
137
|
+
* them is identical (resolve nested refs up front, forward, poll, re-home the draft), which is why
|
|
138
|
+
* they share registerDelegatedRecorder / registerDelegatedStatus rather than each carrying a copy.
|
|
139
|
+
*/
|
|
140
|
+
const DELEGATED_RECORDERS = {
|
|
141
|
+
web: {
|
|
142
|
+
statusTool: 'web_status',
|
|
143
|
+
/** Extra fields beyond `task` + nestStart/nestEnd, forwarded verbatim to the agent. */
|
|
144
|
+
extraInput: {
|
|
145
|
+
url: z.string().optional().describe('Starting URL for the recording browser. STRONGLY recommended — the recording opens on this ' +
|
|
146
|
+
'page. If omitted, the agent uses the first URL found in the task.'),
|
|
147
|
+
profile: z.string().optional().describe('Persistent browser profile (cookies/localStorage). Omit for a fresh isolated profile per ' +
|
|
148
|
+
'recording (recommended — avoids browser-lock collisions); pass a name to REUSE a signed-in ' +
|
|
149
|
+
'profile across recordings.'),
|
|
150
|
+
},
|
|
151
|
+
taskDescribe: 'The GOAL in natural language, e.g. "Sign in at <url> as Admin/admin123, then verify the ' +
|
|
152
|
+
'Dashboard heading is visible." Include the app URL in the task.',
|
|
153
|
+
startNote: 'NON-BLOCKING: this STARTS the delegated web recording on the agent and returns a sessionId ' +
|
|
154
|
+
'immediately — a browser opens and records in the background. Then poll web_status({ sessionId }) ' +
|
|
155
|
+
'until status is "done"; web_status re-homes the draft HERE and returns a Common draftId that ' +
|
|
156
|
+
'tc_save can persist. POLL EVERY ~15-20 SECONDS, never minutes: the recording takes MINUTES end to end, but that is its DURATION, not the poll interval, and waiting minutes between polls leaves a finished draft sitting uncollected. Call web ONCE — do not retry it.',
|
|
157
|
+
doneLabel: 'Web recording complete.',
|
|
158
|
+
},
|
|
159
|
+
mainframe: {
|
|
160
|
+
statusTool: 'mainframe_status',
|
|
161
|
+
extraInput: {
|
|
162
|
+
appPath: z.string().optional().describe('Path to the TN3270 emulator SESSION FILE or its executable. The extension identifies the ' +
|
|
163
|
+
'emulator: `.ecf` = Quick3270, `.ws` = IBM Personal Communications, `.rd3x`/`.rd5x` = Micro ' +
|
|
164
|
+
'Focus Reflection. Launched before recording and becomes the "Launch ${app_path}" step 1, so ' +
|
|
165
|
+
'the test case replays from cold. Omit ONLY when the emulator is already open and you are ' +
|
|
166
|
+
'attaching to its live session. If you do not know the path, ASK THE USER for it — do not ' +
|
|
167
|
+
'search the filesystem.'),
|
|
168
|
+
attachOnly: z.boolean().optional().describe('Do not launch the emulator even though appPath was given — attach to the running one.'),
|
|
169
|
+
// THE DIRECT (TN3270) ROUTE. These MUST be declared here even though the agent already
|
|
170
|
+
// accepts them: this file registers its own schema and forwards only the keys it names
|
|
171
|
+
// (see the loop over Object.keys(cfg.extraInput) below). A field the agent documents but
|
|
172
|
+
// this config omits is not "passed through" — it cannot be supplied by the caller at all,
|
|
173
|
+
// and the route it selects is unreachable from any MCP client.
|
|
174
|
+
host: z.string().optional().describe('DIRECT ROUTE — the mainframe hostname or IP to dial over TN3270, with NO emulator at all, ' +
|
|
175
|
+
'e.g. "zos.example.com". Giving this selects the direct route the way appPath selects the ' +
|
|
176
|
+
'emulator route; pass one or the other, never both. ASK THE USER — never invent a hostname ' +
|
|
177
|
+
'and never reuse one from an earlier conversation. Prefer this route when no emulator is ' +
|
|
178
|
+
'installed, the machine is not Windows, or several mainframe recordings must run at once ' +
|
|
179
|
+
'(it has no single-attachment limit). A test case is TIED to the route it was recorded on.'),
|
|
180
|
+
port: z.string().optional().describe('DIRECT ROUTE — the TN3270 port as a string, e.g. "1023" (Marist) or "3270" (a local ' +
|
|
181
|
+
'Hercules/TK4). ASK THE USER: there is no safe default and the common ports differ per ' +
|
|
182
|
+
'host. Required whenever `host` is given.'),
|
|
183
|
+
marker: z.string().optional().describe('DIRECT ROUTE — text that appears on the FIRST screen once the host is ready, e.g. "z/OS". ' +
|
|
184
|
+
'The connect waits for it, which is how "connected" is told apart from "connected but the ' +
|
|
185
|
+
'screen is not drawn yet". ASK THE USER and pass it EXACTLY: matching is CASE-SENSITIVE, ' +
|
|
186
|
+
'so "z/Os" against a screen showing "z/OS" waits out the timeout and fails. No escaping or ' +
|
|
187
|
+
'URL-encoding — the agent assembles the target itself.'),
|
|
188
|
+
ssl: z.boolean().optional().describe('DIRECT ROUTE, ADVANCED — TLS to the host. Default false, correct for plain TN3270 (port 1023 ' +
|
|
189
|
+
'and most test hosts). Ask only if the user raises it, or a plain connection is refused.'),
|
|
190
|
+
dialect: z.enum(['zos', 'tk4']).optional().describe('DIRECT ROUTE, ADVANCED — which logon flow the host speaks. "zos" (default) is a normal z/OS ' +
|
|
191
|
+
'VTAM banner; "tk4" is MVS 3.8j under Hercules, with a different logon panel and a terminal ' +
|
|
192
|
+
'that needs waking. Ask only if the user mentions Hercules, TK4- or MVS 3.8j.'),
|
|
193
|
+
target: z.string().optional().describe('DIRECT ROUTE — the ALREADY-ASSEMBLED destination a SAVED test case carries: either ' +
|
|
194
|
+
'"host:port?marker=..." or a profile NAME from the agent config file ("marist"). Use it when ' +
|
|
195
|
+
'replaying something stored; for a NEW recording prefer host/port/marker, which are ' +
|
|
196
|
+
'assembled with correct encoding (hand-built strings corrupt a marker containing "+", "&" ' +
|
|
197
|
+
'or "="). A profile name only works where that config file exists, and it is not deployed. ' +
|
|
198
|
+
'Ignored when `host` is given.'),
|
|
199
|
+
},
|
|
200
|
+
taskDescribe: 'The GOAL in natural language, e.g. "Log on to TSO as ANISHA/pass123, then run LISTUSER." ' +
|
|
201
|
+
'Include the real values the host needs — they are parameterized at assembly time.',
|
|
202
|
+
startNote: 'ASK THE USER WHICH ROUTE FIRST — before any other work, and never pick for them. Pass EITHER ' +
|
|
203
|
+
'`host`+`port`+`marker` (DIRECT: dials the host over TN3270, no emulator, any OS, several ' +
|
|
204
|
+
'recordings at once) OR `appPath` (EMULATOR: launches a TN3270 emulator, Windows only, one at a ' +
|
|
205
|
+
'time). A test case is TIED to the route it was recorded on and cannot be switched later, which ' +
|
|
206
|
+
'is why this is never guessed. Do NOT try to INFER it: a running emulator does not mean they want ' +
|
|
207
|
+
'the emulator route, an absent one does not rule it out (the direct route needs none), and the ' +
|
|
208
|
+
'routes used by existing test cases say nothing about the one they want now. Do NOT run tasklist, ' +
|
|
209
|
+
'search the filesystem for .ecf files, or read other test cases to decide this — ask. Calling this ' +
|
|
210
|
+
'tool with neither argument is REFUSED. ' +
|
|
211
|
+
'NON-BLOCKING: this STARTS the delegated mainframe recording on the agent and returns a sessionId ' +
|
|
212
|
+
'immediately — the session connects and records in the background. Then poll ' +
|
|
213
|
+
'mainframe_status({ sessionId }) until status is "done"; mainframe_status re-homes the draft HERE ' +
|
|
214
|
+
'and returns a Common draftId that tc_save can persist. POLL EVERY ~15-20 SECONDS, never minutes: the recording takes MINUTES end to end, but that is its DURATION, not the poll interval, and waiting minutes between polls leaves a finished draft sitting uncollected. Call mainframe ONCE — do not ' +
|
|
215
|
+
'retry it. On the EMULATOR route the HLLAPI session admits one attachment, so those recordings ' +
|
|
216
|
+
'cannot overlap; the DIRECT route has no such limit.',
|
|
217
|
+
doneLabel: 'Mainframe recording complete.',
|
|
218
|
+
},
|
|
219
|
+
android: {
|
|
220
|
+
statusTool: 'android_status',
|
|
221
|
+
extraInput: {
|
|
222
|
+
packageName: z.string().describe('The app under test, e.g. "com.example.app". Launched before recording and becomes the ' +
|
|
223
|
+
'"Launch App ${app_package}" step 1, so the test case replays from cold.'),
|
|
224
|
+
deviceId: z.string().optional().describe('udid of the target device from `adb devices` (e.g. "emulator-5554", "R58M12ABCDE"). OMIT when ' +
|
|
225
|
+
'exactly one device is connected — it is auto-selected and reported back. With SEVERAL ' +
|
|
226
|
+
'connected the call is refused and the udids are listed: ASK THE USER which device to record ' +
|
|
227
|
+
'on. Never pick one yourself — recording on the wrong device does not fail, it silently ' +
|
|
228
|
+
'produces a test case against the wrong handset.'),
|
|
229
|
+
activityName: z.string().optional().describe('Optional launch activity. OMIT IT — the agent reads the app\'s launcher activity off the device ' +
|
|
230
|
+
'and records it, so the saved test case launches explicitly rather than relying on a default. ' +
|
|
231
|
+
'Pass one only to launch a specific non-default entry point.'),
|
|
232
|
+
action: z.enum(['start', 'reset']).optional().describe('"start" (default) launches the app as-is; "reset" clears its data first, for a clean-state flow.'),
|
|
233
|
+
},
|
|
234
|
+
taskDescribe: 'The GOAL in natural language, e.g. "Sign in as admin/admin123, search for \'Acme\' and open the ' +
|
|
235
|
+
'first result." Include the real values the app needs — they are parameterized at assembly time.',
|
|
236
|
+
startNote: 'NON-BLOCKING: this STARTS the delegated android recording on the agent and returns a sessionId ' +
|
|
237
|
+
'immediately — the device attaches over ADB and records in the background. Then poll ' +
|
|
238
|
+
'android_status({ sessionId }) until status is "done"; android_status re-homes the draft HERE and ' +
|
|
239
|
+
'returns a Common draftId that tc_save can persist. POLL EVERY ~15-20 SECONDS, never minutes: the recording takes MINUTES end to end, but that is its DURATION, not the poll interval, and waiting minutes between polls leaves a finished draft sitting uncollected. Call android ONCE — do not retry ' +
|
|
240
|
+
'it: the ' +
|
|
241
|
+
'device is claimed for the recording, so a second call on the same udid is refused. Recordings ' +
|
|
242
|
+
'on DIFFERENT devices can run at the same time.',
|
|
243
|
+
doneLabel: 'Android recording complete.',
|
|
244
|
+
},
|
|
245
|
+
ios: {
|
|
246
|
+
statusTool: 'ios_status',
|
|
247
|
+
extraInput: {
|
|
248
|
+
bundleId: z.string().describe('The app under test, as a BUNDLE ID (e.g. "com.apple.Preferences"). Launched when the WDA '
|
|
249
|
+
+ 'session opens, so the app is frontmost before recording starts. RESOLVE IT YOURSELF '
|
|
250
|
+
+ 'FROM `ios_devices`, which lists every installed app as "Display Name — bundleId" — the '
|
|
251
|
+
+ 'user names the app the way a human does ("record a Settings flow") and you look up the '
|
|
252
|
+
+ 'id. Do NOT ask the user for it (nobody knows one from memory) and do NOT guess it from '
|
|
253
|
+
+ 'the display name: the mapping is not derivable (Photos is com.apple.mobileslideshow, '
|
|
254
|
+
+ 'Messages is com.apple.MobileSMS). Match on the DISPLAY NAME — on iOS that column is the '
|
|
255
|
+
+ 'real home-screen string, unlike android_devices where it is a derived placeholder, and '
|
|
256
|
+
+ 'the list is user-installed apps only so the names do not collide. If nothing matches or '
|
|
257
|
+
+ 'several do, show the candidates and ask.'),
|
|
258
|
+
deviceId: z.string().optional().describe('udid of the target device or simulator, from `ios_devices`. OMIT when exactly one is '
|
|
259
|
+
+ 'available — it is auto-selected and reported back. With SEVERAL available the call is '
|
|
260
|
+
+ 'REFUSED and they are listed: ASK THE USER which one. Never pick one yourself — recording '
|
|
261
|
+
+ 'on the wrong device does not fail, it silently produces a test case against the wrong '
|
|
262
|
+
+ 'handset.'),
|
|
263
|
+
projectId: z.string().optional().describe('Enables the WebDriverAgent auto-install self-heal on a REAL device, using the Apple signing '
|
|
264
|
+
+ 'material stored for that project. Omit for a simulator, which needs no signing. Pass it '
|
|
265
|
+
+ 'only when the user has actually configured signing for that project.'),
|
|
266
|
+
},
|
|
267
|
+
taskDescribe: 'The GOAL in natural language, e.g. "Open General > About and verify the Name row is visible." '
|
|
268
|
+
+ 'Include the real values the app needs — they are parameterized at assembly time.',
|
|
269
|
+
startNote: 'CALL ios_devices FIRST if you do not already have an exact bundle id — it lists the installed '
|
|
270
|
+
+ 'apps as "Display Name — bundleId", so you resolve the id from the app name the user said '
|
|
271
|
+
+ 'rather than asking them for a string they do not have. '
|
|
272
|
+
+ 'NON-BLOCKING: this STARTS the delegated iOS recording on the agent and returns a sessionId '
|
|
273
|
+
+ 'immediately — WebDriverAgent comes up and records in the background. Then poll '
|
|
274
|
+
+ 'ios_status({ sessionId }) until status is "done"; ios_status re-homes the draft HERE and '
|
|
275
|
+
+ 'returns a Common draftId that tc_save can persist. POLL EVERY ~15-20 SECONDS, never minutes: '
|
|
276
|
+
+ 'the recording takes MINUTES end to end, but that is its DURATION, not the poll interval, and '
|
|
277
|
+
+ 'waiting minutes between polls leaves a finished draft sitting uncollected. Bring-up is '
|
|
278
|
+
+ 'SLOWER than android on a real device (signing, install and tunnel), so early polls saying '
|
|
279
|
+
+ '"recording" are normal. Call ios ONCE — do not retry it: the device is claimed for the '
|
|
280
|
+
+ 'recording, so a second call on the same udid is refused. Recordings on DIFFERENT devices can '
|
|
281
|
+
+ 'run at the same time. A REAL DEVICE does not need a macOS agent — go-ios drives pairing, '
|
|
282
|
+
+ 'the developer image and WebDriverAgent from Windows and Linux too. A SIMULATOR does need '
|
|
283
|
+
+ 'macOS (xcodebuild + simctl), so on any other host pass a real device udid.',
|
|
284
|
+
doneLabel: 'iOS recording complete.',
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Convert a product tool's JSON-Schema (object schema) into a Zod raw shape, so the PROXIED tool
|
|
289
|
+
* advertises the SAME named parameters (ref/expected/value/count/…) and required-ness to the client
|
|
290
|
+
* instead of an opaque permissive blob. Without this the client's model can't tell that, say,
|
|
291
|
+
* web_validate_text REQUIRES `expected`; it sends nothing, and the agent invokes a 1-arg method with
|
|
292
|
+
* 0 args ("Arguments length does not match"). Types are approximated (the product agent is the strict
|
|
293
|
+
* validator); the point is that the model knows WHICH args to send. Returns null when the schema is
|
|
294
|
+
* absent or not an object schema, so the caller falls back to the permissive record.
|
|
295
|
+
*/
|
|
296
|
+
function jsonSchemaToShape(schema) {
|
|
297
|
+
if (!schema || typeof schema !== 'object')
|
|
298
|
+
return null;
|
|
299
|
+
const s = schema;
|
|
300
|
+
if (s.type !== 'object' || !s.properties || typeof s.properties !== 'object')
|
|
301
|
+
return null;
|
|
302
|
+
const required = new Set(Array.isArray(s.required) ? s.required.map(String) : []);
|
|
303
|
+
const shape = {};
|
|
304
|
+
for (const [key, raw] of Object.entries(s.properties)) {
|
|
305
|
+
const p = (raw && typeof raw === 'object' ? raw : {});
|
|
306
|
+
let field;
|
|
307
|
+
switch (p.type) {
|
|
308
|
+
case 'string':
|
|
309
|
+
field = z.string();
|
|
310
|
+
break;
|
|
311
|
+
case 'number':
|
|
312
|
+
field = z.number();
|
|
313
|
+
break;
|
|
314
|
+
case 'integer':
|
|
315
|
+
field = z.number().int();
|
|
316
|
+
break;
|
|
317
|
+
case 'boolean':
|
|
318
|
+
field = z.boolean();
|
|
319
|
+
break;
|
|
320
|
+
case 'array':
|
|
321
|
+
field = z.array(z.unknown());
|
|
322
|
+
break;
|
|
323
|
+
case 'object':
|
|
324
|
+
field = z.record(z.string(), z.unknown());
|
|
325
|
+
break;
|
|
326
|
+
default: field = z.unknown();
|
|
327
|
+
}
|
|
328
|
+
if (typeof p.description === 'string')
|
|
329
|
+
field = field.describe(p.description);
|
|
330
|
+
if (!required.has(key))
|
|
331
|
+
field = field.optional();
|
|
332
|
+
shape[key] = field;
|
|
333
|
+
}
|
|
334
|
+
return Object.keys(shape).length ? shape : null;
|
|
335
|
+
}
|
|
336
|
+
export function registerRecordingPassthrough(server, deps) {
|
|
337
|
+
void (async () => {
|
|
338
|
+
const adapter = await waitForConnectedAdapter(deps, 12000);
|
|
339
|
+
if (!adapter?.listAgentTools || !adapter.callRaw)
|
|
340
|
+
return; // offline, or a product without passthrough
|
|
341
|
+
// Retry listAgentTools until the downstream product MCP is primed and advertising. At startup the
|
|
342
|
+
// Common connection can report "connected" (config present) BEFORE the product MCP's OWN connection
|
|
343
|
+
// is primed, so a single call races it, returns nothing, and the web/android/... tools never appear
|
|
344
|
+
// for the whole session (observed after a client reload). The first attempt also nudges the prime.
|
|
345
|
+
// Poll until the downstream advertises tools. This is NOT a one-shot 30s window: the agent
|
|
346
|
+
// (Electron :4050) is frequently started AFTER this MCP server, and a one-shot discovery that
|
|
347
|
+
// misses that window left web/mainframe/... unregistered for the WHOLE session until the user
|
|
348
|
+
// restarted common-mcp (the classic startup race). Instead we retry with backoff (500ms → 10s cap)
|
|
349
|
+
// for a generous window, so the recording surface SELF-HEALS whenever the agent primes. The
|
|
350
|
+
// registration below emits `tools/list_changed`, so a late discovery still reaches the client with
|
|
351
|
+
// no reconnect. Bounded (not eternal) so a truly-absent agent eventually stops polling.
|
|
352
|
+
let tools = [];
|
|
353
|
+
const deadline = Date.now() + 10 * 60000; // ~10 min — covers "agent started shortly after common-mcp"
|
|
354
|
+
let delay = 500;
|
|
355
|
+
let announcedWait = false;
|
|
356
|
+
while (Date.now() < deadline) {
|
|
357
|
+
try {
|
|
358
|
+
const a = deps.getAdapter();
|
|
359
|
+
if (a?.listAgentTools) {
|
|
360
|
+
tools = await a.listAgentTools();
|
|
361
|
+
if (tools.length)
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch { /* downstream not primed yet — retry */ }
|
|
366
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
367
|
+
// Surface the wait once, so a genuinely-down agent is diagnosable (not silently spinning).
|
|
368
|
+
if (!announcedWait && delay >= 10000) {
|
|
369
|
+
announcedWait = true;
|
|
370
|
+
log('recording passthrough: still waiting for the product agent to advertise its tools (will keep retrying)…');
|
|
371
|
+
}
|
|
372
|
+
delay = Math.min(Math.round(delay * 1.5), 10000);
|
|
373
|
+
}
|
|
374
|
+
if (!tools.length) {
|
|
375
|
+
log('recording passthrough: no agent tools discovered within ~10min — the product agent never advertised any this session. Start the agent, then reconnect the MCP.');
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
log(`recording passthrough: discovered ${tools.length} agent tool(s); registering the recording surface (emits tools/list_changed).`);
|
|
379
|
+
// SimplifyQA-only behavior below (granular-verb proxying + real-schema preservation). Walnut keeps
|
|
380
|
+
// its EXACT prior surface, so this cannot affect Walnut. Evaluated once the connection is live.
|
|
381
|
+
const simplifyqa = deps.isSimplifyqa();
|
|
382
|
+
let proxied = 0;
|
|
383
|
+
for (const t of tools) {
|
|
384
|
+
if (PROVIDER_OPS.has(t.name))
|
|
385
|
+
continue;
|
|
386
|
+
// Two recording surfaces are proxied:
|
|
387
|
+
// (a) WALNUT — the technology SUB-AGENT tools (web/android/mainframe/db) + `qa_technology_status`
|
|
388
|
+
// (which LISTS the sub-agents + their availability, the way list_projects lists projects) +
|
|
389
|
+
// every non-blocking recorder's own *_status tool. One delegated sub-agent per tech; its
|
|
390
|
+
// granular browser_*/recording_*/verify_* tools stay INTERNAL to the agent's own loop.
|
|
391
|
+
// The status tools come from DELEGATED_STATUS_TOOLS, NOT a hardcoded 'web_status':
|
|
392
|
+
// `mainframe_status` is equally a client-surface tool, and it matches no core_*/web_* prefix,
|
|
393
|
+
// so naming only web_status here would leave a started mainframe recording uncollectable.
|
|
394
|
+
// (b) SIMPLIFYQA — the client's own LLM drives GRANULAR verbs, and the SimplifyQA agent exposes
|
|
395
|
+
// ONLY client-facing tools (core_*, web_*, generic_*, and any FUTURE technology family such as
|
|
396
|
+
// mobile_*/desktop_* — it has no internal-only tools to hide). So the agent's tools/list IS the
|
|
397
|
+
// source of truth: proxy EVERY non-provider-op tool it advertises (the generic forward branch
|
|
398
|
+
// below). A new tool family on the agent then needs ZERO change here. Prefixes don't collide:
|
|
399
|
+
// Walnut's single tool is exactly `web` (no underscore) and its internals use browser_/…
|
|
400
|
+
const isSubAgent = TECHNOLOGY_SUBAGENTS.has(t.name)
|
|
401
|
+
|| t.name === 'qa_technology_status'
|
|
402
|
+
|| DELEGATED_STATUS_TOOLS.has(t.name)
|
|
403
|
+
|| DISCOVERY_TOOLS.has(t.name)
|
|
404
|
+
|| RECORDING_CONTROL_TOOLS.has(t.name);
|
|
405
|
+
const isRecorderVerb = simplifyqa; // SimplifyQA: every remaining (non-provider-op) tool — agent-driven
|
|
406
|
+
if (!isSubAgent && !isRecorderVerb)
|
|
407
|
+
continue;
|
|
408
|
+
try {
|
|
409
|
+
// A delegated recorder + its status tool get the DRAFT BRIDGE, not a dumb forward: the
|
|
410
|
+
// recording assembles a test case into a draft in the AGENT's OWN store, which tc_save
|
|
411
|
+
// (Common's store) can't see. So we forward, then re-register the returned TestCase in
|
|
412
|
+
// Common's DraftStore and hand back a COMMON draftId — the only kind tc_save can persist.
|
|
413
|
+
const recorderCfg = DELEGATED_RECORDERS[t.name];
|
|
414
|
+
if (recorderCfg) {
|
|
415
|
+
registerDelegatedRecorder(server, deps, t, recorderCfg);
|
|
416
|
+
proxied++;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const statusOwner = Object.values(DELEGATED_RECORDERS).find((c) => c.statusTool === t.name);
|
|
420
|
+
if (statusOwner) {
|
|
421
|
+
registerDelegatedStatus(server, deps, t, statusOwner);
|
|
422
|
+
proxied++;
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (t.name === 'core_close_session') {
|
|
426
|
+
registerCloseSessionWithSaveGuard(server, deps, t);
|
|
427
|
+
proxied++;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
// SimplifyQA-only: intercept `core_activate_technology` so mobile (ANDROID/IOS) recordings
|
|
431
|
+
// can't be started without the LLM having explicitly asked the user which platform. The
|
|
432
|
+
// Java-side tool takes `technology` as a required string; without wrapping, the LLM picks
|
|
433
|
+
// ANDROID vs IOS silently and reuses the previous session's pick on the second recording
|
|
434
|
+
// (the reported bug). Walnut mobile uses a different tool (`android`/`ios`) with its own
|
|
435
|
+
// cascade in registerDelegatedRecorder — this wrapper does NOT apply there.
|
|
436
|
+
if (simplifyqa && t.name === 'core_activate_technology') {
|
|
437
|
+
registerActivateTechnologyWithMobileGuard(server, deps, t);
|
|
438
|
+
proxied++;
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (simplifyqa && FORMULA_INPUT_VERBS.has(t.name)) {
|
|
442
|
+
registerFormulaAwareInput(server, deps, t);
|
|
443
|
+
proxied++;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
// SimplifyQA: preserve the agent's REAL parameter schema (ref/expected/value/count/…) so the
|
|
447
|
+
// client sends the right args (without it, web_validate_text's required `expected` is hidden →
|
|
448
|
+
// "Arguments length does not match"). Walnut keeps the permissive record exactly as before.
|
|
449
|
+
//
|
|
450
|
+
// EXCEPT the recording-control tools, on BOTH products. The permissive record advertises no
|
|
451
|
+
// properties at all, so a client reads `{stop,resume,discard}` as taking nothing and calls
|
|
452
|
+
// them bare — but every one REQUIRES `sessionId` at the agent, and resume additionally takes
|
|
453
|
+
// an optional `task` its own description offers. Args are forwarded verbatim either way, so
|
|
454
|
+
// this changes only what the caller is TOLD it may send; hiding a required argument is not a
|
|
455
|
+
// conservative default, it is a broken call the client cannot see coming. These tools are new,
|
|
456
|
+
// so there is no prior Walnut behaviour to preserve here.
|
|
457
|
+
const useRealShape = simplifyqa || RECORDING_CONTROL_TOOLS.has(t.name);
|
|
458
|
+
const shape = useRealShape ? jsonSchemaToShape(t.inputSchema) : null;
|
|
459
|
+
// core_activate_technology gains a prompt to ASK the user AI-only vs AI + Manual before recording.
|
|
460
|
+
const modePrompt = t.name === 'core_activate_technology' ? RECORDING_MODE_PROMPT : '';
|
|
461
|
+
server.registerTool(t.name, {
|
|
462
|
+
description: `${t.description ?? t.name}${modePrompt}\n\n(Agent-bound tool — runs on the connected product agent, forwarded through the Common MCP.)`,
|
|
463
|
+
inputSchema: shape ?? PASSTHROUGH_INPUT,
|
|
464
|
+
}, async (args = {}) => {
|
|
465
|
+
const a = deps.getAdapter();
|
|
466
|
+
if (!a?.callRaw)
|
|
467
|
+
return err('Not connected to a product agent — recording runs on the agent (qa_connect first).');
|
|
468
|
+
try {
|
|
469
|
+
return (await a.callRaw(t.name, args));
|
|
470
|
+
}
|
|
471
|
+
catch (e) {
|
|
472
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
proxied++;
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
// Name already registered (a Common-native tool) -- skip rather than clobber.
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
log(`recording passthrough: proxied ${proxied} agent tool(s)`);
|
|
482
|
+
})();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* The set of agent text-entry verbs that may carry a `formula` argument. When the passthrough loop
|
|
486
|
+
* encounters one of these tools (SimplifyQA-only), it registers the formula-aware wrapper instead of
|
|
487
|
+
* a dumb forward so the recorder types a freshly-generated value and the saved step regenerates per run.
|
|
488
|
+
* Note: `mainframe_enter_text` is included as the expected mainframe field-entry verb name; confirm
|
|
489
|
+
* against the product's actual tool name if it differs in future.
|
|
490
|
+
* DESKTOP: `desktop_enter_text` (types) and `desktop_set_text` (replaces); their formulas are evaluated as DESKTOP.
|
|
491
|
+
*/
|
|
492
|
+
export const FORMULA_INPUT_VERBS = new Set([
|
|
493
|
+
'web_enter_text', 'web_keyboard_action', 'android_enter_text', 'ios_enter_text',
|
|
494
|
+
'mainframe_enter_text',
|
|
495
|
+
'desktop_enter_text', 'desktop_set_text',
|
|
496
|
+
]);
|
|
497
|
+
/**
|
|
498
|
+
* The BUILT-IN formula catalog the agent's formula engine (`/formula/convert`) supports — mirrors the
|
|
499
|
+
* engine's `FunctionType` enum. Exposed INLINE in the `formula` param description so the recording agent
|
|
500
|
+
* (which often cannot reach the separate `tc_list_formulas` tool) can discover every formula and stops
|
|
501
|
+
* inventing names (e.g. the bogus `RANDOM_ALPHANUMERIC` → the real name is `ALPHA_NUMERIC`). Names are
|
|
502
|
+
* matched case-insensitively; arguments are POSITIONAL in the `expression` form. PROJECT/CUSTOM formulas
|
|
503
|
+
* are NOT listed here (they are dynamic per project) — those still come from `tc_list_formulas`.
|
|
504
|
+
*/
|
|
505
|
+
export const FORMULA_CATALOG = [
|
|
506
|
+
'Arithmetic: SUM(a,b,…), SUBTRACT(a,b), MULTIPLY(a,b,…), DIVISION(a,b), MODULUS(a,b), MAX(a,b,…), MIN(a,b,…)',
|
|
507
|
+
'Text: CONCATENATE(a,b,…), LEFT(text,n), RIGHT(text,n), MID(text,start,len), UPPER(text), LOWER(text), PROPER(text), SPLIT(text,delim,index), REPLACE(text,old,new), REPEAT(text,n), LENGTH(text)',
|
|
508
|
+
'Random/ID: ALPHABET(n)=n letters, NUMERIC(n)=n-digit number (1-9), ALPHA_NUMERIC(n)=n letters+digits — each also takes (min,max) for a random length/range. Also UUID(), PICK_RANDOM(a,b,…), FLIP(). For "3 letters then 3 digits" use =CONCATENATE(ALPHABET(3),NUMERIC(3)).',
|
|
509
|
+
'Date/Time: NOW(), TODAY(), DAY(), MONTH(), YEAR(), TIME(), HOUR(), MINUTE(), SECOND(), FORMAT_DATE(pattern), FORMAT_TIME(pattern), DAY_OF_WEEK()',
|
|
510
|
+
'Logic/Compare: IF_ELSE(cond,then,else), CONTAINS(text,sub), EQUALS(a,b), EQUALS_IGNORE_CASE(a,b), NOT_EQUALS(a,b), GREATER_THAN(a,b), GREATER_THAN_EQUALS(a,b), LESS_THAN(a,b), LESS_THAN_EQUALS(a,b), EMPTY(v), BLANK(v)',
|
|
511
|
+
'Synthetic data: FIRST_NAME(country,sex,min_len,max_len), LAST_NAME(…), FULL_NAME(…), MIDDLE_NAME(…), PREFIX(sex), GENDER(), PHONE_NUMBER(), DATE_OF_BIRTH(pattern,min_age,max_age), EMAIL_ID(prefix,domain), COUNTRY_NAME(), COUNTRY_CODE(), STATE(), CITY(), STREET(), ADDRESS(), ZIPCODE(), TIMEZONE(), CURRENCY_CODE(), CURRENCY_NAME(), CURRENCY_SYMBOL(), CREDIT_CARD_NUMBER(), CREDIT_CARD_CVV(), CREDIT_CARD_EXPIRY()',
|
|
512
|
+
'Name formulas (FIRST_NAME/LAST_NAME/FULL_NAME/MIDDLE_NAME): every arg is OPTIONAL — for a random name just use FIRST_NAME() with NO args. Only set min_len/max_len when the user asks for a specific length, and then pass ALL four args (country,sex,min_len,max_len) and keep min_len ≥ 5, max_len ≥ 6, and min_len < max_len (they must DIFFER — never the same value). Otherwise FIRST_NAME errors: "MIN > 4, MAX > 5 and MIN should be lesser than MAX".',
|
|
513
|
+
'Excel: READ_FROM_EXCEL(…), READ_CELL(…), READ_COLUMN(…), READ_ROW(…)',
|
|
514
|
+
'Misc: ONCE(v), USER_PREFERENCE(key)',
|
|
515
|
+
'Aliases: NUMBER=NUMERIC, ALPHABETS=ALPHABET, MOD=MODULUS, DIV=DIVISION, CONCAT=CONCATENATE, GTE/GT/LTE/LT/EQ/NEQ/EQIGNC = the compare ops above',
|
|
516
|
+
].join('\n ');
|
|
517
|
+
/**
|
|
518
|
+
* Register a formula-aware wrapper for a text-entry verb. When the caller passes a `formula` arg,
|
|
519
|
+
* it is resolved via `adapter.evaluateFormula` and the resulting `value` + `formulaExpression` are
|
|
520
|
+
* forwarded to the agent (the raw `formula` arg is stripped). When no `formula` is passed, all args
|
|
521
|
+
* are forwarded byte-for-byte unchanged — exact backward compatibility.
|
|
522
|
+
*/
|
|
523
|
+
export function registerFormulaAwareInput(server, deps, t) {
|
|
524
|
+
const base = jsonSchemaToShape(t.inputSchema) ?? {};
|
|
525
|
+
const shape = {
|
|
526
|
+
...base,
|
|
527
|
+
formula: z.object({
|
|
528
|
+
name: z.string().optional().describe('Built-in formula name from the catalog below, e.g. "FIRST_NAME", "ALPHA_NUMERIC". Case-insensitive. MUST be a real formula — do NOT invent names (there is no RANDOM_NAME; for a random person name use FIRST_NAME/FULL_NAME). For PROJECT/CUSTOM formulas use tc_list_formulas.'),
|
|
529
|
+
args: z.record(z.string(), z.string()).optional().describe("Named args keyed by the formula's parameter keyNames (see the catalog signatures)."),
|
|
530
|
+
expression: z.string().optional().describe('A full formula with POSITIONAL args, e.g. "=ALPHA_NUMERIC(6)" or "=CONCATENATE(UPPER(LEFT(FIRST_NAME(),3)),NUMERIC(4))". Use instead of name/args; supports any formula in the catalog.'),
|
|
531
|
+
}).optional().describe("OPTIONAL. Generate this field's value with a testdata formula instead of a literal. When set, the recorder types a freshly-generated value and the saved step regenerates per run. Omit for a normal literal (the default). If the user did NOT ask for a formula, do NOT set this.\n\nYou may ONLY use formulas from the catalog below (or a PROJECT/CUSTOM formula from tc_list_formulas). NEVER invent a formula name — if no single formula fits, COMPOSE existing ones, e.g. 3 letters + 3 digits = =CONCATENATE(ALPHABET(3),NUMERIC(3)); a random name = =FULL_NAME().\n\nAVAILABLE BUILT-IN FORMULAS (any work via `expression`; args are positional):\n " + FORMULA_CATALOG),
|
|
532
|
+
};
|
|
533
|
+
server.registerTool(t.name, { description: `${t.description ?? t.name}`, inputSchema: shape }, async (args = {}) => {
|
|
534
|
+
const a = deps.getAdapter();
|
|
535
|
+
if (!a?.callRaw)
|
|
536
|
+
return err('Not connected to a product agent — recording runs on the agent (qa_connect first).');
|
|
537
|
+
const formula = args['formula'];
|
|
538
|
+
const forwarded = {};
|
|
539
|
+
for (const k of Object.keys(args))
|
|
540
|
+
if (k !== 'formula')
|
|
541
|
+
forwarded[k] = args[k];
|
|
542
|
+
if (formula && (formula.name || formula.expression) && a.evaluateFormula) {
|
|
543
|
+
let resolved;
|
|
544
|
+
// DESKTOP verbs are evaluated as DESKTOP; every other verb keeps the adapter's default (WEB).
|
|
545
|
+
try {
|
|
546
|
+
resolved = await a.evaluateFormula(formula, t.name.startsWith('desktop_') ? { technologyType: 'DESKTOP' } : undefined);
|
|
547
|
+
}
|
|
548
|
+
catch (e) {
|
|
549
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
550
|
+
}
|
|
551
|
+
forwarded['value'] = resolved.value;
|
|
552
|
+
forwarded['formulaExpression'] = resolved.expression;
|
|
553
|
+
}
|
|
554
|
+
try {
|
|
555
|
+
return (await a.callRaw(t.name, forwarded));
|
|
556
|
+
}
|
|
557
|
+
catch (e) {
|
|
558
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Register a DELEGATED RECORDER (`web`, `mainframe`) with a REAL schema rather than the permissive
|
|
564
|
+
* passthrough: `task` is required, and the technology's own extra fields are surfaced so the caller is
|
|
565
|
+
* nudged to pass them (a web recording wants `url` so it starts on the real page instead of
|
|
566
|
+
* about:blank; a mainframe recording wants `appPath` so the emulator gets launched and step 1 is
|
|
567
|
+
* recorded).
|
|
568
|
+
*
|
|
569
|
+
* `nestStart`/`nestEnd` arrive here as test-case IDS but go DOWN as resolved `{ tcId, name }` refs —
|
|
570
|
+
* resolved up front so a bad id fails BEFORE a recording is wasted, and so the agent can compose the
|
|
571
|
+
* nesting INTO the session (making the live editor show, and its Save persist, the whole composition).
|
|
572
|
+
*/
|
|
573
|
+
function registerDelegatedRecorder(server, deps, t, cfg) {
|
|
574
|
+
server.registerTool(t.name, {
|
|
575
|
+
description: `${t.description ?? t.name}\n\n(${cfg.startNote})`,
|
|
576
|
+
inputSchema: {
|
|
577
|
+
task: z.string().min(1).describe(cfg.taskDescribe),
|
|
578
|
+
...cfg.extraInput,
|
|
579
|
+
nestStart: z.array(z.string()).optional().describe('Existing test case ids to run BEFORE the recorded activity, as nested steps (e.g. a Login ' +
|
|
580
|
+
'test case). They are prepended to the produced draft in order — so the draft becomes ' +
|
|
581
|
+
'[nestStart…] → recorded activity → [nestEnd…]. Use this to reuse a login flow instead of ' +
|
|
582
|
+
're-recording it.'),
|
|
583
|
+
nestEnd: z.array(z.string()).optional().describe('Existing test case ids to run AFTER the recorded activity, as nested steps (e.g. a Logout ' +
|
|
584
|
+
'test case). They are appended to the produced draft in order.'),
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
// `args` is annotated rather than inferred: the schema above SPREADS cfg.extraInput, whose type is
|
|
588
|
+
// a union across the technologies, so the SDK cannot infer a single concrete arg shape (implicit
|
|
589
|
+
// any). Reading fields off a Record keeps this honest — the agent is the strict validator anyway.
|
|
590
|
+
async (args) => {
|
|
591
|
+
const a = deps.getAdapter();
|
|
592
|
+
if (!a?.callRaw)
|
|
593
|
+
return err('Not connected to a product agent — recording runs on the agent (qa_connect first).');
|
|
594
|
+
const rec = args ?? {};
|
|
595
|
+
const idsOf = (key) => Array.isArray(rec[key]) ? rec[key].map(String) : [];
|
|
596
|
+
let startRefs;
|
|
597
|
+
let endRefs;
|
|
598
|
+
try {
|
|
599
|
+
startRefs = await resolveNestedRefs(a, idsOf('nestStart'));
|
|
600
|
+
endRefs = await resolveNestedRefs(a, idsOf('nestEnd'));
|
|
601
|
+
}
|
|
602
|
+
catch (e) {
|
|
603
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
604
|
+
}
|
|
605
|
+
// Forward `task` plus whichever of this technology's own fields the caller actually supplied.
|
|
606
|
+
// Driven off cfg.extraInput's keys so adding a field to the config is the only edit needed.
|
|
607
|
+
const agentArgs = { task: rec['task'] };
|
|
608
|
+
for (const key of Object.keys(cfg.extraInput)) {
|
|
609
|
+
if (rec[key] !== undefined)
|
|
610
|
+
agentArgs[key] = rec[key];
|
|
611
|
+
}
|
|
612
|
+
if (startRefs.length)
|
|
613
|
+
agentArgs['nestStart'] = startRefs;
|
|
614
|
+
if (endRefs.length)
|
|
615
|
+
agentArgs['nestEnd'] = endRefs;
|
|
616
|
+
// NON-BLOCKING: the agent returns a sessionId immediately (recording runs in the background), so
|
|
617
|
+
// this returns in ms — no long-blocking RPC, no client-timeout-driven retries, no duplicate
|
|
618
|
+
// browser/emulator. The draft is re-homed later, on the status tool's "done".
|
|
619
|
+
try {
|
|
620
|
+
return (await a.callRaw(t.name, agentArgs));
|
|
621
|
+
}
|
|
622
|
+
catch (e) {
|
|
623
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Wrap `core_close_session` with a SAVE GUARD so a tear-down can't silently drop a recorded but
|
|
629
|
+
* unsaved draft (web, mobile, mainframe — any technology). The agent's own close is coarse: it
|
|
630
|
+
* closes every active session (WEB + ANDROID + IOS) at once, and only the browser/driver + device
|
|
631
|
+
* mirror are torn down — the model may still have a `draft_...` in Common that never made it to
|
|
632
|
+
* `tc_save`. This wrapper checks Common's DraftStore for recording-sourced drafts with no `tc.id`
|
|
633
|
+
* and, unless `force:true`, refuses with a list of the offenders and the two ways out (`tc_save` to
|
|
634
|
+
* persist, `tc_draft_discard` to throw away).
|
|
635
|
+
*/
|
|
636
|
+
export function registerCloseSessionWithSaveGuard(server, deps, t) {
|
|
637
|
+
server.registerTool(t.name, {
|
|
638
|
+
description: `${t.description ?? t.name}\n\n` +
|
|
639
|
+
`(Common wraps this with a SAVE GUARD covering BOTH recording paths: (a) delegated-recorder ` +
|
|
640
|
+
`drafts in Common's DraftStore — save with tc_save({draftId}) or discard with ` +
|
|
641
|
+
`tc_draft_discard({draftId}); (b) granular recordings on the Java agent (queried live via ` +
|
|
642
|
+
`core_active_recordings) — save those with tc_save({ sessionId }) (it clicks the recorder ` +
|
|
643
|
+
`window's own Save button, exact parity) or by clicking Save Testcase in the /mcp-recorder ` +
|
|
644
|
+
`window. If either has unsaved work the close is REFUSED and the refusal ` +
|
|
645
|
+
`hands back a ONE-SHOT confirm token. To close AND lose the unsaved steps, call again as ` +
|
|
646
|
+
`core_close_session({ confirm: "<the-token-from-the-refusal>" }) — the browser, driver AND ` +
|
|
647
|
+
`recorder window all tear down. Only redeem the token after the user explicitly says ` +
|
|
648
|
+
`"discard" or "close anyway"; never invent one.)`,
|
|
649
|
+
inputSchema: {
|
|
650
|
+
confirm: z.string().optional().describe('One-shot confirm token minted by this tool in a prior REFUSAL. Only pass it when the ' +
|
|
651
|
+
'user has explicitly said "discard" or "close anyway" after seeing the refusal. Do NOT ' +
|
|
652
|
+
'invent a value — if you don\'t have a token from a prior refusal, call without confirm ' +
|
|
653
|
+
'and the refusal (if any) will give you a fresh one.'),
|
|
654
|
+
keepRecorderOpen: z.boolean().optional().describe('Pass true when the user says "close the browser" / "keep the recorder open": closes the browser, ' +
|
|
655
|
+
'driver and device but KEEPS the recorder window and its captured steps open so they can still be ' +
|
|
656
|
+
'reviewed and saved. Never refused for unsaved steps — nothing is lost.'),
|
|
657
|
+
closeTestcaseWindow: z.boolean().optional().describe('Pass true — ONLY after the user confirms in chat — to close the recorder (testcase) window that a ' +
|
|
658
|
+
'previous keepRecorderOpen / mobile close left open.'),
|
|
659
|
+
},
|
|
660
|
+
}, async (args) => {
|
|
661
|
+
const a = deps.getAdapter();
|
|
662
|
+
if (!a?.callRaw)
|
|
663
|
+
return err('Not connected to a product agent — recording runs on the agent (qa_connect first).');
|
|
664
|
+
const confirmArg = args?.confirm;
|
|
665
|
+
const confirm = typeof confirmArg === 'string' ? confirmArg.trim() : '';
|
|
666
|
+
const bypass = confirm.length > 0 && redeemCloseNonce(confirm);
|
|
667
|
+
// Closing only the browser leaves the steps in the recorder window, so there is nothing to guard.
|
|
668
|
+
const keepRecorderOpen = args?.keepRecorderOpen === true;
|
|
669
|
+
const closeTestcaseWindow = args?.closeTestcaseWindow === true;
|
|
670
|
+
if (!bypass && !keepRecorderOpen) {
|
|
671
|
+
// Two sources of "unsaved":
|
|
672
|
+
// (a) delegated-recorder drafts re-homed into Common's DraftStore (from web/mainframe
|
|
673
|
+
// background recordings polled via *_status).
|
|
674
|
+
// (b) granular recordings live in the JAVA journal (core_activate_technology + *_ verbs).
|
|
675
|
+
// Both must be checked, both must be reported in ONE refusal so the LLM can act on the
|
|
676
|
+
// whole picture. The Java probe is best-effort — if it fails (agent gone, tool not
|
|
677
|
+
// advertised on an older jar), fall back to just (a) so we never widen a failure into
|
|
678
|
+
// a refusal-to-close for the wrong reason.
|
|
679
|
+
const delegatedUnsaved = deps.drafts.listUnsavedRecordings();
|
|
680
|
+
let granularUnsaved = [];
|
|
681
|
+
try {
|
|
682
|
+
const probe = (await a.callRaw('core_active_recordings', {}));
|
|
683
|
+
if (!probe.isError) {
|
|
684
|
+
const sc = probe.structuredContent;
|
|
685
|
+
const rows = Array.isArray(sc?.recordings) ? sc.recordings : [];
|
|
686
|
+
for (const r of rows) {
|
|
687
|
+
const row = r;
|
|
688
|
+
const count = typeof row.stepCount === 'number' ? row.stepCount : 0;
|
|
689
|
+
if (count > 0 && typeof row.sessionId === 'string' && typeof row.mcpSessionKey === 'string') {
|
|
690
|
+
granularUnsaved.push({ sessionId: row.sessionId, mcpSessionKey: row.mcpSessionKey, stepCount: count });
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
catch { /* older jar / no probe — Java's own guard still catches this on forward */ }
|
|
696
|
+
if (delegatedUnsaved.length || granularUnsaved.length) {
|
|
697
|
+
const lines = [];
|
|
698
|
+
if (delegatedUnsaved.length) {
|
|
699
|
+
lines.push(`Unsaved DELEGATED-recorder draft(s) (save with tc_save or discard with tc_draft_discard):`);
|
|
700
|
+
for (const u of delegatedUnsaved) {
|
|
701
|
+
lines.push(` • draftId: ${u.draftId} — "${u.title}" (recording session ${u.sessionId})`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
if (granularUnsaved.length) {
|
|
705
|
+
lines.push(`Unsaved GRANULAR recording(s) — save with tc_save({ sessionId }) (clicks the recorder's Save) or click Save Testcase in the /mcp-recorder window:`);
|
|
706
|
+
for (const g of granularUnsaved) {
|
|
707
|
+
lines.push(` • session ${g.sessionId} (${g.mcpSessionKey}) — ${g.stepCount} step(s)`);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const nonce = mintCloseNonce();
|
|
711
|
+
return err(`Refusing to close: ${delegatedUnsaved.length + granularUnsaved.length} recording(s) are NOT saved yet.\n` +
|
|
712
|
+
`${lines.join('\n')}\n\n` +
|
|
713
|
+
`ASK the user what to do:\n` +
|
|
714
|
+
` • KEEP THE RECORDER — if they only want the BROWSER closed ("close the browser"), call ` +
|
|
715
|
+
`core_close_session({ keepRecorderOpen: true }): the browser/driver close, the recorder window and its ` +
|
|
716
|
+
`steps stay open to review and save. Nothing is lost.\n` +
|
|
717
|
+
` • SAVE — for a delegated draft, tc_save({ draftId: "<id>" }); for a granular ` +
|
|
718
|
+
`recording, tc_save({ sessionId: "<session id>" }) (clicks the recorder's own Save, ` +
|
|
719
|
+
`exact parity) or tell the user to click Save Testcase in the recorder window.\n` +
|
|
720
|
+
` • DISCARD — for a delegated draft, tc_draft_discard({ draftId: "<id>" }); then retry close.\n` +
|
|
721
|
+
` • CLOSE ANYWAY — call core_close_session({ confirm: "${nonce}" }) to tear down the ` +
|
|
722
|
+
`browser, driver AND recorder window (all captured steps above are LOST). This token ` +
|
|
723
|
+
`is one-shot, valid for 5 minutes, tied to THIS refusal. Only redeem it after the ` +
|
|
724
|
+
`user literally says "discard" or "close anyway" — never invent a token.`);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
// Forward to Java. `force:true` goes over the wire ONLY when Common has just redeemed a
|
|
728
|
+
// valid confirm nonce it minted itself — never in response to a raw `force` argument from
|
|
729
|
+
// the client. That means a caller who skips the two-call ceremony (e.g. an LLM that decides
|
|
730
|
+
// on its own to bypass) still faces Java's own save-guard for GRANULAR recordings. Both
|
|
731
|
+
// guards must clear.
|
|
732
|
+
const forward = bypass ? { force: true } : {};
|
|
733
|
+
if (keepRecorderOpen)
|
|
734
|
+
forward['keepRecorderOpen'] = true;
|
|
735
|
+
if (closeTestcaseWindow)
|
|
736
|
+
forward['closeTestcaseWindow'] = true;
|
|
737
|
+
try {
|
|
738
|
+
return (await a.callRaw(t.name, forward));
|
|
739
|
+
}
|
|
740
|
+
catch (e) {
|
|
741
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* SimplifyQA-only wrapper around `core_activate_technology`. Enforces the mobile question sequence
|
|
747
|
+
* — "Android or iOS?" then "which device?" — AND the WEB AI-only-vs-AI+Manual question, on EVERY call, not
|
|
748
|
+
* just the first of the session. The bugs this fixes: the underlying tool takes `technology` as a
|
|
749
|
+
* bare required string, so an LLM that silently reuses the previous session's pick or infers a
|
|
750
|
+
* platform from a vague prompt ("record an app") passes schema validation and starts recording on
|
|
751
|
+
* the wrong device with no re-prompt; likewise `recordingMode` defaults to AI, so a WEB recording
|
|
752
|
+
* started without asking silently drops the user's own manual clicks.
|
|
753
|
+
*
|
|
754
|
+
* Enforcement is per-rung:
|
|
755
|
+
* 1. `technology` — schema-required (Java-side).
|
|
756
|
+
* 2. Mobile (ANDROID/IOS) → `deviceId` MUST be present. Refusal names the fresh discovery call
|
|
757
|
+
* the LLM has to make (`android_list_devices` / `ios_list_devices`) so the user's picking off
|
|
758
|
+
* the CURRENT roster, not a stale memory of last session's udids.
|
|
759
|
+
* 3. Mobile → `platformAskedUser` MUST match `technology`. This is a "did you ask?" checkbox the
|
|
760
|
+
* LLM has to fill AFTER asking the user "Android or iOS?". Same soft ceiling as every other
|
|
761
|
+
* cascade in this file — the LLM can fabricate — but it makes the choice explicit in the
|
|
762
|
+
* call, so the ceiling matches deviceType/cloudDeviceType across the file.
|
|
763
|
+
* 4. WEB → `recordingModeAskedUser` MUST match `recordingMode` (AI|HYBRID; both canonicalised so
|
|
764
|
+
* "AI + Manual"/"manual" also map to HYBRID) and both MUST be present. Makes the AI-only vs
|
|
765
|
+
* AI + Manual choice explicit on every recording instead of letting the agent's AI default win
|
|
766
|
+
* — but if the user already named the mode in their request the agent sets it from that without
|
|
767
|
+
* re-asking. Only WEB is gated — AI + Manual (HYBRID) is a browser-extension feature.
|
|
768
|
+
*
|
|
769
|
+
* MAINFRAME (and every non-WEB/MOBILE technology) is forwarded verbatim — the extra rungs fire
|
|
770
|
+
* only for the technologies they apply to.
|
|
771
|
+
*/
|
|
772
|
+
function registerActivateTechnologyWithMobileGuard(server, deps, t) {
|
|
773
|
+
// Merge the agent's schema with our added rungs. Fresh object so the JSON-schema→zod conversion
|
|
774
|
+
// output (which may be typed as readonly) isn't mutated in place.
|
|
775
|
+
const base = jsonSchemaToShape(t.inputSchema) ?? {};
|
|
776
|
+
const shape = {
|
|
777
|
+
...base,
|
|
778
|
+
platformAskedUser: z.enum(['android', 'ios']).optional().describe('REQUIRED when technology is ANDROID or IOS. Set to the platform the USER explicitly named ' +
|
|
779
|
+
'after you ASKED them "Android or iOS?". If the user\'s prompt already named the platform ' +
|
|
780
|
+
'("record an iOS app…"), set it to that; otherwise ASK first, then set. Do NOT reuse a ' +
|
|
781
|
+
'previous session\'s answer. Must match `technology` (case-insensitive). The tool refuses ' +
|
|
782
|
+
'mobile recordings without this, so a silent tool-side pick can\'t sneak through.'),
|
|
783
|
+
deviceTypeAskedUser: z.enum(['real_device', 'cloud_device', 'virtual_device']).optional().describe('REQUIRED when technology is ANDROID or IOS. The device category the USER chose after you ' +
|
|
784
|
+
'ASKED them "Real Device, Cloud Device, or Virtual Device?". If the user\'s prompt already ' +
|
|
785
|
+
'named it ("record on LambdaTest" → cloud_device, "record on my iPhone" → real_device, ' +
|
|
786
|
+
'"record on simulator" → virtual_device), set it from that WITHOUT re-asking; otherwise ' +
|
|
787
|
+
'ASK. This determines which listing tool to call and which `provider` to pass:\n' +
|
|
788
|
+
' • real_device → call `mobile_list_devices` / the platform list tool, pick a physical device, provider=local\n' +
|
|
789
|
+
' • cloud_device → call `cloud_list_devices` with the platform, pick a cloud device, ' +
|
|
790
|
+
'provider from the row (lambdatest/browserstack/saucelabs/simplifyqa)\n' +
|
|
791
|
+
' • virtual_device → call `mobile_list_devices` / the platform list tool, pick an ' +
|
|
792
|
+
'emulator (Android) or simulator (iOS), provider=emulator or provider=simulator\n' +
|
|
793
|
+
'The tool refuses mobile recordings without this.'),
|
|
794
|
+
recordingModeAskedUser: z.string().optional().describe('REQUIRED for WEB recordings. The recording mode the user chose: ' +
|
|
795
|
+
'"ai" for AI-only, or "hybrid" (equivalently "ai+manual") for AI + Manual. This is the ' +
|
|
796
|
+
'FIRST question asked — before platform, device type, or anything else. If the user ' +
|
|
797
|
+
'ALREADY named the mode in THIS request ("AI-only", "AI + Manual"/"hybrid"), set it from ' +
|
|
798
|
+
'that WITHOUT re-asking; otherwise ASK "AI-only or AI + Manual?" for THIS recording. ' +
|
|
799
|
+
'Do NOT reuse a previous recording\'s choice unless the user explicitly says "same as ' +
|
|
800
|
+
'last time". Must match `recordingMode` ("AI + Manual" = "HYBRID"). The tool refuses ' +
|
|
801
|
+
'WEB recordings without this, so a silent default can\'t skip the question.\n' +
|
|
802
|
+
'FOR ANDROID / IOS: always set recordingMode="AI" and recordingModeAskedUser="AI" — ' +
|
|
803
|
+
'AI + Manual (HYBRID) is a browser-extension feature and is NOT supported on mobile. ' +
|
|
804
|
+
'Do NOT ask the user; just default to AI.'),
|
|
805
|
+
};
|
|
806
|
+
server.registerTool(t.name, {
|
|
807
|
+
description: `${t.description ?? t.name}${RECORDING_MODE_PROMPT}\n\n` +
|
|
808
|
+
`⚠️ ALL RECORDINGS — EVERY session, WITHOUT EXCEPTION, follow these steps in ORDER:\n` +
|
|
809
|
+
` 0. RECORDING MODE:\n` +
|
|
810
|
+
` • WEB → ASK "AI-only or AI + Manual?" FIRST — before anything else. ` +
|
|
811
|
+
`Set \`recordingMode\` ("AI" or "HYBRID") and \`recordingModeAskedUser\` to the same.\n` +
|
|
812
|
+
` • ANDROID / IOS → AI + Manual is NOT supported (browser-extension feature). ` +
|
|
813
|
+
`Always set recordingMode="AI" and recordingModeAskedUser="AI" automatically — do NOT ask.\n` +
|
|
814
|
+
` • API / DATABASE → AI + Manual does NOT apply (there is no browser to capture). ` +
|
|
815
|
+
`Always set recordingMode="AI" and recordingModeAskedUser="AI" automatically — do NOT ask.\n\n` +
|
|
816
|
+
`⚠️ MOBILE (technology ANDROID/IOS) — after setting recordingMode="AI", continue:\n` +
|
|
817
|
+
` 1. ASK the user "Android or iOS?" if their prompt did not explicitly name a platform ` +
|
|
818
|
+
`("record an app" is NOT an answer). Never infer, never reuse a previous session's pick.\n` +
|
|
819
|
+
` 2. Set BOTH \`technology\` and \`platformAskedUser\` to that answer.\n` +
|
|
820
|
+
` 3. ASK the user "Real Device, Cloud Device, or Virtual Device?" if their prompt did ` +
|
|
821
|
+
`not already indicate one (e.g. "LambdaTest" → cloud_device, "my iPhone" → real_device, ` +
|
|
822
|
+
`"simulator" → virtual_device). Set \`deviceTypeAskedUser\` to their choice.\n` +
|
|
823
|
+
` 4. Based on device type:\n` +
|
|
824
|
+
` • real_device → call \`mobile_list_devices\` / \`android_list_devices\` / ` +
|
|
825
|
+
`\`ios_list_devices\`, pick a physical device, set provider=local\n` +
|
|
826
|
+
` • cloud_device → call \`cloud_list_devices\` with the platform, pick a cloud ` +
|
|
827
|
+
`device, set provider from the row (lambdatest/browserstack/saucelabs)\n` +
|
|
828
|
+
` • virtual_device → call \`mobile_list_devices\` / the platform list tool, pick an ` +
|
|
829
|
+
`emulator (Android) or simulator (iOS), set provider=emulator or provider=simulator\n` +
|
|
830
|
+
` 5. Show the user the returned rows, let them pick, pass the row's udid as \`deviceId\`.\n` +
|
|
831
|
+
`The tool refuses each rung it doesn't get, so skipping one just wastes a round-trip.\n\n` +
|
|
832
|
+
`(Agent-bound tool — runs on the connected product agent, forwarded through the Common MCP.)`,
|
|
833
|
+
inputSchema: shape,
|
|
834
|
+
}, async (args = {}) => {
|
|
835
|
+
const a = deps.getAdapter();
|
|
836
|
+
if (!a?.callRaw)
|
|
837
|
+
return err('Not connected to a product agent — recording runs on the agent (qa_connect first).');
|
|
838
|
+
const technologyRaw = typeof args['technology'] === 'string' ? args['technology'] : '';
|
|
839
|
+
const technology = technologyRaw.toUpperCase();
|
|
840
|
+
const mobile = technology === 'ANDROID' || technology === 'IOS';
|
|
841
|
+
// Rung 0 — recording mode. ANDROID / IOS are always AI-only (HYBRID is a browser-extension
|
|
842
|
+
// feature). API and DATABASE are non-browser too, so they are AI-only as well — asking
|
|
843
|
+
// "AI-only or AI + Manual?" for them is meaningless and must not happen. For WEB, make the
|
|
844
|
+
// AI-only vs AI + Manual choice EXPLICIT on EVERY recording.
|
|
845
|
+
const modeForced = mobile || technology === 'API' || technology === 'DATABASE';
|
|
846
|
+
if (modeForced) {
|
|
847
|
+
// No browser extension for mobile / API / DATABASE — AI + Manual (HYBRID) does not apply.
|
|
848
|
+
args['recordingMode'] = 'AI';
|
|
849
|
+
args['recordingModeAskedUser'] = 'AI';
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
// WEB: the marker (recordingModeAskedUser) must match recordingMode; both are
|
|
853
|
+
// canonicalised so "AI + Manual", "manual" and "hybrid" are all understood and map to the
|
|
854
|
+
// backend enum HYBRID. If the user already named the mode in their request the agent sets
|
|
855
|
+
// the marker from that (see the field description) — it does NOT have to re-ask. A
|
|
856
|
+
// missing/mismatched marker is refused with the exact question. This is the FIRST question
|
|
857
|
+
// asked — before platform, device type, or anything else.
|
|
858
|
+
const canonMode = canonRecordingMode(args['recordingMode']);
|
|
859
|
+
const canonAsked = canonRecordingMode(args['recordingModeAskedUser']);
|
|
860
|
+
if (!canonMode || canonAsked !== canonMode) {
|
|
861
|
+
return err(`Refusing to start a ${technology || '(unknown)'} recording: the AI-only vs AI + Manual ` +
|
|
862
|
+
`choice for THIS recording isn't set. If the user ALREADY named it in their request ` +
|
|
863
|
+
`("AI-only", "AI + Manual"/"hybrid"), use that; otherwise ASK FIRST: "AI-only (records ` +
|
|
864
|
+
`only the steps I drive) or AI + Manual (also records your own clicks)?" — do NOT reuse ` +
|
|
865
|
+
`an earlier recording's answer unless they say "same as last time". Then retry ` +
|
|
866
|
+
`\`core_activate_technology\` with \`recordingMode\` set to "AI" or "HYBRID" ` +
|
|
867
|
+
`(AI + Manual = HYBRID) AND \`recordingModeAskedUser\` set to the same choice. ` +
|
|
868
|
+
(canonMode && canonAsked && canonAsked !== canonMode
|
|
869
|
+
? `(You passed recordingModeAskedUser='${String(args['recordingModeAskedUser'])}' but ` +
|
|
870
|
+
`recordingMode='${String(args['recordingMode'])}' — those contradict; the user's ` +
|
|
871
|
+
`answer must drive BOTH.)`
|
|
872
|
+
: ''));
|
|
873
|
+
}
|
|
874
|
+
// Normalise to the backend enum so "AI + Manual"/"manual" still enables HYBRID downstream.
|
|
875
|
+
args['recordingMode'] = canonMode === 'hybrid' ? 'HYBRID' : 'AI';
|
|
876
|
+
}
|
|
877
|
+
if (mobile) {
|
|
878
|
+
const platform = technology.toLowerCase();
|
|
879
|
+
const listTool = platform === 'android' ? 'android_list_devices' : 'ios_list_devices';
|
|
880
|
+
const asked = typeof args['platformAskedUser'] === 'string'
|
|
881
|
+
? args['platformAskedUser'].toLowerCase()
|
|
882
|
+
: undefined;
|
|
883
|
+
// Rung 1 — force the platform question. Refuse when the LLM committed to technology
|
|
884
|
+
// without an explicit "I asked" marker matching it.
|
|
885
|
+
if (asked !== platform) {
|
|
886
|
+
return err(`Refusing to start a ${technology} recording: no evidence the user was asked which ` +
|
|
887
|
+
`mobile platform to use. ASK the user: "Android or iOS?" — do NOT infer from the ` +
|
|
888
|
+
`prompt (e.g. "record an app" gives NO platform), and do NOT reuse a previous ` +
|
|
889
|
+
`session's answer. After they answer, retry \`core_activate_technology\` with ` +
|
|
890
|
+
`\`platformAskedUser\` set to their choice AND \`technology\` matching it. ` +
|
|
891
|
+
(asked && asked !== platform
|
|
892
|
+
? `(You passed platformAskedUser='${asked}' but technology='${technology}' — those ` +
|
|
893
|
+
`contradict. The user's answer must drive BOTH.)`
|
|
894
|
+
: ''));
|
|
895
|
+
}
|
|
896
|
+
// Rung 2 — force the device TYPE question. The user must choose Real Device, Cloud Device,
|
|
897
|
+
// or Virtual Device before listing devices — it determines which listing tool to call and
|
|
898
|
+
// which `provider` to pass to the agent.
|
|
899
|
+
const deviceType = typeof args['deviceTypeAskedUser'] === 'string'
|
|
900
|
+
? args['deviceTypeAskedUser'].toLowerCase()
|
|
901
|
+
: undefined;
|
|
902
|
+
const validDeviceTypes = ['real_device', 'cloud_device', 'virtual_device'];
|
|
903
|
+
if (!deviceType || !validDeviceTypes.includes(deviceType)) {
|
|
904
|
+
const virtualLabel = platform === 'android' ? 'Emulator' : 'Simulator';
|
|
905
|
+
return err(`Refusing to start a ${technology} recording: no device type chosen. ASK the user: ` +
|
|
906
|
+
`"Real Device, Cloud Device, or Virtual Device (${virtualLabel})?" — if their prompt ` +
|
|
907
|
+
`already named one (e.g. "LambdaTest" → cloud_device, "my iPhone" → real_device, ` +
|
|
908
|
+
`"simulator"/"emulator" → virtual_device), use it WITHOUT re-asking. Then retry ` +
|
|
909
|
+
`\`core_activate_technology\` with \`deviceTypeAskedUser\` set to their choice.\n\n` +
|
|
910
|
+
`Based on their choice:\n` +
|
|
911
|
+
` • real_device → call \`mobile_list_devices\` or \`${listTool}\`, pick a physical device, set provider="local"\n` +
|
|
912
|
+
` • cloud_device → call \`cloud_list_devices\` with platform="${platform}", pick a device, set provider from the row (lambdatest/browserstack/saucelabs)\n` +
|
|
913
|
+
` • virtual_device → call \`mobile_list_devices\` or \`${listTool}\`, pick a ${virtualLabel.toLowerCase()}, set provider="${platform === 'android' ? 'emulator' : 'simulator'}"`);
|
|
914
|
+
}
|
|
915
|
+
// Rung 3 — force the device question. deviceId is per-session (devices plug/unplug) so
|
|
916
|
+
// the LLM must call the listing tool fresh AND let the user pick.
|
|
917
|
+
const deviceId = typeof args['deviceId'] === 'string' ? args['deviceId'].trim() : '';
|
|
918
|
+
const listToolHint = deviceType === 'cloud_device'
|
|
919
|
+
? `\`cloud_list_devices\` with platform="${platform}"`
|
|
920
|
+
: `\`${listTool}\` or \`mobile_list_devices\``;
|
|
921
|
+
if (!deviceId) {
|
|
922
|
+
return err(`${technology} recording needs \`deviceId\`. Call ${listToolHint} FRESH this session ` +
|
|
923
|
+
`(the connected roster changes between sessions — do NOT reuse a udid from an ` +
|
|
924
|
+
`earlier call), show the user the returned rows and ASK which device they want to ` +
|
|
925
|
+
`record on, then retry with the picked row's udid as \`deviceId\`.`);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
// Duplicate-name guard: the recorder's Save button persists a NEW test case under `testcaseName`,
|
|
929
|
+
// so a clashing name has to be caught here, before the recording is started. Skipped for edit
|
|
930
|
+
// sessions (mcpTcEditSessionId), for EXISTING-TC re-records (testcaseId — the name IS the target
|
|
931
|
+
// TC's name) and when the user confirmed. Best-effort — lookup failure never blocks.
|
|
932
|
+
const tcName = typeof args['testcaseName'] === 'string' ? args['testcaseName'].trim() : '';
|
|
933
|
+
if (tcName && !args['mcpTcEditSessionId'] && !args['testcaseId'] && args['allowDuplicateName'] !== true) {
|
|
934
|
+
try {
|
|
935
|
+
const hits = await a.listTestCases({ search: tcName, limit: 50 });
|
|
936
|
+
const dup = hits.find((x) => x.title.trim().toLowerCase() === tcName.toLowerCase());
|
|
937
|
+
if (dup) {
|
|
938
|
+
return err(`Refusing to start recording: a test case named "${tcName}" already exists (${dup.code ?? dup.id}). ` +
|
|
939
|
+
'ASK the user: use a different `testcaseName`, or — if they really want a second test case with ' +
|
|
940
|
+
'the same name — retry with `allowDuplicateName: true`.');
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
catch {
|
|
944
|
+
// lookup failed — proceed
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
// platformAskedUser / deviceTypeAskedUser / recordingModeAskedUser / allowDuplicateName are
|
|
948
|
+
// intercept-only — the Java tool doesn't know about them, so don't leak them downstream.
|
|
949
|
+
const forwarded = {};
|
|
950
|
+
for (const k of Object.keys(args)) {
|
|
951
|
+
if (k !== 'platformAskedUser' && k !== 'deviceTypeAskedUser'
|
|
952
|
+
&& k !== 'recordingModeAskedUser' && k !== 'allowDuplicateName') {
|
|
953
|
+
forwarded[k] = args[k];
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
try {
|
|
957
|
+
const res = (await a.callRaw(t.name, forwarded));
|
|
958
|
+
// Remember the name for tc_save's journal fallback, which otherwise names the test case by session id.
|
|
959
|
+
const sid = res?.structuredContent?.sessionId;
|
|
960
|
+
if (!res?.isError && tcName && typeof sid === 'string')
|
|
961
|
+
rememberRecordingName(sid, tcName);
|
|
962
|
+
return res;
|
|
963
|
+
}
|
|
964
|
+
catch (e) {
|
|
965
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Register a delegated recorder's POLL tool (`web_status`, `mainframe_status`) — and with it THE DRAFT
|
|
971
|
+
* BRIDGE. While the recording is running the downstream result is forwarded verbatim; on "done" the
|
|
972
|
+
* agent's assembled TestCase is re-registered in COMMON's DraftStore, because that is the only store
|
|
973
|
+
* `tc_save` can read. Without this hop a finished recording would be visible but unsaveable.
|
|
974
|
+
*/
|
|
975
|
+
function registerDelegatedStatus(server, deps, t, cfg) {
|
|
976
|
+
const starter = t.name.replace(/_status$/, '');
|
|
977
|
+
server.registerTool(t.name, {
|
|
978
|
+
description: `${t.description ?? t.name}\n\n(Poll a recording started by ${starter}(). While it reports ` +
|
|
979
|
+
`"recording", call it again after ~15-20 SECONDS — never minutes, since the recording's MINUTES-long ` +
|
|
980
|
+
`DURATION is not a poll interval. On "done" this re-homes the assembled draft into Common's store and ` +
|
|
981
|
+
`returns a Common draftId — review the steps, then tc_save({ draftId }) to persist.)`,
|
|
982
|
+
inputSchema: { sessionId: z.string().describe(`The sessionId returned by ${starter}().`) },
|
|
983
|
+
annotations: { readOnlyHint: true },
|
|
984
|
+
}, async (args) => {
|
|
985
|
+
const a = deps.getAdapter();
|
|
986
|
+
if (!a?.callRaw)
|
|
987
|
+
return err('Not connected to a product agent — recording runs on the agent (qa_connect first).');
|
|
988
|
+
let res;
|
|
989
|
+
try {
|
|
990
|
+
res = (await a.callRaw(t.name, { sessionId: args.sessionId }));
|
|
991
|
+
}
|
|
992
|
+
catch (e) {
|
|
993
|
+
return err(e instanceof Error ? e.message : String(e));
|
|
994
|
+
}
|
|
995
|
+
if (res.isError)
|
|
996
|
+
return res; // recording error — forward verbatim
|
|
997
|
+
const sc = res.structuredContent;
|
|
998
|
+
if (sc?.status !== 'done' || !sc.tc)
|
|
999
|
+
return res; // still recording → forward as-is
|
|
1000
|
+
// Tag the draft with its recording sessionId (the one polled with, or echoed back) so tc_save can
|
|
1001
|
+
// close this recording's live-steps window on the agent once it's saved through the MCP path.
|
|
1002
|
+
const recSessionId = (typeof args.sessionId === 'string' ? args.sessionId : undefined)
|
|
1003
|
+
?? sc.sessionId;
|
|
1004
|
+
const draftId = deps.drafts.create(sc.tc, recSessionId);
|
|
1005
|
+
const stored = deps.drafts.get(draftId).tc;
|
|
1006
|
+
const stepCount = Array.isArray(stored.steps) ? stored.steps.length : (sc.stepCount ?? 0);
|
|
1007
|
+
return ok(`${sc.summary ?? cfg.doneLabel}\n\nRegistered as draft ${draftId} ` +
|
|
1008
|
+
`(${stepCount} step${stepCount === 1 ? '' : 's'}). This is an UNSAVED draft — SHOW these steps ` +
|
|
1009
|
+
`to the user and ASK whether to save. Do NOT save automatically: finishing a recording is NOT a ` +
|
|
1010
|
+
`save instruction. Call tc_save({ draftId: "${draftId}" }) ONLY after the user EXPLICITLY says to ` +
|
|
1011
|
+
`save (e.g. "save it"). The user may also save it themselves in the product UI.`, { status: 'done', draftId, tc: stored, stepCount, ...(sc.summary ? { summary: sc.summary } : {}) });
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Resolve existing test-case ids to { tcId, name } refs for a delegated recorder to compose as nested
|
|
1016
|
+
* steps DURING recording. Titles come from getTestCase, so a wrong id fails BEFORE a recording is
|
|
1017
|
+
* wasted; the id is passed through as-is (function_call_data.test_case_id is a String — a business key
|
|
1018
|
+
* TC_123 or a Mongo _id both persist). The agent builds the actual function steps in-session so the
|
|
1019
|
+
* live editor renders + saves them.
|
|
1020
|
+
*/
|
|
1021
|
+
async function resolveNestedRefs(adapter, tcIds) {
|
|
1022
|
+
const refs = [];
|
|
1023
|
+
for (const id of tcIds) {
|
|
1024
|
+
let name = id;
|
|
1025
|
+
try {
|
|
1026
|
+
const child = await adapter.getTestCase(id);
|
|
1027
|
+
if (child?.title)
|
|
1028
|
+
name = child.title;
|
|
1029
|
+
}
|
|
1030
|
+
catch {
|
|
1031
|
+
throw new Error(`Cannot reuse test case "${id}" as a nested step — it was not found (check the id).`);
|
|
1032
|
+
}
|
|
1033
|
+
refs.push({ tcId: id, name });
|
|
1034
|
+
}
|
|
1035
|
+
return refs;
|
|
1036
|
+
}
|
|
1037
|
+
/** Poll until the shared connection is live and its adapter can enumerate the agent's tools. */
|
|
1038
|
+
async function waitForConnectedAdapter(deps, timeoutMs) {
|
|
1039
|
+
const start = Date.now();
|
|
1040
|
+
while (Date.now() - start < timeoutMs) {
|
|
1041
|
+
if (deps.isConnected()) {
|
|
1042
|
+
const a = deps.getAdapter();
|
|
1043
|
+
if (a?.listAgentTools)
|
|
1044
|
+
return a;
|
|
1045
|
+
}
|
|
1046
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
1047
|
+
}
|
|
1048
|
+
return deps.isConnected() ? deps.getAdapter() : null;
|
|
1049
|
+
}
|
|
1050
|
+
//# sourceMappingURL=recording.tools.js.map
|