testdriverai 4.1.13 → 4.1.15

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/agent.js CHANGED
@@ -648,8 +648,7 @@ const firstPrompt = async () => {
648
648
  if (!input.trim().length) return promptUser();
649
649
 
650
650
  emitter.emit(events.interactive, false);
651
- await setTerminalApp();
652
- // setTerminalWindowTransparency(true);
651
+ setTerminalWindowTransparency(true);
653
652
  errorCounts = {};
654
653
 
655
654
  // append this to commandHistoryFile
@@ -682,7 +681,7 @@ const firstPrompt = async () => {
682
681
  await humanInput(input, true);
683
682
  }
684
683
 
685
- // setTerminalWindowTransparency(false);
684
+ setTerminalWindowTransparency(false);
686
685
  promptUser();
687
686
  });
688
687
 
@@ -725,6 +724,7 @@ New commands will be appended.
725
724
  };
726
725
 
727
726
  let setTerminalWindowTransparency = async (hide) => {
727
+
728
728
  if (hide) {
729
729
  try {
730
730
  http
@@ -751,6 +751,7 @@ let setTerminalWindowTransparency = async (hide) => {
751
751
  return;
752
752
  }
753
753
 
754
+
754
755
  try {
755
756
  if (hide) {
756
757
  if (terminalApp) {
@@ -774,7 +775,6 @@ let summarize = async (error = null) => {
774
775
 
775
776
  log.log("info", "");
776
777
 
777
- log.log("info", chalk.cyan("summarizing"));
778
778
  log.log("info", chalk.dim("reviewing test..."), true);
779
779
 
780
780
  // let text = prompts.summarize(tasks, error);
@@ -936,9 +936,9 @@ const promptUser = () => {
936
936
  rl.prompt(true);
937
937
  };
938
938
 
939
- const setTerminalApp = async () => {
939
+ const setTerminalApp = async (win) => {
940
+
940
941
  if (terminalApp) return;
941
- let win = await system.activeWin();
942
942
  if (process.platform === "win32") {
943
943
  terminalApp = win?.title || "";
944
944
  } else {
@@ -998,7 +998,8 @@ const embed = async (file, depth) => {
998
998
  log.log("info", `${file} (end)`);
999
999
  };
1000
1000
 
1001
- (async () => {
1001
+ const start = async () => {
1002
+
1002
1003
  // console.log(await system.getPrimaryDisplay());
1003
1004
 
1004
1005
  // @todo add-auth
@@ -1042,7 +1043,6 @@ const embed = async (file, depth) => {
1042
1043
  console.log("");
1043
1044
  }
1044
1045
 
1045
- await setTerminalApp();
1046
1046
 
1047
1047
  // should be start of new session
1048
1048
  const sessionRes = await sdk.req("session/start", {
@@ -1063,7 +1063,7 @@ const embed = async (file, depth) => {
1063
1063
  } else if (thisCommand == "init") {
1064
1064
  init();
1065
1065
  }
1066
- })();
1066
+ };
1067
1067
 
1068
1068
  process.on("uncaughtException", async (err) => {
1069
1069
  analytics.track("uncaughtException", { err });
@@ -1078,3 +1078,8 @@ process.on("unhandledRejection", async (reason, promise) => {
1078
1078
  // Optionally, you might want to exit the process
1079
1079
  await exit(true);
1080
1080
  });
1081
+
1082
+ module.exports = {
1083
+ setTerminalApp,
1084
+ start
1085
+ };
@@ -39,7 +39,10 @@ app.whenReady().then(() => {
39
39
  visibleOnFullScreen: true,
40
40
  });
41
41
  window.loadFile("overlay.html");
42
- window.show();
42
+
43
+ window.once('ready-to-show', () => {
44
+ window.showInactive();
45
+ });
43
46
 
44
47
  // open developer tools
45
48
  // window.webContents.openDevTools();
package/index.js CHANGED
@@ -1,37 +1,49 @@
1
1
  #!/usr/bin/env node
2
2
  const config = require("./lib/config.js");
3
+ const system = require("./lib/system.js");
3
4
  const { emitter, events } = require("./lib/events.js");
4
5
 
5
- if (!config.TD_OVERLAY) {
6
- require("./agent.js");
7
- } else {
8
- // Intercept all stdout and stderr calls (works with console as well)
9
- const originalStdoutWrite = process.stdout.write.bind(process.stdout);
10
- process.stdout.write = (...args) => {
11
- const [data, encoding] = args;
12
- emitter.emit(
13
- events.terminal.stdout,
14
- data.toString(typeof encoding === "string" ? encoding : undefined),
15
- );
16
- originalStdoutWrite(...args);
17
- };
6
+ (async () => {
18
7
 
19
- const originalStderrWrite = process.stderr.write.bind(process.stderr);
20
- process.stderr.write = (...args) => {
21
- const [data, encoding] = args;
22
- emitter.emit(
23
- events.terminal.stderr,
24
- data.toString(typeof encoding === "string" ? encoding : undefined),
25
- );
26
- originalStderrWrite(...args);
27
- };
8
+ let win = await system.activeWin();
28
9
 
29
- require("./lib/overlay.js")
30
- .electronProcessPromise.then(() => {
31
- require("./agent.js");
32
- })
33
- .catch((err) => {
34
- console.error(err);
35
- process.exit(1);
36
- });
37
- }
10
+ if (!config.TD_OVERLAY) {
11
+ let agent = require("./agent.js");
12
+ agent.setTerminalApp(win);
13
+ agent.start();
14
+ } else {
15
+ // Intercept all stdout and stderr calls (works with console as well)
16
+ const originalStdoutWrite = process.stdout.write.bind(process.stdout);
17
+ process.stdout.write = (...args) => {
18
+ const [data, encoding] = args;
19
+ emitter.emit(
20
+ events.terminal.stdout,
21
+ data.toString(typeof encoding === "string" ? encoding : undefined),
22
+ );
23
+ originalStdoutWrite(...args);
24
+ };
25
+
26
+ const originalStderrWrite = process.stderr.write.bind(process.stderr);
27
+ process.stderr.write = (...args) => {
28
+ const [data, encoding] = args;
29
+ emitter.emit(
30
+ events.terminal.stderr,
31
+ data.toString(typeof encoding === "string" ? encoding : undefined),
32
+ );
33
+ originalStderrWrite(...args);
34
+ };
35
+
36
+ require("./lib/overlay.js")
37
+ .electronProcessPromise.then(() => {
38
+ let agent = require("./agent.js");
39
+ agent.setTerminalApp(win);
40
+ agent.start();
41
+ })
42
+ .catch((err) => {
43
+ console.error(err);
44
+ process.exit(1);
45
+ });
46
+ }
47
+
48
+
49
+ })()
package/lib/config.js CHANGED
@@ -28,7 +28,7 @@ const config = {
28
28
  TD_API_ROOT: "https://api.testdriver.ai",
29
29
  TD_DEV: parseValue(process.env["DEV"]),
30
30
  TD_PROFILE: false,
31
- TD_OVERLAY: true,
31
+ TD_OVERLAY: true
32
32
  };
33
33
 
34
34
  // Find all env vars starting with TD_
@@ -3,20 +3,25 @@ const path = require("path");
3
3
  const { execSync } = require("child_process");
4
4
  const { platform } = require("./system");
5
5
  const scriptPath = path.join(__dirname, "focusWindow.ps1");
6
+ const robot = require("robotjs");
6
7
 
7
8
  // apple script that focuses on a window
8
- const appleScriptFocus = (windowName) => `
9
+ const appleScriptSetFrontmost = (windowName) => `
9
10
  tell application "System Events" to tell process "${windowName}"
10
11
  set frontmost to true
11
12
  end tell`;
12
13
 
13
- const appleScriptMin = (windowName) => `
14
- tell application "System Events"
15
- set value of attribute "AXMinimized" of every window of application process "${windowName}" to true
16
- end tell`;
14
+ // const appleScriptAXMinimized = (windowName) => `
15
+ // tell application "System Events"
16
+ // set value of attribute "AXMinimized" of every window of application process "${windowName}" to true
17
+ // end tell`;
18
+
19
+ // const appleScriptActivate = (windowName) => `
20
+ // tell application "${windowName}" to activate
21
+ // `;
17
22
 
18
- const appleScriptMax = (windowName) => `
19
- tell application "${windowName}" to activate
23
+ const appleScriptOpen = (windowName) => `
24
+ open -a "${windowName}"
20
25
  `;
21
26
 
22
27
  const runPwsh = (appName, method) => {
@@ -27,7 +32,7 @@ const runPwsh = (appName, method) => {
27
32
  async function focusApplication(appName) {
28
33
  try {
29
34
  if (platform() == "mac") {
30
- return await execSync(`osascript -e '${appleScriptFocus(appName)}'`);
35
+ return await execSync(`osascript -e '${appleScriptSetFrontmost(appName)}'`);
31
36
  } else if (platform() == "linux") {
32
37
  // TODO: This needs fixing
33
38
  return;
@@ -42,7 +47,8 @@ async function focusApplication(appName) {
42
47
  async function hideTerminal(appName) {
43
48
  try {
44
49
  if (platform() == "mac") {
45
- return await execSync(`osascript -e '${appleScriptMin(appName)}'`);
50
+ robot.keyTap('m', ['command']);
51
+ robot.keyToggle('command', 'up')
46
52
  } else if (platform() == "windows") {
47
53
  return runPwsh(appName, "Minimize");
48
54
  }
@@ -54,7 +60,7 @@ async function hideTerminal(appName) {
54
60
  async function showTerminal(appName) {
55
61
  try {
56
62
  if (platform() == "mac") {
57
- return await execSync(`osascript -e '${appleScriptMax(appName)}'`);
63
+ return await execSync(appleScriptOpen(appName));
58
64
  } else if (platform() == "windows") {
59
65
  return runPwsh(appName, "Restore");
60
66
  }
package/lib/overlay.js CHANGED
@@ -10,7 +10,7 @@ ipc.config.silent = true;
10
10
 
11
11
  let electronProcess;
12
12
 
13
- console.log("Starting overlay process...");
13
+ console.log("Spawning GUI...");
14
14
 
15
15
  try {
16
16
  // Resolve the path to Electron CLI
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "4.1.13",
3
+ "version": "4.1.15",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {