@ancha-labs/cli 0.4.27 → 0.4.28
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/lib/ancha.mjs +972 -958
- package/lib/worker.mjs +10 -9
- package/package.json +1 -1
package/lib/ancha.mjs
CHANGED
|
@@ -222706,1053 +222706,1067 @@ var init_run = __esm({
|
|
|
222706
222706
|
}
|
|
222707
222707
|
});
|
|
222708
222708
|
|
|
222709
|
-
// backend/src/kit/
|
|
222710
|
-
|
|
222711
|
-
|
|
222712
|
-
|
|
222713
|
-
if (
|
|
222714
|
-
const
|
|
222715
|
-
|
|
222716
|
-
const
|
|
222717
|
-
|
|
222718
|
-
|
|
222719
|
-
const env2 = {};
|
|
222720
|
-
const variables2 = [...code5.matchAll(/(?:process\.env\.([A-Za-z_]\w*)|(?:os\.)?(?:environ(?:\.get)?|getenv)\s*[\[(]\s*["']([A-Za-z_]\w*)["'])/g)].map((match3) => match3[1] ?? match3[2]);
|
|
222721
|
-
for (const name5 of variables2) {
|
|
222722
|
-
const value5 = /SIGNING.*SECRET/i.test(name5) ? "slack.signing_secret" : /APP.*TOKEN|TOKEN.*APP/i.test(name5) ? "slack.app_token" : /(?:SLACK|BOT).*TOKEN/i.test(name5) ? "slack.token" : /SLACK.*(?:URL|BASE)/i.test(name5) ? "slack.url" : void 0;
|
|
222723
|
-
if (value5) env2[name5] = `{{${value5}}}`;
|
|
222724
|
-
}
|
|
222725
|
-
if (socket) return { file: file3, transport: "socket", env: env2 };
|
|
222726
|
-
const portVar = variables2.find((name5) => /(?:^|_)PORT$/.test(name5));
|
|
222727
|
-
const literal4 = /^(?:\s*port\s*=)?\s*(\d+)\b/.exec(start2 ?? "")?.[1] ?? portOption;
|
|
222728
|
-
const dynamic = portVar !== void 0 && literal4 === void 0;
|
|
222729
|
-
if (dynamic) env2[portVar] = "{{agent.port}}";
|
|
222730
|
-
const path7 = /\b(?:endpoints|path)\s*:\s*["'](\/[^"']*)["']/.exec(code5)?.[1] ?? "/slack/events";
|
|
222731
|
-
return { file: file3, transport: "http", url: `http://127.0.0.1:${dynamic ? "{{agent.port}}" : literal4 ?? "3000"}${path7}`, env: env2 };
|
|
222709
|
+
// backend/src/kit/task-input.ts
|
|
222710
|
+
import { open as open5, stat as stat6 } from "node:fs/promises";
|
|
222711
|
+
import { basename as basename7, dirname as dirname10, extname, isAbsolute as isAbsolute6, join as join23, relative as relative9, resolve as resolve18, sep as sep4 } from "node:path";
|
|
222712
|
+
function taskVariable(name5) {
|
|
222713
|
+
if (!/^[A-Z][A-Z0-9_]*$/.test(name5) || name5.startsWith("ANCHA_")) return null;
|
|
222714
|
+
const parts3 = name5.split("_").filter(Boolean);
|
|
222715
|
+
if (parts3.some((part) => NOT_TASK.has(part))) return null;
|
|
222716
|
+
const strong = parts3.some((part) => STRONG.has(part)), weak = parts3.some((part) => WEAK.has(part));
|
|
222717
|
+
if (!strong && !weak) return null;
|
|
222718
|
+
return { strength: strong ? 2 : 1, file: parts3.some((part) => FILE_WORDS.has(part)) };
|
|
222732
222719
|
}
|
|
222733
|
-
|
|
222734
|
-
|
|
222735
|
-
|
|
222720
|
+
function taskFlag(flag5) {
|
|
222721
|
+
const match3 = FLAG.exec(flag5.toLowerCase());
|
|
222722
|
+
if (!match3) return null;
|
|
222723
|
+
return { strength: /^(task|prompt|instructions?)$/.test(match3[1]) ? 2 : 1, file: match3[2] !== void 0 };
|
|
222724
|
+
}
|
|
222725
|
+
function rank(found) {
|
|
222726
|
+
const via = (input5) => (input5.file ? 2 : 0) + (input5.via === "flag" ? 1 : 0);
|
|
222727
|
+
const seen = /* @__PURE__ */ new Set();
|
|
222728
|
+
return found.sort((a, b) => b.strength - a.strength || via(a.input) - via(b.input) || a.order - b.order).map((item2) => item2.input).filter((input5) => {
|
|
222729
|
+
const key4 = `${input5.via}:${input5.name}`;
|
|
222730
|
+
if (seen.has(key4)) return false;
|
|
222731
|
+
seen.add(key4);
|
|
222732
|
+
return true;
|
|
222733
|
+
});
|
|
222734
|
+
}
|
|
222735
|
+
function envReads(text30, python) {
|
|
222736
|
+
const reads2 = [];
|
|
222737
|
+
const all9 = (pattern, group5) => {
|
|
222738
|
+
for (const match3 of text30.matchAll(pattern)) reads2.push({ name: match3[group5], index: match3.index });
|
|
222739
|
+
};
|
|
222740
|
+
if (python) {
|
|
222741
|
+
all9(/\bos\.environ\[\s*(['"])([A-Za-z_]\w*)\1\s*\]/g, 2);
|
|
222742
|
+
all9(/\b(?:os\.environ\.get|os\.getenv|(?<![\w.])getenv|(?<![\w.])environ\.get)\(\s*(['"])([A-Za-z_]\w*)\1/g, 2);
|
|
222743
|
+
all9(/(?<![\w.])environ\[\s*(['"])([A-Za-z_]\w*)\1\s*\]/g, 2);
|
|
222744
|
+
for (const alias of text30.matchAll(/^\s*([A-Za-z_]\w*)\s*=\s*os\.environ\s*$/gm)) {
|
|
222745
|
+
all9(new RegExp(`(?<![\\w.])${alias[1]}(?:\\.get\\(|\\[)\\s*(['"])([A-Za-z_]\\w*)\\1`, "g"), 2);
|
|
222746
|
+
}
|
|
222747
|
+
return reads2;
|
|
222736
222748
|
}
|
|
222737
|
-
|
|
222738
|
-
|
|
222739
|
-
|
|
222740
|
-
|
|
222741
|
-
|
|
222742
|
-
|
|
222743
|
-
|
|
222744
|
-
|
|
222745
|
-
|
|
222746
|
-
|
|
222747
|
-
let current = resolve18(root3);
|
|
222748
|
-
for (const part of rel.split(sep4)) {
|
|
222749
|
-
current = resolve18(current, part);
|
|
222750
|
-
if ((await lstat3(current)).isSymbolicLink()) return void 0;
|
|
222749
|
+
all9(/\bprocess\.env\.([A-Za-z_]\w*)/g, 1);
|
|
222750
|
+
all9(/\bprocess\.env\[\s*(['"`])([A-Za-z_]\w*)\1\s*\]/g, 2);
|
|
222751
|
+
all9(/\b(?:Deno\.env\.get)\(\s*(['"`])([A-Za-z_]\w*)\1/g, 2);
|
|
222752
|
+
all9(/\bBun\.env\.([A-Za-z_]\w*)/g, 1);
|
|
222753
|
+
const destructured = (pattern) => {
|
|
222754
|
+
for (const match3 of text30.matchAll(pattern)) {
|
|
222755
|
+
for (const part of match3[1].split(",")) {
|
|
222756
|
+
const name5 = /^\s*([A-Za-z_]\w*)/.exec(part)?.[1];
|
|
222757
|
+
if (name5) reads2.push({ name: name5, index: match3.index });
|
|
222758
|
+
}
|
|
222751
222759
|
}
|
|
222752
|
-
|
|
222753
|
-
|
|
222754
|
-
|
|
222755
|
-
|
|
222756
|
-
|
|
222757
|
-
|
|
222758
|
-
|
|
222759
|
-
|
|
222760
|
-
|
|
222760
|
+
};
|
|
222761
|
+
destructured(/\{([^{}]*)\}\s*=\s*process\.env\b/g);
|
|
222762
|
+
for (const alias of text30.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*process\.env\s*(?:[;\n]|$)/g)) {
|
|
222763
|
+
const name5 = alias[1].replace(/\$/g, "\\$");
|
|
222764
|
+
all9(new RegExp(`(?<![\\w$.])${name5}\\.([A-Za-z_]\\w*)`, "g"), 1);
|
|
222765
|
+
all9(new RegExp(`(?<![\\w$.])${name5}\\[\\s*(['"\`])([A-Za-z_]\\w*)\\1\\s*\\]`, "g"), 2);
|
|
222766
|
+
destructured(new RegExp(`\\{([^{}]*)\\}\\s*=\\s*${name5}\\b`, "g"));
|
|
222767
|
+
}
|
|
222768
|
+
return reads2;
|
|
222769
|
+
}
|
|
222770
|
+
function scanSource(text30, source, python, found, order6, variables2, marks) {
|
|
222771
|
+
const entryHelper = !python && /@ancha-labs\/tools/.test(text30) && /\bentry\s*\(/.test(text30) || python && (/from\s+ancha(?:\.tools)?\s+import\s+[^\n]*\bentry\b/.test(text30) || /\bancha\.entry\s*\(/.test(text30));
|
|
222772
|
+
const native2 = NATIVE_NAMES.exec(text30) ?? (entryHelper ? [, "entry"] : null);
|
|
222773
|
+
const stdin = (python ? PYTHON_STDIN : NODE_STDIN).exec(text30);
|
|
222774
|
+
if (stdin && !marks.stdin) marks.stdin = { source, line: lineAt(text30, stdin.index) };
|
|
222775
|
+
const done = /\bANCHA_DONE_URL\b/.exec(text30) ?? (entryHelper ? /\bentry\s*\(/.exec(text30) : null);
|
|
222776
|
+
if (done && !marks.done) marks.done = { name: done[0].startsWith("ANCHA_") ? "ANCHA_DONE_URL" : "entry", source, line: lineAt(text30, done.index) };
|
|
222777
|
+
const env2 = (name5, index) => {
|
|
222778
|
+
if (!variables2.has(name5)) variables2.set(name5, { source, line: lineAt(text30, index) });
|
|
222779
|
+
if (native2) return;
|
|
222780
|
+
const kind2 = taskVariable(name5);
|
|
222781
|
+
if (kind2) found.push({ input: { via: "env", name: name5, file: kind2.file, source, line: lineAt(text30, index) }, strength: kind2.strength, order: order6.next++ });
|
|
222782
|
+
};
|
|
222783
|
+
const flag5 = (name5, index) => {
|
|
222784
|
+
if (native2) return;
|
|
222785
|
+
const kind2 = taskFlag(name5);
|
|
222786
|
+
if (kind2) found.push({ input: { via: "flag", name: name5.toLowerCase(), file: kind2.file, source, line: lineAt(text30, index) }, strength: kind2.strength, order: order6.next++ });
|
|
222787
|
+
};
|
|
222788
|
+
const all9 = (pattern, group5, each) => {
|
|
222789
|
+
for (const match3 of text30.matchAll(pattern)) each(match3[group5], match3.index);
|
|
222790
|
+
};
|
|
222791
|
+
for (const read7 of envReads(text30, python)) env2(read7.name, read7.index);
|
|
222792
|
+
if (python) {
|
|
222793
|
+
all9(/\b([a-z][a-z0-9_]*)\s*:\s*[\w[\], |.]+?=\s*typer\.Option\(/g, 1, (name5, index) => flag5(`--${name5.replaceAll("_", "-")}`, index));
|
|
222794
|
+
} else {
|
|
222795
|
+
for (const call4 of text30.matchAll(/\bparseArgs\s*\(|\.options\s*\(\s*\{/g)) {
|
|
222796
|
+
const region = text30.slice(call4.index, call4.index + 4e3);
|
|
222797
|
+
for (const match3 of region.matchAll(/(['"]?)([A-Za-z][\w-]*)\1\s*:\s*\{[^{}]*?\btype\s*:\s*['"]string['"]/g)) flag5(`--${match3[2]}`, call4.index + match3.index);
|
|
222761
222798
|
}
|
|
222762
|
-
|
|
222763
|
-
return void 0;
|
|
222799
|
+
all9(/\.option\(\s*(['"])([A-Za-z][\w-]*)\1\s*,\s*\{/g, 2, (name5, index) => flag5(`--${name5}`, index));
|
|
222764
222800
|
}
|
|
222801
|
+
const argv = python ? /\bsys\.argv\b|\bargparse\b|\bclick\b|\btyper\b|\bdocopt\b|\bfire\.Fire\b/ : /\bprocess\.argv\b|\bparseArgs\b|\bcommander\b|\byargs\b|\bminimist\b|\bmri\b|\bmeow\b|\bcac\b|\bsade\b|\bDeno\.args\b|\bBun\.argv\b/;
|
|
222802
|
+
if (argv.test(text30)) all9(FLAG_WORDS, 0, flag5);
|
|
222803
|
+
return native2 ? { name: native2[1] } : null;
|
|
222765
222804
|
}
|
|
222766
|
-
|
|
222767
|
-
const
|
|
222768
|
-
let
|
|
222769
|
-
|
|
222770
|
-
const
|
|
222771
|
-
|
|
222772
|
-
|
|
222773
|
-
|
|
222774
|
-
|
|
222775
|
-
|
|
222776
|
-
|
|
222777
|
-
|
|
222805
|
+
function taskInputsInText(text30) {
|
|
222806
|
+
const found = [];
|
|
222807
|
+
let order6 = 0;
|
|
222808
|
+
for (const line2 of text30.split(/\r?\n/)) {
|
|
222809
|
+
for (const match3 of line2.matchAll(FLAG_WORDS)) {
|
|
222810
|
+
const kind2 = taskFlag(match3[0]);
|
|
222811
|
+
if (kind2) found.push({ input: { via: "flag", name: match3[0].toLowerCase(), file: kind2.file, source: "output" }, strength: kind2.strength, order: order6++ });
|
|
222812
|
+
}
|
|
222813
|
+
const variables2 = /\b(?:env|environment|variable|var)\b/i.test(line2);
|
|
222814
|
+
for (const match3 of line2.matchAll(/(?<![\w$])\$?([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*)\b/g)) {
|
|
222815
|
+
const name5 = match3[1], kind2 = taskVariable(name5);
|
|
222816
|
+
if (kind2 && (name5.includes("_") || variables2 || match3[0].startsWith("$"))) found.push({ input: { via: "env", name: name5, file: kind2.file, source: "output" }, strength: kind2.strength, order: order6++ });
|
|
222778
222817
|
}
|
|
222779
222818
|
}
|
|
222780
|
-
return
|
|
222819
|
+
return rank(found);
|
|
222781
222820
|
}
|
|
222782
|
-
|
|
222783
|
-
|
|
222784
|
-
"
|
|
222785
|
-
|
|
222786
|
-
|
|
222787
|
-
|
|
222788
|
-
|
|
222821
|
+
function words7(command) {
|
|
222822
|
+
const commands = [[]];
|
|
222823
|
+
let word2 = "", quote6 = "", started = false;
|
|
222824
|
+
const end = () => {
|
|
222825
|
+
if (started) commands.at(-1).push(word2);
|
|
222826
|
+
word2 = "";
|
|
222827
|
+
started = false;
|
|
222828
|
+
};
|
|
222829
|
+
for (let i = 0; i < command.length; i++) {
|
|
222830
|
+
const char = command[i];
|
|
222831
|
+
if (quote6) {
|
|
222832
|
+
if (char === quote6) quote6 = "";
|
|
222833
|
+
else if (char === "\\" && quote6 === '"' && i + 1 < command.length) word2 += command[++i];
|
|
222834
|
+
else word2 += char;
|
|
222835
|
+
continue;
|
|
222836
|
+
}
|
|
222837
|
+
if (char === "'" || char === '"') {
|
|
222838
|
+
quote6 = char;
|
|
222839
|
+
started = true;
|
|
222840
|
+
continue;
|
|
222841
|
+
}
|
|
222842
|
+
if (char === "\\" && i + 1 < command.length) {
|
|
222843
|
+
word2 += command[++i];
|
|
222844
|
+
started = true;
|
|
222845
|
+
continue;
|
|
222846
|
+
}
|
|
222847
|
+
if (/[;&|\n]/.test(char)) {
|
|
222848
|
+
end();
|
|
222849
|
+
if (commands.at(-1).length) commands.push([]);
|
|
222850
|
+
continue;
|
|
222851
|
+
}
|
|
222852
|
+
if (/\s/.test(char)) {
|
|
222853
|
+
end();
|
|
222854
|
+
continue;
|
|
222855
|
+
}
|
|
222856
|
+
word2 += char;
|
|
222857
|
+
started = true;
|
|
222789
222858
|
}
|
|
222790
|
-
|
|
222791
|
-
|
|
222792
|
-
|
|
222793
|
-
function
|
|
222794
|
-
|
|
222795
|
-
if (!last) return void 0;
|
|
222796
|
-
if (!last.startsWith("[")) return last;
|
|
222859
|
+
end();
|
|
222860
|
+
return commands.filter((list18) => list18.length > 0);
|
|
222861
|
+
}
|
|
222862
|
+
async function readSmall(path7) {
|
|
222863
|
+
let handle30;
|
|
222797
222864
|
try {
|
|
222798
|
-
|
|
222799
|
-
return Array.isArray(parts3) && parts3.length > 0 && parts3.every((part) => typeof part === "string") ? parts3.map((part) => /^[\w./:=@+-]+$/.test(part) ? part : `'${part.replaceAll("'", "'\\''")}'`).join(" ") : void 0;
|
|
222865
|
+
handle30 = await open5(path7, "r");
|
|
222800
222866
|
} catch {
|
|
222801
222867
|
return void 0;
|
|
222802
222868
|
}
|
|
222869
|
+
try {
|
|
222870
|
+
const info = await handle30.stat();
|
|
222871
|
+
if (!info.isFile() || info.size > MAX_FILE_BYTES) return void 0;
|
|
222872
|
+
return await handle30.readFile("utf8");
|
|
222873
|
+
} finally {
|
|
222874
|
+
await handle30.close();
|
|
222875
|
+
}
|
|
222803
222876
|
}
|
|
222804
|
-
|
|
222805
|
-
|
|
222806
|
-
|
|
222807
|
-
|
|
222808
|
-
|
|
222809
|
-
|
|
222810
|
-
|
|
222811
|
-
|
|
222812
|
-
|
|
222813
|
-
|
|
222814
|
-
return
|
|
222877
|
+
function project12(root3) {
|
|
222878
|
+
return {
|
|
222879
|
+
root: root3,
|
|
222880
|
+
read: (path7) => readSmall(resolve18(root3, path7)),
|
|
222881
|
+
exists: async (path7) => (await stat6(resolve18(root3, path7)).catch(() => void 0))?.isFile() ?? false
|
|
222882
|
+
};
|
|
222883
|
+
}
|
|
222884
|
+
async function packageScript(p2, cwd, name5) {
|
|
222885
|
+
try {
|
|
222886
|
+
const value5 = JSON.parse(await p2.read(join23(cwd, "package.json")) ?? "{}").scripts?.[name5];
|
|
222887
|
+
return typeof value5 === "string" ? value5 : void 0;
|
|
222888
|
+
} catch {
|
|
222889
|
+
return void 0;
|
|
222815
222890
|
}
|
|
222816
|
-
file3 = file3.replace(/^(['"])(.*)\1$/, "$2");
|
|
222817
|
-
if (!SOURCE_FILE.test(file3) || /(?:^|\/)(?:test[^/]*|setup\.py|conftest\.py|scripts\/)/.test(file3)) return false;
|
|
222818
|
-
return await read7(file3) !== void 0;
|
|
222819
222891
|
}
|
|
222820
|
-
async function
|
|
222821
|
-
|
|
222822
|
-
|
|
222823
|
-
|
|
222824
|
-
|
|
222825
|
-
|
|
222826
|
-
|
|
222827
|
-
|
|
222828
|
-
const manager = typeof manifest2.packageManager === "string" ? /^(pnpm|yarn|bun)@/.exec(manifest2.packageManager)?.[1] ?? "npm" : "npm";
|
|
222829
|
-
return result(`${manager} ${manager === "npm" && script !== "start" || manager === "bun" ? "run " : ""}${script}`, "package.json", `package.json scripts.${script}`);
|
|
222830
|
-
}
|
|
222831
|
-
} catch {
|
|
222832
|
-
}
|
|
222892
|
+
async function packageBin(p2, cwd, name5) {
|
|
222893
|
+
try {
|
|
222894
|
+
const manifest2 = JSON.parse(await p2.read(join23(cwd, "package.json")) ?? "{}");
|
|
222895
|
+
if (typeof manifest2.bin === "string") return manifest2.name === name5 || String(manifest2.name).split("/").at(-1) === name5 ? join23(cwd, manifest2.bin) : void 0;
|
|
222896
|
+
const value5 = manifest2.bin?.[name5];
|
|
222897
|
+
return typeof value5 === "string" ? join23(cwd, value5) : void 0;
|
|
222898
|
+
} catch {
|
|
222899
|
+
return void 0;
|
|
222833
222900
|
}
|
|
222834
|
-
|
|
222835
|
-
|
|
222836
|
-
const
|
|
222837
|
-
const
|
|
222838
|
-
const
|
|
222839
|
-
|
|
222840
|
-
|
|
222841
|
-
|
|
222842
|
-
|
|
222843
|
-
|
|
222844
|
-
|
|
222845
|
-
|
|
222846
|
-
|
|
222847
|
-
|
|
222848
|
-
|
|
222849
|
-
|
|
222850
|
-
|
|
222851
|
-
|
|
222852
|
-
|
|
222853
|
-
|
|
222901
|
+
}
|
|
222902
|
+
async function pyprojectScript(p2, cwd, name5) {
|
|
222903
|
+
const body7 = await p2.read(join23(cwd, "pyproject.toml"));
|
|
222904
|
+
const section2 = body7 === void 0 ? void 0 : /^\[(?:project\.scripts|tool\.poetry\.scripts)\]\s*\n((?:[^[\n].*\n?)*)/m.exec(body7)?.[1];
|
|
222905
|
+
const target6 = section2?.split("\n").map((line2) => /^\s*["']?([\w.-]+)["']?\s*=\s*["']([\w.]+)(?::\w+)?["']/.exec(line2)).find((match3) => match3?.[1] === name5)?.[2];
|
|
222906
|
+
return target6 === void 0 ? [] : pythonModule(cwd, target6);
|
|
222907
|
+
}
|
|
222908
|
+
async function entries3(p2, command, cwd = ".", depth = 0) {
|
|
222909
|
+
if (depth > 3) return [];
|
|
222910
|
+
const out = [];
|
|
222911
|
+
let dir2 = cwd;
|
|
222912
|
+
for (let list18 of words7(command)) {
|
|
222913
|
+
while (list18.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(list18[0])) list18 = list18.slice(1);
|
|
222914
|
+
if (!list18.length) continue;
|
|
222915
|
+
const program2 = basename7(list18[0]), rest2 = list18.slice(1);
|
|
222916
|
+
if (program2 === "cd" && rest2[0] !== void 0) {
|
|
222917
|
+
dir2 = join23(dir2, rest2[0]);
|
|
222918
|
+
continue;
|
|
222919
|
+
}
|
|
222920
|
+
if (["uv", "poetry", "pipenv", "pdm", "rye", "hatch"].includes(program2) && rest2[0] === "run") {
|
|
222921
|
+
out.push(...await entries3(p2, quoteAll(rest2.slice(1)), dir2, depth + 1));
|
|
222922
|
+
continue;
|
|
222923
|
+
}
|
|
222924
|
+
if (["npx", "pnpx", "exec", "env", "time", "nohup", "dotenv"].includes(program2)) {
|
|
222925
|
+
const at4 = rest2.findIndex((word2) => !word2.startsWith("-") && !/^[A-Za-z_]\w*=/.test(word2));
|
|
222926
|
+
if (at4 >= 0) out.push(...await entries3(p2, quoteAll(rest2.slice(at4)), dir2, depth + 1));
|
|
222927
|
+
continue;
|
|
222928
|
+
}
|
|
222929
|
+
if (["npm", "pnpm", "yarn", "bun"].includes(program2)) {
|
|
222930
|
+
const script = rest2[0] === "run" || rest2[0] === "run-script" ? rest2[1] : rest2[0];
|
|
222931
|
+
if (program2 === "bun" && script !== void 0 && /[/.]/.test(script)) {
|
|
222932
|
+
out.push(...await scriptEntry(p2, dir2, rest2[0] === "run" ? rest2.slice(1) : rest2, false));
|
|
222933
|
+
continue;
|
|
222854
222934
|
}
|
|
222935
|
+
const body7 = script === void 0 ? void 0 : await packageScript(p2, dir2, script);
|
|
222936
|
+
if (body7 !== void 0) out.push(...await entries3(p2, body7, dir2, depth + 1));
|
|
222937
|
+
continue;
|
|
222855
222938
|
}
|
|
222856
|
-
|
|
222857
|
-
|
|
222858
|
-
|
|
222859
|
-
|
|
222860
|
-
|
|
222861
|
-
|
|
222862
|
-
|
|
222863
|
-
|
|
222864
|
-
|
|
222865
|
-
|
|
222866
|
-
|
|
222867
|
-
|
|
222868
|
-
|
|
222869
|
-
|
|
222870
|
-
|
|
222871
|
-
if (await read7(target6) !== void 0 || await read7(`src/${target6}`) !== void 0) return { agent: null, agentSource: "unconfigured" };
|
|
222872
|
-
}
|
|
222939
|
+
if (/^python(?:\d+(?:\.\d+)*)?$/.test(program2) || program2 === "py") {
|
|
222940
|
+
out.push(...await scriptEntry(p2, dir2, rest2, true));
|
|
222941
|
+
continue;
|
|
222942
|
+
}
|
|
222943
|
+
if (["node", "nodejs", "tsx", "ts-node", "ts-node-esm", "bun", "deno", "esno", "jiti"].includes(program2)) {
|
|
222944
|
+
out.push(...await scriptEntry(p2, dir2, (program2 === "deno" || program2 === "bun") && rest2[0] === "run" ? rest2.slice(1) : rest2, false));
|
|
222945
|
+
continue;
|
|
222946
|
+
}
|
|
222947
|
+
const path7 = join23(dir2, list18[0]);
|
|
222948
|
+
if (/[/.]/.test(list18[0]) && await p2.exists(path7)) {
|
|
222949
|
+
const text30 = await p2.read(path7) ?? "";
|
|
222950
|
+
const shebang = /^#!(.*)/.exec(text30)?.[1] ?? "";
|
|
222951
|
+
if (/\b(node|tsx|bun|deno|python[\d.]*)\b/.test(shebang) || SOURCE_EXT.includes(extname(path7)) || extname(path7) === ".py") out.push(path7);
|
|
222952
|
+
else if (/\b(sh|bash|zsh)\b/.test(shebang) || extname(path7) === ".sh") {
|
|
222953
|
+
for (const line2 of text30.split("\n")) if (line2.trim() && !line2.trim().startsWith("#")) out.push(...await entries3(p2, line2, dir2, depth + 1));
|
|
222873
222954
|
}
|
|
222874
|
-
|
|
222955
|
+
continue;
|
|
222875
222956
|
}
|
|
222957
|
+
const bin = await packageBin(p2, dir2, program2);
|
|
222958
|
+
if (bin !== void 0) {
|
|
222959
|
+
out.push(bin);
|
|
222960
|
+
continue;
|
|
222961
|
+
}
|
|
222962
|
+
out.push(...await pyprojectScript(p2, dir2, program2));
|
|
222876
222963
|
}
|
|
222877
|
-
|
|
222878
|
-
const runnable = [];
|
|
222879
|
-
for (const file3 of files2.filter((file4) => /^(?:src\/)?[^/]+\.py$/.test(file4) && !/(?:^|\/)(?:setup|conftest)\.py$/.test(file4))) {
|
|
222880
|
-
if (/^\s*if\s+__name__\s*==\s*['"]__main__['"]\s*:/m.test(await read7(file3) ?? "")) runnable.push(file3);
|
|
222881
|
-
}
|
|
222882
|
-
const choices = runnable.length ? [...runnable, ...candidates.filter((file3) => !file3.endsWith(".py"))] : candidates;
|
|
222883
|
-
if (choices.length === 1) {
|
|
222884
|
-
const file3 = choices[0];
|
|
222885
|
-
const runtime2 = file3.endsWith(".py") ? "python" : /\.(?:[cm]?ts)$/.test(file3) ? "npx tsx" : "node";
|
|
222886
|
-
return result(`${runtime2} ${file3}`, "entry-file", file3);
|
|
222887
|
-
}
|
|
222888
|
-
return { agent: null, agentSource: "unconfigured" };
|
|
222964
|
+
return out;
|
|
222889
222965
|
}
|
|
222890
|
-
|
|
222891
|
-
|
|
222892
|
-
|
|
222893
|
-
|
|
222966
|
+
async function scriptEntry(p2, dir2, args, python) {
|
|
222967
|
+
const values2 = python ? PYTHON_VALUE_FLAGS : NODE_VALUE_FLAGS;
|
|
222968
|
+
let i = 0;
|
|
222969
|
+
for (; i < args.length && args[i].startsWith("-"); i++) {
|
|
222970
|
+
if (args[i] === "--") {
|
|
222971
|
+
i++;
|
|
222972
|
+
break;
|
|
222973
|
+
}
|
|
222974
|
+
if (python && args[i] === "-m") return args[i + 1] === void 0 ? [] : pythonModule(dir2, args[i + 1]);
|
|
222975
|
+
if (python && args[i] === "-c") return [];
|
|
222976
|
+
if (!python && (args[i] === "-e" || args[i] === "--eval" || args[i] === "-p" || args[i] === "--print")) return [];
|
|
222977
|
+
if (values2.has(args[i].split("=")[0]) && !args[i].includes("=")) i++;
|
|
222894
222978
|
}
|
|
222895
|
-
|
|
222896
|
-
|
|
222897
|
-
|
|
222898
|
-
|
|
222899
|
-
const
|
|
222900
|
-
|
|
222901
|
-
|
|
222902
|
-
|
|
222903
|
-
|
|
222904
|
-
|
|
222905
|
-
|
|
222906
|
-
|
|
222907
|
-
|
|
222979
|
+
const entry3 = args[i];
|
|
222980
|
+
if (entry3 === void 0 || /^[a-z][a-z\d+.-]*:/i.test(entry3)) return [];
|
|
222981
|
+
const path7 = join23(dir2, entry3);
|
|
222982
|
+
if (await p2.exists(path7)) return [path7];
|
|
222983
|
+
const built3 = /^(?:\.\/)?(?:dist|build|out|lib)\/(.+)\.(?:c|m)?js$/.exec(entry3)?.[1];
|
|
222984
|
+
return built3 === void 0 ? [path7] : [path7, ...[".ts", ".mts", ".tsx"].map((ext) => join23(dir2, "src", `${built3}${ext}`))];
|
|
222985
|
+
}
|
|
222986
|
+
async function fallbackEntries(p2) {
|
|
222987
|
+
let main2;
|
|
222988
|
+
try {
|
|
222989
|
+
const value5 = JSON.parse(await p2.read("package.json") ?? "{}").main;
|
|
222990
|
+
if (typeof value5 === "string") main2 = value5;
|
|
222991
|
+
} catch {
|
|
222908
222992
|
}
|
|
222909
|
-
return
|
|
222993
|
+
return [...main2 ? [main2] : [], "agent.ts", "agent.mjs", "agent.js", "agent.py", "index.ts", "index.mjs", "index.js", "main.py", "app.py", "src/index.ts", "src/agent.ts", "src/main.py", "src/agent.py"];
|
|
222910
222994
|
}
|
|
222911
|
-
function
|
|
222912
|
-
|
|
222913
|
-
const
|
|
222914
|
-
const
|
|
222915
|
-
const
|
|
222916
|
-
|
|
222917
|
-
|
|
222918
|
-
const end = (start2) => {
|
|
222919
|
-
const stack = [], pairs = { "(": ")", "[": "]", "{": "}" };
|
|
222920
|
-
for (let i = start2; i < v.length; i++) {
|
|
222921
|
-
if (pairs[v[i]]) stack.push(pairs[v[i]]);
|
|
222922
|
-
else if (v[i] === stack.at(-1) && stack.pop() && !stack.length) return i;
|
|
222923
|
-
}
|
|
222924
|
-
return start2;
|
|
222995
|
+
async function imports(p2, file3, text30) {
|
|
222996
|
+
const out = [];
|
|
222997
|
+
const from = dirname10(file3);
|
|
222998
|
+
const underBuild = file3.split("/").some((part) => BUILD_DIRS.has(part));
|
|
222999
|
+
const keep2 = (path7) => {
|
|
223000
|
+
const parts3 = path7.split(/[\\/]/);
|
|
223001
|
+
return !parts3.some((part) => SKIP_DIRS.has(part)) && (underBuild || !parts3.some((part) => BUILD_DIRS.has(part)));
|
|
222925
223002
|
};
|
|
222926
|
-
|
|
222927
|
-
|
|
222928
|
-
|
|
222929
|
-
|
|
222930
|
-
|
|
222931
|
-
|
|
222932
|
-
while (v[decorator + 1] === ".") decorator += 2;
|
|
222933
|
-
if (!aliases.has(v[decorator])) continue;
|
|
222934
|
-
const close2 = v[decorator + 1] === "(" ? end(decorator + 1) : decorator;
|
|
222935
|
-
let d = close2 + 1;
|
|
222936
|
-
while (v[d] === "@") {
|
|
222937
|
-
d++;
|
|
222938
|
-
while (d < v.length && v[d] !== "def" && v[d] !== "async") d++;
|
|
222939
|
-
}
|
|
222940
|
-
if (v[d] === "async") d++;
|
|
222941
|
-
if (v[d] !== "def") continue;
|
|
222942
|
-
const symbol3 = v[d + 1];
|
|
222943
|
-
const args2 = v.slice(decorator + 2, close2);
|
|
222944
|
-
const named6 = args2.findIndex((x) => x === "name" || x === "name_override");
|
|
222945
|
-
const name6 = literal2(args2[named6 >= 0 ? named6 + 2 : 0]) ?? symbol3;
|
|
222946
|
-
definitions3.set(symbol3, name6);
|
|
222947
|
-
add(name6, symbol3, i);
|
|
222948
|
-
}
|
|
222949
|
-
if (v[i] !== "=" || !identifier4(v[i - 1])) continue;
|
|
222950
|
-
const symbol2 = v[i - 1];
|
|
222951
|
-
let c = i + 1;
|
|
222952
|
-
while (v[c + 1] === ".") c += 2;
|
|
222953
|
-
if (!(aliases.has(v[c]) || v[c] === "StructuredTool" || v[c] === "from_function") || v[c + 1] !== "(") continue;
|
|
222954
|
-
const close = end(c + 1), args = v.slice(c + 2, close);
|
|
222955
|
-
const named5 = args.findIndex((x) => x === "name" || x === "name_override");
|
|
222956
|
-
const name5 = literal2(args[named5 + 2]) ?? (v[c] === "wrapTool" ? literal2(args[0]) : void 0) ?? symbol2;
|
|
222957
|
-
definitions3.set(symbol2, name5);
|
|
222958
|
-
add(name5, symbol2, i - 1);
|
|
222959
|
-
}
|
|
222960
|
-
const lists2 = /* @__PURE__ */ new Map();
|
|
222961
|
-
for (let i = 0; i < v.length; i++) if (identifier4(v[i]) && v[i + 1] === "=" && ["[", "{"].includes(v[i + 2])) lists2.set(v[i], i + 2);
|
|
222962
|
-
const inspectList = (at4) => {
|
|
222963
|
-
const start2 = lists2.get(v[at4]) ?? at4;
|
|
222964
|
-
if (!["[", "{"].includes(v[start2])) return;
|
|
222965
|
-
const stop = end(start2), object23 = v[start2] === "{";
|
|
222966
|
-
const collection2 = v[start2 - 1] === "=" && identifier4(v[start2 - 2]) ? v[start2 - 2] : void 0;
|
|
222967
|
-
for (let j = start2 + 1; j < stop; ) {
|
|
222968
|
-
const symbol2 = v[j];
|
|
222969
|
-
if (identifier4(symbol2) || literal2(symbol2)) {
|
|
222970
|
-
const key4 = literal2(symbol2) ?? symbol2;
|
|
222971
|
-
const ref22 = object23 && v[j + 1] === ":" ? v[j + 2] : symbol2;
|
|
222972
|
-
const name5 = object23 ? key4 : definitions3.get(ref22) ?? ref22;
|
|
222973
|
-
add(name5, ref22, j);
|
|
222974
|
-
const tool = result.get(name5);
|
|
222975
|
-
if (tool && collection2) tool.collection = collection2;
|
|
222976
|
-
if (tool && object23 && !collection2) tool.inlineObject = true;
|
|
223003
|
+
if (extname(file3) === ".py") {
|
|
223004
|
+
const tryModule = async (base4, module) => {
|
|
223005
|
+
const path7 = module ? join23(base4, ...module.split(".")) : base4;
|
|
223006
|
+
for (const candidate of [`${path7}.py`, join23(path7, "__init__.py")]) if (keep2(candidate) && await p2.exists(candidate)) {
|
|
223007
|
+
out.push(candidate);
|
|
223008
|
+
return true;
|
|
222977
223009
|
}
|
|
222978
|
-
|
|
222979
|
-
|
|
222980
|
-
|
|
222981
|
-
|
|
223010
|
+
return false;
|
|
223011
|
+
};
|
|
223012
|
+
for (const match3 of text30.matchAll(/^[ \t]*from[ \t]+(\.*)([\w.]*)[ \t]+import[ \t]+(?:\(([^)]*)\)|([\w \t,*]+))/gm)) {
|
|
223013
|
+
const dots = match3[1].length, module = match3[2];
|
|
223014
|
+
const bases2 = dots > 0 ? [join23(from, ...Array(dots - 1).fill(".."))] : [from, ".", "src"];
|
|
223015
|
+
for (const base4 of bases2) {
|
|
223016
|
+
const found = await tryModule(base4, module);
|
|
223017
|
+
for (const name5 of (match3[3] ?? match3[4]).split(",").map((word2) => word2.trim().split(/\s+/)[0]).filter((word2) => /^\w+$/.test(word2))) await tryModule(base4, module ? `${module}.${name5}` : name5);
|
|
223018
|
+
if (found) break;
|
|
222982
223019
|
}
|
|
222983
|
-
j++;
|
|
222984
|
-
}
|
|
222985
|
-
};
|
|
222986
|
-
for (let i = 0; i < v.length; i++) {
|
|
222987
|
-
if (["tools", "functions"].includes(v[i]) && ["=", ":"].includes(v[i + 1])) {
|
|
222988
|
-
let start2 = i + 2;
|
|
222989
|
-
if (v[start2] === "ancha" && v[start2 + 1] === ".") start2 += 2;
|
|
222990
|
-
if (["wrap_tools", "wrapTools"].includes(v[start2])) start2 += 2;
|
|
222991
|
-
inspectList(start2);
|
|
222992
223020
|
}
|
|
222993
|
-
|
|
222994
|
-
|
|
222995
|
-
const stop = end(i + 1);
|
|
222996
|
-
for (let j = i + 2; j < stop; j++) {
|
|
222997
|
-
if (v[j] === ",") {
|
|
222998
|
-
inspectList(j + 1);
|
|
222999
|
-
break;
|
|
223000
|
-
}
|
|
223001
|
-
if (["(", "[", "{"].includes(v[j])) j = end(j);
|
|
223002
|
-
}
|
|
223021
|
+
for (const match3 of text30.matchAll(/^[ \t]*import[ \t]+([\w.]+(?:[ \t]*,[ \t]*[\w.]+)*)/gm)) {
|
|
223022
|
+
for (const module of match3[1].split(",").map((word2) => word2.trim())) for (const base4 of [from, ".", "src"]) if (await tryModule(base4, module)) break;
|
|
223003
223023
|
}
|
|
223024
|
+
return out;
|
|
223004
223025
|
}
|
|
223005
|
-
|
|
223006
|
-
|
|
223007
|
-
|
|
223008
|
-
|
|
223009
|
-
|
|
223010
|
-
if (
|
|
223011
|
-
|
|
223012
|
-
|
|
223013
|
-
|
|
223014
|
-
return [language === "py" ? `Add import ancha; pass ancha.wrap_tools([${names5}]) as the framework's tools list, then call ancha.entry(run) at the task entrypoint.` : `Add import { wrapTools, entry } from '@ancha-labs/tools'; ${js}, then call await entry(run) at the task entrypoint.`];
|
|
223015
|
-
});
|
|
223016
|
-
}
|
|
223017
|
-
var identifier4, literal2;
|
|
223018
|
-
var init_function_tools = __esm({
|
|
223019
|
-
"backend/src/kit/function-tools.ts"() {
|
|
223020
|
-
"use strict";
|
|
223021
|
-
identifier4 = (value5 = "") => /^[A-Za-z_$][\w$]*$/.test(value5);
|
|
223022
|
-
literal2 = (value5 = "") => /^["'][A-Za-z_][\w.-]{0,127}["']$/.test(value5) ? value5.slice(1, -1) : void 0;
|
|
223026
|
+
for (const match3 of text30.matchAll(/(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)(['"])(\.{1,2}\/[^'"\n]+)\1/g)) {
|
|
223027
|
+
const base4 = join23(from, match3[2]);
|
|
223028
|
+
const candidates = [base4, ...SOURCE_EXT.map((ext) => `${base4}${ext}`), ...SOURCE_EXT.map((ext) => join23(base4, `index${ext}`))];
|
|
223029
|
+
const js = /\.(c|m)?js$/.exec(base4);
|
|
223030
|
+
if (js) candidates.push(...[".ts", ".tsx", ".mts", ".cts"].map((ext) => base4.slice(0, -js[0].length) + ext));
|
|
223031
|
+
for (const candidate of candidates) if (keep2(candidate) && await p2.exists(candidate)) {
|
|
223032
|
+
out.push(candidate);
|
|
223033
|
+
break;
|
|
223034
|
+
}
|
|
223023
223035
|
}
|
|
223024
|
-
|
|
223025
|
-
|
|
223026
|
-
// backend/src/kit/tool-signals.ts
|
|
223027
|
-
function toolsForSdk(name5, imported2 = false) {
|
|
223028
|
-
const value5 = normalize3(name5);
|
|
223029
|
-
return SUPPORTED_TWINS.filter((twin) => TOOL_SDKS[twin].some((alias) => {
|
|
223030
|
-
const key4 = normalize3(alias);
|
|
223031
|
-
return key4.endsWith("/*") ? value5.startsWith(key4.slice(0, -1)) : value5 === key4 || imported2 && (value5.startsWith(`${key4}.`) || value5.startsWith(`${key4}/`));
|
|
223032
|
-
}));
|
|
223036
|
+
return out;
|
|
223033
223037
|
}
|
|
223034
|
-
function
|
|
223035
|
-
const
|
|
223036
|
-
const
|
|
223037
|
-
|
|
223038
|
-
|
|
223039
|
-
|
|
223040
|
-
|
|
223041
|
-
|
|
223042
|
-
|
|
223043
|
-
|
|
223044
|
-
|
|
223045
|
-
|
|
223046
|
-
|
|
223047
|
-
|
|
223048
|
-
|
|
223049
|
-
|
|
223038
|
+
async function scanTaskInput(root3, command, options4 = {}) {
|
|
223039
|
+
const p2 = project12(resolve18(root3));
|
|
223040
|
+
const maxFiles = options4.maxFiles ?? 200;
|
|
223041
|
+
const normal = (path7) => relative9(p2.root, resolve18(p2.root, path7)).split(sep4).join("/");
|
|
223042
|
+
let queue = command === null ? [] : (await entries3(p2, command)).map(normal);
|
|
223043
|
+
if (!(await Promise.all(queue.map((path7) => p2.exists(path7)))).some(Boolean)) queue = [...queue, ...await fallbackEntries(p2)];
|
|
223044
|
+
const seen = /* @__PURE__ */ new Set(), scanned = [], found = [], variables2 = /* @__PURE__ */ new Map();
|
|
223045
|
+
const order6 = { next: 0 }, marks = { stdin: null, done: null };
|
|
223046
|
+
let native2 = null;
|
|
223047
|
+
while (queue.length && scanned.length < maxFiles) {
|
|
223048
|
+
const file3 = normal(queue.shift());
|
|
223049
|
+
if (seen.has(file3) || !inside(p2.root, resolve18(p2.root, file3))) continue;
|
|
223050
|
+
seen.add(file3);
|
|
223051
|
+
const text30 = await p2.read(file3);
|
|
223052
|
+
if (text30 === void 0) continue;
|
|
223053
|
+
scanned.push(file3);
|
|
223054
|
+
const python = extname(file3) === ".py" || /^#!.*python/.test(text30);
|
|
223055
|
+
const own2 = scanSource(text30, file3, python, found, order6, variables2, marks);
|
|
223056
|
+
if (own2 && !native2) native2 = { name: own2.name, source: file3 };
|
|
223057
|
+
queue.push(...(await imports(p2, file3, text30)).map(normal));
|
|
223050
223058
|
}
|
|
223051
|
-
|
|
223052
|
-
|
|
223053
|
-
|
|
223054
|
-
|
|
223055
|
-
|
|
223059
|
+
return { native: native2, inputs: native2 ? [] : rank(found), scanned, variables: [...variables2.keys()].sort(), variableSources: Object.fromEntries(variables2), ...marks };
|
|
223060
|
+
}
|
|
223061
|
+
function answerSource(scan2, http) {
|
|
223062
|
+
return scan2.done !== null ? "done" : http ? "reply" : "stdout";
|
|
223063
|
+
}
|
|
223064
|
+
function netsuiteField(name5) {
|
|
223065
|
+
const parts3 = new Set(name5.split("_").filter(Boolean));
|
|
223066
|
+
const has4 = (...words9) => words9.some((word2) => parts3.has(word2));
|
|
223067
|
+
const url4 = has4("URL", "URI", "ENDPOINT", "BASE");
|
|
223068
|
+
if (has4("PATH", "FILE", "DIR", "HOST", "DOMAIN", "HOSTNAME", "RESTLET", "RESTLETS", "SCRIPT", "DEPLOY", "DEPLOYMENT", "SOAP", "WSDL")) return void 0;
|
|
223069
|
+
if (has4("MCP")) return has4("TOKEN", "BEARER") ? "mcp_token" : url4 ? "mcp_url" : void 0;
|
|
223070
|
+
if (has4("CONSUMER")) return has4("SECRET") ? "consumer_secret" : has4("KEY", "ID") ? "consumer_key" : void 0;
|
|
223071
|
+
if (has4("TOKEN") && has4("SECRET")) return "token_secret";
|
|
223072
|
+
if (has4("TOKEN") && url4) return "token_url";
|
|
223073
|
+
if (has4("TOKEN") && has4("ID", "KEY")) return "token_id";
|
|
223074
|
+
if (has4("CLIENT")) return has4("SECRET") ? "client_secret" : has4("ID", "KEY") ? "client_id" : void 0;
|
|
223075
|
+
if (has4("CERT", "CERTIFICATE", "KID")) return "certificate_id";
|
|
223076
|
+
if (has4("PRIVATE", "PEM")) return "private_key";
|
|
223077
|
+
if (has4("SUITEQL")) return "suiteql_url";
|
|
223078
|
+
if (has4("RECORD", "RECORDS")) return url4 ? "record_url" : void 0;
|
|
223079
|
+
if (has4("REST") && url4) return "rest_url";
|
|
223080
|
+
if (url4) return "url";
|
|
223081
|
+
if (has4("ACCOUNT", "REALM", "COMPANY")) return "account_id";
|
|
223082
|
+
if (has4("TOKEN", "BEARER")) return "access_token";
|
|
223083
|
+
return void 0;
|
|
223084
|
+
}
|
|
223085
|
+
function netsuiteMappings(variables2) {
|
|
223086
|
+
netsuiteGiven ??= new Set(Object.keys(toolConnectionEnvironment({ netsuite: ANY_SERVICE })));
|
|
223087
|
+
return variables2.filter((name5) => NETSUITE_NAME.test(name5) && !netsuiteGiven.has(name5)).flatMap((name5) => {
|
|
223088
|
+
const field6 = netsuiteField(name5);
|
|
223089
|
+
return field6 === void 0 ? [] : [{ name: name5, value: NETSUITE_VALUE[field6] ?? `{{netsuite.${field6}}}` }];
|
|
223090
|
+
});
|
|
223091
|
+
}
|
|
223092
|
+
function taskWiring(input5, command) {
|
|
223093
|
+
if (input5.via === "env") {
|
|
223094
|
+
const value5 = input5.file ? "{{task_file}}" : "{{task}}";
|
|
223095
|
+
return { input: input5, env: { [input5.name]: value5 }, yaml: `env: { ${input5.name}: "${value5}" }` };
|
|
223056
223096
|
}
|
|
223057
|
-
|
|
223058
|
-
|
|
223097
|
+
const base4 = NPM_SCRIPT2.test(command) ? `${command.trim()} --` : command.trim();
|
|
223098
|
+
const next2 = `${base4} ${input5.name} "${input5.file ? "$ANCHA_TASK_FILE" : "$ANCHA_TASK"}"`;
|
|
223099
|
+
return { input: input5, command: next2, yaml: `command: ${/^[\w./@+-]/.test(next2) && !/: | #/.test(next2) ? next2 : JSON.stringify(next2)}` };
|
|
223059
223100
|
}
|
|
223060
|
-
|
|
223061
|
-
|
|
223062
|
-
|
|
223101
|
+
function mappedTaskInput(agent) {
|
|
223102
|
+
const mapped = Object.entries(agent.env ?? {}).find(([, value5]) => /\{\{\s*task(?:_file)?\s*\}\}/.test(value5));
|
|
223103
|
+
if (mapped) return mapped[0];
|
|
223104
|
+
const command = agent.command ?? "";
|
|
223105
|
+
const flag5 = /(--[\w-]+)(?:\s+|=)["']?\$\{?ANCHA_TASK(?:_FILE)?\b/.exec(command);
|
|
223106
|
+
if (flag5) return flag5[1];
|
|
223107
|
+
return /\$\{?ANCHA_TASK(?:_FILE)?\b/.test(command) ? "ANCHA_TASK" : null;
|
|
223108
|
+
}
|
|
223109
|
+
function unmappedTaskInput(inputs2, agent) {
|
|
223110
|
+
const command = agent.command ?? "";
|
|
223111
|
+
return inputs2.find((input5) => input5.via === "env" ? !Object.hasOwn(agent.env ?? {}, input5.name) : !new RegExp(`(?<![\\w-])${input5.name.replace(/[-]/g, "\\-")}(?![\\w-])`).test(command)) ?? null;
|
|
223112
|
+
}
|
|
223113
|
+
var STRONG, WEAK, FILE_WORDS, NOT_TASK, FLAG, NATIVE_NAMES, FLAG_WORDS, lineAt, PYTHON_STDIN, NODE_STDIN, SKIP_DIRS, BUILD_DIRS, SOURCE_EXT, MAX_FILE_BYTES, inside, pythonModule, NODE_VALUE_FLAGS, PYTHON_VALUE_FLAGS, quoteAll, NETSUITE_NAME, netsuiteGiven, NETSUITE_VALUE, NPM_SCRIPT2, describeTaskInput;
|
|
223114
|
+
var init_task_input = __esm({
|
|
223115
|
+
"backend/src/kit/task-input.ts"() {
|
|
223063
223116
|
"use strict";
|
|
223064
223117
|
init_src();
|
|
223065
|
-
|
|
223066
|
-
|
|
223067
|
-
|
|
223068
|
-
|
|
223069
|
-
|
|
223070
|
-
"
|
|
223071
|
-
|
|
223072
|
-
|
|
223073
|
-
|
|
223074
|
-
|
|
223075
|
-
"
|
|
223076
|
-
"
|
|
223077
|
-
"
|
|
223078
|
-
|
|
223079
|
-
"
|
|
223080
|
-
"
|
|
223081
|
-
"
|
|
223082
|
-
|
|
223083
|
-
|
|
223084
|
-
|
|
223085
|
-
|
|
223086
|
-
"
|
|
223087
|
-
|
|
223088
|
-
|
|
223089
|
-
|
|
223090
|
-
|
|
223091
|
-
"
|
|
223092
|
-
|
|
223093
|
-
|
|
223094
|
-
|
|
223095
|
-
|
|
223096
|
-
|
|
223097
|
-
|
|
223098
|
-
|
|
223099
|
-
|
|
223100
|
-
|
|
223101
|
-
|
|
223102
|
-
|
|
223103
|
-
|
|
223104
|
-
|
|
223105
|
-
|
|
223106
|
-
"
|
|
223107
|
-
|
|
223108
|
-
|
|
223109
|
-
|
|
223110
|
-
|
|
223111
|
-
|
|
223112
|
-
|
|
223113
|
-
|
|
223114
|
-
|
|
223115
|
-
|
|
223116
|
-
"
|
|
223117
|
-
|
|
223118
|
-
|
|
223119
|
-
|
|
223120
|
-
|
|
223121
|
-
"
|
|
223122
|
-
"
|
|
223123
|
-
"
|
|
223124
|
-
|
|
223125
|
-
"
|
|
223126
|
-
"
|
|
223127
|
-
|
|
223128
|
-
|
|
223129
|
-
|
|
223130
|
-
|
|
223131
|
-
"
|
|
223132
|
-
|
|
223133
|
-
|
|
223134
|
-
|
|
223135
|
-
|
|
223136
|
-
|
|
223137
|
-
"
|
|
223138
|
-
|
|
223139
|
-
|
|
223140
|
-
|
|
223141
|
-
|
|
223142
|
-
|
|
223143
|
-
|
|
223144
|
-
|
|
223145
|
-
|
|
223146
|
-
|
|
223147
|
-
|
|
223148
|
-
|
|
223118
|
+
init_agent_env();
|
|
223119
|
+
STRONG = /* @__PURE__ */ new Set(["TASK", "PROMPT", "INSTRUCTION", "INSTRUCTIONS"]);
|
|
223120
|
+
WEAK = /* @__PURE__ */ new Set(["QUERY", "QUESTION", "MESSAGE", "REQUEST", "INPUT"]);
|
|
223121
|
+
FILE_WORDS = /* @__PURE__ */ new Set(["FILE", "PATH"]);
|
|
223122
|
+
NOT_TASK = /* @__PURE__ */ new Set([
|
|
223123
|
+
"SYSTEM",
|
|
223124
|
+
"TEMPLATE",
|
|
223125
|
+
"TEMPLATES",
|
|
223126
|
+
"DIR",
|
|
223127
|
+
"DIRS",
|
|
223128
|
+
"DIRECTORY",
|
|
223129
|
+
"FOLDER",
|
|
223130
|
+
"URL",
|
|
223131
|
+
"URLS",
|
|
223132
|
+
"URI",
|
|
223133
|
+
"HOST",
|
|
223134
|
+
"PORT",
|
|
223135
|
+
"KEY",
|
|
223136
|
+
"KEYS",
|
|
223137
|
+
"TOKEN",
|
|
223138
|
+
"TOKENS",
|
|
223139
|
+
"SECRET",
|
|
223140
|
+
"PASSWORD",
|
|
223141
|
+
"ID",
|
|
223142
|
+
"IDS",
|
|
223143
|
+
"MODEL",
|
|
223144
|
+
"TIMEOUT",
|
|
223145
|
+
"MAX",
|
|
223146
|
+
"MIN",
|
|
223147
|
+
"LIMIT",
|
|
223148
|
+
"COUNT",
|
|
223149
|
+
"SIZE",
|
|
223150
|
+
"TYPE",
|
|
223151
|
+
"TYPES",
|
|
223152
|
+
"FORMAT",
|
|
223153
|
+
"MODE",
|
|
223154
|
+
"QUEUE",
|
|
223155
|
+
"TOPIC",
|
|
223156
|
+
"LOG",
|
|
223157
|
+
"LOGS",
|
|
223158
|
+
"LEVEL",
|
|
223159
|
+
"ENABLED",
|
|
223160
|
+
"DISABLED",
|
|
223161
|
+
"ENABLE",
|
|
223162
|
+
"DISABLE",
|
|
223163
|
+
"DEBUG",
|
|
223164
|
+
"VERSION",
|
|
223165
|
+
"NAME",
|
|
223166
|
+
"RETRIES",
|
|
223167
|
+
"RETRY",
|
|
223168
|
+
"CACHE",
|
|
223169
|
+
"BUCKET",
|
|
223170
|
+
"TABLE",
|
|
223171
|
+
"DB",
|
|
223172
|
+
"WEBHOOK",
|
|
223173
|
+
"CHANNEL",
|
|
223174
|
+
"ARN",
|
|
223175
|
+
"REGION",
|
|
223176
|
+
"PREFIX",
|
|
223177
|
+
"SUFFIX",
|
|
223178
|
+
"SCHEMA",
|
|
223179
|
+
"LANG",
|
|
223180
|
+
"LANGUAGE",
|
|
223181
|
+
"ENCODING",
|
|
223182
|
+
"LENGTH",
|
|
223183
|
+
"LEN",
|
|
223184
|
+
"STATUS",
|
|
223185
|
+
"STATE",
|
|
223186
|
+
"TTL",
|
|
223187
|
+
"INTERVAL",
|
|
223188
|
+
"DELAY",
|
|
223189
|
+
"CONCURRENCY",
|
|
223190
|
+
"WORKERS",
|
|
223191
|
+
"BATCH",
|
|
223192
|
+
"ENDPOINT",
|
|
223193
|
+
"EXAMPLE",
|
|
223194
|
+
"EXAMPLES",
|
|
223195
|
+
"HISTORY",
|
|
223196
|
+
"TEMPERATURE",
|
|
223197
|
+
"COST",
|
|
223198
|
+
"BUDGET",
|
|
223199
|
+
"TRACE",
|
|
223200
|
+
"TRACES",
|
|
223201
|
+
"TRACING",
|
|
223202
|
+
"EVENT",
|
|
223203
|
+
"EVENTS",
|
|
223204
|
+
"QUEUES",
|
|
223205
|
+
"SIGNING",
|
|
223206
|
+
"HEADER",
|
|
223207
|
+
"HEADERS"
|
|
223208
|
+
]);
|
|
223209
|
+
FLAG = /^--(task|prompt|message|input|query|instructions?|request|question)(?:[-_](file|path))?$/;
|
|
223210
|
+
NATIVE_NAMES = /\b(ANCHA_TASK_FILE|ANCHA_TASK|ANCHA_INPUT_JSON)\b/;
|
|
223211
|
+
FLAG_WORDS = /(?<![\w-])--[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*(?![\w-])/gi;
|
|
223212
|
+
lineAt = (text30, index) => text30.slice(0, index).split("\n").length;
|
|
223213
|
+
PYTHON_STDIN = /\bsys\.stdin\b|(?<![\w.])(?<!\bdef\s+)input\s*\(|\bfileinput\.input\s*\(|\bopen\(\s*(?:0\s*[,)]|['"]\/dev\/stdin['"])/;
|
|
223214
|
+
NODE_STDIN = /\bprocess\.stdin\b|\b(?:Deno|Bun)\.stdin\b|\breadFileSync\(\s*(?:0\s*[,)]|['"`]\/dev\/stdin['"`])/;
|
|
223215
|
+
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".venv", "venv", "site-packages", ".git", "__pycache__"]);
|
|
223216
|
+
BUILD_DIRS = /* @__PURE__ */ new Set(["dist", "build", "out", ".next"]);
|
|
223217
|
+
SOURCE_EXT = [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".jsx"];
|
|
223218
|
+
MAX_FILE_BYTES = 1e6;
|
|
223219
|
+
inside = (root3, path7) => {
|
|
223220
|
+
const rel = relative9(root3, path7);
|
|
223221
|
+
return rel !== "" && !rel.startsWith(`..${sep4}`) && rel !== ".." && !isAbsolute6(rel);
|
|
223222
|
+
};
|
|
223223
|
+
pythonModule = (cwd, module) => {
|
|
223224
|
+
const path7 = module.split(".").join("/");
|
|
223225
|
+
return [`${path7}.py`, `${path7}/__main__.py`, `${path7}/__init__.py`, `src/${path7}.py`, `src/${path7}/__main__.py`, `src/${path7}/__init__.py`].map((file3) => join23(cwd, file3));
|
|
223149
223226
|
};
|
|
223227
|
+
NODE_VALUE_FLAGS = /* @__PURE__ */ new Set(["--require", "-r", "--import", "--loader", "--experimental-loader", "--tsconfig", "--config", "-c", "--env-file", "--conditions", "-C", "--title", "--inspect-port"]);
|
|
223228
|
+
PYTHON_VALUE_FLAGS = /* @__PURE__ */ new Set(["-W", "-X", "-Q"]);
|
|
223229
|
+
quoteAll = (list18) => list18.map((word2) => /^[\w./:=@+-]+$/.test(word2) ? word2 : `'${word2.replaceAll("'", "'\\''")}'`).join(" ");
|
|
223230
|
+
NETSUITE_NAME = /^(?:NETSUITE|NS)_|NETSUITE|SUITETALK/;
|
|
223231
|
+
NETSUITE_VALUE = { url: "{{netsuite.url}}", rest_url: "{{netsuite.url}}/services/rest" };
|
|
223232
|
+
NPM_SCRIPT2 = /^\s*npm\s+(?:start|test|run(?:-script)?\s+\S+)\s*$/;
|
|
223233
|
+
describeTaskInput = (input5) => input5.via === "env" ? input5.name : `the ${input5.name} flag`;
|
|
223150
223234
|
}
|
|
223151
223235
|
});
|
|
223152
223236
|
|
|
223153
|
-
// backend/src/kit/
|
|
223154
|
-
function
|
|
223155
|
-
|
|
223156
|
-
const
|
|
223157
|
-
|
|
223158
|
-
|
|
223159
|
-
|
|
223160
|
-
|
|
223161
|
-
|
|
223162
|
-
|
|
223163
|
-
|
|
223164
|
-
|
|
223165
|
-
|
|
223166
|
-
const
|
|
223167
|
-
if (
|
|
223168
|
-
const name5 = /^\s*["']?([\w.-]+)["']?\s*=/.exec(line2)?.[1];
|
|
223169
|
-
if (name5 && name5 !== "python") names5.push(name5);
|
|
223170
|
-
continue;
|
|
223171
|
-
}
|
|
223172
|
-
const array3 = section2 === "project.optional-dependencies" || section2 === "dependency-groups" || section2 === "project" && (/^\s*dependencies\s*=/.test(line2) || dependencies);
|
|
223173
|
-
if (!array3) continue;
|
|
223174
|
-
for (const match3 of line2.matchAll(/["']([a-zA-Z0-9][\w.-]*)(?:\[[^\]]*\])?(?:[ <>=!~;@][^"']*)?["']/g)) names5.push(match3[1]);
|
|
223175
|
-
dependencies = !/\]\s*,?\s*$/.test(line2);
|
|
223176
|
-
}
|
|
223177
|
-
return names5;
|
|
223178
|
-
}
|
|
223179
|
-
async function detectProject(cwd, agent) {
|
|
223180
|
-
if (agent !== void 0 && agent.trim() === "") throw new AnchaError("USAGE", "--agent must be a non-empty command", { hint: 'e.g. --agent "node agent.mjs"' });
|
|
223181
|
-
const evidence2 = [];
|
|
223182
|
-
const found = /* @__PURE__ */ new Map();
|
|
223183
|
-
const files2 = await projectFiles2(cwd);
|
|
223184
|
-
const read7 = (name5) => readProjectFile(cwd, name5);
|
|
223185
|
-
let node5 = false, python = false;
|
|
223186
|
-
for (const name5 of files2.filter((name6) => MANIFEST_FILE.test(name6.split("/").at(-1)))) {
|
|
223187
|
-
const body7 = await read7(name5);
|
|
223188
|
-
if (body7 === void 0) continue;
|
|
223189
|
-
evidence2.push(name5);
|
|
223190
|
-
let dependencies = [];
|
|
223191
|
-
if (name5.endsWith("package.json")) {
|
|
223192
|
-
node5 = true;
|
|
223193
|
-
try {
|
|
223194
|
-
const manifest2 = JSON.parse(body7);
|
|
223195
|
-
dependencies = [...Object.keys(manifest2.dependencies ?? {}), ...Object.keys(manifest2.devDependencies ?? {}), ...Object.keys(manifest2.optionalDependencies ?? {})];
|
|
223196
|
-
} catch {
|
|
223197
|
-
evidence2.push("package.json could not be parsed; dependency detection incomplete");
|
|
223198
|
-
}
|
|
223199
|
-
} else {
|
|
223200
|
-
python = true;
|
|
223201
|
-
dependencies = pythonDependencies(body7, name5);
|
|
223202
|
-
}
|
|
223203
|
-
for (const dependency of dependencies) for (const twin of toolsForSdk(dependency)) if (!found.has(twin)) found.set(twin, `${dependency.toLowerCase()} in ${name5}`);
|
|
223204
|
-
}
|
|
223205
|
-
let sourceNode = false, sourcePython = false;
|
|
223206
|
-
const apps = [];
|
|
223207
|
-
const functions = /* @__PURE__ */ new Map();
|
|
223208
|
-
for (const name5 of files2.filter((name6) => SOURCE_FILE.test(name6))) {
|
|
223209
|
-
const body7 = await read7(name5);
|
|
223210
|
-
if (body7 === void 0) continue;
|
|
223211
|
-
const app2 = slackAppInSource(body7, name5);
|
|
223212
|
-
if (app2) apps.push(app2);
|
|
223213
|
-
for (const tool of functionToolsIn(body7, name5)) if (!functions.has(tool.name)) functions.set(tool.name, tool);
|
|
223214
|
-
if (name5.endsWith(".py")) sourcePython = true;
|
|
223215
|
-
else sourceNode = true;
|
|
223216
|
-
for (const [twin, signal] of sourceToolSignals(body7, name5.endsWith(".py"))) if (!found.has(twin)) found.set(twin, `${signal} in ${name5}`);
|
|
223217
|
-
}
|
|
223218
|
-
if (!node5 && !python) {
|
|
223219
|
-
node5 = sourceNode;
|
|
223220
|
-
python = sourcePython;
|
|
223221
|
-
}
|
|
223222
|
-
if (node5 && python) evidence2.push("mixed Node/Python sources; choose connect --lang explicitly");
|
|
223223
|
-
const start2 = agent === void 0 ? await inferStartCommand(read7, files2) : { agent, agentSource: "explicit" };
|
|
223224
|
-
const slackApp = apps.find((app2) => start2.agent?.includes(app2.file)) ?? (apps.length === 1 ? apps[0] : void 0);
|
|
223225
|
-
if (slackApp && start2.agent === null) {
|
|
223226
|
-
const file3 = slackApp.file;
|
|
223227
|
-
Object.assign(start2, { agent: `${file3.endsWith(".py") ? "python" : /\.ts$/.test(file3) ? "npx tsx" : "node"} '${file3.replaceAll("'", "'\\''")}'`, agentSource: "entry-file", agentEvidence: file3 });
|
|
223237
|
+
// backend/src/kit/slack-app.ts
|
|
223238
|
+
function slackAppInSource(body7, file3) {
|
|
223239
|
+
const python = file3.endsWith(".py");
|
|
223240
|
+
const code5 = body7.replace(python ? /^\s*#.*$/gm : /\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm, "");
|
|
223241
|
+
if (!(python ? /\bfrom\s+slack_bolt(?:\.async_app)?\s+import\s+.*\b(?:Async)?App\b/ : /["']@slack\/bolt["']/).test(code5) || !/\b(?:Async)?App\s*\(/.test(code5)) return;
|
|
223242
|
+
const socket = python ? /\b(?:Async)?SocketModeHandler\s*\(/.test(code5) : /\bsocketMode\s*:\s*true\b/.test(code5);
|
|
223243
|
+
const start2 = /\.start\s*\(([^\n;]*)/.exec(code5)?.[1];
|
|
223244
|
+
const portOption = /\bport\s*:\s*(\d+)/.exec(code5)?.[1];
|
|
223245
|
+
const hasPort = /\bport\s*:/.test(code5);
|
|
223246
|
+
if (!socket && start2 === void 0 && !hasPort) return;
|
|
223247
|
+
const env2 = {};
|
|
223248
|
+
const variables2 = [...new Set(envReads(code5, python).sort((a, b) => a.index - b.index).map((read7) => read7.name))];
|
|
223249
|
+
for (const name5 of variables2) {
|
|
223250
|
+
const value5 = /SIGNING.*SECRET/i.test(name5) ? "slack.signing_secret" : /APP.*TOKEN|TOKEN.*APP/i.test(name5) ? "slack.app_token" : /(?:SLACK|BOT).*TOKEN/i.test(name5) ? "slack.token" : /SLACK.*(?:URL|BASE)/i.test(name5) ? "slack.url" : void 0;
|
|
223251
|
+
if (value5) env2[name5] = `{{${value5}}}`;
|
|
223228
223252
|
}
|
|
223229
|
-
|
|
223230
|
-
|
|
223253
|
+
if (socket) return { file: file3, transport: "socket", env: env2 };
|
|
223254
|
+
const portVar = variables2.find((name5) => /(?:^|_)PORT$/.test(name5));
|
|
223255
|
+
const literal4 = /^(?:\s*port\s*=)?\s*(\d+)\b/.exec(start2 ?? "")?.[1] ?? portOption;
|
|
223256
|
+
const dynamic = portVar !== void 0 && literal4 === void 0;
|
|
223257
|
+
if (dynamic) env2[portVar] = "{{agent.port}}";
|
|
223258
|
+
const path7 = /\b(?:endpoints|path)\s*:\s*["'](\/[^"']*)["']/.exec(code5)?.[1] ?? "/slack/events";
|
|
223259
|
+
return { file: file3, transport: "http", url: `http://127.0.0.1:${dynamic ? "{{agent.port}}" : literal4 ?? "3000"}${path7}`, env: env2 };
|
|
223231
223260
|
}
|
|
223232
|
-
var
|
|
223233
|
-
"backend/src/kit/
|
|
223261
|
+
var init_slack_app2 = __esm({
|
|
223262
|
+
"backend/src/kit/slack-app.ts"() {
|
|
223234
223263
|
"use strict";
|
|
223235
|
-
|
|
223236
|
-
init_src();
|
|
223237
|
-
init_start_command();
|
|
223238
|
-
init_project_files();
|
|
223239
|
-
init_function_tools();
|
|
223240
|
-
init_tool_signals();
|
|
223264
|
+
init_task_input();
|
|
223241
223265
|
}
|
|
223242
223266
|
});
|
|
223243
223267
|
|
|
223244
|
-
// backend/src/kit/
|
|
223245
|
-
import {
|
|
223246
|
-
import {
|
|
223247
|
-
|
|
223248
|
-
|
|
223249
|
-
const
|
|
223250
|
-
if (
|
|
223251
|
-
const strong = parts3.some((part) => STRONG.has(part)), weak = parts3.some((part) => WEAK.has(part));
|
|
223252
|
-
if (!strong && !weak) return null;
|
|
223253
|
-
return { strength: strong ? 2 : 1, file: parts3.some((part) => FILE_WORDS.has(part)) };
|
|
223254
|
-
}
|
|
223255
|
-
function taskFlag(flag5) {
|
|
223256
|
-
const match3 = FLAG.exec(flag5.toLowerCase());
|
|
223257
|
-
if (!match3) return null;
|
|
223258
|
-
return { strength: /^(task|prompt|instructions?)$/.test(match3[1]) ? 2 : 1, file: match3[2] !== void 0 };
|
|
223259
|
-
}
|
|
223260
|
-
function rank(found) {
|
|
223261
|
-
const via = (input5) => (input5.file ? 2 : 0) + (input5.via === "flag" ? 1 : 0);
|
|
223262
|
-
const seen = /* @__PURE__ */ new Set();
|
|
223263
|
-
return found.sort((a, b) => b.strength - a.strength || via(a.input) - via(b.input) || a.order - b.order).map((item2) => item2.input).filter((input5) => {
|
|
223264
|
-
const key4 = `${input5.via}:${input5.name}`;
|
|
223265
|
-
if (seen.has(key4)) return false;
|
|
223266
|
-
seen.add(key4);
|
|
223267
|
-
return true;
|
|
223268
|
-
});
|
|
223269
|
-
}
|
|
223270
|
-
function scanSource(text30, source, python, found, order6, variables2, marks) {
|
|
223271
|
-
const entryHelper = !python && /@ancha-labs\/tools/.test(text30) && /\bentry\s*\(/.test(text30) || python && (/from\s+ancha(?:\.tools)?\s+import\s+[^\n]*\bentry\b/.test(text30) || /\bancha\.entry\s*\(/.test(text30));
|
|
223272
|
-
const native2 = NATIVE_NAMES.exec(text30) ?? (entryHelper ? [, "entry"] : null);
|
|
223273
|
-
const stdin = (python ? PYTHON_STDIN : NODE_STDIN).exec(text30);
|
|
223274
|
-
if (stdin && !marks.stdin) marks.stdin = { source, line: lineAt(text30, stdin.index) };
|
|
223275
|
-
const done = /\bANCHA_DONE_URL\b/.exec(text30) ?? (entryHelper ? /\bentry\s*\(/.exec(text30) : null);
|
|
223276
|
-
if (done && !marks.done) marks.done = { name: done[0].startsWith("ANCHA_") ? "ANCHA_DONE_URL" : "entry", source, line: lineAt(text30, done.index) };
|
|
223277
|
-
const env2 = (name5, index) => {
|
|
223278
|
-
if (!variables2.has(name5)) variables2.set(name5, { source, line: lineAt(text30, index) });
|
|
223279
|
-
if (native2) return;
|
|
223280
|
-
const kind2 = taskVariable(name5);
|
|
223281
|
-
if (kind2) found.push({ input: { via: "env", name: name5, file: kind2.file, source, line: lineAt(text30, index) }, strength: kind2.strength, order: order6.next++ });
|
|
223282
|
-
};
|
|
223283
|
-
const flag5 = (name5, index) => {
|
|
223284
|
-
if (native2) return;
|
|
223285
|
-
const kind2 = taskFlag(name5);
|
|
223286
|
-
if (kind2) found.push({ input: { via: "flag", name: name5.toLowerCase(), file: kind2.file, source, line: lineAt(text30, index) }, strength: kind2.strength, order: order6.next++ });
|
|
223287
|
-
};
|
|
223288
|
-
const all9 = (pattern, group5, each) => {
|
|
223289
|
-
for (const match3 of text30.matchAll(pattern)) each(match3[group5], match3.index);
|
|
223290
|
-
};
|
|
223291
|
-
if (python) {
|
|
223292
|
-
all9(/\bos\.environ\[\s*(['"])([A-Za-z_]\w*)\1\s*\]/g, 2, env2);
|
|
223293
|
-
all9(/\b(?:os\.environ\.get|os\.getenv|(?<![\w.])getenv|(?<![\w.])environ\.get)\(\s*(['"])([A-Za-z_]\w*)\1/g, 2, env2);
|
|
223294
|
-
all9(/(?<![\w.])environ\[\s*(['"])([A-Za-z_]\w*)\1\s*\]/g, 2, env2);
|
|
223295
|
-
for (const alias of text30.matchAll(/^\s*([A-Za-z_]\w*)\s*=\s*os\.environ\s*$/gm)) {
|
|
223296
|
-
all9(new RegExp(`(?<![\\w.])${alias[1]}(?:\\.get\\(|\\[)\\s*(['"])([A-Za-z_]\\w*)\\1`, "g"), 2, env2);
|
|
223297
|
-
}
|
|
223298
|
-
all9(/\b([a-z][a-z0-9_]*)\s*:\s*[\w[\], |.]+?=\s*typer\.Option\(/g, 1, (name5, index) => flag5(`--${name5.replaceAll("_", "-")}`, index));
|
|
223299
|
-
} else {
|
|
223300
|
-
all9(/\bprocess\.env\.([A-Za-z_]\w*)/g, 1, env2);
|
|
223301
|
-
all9(/\bprocess\.env\[\s*(['"`])([A-Za-z_]\w*)\1\s*\]/g, 2, env2);
|
|
223302
|
-
all9(/\b(?:Deno\.env\.get)\(\s*(['"`])([A-Za-z_]\w*)\1/g, 2, env2);
|
|
223303
|
-
all9(/\bBun\.env\.([A-Za-z_]\w*)/g, 1, env2);
|
|
223304
|
-
const destructured = (body7, index) => {
|
|
223305
|
-
for (const part of body7.split(",")) {
|
|
223306
|
-
const name5 = /^\s*([A-Za-z_]\w*)/.exec(part)?.[1];
|
|
223307
|
-
if (name5) env2(name5, index);
|
|
223308
|
-
}
|
|
223309
|
-
};
|
|
223310
|
-
all9(/\{([^{}]*)\}\s*=\s*process\.env\b/g, 1, destructured);
|
|
223311
|
-
for (const alias of text30.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*process\.env\s*(?:[;\n]|$)/g)) {
|
|
223312
|
-
const name5 = alias[1].replace(/\$/g, "\\$");
|
|
223313
|
-
all9(new RegExp(`(?<![\\w$.])${name5}\\.([A-Za-z_]\\w*)`, "g"), 1, env2);
|
|
223314
|
-
all9(new RegExp(`(?<![\\w$.])${name5}\\[\\s*(['"\`])([A-Za-z_]\\w*)\\1\\s*\\]`, "g"), 2, env2);
|
|
223315
|
-
all9(new RegExp(`\\{([^{}]*)\\}\\s*=\\s*${name5}\\b`, "g"), 1, destructured);
|
|
223316
|
-
}
|
|
223317
|
-
for (const call4 of text30.matchAll(/\bparseArgs\s*\(|\.options\s*\(\s*\{/g)) {
|
|
223318
|
-
const region = text30.slice(call4.index, call4.index + 4e3);
|
|
223319
|
-
for (const match3 of region.matchAll(/(['"]?)([A-Za-z][\w-]*)\1\s*:\s*\{[^{}]*?\btype\s*:\s*['"]string['"]/g)) flag5(`--${match3[2]}`, call4.index + match3.index);
|
|
223320
|
-
}
|
|
223321
|
-
all9(/\.option\(\s*(['"])([A-Za-z][\w-]*)\1\s*,\s*\{/g, 2, (name5, index) => flag5(`--${name5}`, index));
|
|
223322
|
-
}
|
|
223323
|
-
const argv = python ? /\bsys\.argv\b|\bargparse\b|\bclick\b|\btyper\b|\bdocopt\b|\bfire\.Fire\b/ : /\bprocess\.argv\b|\bparseArgs\b|\bcommander\b|\byargs\b|\bminimist\b|\bmri\b|\bmeow\b|\bcac\b|\bsade\b|\bDeno\.args\b|\bBun\.argv\b/;
|
|
223324
|
-
if (argv.test(text30)) all9(FLAG_WORDS, 0, flag5);
|
|
223325
|
-
return native2 ? { name: native2[1] } : null;
|
|
223326
|
-
}
|
|
223327
|
-
function taskInputsInText(text30) {
|
|
223328
|
-
const found = [];
|
|
223329
|
-
let order6 = 0;
|
|
223330
|
-
for (const line2 of text30.split(/\r?\n/)) {
|
|
223331
|
-
for (const match3 of line2.matchAll(FLAG_WORDS)) {
|
|
223332
|
-
const kind2 = taskFlag(match3[0]);
|
|
223333
|
-
if (kind2) found.push({ input: { via: "flag", name: match3[0].toLowerCase(), file: kind2.file, source: "output" }, strength: kind2.strength, order: order6++ });
|
|
223334
|
-
}
|
|
223335
|
-
const variables2 = /\b(?:env|environment|variable|var)\b/i.test(line2);
|
|
223336
|
-
for (const match3 of line2.matchAll(/(?<![\w$])\$?([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*)\b/g)) {
|
|
223337
|
-
const name5 = match3[1], kind2 = taskVariable(name5);
|
|
223338
|
-
if (kind2 && (name5.includes("_") || variables2 || match3[0].startsWith("$"))) found.push({ input: { via: "env", name: name5, file: kind2.file, source: "output" }, strength: kind2.strength, order: order6++ });
|
|
223339
|
-
}
|
|
223340
|
-
}
|
|
223341
|
-
return rank(found);
|
|
223342
|
-
}
|
|
223343
|
-
function words7(command) {
|
|
223344
|
-
const commands = [[]];
|
|
223345
|
-
let word2 = "", quote6 = "", started = false;
|
|
223346
|
-
const end = () => {
|
|
223347
|
-
if (started) commands.at(-1).push(word2);
|
|
223348
|
-
word2 = "";
|
|
223349
|
-
started = false;
|
|
223350
|
-
};
|
|
223351
|
-
for (let i = 0; i < command.length; i++) {
|
|
223352
|
-
const char = command[i];
|
|
223353
|
-
if (quote6) {
|
|
223354
|
-
if (char === quote6) quote6 = "";
|
|
223355
|
-
else if (char === "\\" && quote6 === '"' && i + 1 < command.length) word2 += command[++i];
|
|
223356
|
-
else word2 += char;
|
|
223357
|
-
continue;
|
|
223358
|
-
}
|
|
223359
|
-
if (char === "'" || char === '"') {
|
|
223360
|
-
quote6 = char;
|
|
223361
|
-
started = true;
|
|
223362
|
-
continue;
|
|
223363
|
-
}
|
|
223364
|
-
if (char === "\\" && i + 1 < command.length) {
|
|
223365
|
-
word2 += command[++i];
|
|
223366
|
-
started = true;
|
|
223367
|
-
continue;
|
|
223368
|
-
}
|
|
223369
|
-
if (/[;&|\n]/.test(char)) {
|
|
223370
|
-
end();
|
|
223371
|
-
if (commands.at(-1).length) commands.push([]);
|
|
223372
|
-
continue;
|
|
223373
|
-
}
|
|
223374
|
-
if (/\s/.test(char)) {
|
|
223375
|
-
end();
|
|
223376
|
-
continue;
|
|
223377
|
-
}
|
|
223378
|
-
word2 += char;
|
|
223379
|
-
started = true;
|
|
223380
|
-
}
|
|
223381
|
-
end();
|
|
223382
|
-
return commands.filter((list18) => list18.length > 0);
|
|
223383
|
-
}
|
|
223384
|
-
async function readSmall(path7) {
|
|
223385
|
-
let handle30;
|
|
223268
|
+
// backend/src/kit/project-files.ts
|
|
223269
|
+
import { constants as constants8 } from "node:fs";
|
|
223270
|
+
import { lstat as lstat3, open as open6, readdir as readdir3 } from "node:fs/promises";
|
|
223271
|
+
import { isAbsolute as isAbsolute7, relative as relative10, resolve as resolve19, sep as sep5 } from "node:path";
|
|
223272
|
+
async function readProjectFile(root3, path7) {
|
|
223273
|
+
const rel = relative10(resolve19(root3), resolve19(root3, path7));
|
|
223274
|
+
if (!rel || isAbsolute7(rel) || rel.split(sep5).some((part) => part === ".." || part.startsWith(".") || SKIP.has(part)) || /(?:^|\/)(?:credentials|secrets)(?:\.|$)|\.(?:pem|key)$/i.test(rel)) return void 0;
|
|
223386
223275
|
try {
|
|
223387
|
-
|
|
223276
|
+
let current = resolve19(root3);
|
|
223277
|
+
for (const part of rel.split(sep5)) {
|
|
223278
|
+
current = resolve19(current, part);
|
|
223279
|
+
if ((await lstat3(current)).isSymbolicLink()) return void 0;
|
|
223280
|
+
}
|
|
223281
|
+
const handle30 = await open6(current, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
223282
|
+
try {
|
|
223283
|
+
const stat22 = await handle30.stat();
|
|
223284
|
+
if (!stat22.isFile() || stat22.size > 256e3) return void 0;
|
|
223285
|
+
const buffer = Buffer.alloc(256001);
|
|
223286
|
+
const { bytesRead } = await handle30.read(buffer, 0, buffer.length, 0);
|
|
223287
|
+
return bytesRead > 256e3 ? void 0 : buffer.subarray(0, bytesRead).toString("utf8");
|
|
223288
|
+
} finally {
|
|
223289
|
+
await handle30.close();
|
|
223290
|
+
}
|
|
223388
223291
|
} catch {
|
|
223389
223292
|
return void 0;
|
|
223390
223293
|
}
|
|
223391
|
-
try {
|
|
223392
|
-
const info = await handle30.stat();
|
|
223393
|
-
if (!info.isFile() || info.size > MAX_FILE_BYTES) return void 0;
|
|
223394
|
-
return await handle30.readFile("utf8");
|
|
223395
|
-
} finally {
|
|
223396
|
-
await handle30.close();
|
|
223397
|
-
}
|
|
223398
223294
|
}
|
|
223399
|
-
function
|
|
223400
|
-
|
|
223401
|
-
|
|
223402
|
-
|
|
223403
|
-
|
|
223404
|
-
|
|
223295
|
+
async function projectFiles2(root3) {
|
|
223296
|
+
const queue = [""], files2 = [];
|
|
223297
|
+
let entries4 = 0;
|
|
223298
|
+
while (queue.length && entries4 < 2e3 && files2.length < 500) {
|
|
223299
|
+
const dir2 = queue.shift();
|
|
223300
|
+
const children3 = await readdir3(resolve19(root3, dir2), { withFileTypes: true }).catch(() => []);
|
|
223301
|
+
for (const child2 of children3.sort((a, b) => a.name.localeCompare(b.name, "en"))) {
|
|
223302
|
+
if (++entries4 > 2e3 || files2.length >= 500) break;
|
|
223303
|
+
if (child2.name.startsWith(".") || SKIP.has(child2.name) || child2.isSymbolicLink()) continue;
|
|
223304
|
+
const path7 = dir2 ? `${dir2}/${child2.name}` : child2.name;
|
|
223305
|
+
if (child2.isDirectory() && path7.split("/").length < 6) queue.push(path7);
|
|
223306
|
+
else if (child2.isFile() && (SOURCE_FILE.test(child2.name) || MANIFEST_FILE.test(child2.name)) && !/(?:^|\/)(?:test[_.-]|.*[.-](?:test|spec)\.)/.test(path7)) files2.push(path7);
|
|
223307
|
+
}
|
|
223308
|
+
}
|
|
223309
|
+
return files2;
|
|
223405
223310
|
}
|
|
223406
|
-
|
|
223311
|
+
var SKIP, SOURCE_FILE, MANIFEST_FILE;
|
|
223312
|
+
var init_project_files = __esm({
|
|
223313
|
+
"backend/src/kit/project-files.ts"() {
|
|
223314
|
+
"use strict";
|
|
223315
|
+
SKIP = /* @__PURE__ */ new Set(["node_modules", "venv", "site-packages", "__pycache__", "dist", "build", "out", "vendor", "coverage", "scenes", "ancha", "tests", "test", "notebooks"]);
|
|
223316
|
+
SOURCE_FILE = /\.(?:[cm]?[jt]sx?|py)$/i;
|
|
223317
|
+
MANIFEST_FILE = /^(?:package\.json|pyproject\.toml|requirements(?:[-\w]*)\.txt|Pipfile)$/;
|
|
223318
|
+
}
|
|
223319
|
+
});
|
|
223320
|
+
|
|
223321
|
+
// backend/src/kit/start-command.ts
|
|
223322
|
+
function dockerfileCommand(body7) {
|
|
223323
|
+
const last = body7.split(/\r?\n/).filter((line2) => /^\s*CMD\s/i.test(line2)).at(-1)?.replace(/^\s*CMD\s+/i, "").trim();
|
|
223324
|
+
if (!last) return void 0;
|
|
223325
|
+
if (!last.startsWith("[")) return last;
|
|
223407
223326
|
try {
|
|
223408
|
-
const
|
|
223409
|
-
return typeof
|
|
223327
|
+
const parts3 = JSON.parse(last);
|
|
223328
|
+
return Array.isArray(parts3) && parts3.length > 0 && parts3.every((part) => typeof part === "string") ? parts3.map((part) => /^[\w./:=@+-]+$/.test(part) ? part : `'${part.replaceAll("'", "'\\''")}'`).join(" ") : void 0;
|
|
223410
223329
|
} catch {
|
|
223411
223330
|
return void 0;
|
|
223412
223331
|
}
|
|
223413
223332
|
}
|
|
223414
|
-
async function
|
|
223415
|
-
|
|
223416
|
-
|
|
223417
|
-
|
|
223418
|
-
|
|
223419
|
-
|
|
223420
|
-
|
|
223421
|
-
|
|
223333
|
+
async function readmeCommand(candidate, read7) {
|
|
223334
|
+
if (/[;&|<>`$\\]/.test(candidate)) return false;
|
|
223335
|
+
const match3 = /^(?:(?:npx\s+(?:--no-install\s+)?(?:ts-node|tsx|node)|(?:ts-node|tsx|node)|(?:uv|poetry)\s+run(?:\s+python[\d.]*)?|python[\d.]*)\s+)(.+)$/.exec(candidate);
|
|
223336
|
+
if (!match3) return false;
|
|
223337
|
+
const args = match3[1].trim().split(/\s+/);
|
|
223338
|
+
let file3 = args[0];
|
|
223339
|
+
if (file3 === "-m") {
|
|
223340
|
+
const module = args[1];
|
|
223341
|
+
if (!module || !/^[\w.]+$/.test(module) || /^(?:pip|venv|pytest|unittest|ensurepip)(?:\.|$)/.test(module)) return false;
|
|
223342
|
+
file3 = module.replaceAll(".", "/");
|
|
223343
|
+
return await read7(`${file3}.py`) !== void 0 || await read7(`${file3}/__main__.py`) !== void 0;
|
|
223422
223344
|
}
|
|
223345
|
+
file3 = file3.replace(/^(['"])(.*)\1$/, "$2");
|
|
223346
|
+
if (!SOURCE_FILE.test(file3) || /(?:^|\/)(?:test[^/]*|setup\.py|conftest\.py|scripts\/)/.test(file3)) return false;
|
|
223347
|
+
return await read7(file3) !== void 0;
|
|
223423
223348
|
}
|
|
223424
|
-
async function
|
|
223425
|
-
const
|
|
223426
|
-
const
|
|
223427
|
-
|
|
223428
|
-
|
|
223349
|
+
async function inferStartCommand(read7, files2) {
|
|
223350
|
+
const result = (agent, agentSource, agentEvidence) => ({ agent, agentSource, agentEvidence });
|
|
223351
|
+
const pkg = await read7("package.json");
|
|
223352
|
+
if (pkg !== void 0) {
|
|
223353
|
+
try {
|
|
223354
|
+
const manifest2 = JSON.parse(pkg);
|
|
223355
|
+
for (const script of ["start", "dev", "agent"]) {
|
|
223356
|
+
if (typeof manifest2.scripts?.[script] !== "string" || !manifest2.scripts[script].trim()) continue;
|
|
223357
|
+
const manager = typeof manifest2.packageManager === "string" ? /^(pnpm|yarn|bun)@/.exec(manifest2.packageManager)?.[1] ?? "npm" : "npm";
|
|
223358
|
+
return result(`${manager} ${manager === "npm" && script !== "start" || manager === "bun" ? "run " : ""}${script}`, "package.json", `package.json scripts.${script}`);
|
|
223359
|
+
}
|
|
223360
|
+
} catch {
|
|
223361
|
+
}
|
|
223362
|
+
}
|
|
223363
|
+
const procfile = (await read7("Procfile"))?.split(/\r?\n/).map((line2) => /^[\w-]+:\s*(.+)$/.exec(line2)?.[1]?.trim()).find(Boolean);
|
|
223364
|
+
if (procfile) return result(procfile, "Procfile", "Procfile");
|
|
223365
|
+
const pyproject = await read7("pyproject.toml");
|
|
223366
|
+
const scripts = pyproject === void 0 ? void 0 : /^\[project\.scripts\][ \t]*(?:#.*)?\r?\n([\s\S]*?)(?=^\[|$(?![\s\S]))/m.exec(pyproject)?.[1];
|
|
223367
|
+
const names5 = scripts?.split("\n").map((line2) => /^\s*["']?([A-Za-z0-9_.-]+)["']?\s*=\s*["'][\w.]+:[\w.]+["']/.exec(line2)?.[1]).filter((name5) => name5 !== void 0) ?? [];
|
|
223368
|
+
if (names5.length === 1) return result(names5[0], "pyproject.toml", `pyproject.toml [project.scripts] ${names5[0]}`);
|
|
223369
|
+
for (const name5 of ["README.md", "README.MD", "readme.md", "README.rst", "README"]) {
|
|
223370
|
+
const body7 = await read7(name5);
|
|
223371
|
+
if (body7 === void 0) continue;
|
|
223372
|
+
let fence = false;
|
|
223373
|
+
const candidates2 = [];
|
|
223374
|
+
for (const [index, line2] of body7.split(/\r?\n/).entries()) {
|
|
223375
|
+
if (/^\s*(?:```|~~~)/.test(line2)) {
|
|
223376
|
+
fence = !fence;
|
|
223377
|
+
continue;
|
|
223378
|
+
}
|
|
223379
|
+
const snippets = fence || /^ {4}\S/.test(line2) ? [line2.trim().replace(/^\$\s+/, "")] : [...line2.matchAll(/`([^`\n]+)`/g)].map((match3) => match3[1]);
|
|
223380
|
+
for (const snippet of snippets) {
|
|
223381
|
+
const command = snippet.replace(/\s+#.*$/, "").trim();
|
|
223382
|
+
if (await readmeCommand(command, read7)) candidates2.push({ command, line: index + 1 });
|
|
223383
|
+
}
|
|
223384
|
+
}
|
|
223385
|
+
const first2 = candidates2[0];
|
|
223386
|
+
if (first2) return result(first2.command, "README", `${name5}:${first2.line}`);
|
|
223387
|
+
}
|
|
223388
|
+
const dockerfile = await read7("Dockerfile");
|
|
223389
|
+
const cmd = dockerfile === void 0 ? void 0 : dockerfileCommand(dockerfile);
|
|
223390
|
+
if (cmd) return result(cmd, "Dockerfile", "Dockerfile CMD");
|
|
223391
|
+
const graphText = await read7("langgraph.json");
|
|
223392
|
+
if (graphText !== void 0) {
|
|
223393
|
+
try {
|
|
223394
|
+
const graphs = JSON.parse(graphText).graphs;
|
|
223395
|
+
if (graphs && typeof graphs === "object" && !Array.isArray(graphs)) {
|
|
223396
|
+
for (const value5 of Object.values(graphs)) {
|
|
223397
|
+
if (typeof value5 !== "string" || !/^[\w./-]+:\w+$/.test(value5)) continue;
|
|
223398
|
+
const path7 = value5.split(":")[0];
|
|
223399
|
+
const target6 = path7.endsWith(".py") ? path7 : `${path7.replaceAll(".", "/")}.py`;
|
|
223400
|
+
if (await read7(target6) !== void 0 || await read7(`src/${target6}`) !== void 0) return { agent: null, agentSource: "unconfigured" };
|
|
223401
|
+
}
|
|
223402
|
+
}
|
|
223403
|
+
} catch {
|
|
223404
|
+
}
|
|
223405
|
+
}
|
|
223406
|
+
const candidates = files2.filter((file3) => /^(?:src\/)?(?:main|app|agent|index)\.(?:[cm]?[jt]s|py)$/.test(file3));
|
|
223407
|
+
const runnable = [];
|
|
223408
|
+
for (const file3 of files2.filter((file4) => /^(?:src\/)?[^/]+\.py$/.test(file4) && !/(?:^|\/)(?:setup|conftest)\.py$/.test(file4))) {
|
|
223409
|
+
if (/^\s*if\s+__name__\s*==\s*['"]__main__['"]\s*:/m.test(await read7(file3) ?? "")) runnable.push(file3);
|
|
223410
|
+
}
|
|
223411
|
+
const choices = runnable.length ? [...runnable, ...candidates.filter((file3) => !file3.endsWith(".py"))] : candidates;
|
|
223412
|
+
if (choices.length === 1) {
|
|
223413
|
+
const file3 = choices[0];
|
|
223414
|
+
const runtime2 = file3.endsWith(".py") ? "python" : /\.(?:[cm]?ts)$/.test(file3) ? "npx tsx" : "node";
|
|
223415
|
+
return result(`${runtime2} ${file3}`, "entry-file", file3);
|
|
223416
|
+
}
|
|
223417
|
+
return { agent: null, agentSource: "unconfigured" };
|
|
223429
223418
|
}
|
|
223430
|
-
|
|
223431
|
-
|
|
223419
|
+
var init_start_command = __esm({
|
|
223420
|
+
"backend/src/kit/start-command.ts"() {
|
|
223421
|
+
"use strict";
|
|
223422
|
+
init_project_files();
|
|
223423
|
+
}
|
|
223424
|
+
});
|
|
223425
|
+
|
|
223426
|
+
// backend/src/kit/function-tools.ts
|
|
223427
|
+
function tokens3(text30, python) {
|
|
223428
|
+
const pattern = python ? /#[^\n]*|"""[\s\S]*?"""|'''[\s\S]*?'''|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[A-Za-z_$][\w$]*|[^\s]/g : /\/\/[^\n]*|\/\*[\s\S]*?\*\/|`(?:\\.|[^`\\])*`|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[A-Za-z_$][\w$]*|[^\s]/g;
|
|
223432
223429
|
const out = [];
|
|
223433
|
-
let
|
|
223434
|
-
for (
|
|
223435
|
-
|
|
223436
|
-
|
|
223437
|
-
|
|
223438
|
-
|
|
223439
|
-
|
|
223440
|
-
|
|
223441
|
-
|
|
223442
|
-
|
|
223443
|
-
|
|
223444
|
-
|
|
223430
|
+
let line2 = 1, offset18 = 0;
|
|
223431
|
+
for (const match3 of text30.matchAll(pattern)) {
|
|
223432
|
+
line2 += text30.slice(offset18, match3.index).split("\n").length - 1;
|
|
223433
|
+
const value5 = match3[0];
|
|
223434
|
+
if (!(python ? /^(?:#|"""|''')/ : /^(?:\/\/|\/\*|`)/).test(value5)) out.push({ value: value5, line: line2 });
|
|
223435
|
+
line2 += value5.split("\n").length - 1;
|
|
223436
|
+
offset18 = match3.index + value5.length;
|
|
223437
|
+
}
|
|
223438
|
+
return out;
|
|
223439
|
+
}
|
|
223440
|
+
function functionToolsIn(text30, source) {
|
|
223441
|
+
if (!/tool|create_?react_?agent/i.test(text30)) return [];
|
|
223442
|
+
const python = source.endsWith(".py"), ts3 = tokens3(text30, python), v = ts3.map((t) => t.value);
|
|
223443
|
+
const result = /* @__PURE__ */ new Map();
|
|
223444
|
+
const add = (name5, symbol2, at4) => {
|
|
223445
|
+
if (name5 && /^[A-Za-z_][\w.-]{0,127}$/.test(name5)) result.set(name5, { name: name5, symbol: symbol2, source, line: ts3[at4].line, language: python ? "py" : "ts" });
|
|
223446
|
+
};
|
|
223447
|
+
const end = (start2) => {
|
|
223448
|
+
const stack = [], pairs = { "(": ")", "[": "]", "{": "}" };
|
|
223449
|
+
for (let i = start2; i < v.length; i++) {
|
|
223450
|
+
if (pairs[v[i]]) stack.push(pairs[v[i]]);
|
|
223451
|
+
else if (v[i] === stack.at(-1) && stack.pop() && !stack.length) return i;
|
|
223445
223452
|
}
|
|
223446
|
-
|
|
223447
|
-
|
|
223448
|
-
|
|
223449
|
-
|
|
223453
|
+
return start2;
|
|
223454
|
+
};
|
|
223455
|
+
const aliases = /* @__PURE__ */ new Set(["tool", "function_tool", "wrapTool"]);
|
|
223456
|
+
for (let i = 0; i < v.length; i++) if (aliases.has(v[i]) && v[i + 1] === "as" && identifier4(v[i + 2])) aliases.add(v[i + 2]);
|
|
223457
|
+
const definitions3 = /* @__PURE__ */ new Map();
|
|
223458
|
+
for (let i = 0; i < v.length; i++) {
|
|
223459
|
+
if (python && v[i] === "@") {
|
|
223460
|
+
let decorator = i + 1;
|
|
223461
|
+
while (v[decorator + 1] === ".") decorator += 2;
|
|
223462
|
+
if (!aliases.has(v[decorator])) continue;
|
|
223463
|
+
const close2 = v[decorator + 1] === "(" ? end(decorator + 1) : decorator;
|
|
223464
|
+
let d = close2 + 1;
|
|
223465
|
+
while (v[d] === "@") {
|
|
223466
|
+
d++;
|
|
223467
|
+
while (d < v.length && v[d] !== "def" && v[d] !== "async") d++;
|
|
223468
|
+
}
|
|
223469
|
+
if (v[d] === "async") d++;
|
|
223470
|
+
if (v[d] !== "def") continue;
|
|
223471
|
+
const symbol3 = v[d + 1];
|
|
223472
|
+
const args2 = v.slice(decorator + 2, close2);
|
|
223473
|
+
const named6 = args2.findIndex((x) => x === "name" || x === "name_override");
|
|
223474
|
+
const name6 = literal2(args2[named6 >= 0 ? named6 + 2 : 0]) ?? symbol3;
|
|
223475
|
+
definitions3.set(symbol3, name6);
|
|
223476
|
+
add(name6, symbol3, i);
|
|
223450
223477
|
}
|
|
223451
|
-
if ([
|
|
223452
|
-
|
|
223453
|
-
|
|
223454
|
-
|
|
223455
|
-
|
|
223478
|
+
if (v[i] !== "=" || !identifier4(v[i - 1])) continue;
|
|
223479
|
+
const symbol2 = v[i - 1];
|
|
223480
|
+
let c = i + 1;
|
|
223481
|
+
while (v[c + 1] === ".") c += 2;
|
|
223482
|
+
if (!(aliases.has(v[c]) || v[c] === "StructuredTool" || v[c] === "from_function") || v[c + 1] !== "(") continue;
|
|
223483
|
+
const close = end(c + 1), args = v.slice(c + 2, close);
|
|
223484
|
+
const named5 = args.findIndex((x) => x === "name" || x === "name_override");
|
|
223485
|
+
const name5 = literal2(args[named5 + 2]) ?? (v[c] === "wrapTool" ? literal2(args[0]) : void 0) ?? symbol2;
|
|
223486
|
+
definitions3.set(symbol2, name5);
|
|
223487
|
+
add(name5, symbol2, i - 1);
|
|
223488
|
+
}
|
|
223489
|
+
const lists2 = /* @__PURE__ */ new Map();
|
|
223490
|
+
for (let i = 0; i < v.length; i++) if (identifier4(v[i]) && v[i + 1] === "=" && ["[", "{"].includes(v[i + 2])) lists2.set(v[i], i + 2);
|
|
223491
|
+
const inspectList = (at4) => {
|
|
223492
|
+
const start2 = lists2.get(v[at4]) ?? at4;
|
|
223493
|
+
if (!["[", "{"].includes(v[start2])) return;
|
|
223494
|
+
const stop = end(start2), object23 = v[start2] === "{";
|
|
223495
|
+
const collection2 = v[start2 - 1] === "=" && identifier4(v[start2 - 2]) ? v[start2 - 2] : void 0;
|
|
223496
|
+
for (let j = start2 + 1; j < stop; ) {
|
|
223497
|
+
const symbol2 = v[j];
|
|
223498
|
+
if (identifier4(symbol2) || literal2(symbol2)) {
|
|
223499
|
+
const key4 = literal2(symbol2) ?? symbol2;
|
|
223500
|
+
const ref22 = object23 && v[j + 1] === ":" ? v[j + 2] : symbol2;
|
|
223501
|
+
const name5 = object23 ? key4 : definitions3.get(ref22) ?? ref22;
|
|
223502
|
+
add(name5, ref22, j);
|
|
223503
|
+
const tool = result.get(name5);
|
|
223504
|
+
if (tool && collection2) tool.collection = collection2;
|
|
223505
|
+
if (tool && object23 && !collection2) tool.inlineObject = true;
|
|
223506
|
+
}
|
|
223507
|
+
j++;
|
|
223508
|
+
while (j < stop && v[j] !== ",") {
|
|
223509
|
+
if (["(", "[", "{"].includes(v[j])) j = end(j);
|
|
223510
|
+
j++;
|
|
223456
223511
|
}
|
|
223457
|
-
|
|
223458
|
-
if (body7 !== void 0) out.push(...await entries3(p2, body7, dir2, depth + 1));
|
|
223459
|
-
continue;
|
|
223460
|
-
}
|
|
223461
|
-
if (/^python(?:\d+(?:\.\d+)*)?$/.test(program2) || program2 === "py") {
|
|
223462
|
-
out.push(...await scriptEntry(p2, dir2, rest2, true));
|
|
223463
|
-
continue;
|
|
223512
|
+
j++;
|
|
223464
223513
|
}
|
|
223465
|
-
|
|
223466
|
-
|
|
223467
|
-
|
|
223514
|
+
};
|
|
223515
|
+
for (let i = 0; i < v.length; i++) {
|
|
223516
|
+
if (["tools", "functions"].includes(v[i]) && ["=", ":"].includes(v[i + 1])) {
|
|
223517
|
+
let start2 = i + 2;
|
|
223518
|
+
if (v[start2] === "ancha" && v[start2 + 1] === ".") start2 += 2;
|
|
223519
|
+
if (["wrap_tools", "wrapTools"].includes(v[start2])) start2 += 2;
|
|
223520
|
+
inspectList(start2);
|
|
223468
223521
|
}
|
|
223469
|
-
|
|
223470
|
-
if (
|
|
223471
|
-
const
|
|
223472
|
-
|
|
223473
|
-
|
|
223474
|
-
|
|
223475
|
-
|
|
223522
|
+
if (["bind_tools", "bindTools", "wrap_tools", "wrapTools"].includes(v[i]) && v[i + 1] === "(") inspectList(i + 2);
|
|
223523
|
+
if (["create_react_agent", "createReactAgent"].includes(v[i]) && v[i + 1] === "(") {
|
|
223524
|
+
const stop = end(i + 1);
|
|
223525
|
+
for (let j = i + 2; j < stop; j++) {
|
|
223526
|
+
if (v[j] === ",") {
|
|
223527
|
+
inspectList(j + 1);
|
|
223528
|
+
break;
|
|
223529
|
+
}
|
|
223530
|
+
if (["(", "[", "{"].includes(v[j])) j = end(j);
|
|
223476
223531
|
}
|
|
223477
|
-
continue;
|
|
223478
|
-
}
|
|
223479
|
-
const bin = await packageBin(p2, dir2, program2);
|
|
223480
|
-
if (bin !== void 0) {
|
|
223481
|
-
out.push(bin);
|
|
223482
|
-
continue;
|
|
223483
223532
|
}
|
|
223484
|
-
out.push(...await pyprojectScript(p2, dir2, program2));
|
|
223485
223533
|
}
|
|
223486
|
-
return
|
|
223534
|
+
return [...result.values()];
|
|
223487
223535
|
}
|
|
223488
|
-
|
|
223489
|
-
|
|
223490
|
-
|
|
223491
|
-
|
|
223492
|
-
|
|
223493
|
-
|
|
223494
|
-
|
|
223495
|
-
}
|
|
223496
|
-
|
|
223497
|
-
if (python && args[i] === "-c") return [];
|
|
223498
|
-
if (!python && (args[i] === "-e" || args[i] === "--eval" || args[i] === "-p" || args[i] === "--print")) return [];
|
|
223499
|
-
if (values2.has(args[i].split("=")[0]) && !args[i].includes("=")) i++;
|
|
223500
|
-
}
|
|
223501
|
-
const entry3 = args[i];
|
|
223502
|
-
if (entry3 === void 0 || /^[a-z][a-z\d+.-]*:/i.test(entry3)) return [];
|
|
223503
|
-
const path7 = join23(dir2, entry3);
|
|
223504
|
-
if (await p2.exists(path7)) return [path7];
|
|
223505
|
-
const built3 = /^(?:\.\/)?(?:dist|build|out|lib)\/(.+)\.(?:c|m)?js$/.exec(entry3)?.[1];
|
|
223506
|
-
return built3 === void 0 ? [path7] : [path7, ...[".ts", ".mts", ".tsx"].map((ext) => join23(dir2, "src", `${built3}${ext}`))];
|
|
223536
|
+
function functionToolWiring(tools2) {
|
|
223537
|
+
return ["py", "ts"].flatMap((language) => {
|
|
223538
|
+
const found = tools2.filter((t) => t.language === language);
|
|
223539
|
+
if (!found.length) return [];
|
|
223540
|
+
const names5 = [...new Set(found.map((t) => t.symbol))].filter(identifier4).join(", ");
|
|
223541
|
+
const collections3 = [...new Set(found.map((t) => t.collection))];
|
|
223542
|
+
const js = collections3.length === 1 && collections3[0] ? `pass wrapTools(${collections3[0]}) as the framework's tools collection` : found.some((t) => t.inlineObject) ? "wrap the existing tools object in place: tools: wrapTools({ ... })" : `pass wrapTools([${names5}]) as the framework's tools list (for an AI SDK tools object, use wrapTools({${names5}}))`;
|
|
223543
|
+
return [language === "py" ? `Add import ancha; pass ancha.wrap_tools([${names5}]) as the framework's tools list, then call ancha.entry(run) at the task entrypoint.` : `Add import { wrapTools, entry } from '@ancha-labs/tools'; ${js}, then call await entry(run) at the task entrypoint.`];
|
|
223544
|
+
});
|
|
223507
223545
|
}
|
|
223508
|
-
|
|
223509
|
-
|
|
223510
|
-
|
|
223511
|
-
|
|
223512
|
-
|
|
223513
|
-
|
|
223546
|
+
var identifier4, literal2;
|
|
223547
|
+
var init_function_tools = __esm({
|
|
223548
|
+
"backend/src/kit/function-tools.ts"() {
|
|
223549
|
+
"use strict";
|
|
223550
|
+
identifier4 = (value5 = "") => /^[A-Za-z_$][\w$]*$/.test(value5);
|
|
223551
|
+
literal2 = (value5 = "") => /^["'][A-Za-z_][\w.-]{0,127}["']$/.test(value5) ? value5.slice(1, -1) : void 0;
|
|
223514
223552
|
}
|
|
223515
|
-
|
|
223553
|
+
});
|
|
223554
|
+
|
|
223555
|
+
// backend/src/kit/tool-signals.ts
|
|
223556
|
+
function toolsForSdk(name5, imported2 = false) {
|
|
223557
|
+
const value5 = normalize3(name5);
|
|
223558
|
+
return SUPPORTED_TWINS.filter((twin) => TOOL_SDKS[twin].some((alias) => {
|
|
223559
|
+
const key4 = normalize3(alias);
|
|
223560
|
+
return key4.endsWith("/*") ? value5.startsWith(key4.slice(0, -1)) : value5 === key4 || imported2 && (value5.startsWith(`${key4}.`) || value5.startsWith(`${key4}/`));
|
|
223561
|
+
}));
|
|
223516
223562
|
}
|
|
223517
|
-
|
|
223518
|
-
const
|
|
223519
|
-
const
|
|
223520
|
-
|
|
223521
|
-
const keep2 = (path7) => {
|
|
223522
|
-
const parts3 = path7.split(/[\\/]/);
|
|
223523
|
-
return !parts3.some((part) => SKIP_DIRS.has(part)) && (underBuild || !parts3.some((part) => BUILD_DIRS.has(part)));
|
|
223563
|
+
function sourceToolSignals(text30, python) {
|
|
223564
|
+
const found = /* @__PURE__ */ new Map();
|
|
223565
|
+
const add = (name5) => {
|
|
223566
|
+
for (const twin of toolsForSdk(name5, true)) if (!found.has(twin)) found.set(twin, name5);
|
|
223524
223567
|
};
|
|
223525
|
-
|
|
223526
|
-
|
|
223527
|
-
|
|
223528
|
-
|
|
223529
|
-
|
|
223530
|
-
|
|
223568
|
+
const body7 = text30.replace(/^\s*(?:#|\/\/).*$/gm, "");
|
|
223569
|
+
if (python) {
|
|
223570
|
+
for (const match3 of body7.matchAll(/^\s*from\s+([\w.]+)\s+import\b/gm)) add(match3[1]);
|
|
223571
|
+
for (const match3 of body7.matchAll(/^\s*import\s+([^\n;]+)/gm)) {
|
|
223572
|
+
for (const item2 of match3[1].split(",")) {
|
|
223573
|
+
const name5 = /^\s*([\w.]+)/.exec(item2)?.[1];
|
|
223574
|
+
if (name5) add(name5);
|
|
223531
223575
|
}
|
|
223532
|
-
|
|
223576
|
+
}
|
|
223577
|
+
} else {
|
|
223578
|
+
for (const match3 of body7.matchAll(/(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)(['"])([@\w][\w@./-]*)\1/g)) add(match3[2]);
|
|
223579
|
+
}
|
|
223580
|
+
for (const twin of SUPPORTED_TWINS) if (!found.has(twin) && HOSTS[twin]?.test(body7)) found.set(twin, `${twin} API endpoint`);
|
|
223581
|
+
if (/\bgoogleapiclient\b/.test(body7)) {
|
|
223582
|
+
for (const [service, twin] of [["gmail", "gmail"], ["drive", "google-drive"], ["calendar", "google-calendar"]]) {
|
|
223583
|
+
if (new RegExp(`\\bbuild\\(\\s*['"]${service}['"]`).test(body7)) found.set(twin, `googleapiclient ${service}`);
|
|
223584
|
+
}
|
|
223585
|
+
}
|
|
223586
|
+
if (/\bboto3\b/.test(body7) && /\b(?:client|resource)\(\s*['"]s3['"]/.test(body7)) found.set("amazon-s3", "boto3 s3");
|
|
223587
|
+
return found;
|
|
223588
|
+
}
|
|
223589
|
+
var TOOL_SDKS, normalize3, HOSTS;
|
|
223590
|
+
var init_tool_signals = __esm({
|
|
223591
|
+
"backend/src/kit/tool-signals.ts"() {
|
|
223592
|
+
"use strict";
|
|
223593
|
+
init_src();
|
|
223594
|
+
TOOL_SDKS = {
|
|
223595
|
+
slack: ["@slack/*", "slack-sdk", "slack-bolt"],
|
|
223596
|
+
github: ["@octokit/*", "octokit", "pygithub", "github"],
|
|
223597
|
+
datadog: ["@datadog/datadog-api-client", "datadog-api-client", "datadog"],
|
|
223598
|
+
pagerduty: ["@pagerduty/pdjs", "pdpyras", "pagerduty"],
|
|
223599
|
+
"linkedin-ads": ["linkedin-api-client"],
|
|
223600
|
+
salesforce: ["jsforce", "simple-salesforce"],
|
|
223601
|
+
gong: [],
|
|
223602
|
+
hubspot: ["@hubspot/api-client", "hubspot-api-client", "hubspot"],
|
|
223603
|
+
ga4: ["@google-analytics/data", "google-analytics-data", "google.analytics.data"],
|
|
223604
|
+
"google-ads": ["google-ads", "google-ads-api", "google.ads.googleads"],
|
|
223605
|
+
"chatgpt-ads": [],
|
|
223606
|
+
"open-meteo": ["openmeteo-requests", "openmeteo"],
|
|
223607
|
+
gmail: ["@googleapis/gmail", "googleapis"],
|
|
223608
|
+
"google-drive": ["@googleapis/drive", "googleapis", "pydrive", "pydrive2"],
|
|
223609
|
+
"google-calendar": ["@googleapis/calendar", "googleapis"],
|
|
223610
|
+
"amazon-s3": ["@aws-sdk/client-s3", "s3fs", "minio"],
|
|
223611
|
+
linear: ["@linear/sdk"],
|
|
223612
|
+
okta: ["@okta/okta-sdk-nodejs", "okta"],
|
|
223613
|
+
stripe: ["stripe"],
|
|
223614
|
+
clerk: ["@clerk/backend", "clerk-backend-api"],
|
|
223615
|
+
"better-stack": ["@logtail/node", "logtail-python"],
|
|
223616
|
+
notion: ["@notionhq/client", "notion-client"],
|
|
223617
|
+
attio: ["attio"],
|
|
223618
|
+
dropbox: ["dropbox"],
|
|
223619
|
+
resend: ["resend"],
|
|
223620
|
+
"microsoft-word": ["@microsoft/microsoft-graph-client", "msgraph-sdk", "msgraph"],
|
|
223621
|
+
outlook: ["@microsoft/microsoft-graph-client", "msgraph-sdk", "msgraph"],
|
|
223622
|
+
shopify: ["@shopify/admin-api-client", "@shopify/shopify-api", "shopifyapi", "shopify"],
|
|
223623
|
+
lob: ["@lob/lob-typescript-sdk", "lob"],
|
|
223624
|
+
paypal: ["@paypal/agent-toolkit", "@paypal/paypal-server-sdk", "@paypal/checkout-server-sdk", "paypal-rest-sdk", "paypalrestsdk", "paypalserversdk", "paypalcheckoutsdk", "paypal-server-sdk", "paypal-checkout-serversdk"],
|
|
223625
|
+
jira: ["jira", "jira-client", "jira.js", "atlassian-python-api", "atlassian"],
|
|
223626
|
+
kalshi: ["kalshi-typescript", "kalshi-python", "kalshi-python-sync", "kalshi-python-async"],
|
|
223627
|
+
intercom: ["intercom-client", "python-intercom", "intercom"],
|
|
223628
|
+
twilio: ["twilio"],
|
|
223629
|
+
zendesk: ["node-zendesk", "zenpy", "zendesk"],
|
|
223630
|
+
asana: ["asana"],
|
|
223631
|
+
discord: ["discord.js", "discord-py", "discord"],
|
|
223632
|
+
sentry: ["@sentry/*", "sentry-sdk"],
|
|
223633
|
+
airtable: ["airtable", "pyairtable"],
|
|
223634
|
+
netsuite: ["netsuite", "netsuite-api", "netsuitesdk"],
|
|
223635
|
+
"carrier-portal": []
|
|
223533
223636
|
};
|
|
223534
|
-
|
|
223535
|
-
|
|
223536
|
-
|
|
223537
|
-
|
|
223538
|
-
|
|
223539
|
-
|
|
223540
|
-
|
|
223637
|
+
normalize3 = (name5) => name5.toLowerCase().replaceAll("_", "-");
|
|
223638
|
+
HOSTS = {
|
|
223639
|
+
slack: /\bslack\.com\/api\b/,
|
|
223640
|
+
github: /\bapi\.github\.com\b/,
|
|
223641
|
+
jira: /\b[\w-]+\.atlassian\.net\b|\/rest\/(?:api\/(?:2|3|latest)|agile\/1\.0)\//,
|
|
223642
|
+
paypal: /\bapi(?:-m)?\.(?:sandbox\.)?paypal\.com\b/,
|
|
223643
|
+
datadog: /\bapi\.(?:[\w-]+\.)?datadoghq\.(?:com|eu)\b/,
|
|
223644
|
+
pagerduty: /\bapi\.pagerduty\.com\b/,
|
|
223645
|
+
"linkedin-ads": /\bapi\.linkedin\.com\/(?:rest|v2)\/(?:ad|campaign)/,
|
|
223646
|
+
salesforce: /\b[\w.-]+\.salesforce\.com\b/,
|
|
223647
|
+
gong: /\bapi\.gong\.io\b/,
|
|
223648
|
+
hubspot: /\bapi\.hubapi\.com\b/,
|
|
223649
|
+
ga4: /\banalyticsdata\.googleapis\.com\b/,
|
|
223650
|
+
"google-ads": /\bgoogleads\.googleapis\.com\b/,
|
|
223651
|
+
"open-meteo": /\bapi\.open-meteo\.com\b/,
|
|
223652
|
+
"google-drive": /\b(?:www\.)?googleapis\.com\/drive\b/,
|
|
223653
|
+
gmail: /\bgmail\.googleapis\.com\b|\bwww\.googleapis\.com\/gmail\b/,
|
|
223654
|
+
"google-calendar": /\bwww\.googleapis\.com\/calendar\b/,
|
|
223655
|
+
"amazon-s3": /\bs3(?:[.-][\w-]+)?\.amazonaws\.com\b/,
|
|
223656
|
+
linear: /\bapi\.linear\.app\b/,
|
|
223657
|
+
okta: /\b[\w-]+\.okta\.com\b/,
|
|
223658
|
+
stripe: /\bapi\.stripe\.com\b/,
|
|
223659
|
+
clerk: /\bapi\.clerk\.com\b/,
|
|
223660
|
+
"better-stack": /\b(?:uptime|telemetry)\.betterstack\.com\b/,
|
|
223661
|
+
notion: /\bapi\.notion\.com\b/,
|
|
223662
|
+
attio: /\bapi\.attio\.com\b/,
|
|
223663
|
+
dropbox: /\b(?:api|content)\.dropboxapi\.com\b/,
|
|
223664
|
+
resend: /\bapi\.resend\.com\b/,
|
|
223665
|
+
outlook: /\bgraph\.microsoft\.com\b/,
|
|
223666
|
+
"microsoft-word": /\bgraph\.microsoft\.com\b/,
|
|
223667
|
+
shopify: /\b[\w-]+\.myshopify\.com\b/,
|
|
223668
|
+
lob: /\bapi\.lob\.com\b/,
|
|
223669
|
+
kalshi: /\b(?:api\.elections|trading-api)\.kalshi\.com\b/,
|
|
223670
|
+
intercom: /\bapi\.intercom\.io\b/,
|
|
223671
|
+
zendesk: /\b[\w-]+\.zendesk\.com\b/,
|
|
223672
|
+
twilio: /\bapi\.twilio\.com\b/,
|
|
223673
|
+
asana: /\bapp\.asana\.com\/api\b/,
|
|
223674
|
+
discord: /\bdiscord(?:app)?\.com\/api\b/,
|
|
223675
|
+
sentry: /\bsentry\.io\/api\b/,
|
|
223676
|
+
airtable: /\bapi\.airtable\.com\b/,
|
|
223677
|
+
netsuite: /\b[\w.-]+\.suitetalk\.api\.netsuite\.com\b/
|
|
223678
|
+
};
|
|
223679
|
+
}
|
|
223680
|
+
});
|
|
223681
|
+
|
|
223682
|
+
// backend/src/kit/detect.ts
|
|
223683
|
+
function pythonDependencies(body7, file3) {
|
|
223684
|
+
if (/requirements[^/]*\.txt$/.test(file3)) return body7.split(/\r?\n/).flatMap((line2) => /^\s*([A-Za-z0-9][\w.-]*)(?:\[|\s*[<>=!~;@]|\s*$)/.exec(line2)?.[1] ?? []);
|
|
223685
|
+
const names5 = [];
|
|
223686
|
+
let section2 = "", dependencies = false;
|
|
223687
|
+
for (const raw3 of body7.split(/\r?\n/)) {
|
|
223688
|
+
const line2 = raw3.replace(/\s+#.*$/, "");
|
|
223689
|
+
const header4 = /^\s*\[([^\]]+)\]/.exec(line2);
|
|
223690
|
+
if (header4) {
|
|
223691
|
+
section2 = header4[1];
|
|
223692
|
+
dependencies = false;
|
|
223693
|
+
continue;
|
|
223694
|
+
}
|
|
223695
|
+
const map2 = /^(?:tool\.poetry(?:\.group\.[\w-]+)?\.(?:dev-)?dependencies|packages|dev-packages)$/.test(section2);
|
|
223696
|
+
if (map2) {
|
|
223697
|
+
const name5 = /^\s*["']?([\w.-]+)["']?\s*=/.exec(line2)?.[1];
|
|
223698
|
+
if (name5 && name5 !== "python") names5.push(name5);
|
|
223699
|
+
continue;
|
|
223700
|
+
}
|
|
223701
|
+
const array3 = section2 === "project.optional-dependencies" || section2 === "dependency-groups" || section2 === "project" && (/^\s*dependencies\s*=/.test(line2) || dependencies);
|
|
223702
|
+
if (!array3) continue;
|
|
223703
|
+
for (const match3 of line2.matchAll(/["']([a-zA-Z0-9][\w.-]*)(?:\[[^\]]*\])?(?:[ <>=!~;@][^"']*)?["']/g)) names5.push(match3[1]);
|
|
223704
|
+
dependencies = !/\]\s*,?\s*$/.test(line2);
|
|
223705
|
+
}
|
|
223706
|
+
return names5;
|
|
223707
|
+
}
|
|
223708
|
+
async function detectProject(cwd, agent) {
|
|
223709
|
+
if (agent !== void 0 && agent.trim() === "") throw new AnchaError("USAGE", "--agent must be a non-empty command", { hint: 'e.g. --agent "node agent.mjs"' });
|
|
223710
|
+
const evidence2 = [];
|
|
223711
|
+
const found = /* @__PURE__ */ new Map();
|
|
223712
|
+
const files2 = await projectFiles2(cwd);
|
|
223713
|
+
const read7 = (name5) => readProjectFile(cwd, name5);
|
|
223714
|
+
let node5 = false, python = false;
|
|
223715
|
+
for (const name5 of files2.filter((name6) => MANIFEST_FILE.test(name6.split("/").at(-1)))) {
|
|
223716
|
+
const body7 = await read7(name5);
|
|
223717
|
+
if (body7 === void 0) continue;
|
|
223718
|
+
evidence2.push(name5);
|
|
223719
|
+
let dependencies = [];
|
|
223720
|
+
if (name5.endsWith("package.json")) {
|
|
223721
|
+
node5 = true;
|
|
223722
|
+
try {
|
|
223723
|
+
const manifest2 = JSON.parse(body7);
|
|
223724
|
+
dependencies = [...Object.keys(manifest2.dependencies ?? {}), ...Object.keys(manifest2.devDependencies ?? {}), ...Object.keys(manifest2.optionalDependencies ?? {})];
|
|
223725
|
+
} catch {
|
|
223726
|
+
evidence2.push("package.json could not be parsed; dependency detection incomplete");
|
|
223541
223727
|
}
|
|
223728
|
+
} else {
|
|
223729
|
+
python = true;
|
|
223730
|
+
dependencies = pythonDependencies(body7, name5);
|
|
223542
223731
|
}
|
|
223543
|
-
for (const
|
|
223544
|
-
for (const module of match3[1].split(",").map((word2) => word2.trim())) for (const base4 of [from, ".", "src"]) if (await tryModule(base4, module)) break;
|
|
223545
|
-
}
|
|
223546
|
-
return out;
|
|
223732
|
+
for (const dependency of dependencies) for (const twin of toolsForSdk(dependency)) if (!found.has(twin)) found.set(twin, `${dependency.toLowerCase()} in ${name5}`);
|
|
223547
223733
|
}
|
|
223548
|
-
|
|
223549
|
-
|
|
223550
|
-
|
|
223551
|
-
|
|
223552
|
-
|
|
223553
|
-
|
|
223554
|
-
|
|
223555
|
-
|
|
223556
|
-
|
|
223734
|
+
let sourceNode = false, sourcePython = false;
|
|
223735
|
+
const apps = [];
|
|
223736
|
+
const functions = /* @__PURE__ */ new Map();
|
|
223737
|
+
for (const name5 of files2.filter((name6) => SOURCE_FILE.test(name6))) {
|
|
223738
|
+
const body7 = await read7(name5);
|
|
223739
|
+
if (body7 === void 0) continue;
|
|
223740
|
+
const app2 = slackAppInSource(body7, name5);
|
|
223741
|
+
if (app2) apps.push(app2);
|
|
223742
|
+
for (const tool of functionToolsIn(body7, name5)) if (!functions.has(tool.name)) functions.set(tool.name, tool);
|
|
223743
|
+
if (name5.endsWith(".py")) sourcePython = true;
|
|
223744
|
+
else sourceNode = true;
|
|
223745
|
+
for (const [twin, signal] of sourceToolSignals(body7, name5.endsWith(".py"))) if (!found.has(twin)) found.set(twin, `${signal} in ${name5}`);
|
|
223557
223746
|
}
|
|
223558
|
-
|
|
223559
|
-
|
|
223560
|
-
|
|
223561
|
-
const p2 = project12(resolve19(root3));
|
|
223562
|
-
const maxFiles = options4.maxFiles ?? 200;
|
|
223563
|
-
const normal = (path7) => relative10(p2.root, resolve19(p2.root, path7)).split(sep5).join("/");
|
|
223564
|
-
let queue = command === null ? [] : (await entries3(p2, command)).map(normal);
|
|
223565
|
-
if (!(await Promise.all(queue.map((path7) => p2.exists(path7)))).some(Boolean)) queue = [...queue, ...await fallbackEntries(p2)];
|
|
223566
|
-
const seen = /* @__PURE__ */ new Set(), scanned = [], found = [], variables2 = /* @__PURE__ */ new Map();
|
|
223567
|
-
const order6 = { next: 0 }, marks = { stdin: null, done: null };
|
|
223568
|
-
let native2 = null;
|
|
223569
|
-
while (queue.length && scanned.length < maxFiles) {
|
|
223570
|
-
const file3 = normal(queue.shift());
|
|
223571
|
-
if (seen.has(file3) || !inside(p2.root, resolve19(p2.root, file3))) continue;
|
|
223572
|
-
seen.add(file3);
|
|
223573
|
-
const text30 = await p2.read(file3);
|
|
223574
|
-
if (text30 === void 0) continue;
|
|
223575
|
-
scanned.push(file3);
|
|
223576
|
-
const python = extname(file3) === ".py" || /^#!.*python/.test(text30);
|
|
223577
|
-
const own2 = scanSource(text30, file3, python, found, order6, variables2, marks);
|
|
223578
|
-
if (own2 && !native2) native2 = { name: own2.name, source: file3 };
|
|
223579
|
-
queue.push(...(await imports(p2, file3, text30)).map(normal));
|
|
223747
|
+
if (!node5 && !python) {
|
|
223748
|
+
node5 = sourceNode;
|
|
223749
|
+
python = sourcePython;
|
|
223580
223750
|
}
|
|
223581
|
-
|
|
223582
|
-
}
|
|
223583
|
-
|
|
223584
|
-
|
|
223585
|
-
|
|
223586
|
-
|
|
223587
|
-
const parts3 = new Set(name5.split("_").filter(Boolean));
|
|
223588
|
-
const has4 = (...words9) => words9.some((word2) => parts3.has(word2));
|
|
223589
|
-
const url4 = has4("URL", "URI", "ENDPOINT", "BASE");
|
|
223590
|
-
if (has4("PATH", "FILE", "DIR", "HOST", "DOMAIN", "HOSTNAME", "RESTLET", "RESTLETS", "SCRIPT", "DEPLOY", "DEPLOYMENT", "SOAP", "WSDL")) return void 0;
|
|
223591
|
-
if (has4("MCP")) return has4("TOKEN", "BEARER") ? "mcp_token" : url4 ? "mcp_url" : void 0;
|
|
223592
|
-
if (has4("CONSUMER")) return has4("SECRET") ? "consumer_secret" : has4("KEY", "ID") ? "consumer_key" : void 0;
|
|
223593
|
-
if (has4("TOKEN") && has4("SECRET")) return "token_secret";
|
|
223594
|
-
if (has4("TOKEN") && url4) return "token_url";
|
|
223595
|
-
if (has4("TOKEN") && has4("ID", "KEY")) return "token_id";
|
|
223596
|
-
if (has4("CLIENT")) return has4("SECRET") ? "client_secret" : has4("ID", "KEY") ? "client_id" : void 0;
|
|
223597
|
-
if (has4("CERT", "CERTIFICATE", "KID")) return "certificate_id";
|
|
223598
|
-
if (has4("PRIVATE", "PEM")) return "private_key";
|
|
223599
|
-
if (has4("SUITEQL")) return "suiteql_url";
|
|
223600
|
-
if (has4("RECORD", "RECORDS")) return url4 ? "record_url" : void 0;
|
|
223601
|
-
if (has4("REST") && url4) return "rest_url";
|
|
223602
|
-
if (url4) return "url";
|
|
223603
|
-
if (has4("ACCOUNT", "REALM", "COMPANY")) return "account_id";
|
|
223604
|
-
if (has4("TOKEN", "BEARER")) return "access_token";
|
|
223605
|
-
return void 0;
|
|
223606
|
-
}
|
|
223607
|
-
function netsuiteMappings(variables2) {
|
|
223608
|
-
netsuiteGiven ??= new Set(Object.keys(toolConnectionEnvironment({ netsuite: ANY_SERVICE })));
|
|
223609
|
-
return variables2.filter((name5) => NETSUITE_NAME.test(name5) && !netsuiteGiven.has(name5)).flatMap((name5) => {
|
|
223610
|
-
const field6 = netsuiteField(name5);
|
|
223611
|
-
return field6 === void 0 ? [] : [{ name: name5, value: NETSUITE_VALUE[field6] ?? `{{netsuite.${field6}}}` }];
|
|
223612
|
-
});
|
|
223613
|
-
}
|
|
223614
|
-
function taskWiring(input5, command) {
|
|
223615
|
-
if (input5.via === "env") {
|
|
223616
|
-
const value5 = input5.file ? "{{task_file}}" : "{{task}}";
|
|
223617
|
-
return { input: input5, env: { [input5.name]: value5 }, yaml: `env: { ${input5.name}: "${value5}" }` };
|
|
223751
|
+
if (node5 && python) evidence2.push("mixed Node/Python sources; choose connect --lang explicitly");
|
|
223752
|
+
const start2 = agent === void 0 ? await inferStartCommand(read7, files2) : { agent, agentSource: "explicit" };
|
|
223753
|
+
const slackApp = apps.find((app2) => start2.agent?.includes(app2.file)) ?? (apps.length === 1 ? apps[0] : void 0);
|
|
223754
|
+
if (slackApp && start2.agent === null) {
|
|
223755
|
+
const file3 = slackApp.file;
|
|
223756
|
+
Object.assign(start2, { agent: `${file3.endsWith(".py") ? "python" : /\.ts$/.test(file3) ? "npx tsx" : "node"} '${file3.replaceAll("'", "'\\''")}'`, agentSource: "entry-file", agentEvidence: file3 });
|
|
223618
223757
|
}
|
|
223619
|
-
const
|
|
223620
|
-
|
|
223621
|
-
return { input: input5, command: next2, yaml: `command: ${/^[\w./@+-]/.test(next2) && !/: | #/.test(next2) ? next2 : JSON.stringify(next2)}` };
|
|
223622
|
-
}
|
|
223623
|
-
function mappedTaskInput(agent) {
|
|
223624
|
-
const mapped = Object.entries(agent.env ?? {}).find(([, value5]) => /\{\{\s*task(?:_file)?\s*\}\}/.test(value5));
|
|
223625
|
-
if (mapped) return mapped[0];
|
|
223626
|
-
const command = agent.command ?? "";
|
|
223627
|
-
const flag5 = /(--[\w-]+)(?:\s+|=)["']?\$\{?ANCHA_TASK(?:_FILE)?\b/.exec(command);
|
|
223628
|
-
if (flag5) return flag5[1];
|
|
223629
|
-
return /\$\{?ANCHA_TASK(?:_FILE)?\b/.test(command) ? "ANCHA_TASK" : null;
|
|
223630
|
-
}
|
|
223631
|
-
function unmappedTaskInput(inputs2, agent) {
|
|
223632
|
-
const command = agent.command ?? "";
|
|
223633
|
-
return inputs2.find((input5) => input5.via === "env" ? !Object.hasOwn(agent.env ?? {}, input5.name) : !new RegExp(`(?<![\\w-])${input5.name.replace(/[-]/g, "\\-")}(?![\\w-])`).test(command)) ?? null;
|
|
223758
|
+
const sdks = SUPPORTED_TWINS.filter((twin) => found.has(twin));
|
|
223759
|
+
return { language: node5 === python ? "unknown" : node5 ? "ts" : "py", sdks, sdkSources: Object.fromEntries(sdks.map((twin) => [twin, found.get(twin)])), evidence: evidence2, functionTools: [...functions.values()], ...start2, ...slackApp && { slackApp } };
|
|
223634
223760
|
}
|
|
223635
|
-
var
|
|
223636
|
-
|
|
223637
|
-
"backend/src/kit/task-input.ts"() {
|
|
223761
|
+
var init_detect = __esm({
|
|
223762
|
+
"backend/src/kit/detect.ts"() {
|
|
223638
223763
|
"use strict";
|
|
223764
|
+
init_slack_app2();
|
|
223639
223765
|
init_src();
|
|
223640
|
-
|
|
223641
|
-
|
|
223642
|
-
|
|
223643
|
-
|
|
223644
|
-
NOT_TASK = /* @__PURE__ */ new Set([
|
|
223645
|
-
"SYSTEM",
|
|
223646
|
-
"TEMPLATE",
|
|
223647
|
-
"TEMPLATES",
|
|
223648
|
-
"DIR",
|
|
223649
|
-
"DIRS",
|
|
223650
|
-
"DIRECTORY",
|
|
223651
|
-
"FOLDER",
|
|
223652
|
-
"URL",
|
|
223653
|
-
"URLS",
|
|
223654
|
-
"URI",
|
|
223655
|
-
"HOST",
|
|
223656
|
-
"PORT",
|
|
223657
|
-
"KEY",
|
|
223658
|
-
"KEYS",
|
|
223659
|
-
"TOKEN",
|
|
223660
|
-
"TOKENS",
|
|
223661
|
-
"SECRET",
|
|
223662
|
-
"PASSWORD",
|
|
223663
|
-
"ID",
|
|
223664
|
-
"IDS",
|
|
223665
|
-
"MODEL",
|
|
223666
|
-
"TIMEOUT",
|
|
223667
|
-
"MAX",
|
|
223668
|
-
"MIN",
|
|
223669
|
-
"LIMIT",
|
|
223670
|
-
"COUNT",
|
|
223671
|
-
"SIZE",
|
|
223672
|
-
"TYPE",
|
|
223673
|
-
"TYPES",
|
|
223674
|
-
"FORMAT",
|
|
223675
|
-
"MODE",
|
|
223676
|
-
"QUEUE",
|
|
223677
|
-
"TOPIC",
|
|
223678
|
-
"LOG",
|
|
223679
|
-
"LOGS",
|
|
223680
|
-
"LEVEL",
|
|
223681
|
-
"ENABLED",
|
|
223682
|
-
"DISABLED",
|
|
223683
|
-
"ENABLE",
|
|
223684
|
-
"DISABLE",
|
|
223685
|
-
"DEBUG",
|
|
223686
|
-
"VERSION",
|
|
223687
|
-
"NAME",
|
|
223688
|
-
"RETRIES",
|
|
223689
|
-
"RETRY",
|
|
223690
|
-
"CACHE",
|
|
223691
|
-
"BUCKET",
|
|
223692
|
-
"TABLE",
|
|
223693
|
-
"DB",
|
|
223694
|
-
"WEBHOOK",
|
|
223695
|
-
"CHANNEL",
|
|
223696
|
-
"ARN",
|
|
223697
|
-
"REGION",
|
|
223698
|
-
"PREFIX",
|
|
223699
|
-
"SUFFIX",
|
|
223700
|
-
"SCHEMA",
|
|
223701
|
-
"LANG",
|
|
223702
|
-
"LANGUAGE",
|
|
223703
|
-
"ENCODING",
|
|
223704
|
-
"LENGTH",
|
|
223705
|
-
"LEN",
|
|
223706
|
-
"STATUS",
|
|
223707
|
-
"STATE",
|
|
223708
|
-
"TTL",
|
|
223709
|
-
"INTERVAL",
|
|
223710
|
-
"DELAY",
|
|
223711
|
-
"CONCURRENCY",
|
|
223712
|
-
"WORKERS",
|
|
223713
|
-
"BATCH",
|
|
223714
|
-
"ENDPOINT",
|
|
223715
|
-
"EXAMPLE",
|
|
223716
|
-
"EXAMPLES",
|
|
223717
|
-
"HISTORY",
|
|
223718
|
-
"TEMPERATURE",
|
|
223719
|
-
"COST",
|
|
223720
|
-
"BUDGET",
|
|
223721
|
-
"TRACE",
|
|
223722
|
-
"TRACES",
|
|
223723
|
-
"TRACING",
|
|
223724
|
-
"EVENT",
|
|
223725
|
-
"EVENTS",
|
|
223726
|
-
"QUEUES",
|
|
223727
|
-
"SIGNING",
|
|
223728
|
-
"HEADER",
|
|
223729
|
-
"HEADERS"
|
|
223730
|
-
]);
|
|
223731
|
-
FLAG = /^--(task|prompt|message|input|query|instructions?|request|question)(?:[-_](file|path))?$/;
|
|
223732
|
-
NATIVE_NAMES = /\b(ANCHA_TASK_FILE|ANCHA_TASK|ANCHA_INPUT_JSON)\b/;
|
|
223733
|
-
FLAG_WORDS = /(?<![\w-])--[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*(?![\w-])/gi;
|
|
223734
|
-
lineAt = (text30, index) => text30.slice(0, index).split("\n").length;
|
|
223735
|
-
PYTHON_STDIN = /\bsys\.stdin\b|(?<![\w.])(?<!\bdef\s+)input\s*\(|\bfileinput\.input\s*\(|\bopen\(\s*(?:0\s*[,)]|['"]\/dev\/stdin['"])/;
|
|
223736
|
-
NODE_STDIN = /\bprocess\.stdin\b|\b(?:Deno|Bun)\.stdin\b|\breadFileSync\(\s*(?:0\s*[,)]|['"`]\/dev\/stdin['"`])/;
|
|
223737
|
-
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".venv", "venv", "site-packages", ".git", "__pycache__"]);
|
|
223738
|
-
BUILD_DIRS = /* @__PURE__ */ new Set(["dist", "build", "out", ".next"]);
|
|
223739
|
-
SOURCE_EXT = [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".jsx"];
|
|
223740
|
-
MAX_FILE_BYTES = 1e6;
|
|
223741
|
-
inside = (root3, path7) => {
|
|
223742
|
-
const rel = relative10(root3, path7);
|
|
223743
|
-
return rel !== "" && !rel.startsWith(`..${sep5}`) && rel !== ".." && !isAbsolute7(rel);
|
|
223744
|
-
};
|
|
223745
|
-
pythonModule = (cwd, module) => {
|
|
223746
|
-
const path7 = module.split(".").join("/");
|
|
223747
|
-
return [`${path7}.py`, `${path7}/__main__.py`, `${path7}/__init__.py`, `src/${path7}.py`, `src/${path7}/__main__.py`, `src/${path7}/__init__.py`].map((file3) => join23(cwd, file3));
|
|
223748
|
-
};
|
|
223749
|
-
NODE_VALUE_FLAGS = /* @__PURE__ */ new Set(["--require", "-r", "--import", "--loader", "--experimental-loader", "--tsconfig", "--config", "-c", "--env-file", "--conditions", "-C", "--title", "--inspect-port"]);
|
|
223750
|
-
PYTHON_VALUE_FLAGS = /* @__PURE__ */ new Set(["-W", "-X", "-Q"]);
|
|
223751
|
-
quoteAll = (list18) => list18.map((word2) => /^[\w./:=@+-]+$/.test(word2) ? word2 : `'${word2.replaceAll("'", "'\\''")}'`).join(" ");
|
|
223752
|
-
NETSUITE_NAME = /^(?:NETSUITE|NS)_|NETSUITE|SUITETALK/;
|
|
223753
|
-
NETSUITE_VALUE = { url: "{{netsuite.url}}", rest_url: "{{netsuite.url}}/services/rest" };
|
|
223754
|
-
NPM_SCRIPT2 = /^\s*npm\s+(?:start|test|run(?:-script)?\s+\S+)\s*$/;
|
|
223755
|
-
describeTaskInput = (input5) => input5.via === "env" ? input5.name : `the ${input5.name} flag`;
|
|
223766
|
+
init_start_command();
|
|
223767
|
+
init_project_files();
|
|
223768
|
+
init_function_tools();
|
|
223769
|
+
init_tool_signals();
|
|
223756
223770
|
}
|
|
223757
223771
|
});
|
|
223758
223772
|
|