qazen-cli 0.1.4 → 0.1.6

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.
@@ -3,7 +3,7 @@ import ora from "ora";
3
3
  import inquirer from "inquirer";
4
4
  import Anthropic from "@anthropic-ai/sdk";
5
5
  import { getConfig, isConfigured } from "../lib/config.js";
6
- import { fetchProjects, uploadVisionDiscovery } from "../lib/api.js";
6
+ import { fetchProjects, uploadVisionDiscovery, fetchProjectAuthSession } from "../lib/api.js";
7
7
  import { VisionNavigator } from "../lib/visionNavigator.js";
8
8
  export async function visionScoutCommand(options) {
9
9
  if (!isConfigured()) {
@@ -73,8 +73,22 @@ export async function visionScoutCommand(options) {
73
73
  console.log(chalk.gray("\n Cancelled.\n"));
74
74
  process.exit(0);
75
75
  }
76
+ let storedSession = null;
77
+ try {
78
+ storedSession = await fetchProjectAuthSession(config.apiUrl, config.cliToken, project.id);
79
+ if (storedSession) {
80
+ console.log(chalk.green(" ✓ Loaded stored auth session"));
81
+ }
82
+ else {
83
+ console.log(chalk.yellow(" ⚠ No stored session — browser will start unauthenticated"));
84
+ console.log(chalk.gray(" Tip: Run qazen record first to capture a session"));
85
+ }
86
+ }
87
+ catch {
88
+ console.log(chalk.gray(" No stored session found"));
89
+ }
76
90
  const anthropic = new Anthropic({ apiKey: anthropicKey });
77
- const navigator = new VisionNavigator(anthropic, targetUrl, maxPages);
91
+ const navigator = new VisionNavigator(anthropic, targetUrl, maxPages, storedSession || undefined);
78
92
  console.log("\n " + chalk.hex("#6366F1")("Starting Vision Scout...") + "\n");
79
93
  try {
80
94
  const result = await navigator.explore((event) => {
package/dist/lib/api.js CHANGED
@@ -32,6 +32,22 @@ export async function uploadSession(apiUrl, cliToken, projectId, storageState, d
32
32
  throw new Error(`Upload failed (HTTP ${res.status}): ${text}`);
33
33
  }
34
34
  }
35
+ export async function fetchProjectAuthSession(apiUrl, cliToken, projectId) {
36
+ const response = await fetch(`${apiUrl}/api/cli/projects/${projectId}/session`, {
37
+ headers: authHeaders(cliToken),
38
+ });
39
+ if (!response.ok)
40
+ return null;
41
+ const data = (await response.json());
42
+ if (!data.storageState)
43
+ return null;
44
+ try {
45
+ return JSON.parse(data.storageState);
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ }
35
51
  export async function uploadVisionDiscovery(apiUrl, cliToken, projectId, result) {
36
52
  const appMap = {
37
53
  baseUrl: result.pages[0]?.url ?? "",
@@ -15,6 +15,15 @@ export class VisionNavigator {
15
15
  baseUrl;
16
16
  maxPages;
17
17
  visitedUrls = new Set();
18
+ normalizeUrl(url) {
19
+ try {
20
+ const u = new URL(url);
21
+ return u.origin + u.pathname.replace(/\/$/, "");
22
+ }
23
+ catch {
24
+ return url;
25
+ }
26
+ }
18
27
  explorationQueue = [];
19
28
  pages = [];
20
29
  screenshots = [];
@@ -23,10 +32,13 @@ export class VisionNavigator {
23
32
  browserContext;
24
33
  page;
25
34
  screenshotDir;
26
- constructor(anthropic, baseUrl, maxPages = 20) {
35
+ storageState;
36
+ constructor(anthropic, baseUrl, maxPages = 20, storageState) {
27
37
  this.anthropic = anthropic;
28
38
  this.baseUrl = baseUrl;
29
39
  this.maxPages = maxPages;
40
+ if (storageState)
41
+ this.storageState = storageState;
30
42
  this.screenshotDir = fs.mkdtempSync(path.join(os.tmpdir(), "qazen-vision-"));
31
43
  }
32
44
  async explore(onEvent) {
@@ -44,6 +56,9 @@ export class VisionNavigator {
44
56
  viewport: { width: 1280, height: 720 },
45
57
  userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
46
58
  ignoreHTTPSErrors: true,
59
+ ...(this.storageState
60
+ ? { storageState: this.storageState }
61
+ : {}),
47
62
  });
48
63
  await this.browserContext.addInitScript(() => {
49
64
  Object.defineProperty(navigator, "webdriver", { get: () => false });
@@ -73,9 +88,10 @@ export class VisionNavigator {
73
88
  };
74
89
  }
75
90
  async explorePage(url, context, onEvent) {
76
- if (this.visitedUrls.has(url))
91
+ const normalizedUrl = this.normalizeUrl(url);
92
+ if (this.visitedUrls.has(normalizedUrl))
77
93
  return;
78
- this.visitedUrls.add(url);
94
+ this.visitedUrls.add(normalizedUrl);
79
95
  onEvent({ type: "page_start", url, message: url });
80
96
  try {
81
97
  await this.page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 });
@@ -112,7 +128,7 @@ export class VisionNavigator {
112
128
  for (const element of highPriority) {
113
129
  try {
114
130
  const newUrl = await this.clickElement(element, pageMap, onEvent);
115
- if (newUrl && !this.visitedUrls.has(newUrl)) {
131
+ if (newUrl && !this.visitedUrls.has(this.normalizeUrl(newUrl))) {
116
132
  this.explorationQueue.push({
117
133
  url: newUrl,
118
134
  context: `Navigated from ${url} by clicking "${element.description}"`,
@@ -139,7 +155,7 @@ export class VisionNavigator {
139
155
  }
140
156
  });
141
157
  for (const link of links) {
142
- if (!this.visitedUrls.has(link)) {
158
+ if (!this.visitedUrls.has(this.normalizeUrl(link))) {
143
159
  this.explorationQueue.push({ url: link, context: `Link found on ${url}` });
144
160
  }
145
161
  }
@@ -186,6 +202,11 @@ Analyse this screenshot and return ONLY valid JSON:
186
202
  ]
187
203
  }
188
204
 
205
+ Already visited URLs — do NOT suggest clicking these as high priority:
206
+ ${Array.from(this.visitedUrls).join("\n")}
207
+
208
+ If an element links to an already-visited URL, set its priority to 'low'.
209
+
189
210
  Focus on:
190
211
  - Navigation items and menu links (high priority)
191
212
  - Primary action buttons (high priority)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qazen-cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "QAZen CLI — capture authenticated browser sessions for enterprise SSO testing",
5
5
  "license": "MIT",
6
6
  "author": "QAZen",