@qablehq/atto 0.0.13 → 0.0.16
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/out/main/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const electron = require("electron");
|
|
3
3
|
const node_path = require("node:path");
|
|
4
|
-
const Anthropic = require("@anthropic-ai/sdk");
|
|
5
4
|
const node_fs = require("node:fs");
|
|
5
|
+
const Anthropic = require("@anthropic-ai/sdk");
|
|
6
6
|
const node_crypto = require("node:crypto");
|
|
7
7
|
const node_http = require("node:http");
|
|
8
8
|
const node_url = require("node:url");
|
|
@@ -55,154 +55,567 @@ const IPC_CHANNELS = {
|
|
|
55
55
|
tesboLogout: "taa:tesbo:logout",
|
|
56
56
|
tesboAgents: "taa:tesbo:agents",
|
|
57
57
|
tesboRemoteConfig: "taa:tesbo:remoteConfig",
|
|
58
|
+
/** Main → renderer: start a Chat-queued desktop session (New session equivalent). */
|
|
59
|
+
tesboRemoteSession: "taa:tesbo:remoteSession",
|
|
60
|
+
tesboAckRemoteSession: "taa:tesbo:ackRemoteSession",
|
|
61
|
+
/** Renderer → main: bind a RealEngine session to a Chat job for live mirroring. */
|
|
62
|
+
tesboBindRemoteSession: "taa:tesbo:bindRemoteSession",
|
|
58
63
|
// Contextual command handling
|
|
59
64
|
submitCommand: "taa:sessions:submitCommand",
|
|
60
65
|
getCommandQueue: "taa:sessions:getCommandQueue",
|
|
61
66
|
clearCommandQueue: "taa:sessions:clearCommandQueue"
|
|
62
67
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(_e, cmd) => adapter.answerStuckQuestion(cmd)
|
|
68
|
-
);
|
|
69
|
-
electron.ipcMain.handle(IPC_CHANNELS.startRun, (_e, cmd) => adapter.startRun(cmd));
|
|
70
|
-
electron.ipcMain.handle(IPC_CHANNELS.openRunReport, (_e, cmd) => adapter.openRunReport(cmd));
|
|
71
|
-
electron.ipcMain.handle(IPC_CHANNELS.submitFeedback, (_e, cmd) => adapter.submitFeedback(cmd));
|
|
72
|
-
electron.ipcMain.handle(IPC_CHANNELS.approve, (_e, cmd) => adapter.approve(cmd));
|
|
73
|
-
electron.ipcMain.handle(IPC_CHANNELS.list, () => adapter.list());
|
|
74
|
-
electron.ipcMain.handle(IPC_CHANNELS.getBacklog, () => adapter.getBacklogEvents());
|
|
75
|
-
electron.ipcMain.handle(
|
|
76
|
-
IPC_CHANNELS.registerProject,
|
|
77
|
-
(_e, context) => adapter.registerProject(context)
|
|
78
|
-
);
|
|
79
|
-
electron.ipcMain.handle(IPC_CHANNELS.pauseSession, (_e, cmd) => adapter.pauseSession(cmd));
|
|
80
|
-
electron.ipcMain.handle(IPC_CHANNELS.resumeSession, (_e, cmd) => adapter.resumeSession(cmd));
|
|
81
|
-
electron.ipcMain.handle(IPC_CHANNELS.stopSession, (_e, cmd) => adapter.stopSession(cmd));
|
|
82
|
-
electron.ipcMain.handle(IPC_CHANNELS.submitCommand, (_e, cmd) => adapter.submitCommand(cmd));
|
|
83
|
-
electron.ipcMain.handle(IPC_CHANNELS.getCommandQueue, (_e, cmd) => adapter.getCommandQueue(cmd));
|
|
84
|
-
electron.ipcMain.handle(
|
|
85
|
-
IPC_CHANNELS.clearCommandQueue,
|
|
86
|
-
(_e, cmd) => adapter.clearCommandQueue(cmd)
|
|
87
|
-
);
|
|
88
|
-
adapter.onEvent((event) => {
|
|
89
|
-
for (const win of electron.BrowserWindow.getAllWindows()) {
|
|
90
|
-
win.webContents.send(IPC_CHANNELS.engineEvent, event);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
68
|
+
const DEFAULT_BASE_URL = "https://api-app-atto.tesbo.io";
|
|
69
|
+
const ACCESS_HEADER = "x-atto-access-code";
|
|
70
|
+
function sessionPath() {
|
|
71
|
+
return node_path.join(electron.app.getPath("userData"), "tesbo-link.json");
|
|
93
72
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
73
|
+
function readLink() {
|
|
74
|
+
try {
|
|
75
|
+
const parsed = JSON.parse(node_fs.readFileSync(sessionPath(), "utf8"));
|
|
76
|
+
if (typeof parsed.code !== "string" || !parsed.code.trim()) return null;
|
|
77
|
+
return { baseUrl: DEFAULT_BASE_URL, code: parsed.code.trim() };
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
102
81
|
}
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
failed: outcomes.filter((outcome) => outcome.status === "failed" && outcome.severity === "error").length,
|
|
109
|
-
warned: outcomes.filter((outcome) => outcome.status === "failed" && outcome.severity === "warning").length,
|
|
110
|
-
disabled: count("disabled"),
|
|
111
|
-
notApplicable: count("not-applicable"),
|
|
112
|
-
bypassed: count("bypassed"),
|
|
113
|
-
attempt
|
|
114
|
-
};
|
|
82
|
+
function writeLink(link) {
|
|
83
|
+
const path = sessionPath();
|
|
84
|
+
node_fs.mkdirSync(electron.app.getPath("userData"), { recursive: true });
|
|
85
|
+
node_fs.writeFileSync(path, JSON.stringify(link), { mode: 384 });
|
|
86
|
+
node_fs.chmodSync(path, 384);
|
|
115
87
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
return summariseGateReport(
|
|
119
|
-
report.outcomes.map(
|
|
120
|
-
(outcome) => outcome.status === "failed" && ids.has(outcome.id) ? { ...outcome, status: "bypassed" } : outcome
|
|
121
|
-
),
|
|
122
|
-
report.attempt
|
|
123
|
-
);
|
|
88
|
+
function clearLink() {
|
|
89
|
+
node_fs.rmSync(sessionPath(), { force: true });
|
|
124
90
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"assertions-required",
|
|
128
|
-
"pom-dangling-import",
|
|
129
|
-
"import-tokens"
|
|
130
|
-
];
|
|
131
|
-
function isLockedGate(id) {
|
|
132
|
-
return LOCKED_GATE_IDS.includes(id);
|
|
91
|
+
function disconnected(error = null) {
|
|
92
|
+
return { connected: false, baseUrl: DEFAULT_BASE_URL, user: null, workspaces: [], projects: [], error };
|
|
133
93
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
94
|
+
async function errorMessage(response) {
|
|
95
|
+
try {
|
|
96
|
+
const body = await response.json();
|
|
97
|
+
if (typeof body.error === "string" && body.error.trim()) return body.error;
|
|
98
|
+
if (typeof body.message === "string" && body.message.trim()) return body.message;
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
return `Tesbo returned ${response.status}`;
|
|
102
|
+
}
|
|
103
|
+
function isTransientNetworkError(error) {
|
|
104
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
105
|
+
return /fetch failed|failed to fetch|network|ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENOTFOUND|socket/i.test(
|
|
106
|
+
message
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
async function tesboFetch(link, path, init) {
|
|
110
|
+
const run = () => fetch(`${link.baseUrl}${path}`, {
|
|
111
|
+
...init,
|
|
112
|
+
headers: {
|
|
113
|
+
accept: "application/json",
|
|
114
|
+
[ACCESS_HEADER]: link.code,
|
|
115
|
+
...init?.body ? { "content-type": "application/json" } : {},
|
|
116
|
+
...init?.headers
|
|
142
117
|
}
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
return await run();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (!isTransientNetworkError(error) || init?.method && init.method !== "GET") throw error;
|
|
123
|
+
await new Promise((resolve2) => setTimeout(resolve2, 400));
|
|
124
|
+
return await run();
|
|
143
125
|
}
|
|
144
|
-
const custom = Array.isArray(record.custom) ? record.custom.map(normalizeCustomGate).filter((gate) => gate !== null) : [];
|
|
145
|
-
return { version: 1, disabled, severityOverrides, custom };
|
|
146
126
|
}
|
|
147
|
-
function
|
|
148
|
-
if (
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
127
|
+
function asProjects(value) {
|
|
128
|
+
if (!Array.isArray(value)) return [];
|
|
129
|
+
const projects = [];
|
|
130
|
+
for (const item of value) {
|
|
131
|
+
if (!item || typeof item !== "object") continue;
|
|
132
|
+
const row = item;
|
|
133
|
+
if (typeof row.id !== "string" || typeof row.name !== "string") continue;
|
|
134
|
+
projects.push({
|
|
135
|
+
id: row.id,
|
|
136
|
+
key: typeof row.key === "string" ? row.key : "",
|
|
137
|
+
name: row.name,
|
|
138
|
+
role: typeof row.role === "string" ? row.role : "member",
|
|
139
|
+
clientName: typeof row.clientName === "string" ? row.clientName : void 0,
|
|
140
|
+
userName: typeof row.userName === "string" ? row.userName : void 0
|
|
141
|
+
});
|
|
159
142
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
143
|
+
return projects;
|
|
144
|
+
}
|
|
145
|
+
async function loadAccount(link) {
|
|
146
|
+
const response = await tesboFetch(link, "/api/atto/projects");
|
|
147
|
+
if (response.status === 401) {
|
|
148
|
+
clearLink();
|
|
149
|
+
return disconnected(await errorMessage(response));
|
|
150
|
+
}
|
|
151
|
+
if (!response.ok) throw new Error(await errorMessage(response));
|
|
152
|
+
const projects = asProjects(await response.json());
|
|
163
153
|
return {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
matcher: {
|
|
171
|
-
type: matcher?.type === "regex" ? "regex" : "literal",
|
|
172
|
-
value,
|
|
173
|
-
caseInsensitive: matcher?.caseInsensitive === true
|
|
174
|
-
},
|
|
175
|
-
severity,
|
|
176
|
-
hint: typeof record.hint === "string" && record.hint.trim() ? record.hint.trim() : void 0,
|
|
177
|
-
enabled
|
|
154
|
+
connected: true,
|
|
155
|
+
baseUrl: link.baseUrl,
|
|
156
|
+
user: signedInUser(projects),
|
|
157
|
+
workspaces: [],
|
|
158
|
+
projects,
|
|
159
|
+
error: null
|
|
178
160
|
};
|
|
179
161
|
}
|
|
180
|
-
function
|
|
181
|
-
|
|
162
|
+
function signedInUser(projects) {
|
|
163
|
+
const project = projects.find((item) => item.userName || item.clientName);
|
|
164
|
+
if (!project) return null;
|
|
165
|
+
const name = [project.userName, project.clientName].filter(Boolean).join(" · ");
|
|
166
|
+
return { userId: project.userName || project.clientName || "", email: null, name: name || null };
|
|
182
167
|
}
|
|
183
|
-
function
|
|
184
|
-
const
|
|
168
|
+
async function tesboStatus() {
|
|
169
|
+
const link = readLink();
|
|
170
|
+
if (!link) return disconnected();
|
|
185
171
|
try {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return
|
|
172
|
+
return await loadAccount(link);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (isTransientNetworkError(error)) return disconnected("Could not reach Tesbo.");
|
|
175
|
+
return disconnected(error instanceof Error ? error.message : "Could not reach Tesbo.");
|
|
190
176
|
}
|
|
191
177
|
}
|
|
192
|
-
|
|
178
|
+
async function tesboLogin(cmd) {
|
|
179
|
+
const code = cmd.code.trim();
|
|
180
|
+
if (!code) throw new Error("Paste the access code from Tesbo.");
|
|
181
|
+
const link = { baseUrl: DEFAULT_BASE_URL, code };
|
|
182
|
+
const connectOnce = () => fetch(`${link.baseUrl}/api/atto/connect`, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
185
|
+
body: JSON.stringify({ code })
|
|
186
|
+
});
|
|
187
|
+
let response;
|
|
188
|
+
try {
|
|
189
|
+
response = await connectOnce();
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (!isTransientNetworkError(error)) throw error;
|
|
192
|
+
await new Promise((resolve2) => setTimeout(resolve2, 400));
|
|
193
|
+
response = await connectOnce();
|
|
194
|
+
}
|
|
195
|
+
if (!response.ok) throw new Error(await errorMessage(response));
|
|
196
|
+
writeLink(link);
|
|
197
|
+
const projects = asProjects(await response.json());
|
|
198
|
+
return {
|
|
199
|
+
connected: true,
|
|
200
|
+
baseUrl: link.baseUrl,
|
|
201
|
+
user: signedInUser(projects),
|
|
202
|
+
workspaces: [],
|
|
203
|
+
projects,
|
|
204
|
+
error: null
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async function tesboLogout() {
|
|
208
|
+
clearLink();
|
|
209
|
+
return disconnected();
|
|
210
|
+
}
|
|
211
|
+
const SERVER_AGENTS = [
|
|
193
212
|
{
|
|
194
|
-
id: "
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
213
|
+
id: "zyra",
|
|
214
|
+
name: "Zyra the Test Generator",
|
|
215
|
+
role: "AI testcase generation agent",
|
|
216
|
+
summary: "Stays on Tesbo for the QAble team. This package does not open the website.",
|
|
217
|
+
status: "active",
|
|
218
|
+
detail: null
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: "nyra",
|
|
222
|
+
name: "NYRA",
|
|
223
|
+
role: "App exploration agent",
|
|
224
|
+
summary: "Stays on Tesbo for the QAble team. This package does not open the website.",
|
|
225
|
+
status: "active",
|
|
226
|
+
detail: null
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
const COMING_SOON = [
|
|
230
|
+
{
|
|
231
|
+
id: "run-analyst",
|
|
232
|
+
name: "Run Analyst",
|
|
233
|
+
role: "Execution insight agent",
|
|
234
|
+
summary: "Planned for run failure clustering, flaky-test signals, and release risk notes.",
|
|
235
|
+
status: "coming-soon",
|
|
236
|
+
detail: null
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
id: "bug-triage",
|
|
240
|
+
name: "Bug Triage",
|
|
241
|
+
role: "Defect analysis agent",
|
|
242
|
+
summary: "Planned for duplicate bug checks, severity suggestions, and owner recommendations.",
|
|
243
|
+
status: "coming-soon",
|
|
244
|
+
detail: null
|
|
245
|
+
}
|
|
246
|
+
];
|
|
247
|
+
async function tesboAgents(projectId) {
|
|
248
|
+
const link = readLink();
|
|
249
|
+
if (!link) throw new Error("Connect with an access code first.");
|
|
250
|
+
if (!projectId.trim()) throw new Error("Choose a project.");
|
|
251
|
+
const status = await loadAccount(link);
|
|
252
|
+
if (!status.connected) throw new Error(status.error || "This access code has been stopped.");
|
|
253
|
+
if (!status.projects.some((project) => project.id === projectId)) {
|
|
254
|
+
throw new Error("This project is not available for this access code.");
|
|
255
|
+
}
|
|
256
|
+
return { projectId, agents: [...SERVER_AGENTS, ...COMING_SOON], notice: null };
|
|
257
|
+
}
|
|
258
|
+
function safeTargetPath(savePath, fileName) {
|
|
259
|
+
const folder = node_path.resolve(node_path.normalize(savePath.trim()));
|
|
260
|
+
if (!node_path.isAbsolute(folder)) throw new Error("Save location from Tesbo must be an absolute path.");
|
|
261
|
+
const base = String(fileName || "script.spec.ts").replace(/[/\\]/g, "_").trim() || "script.spec.ts";
|
|
262
|
+
const target = node_path.resolve(folder, base);
|
|
263
|
+
const root = folder.endsWith(node_path.sep) ? folder : folder + node_path.sep;
|
|
264
|
+
if (target !== folder && !target.startsWith(root)) {
|
|
265
|
+
throw new Error("Refusing to write outside the configured save location.");
|
|
266
|
+
}
|
|
267
|
+
return target;
|
|
268
|
+
}
|
|
269
|
+
async function pullAndSavePendingScripts() {
|
|
270
|
+
const link = readLink();
|
|
271
|
+
if (!link) return { saved: 0, errors: [] };
|
|
272
|
+
const response = await tesboFetch(link, "/api/atto/scripts/pending");
|
|
273
|
+
if (response.status === 401) {
|
|
274
|
+
clearLink();
|
|
275
|
+
return { saved: 0, errors: ["Access code stopped."] };
|
|
276
|
+
}
|
|
277
|
+
if (!response.ok) throw new Error(await errorMessage(response));
|
|
278
|
+
const body = await response.json();
|
|
279
|
+
const scripts = Array.isArray(body.scripts) ? body.scripts : [];
|
|
280
|
+
let saved = 0;
|
|
281
|
+
const errors = [];
|
|
282
|
+
for (const item of scripts) {
|
|
283
|
+
if (!item?.id || !item.script || !item.savePath) continue;
|
|
284
|
+
try {
|
|
285
|
+
const target = safeTargetPath(item.savePath, item.fileName || `${item.externalId || "script"}.spec.ts`);
|
|
286
|
+
node_fs.mkdirSync(node_path.resolve(node_path.normalize(item.savePath.trim())), { recursive: true });
|
|
287
|
+
node_fs.writeFileSync(target, item.script, { encoding: "utf8" });
|
|
288
|
+
const ack = await tesboFetch(link, `/api/atto/scripts/${encodeURIComponent(item.id)}/ack`, { method: "POST", body: "{}" });
|
|
289
|
+
if (!ack.ok) throw new Error(await errorMessage(ack));
|
|
290
|
+
saved += 1;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
errors.push(error instanceof Error ? error.message : "Could not save a script.");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return { saved, errors };
|
|
296
|
+
}
|
|
297
|
+
let scriptPollTimer = null;
|
|
298
|
+
const claimedSessionJobs = /* @__PURE__ */ new Set();
|
|
299
|
+
let remoteSessionSink = null;
|
|
300
|
+
function setRemoteSessionSink(sink) {
|
|
301
|
+
remoteSessionSink = sink;
|
|
302
|
+
}
|
|
303
|
+
async function ackAttoRemoteSession(id, status, error, desktopSessionId) {
|
|
304
|
+
const link = readLink();
|
|
305
|
+
if (!link || !id) return;
|
|
306
|
+
await tesboFetch(link, `/api/atto/sessions/${encodeURIComponent(id)}/ack`, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
body: JSON.stringify({
|
|
309
|
+
status,
|
|
310
|
+
error: error || void 0,
|
|
311
|
+
desktopSessionId: desktopSessionId || void 0
|
|
312
|
+
})
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
const remoteJobByDesktopSession = /* @__PURE__ */ new Map();
|
|
316
|
+
const activeRemoteJobIds = /* @__PURE__ */ new Set();
|
|
317
|
+
let answerPollTimer = null;
|
|
318
|
+
let engineAdapterForAnswers = null;
|
|
319
|
+
function bindRemoteSessionJob(jobId, desktopSessionId) {
|
|
320
|
+
if (!jobId || !desktopSessionId) return;
|
|
321
|
+
remoteJobByDesktopSession.set(desktopSessionId, jobId);
|
|
322
|
+
activeRemoteJobIds.add(jobId);
|
|
323
|
+
void ackAttoRemoteSession(jobId, "running", void 0, desktopSessionId).catch(() => void 0);
|
|
324
|
+
}
|
|
325
|
+
function attachEngineForRemoteAnswers(adapter) {
|
|
326
|
+
engineAdapterForAnswers = adapter;
|
|
327
|
+
if (answerPollTimer) return;
|
|
328
|
+
answerPollTimer = setInterval(() => {
|
|
329
|
+
void pullRemoteSessionAnswers().catch(() => void 0);
|
|
330
|
+
}, 2500);
|
|
331
|
+
answerPollTimer.unref?.();
|
|
332
|
+
}
|
|
333
|
+
function mirrorEngineEventToChat(event) {
|
|
334
|
+
const jobId = remoteJobByDesktopSession.get(event.sessionId);
|
|
335
|
+
if (!jobId) return;
|
|
336
|
+
if (event.type !== "narration_step" && event.type !== "assertion_result" && event.type !== "stuck_question" && event.type !== "session_status_changed" && event.type !== "agent_log") {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (event.type === "narration_step" && event.status === "in_progress") return;
|
|
340
|
+
void postRemoteSessionEvent(jobId, event).catch(() => void 0);
|
|
341
|
+
if (event.type === "session_status_changed") {
|
|
342
|
+
const status = event.status;
|
|
343
|
+
if (status === "failed" || status === "stopped" || status === "developed" || status === "approved") {
|
|
344
|
+
void ackAttoRemoteSession(jobId, status === "failed" ? "failed" : "done").catch(() => void 0);
|
|
345
|
+
activeRemoteJobIds.delete(jobId);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function postRemoteSessionEvent(jobId, event) {
|
|
350
|
+
const link = readLink();
|
|
351
|
+
if (!link) return;
|
|
352
|
+
await tesboFetch(link, `/api/atto/sessions/${encodeURIComponent(jobId)}/events`, {
|
|
353
|
+
method: "POST",
|
|
354
|
+
body: JSON.stringify(event)
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
async function pullRemoteSessionAnswers() {
|
|
358
|
+
const link = readLink();
|
|
359
|
+
const adapter = engineAdapterForAnswers;
|
|
360
|
+
if (!link || !adapter || activeRemoteJobIds.size === 0) return;
|
|
361
|
+
for (const jobId of [...activeRemoteJobIds]) {
|
|
362
|
+
try {
|
|
363
|
+
const response = await tesboFetch(link, `/api/atto/sessions/${encodeURIComponent(jobId)}/answers/pending`);
|
|
364
|
+
if (!response.ok) continue;
|
|
365
|
+
const body = await response.json();
|
|
366
|
+
const answers = Array.isArray(body.answers) ? body.answers : [];
|
|
367
|
+
for (const answer of answers) {
|
|
368
|
+
if (!answer?.questionId) continue;
|
|
369
|
+
const desktopSessionId = [...remoteJobByDesktopSession.entries()].find(([, id]) => id === jobId)?.[0];
|
|
370
|
+
if (!desktopSessionId) continue;
|
|
371
|
+
await adapter.answerStuckQuestion({
|
|
372
|
+
sessionId: desktopSessionId,
|
|
373
|
+
questionId: answer.questionId,
|
|
374
|
+
optionId: answer.optionId,
|
|
375
|
+
text: answer.text
|
|
376
|
+
});
|
|
377
|
+
await tesboFetch(
|
|
378
|
+
link,
|
|
379
|
+
`/api/atto/sessions/${encodeURIComponent(jobId)}/answers/${encodeURIComponent(answer.questionId)}/ack`,
|
|
380
|
+
{ method: "POST", body: "{}" }
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
} catch {
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async function pullAndDispatchPendingSessions() {
|
|
388
|
+
const link = readLink();
|
|
389
|
+
if (!link) return { started: 0, errors: [] };
|
|
390
|
+
const response = await tesboFetch(link, "/api/atto/sessions/pending");
|
|
391
|
+
if (response.status === 401) {
|
|
392
|
+
clearLink();
|
|
393
|
+
return { started: 0, errors: ["Access code stopped."] };
|
|
394
|
+
}
|
|
395
|
+
if (!response.ok) throw new Error(await errorMessage(response));
|
|
396
|
+
const body = await response.json();
|
|
397
|
+
const sessions = Array.isArray(body.sessions) ? body.sessions : [];
|
|
398
|
+
let started = 0;
|
|
399
|
+
const errors = [];
|
|
400
|
+
for (const item of sessions) {
|
|
401
|
+
if (!item?.id || !item.goal || !item.folderPath) continue;
|
|
402
|
+
if (claimedSessionJobs.has(item.id)) continue;
|
|
403
|
+
claimedSessionJobs.add(item.id);
|
|
404
|
+
try {
|
|
405
|
+
const job = {
|
|
406
|
+
id: String(item.id),
|
|
407
|
+
projectId: String(item.projectId || ""),
|
|
408
|
+
projectName: String(item.projectName || ""),
|
|
409
|
+
goal: String(item.goal || "").trim(),
|
|
410
|
+
targetUrl: String(item.targetUrl || "").trim(),
|
|
411
|
+
folderPath: String(item.folderPath || "").trim(),
|
|
412
|
+
browserMode: item.browserMode === "headless" ? "headless" : "headed",
|
|
413
|
+
createdAt: String(item.createdAt || ""),
|
|
414
|
+
chatSessionId: item.chatSessionId ? String(item.chatSessionId) : void 0
|
|
415
|
+
};
|
|
416
|
+
activeRemoteJobIds.add(job.id);
|
|
417
|
+
if (!remoteSessionSink) {
|
|
418
|
+
claimedSessionJobs.delete(item.id);
|
|
419
|
+
errors.push("Atto window is not ready to start a remote session yet.");
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
await ackAttoRemoteSession(job.id, "running");
|
|
423
|
+
remoteSessionSink(job);
|
|
424
|
+
started += 1;
|
|
425
|
+
} catch (error) {
|
|
426
|
+
claimedSessionJobs.delete(item.id);
|
|
427
|
+
errors.push(error instanceof Error ? error.message : "Could not start a remote session.");
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (claimedSessionJobs.size > 200) {
|
|
431
|
+
const keep = [...claimedSessionJobs].slice(-100);
|
|
432
|
+
claimedSessionJobs.clear();
|
|
433
|
+
for (const id of keep) claimedSessionJobs.add(id);
|
|
434
|
+
}
|
|
435
|
+
return { started, errors };
|
|
436
|
+
}
|
|
437
|
+
async function fetchAttoRemoteConfig() {
|
|
438
|
+
const link = readLink();
|
|
439
|
+
if (!link) return null;
|
|
440
|
+
const response = await tesboFetch(link, "/api/atto/remote-config");
|
|
441
|
+
if (response.status === 401) {
|
|
442
|
+
clearLink();
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
if (!response.ok) throw new Error(await errorMessage(response));
|
|
446
|
+
const body = await response.json();
|
|
447
|
+
return {
|
|
448
|
+
userName: String(body.userName || ""),
|
|
449
|
+
clientName: String(body.clientName || ""),
|
|
450
|
+
projectId: String(body.projectId || ""),
|
|
451
|
+
projectName: String(body.projectName || ""),
|
|
452
|
+
scriptSavePath: String(body.scriptSavePath || "").trim(),
|
|
453
|
+
browserMode: body.browserMode === "headless" ? "headless" : "headed",
|
|
454
|
+
targetUrl: String(body.targetUrl || "").trim(),
|
|
455
|
+
description: String(body.description || "").trim(),
|
|
456
|
+
memories: Array.isArray(body.memories) ? body.memories : [],
|
|
457
|
+
qualityGates: body.qualityGates && typeof body.qualityGates === "object" ? body.qualityGates : {},
|
|
458
|
+
install: {
|
|
459
|
+
package: String(body.install?.package || "npm install -g @qablehq/atto"),
|
|
460
|
+
chromium: String(body.install?.chromium || "npx playwright install chromium"),
|
|
461
|
+
note: String(body.install?.note || "")
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
function startAttoScriptPoller(intervalMs = 5e3) {
|
|
466
|
+
if (scriptPollTimer) return;
|
|
467
|
+
const tick = () => {
|
|
468
|
+
void pullAndSavePendingScripts().catch(() => void 0);
|
|
469
|
+
void pullAndDispatchPendingSessions().catch(() => void 0);
|
|
470
|
+
};
|
|
471
|
+
tick();
|
|
472
|
+
scriptPollTimer = setInterval(tick, intervalMs);
|
|
473
|
+
scriptPollTimer.unref?.();
|
|
474
|
+
}
|
|
475
|
+
function registerIpcHandlers(adapter) {
|
|
476
|
+
electron.ipcMain.handle(IPC_CHANNELS.submitGoal, (_e, cmd) => adapter.submitGoal(cmd));
|
|
477
|
+
electron.ipcMain.handle(
|
|
478
|
+
IPC_CHANNELS.answerStuckQuestion,
|
|
479
|
+
(_e, cmd) => adapter.answerStuckQuestion(cmd)
|
|
480
|
+
);
|
|
481
|
+
electron.ipcMain.handle(IPC_CHANNELS.startRun, (_e, cmd) => adapter.startRun(cmd));
|
|
482
|
+
electron.ipcMain.handle(IPC_CHANNELS.openRunReport, (_e, cmd) => adapter.openRunReport(cmd));
|
|
483
|
+
electron.ipcMain.handle(IPC_CHANNELS.submitFeedback, (_e, cmd) => adapter.submitFeedback(cmd));
|
|
484
|
+
electron.ipcMain.handle(IPC_CHANNELS.approve, (_e, cmd) => adapter.approve(cmd));
|
|
485
|
+
electron.ipcMain.handle(IPC_CHANNELS.list, () => adapter.list());
|
|
486
|
+
electron.ipcMain.handle(IPC_CHANNELS.getBacklog, () => adapter.getBacklogEvents());
|
|
487
|
+
electron.ipcMain.handle(
|
|
488
|
+
IPC_CHANNELS.registerProject,
|
|
489
|
+
(_e, context) => adapter.registerProject(context)
|
|
490
|
+
);
|
|
491
|
+
electron.ipcMain.handle(IPC_CHANNELS.pauseSession, (_e, cmd) => adapter.pauseSession(cmd));
|
|
492
|
+
electron.ipcMain.handle(IPC_CHANNELS.resumeSession, (_e, cmd) => adapter.resumeSession(cmd));
|
|
493
|
+
electron.ipcMain.handle(IPC_CHANNELS.stopSession, (_e, cmd) => adapter.stopSession(cmd));
|
|
494
|
+
electron.ipcMain.handle(IPC_CHANNELS.submitCommand, (_e, cmd) => adapter.submitCommand(cmd));
|
|
495
|
+
electron.ipcMain.handle(IPC_CHANNELS.getCommandQueue, (_e, cmd) => adapter.getCommandQueue(cmd));
|
|
496
|
+
electron.ipcMain.handle(
|
|
497
|
+
IPC_CHANNELS.clearCommandQueue,
|
|
498
|
+
(_e, cmd) => adapter.clearCommandQueue(cmd)
|
|
499
|
+
);
|
|
500
|
+
adapter.onEvent((event) => {
|
|
501
|
+
for (const win of electron.BrowserWindow.getAllWindows()) {
|
|
502
|
+
win.webContents.send(IPC_CHANNELS.engineEvent, event);
|
|
503
|
+
}
|
|
504
|
+
mirrorEngineEventToChat(event);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
const DEFAULT_GATE_POLICY = {
|
|
508
|
+
version: 1,
|
|
509
|
+
disabled: [],
|
|
510
|
+
severityOverrides: {},
|
|
511
|
+
custom: []
|
|
512
|
+
};
|
|
513
|
+
function emptyGateReport(attempt = 1) {
|
|
514
|
+
return { outcomes: [], passed: 0, failed: 0, warned: 0, disabled: 0, notApplicable: 0, bypassed: 0, attempt };
|
|
515
|
+
}
|
|
516
|
+
function summariseGateReport(outcomes, attempt) {
|
|
517
|
+
const count = (status) => outcomes.filter((outcome) => outcome.status === status).length;
|
|
518
|
+
return {
|
|
519
|
+
outcomes,
|
|
520
|
+
passed: count("passed"),
|
|
521
|
+
failed: outcomes.filter((outcome) => outcome.status === "failed" && outcome.severity === "error").length,
|
|
522
|
+
warned: outcomes.filter((outcome) => outcome.status === "failed" && outcome.severity === "warning").length,
|
|
523
|
+
disabled: count("disabled"),
|
|
524
|
+
notApplicable: count("not-applicable"),
|
|
525
|
+
bypassed: count("bypassed"),
|
|
526
|
+
attempt
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function applyBypass(report, bypassedIds) {
|
|
530
|
+
const ids = new Set(bypassedIds);
|
|
531
|
+
return summariseGateReport(
|
|
532
|
+
report.outcomes.map(
|
|
533
|
+
(outcome) => outcome.status === "failed" && ids.has(outcome.id) ? { ...outcome, status: "bypassed" } : outcome
|
|
534
|
+
),
|
|
535
|
+
report.attempt
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
const LOCKED_GATE_IDS = [
|
|
539
|
+
"test-required",
|
|
540
|
+
"assertions-required",
|
|
541
|
+
"pom-dangling-import",
|
|
542
|
+
"import-tokens"
|
|
543
|
+
];
|
|
544
|
+
function isLockedGate(id) {
|
|
545
|
+
return LOCKED_GATE_IDS.includes(id);
|
|
546
|
+
}
|
|
547
|
+
function normalizeGatePolicy(raw) {
|
|
548
|
+
if (typeof raw !== "object" || raw === null) return DEFAULT_GATE_POLICY;
|
|
549
|
+
const record = raw;
|
|
550
|
+
const disabled = Array.isArray(record.disabled) ? record.disabled.filter((id) => typeof id === "string" && !isLockedGate(id)) : [];
|
|
551
|
+
const severityOverrides = {};
|
|
552
|
+
if (typeof record.severityOverrides === "object" && record.severityOverrides !== null) {
|
|
553
|
+
for (const [id, severity] of Object.entries(record.severityOverrides)) {
|
|
554
|
+
if (severity === "error" || severity === "warning") severityOverrides[id] = severity;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const custom = Array.isArray(record.custom) ? record.custom.map(normalizeCustomGate).filter((gate) => gate !== null) : [];
|
|
558
|
+
return { version: 1, disabled, severityOverrides, custom };
|
|
559
|
+
}
|
|
560
|
+
function normalizeCustomGate(raw) {
|
|
561
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
562
|
+
const record = raw;
|
|
563
|
+
const id = typeof record.id === "string" && record.id.trim() ? record.id : null;
|
|
564
|
+
const name = typeof record.name === "string" && record.name.trim() ? record.name.trim() : null;
|
|
565
|
+
if (!id || !name) return null;
|
|
566
|
+
const severity = record.severity === "warning" ? "warning" : "error";
|
|
567
|
+
const enabled = record.enabled !== false;
|
|
568
|
+
if (record.kind === "ai") {
|
|
569
|
+
const prompt = typeof record.prompt === "string" ? record.prompt.trim() : "";
|
|
570
|
+
if (!prompt) return null;
|
|
571
|
+
return { id, kind: "ai", name, prompt, severity, enabled };
|
|
572
|
+
}
|
|
573
|
+
const matcher = record.matcher;
|
|
574
|
+
const value = typeof matcher?.value === "string" ? matcher.value : "";
|
|
575
|
+
if (!value.trim()) return null;
|
|
576
|
+
return {
|
|
577
|
+
id,
|
|
578
|
+
kind: "pattern",
|
|
579
|
+
name,
|
|
580
|
+
description: typeof record.description === "string" ? record.description : "",
|
|
581
|
+
scope: isGateScope(record.scope) ? record.scope : "all",
|
|
582
|
+
condition: record.condition === "must_contain" ? "must_contain" : "must_not_contain",
|
|
583
|
+
matcher: {
|
|
584
|
+
type: matcher?.type === "regex" ? "regex" : "literal",
|
|
585
|
+
value,
|
|
586
|
+
caseInsensitive: matcher?.caseInsensitive === true
|
|
587
|
+
},
|
|
588
|
+
severity,
|
|
589
|
+
hint: typeof record.hint === "string" && record.hint.trim() ? record.hint.trim() : void 0,
|
|
590
|
+
enabled
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function isGateScope(value) {
|
|
594
|
+
return value === "spec" || value === "page-objects" || value === "fixtures" || value === "all";
|
|
595
|
+
}
|
|
596
|
+
function compileMatcher(gate) {
|
|
597
|
+
const flags = gate.matcher.caseInsensitive ? "i" : "";
|
|
598
|
+
try {
|
|
599
|
+
if (gate.matcher.type === "regex") return new RegExp(gate.matcher.value, flags);
|
|
600
|
+
return new RegExp(gate.matcher.value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
601
|
+
} catch {
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const AI_PROVIDERS = [
|
|
606
|
+
{
|
|
607
|
+
id: "anthropic",
|
|
608
|
+
label: "Anthropic (Claude)",
|
|
609
|
+
defaultModel: "claude-opus-5",
|
|
610
|
+
keyPlaceholder: "sk-ant-…",
|
|
611
|
+
authKinds: ["api_key"],
|
|
612
|
+
subscriptionNote: "A Claude Pro/Max subscription can't be used by third-party apps (Anthropic Consumer Terms, Feb 2026). Use an API key here, or connect Claude Code below to run on your plan.",
|
|
613
|
+
models: [
|
|
614
|
+
{ id: "claude-opus-5", label: "Claude Opus 5", description: "Frontier intelligence — best for exploration and repair", inputPer1M: 5, outputPer1M: 25, contextWindow: 1e6, vision: true },
|
|
615
|
+
{ id: "claude-sonnet-5", label: "Claude Sonnet 5", description: "Balanced speed and intelligence", inputPer1M: 2, outputPer1M: 10, contextWindow: 1e6, vision: true },
|
|
616
|
+
{ id: "claude-opus-4-8", label: "Claude Opus 4.8", description: "Previous frontier generation", inputPer1M: 5, outputPer1M: 25, contextWindow: 1e6, vision: true },
|
|
617
|
+
{ id: "claude-sonnet-4-6", label: "Claude Sonnet 4.6", description: "Previous Sonnet generation", inputPer1M: 3, outputPer1M: 15, contextWindow: 1e6, vision: true },
|
|
618
|
+
{ id: "claude-haiku-4-5", label: "Claude Haiku 4.5", description: "Fastest and cheapest — good for narration", inputPer1M: 1, outputPer1M: 5, contextWindow: 2e5, vision: true }
|
|
206
619
|
]
|
|
207
620
|
},
|
|
208
621
|
{
|
|
@@ -2974,382 +3387,133 @@ function registerAiHandlers() {
|
|
|
2974
3387
|
(_e, cmd) => listModels(cmd.connectionId, { refresh: cmd.refresh })
|
|
2975
3388
|
);
|
|
2976
3389
|
electron.ipcMain.handle(
|
|
2977
|
-
IPC_CHANNELS.getProjectAiUsage,
|
|
2978
|
-
(_e, cmd) => getProjectUsage(cmd.projectId)
|
|
2979
|
-
);
|
|
2980
|
-
}
|
|
2981
|
-
const IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
2982
|
-
"node_modules",
|
|
2983
|
-
".git",
|
|
2984
|
-
".tesbo",
|
|
2985
|
-
"dist",
|
|
2986
|
-
"build",
|
|
2987
|
-
"out",
|
|
2988
|
-
"coverage",
|
|
2989
|
-
"test-results",
|
|
2990
|
-
"playwright-report",
|
|
2991
|
-
".next",
|
|
2992
|
-
".turbo",
|
|
2993
|
-
".cache"
|
|
2994
|
-
]);
|
|
2995
|
-
const MAX_FILES$1 = 5e3;
|
|
2996
|
-
const MAX_FILE_BYTES = 512 * 1024;
|
|
2997
|
-
function insideProject(projectFolder, relativePath) {
|
|
2998
|
-
const root = node_path.resolve(projectFolder);
|
|
2999
|
-
const target = node_path.resolve(root, relativePath);
|
|
3000
|
-
if (target === root) return null;
|
|
3001
|
-
return target.startsWith(root + node_path.sep) ? target : null;
|
|
3002
|
-
}
|
|
3003
|
-
async function walk(root, dir, out) {
|
|
3004
|
-
const entries = await node_fs.promises.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
3005
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
3006
|
-
for (const entry of entries) {
|
|
3007
|
-
if (out.length >= MAX_FILES$1) return true;
|
|
3008
|
-
const full = node_path.join(dir, entry.name);
|
|
3009
|
-
if (entry.isDirectory()) {
|
|
3010
|
-
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
3011
|
-
if (await walk(root, full, out)) return true;
|
|
3012
|
-
} else if (entry.isFile()) {
|
|
3013
|
-
out.push(node_path.relative(root, full).split(node_path.sep).join("/"));
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
return false;
|
|
3017
|
-
}
|
|
3018
|
-
async function listProjectFiles(cmd) {
|
|
3019
|
-
const root = node_path.resolve(cmd.folderPath);
|
|
3020
|
-
const files = [];
|
|
3021
|
-
const truncated = await walk(root, root, files);
|
|
3022
|
-
files.sort();
|
|
3023
|
-
return { files, truncated };
|
|
3024
|
-
}
|
|
3025
|
-
async function readProjectFile(cmd) {
|
|
3026
|
-
const target = insideProject(cmd.folderPath, cmd.relativePath);
|
|
3027
|
-
if (!target) return { exists: false, content: null, truncated: false };
|
|
3028
|
-
const stat = await node_fs.promises.stat(target).catch(() => null);
|
|
3029
|
-
if (!stat || !stat.isFile()) return { exists: false, content: null, truncated: false };
|
|
3030
|
-
const handle = await node_fs.promises.open(target, "r");
|
|
3031
|
-
try {
|
|
3032
|
-
const length = Math.min(stat.size, MAX_FILE_BYTES);
|
|
3033
|
-
const buffer = Buffer.alloc(length);
|
|
3034
|
-
await handle.read(buffer, 0, length, 0);
|
|
3035
|
-
if (buffer.subarray(0, Math.min(length, 8e3)).includes(0)) {
|
|
3036
|
-
return { exists: true, content: null, truncated: false };
|
|
3037
|
-
}
|
|
3038
|
-
return { exists: true, content: buffer.toString("utf-8"), truncated: stat.size > length };
|
|
3039
|
-
} finally {
|
|
3040
|
-
await handle.close();
|
|
3041
|
-
}
|
|
3042
|
-
}
|
|
3043
|
-
function registerProjectFilesHandlers() {
|
|
3044
|
-
electron.ipcMain.handle(IPC_CHANNELS.listProjectFiles, (_e, cmd) => listProjectFiles(cmd));
|
|
3045
|
-
electron.ipcMain.handle(IPC_CHANNELS.readProjectFile, (_e, cmd) => readProjectFile(cmd));
|
|
3046
|
-
}
|
|
3047
|
-
function appStatePath() {
|
|
3048
|
-
return node_path.join(electron.app.getPath("userData"), "app-state.json");
|
|
3049
|
-
}
|
|
3050
|
-
async function readAppState() {
|
|
3051
|
-
try {
|
|
3052
|
-
return await node_fs.promises.readFile(appStatePath(), "utf-8");
|
|
3053
|
-
} catch {
|
|
3054
|
-
return null;
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
async function commit(value) {
|
|
3058
|
-
const path = appStatePath();
|
|
3059
|
-
if (value === null) {
|
|
3060
|
-
await node_fs.promises.rm(path, { force: true });
|
|
3061
|
-
return;
|
|
3062
|
-
}
|
|
3063
|
-
const tmp = `${path}.tmp`;
|
|
3064
|
-
await node_fs.promises.writeFile(tmp, value, "utf-8");
|
|
3065
|
-
await node_fs.promises.rename(tmp, path);
|
|
3066
|
-
}
|
|
3067
|
-
let queue = Promise.resolve();
|
|
3068
|
-
function writeAppState(value) {
|
|
3069
|
-
const next = queue.then(
|
|
3070
|
-
() => commit(value),
|
|
3071
|
-
() => commit(value)
|
|
3072
|
-
);
|
|
3073
|
-
queue = next.catch(() => void 0);
|
|
3074
|
-
return next;
|
|
3075
|
-
}
|
|
3076
|
-
function registerAppStateHandlers() {
|
|
3077
|
-
electron.ipcMain.handle(IPC_CHANNELS.getAppState, () => readAppState());
|
|
3078
|
-
electron.ipcMain.handle(IPC_CHANNELS.setAppState, (_e, value) => writeAppState(value));
|
|
3079
|
-
}
|
|
3080
|
-
const DEFAULT_BASE_URL = "https://api-app-atto.tesbo.io";
|
|
3081
|
-
const ACCESS_HEADER = "x-atto-access-code";
|
|
3082
|
-
function sessionPath() {
|
|
3083
|
-
return node_path.join(electron.app.getPath("userData"), "tesbo-link.json");
|
|
3084
|
-
}
|
|
3085
|
-
function readLink() {
|
|
3086
|
-
try {
|
|
3087
|
-
const parsed = JSON.parse(node_fs.readFileSync(sessionPath(), "utf8"));
|
|
3088
|
-
if (typeof parsed.code !== "string" || !parsed.code.trim()) return null;
|
|
3089
|
-
return { baseUrl: DEFAULT_BASE_URL, code: parsed.code.trim() };
|
|
3090
|
-
} catch {
|
|
3091
|
-
return null;
|
|
3092
|
-
}
|
|
3093
|
-
}
|
|
3094
|
-
function writeLink(link) {
|
|
3095
|
-
const path = sessionPath();
|
|
3096
|
-
node_fs.mkdirSync(electron.app.getPath("userData"), { recursive: true });
|
|
3097
|
-
node_fs.writeFileSync(path, JSON.stringify(link), { mode: 384 });
|
|
3098
|
-
node_fs.chmodSync(path, 384);
|
|
3099
|
-
}
|
|
3100
|
-
function clearLink() {
|
|
3101
|
-
node_fs.rmSync(sessionPath(), { force: true });
|
|
3102
|
-
}
|
|
3103
|
-
function disconnected(error = null) {
|
|
3104
|
-
return { connected: false, baseUrl: DEFAULT_BASE_URL, user: null, workspaces: [], projects: [], error };
|
|
3105
|
-
}
|
|
3106
|
-
async function errorMessage(response) {
|
|
3107
|
-
try {
|
|
3108
|
-
const body = await response.json();
|
|
3109
|
-
if (typeof body.error === "string" && body.error.trim()) return body.error;
|
|
3110
|
-
if (typeof body.message === "string" && body.message.trim()) return body.message;
|
|
3111
|
-
} catch {
|
|
3112
|
-
}
|
|
3113
|
-
return `Tesbo returned ${response.status}`;
|
|
3114
|
-
}
|
|
3115
|
-
function isTransientNetworkError(error) {
|
|
3116
|
-
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
3117
|
-
return /fetch failed|failed to fetch|network|ECONNRESET|ECONNREFUSED|ETIMEDOUT|ENOTFOUND|socket/i.test(
|
|
3118
|
-
message
|
|
3119
|
-
);
|
|
3120
|
-
}
|
|
3121
|
-
async function tesboFetch(link, path, init) {
|
|
3122
|
-
const run = () => fetch(`${link.baseUrl}${path}`, {
|
|
3123
|
-
...init,
|
|
3124
|
-
headers: {
|
|
3125
|
-
accept: "application/json",
|
|
3126
|
-
[ACCESS_HEADER]: link.code,
|
|
3127
|
-
...init?.body ? { "content-type": "application/json" } : {},
|
|
3128
|
-
...init?.headers
|
|
3129
|
-
}
|
|
3130
|
-
});
|
|
3131
|
-
try {
|
|
3132
|
-
return await run();
|
|
3133
|
-
} catch (error) {
|
|
3134
|
-
if (!isTransientNetworkError(error) || init?.method && init.method !== "GET") throw error;
|
|
3135
|
-
await new Promise((resolve2) => setTimeout(resolve2, 400));
|
|
3136
|
-
return await run();
|
|
3137
|
-
}
|
|
3138
|
-
}
|
|
3139
|
-
function asProjects(value) {
|
|
3140
|
-
if (!Array.isArray(value)) return [];
|
|
3141
|
-
const projects = [];
|
|
3142
|
-
for (const item of value) {
|
|
3143
|
-
if (!item || typeof item !== "object") continue;
|
|
3144
|
-
const row = item;
|
|
3145
|
-
if (typeof row.id !== "string" || typeof row.name !== "string") continue;
|
|
3146
|
-
projects.push({
|
|
3147
|
-
id: row.id,
|
|
3148
|
-
key: typeof row.key === "string" ? row.key : "",
|
|
3149
|
-
name: row.name,
|
|
3150
|
-
role: typeof row.role === "string" ? row.role : "member",
|
|
3151
|
-
clientName: typeof row.clientName === "string" ? row.clientName : void 0,
|
|
3152
|
-
userName: typeof row.userName === "string" ? row.userName : void 0
|
|
3153
|
-
});
|
|
3154
|
-
}
|
|
3155
|
-
return projects;
|
|
3156
|
-
}
|
|
3157
|
-
async function loadAccount(link) {
|
|
3158
|
-
const response = await tesboFetch(link, "/api/atto/projects");
|
|
3159
|
-
if (response.status === 401) {
|
|
3160
|
-
clearLink();
|
|
3161
|
-
return disconnected(await errorMessage(response));
|
|
3162
|
-
}
|
|
3163
|
-
if (!response.ok) throw new Error(await errorMessage(response));
|
|
3164
|
-
const projects = asProjects(await response.json());
|
|
3165
|
-
return {
|
|
3166
|
-
connected: true,
|
|
3167
|
-
baseUrl: link.baseUrl,
|
|
3168
|
-
user: signedInUser(projects),
|
|
3169
|
-
workspaces: [],
|
|
3170
|
-
projects,
|
|
3171
|
-
error: null
|
|
3172
|
-
};
|
|
3390
|
+
IPC_CHANNELS.getProjectAiUsage,
|
|
3391
|
+
(_e, cmd) => getProjectUsage(cmd.projectId)
|
|
3392
|
+
);
|
|
3173
3393
|
}
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3394
|
+
const IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
3395
|
+
"node_modules",
|
|
3396
|
+
".git",
|
|
3397
|
+
".tesbo",
|
|
3398
|
+
"dist",
|
|
3399
|
+
"build",
|
|
3400
|
+
"out",
|
|
3401
|
+
"coverage",
|
|
3402
|
+
"test-results",
|
|
3403
|
+
"playwright-report",
|
|
3404
|
+
".next",
|
|
3405
|
+
".turbo",
|
|
3406
|
+
".cache"
|
|
3407
|
+
]);
|
|
3408
|
+
const MAX_FILES$1 = 5e3;
|
|
3409
|
+
const MAX_FILE_BYTES = 512 * 1024;
|
|
3410
|
+
function insideProject(projectFolder, relativePath) {
|
|
3411
|
+
const root = node_path.resolve(projectFolder);
|
|
3412
|
+
const target = node_path.resolve(root, relativePath);
|
|
3413
|
+
if (target === root) return null;
|
|
3414
|
+
return target.startsWith(root + node_path.sep) ? target : null;
|
|
3179
3415
|
}
|
|
3180
|
-
async function
|
|
3181
|
-
const
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
if (
|
|
3187
|
-
|
|
3416
|
+
async function walk(root, dir, out) {
|
|
3417
|
+
const entries = await node_fs.promises.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
3418
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
3419
|
+
for (const entry of entries) {
|
|
3420
|
+
if (out.length >= MAX_FILES$1) return true;
|
|
3421
|
+
const full = node_path.join(dir, entry.name);
|
|
3422
|
+
if (entry.isDirectory()) {
|
|
3423
|
+
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
3424
|
+
if (await walk(root, full, out)) return true;
|
|
3425
|
+
} else if (entry.isFile()) {
|
|
3426
|
+
out.push(node_path.relative(root, full).split(node_path.sep).join("/"));
|
|
3427
|
+
}
|
|
3188
3428
|
}
|
|
3429
|
+
return false;
|
|
3189
3430
|
}
|
|
3190
|
-
async function
|
|
3191
|
-
const
|
|
3192
|
-
|
|
3193
|
-
const
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3431
|
+
async function listProjectFiles(cmd) {
|
|
3432
|
+
const root = node_path.resolve(cmd.folderPath);
|
|
3433
|
+
const files = [];
|
|
3434
|
+
const truncated = await walk(root, root, files);
|
|
3435
|
+
files.sort();
|
|
3436
|
+
return { files, truncated };
|
|
3437
|
+
}
|
|
3438
|
+
async function readProjectFile(cmd) {
|
|
3439
|
+
const target = insideProject(cmd.folderPath, cmd.relativePath);
|
|
3440
|
+
if (!target) return { exists: false, content: null, truncated: false };
|
|
3441
|
+
const stat = await node_fs.promises.stat(target).catch(() => null);
|
|
3442
|
+
if (!stat || !stat.isFile()) return { exists: false, content: null, truncated: false };
|
|
3443
|
+
const handle = await node_fs.promises.open(target, "r");
|
|
3200
3444
|
try {
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3445
|
+
const length = Math.min(stat.size, MAX_FILE_BYTES);
|
|
3446
|
+
const buffer = Buffer.alloc(length);
|
|
3447
|
+
await handle.read(buffer, 0, length, 0);
|
|
3448
|
+
if (buffer.subarray(0, Math.min(length, 8e3)).includes(0)) {
|
|
3449
|
+
return { exists: true, content: null, truncated: false };
|
|
3450
|
+
}
|
|
3451
|
+
return { exists: true, content: buffer.toString("utf-8"), truncated: stat.size > length };
|
|
3452
|
+
} finally {
|
|
3453
|
+
await handle.close();
|
|
3206
3454
|
}
|
|
3207
|
-
if (!response.ok) throw new Error(await errorMessage(response));
|
|
3208
|
-
writeLink(link);
|
|
3209
|
-
const projects = asProjects(await response.json());
|
|
3210
|
-
return {
|
|
3211
|
-
connected: true,
|
|
3212
|
-
baseUrl: link.baseUrl,
|
|
3213
|
-
user: signedInUser(projects),
|
|
3214
|
-
workspaces: [],
|
|
3215
|
-
projects,
|
|
3216
|
-
error: null
|
|
3217
|
-
};
|
|
3218
3455
|
}
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3456
|
+
function registerProjectFilesHandlers() {
|
|
3457
|
+
electron.ipcMain.handle(IPC_CHANNELS.listProjectFiles, (_e, cmd) => listProjectFiles(cmd));
|
|
3458
|
+
electron.ipcMain.handle(IPC_CHANNELS.readProjectFile, (_e, cmd) => readProjectFile(cmd));
|
|
3222
3459
|
}
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
id: "zyra",
|
|
3226
|
-
name: "Zyra the Test Generator",
|
|
3227
|
-
role: "AI testcase generation agent",
|
|
3228
|
-
summary: "Stays on Tesbo for the QAble team. This package does not open the website.",
|
|
3229
|
-
status: "active",
|
|
3230
|
-
detail: null
|
|
3231
|
-
},
|
|
3232
|
-
{
|
|
3233
|
-
id: "nyra",
|
|
3234
|
-
name: "NYRA",
|
|
3235
|
-
role: "App exploration agent",
|
|
3236
|
-
summary: "Stays on Tesbo for the QAble team. This package does not open the website.",
|
|
3237
|
-
status: "active",
|
|
3238
|
-
detail: null
|
|
3239
|
-
}
|
|
3240
|
-
];
|
|
3241
|
-
const COMING_SOON = [
|
|
3242
|
-
{
|
|
3243
|
-
id: "run-analyst",
|
|
3244
|
-
name: "Run Analyst",
|
|
3245
|
-
role: "Execution insight agent",
|
|
3246
|
-
summary: "Planned for run failure clustering, flaky-test signals, and release risk notes.",
|
|
3247
|
-
status: "coming-soon",
|
|
3248
|
-
detail: null
|
|
3249
|
-
},
|
|
3250
|
-
{
|
|
3251
|
-
id: "bug-triage",
|
|
3252
|
-
name: "Bug Triage",
|
|
3253
|
-
role: "Defect analysis agent",
|
|
3254
|
-
summary: "Planned for duplicate bug checks, severity suggestions, and owner recommendations.",
|
|
3255
|
-
status: "coming-soon",
|
|
3256
|
-
detail: null
|
|
3257
|
-
}
|
|
3258
|
-
];
|
|
3259
|
-
async function tesboAgents(projectId) {
|
|
3260
|
-
const link = readLink();
|
|
3261
|
-
if (!link) throw new Error("Connect with an access code first.");
|
|
3262
|
-
if (!projectId.trim()) throw new Error("Choose a project.");
|
|
3263
|
-
const status = await loadAccount(link);
|
|
3264
|
-
if (!status.connected) throw new Error(status.error || "This access code has been stopped.");
|
|
3265
|
-
if (!status.projects.some((project) => project.id === projectId)) {
|
|
3266
|
-
throw new Error("This project is not available for this access code.");
|
|
3267
|
-
}
|
|
3268
|
-
return { projectId, agents: [...SERVER_AGENTS, ...COMING_SOON], notice: null };
|
|
3460
|
+
function appStatePath() {
|
|
3461
|
+
return node_path.join(electron.app.getPath("userData"), "app-state.json");
|
|
3269
3462
|
}
|
|
3270
|
-
function
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
const root = folder.endsWith(node_path.sep) ? folder : folder + node_path.sep;
|
|
3276
|
-
if (target !== folder && !target.startsWith(root)) {
|
|
3277
|
-
throw new Error("Refusing to write outside the configured save location.");
|
|
3463
|
+
async function readAppState() {
|
|
3464
|
+
try {
|
|
3465
|
+
return await node_fs.promises.readFile(appStatePath(), "utf-8");
|
|
3466
|
+
} catch {
|
|
3467
|
+
return null;
|
|
3278
3468
|
}
|
|
3279
|
-
return target;
|
|
3280
3469
|
}
|
|
3281
|
-
async function
|
|
3282
|
-
const
|
|
3283
|
-
if (
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
clearLink();
|
|
3287
|
-
return { saved: 0, errors: ["Access code stopped."] };
|
|
3288
|
-
}
|
|
3289
|
-
if (!response.ok) throw new Error(await errorMessage(response));
|
|
3290
|
-
const body = await response.json();
|
|
3291
|
-
const scripts = Array.isArray(body.scripts) ? body.scripts : [];
|
|
3292
|
-
let saved = 0;
|
|
3293
|
-
const errors = [];
|
|
3294
|
-
for (const item of scripts) {
|
|
3295
|
-
if (!item?.id || !item.script || !item.savePath) continue;
|
|
3296
|
-
try {
|
|
3297
|
-
const target = safeTargetPath(item.savePath, item.fileName || `${item.externalId || "script"}.spec.ts`);
|
|
3298
|
-
node_fs.mkdirSync(node_path.resolve(node_path.normalize(item.savePath.trim())), { recursive: true });
|
|
3299
|
-
node_fs.writeFileSync(target, item.script, { encoding: "utf8" });
|
|
3300
|
-
const ack = await tesboFetch(link, `/api/atto/scripts/${encodeURIComponent(item.id)}/ack`, { method: "POST", body: "{}" });
|
|
3301
|
-
if (!ack.ok) throw new Error(await errorMessage(ack));
|
|
3302
|
-
saved += 1;
|
|
3303
|
-
} catch (error) {
|
|
3304
|
-
errors.push(error instanceof Error ? error.message : "Could not save a script.");
|
|
3305
|
-
}
|
|
3470
|
+
async function commit(value) {
|
|
3471
|
+
const path = appStatePath();
|
|
3472
|
+
if (value === null) {
|
|
3473
|
+
await node_fs.promises.rm(path, { force: true });
|
|
3474
|
+
return;
|
|
3306
3475
|
}
|
|
3307
|
-
|
|
3476
|
+
const tmp = `${path}.tmp`;
|
|
3477
|
+
await node_fs.promises.writeFile(tmp, value, "utf-8");
|
|
3478
|
+
await node_fs.promises.rename(tmp, path);
|
|
3308
3479
|
}
|
|
3309
|
-
let
|
|
3310
|
-
|
|
3311
|
-
const
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
}
|
|
3318
|
-
if (!response.ok) throw new Error(await errorMessage(response));
|
|
3319
|
-
const body = await response.json();
|
|
3320
|
-
return {
|
|
3321
|
-
userName: String(body.userName || ""),
|
|
3322
|
-
clientName: String(body.clientName || ""),
|
|
3323
|
-
projectId: String(body.projectId || ""),
|
|
3324
|
-
projectName: String(body.projectName || ""),
|
|
3325
|
-
scriptSavePath: String(body.scriptSavePath || "").trim(),
|
|
3326
|
-
browserMode: body.browserMode === "headless" ? "headless" : "headed",
|
|
3327
|
-
targetUrl: String(body.targetUrl || "").trim(),
|
|
3328
|
-
description: String(body.description || "").trim(),
|
|
3329
|
-
memories: Array.isArray(body.memories) ? body.memories : [],
|
|
3330
|
-
qualityGates: body.qualityGates && typeof body.qualityGates === "object" ? body.qualityGates : {},
|
|
3331
|
-
install: {
|
|
3332
|
-
package: String(body.install?.package || "npm install -g @qablehq/atto"),
|
|
3333
|
-
chromium: String(body.install?.chromium || "npx playwright install chromium"),
|
|
3334
|
-
note: String(body.install?.note || "")
|
|
3335
|
-
}
|
|
3336
|
-
};
|
|
3480
|
+
let queue = Promise.resolve();
|
|
3481
|
+
function writeAppState(value) {
|
|
3482
|
+
const next = queue.then(
|
|
3483
|
+
() => commit(value),
|
|
3484
|
+
() => commit(value)
|
|
3485
|
+
);
|
|
3486
|
+
queue = next.catch(() => void 0);
|
|
3487
|
+
return next;
|
|
3337
3488
|
}
|
|
3338
|
-
function
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
void pullAndSavePendingScripts().catch(() => void 0);
|
|
3342
|
-
};
|
|
3343
|
-
tick();
|
|
3344
|
-
scriptPollTimer = setInterval(tick, intervalMs);
|
|
3345
|
-
scriptPollTimer.unref?.();
|
|
3489
|
+
function registerAppStateHandlers() {
|
|
3490
|
+
electron.ipcMain.handle(IPC_CHANNELS.getAppState, () => readAppState());
|
|
3491
|
+
electron.ipcMain.handle(IPC_CHANNELS.setAppState, (_e, value) => writeAppState(value));
|
|
3346
3492
|
}
|
|
3347
|
-
function registerTesboHandlers() {
|
|
3493
|
+
function registerTesboHandlers(adapter) {
|
|
3348
3494
|
electron.ipcMain.handle(IPC_CHANNELS.tesboStatus, () => tesboStatus());
|
|
3349
3495
|
electron.ipcMain.handle(IPC_CHANNELS.tesboLogin, (_event, cmd) => tesboLogin(cmd));
|
|
3350
3496
|
electron.ipcMain.handle(IPC_CHANNELS.tesboLogout, () => tesboLogout());
|
|
3351
3497
|
electron.ipcMain.handle(IPC_CHANNELS.tesboAgents, (_event, projectId) => tesboAgents(projectId));
|
|
3352
3498
|
electron.ipcMain.handle(IPC_CHANNELS.tesboRemoteConfig, () => fetchAttoRemoteConfig());
|
|
3499
|
+
electron.ipcMain.handle(
|
|
3500
|
+
IPC_CHANNELS.tesboAckRemoteSession,
|
|
3501
|
+
async (_event, cmd) => {
|
|
3502
|
+
await ackAttoRemoteSession(cmd.id, cmd.status, cmd.error, cmd.desktopSessionId);
|
|
3503
|
+
}
|
|
3504
|
+
);
|
|
3505
|
+
electron.ipcMain.handle(
|
|
3506
|
+
IPC_CHANNELS.tesboBindRemoteSession,
|
|
3507
|
+
async (_event, cmd) => {
|
|
3508
|
+
bindRemoteSessionJob(cmd.jobId, cmd.desktopSessionId);
|
|
3509
|
+
}
|
|
3510
|
+
);
|
|
3511
|
+
setRemoteSessionSink((job) => {
|
|
3512
|
+
for (const win of electron.BrowserWindow.getAllWindows()) {
|
|
3513
|
+
win.webContents.send(IPC_CHANNELS.tesboRemoteSession, job);
|
|
3514
|
+
}
|
|
3515
|
+
});
|
|
3516
|
+
if (adapter) attachEngineForRemoteAnswers(adapter);
|
|
3353
3517
|
startAttoScriptPoller();
|
|
3354
3518
|
void pullAndSavePendingScripts().catch(() => void 0);
|
|
3355
3519
|
}
|
|
@@ -12328,7 +12492,7 @@ electron.app.whenReady().then(() => {
|
|
|
12328
12492
|
registerAiHandlers();
|
|
12329
12493
|
registerProjectFilesHandlers();
|
|
12330
12494
|
registerAppStateHandlers();
|
|
12331
|
-
registerTesboHandlers();
|
|
12495
|
+
registerTesboHandlers(engine);
|
|
12332
12496
|
createMainWindow();
|
|
12333
12497
|
setupAutoUpdater();
|
|
12334
12498
|
electron.app.on("activate", () => {
|