@qablehq/atto 0.0.29 → 0.0.30
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 +54 -6
- package/package.json +1 -1
package/out/main/index.js
CHANGED
|
@@ -341,10 +341,11 @@ async function tesboAgents(projectId) {
|
|
|
341
341
|
}
|
|
342
342
|
return { projectId, agents: [...SERVER_AGENTS, ...COMING_SOON], notice: null };
|
|
343
343
|
}
|
|
344
|
-
function safeTargetPath(savePath,
|
|
344
|
+
function safeTargetPath(savePath, relativePath) {
|
|
345
345
|
const folder = node_path.resolve(node_path.normalize(savePath.trim()));
|
|
346
346
|
if (!node_path.isAbsolute(folder)) throw new Error("Save location from Tesbo must be an absolute path.");
|
|
347
|
-
const
|
|
347
|
+
const relative = String(relativePath || "script.spec.ts").replace(/\\/g, "/").replace(/^\/+/, "").split("/").filter((part) => part && part !== "." && part !== "..").join("/");
|
|
348
|
+
const base = relative || "script.spec.ts";
|
|
348
349
|
const target = node_path.resolve(folder, base);
|
|
349
350
|
const root = folder.endsWith(node_path.sep) ? folder : folder + node_path.sep;
|
|
350
351
|
if (target !== folder && !target.startsWith(root)) {
|
|
@@ -366,11 +367,16 @@ async function pullAndSavePendingScripts() {
|
|
|
366
367
|
let saved = 0;
|
|
367
368
|
const errors = [];
|
|
368
369
|
for (const item of scripts) {
|
|
369
|
-
|
|
370
|
+
const bundle = Array.isArray(item?.files) && item.files.length > 0 ? item.files.filter((file) => file?.path && typeof file.content === "string") : item?.script ? [{ path: item.fileName || `${item.externalId || "script"}.spec.ts`, content: item.script }] : [];
|
|
371
|
+
if (!item?.id || !item.savePath || bundle.length === 0) continue;
|
|
370
372
|
try {
|
|
371
|
-
const
|
|
372
|
-
node_fs.mkdirSync(
|
|
373
|
-
|
|
373
|
+
const root = node_path.resolve(node_path.normalize(item.savePath.trim()));
|
|
374
|
+
node_fs.mkdirSync(root, { recursive: true });
|
|
375
|
+
for (const file of bundle) {
|
|
376
|
+
const target = safeTargetPath(item.savePath, file.path);
|
|
377
|
+
node_fs.mkdirSync(node_path.dirname(target), { recursive: true });
|
|
378
|
+
node_fs.writeFileSync(target, file.content, { encoding: "utf8" });
|
|
379
|
+
}
|
|
374
380
|
const ack = await tesboFetch(link, `/api/atto/scripts/${encodeURIComponent(item.id)}/ack`, { method: "POST", body: "{}" });
|
|
375
381
|
if (!ack.ok) throw new Error(await errorMessage(ack));
|
|
376
382
|
saved += 1;
|
|
@@ -653,6 +659,29 @@ function listPcFolderEntries(requestPath) {
|
|
|
653
659
|
const parentPath = parent === abs ? null : parent;
|
|
654
660
|
return { path: abs, parentPath, entries };
|
|
655
661
|
}
|
|
662
|
+
|
|
663
|
+
function createPcFolder(parentPath, name) {
|
|
664
|
+
const parent = node_path.resolve(String(parentPath || "").trim());
|
|
665
|
+
const folderName = String(name || "").trim();
|
|
666
|
+
if (!parent || !node_path.isAbsolute(parent) || !safeStatDir(parent)) {
|
|
667
|
+
throw new Error("Open a real folder on the PC first.");
|
|
668
|
+
}
|
|
669
|
+
if (!folderName) throw new Error("Enter a folder name.");
|
|
670
|
+
if (folderName.length > 120) throw new Error("Folder name is too long.");
|
|
671
|
+
if (/[\\/]/.test(folderName) || folderName === "." || folderName === "..") {
|
|
672
|
+
throw new Error("Folder name cannot contain path separators.");
|
|
673
|
+
}
|
|
674
|
+
const target = node_path.resolve(parent, folderName);
|
|
675
|
+
const root = parent.endsWith(node_path.sep) ? parent : parent + node_path.sep;
|
|
676
|
+
if (target !== parent && !target.startsWith(root)) {
|
|
677
|
+
throw new Error("Refusing to create a folder outside the selected path.");
|
|
678
|
+
}
|
|
679
|
+
if (safeStatDir(target)) {
|
|
680
|
+
return { path: target, parentPath: parent };
|
|
681
|
+
}
|
|
682
|
+
node_fs.mkdirSync(target, { recursive: false });
|
|
683
|
+
return { path: target, parentPath: parent };
|
|
684
|
+
}
|
|
656
685
|
const claimedDesktopCommands = /* @__PURE__ */ new Set();
|
|
657
686
|
async function pullAndHandleDesktopCommands() {
|
|
658
687
|
const link = readLink();
|
|
@@ -686,6 +715,25 @@ async function pullAndHandleDesktopCommands() {
|
|
|
686
715
|
}
|
|
687
716
|
continue;
|
|
688
717
|
}
|
|
718
|
+
|
|
719
|
+
if (command.type === "create_folder") {
|
|
720
|
+
const parentPath = String(command.parentPath || "").trim();
|
|
721
|
+
const name = String(command.name || "").trim();
|
|
722
|
+
try {
|
|
723
|
+
const created = createPcFolder(parentPath, name);
|
|
724
|
+
await tesboFetch(link, `/api/atto/commands/${encodeURIComponent(command.id)}/complete`, {
|
|
725
|
+
method: "POST",
|
|
726
|
+
body: JSON.stringify(created)
|
|
727
|
+
});
|
|
728
|
+
} catch (err) {
|
|
729
|
+
const message = err instanceof Error ? err.message : "Could not create folder.";
|
|
730
|
+
await tesboFetch(link, `/api/atto/commands/${encodeURIComponent(command.id)}/complete`, {
|
|
731
|
+
method: "POST",
|
|
732
|
+
body: JSON.stringify({ path: "", parentPath, error: message })
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
689
737
|
if (command.type !== "pick_folder") continue;
|
|
690
738
|
const win = electron.BrowserWindow.getFocusedWindow() ?? electron.BrowserWindow.getAllWindows()[0];
|
|
691
739
|
const result = win ? await electron.dialog.showOpenDialog(win, {
|