@harperfast/agent 0.12.1 → 0.13.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/dist/BrowserWebSocketTransport-YCNS4FS4.js +7 -0
- package/dist/LaunchOptions-Y7D2IMM3.js +9 -0
- package/dist/NodeWebSocketTransport-TOVQQIXD.js +8 -0
- package/dist/agent.js +497 -240
- package/dist/bidi-UGABXYIW.js +18794 -0
- package/dist/chunk-23SGXNI6.js +244 -0
- package/dist/chunk-2ESYSVXG.js +48 -0
- package/dist/chunk-435G4BZK.js +210767 -0
- package/dist/chunk-FCLITLWE.js +775 -0
- package/dist/chunk-MGX7MDP2.js +15 -0
- package/dist/chunk-PG3SGAEX.js +40 -0
- package/dist/chunk-SACY2WFT.js +12205 -0
- package/dist/chunk-SLTU5TTQ.js +31483 -0
- package/dist/chunk-VD4EVG4H.js +3692 -0
- package/dist/chunk-YLJAHQTP.js +30 -0
- package/dist/chunk-ZDS7NDTW.js +1661 -0
- package/dist/extract-zip-N66P73SM.js +1499 -0
- package/dist/helpers-4S4VJSDS.js +17 -0
- package/dist/main-J53CTMGG.js +60 -0
- package/dist/puppeteer-KULXOV7T.js +15064 -0
- package/dist/src-GTRPEVYZ.js +5 -0
- package/dist/tar-fs-ETYYVPLS.js +2562 -0
- package/dist/typescript-XXE3DJ5D.js +5 -0
- package/dist/yargs-CJ75NAFN.js +3230 -0
- package/package.json +4 -1
package/dist/agent.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "./chunk-2ESYSVXG.js";
|
|
2
3
|
|
|
3
4
|
// agent.ts
|
|
4
5
|
import "dotenv/config";
|
|
@@ -282,9 +283,9 @@ var HarperProcess = class {
|
|
|
282
283
|
this.stopTailingLogs();
|
|
283
284
|
}
|
|
284
285
|
getAndClearLogs() {
|
|
285
|
-
const
|
|
286
|
+
const logs2 = this.logs;
|
|
286
287
|
this.logs = [];
|
|
287
|
-
return
|
|
288
|
+
return logs2.join("");
|
|
288
289
|
}
|
|
289
290
|
};
|
|
290
291
|
var harperProcess = new HarperProcess();
|
|
@@ -702,10 +703,275 @@ function sayHi() {
|
|
|
702
703
|
);
|
|
703
704
|
}
|
|
704
705
|
|
|
705
|
-
// tools/
|
|
706
|
+
// tools/browser/browserClickTool.ts
|
|
707
|
+
import { tool } from "@openai/agents";
|
|
708
|
+
import { z } from "zod";
|
|
709
|
+
|
|
710
|
+
// tools/browser/browserManager.ts
|
|
711
|
+
var browser = null;
|
|
712
|
+
var page = null;
|
|
713
|
+
var logs = [];
|
|
714
|
+
async function getBrowser() {
|
|
715
|
+
if (!browser) {
|
|
716
|
+
let puppeteer;
|
|
717
|
+
try {
|
|
718
|
+
puppeteer = await import("./puppeteer-KULXOV7T.js");
|
|
719
|
+
} catch {
|
|
720
|
+
throw new Error(
|
|
721
|
+
"Puppeteer is not installed. Browser tools require puppeteer. Please install it with `npm install puppeteer`."
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
browser = await puppeteer.default.launch({
|
|
725
|
+
headless: false,
|
|
726
|
+
defaultViewport: null
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
return browser;
|
|
730
|
+
}
|
|
731
|
+
async function getPage() {
|
|
732
|
+
if (!page) {
|
|
733
|
+
const b = await getBrowser();
|
|
734
|
+
const pages = await b.pages();
|
|
735
|
+
if (pages.length > 0) {
|
|
736
|
+
page = pages[0];
|
|
737
|
+
} else {
|
|
738
|
+
page = await b.newPage();
|
|
739
|
+
}
|
|
740
|
+
page.on("console", (msg) => {
|
|
741
|
+
logs.push(`[${msg.type()}] ${msg.text()}`);
|
|
742
|
+
});
|
|
743
|
+
page.on("pageerror", (err) => {
|
|
744
|
+
logs.push(`[error] ${err.message || err}`);
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
return page;
|
|
748
|
+
}
|
|
749
|
+
function getBrowserLogs() {
|
|
750
|
+
return logs;
|
|
751
|
+
}
|
|
752
|
+
function clearBrowserLogs() {
|
|
753
|
+
logs.length = 0;
|
|
754
|
+
}
|
|
755
|
+
async function closeBrowser() {
|
|
756
|
+
if (browser) {
|
|
757
|
+
await browser.close();
|
|
758
|
+
browser = null;
|
|
759
|
+
page = null;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// tools/browser/browserClickTool.ts
|
|
764
|
+
var ToolParameters = z.object({
|
|
765
|
+
selector: z.string().describe("The CSS selector of the element to click."),
|
|
766
|
+
button: z.enum(["left", "right", "middle"]).default("left").describe("The button to use for the click."),
|
|
767
|
+
clickCount: z.number().default(1).describe("The number of times to click.")
|
|
768
|
+
});
|
|
769
|
+
async function execute({ selector, button, clickCount }) {
|
|
770
|
+
try {
|
|
771
|
+
const page2 = await getPage();
|
|
772
|
+
await page2.click(selector, { button, clickCount });
|
|
773
|
+
return `Successfully clicked on ${selector}`;
|
|
774
|
+
} catch (error) {
|
|
775
|
+
return `Error clicking on ${selector}: ${error}`;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
var browserClickTool = tool({
|
|
779
|
+
name: "browser_click",
|
|
780
|
+
description: "Clicks on an element specified by a CSS selector.",
|
|
781
|
+
parameters: ToolParameters,
|
|
782
|
+
execute
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
// tools/browser/browserCloseTool.ts
|
|
706
786
|
import { tool as tool2 } from "@openai/agents";
|
|
707
|
-
import chalk7 from "chalk";
|
|
708
787
|
import { z as z2 } from "zod";
|
|
788
|
+
var ToolParameters2 = z2.object({});
|
|
789
|
+
async function execute2() {
|
|
790
|
+
try {
|
|
791
|
+
await closeBrowser();
|
|
792
|
+
return "Browser closed successfully.";
|
|
793
|
+
} catch (error) {
|
|
794
|
+
return `Error closing browser: ${error}`;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
var browserCloseTool = tool2({
|
|
798
|
+
name: "browser_close",
|
|
799
|
+
description: "Closes the browser instance.",
|
|
800
|
+
parameters: ToolParameters2,
|
|
801
|
+
execute: execute2
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
// tools/browser/browserEvaluateTool.ts
|
|
805
|
+
import { tool as tool3 } from "@openai/agents";
|
|
806
|
+
import { z as z3 } from "zod";
|
|
807
|
+
var ToolParameters3 = z3.object({
|
|
808
|
+
script: z3.string().describe("The JavaScript to evaluate in the context of the page.")
|
|
809
|
+
});
|
|
810
|
+
async function execute3({ script }) {
|
|
811
|
+
try {
|
|
812
|
+
const page2 = await getPage();
|
|
813
|
+
const result = await page2.evaluate(script);
|
|
814
|
+
return JSON.stringify(result, null, 2);
|
|
815
|
+
} catch (error) {
|
|
816
|
+
return `Error evaluating script: ${error}`;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
var browserEvaluateTool = tool3({
|
|
820
|
+
name: "browser_evaluate",
|
|
821
|
+
description: "Evaluates JavaScript in the context of the current page.",
|
|
822
|
+
parameters: ToolParameters3,
|
|
823
|
+
execute: execute3
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
// tools/browser/browserGetContentTool.ts
|
|
827
|
+
import { tool as tool4 } from "@openai/agents";
|
|
828
|
+
import { z as z4 } from "zod";
|
|
829
|
+
var ToolParameters4 = z4.object({
|
|
830
|
+
type: z4.enum(["html", "text"]).default("html").describe("The type of content to retrieve (html or text).")
|
|
831
|
+
});
|
|
832
|
+
async function execute4({ type }) {
|
|
833
|
+
try {
|
|
834
|
+
const page2 = await getPage();
|
|
835
|
+
if (type === "text") {
|
|
836
|
+
return await page2.evaluate(() => document.body.innerText);
|
|
837
|
+
}
|
|
838
|
+
return await page2.content();
|
|
839
|
+
} catch (error) {
|
|
840
|
+
return `Error getting content: ${error}`;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
var browserGetContentTool = tool4({
|
|
844
|
+
name: "browser_get_content",
|
|
845
|
+
description: "Gets the content (HTML or text) of the current page.",
|
|
846
|
+
parameters: ToolParameters4,
|
|
847
|
+
execute: execute4
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
// tools/browser/browserGetLogsTool.ts
|
|
851
|
+
import { tool as tool5 } from "@openai/agents";
|
|
852
|
+
import { z as z5 } from "zod";
|
|
853
|
+
var ToolParameters5 = z5.object({
|
|
854
|
+
clear: z5.boolean().default(false).describe("Whether to clear the logs after reading them.")
|
|
855
|
+
});
|
|
856
|
+
async function execute5({ clear }) {
|
|
857
|
+
const logs2 = getBrowserLogs();
|
|
858
|
+
const result = logs2.length > 0 ? logs2.join("\n") : "No logs found.";
|
|
859
|
+
if (clear) {
|
|
860
|
+
clearBrowserLogs();
|
|
861
|
+
}
|
|
862
|
+
return result;
|
|
863
|
+
}
|
|
864
|
+
var browserGetLogsTool = tool5({
|
|
865
|
+
name: "browser_get_logs",
|
|
866
|
+
description: "Returns the console logs from the browser.",
|
|
867
|
+
parameters: ToolParameters5,
|
|
868
|
+
execute: execute5
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
// tools/browser/browserIsElementPresentTool.ts
|
|
872
|
+
import { tool as tool6 } from "@openai/agents";
|
|
873
|
+
import { z as z6 } from "zod";
|
|
874
|
+
var ToolParameters6 = z6.object({
|
|
875
|
+
selector: z6.string().describe("The CSS selector of the element to check for presence.")
|
|
876
|
+
});
|
|
877
|
+
async function execute6({ selector }) {
|
|
878
|
+
try {
|
|
879
|
+
const page2 = await getPage();
|
|
880
|
+
const element = await page2.$(selector);
|
|
881
|
+
return element !== null ? `Element ${selector} is present.` : `Element ${selector} is not present.`;
|
|
882
|
+
} catch (error) {
|
|
883
|
+
return `Error checking for element ${selector}: ${error}`;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
var browserIsElementPresentTool = tool6({
|
|
887
|
+
name: "browser_is_element_present",
|
|
888
|
+
description: "Checks if an element is present on the page.",
|
|
889
|
+
parameters: ToolParameters6,
|
|
890
|
+
execute: execute6
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
// tools/browser/browserNavigateTool.ts
|
|
894
|
+
import { tool as tool7 } from "@openai/agents";
|
|
895
|
+
import { z as z7 } from "zod";
|
|
896
|
+
var ToolParameters7 = z7.object({
|
|
897
|
+
url: z7.string().describe("The URL to navigate to."),
|
|
898
|
+
waitUntil: z7.enum(["load", "domcontentloaded", "networkidle0", "networkidle2"]).default("load").describe("When to consider navigation succeeded.")
|
|
899
|
+
});
|
|
900
|
+
async function execute7({ url, waitUntil }) {
|
|
901
|
+
try {
|
|
902
|
+
const page2 = await getPage();
|
|
903
|
+
await page2.goto(url, { waitUntil });
|
|
904
|
+
return `Successfully navigated to ${url}`;
|
|
905
|
+
} catch (error) {
|
|
906
|
+
return `Error navigating to ${url}: ${error}`;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
var browserNavigateTool = tool7({
|
|
910
|
+
name: "browser_navigate",
|
|
911
|
+
description: "Navigates the browser to a specified URL.",
|
|
912
|
+
parameters: ToolParameters7,
|
|
913
|
+
execute: execute7
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
// tools/browser/browserScreenshotTool.ts
|
|
917
|
+
import { tool as tool8 } from "@openai/agents";
|
|
918
|
+
import { z as z8 } from "zod";
|
|
919
|
+
var ToolParameters8 = z8.object({
|
|
920
|
+
fullPage: z8.boolean().default(false).describe("Whether to take a screenshot of the full scrollable page.")
|
|
921
|
+
});
|
|
922
|
+
async function execute8({ fullPage }) {
|
|
923
|
+
try {
|
|
924
|
+
const page2 = await getPage();
|
|
925
|
+
const screenshot = await page2.screenshot({
|
|
926
|
+
encoding: "base64",
|
|
927
|
+
type: "jpeg",
|
|
928
|
+
quality: 80,
|
|
929
|
+
fullPage
|
|
930
|
+
});
|
|
931
|
+
return {
|
|
932
|
+
type: "image",
|
|
933
|
+
image: `data:image/jpeg;base64,${screenshot}`,
|
|
934
|
+
detail: "auto"
|
|
935
|
+
};
|
|
936
|
+
} catch (error) {
|
|
937
|
+
return `Error taking screenshot: ${error}`;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
var browserScreenshotTool = tool8({
|
|
941
|
+
name: "browser_screenshot",
|
|
942
|
+
description: "Takes a screenshot of the current page.",
|
|
943
|
+
parameters: ToolParameters8,
|
|
944
|
+
execute: execute8
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
// tools/browser/browserTypeTool.ts
|
|
948
|
+
import { tool as tool9 } from "@openai/agents";
|
|
949
|
+
import { z as z9 } from "zod";
|
|
950
|
+
var ToolParameters9 = z9.object({
|
|
951
|
+
selector: z9.string().describe("The CSS selector of the element to type into."),
|
|
952
|
+
text: z9.string().describe("The text to type into the element."),
|
|
953
|
+
delay: z9.number().default(0).describe("Delay between key presses in milliseconds.")
|
|
954
|
+
});
|
|
955
|
+
async function execute9({ selector, text, delay }) {
|
|
956
|
+
try {
|
|
957
|
+
const page2 = await getPage();
|
|
958
|
+
await page2.type(selector, text, { delay });
|
|
959
|
+
return `Successfully typed into ${selector}`;
|
|
960
|
+
} catch (error) {
|
|
961
|
+
return `Error typing into ${selector}: ${error}`;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
var browserTypeTool = tool9({
|
|
965
|
+
name: "browser_type",
|
|
966
|
+
description: "Types text into an element specified by a CSS selector.",
|
|
967
|
+
parameters: ToolParameters9,
|
|
968
|
+
execute: execute9
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
// tools/files/applyPatchTool.ts
|
|
972
|
+
import { tool as tool11 } from "@openai/agents";
|
|
973
|
+
import chalk7 from "chalk";
|
|
974
|
+
import { z as z11 } from "zod";
|
|
709
975
|
|
|
710
976
|
// utils/files/printDiff.ts
|
|
711
977
|
import chalk5 from "chalk";
|
|
@@ -746,11 +1012,11 @@ function getEnv(newKey, oldKey) {
|
|
|
746
1012
|
}
|
|
747
1013
|
|
|
748
1014
|
// tools/harper/getHarperSkillTool.ts
|
|
749
|
-
import { tool } from "@openai/agents";
|
|
1015
|
+
import { tool as tool10 } from "@openai/agents";
|
|
750
1016
|
import { readdirSync, readFileSync as readFileSync3 } from "fs";
|
|
751
1017
|
import { createRequire } from "module";
|
|
752
1018
|
import { dirname, join as join6 } from "path";
|
|
753
|
-
import { z } from "zod";
|
|
1019
|
+
import { z as z10 } from "zod";
|
|
754
1020
|
var createHarper = dirname(createRequire(import.meta.url).resolve("create-harper"));
|
|
755
1021
|
var agentsMarkdown = join6(
|
|
756
1022
|
createHarper,
|
|
@@ -763,16 +1029,16 @@ var skillsDir = join6(
|
|
|
763
1029
|
);
|
|
764
1030
|
var skillLinkRegex = /\[[^\]]+]\(skills\/([^)]+)\.md\)/g;
|
|
765
1031
|
var skills = getSkills();
|
|
766
|
-
var
|
|
767
|
-
skill:
|
|
1032
|
+
var ToolParameters10 = z10.object({
|
|
1033
|
+
skill: z10.enum(skills.length > 0 ? skills : ["none"]).describe(
|
|
768
1034
|
"The name of the skill to retrieve."
|
|
769
1035
|
)
|
|
770
1036
|
});
|
|
771
|
-
var getHarperSkillTool =
|
|
1037
|
+
var getHarperSkillTool = tool10({
|
|
772
1038
|
name: "getHarperSkill",
|
|
773
1039
|
description: getSkillsDescription(),
|
|
774
|
-
parameters:
|
|
775
|
-
execute
|
|
1040
|
+
parameters: ToolParameters10,
|
|
1041
|
+
execute: execute10
|
|
776
1042
|
});
|
|
777
1043
|
function getSkillsDescription() {
|
|
778
1044
|
try {
|
|
@@ -788,7 +1054,7 @@ function getSkills() {
|
|
|
788
1054
|
return [];
|
|
789
1055
|
}
|
|
790
1056
|
}
|
|
791
|
-
async function
|
|
1057
|
+
async function execute10({ skill }) {
|
|
792
1058
|
if (skill === "none") {
|
|
793
1059
|
return "No skills found.";
|
|
794
1060
|
}
|
|
@@ -933,10 +1199,10 @@ var WorkspaceEditor = class {
|
|
|
933
1199
|
};
|
|
934
1200
|
|
|
935
1201
|
// tools/files/applyPatchTool.ts
|
|
936
|
-
var ApplyPatchParameters =
|
|
937
|
-
type:
|
|
938
|
-
path:
|
|
939
|
-
diff:
|
|
1202
|
+
var ApplyPatchParameters = z11.object({
|
|
1203
|
+
type: z11.enum(["create_file", "update_file", "delete_file"]).describe("The type of operation to perform."),
|
|
1204
|
+
path: z11.string().describe("The path to the file to operate on."),
|
|
1205
|
+
diff: z11.string().optional().default("").describe(
|
|
940
1206
|
'The diff to apply. For create_file, every line must start with "+". For update_file, use a headerless unified diff format (start sections with "@@", and use "+", "-", or " " for lines). Do not include markers like "*** Begin Patch" or "*** Add File:".'
|
|
941
1207
|
)
|
|
942
1208
|
});
|
|
@@ -1011,7 +1277,7 @@ ${chalk7.bold.bgYellow.black(" Apply patch approval required: ")}`);
|
|
|
1011
1277
|
}
|
|
1012
1278
|
}
|
|
1013
1279
|
function createApplyPatchTool() {
|
|
1014
|
-
return
|
|
1280
|
+
return tool11({
|
|
1015
1281
|
name: "apply_patch",
|
|
1016
1282
|
description: "Applies a patch (create, update, or delete a file) to the workspace.",
|
|
1017
1283
|
parameters: ApplyPatchParameters,
|
|
@@ -1020,7 +1286,7 @@ function createApplyPatchTool() {
|
|
|
1020
1286
|
try {
|
|
1021
1287
|
const needed = await requiredSkillForOperation(operation.path, operation.type);
|
|
1022
1288
|
if (needed) {
|
|
1023
|
-
const content = await
|
|
1289
|
+
const content = await execute10({ skill: needed });
|
|
1024
1290
|
return { status: "completed", output: content };
|
|
1025
1291
|
}
|
|
1026
1292
|
switch (operation.type) {
|
|
@@ -1048,13 +1314,13 @@ function createApplyPatchTool() {
|
|
|
1048
1314
|
}
|
|
1049
1315
|
|
|
1050
1316
|
// tools/files/changeCwdTool.ts
|
|
1051
|
-
import { tool as
|
|
1317
|
+
import { tool as tool12 } from "@openai/agents";
|
|
1052
1318
|
import { statSync } from "fs";
|
|
1053
|
-
import { z as
|
|
1054
|
-
var
|
|
1055
|
-
path:
|
|
1319
|
+
import { z as z12 } from "zod";
|
|
1320
|
+
var ToolParameters11 = z12.object({
|
|
1321
|
+
path: z12.string().describe("Directory to switch into. Can be absolute or relative to current workspace.")
|
|
1056
1322
|
});
|
|
1057
|
-
async function
|
|
1323
|
+
async function execute11({ path: path8 }) {
|
|
1058
1324
|
try {
|
|
1059
1325
|
const target = resolvePath(trackedState.cwd, path8);
|
|
1060
1326
|
const stat = statSync(target);
|
|
@@ -1081,27 +1347,27 @@ I strongly suggest you use these newfound skills!`;
|
|
|
1081
1347
|
return `Failed to change directory: ${err.message}`;
|
|
1082
1348
|
}
|
|
1083
1349
|
}
|
|
1084
|
-
var changeCwdTool =
|
|
1350
|
+
var changeCwdTool = tool12({
|
|
1085
1351
|
name: "changeCwd",
|
|
1086
1352
|
description: "Changes the current working directory for subsequent tools. Accepts absolute or relative paths.",
|
|
1087
|
-
parameters:
|
|
1088
|
-
execute:
|
|
1353
|
+
parameters: ToolParameters11,
|
|
1354
|
+
execute: execute11
|
|
1089
1355
|
});
|
|
1090
1356
|
|
|
1091
1357
|
// tools/files/egrepTool.ts
|
|
1092
|
-
import { tool as
|
|
1358
|
+
import { tool as tool13 } from "@openai/agents";
|
|
1093
1359
|
import { execFile } from "child_process";
|
|
1094
1360
|
import { promisify } from "util";
|
|
1095
|
-
import { z as
|
|
1361
|
+
import { z as z13 } from "zod";
|
|
1096
1362
|
var execFileAsync = promisify(execFile);
|
|
1097
|
-
var
|
|
1098
|
-
path:
|
|
1099
|
-
pattern:
|
|
1363
|
+
var ToolParameters12 = z13.object({
|
|
1364
|
+
path: z13.string().describe("The path to start the search from."),
|
|
1365
|
+
pattern: z13.string().describe("The pattern to search")
|
|
1100
1366
|
});
|
|
1101
|
-
var egrepTool =
|
|
1367
|
+
var egrepTool = tool13({
|
|
1102
1368
|
name: "egrep",
|
|
1103
1369
|
description: "File pattern searcher.",
|
|
1104
|
-
parameters:
|
|
1370
|
+
parameters: ToolParameters12,
|
|
1105
1371
|
async execute({ path: searchPath, pattern }) {
|
|
1106
1372
|
try {
|
|
1107
1373
|
const resolvedPath = resolvePath(trackedState.cwd, searchPath);
|
|
@@ -1127,21 +1393,21 @@ var egrepTool = tool4({
|
|
|
1127
1393
|
});
|
|
1128
1394
|
|
|
1129
1395
|
// tools/files/findTool.ts
|
|
1130
|
-
import { tool as
|
|
1396
|
+
import { tool as tool14 } from "@openai/agents";
|
|
1131
1397
|
import { execFile as execFile2 } from "child_process";
|
|
1132
1398
|
import { promisify as promisify2 } from "util";
|
|
1133
|
-
import { z as
|
|
1399
|
+
import { z as z14 } from "zod";
|
|
1134
1400
|
var execFileAsync2 = promisify2(execFile2);
|
|
1135
|
-
var
|
|
1136
|
-
path:
|
|
1137
|
-
iname:
|
|
1401
|
+
var ToolParameters13 = z14.object({
|
|
1402
|
+
path: z14.string().describe("The path to start the search from."),
|
|
1403
|
+
iname: z14.string().describe(
|
|
1138
1404
|
"Case insensitive, true if the last component of the pathname being examined matches pattern. Special shell pattern matching characters (\u201C[\u201D, \u201C]\u201D, \u201C*\u201D, and \u201C?\u201D) may be used as part of pattern. These characters may be matched explicitly by escaping them with a backslash (\u201C\\\u201D)."
|
|
1139
1405
|
)
|
|
1140
1406
|
});
|
|
1141
|
-
var findTool =
|
|
1407
|
+
var findTool = tool14({
|
|
1142
1408
|
name: "find",
|
|
1143
1409
|
description: "Walk a file hierarchy.",
|
|
1144
|
-
parameters:
|
|
1410
|
+
parameters: ToolParameters13,
|
|
1145
1411
|
async execute({ path: searchPath, iname }) {
|
|
1146
1412
|
try {
|
|
1147
1413
|
const resolvedPath = resolvePath(trackedState.cwd, searchPath);
|
|
@@ -1154,17 +1420,17 @@ var findTool = tool5({
|
|
|
1154
1420
|
});
|
|
1155
1421
|
|
|
1156
1422
|
// tools/files/readDirTool.ts
|
|
1157
|
-
import { tool as
|
|
1423
|
+
import { tool as tool15 } from "@openai/agents";
|
|
1158
1424
|
import { readdir } from "fs/promises";
|
|
1159
1425
|
import path5 from "path";
|
|
1160
|
-
import { z as
|
|
1161
|
-
var
|
|
1162
|
-
directoryName:
|
|
1426
|
+
import { z as z15 } from "zod";
|
|
1427
|
+
var ToolParameters14 = z15.object({
|
|
1428
|
+
directoryName: z15.string().describe("The name of the directory to read.")
|
|
1163
1429
|
});
|
|
1164
|
-
var readDirTool =
|
|
1430
|
+
var readDirTool = tool15({
|
|
1165
1431
|
name: "readDir",
|
|
1166
1432
|
description: "Lists the files in a directory.",
|
|
1167
|
-
parameters:
|
|
1433
|
+
parameters: ToolParameters14,
|
|
1168
1434
|
async execute({ directoryName }) {
|
|
1169
1435
|
try {
|
|
1170
1436
|
const resolvedPath = resolvePath(trackedState.cwd, directoryName);
|
|
@@ -1177,51 +1443,70 @@ var readDirTool = tool6({
|
|
|
1177
1443
|
});
|
|
1178
1444
|
|
|
1179
1445
|
// tools/files/readFileTool.ts
|
|
1180
|
-
import { tool as
|
|
1446
|
+
import { tool as tool16 } from "@openai/agents";
|
|
1181
1447
|
import { readFile } from "fs/promises";
|
|
1182
|
-
import {
|
|
1183
|
-
|
|
1184
|
-
|
|
1448
|
+
import { extname } from "path";
|
|
1449
|
+
import { z as z16 } from "zod";
|
|
1450
|
+
var ToolParameters15 = z16.object({
|
|
1451
|
+
fileName: z16.string().describe("The name of the file to read.")
|
|
1185
1452
|
});
|
|
1186
|
-
var
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1453
|
+
var IMAGE_EXTENSIONS = {
|
|
1454
|
+
".png": "image/png",
|
|
1455
|
+
".jpg": "image/jpeg",
|
|
1456
|
+
".jpeg": "image/jpeg",
|
|
1457
|
+
".gif": "image/gif",
|
|
1458
|
+
".webp": "image/webp",
|
|
1459
|
+
".bmp": "image/bmp"
|
|
1460
|
+
};
|
|
1461
|
+
async function execute12({ fileName }) {
|
|
1462
|
+
try {
|
|
1463
|
+
const normalized = String(fileName).replace(/\\/g, "/");
|
|
1464
|
+
const m = normalized.match(/(?:^|\/)skills\/([A-Za-z0-9_-]+)\.md(?:$|[?#])/);
|
|
1465
|
+
if (m && m[1]) {
|
|
1466
|
+
trackedState.session?.addSkillRead?.(m[1]);
|
|
1467
|
+
}
|
|
1468
|
+
const resolvedPath = resolvePath(trackedState.cwd, fileName);
|
|
1469
|
+
const ext = extname(resolvedPath).toLowerCase();
|
|
1470
|
+
if (IMAGE_EXTENSIONS[ext]) {
|
|
1471
|
+
const buffer = await readFile(resolvedPath);
|
|
1472
|
+
return {
|
|
1473
|
+
type: "image",
|
|
1474
|
+
image: `data:${IMAGE_EXTENSIONS[ext]};base64,${buffer.toString("base64")}`,
|
|
1475
|
+
detail: "auto"
|
|
1476
|
+
};
|
|
1201
1477
|
}
|
|
1478
|
+
return await readFile(resolvedPath, "utf8");
|
|
1479
|
+
} catch (error) {
|
|
1480
|
+
return `Error reading file: ${error}`;
|
|
1202
1481
|
}
|
|
1482
|
+
}
|
|
1483
|
+
var readFileTool = tool16({
|
|
1484
|
+
name: "readFile",
|
|
1485
|
+
description: "Reads the contents of a specified file. If the file is an image, it returns a structured image object.",
|
|
1486
|
+
parameters: ToolParameters15,
|
|
1487
|
+
execute: execute12
|
|
1203
1488
|
});
|
|
1204
1489
|
|
|
1205
1490
|
// tools/general/codeInterpreterTool.ts
|
|
1206
|
-
import { tool as
|
|
1491
|
+
import { tool as tool17 } from "@openai/agents";
|
|
1207
1492
|
import chalk8 from "chalk";
|
|
1208
1493
|
import { exec } from "child_process";
|
|
1209
1494
|
import { unlink, writeFile as writeFile2 } from "fs/promises";
|
|
1210
1495
|
import path6 from "path";
|
|
1211
1496
|
import { promisify as promisify3 } from "util";
|
|
1212
|
-
import { z as
|
|
1497
|
+
import { z as z17 } from "zod";
|
|
1213
1498
|
var execAsync = promisify3(exec);
|
|
1214
|
-
var CodeInterpreterParameters =
|
|
1215
|
-
code:
|
|
1216
|
-
language:
|
|
1499
|
+
var CodeInterpreterParameters = z17.object({
|
|
1500
|
+
code: z17.string().describe("The code to execute."),
|
|
1501
|
+
language: z17.enum(["python", "javascript"]).optional().default("python").describe(
|
|
1217
1502
|
"The programming language of the code."
|
|
1218
1503
|
)
|
|
1219
1504
|
});
|
|
1220
|
-
var codeInterpreterTool =
|
|
1505
|
+
var codeInterpreterTool = tool17({
|
|
1221
1506
|
name: "code_interpreter",
|
|
1222
1507
|
description: "Executes Python or JavaScript code in a local environment. This is useful for data analysis, complex calculations, and more. All code will be executed in the current workspace.",
|
|
1223
1508
|
parameters: CodeInterpreterParameters,
|
|
1224
|
-
execute:
|
|
1509
|
+
execute: execute13,
|
|
1225
1510
|
needsApproval: needsApproval2
|
|
1226
1511
|
});
|
|
1227
1512
|
async function needsApproval2(runContext, { code, language }, callId) {
|
|
@@ -1243,7 +1528,7 @@ ${chalk8.bold.bgYellow.black(` Code interpreter (${language}) approval required:
|
|
|
1243
1528
|
}
|
|
1244
1529
|
return !autoApproved;
|
|
1245
1530
|
}
|
|
1246
|
-
async function
|
|
1531
|
+
async function execute13({ code, language }) {
|
|
1247
1532
|
const extension = language === "javascript" ? "js" : "py";
|
|
1248
1533
|
const interpreter = language === "javascript" ? "node" : "python3";
|
|
1249
1534
|
const tempFile = path6.join(trackedState.cwd, `.temp_code_${Date.now()}.${extension}`);
|
|
@@ -1265,8 +1550,8 @@ STDERR: ${error.stderr || ""}`;
|
|
|
1265
1550
|
}
|
|
1266
1551
|
|
|
1267
1552
|
// tools/general/setInterpreterAutoApproveTool.ts
|
|
1268
|
-
import { tool as
|
|
1269
|
-
import { z as
|
|
1553
|
+
import { tool as tool18 } from "@openai/agents";
|
|
1554
|
+
import { z as z18 } from "zod";
|
|
1270
1555
|
|
|
1271
1556
|
// utils/files/updateEnv.ts
|
|
1272
1557
|
import { existsSync as existsSync6 } from "fs";
|
|
@@ -1293,10 +1578,10 @@ async function updateEnv(key, value) {
|
|
|
1293
1578
|
}
|
|
1294
1579
|
|
|
1295
1580
|
// tools/general/setInterpreterAutoApproveTool.ts
|
|
1296
|
-
var SetInterpreterAutoApproveParameters =
|
|
1297
|
-
autoApprove:
|
|
1581
|
+
var SetInterpreterAutoApproveParameters = z18.object({
|
|
1582
|
+
autoApprove: z18.boolean()
|
|
1298
1583
|
});
|
|
1299
|
-
var setInterpreterAutoApproveTool =
|
|
1584
|
+
var setInterpreterAutoApproveTool = tool18({
|
|
1300
1585
|
name: "setInterpreterAutoApproveTool",
|
|
1301
1586
|
description: "Enable or disable automatic approval for code interpreter by setting HARPER_AGENT_AUTO_APPROVE_CODE_INTERPRETER=1 or 0 in .env and current process.",
|
|
1302
1587
|
parameters: SetInterpreterAutoApproveParameters,
|
|
@@ -1319,12 +1604,12 @@ var setInterpreterAutoApproveTool = tool9({
|
|
|
1319
1604
|
});
|
|
1320
1605
|
|
|
1321
1606
|
// tools/general/setPatchAutoApproveTool.ts
|
|
1322
|
-
import { tool as
|
|
1323
|
-
import { z as
|
|
1324
|
-
var SetPatchAutoApproveParameters =
|
|
1325
|
-
autoApprove:
|
|
1607
|
+
import { tool as tool19 } from "@openai/agents";
|
|
1608
|
+
import { z as z19 } from "zod";
|
|
1609
|
+
var SetPatchAutoApproveParameters = z19.object({
|
|
1610
|
+
autoApprove: z19.boolean()
|
|
1326
1611
|
});
|
|
1327
|
-
var setPatchAutoApproveTool =
|
|
1612
|
+
var setPatchAutoApproveTool = tool19({
|
|
1328
1613
|
name: "setPatchAutoApproveTool",
|
|
1329
1614
|
description: "Enable or disable automatic approval for patch commands by setting HARPER_AGENT_AUTO_APPROVE_PATCHES=1 or 0 in .env and current process.",
|
|
1330
1615
|
parameters: SetPatchAutoApproveParameters,
|
|
@@ -1347,12 +1632,12 @@ var setPatchAutoApproveTool = tool10({
|
|
|
1347
1632
|
});
|
|
1348
1633
|
|
|
1349
1634
|
// tools/general/setShellAutoApproveTool.ts
|
|
1350
|
-
import { tool as
|
|
1351
|
-
import { z as
|
|
1352
|
-
var SetShellAutoApproveParameters =
|
|
1353
|
-
autoApprove:
|
|
1635
|
+
import { tool as tool20 } from "@openai/agents";
|
|
1636
|
+
import { z as z20 } from "zod";
|
|
1637
|
+
var SetShellAutoApproveParameters = z20.object({
|
|
1638
|
+
autoApprove: z20.boolean()
|
|
1354
1639
|
});
|
|
1355
|
-
var setShellAutoApproveTool =
|
|
1640
|
+
var setShellAutoApproveTool = tool20({
|
|
1356
1641
|
name: "setShellAutoApproveTool",
|
|
1357
1642
|
description: "Enable or disable automatic approval for shell commands by setting HARPER_AGENT_AUTO_APPROVE_SHELL=1 or 0 in .env and current process.",
|
|
1358
1643
|
parameters: SetShellAutoApproveParameters,
|
|
@@ -1375,9 +1660,9 @@ var setShellAutoApproveTool = tool11({
|
|
|
1375
1660
|
});
|
|
1376
1661
|
|
|
1377
1662
|
// tools/general/shellTool.ts
|
|
1378
|
-
import { tool as
|
|
1663
|
+
import { tool as tool21 } from "@openai/agents";
|
|
1379
1664
|
import chalk9 from "chalk";
|
|
1380
|
-
import { z as
|
|
1665
|
+
import { z as z21 } from "zod";
|
|
1381
1666
|
|
|
1382
1667
|
// utils/files/mentionsIgnoredPath.ts
|
|
1383
1668
|
function mentionsIgnoredPath(command) {
|
|
@@ -1489,11 +1774,11 @@ var LocalShell = class {
|
|
|
1489
1774
|
};
|
|
1490
1775
|
|
|
1491
1776
|
// tools/general/shellTool.ts
|
|
1492
|
-
var ShellParameters =
|
|
1493
|
-
commands:
|
|
1777
|
+
var ShellParameters = z21.object({
|
|
1778
|
+
commands: z21.array(z21.string()).describe("The commands to execute.")
|
|
1494
1779
|
});
|
|
1495
1780
|
var shell = new LocalShell();
|
|
1496
|
-
var shellTool =
|
|
1781
|
+
var shellTool = tool21({
|
|
1497
1782
|
name: "shellToolForCommandsWithoutABetterTool",
|
|
1498
1783
|
description: "Executes shell commands.",
|
|
1499
1784
|
parameters: ShellParameters,
|
|
@@ -1550,15 +1835,15 @@ TIMEOUT`;
|
|
|
1550
1835
|
});
|
|
1551
1836
|
|
|
1552
1837
|
// tools/git/gitAddTool.ts
|
|
1553
|
-
import { tool as
|
|
1838
|
+
import { tool as tool22 } from "@openai/agents";
|
|
1554
1839
|
import { execFile as execFile3 } from "child_process";
|
|
1555
1840
|
import { promisify as promisify5 } from "util";
|
|
1556
|
-
import { z as
|
|
1841
|
+
import { z as z22 } from "zod";
|
|
1557
1842
|
var execFileAsync3 = promisify5(execFile3);
|
|
1558
|
-
var GitAddParameters =
|
|
1559
|
-
files:
|
|
1843
|
+
var GitAddParameters = z22.object({
|
|
1844
|
+
files: z22.array(z22.string()).describe("The files to add. If not provided, all changes will be added.")
|
|
1560
1845
|
});
|
|
1561
|
-
var gitAddTool =
|
|
1846
|
+
var gitAddTool = tool22({
|
|
1562
1847
|
name: "gitAddTool",
|
|
1563
1848
|
description: "Add file contents to the index.",
|
|
1564
1849
|
parameters: GitAddParameters,
|
|
@@ -1579,16 +1864,16 @@ var gitAddTool = tool13({
|
|
|
1579
1864
|
});
|
|
1580
1865
|
|
|
1581
1866
|
// tools/git/gitBranchTool.ts
|
|
1582
|
-
import { tool as
|
|
1867
|
+
import { tool as tool23 } from "@openai/agents";
|
|
1583
1868
|
import { execFile as execFile4 } from "child_process";
|
|
1584
1869
|
import { promisify as promisify6 } from "util";
|
|
1585
|
-
import { z as
|
|
1870
|
+
import { z as z23 } from "zod";
|
|
1586
1871
|
var execFileAsync4 = promisify6(execFile4);
|
|
1587
|
-
var GitBranchParameters =
|
|
1588
|
-
branchName:
|
|
1589
|
-
create:
|
|
1872
|
+
var GitBranchParameters = z23.object({
|
|
1873
|
+
branchName: z23.string().describe("The name of the branch to create or switch to."),
|
|
1874
|
+
create: z23.boolean().optional().default(false).describe("Whether to create a new branch.")
|
|
1590
1875
|
});
|
|
1591
|
-
var gitBranchTool =
|
|
1876
|
+
var gitBranchTool = tool23({
|
|
1592
1877
|
name: "gitBranchTool",
|
|
1593
1878
|
description: "Create or switch to a git branch.",
|
|
1594
1879
|
parameters: GitBranchParameters,
|
|
@@ -1605,18 +1890,18 @@ var gitBranchTool = tool14({
|
|
|
1605
1890
|
});
|
|
1606
1891
|
|
|
1607
1892
|
// tools/git/gitCommitTool.ts
|
|
1608
|
-
import { tool as
|
|
1893
|
+
import { tool as tool24 } from "@openai/agents";
|
|
1609
1894
|
import { execFile as execFile5 } from "child_process";
|
|
1610
1895
|
import { promisify as promisify7 } from "util";
|
|
1611
|
-
import { z as
|
|
1896
|
+
import { z as z24 } from "zod";
|
|
1612
1897
|
var execFileAsync5 = promisify7(execFile5);
|
|
1613
|
-
var GitCommitParameters =
|
|
1614
|
-
message:
|
|
1615
|
-
addAll:
|
|
1898
|
+
var GitCommitParameters = z24.object({
|
|
1899
|
+
message: z24.string().describe("The commit message."),
|
|
1900
|
+
addAll: z24.boolean().optional().default(false).describe(
|
|
1616
1901
|
"Whether to add all changes before committing (git commit -am)."
|
|
1617
1902
|
)
|
|
1618
1903
|
});
|
|
1619
|
-
var gitCommitTool =
|
|
1904
|
+
var gitCommitTool = tool24({
|
|
1620
1905
|
name: "gitCommitTool",
|
|
1621
1906
|
description: "Commit changes to the repository.",
|
|
1622
1907
|
parameters: GitCommitParameters,
|
|
@@ -1632,16 +1917,16 @@ var gitCommitTool = tool15({
|
|
|
1632
1917
|
});
|
|
1633
1918
|
|
|
1634
1919
|
// tools/git/gitLogTool.ts
|
|
1635
|
-
import { tool as
|
|
1920
|
+
import { tool as tool25 } from "@openai/agents";
|
|
1636
1921
|
import { execFile as execFile6 } from "child_process";
|
|
1637
1922
|
import { promisify as promisify8 } from "util";
|
|
1638
|
-
import { z as
|
|
1923
|
+
import { z as z25 } from "zod";
|
|
1639
1924
|
var execFileAsync6 = promisify8(execFile6);
|
|
1640
|
-
var GitLogParameters =
|
|
1641
|
-
count:
|
|
1642
|
-
oneline:
|
|
1925
|
+
var GitLogParameters = z25.object({
|
|
1926
|
+
count: z25.number().optional().default(10).describe("Number of commits to show."),
|
|
1927
|
+
oneline: z25.boolean().optional().default(true).describe("Whether to show log in oneline format.")
|
|
1643
1928
|
});
|
|
1644
|
-
var gitLogTool =
|
|
1929
|
+
var gitLogTool = tool25({
|
|
1645
1930
|
name: "gitLogTool",
|
|
1646
1931
|
description: "Show commit logs.",
|
|
1647
1932
|
parameters: GitLogParameters,
|
|
@@ -1660,17 +1945,17 @@ var gitLogTool = tool16({
|
|
|
1660
1945
|
});
|
|
1661
1946
|
|
|
1662
1947
|
// tools/git/gitStashTool.ts
|
|
1663
|
-
import { tool as
|
|
1948
|
+
import { tool as tool26 } from "@openai/agents";
|
|
1664
1949
|
import { execFile as execFile7 } from "child_process";
|
|
1665
1950
|
import { promisify as promisify9 } from "util";
|
|
1666
|
-
import { z as
|
|
1951
|
+
import { z as z26 } from "zod";
|
|
1667
1952
|
var execFileAsync7 = promisify9(execFile7);
|
|
1668
1953
|
var allowedActions = ["push", "pop", "apply", "list"];
|
|
1669
|
-
var GitStashParameters =
|
|
1670
|
-
action:
|
|
1671
|
-
message:
|
|
1954
|
+
var GitStashParameters = z26.object({
|
|
1955
|
+
action: z26.string().describe("The stash action to perform: " + allowedActions.join(", ")),
|
|
1956
|
+
message: z26.string().describe("A message for the stash change.")
|
|
1672
1957
|
});
|
|
1673
|
-
var gitStashTool =
|
|
1958
|
+
var gitStashTool = tool26({
|
|
1674
1959
|
name: "gitStashTool",
|
|
1675
1960
|
description: "Stash changes or apply a stash.",
|
|
1676
1961
|
parameters: GitStashParameters,
|
|
@@ -1692,15 +1977,15 @@ var gitStashTool = tool17({
|
|
|
1692
1977
|
});
|
|
1693
1978
|
|
|
1694
1979
|
// tools/git/gitStatusTool.ts
|
|
1695
|
-
import { tool as
|
|
1980
|
+
import { tool as tool27 } from "@openai/agents";
|
|
1696
1981
|
import { execFile as execFile8 } from "child_process";
|
|
1697
1982
|
import { promisify as promisify10 } from "util";
|
|
1698
|
-
import { z as
|
|
1983
|
+
import { z as z27 } from "zod";
|
|
1699
1984
|
var execFileAsync8 = promisify10(execFile8);
|
|
1700
|
-
var GitStatusParameters =
|
|
1701
|
-
short:
|
|
1985
|
+
var GitStatusParameters = z27.object({
|
|
1986
|
+
short: z27.boolean().optional().default(false).describe("Whether to show the status in short format.")
|
|
1702
1987
|
});
|
|
1703
|
-
var gitStatusTool =
|
|
1988
|
+
var gitStatusTool = tool27({
|
|
1704
1989
|
name: "gitStatusTool",
|
|
1705
1990
|
description: "Show the working tree status.",
|
|
1706
1991
|
parameters: GitStatusParameters,
|
|
@@ -1719,17 +2004,17 @@ var gitStatusTool = tool18({
|
|
|
1719
2004
|
});
|
|
1720
2005
|
|
|
1721
2006
|
// tools/git/gitWorkspaceTool.ts
|
|
1722
|
-
import { tool as
|
|
2007
|
+
import { tool as tool28 } from "@openai/agents";
|
|
1723
2008
|
import { execFile as execFile9 } from "child_process";
|
|
1724
2009
|
import { promisify as promisify11 } from "util";
|
|
1725
|
-
import { z as
|
|
2010
|
+
import { z as z28 } from "zod";
|
|
1726
2011
|
var execFileAsync9 = promisify11(execFile9);
|
|
1727
|
-
var GitWorkspaceParameters =
|
|
1728
|
-
path:
|
|
1729
|
-
branchName:
|
|
1730
|
-
createBranch:
|
|
2012
|
+
var GitWorkspaceParameters = z28.object({
|
|
2013
|
+
path: z28.string().describe("The path where the new workspace (worktree) should be created."),
|
|
2014
|
+
branchName: z28.string().describe("The name of the branch to use in the new workspace."),
|
|
2015
|
+
createBranch: z28.boolean().optional().default(false).describe("Whether to create a new branch for this workspace.")
|
|
1731
2016
|
});
|
|
1732
|
-
var gitWorkspaceTool =
|
|
2017
|
+
var gitWorkspaceTool = tool28({
|
|
1733
2018
|
name: "gitWorkspaceTool",
|
|
1734
2019
|
description: "Create a new workspace (git worktree) for parallel work.",
|
|
1735
2020
|
parameters: GitWorkspaceParameters,
|
|
@@ -1746,13 +2031,13 @@ var gitWorkspaceTool = tool19({
|
|
|
1746
2031
|
});
|
|
1747
2032
|
|
|
1748
2033
|
// tools/harper/checkHarperStatusTool.ts
|
|
1749
|
-
import { tool as
|
|
1750
|
-
import { z as
|
|
1751
|
-
var
|
|
1752
|
-
var checkHarperStatusTool =
|
|
2034
|
+
import { tool as tool29 } from "@openai/agents";
|
|
2035
|
+
import { z as z29 } from "zod";
|
|
2036
|
+
var ToolParameters16 = z29.object({});
|
|
2037
|
+
var checkHarperStatusTool = tool29({
|
|
1753
2038
|
name: "checkHarperStatusTool",
|
|
1754
2039
|
description: "Checks if a Harper application is currently running.",
|
|
1755
|
-
parameters:
|
|
2040
|
+
parameters: ToolParameters16,
|
|
1756
2041
|
async execute() {
|
|
1757
2042
|
if (harperProcess.running) {
|
|
1758
2043
|
return "A Harper application is currently running.";
|
|
@@ -1763,10 +2048,10 @@ var checkHarperStatusTool = tool20({
|
|
|
1763
2048
|
});
|
|
1764
2049
|
|
|
1765
2050
|
// tools/harper/createNewHarperApplicationTool.ts
|
|
1766
|
-
import { tool as
|
|
2051
|
+
import { tool as tool30 } from "@openai/agents";
|
|
1767
2052
|
import { execSync as execSync3 } from "child_process";
|
|
1768
2053
|
import path7 from "path";
|
|
1769
|
-
import { z as
|
|
2054
|
+
import { z as z30 } from "zod";
|
|
1770
2055
|
|
|
1771
2056
|
// utils/package/buildHarperCreateCommand.ts
|
|
1772
2057
|
function buildCreateCommand(pm, appName, template) {
|
|
@@ -1816,11 +2101,11 @@ var PM_DISPLAY = {
|
|
|
1816
2101
|
};
|
|
1817
2102
|
|
|
1818
2103
|
// tools/harper/createNewHarperApplicationTool.ts
|
|
1819
|
-
var
|
|
1820
|
-
directoryName:
|
|
1821
|
-
template:
|
|
2104
|
+
var ToolParameters17 = z30.object({
|
|
2105
|
+
directoryName: z30.string().describe("The name of the directory to create the application in."),
|
|
2106
|
+
template: z30.enum(["vanilla-ts", "vanilla", "react-ts", "react"]).optional().describe("The template to use for the new application. Defaults to vanilla-ts.").default("vanilla-ts")
|
|
1822
2107
|
});
|
|
1823
|
-
async function
|
|
2108
|
+
async function execute14({ directoryName, template }) {
|
|
1824
2109
|
const currentCwd = trackedState.cwd;
|
|
1825
2110
|
const resolvedPath = resolvePath(currentCwd, directoryName);
|
|
1826
2111
|
const isCurrentDir = resolvedPath === currentCwd;
|
|
@@ -1837,7 +2122,7 @@ async function execute4({ directoryName, template }) {
|
|
|
1837
2122
|
});
|
|
1838
2123
|
console.log(`Initializing new Git repository in ${resolvedPath}...`);
|
|
1839
2124
|
execSync3("git init", { cwd: resolvedPath, stdio: "ignore" });
|
|
1840
|
-
const switchedDir = await
|
|
2125
|
+
const switchedDir = await execute11({ path: resolvedPath });
|
|
1841
2126
|
return `Successfully created a new Harper application in '${resolvedPath}' using template '${template}' with a matching Git repository initialized. Use the readDir and readFile tools to inspect the contents of the application. ${switchedDir}.`;
|
|
1842
2127
|
} catch (error) {
|
|
1843
2128
|
let errorMsg = `Error creating new Harper application: ${error.message}`;
|
|
@@ -1850,28 +2135,28 @@ ${error.stdout}`;
|
|
|
1850
2135
|
return errorMsg;
|
|
1851
2136
|
}
|
|
1852
2137
|
}
|
|
1853
|
-
var createNewHarperApplicationTool =
|
|
2138
|
+
var createNewHarperApplicationTool = tool30({
|
|
1854
2139
|
name: "createNewHarperApplicationTool",
|
|
1855
2140
|
description: "Creates a new Harper application using the best available package manager (yarn/pnpm/bun/deno, falling back to npm).",
|
|
1856
|
-
parameters:
|
|
1857
|
-
execute:
|
|
2141
|
+
parameters: ToolParameters17,
|
|
2142
|
+
execute: execute14
|
|
1858
2143
|
});
|
|
1859
2144
|
|
|
1860
2145
|
// tools/harper/getHarperConfigSchemaTool.ts
|
|
1861
|
-
import { tool as
|
|
2146
|
+
import { tool as tool31 } from "@openai/agents";
|
|
1862
2147
|
import { readFile as readFile3 } from "fs/promises";
|
|
1863
2148
|
import { createRequire as createRequire2 } from "module";
|
|
1864
2149
|
import { dirname as dirname2, join as join8 } from "path";
|
|
1865
|
-
import { z as
|
|
1866
|
-
var
|
|
1867
|
-
schemaType:
|
|
2150
|
+
import { z as z31 } from "zod";
|
|
2151
|
+
var ToolParameters18 = z31.object({
|
|
2152
|
+
schemaType: z31.enum(["app", "root"]).describe(
|
|
1868
2153
|
'The type of configuration schema to retrieve: "app" for application configuration or "root" for root Harper configuration.'
|
|
1869
2154
|
)
|
|
1870
2155
|
});
|
|
1871
|
-
var getHarperConfigSchemaTool =
|
|
2156
|
+
var getHarperConfigSchemaTool = tool31({
|
|
1872
2157
|
name: "getHarperConfigSchemaTool",
|
|
1873
2158
|
description: "Returns the JSON schema for HarperDB configuration files (either app or root), which describes the config.yaml or harperdb-config.yaml files.",
|
|
1874
|
-
parameters:
|
|
2159
|
+
parameters: ToolParameters18,
|
|
1875
2160
|
async execute({ schemaType }) {
|
|
1876
2161
|
try {
|
|
1877
2162
|
return await readFile3(
|
|
@@ -1888,13 +2173,13 @@ var getHarperConfigSchemaTool = tool22({
|
|
|
1888
2173
|
});
|
|
1889
2174
|
|
|
1890
2175
|
// tools/harper/getHarperResourceInterfaceTool.ts
|
|
1891
|
-
import { tool as
|
|
2176
|
+
import { tool as tool32 } from "@openai/agents";
|
|
1892
2177
|
import { readFile as readFile4 } from "fs/promises";
|
|
1893
2178
|
import { createRequire as createRequire3 } from "module";
|
|
1894
2179
|
import { dirname as dirname3, join as join9 } from "path";
|
|
1895
|
-
import { z as
|
|
1896
|
-
var
|
|
1897
|
-
resourceFile:
|
|
2180
|
+
import { z as z32 } from "zod";
|
|
2181
|
+
var ToolParameters19 = z32.object({
|
|
2182
|
+
resourceFile: z32.enum([
|
|
1898
2183
|
"ResourceInterfaceV2",
|
|
1899
2184
|
"ResourceInterface",
|
|
1900
2185
|
"Table",
|
|
@@ -1904,10 +2189,10 @@ var ToolParameters10 = z23.object({
|
|
|
1904
2189
|
"The resource-related definition file to read. Defaults to ResourceInterfaceV2."
|
|
1905
2190
|
).default("ResourceInterfaceV2")
|
|
1906
2191
|
});
|
|
1907
|
-
var getHarperResourceInterfaceTool =
|
|
2192
|
+
var getHarperResourceInterfaceTool = tool32({
|
|
1908
2193
|
name: "getHarperResourceInterfaceTool",
|
|
1909
2194
|
description: "Reads HarperDB resource interface and class definitions (like ResourceInterfaceV2.d.ts) to understand how resources and tables are structured.",
|
|
1910
|
-
parameters:
|
|
2195
|
+
parameters: ToolParameters19,
|
|
1911
2196
|
async execute({ resourceFile }) {
|
|
1912
2197
|
try {
|
|
1913
2198
|
return await readFile4(
|
|
@@ -1925,16 +2210,16 @@ var getHarperResourceInterfaceTool = tool23({
|
|
|
1925
2210
|
});
|
|
1926
2211
|
|
|
1927
2212
|
// tools/harper/getHarperSchemaGraphQLTool.ts
|
|
1928
|
-
import { tool as
|
|
2213
|
+
import { tool as tool33 } from "@openai/agents";
|
|
1929
2214
|
import { readFile as readFile5 } from "fs/promises";
|
|
1930
2215
|
import { createRequire as createRequire4 } from "module";
|
|
1931
2216
|
import { dirname as dirname4, join as join10 } from "path";
|
|
1932
|
-
import { z as
|
|
1933
|
-
var
|
|
1934
|
-
var getHarperSchemaGraphQLTool =
|
|
2217
|
+
import { z as z33 } from "zod";
|
|
2218
|
+
var ToolParameters20 = z33.object({});
|
|
2219
|
+
var getHarperSchemaGraphQLTool = tool33({
|
|
1935
2220
|
name: "getHarperSchemaGraphQLTool",
|
|
1936
2221
|
description: "Returns the GraphQL schema for HarperDB schema files, which define the structure of HarperDB database tables.",
|
|
1937
|
-
parameters:
|
|
2222
|
+
parameters: ToolParameters20,
|
|
1938
2223
|
async execute() {
|
|
1939
2224
|
try {
|
|
1940
2225
|
return await readFile5(
|
|
@@ -1951,22 +2236,22 @@ var getHarperSchemaGraphQLTool = tool24({
|
|
|
1951
2236
|
});
|
|
1952
2237
|
|
|
1953
2238
|
// tools/harper/hitHarperAPITool.ts
|
|
1954
|
-
import { tool as
|
|
1955
|
-
import { z as
|
|
1956
|
-
var
|
|
1957
|
-
method:
|
|
2239
|
+
import { tool as tool34 } from "@openai/agents";
|
|
2240
|
+
import { z as z34 } from "zod";
|
|
2241
|
+
var ToolParameters21 = z34.object({
|
|
2242
|
+
method: z34.enum(["POST", "GET", "PUT", "DELETE"]).optional().default("GET").describe(
|
|
1958
2243
|
'The HTTP method to use, defaults to "get". Notably, POST and PUT require the full body be sent.'
|
|
1959
2244
|
),
|
|
1960
|
-
path:
|
|
1961
|
-
port:
|
|
2245
|
+
path: z34.string().optional().default("/openapi").describe("The path to fetch from localhost (defaults to /openapi)."),
|
|
2246
|
+
port: z34.number().optional().default(harperProcess.httpPort).describe(
|
|
1962
2247
|
"The port to fetch from localhost (defaults to the running Harper port)."
|
|
1963
2248
|
),
|
|
1964
|
-
body:
|
|
2249
|
+
body: z34.string().optional().default("").describe("An optional JSON string body to send along with the request.")
|
|
1965
2250
|
});
|
|
1966
|
-
var hitHarperAPITool =
|
|
2251
|
+
var hitHarperAPITool = tool34({
|
|
1967
2252
|
name: "hitHarperAPITool",
|
|
1968
2253
|
description: "Performs a request against the running Harper API. Use /openapi to look up Harper APIs.",
|
|
1969
|
-
parameters:
|
|
2254
|
+
parameters: ToolParameters21,
|
|
1970
2255
|
needsApproval: async (runContext, input, callId) => {
|
|
1971
2256
|
if (callId && runContext.isToolApproved({ toolName: "hitHarperAPITool", callId })) {
|
|
1972
2257
|
return false;
|
|
@@ -2003,57 +2288,21 @@ var hitHarperAPITool = tool25({
|
|
|
2003
2288
|
}
|
|
2004
2289
|
});
|
|
2005
2290
|
|
|
2006
|
-
// tools/harper/openHarperInBrowserTool.ts
|
|
2007
|
-
import { tool as tool26 } from "@openai/agents";
|
|
2008
|
-
import spawn2 from "cross-spawn";
|
|
2009
|
-
import { platform } from "os";
|
|
2010
|
-
import { z as z26 } from "zod";
|
|
2011
|
-
var alreadyOpened = false;
|
|
2012
|
-
var ToolParameters13 = z26.object({});
|
|
2013
|
-
var openHarperInBrowserTool = tool26({
|
|
2014
|
-
name: "openHarperInBrowserTool",
|
|
2015
|
-
description: "Opens the running Harper app in the user's browser.",
|
|
2016
|
-
parameters: ToolParameters13,
|
|
2017
|
-
async execute() {
|
|
2018
|
-
try {
|
|
2019
|
-
if (alreadyOpened) {
|
|
2020
|
-
return `Browser is already open.`;
|
|
2021
|
-
}
|
|
2022
|
-
if (!harperProcess.running) {
|
|
2023
|
-
return `Error: No Harper application is currently running.`;
|
|
2024
|
-
}
|
|
2025
|
-
const url = `http://localhost:${harperProcess.httpPort}/`;
|
|
2026
|
-
const p = platform();
|
|
2027
|
-
if (p === "darwin") {
|
|
2028
|
-
spawn2("open", [url]);
|
|
2029
|
-
} else if (p === "win32") {
|
|
2030
|
-
spawn2("start", ["", url]);
|
|
2031
|
-
} else {
|
|
2032
|
-
spawn2("xdg-open", [url]);
|
|
2033
|
-
}
|
|
2034
|
-
alreadyOpened = true;
|
|
2035
|
-
return `Successfully opened '${url}' in the browser.`;
|
|
2036
|
-
} catch (error) {
|
|
2037
|
-
return `Error opening browser: ${error}`;
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
});
|
|
2041
|
-
|
|
2042
2291
|
// tools/harper/readHarperLogsTool.ts
|
|
2043
|
-
import { tool as
|
|
2044
|
-
import { z as
|
|
2045
|
-
var
|
|
2046
|
-
var readHarperLogsTool =
|
|
2292
|
+
import { tool as tool35 } from "@openai/agents";
|
|
2293
|
+
import { z as z35 } from "zod";
|
|
2294
|
+
var ToolParameters22 = z35.object({});
|
|
2295
|
+
var readHarperLogsTool = tool35({
|
|
2047
2296
|
name: "readHarperLogsTool",
|
|
2048
2297
|
description: "Reads the most recent console logs of a started Harper app and clears them so that subsequent reads will only show new logs.",
|
|
2049
|
-
parameters:
|
|
2298
|
+
parameters: ToolParameters22,
|
|
2050
2299
|
async execute() {
|
|
2051
2300
|
if (!harperProcess.running) {
|
|
2052
2301
|
return `Error: No Harper application is currently running.`;
|
|
2053
2302
|
}
|
|
2054
2303
|
try {
|
|
2055
|
-
const
|
|
2056
|
-
return
|
|
2304
|
+
const logs2 = harperProcess.getAndClearLogs();
|
|
2305
|
+
return logs2 || "No logs available yet.";
|
|
2057
2306
|
} catch (error) {
|
|
2058
2307
|
return `Error reading Harper application logs: ${error}`;
|
|
2059
2308
|
}
|
|
@@ -2061,10 +2310,10 @@ var readHarperLogsTool = tool27({
|
|
|
2061
2310
|
});
|
|
2062
2311
|
|
|
2063
2312
|
// tools/harper/startHarperTool.ts
|
|
2064
|
-
import { tool as
|
|
2313
|
+
import { tool as tool36 } from "@openai/agents";
|
|
2065
2314
|
import { existsSync as existsSync7 } from "fs";
|
|
2066
2315
|
import { basename, resolve } from "path";
|
|
2067
|
-
import { z as
|
|
2316
|
+
import { z as z36 } from "zod";
|
|
2068
2317
|
|
|
2069
2318
|
// utils/promises/sleep.ts
|
|
2070
2319
|
function sleep(ms) {
|
|
@@ -2072,13 +2321,13 @@ function sleep(ms) {
|
|
|
2072
2321
|
}
|
|
2073
2322
|
|
|
2074
2323
|
// tools/harper/startHarperTool.ts
|
|
2075
|
-
var
|
|
2076
|
-
directoryName:
|
|
2324
|
+
var ToolParameters23 = z36.object({
|
|
2325
|
+
directoryName: z36.string().describe("The name of the directory that the Harper app is in.")
|
|
2077
2326
|
});
|
|
2078
|
-
var startHarperTool =
|
|
2327
|
+
var startHarperTool = tool36({
|
|
2079
2328
|
name: "startHarperTool",
|
|
2080
|
-
description: "Starts a Harper app background process, allowing you to observe the app in action (by readHarperLogsTool, hitHarperAPITool,
|
|
2081
|
-
parameters:
|
|
2329
|
+
description: "Starts a Harper app background process, allowing you to observe the app in action (by readHarperLogsTool, hitHarperAPITool, etc).",
|
|
2330
|
+
parameters: ToolParameters23,
|
|
2082
2331
|
async execute({ directoryName }) {
|
|
2083
2332
|
if (isIgnored(directoryName)) {
|
|
2084
2333
|
return `Error: Target directory ${directoryName} is restricted by .aiignore`;
|
|
@@ -2097,9 +2346,9 @@ var startHarperTool = tool28({
|
|
|
2097
2346
|
}
|
|
2098
2347
|
harperProcess.start(effectiveDirectory);
|
|
2099
2348
|
await sleep(5e3);
|
|
2100
|
-
const
|
|
2349
|
+
const logs2 = harperProcess.getAndClearLogs();
|
|
2101
2350
|
return `Successfully started Harper application with auto-reload in '${effectiveDirectory}' with initial logs:
|
|
2102
|
-
${
|
|
2351
|
+
${logs2}`;
|
|
2103
2352
|
} catch (error) {
|
|
2104
2353
|
return `Error: failed to start Harper application: ${error}`;
|
|
2105
2354
|
}
|
|
@@ -2107,13 +2356,13 @@ ${logs}`;
|
|
|
2107
2356
|
});
|
|
2108
2357
|
|
|
2109
2358
|
// tools/harper/stopHarperTool.ts
|
|
2110
|
-
import { tool as
|
|
2111
|
-
import { z as
|
|
2112
|
-
var
|
|
2113
|
-
var stopHarperTool =
|
|
2359
|
+
import { tool as tool37 } from "@openai/agents";
|
|
2360
|
+
import { z as z37 } from "zod";
|
|
2361
|
+
var ToolParameters24 = z37.object({});
|
|
2362
|
+
var stopHarperTool = tool37({
|
|
2114
2363
|
name: "stopHarperTool",
|
|
2115
2364
|
description: "Stops all previously started Harper app background process.",
|
|
2116
|
-
parameters:
|
|
2365
|
+
parameters: ToolParameters24,
|
|
2117
2366
|
async execute() {
|
|
2118
2367
|
if (!harperProcess.running) {
|
|
2119
2368
|
return `Error: No Harper application is currently running.`;
|
|
@@ -2130,6 +2379,15 @@ var stopHarperTool = tool29({
|
|
|
2130
2379
|
// tools/factory.ts
|
|
2131
2380
|
function createTools() {
|
|
2132
2381
|
return [
|
|
2382
|
+
browserClickTool,
|
|
2383
|
+
browserCloseTool,
|
|
2384
|
+
browserEvaluateTool,
|
|
2385
|
+
browserGetContentTool,
|
|
2386
|
+
browserGetLogsTool,
|
|
2387
|
+
browserIsElementPresentTool,
|
|
2388
|
+
browserNavigateTool,
|
|
2389
|
+
browserScreenshotTool,
|
|
2390
|
+
browserTypeTool,
|
|
2133
2391
|
changeCwdTool,
|
|
2134
2392
|
checkHarperStatusTool,
|
|
2135
2393
|
codeInterpreterTool,
|
|
@@ -2149,7 +2407,6 @@ function createTools() {
|
|
|
2149
2407
|
gitStatusTool,
|
|
2150
2408
|
gitWorkspaceTool,
|
|
2151
2409
|
hitHarperAPITool,
|
|
2152
|
-
openHarperInBrowserTool,
|
|
2153
2410
|
readDirTool,
|
|
2154
2411
|
readFileTool,
|
|
2155
2412
|
readHarperLogsTool,
|
|
@@ -2164,7 +2421,7 @@ function createTools() {
|
|
|
2164
2421
|
|
|
2165
2422
|
// utils/package/checkForUpdate.ts
|
|
2166
2423
|
import chalk10 from "chalk";
|
|
2167
|
-
import
|
|
2424
|
+
import spawn2 from "cross-spawn";
|
|
2168
2425
|
|
|
2169
2426
|
// utils/package/getLatestVersion.ts
|
|
2170
2427
|
async function getLatestVersion(packageName) {
|
|
@@ -2224,7 +2481,7 @@ A new version of ${chalk10.bold(packageName)} is available! (${chalk10.dim(packa
|
|
|
2224
2481
|
`);
|
|
2225
2482
|
let isGlobal = false;
|
|
2226
2483
|
try {
|
|
2227
|
-
const globalRootResult =
|
|
2484
|
+
const globalRootResult = spawn2.sync("npm", ["root", "-g"], {
|
|
2228
2485
|
encoding: "utf8"
|
|
2229
2486
|
});
|
|
2230
2487
|
const globalRoot = globalRootResult.stdout?.trim();
|
|
@@ -2234,15 +2491,15 @@ A new version of ${chalk10.bold(packageName)} is available! (${chalk10.dim(packa
|
|
|
2234
2491
|
} catch {
|
|
2235
2492
|
}
|
|
2236
2493
|
if (isGlobal) {
|
|
2237
|
-
|
|
2494
|
+
spawn2.sync("npm", ["install", "-g", `${packageName}@latest`], {
|
|
2238
2495
|
stdio: "inherit"
|
|
2239
2496
|
});
|
|
2240
|
-
const result2 =
|
|
2497
|
+
const result2 = spawn2.sync("harper-agent", process.argv.slice(2), {
|
|
2241
2498
|
stdio: "inherit"
|
|
2242
2499
|
});
|
|
2243
2500
|
process.exit(result2.status ?? 0);
|
|
2244
2501
|
}
|
|
2245
|
-
const lsResult =
|
|
2502
|
+
const lsResult = spawn2.sync("npm", ["cache", "npx", "ls", packageName], {
|
|
2246
2503
|
encoding: "utf8"
|
|
2247
2504
|
});
|
|
2248
2505
|
if (lsResult.stdout) {
|
|
@@ -2251,12 +2508,12 @@ A new version of ${chalk10.bold(packageName)} is available! (${chalk10.dim(packa
|
|
|
2251
2508
|
return pkgPart && pkgPart.trim().startsWith(`${packageName}@`);
|
|
2252
2509
|
}).map((line) => line.split(":")[0].trim());
|
|
2253
2510
|
if (keys.length > 0) {
|
|
2254
|
-
|
|
2511
|
+
spawn2.sync("npm", ["cache", "npx", "rm", ...keys], {
|
|
2255
2512
|
stdio: "inherit"
|
|
2256
2513
|
});
|
|
2257
2514
|
}
|
|
2258
2515
|
}
|
|
2259
|
-
const result =
|
|
2516
|
+
const result = spawn2.sync("npx", ["-y", `${packageName}@latest`, ...process.argv.slice(2)], {
|
|
2260
2517
|
stdio: "inherit"
|
|
2261
2518
|
});
|
|
2262
2519
|
process.exit(result.status ?? 0);
|