@akanjs/cli 3.1.1 → 3.1.2-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build-stamp +1 -1
- package/CodeAgent-dyc45f5w.js +11 -0
- package/{CodeAgentRpcHost-9g27hmer.js → CodeAgentRpcHost-6dzfkvsc.js} +1 -1
- package/CodeAgentRpcListener-tcwrdvst.js +182 -0
- package/{CodeTui-h6yz2kvq.js → CodeTui-q55b2zrn.js} +25 -8
- package/TunnelShare-hdq9h1hr.js +14 -0
- package/{agent.command-3r4jsck8.js → agent.command-20zaqe60.js} +18 -15
- package/akanCode.js +8 -7
- package/{application.command-g7xv6ad0.js → application.command-nd0fshsk.js} +11 -11
- package/{applicationBuildRunner-qvjnhr9j.js → applicationBuildRunner-s13x3zqb.js} +10 -9
- package/buildBatch.proc.js +6 -6
- package/{cloud.command-6ebygmhw.js → cloud.command-8kbddsz9.js} +25 -18
- package/cloud.script-hgvvajm3.js +27 -0
- package/code.command-625bg8s8.js +345 -0
- package/{context.command-svdh6b2w.js → context.command-p6haqjay.js} +19 -18
- package/context.runner-rsnqnk9j.js +27 -0
- package/{dependencyScanner-3afj2vt1.js → dependencyScanner-78sq8m4q.js} +2 -2
- package/{fileSys-wzzrntkw.js → fileSys-zpvt5gtf.js} +1 -1
- package/{guideline.command-qwp3tnjx.js → guideline.command-195g0h9a.js} +4 -4
- package/guidelines/agentRule/agentRule.instruction.md +22 -8
- package/guidelines/conventions/rules/auth.md +5 -4
- package/guidelines/conventions/rules/config.md +5 -1
- package/guidelines/conventions/rules/gates.md +2 -1
- package/guidelines/conventions/rules/module.md +1 -1
- package/guidelines/conventions/rules/server.md +8 -3
- package/guidelines/conventions/rules/ssr.md +2 -2
- package/guidelines/conventions/rules/tsx.md +2 -1
- package/guidelines/pageRule/pageRule.instruction.md +4 -4
- package/guidelines/runtimeRule/runtimeRule.instruction.md +35 -25
- package/guidelines/ssrRule/ssrRule.instruction.md +11 -10
- package/guidelines/transportRule/transportRule.instruction.md +5 -4
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +1 -1
- package/incrementalBuilder.proc.js +4 -4
- package/{index-w4k2ragk.js → index-00a7j05x.js} +7 -7
- package/{index-w7q6h97v.js → index-0j1t1h2b.js} +3 -1
- package/{index-payhwt51.js → index-1h2jc0x3.js} +141 -67
- package/{index-vxmy1p4f.js → index-1qsd8ft1.js} +63 -123
- package/{index-s6da8ta9.js → index-2mwjshz5.js} +158 -51
- package/index-2nxk8wgs.js +266 -0
- package/{index-k5jbcxyh.js → index-2phm56a1.js} +49 -8
- package/{index-jje9qzyq.js → index-35j83zkd.js} +37 -3
- package/{index-m5n3ka0p.js → index-4am4dvmf.js} +13 -2
- package/index-75y7bcz4.js +28 -0
- package/{index-b8c289dx.js → index-7apsdr5g.js} +55 -12
- package/{index-8559hsz4.js → index-84h43kg6.js} +6 -5
- package/{index-eja64h28.js → index-9zy8479y.js} +5 -3
- package/{index-96wzdhfh.js → index-a1vb3x7t.js} +209 -36
- package/{index-52w0fvh8.js → index-bns3wcpc.js} +15 -0
- package/{index-am36s3jh.js → index-cjmjvg4r.js} +157 -117
- package/{index-1p0qbq3m.js → index-defp4gmb.js} +1 -1
- package/{index-4pdts00b.js → index-ewbmfarf.js} +10 -8
- package/{index-9rvcs76p.js → index-fhw7yq2d.js} +10 -10
- package/{index-8scw1pjk.js → index-g500c5j9.js} +178 -82
- package/{index-qxzrp5xt.js → index-g841cap9.js} +4 -4
- package/{index-qkkdhjm6.js → index-gr9thy79.js} +5 -5
- package/{index-4pf8g7ff.js → index-h7hehkw6.js} +3 -0
- package/{index-4mj92tsh.js → index-hm0tn7qv.js} +73 -68
- package/{index-r2wedvqn.js → index-j6eeh5d7.js} +1 -1
- package/{index-tgt2fnd6.js → index-j7hwy56s.js} +3 -3
- package/{index-rnphv731.js → index-jc2zbwra.js} +2 -2
- package/{index-z4b84y6k.js → index-khk05tsf.js} +1 -1
- package/{index-tvehn2sp.js → index-qd7xn2bk.js} +1 -1
- package/{index-266dewjs.js → index-qw6814m4.js} +53 -15
- package/{index-zcf6k8a5.js → index-raz588b3.js} +47 -12
- package/{index-at7bz0xq.js → index-s4nvxpzm.js} +2 -0
- package/{index-3yz30c07.js → index-sp0qsr7a.js} +114 -12
- package/{index-1shvxzt0.js → index-sveq36gh.js} +39 -42
- package/{index-r2w2eh93.js → index-t1t9wq9a.js} +4 -4
- package/index-t78230d7.js +191 -0
- package/{index-r0k3ham2.js → index-tgqameyb.js} +4 -4
- package/{index-dd44g6vz.js → index-tp56652m.js} +5 -5
- package/index-w15mg3km.js +389 -0
- package/{index-xq543a5y.js → index-y4kcmbt2.js} +2 -2
- package/index-yf9wc28h.js +52 -0
- package/{index-xqgwjz7a.js → index-zbrwnmf1.js} +9 -7
- package/{index-xxfy1jp2.js → index-zttm13c3.js} +4 -4
- package/index.js +24 -24
- package/{library.command-2853y6mk.js → library.command-63hgt9te.js} +4 -4
- package/{localRegistry.command-76ds31p4.js → localRegistry.command-g3f8k25t.js} +43 -23
- package/{module.command-yfnb0abs.js → module.command-r4sa2khp.js} +7 -6
- package/{package.command-d9s86hp9.js → package.command-96eheyvd.js} +5 -5
- package/package.json +2 -2
- package/{page.command-6a8a8rd1.js → page.command-gs6d841d.js} +4 -4
- package/{pipeline.command-rt3rwd2z.js → pipeline.command-wdfvdbfj.js} +3 -3
- package/{primitive.command-emcebgrq.js → primitive.command-dfsv4mpe.js} +8 -7
- package/{projectTypecheck-51m7eh1f.js → projectTypecheck-kqj1t6hb.js} +1 -1
- package/{prompter-hgcta8pb.js → prompter-qrwx1p17.js} +2 -2
- package/{quality.command-xtrk0n3x.js → quality.command-webzxee2.js} +6 -4
- package/{repair.command-51szxnxx.js → repair.command-3r3j1xre.js} +7 -6
- package/{scalar.command-8qv27t82.js → scalar.command-e8y47j6d.js} +6 -5
- package/skills/akan-agent/SKILL.md +8 -1
- package/skills/akan-code/SKILL.md +37 -11
- package/skills/akan-debug/SKILL.md +2 -1
- package/skills/akan-err/SKILL.md +2 -1
- package/skills/akan-query/SKILL.md +3 -2
- package/skills/akan-runtime/SKILL.md +3 -0
- package/{subspace.command-pn56pnh8.js → subspace.command-a1sf9n5a.js} +12 -10
- package/templates/appSample/lib/task/task.signal.ts +14 -9
- package/templates/appSample/srvkit/guards.ts +11 -0
- package/templates/service/__model__.dictionary.ts +3 -5
- package/templates/workspaceRoot/.gitignore.template +1 -0
- package/{tunnel.command-q2h0j2en.js → tunnel.command-dcb0wg93.js} +25 -13
- package/{verify.command-z1dsbmrt.js → verify.command-yyepccbh.js} +13 -11
- package/{workflow.command-r3y67jeq.js → workflow.command-z5pg9ay0.js} +12 -11
- package/{workspace.command-t2f0xsrw.js → workspace.command-d7x5jttw.js} +74 -47
- package/CodeAgent-35wnb7w5.js +0 -9
- package/CodeAgentRpcListener-7p7z5dd7.js +0 -97
- package/TunnelShare-xyjpa7gx.js +0 -14
- package/cloud.script-0s1jybd5.js +0 -26
- package/code.command-mpkm2emr.js +0 -167
- package/context.runner-ch0z3a8g.js +0 -26
- package/index-c6eggbee.js +0 -123
- package/index-ksfgqq1x.js +0 -49
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
AkanCodeEnv,
|
|
4
|
+
akanCodePaths2
|
|
5
|
+
} from "./index-35j83zkd.js";
|
|
6
|
+
import {
|
|
7
|
+
akanCodeDefaultModel2,
|
|
8
|
+
akanCodeModel2,
|
|
9
|
+
akanCodeModelSupportsImages2,
|
|
10
|
+
akanCodeModelWarnings2,
|
|
4
11
|
McpServerConfig,
|
|
12
|
+
WorkspaceTrust
|
|
13
|
+
} from "./index-w15mg3km.js";
|
|
14
|
+
import {
|
|
15
|
+
SubagentPool2,
|
|
5
16
|
McpSignIn,
|
|
6
17
|
AkanCodeCompaction2
|
|
7
|
-
} from "./index-
|
|
18
|
+
} from "./index-1qsd8ft1.js";
|
|
8
19
|
import {
|
|
9
20
|
PreviewView2,
|
|
10
21
|
stripAnsi
|
|
11
22
|
} from "./index-tenw3mah.js";
|
|
12
23
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "./index-c6eggbee.js";
|
|
18
|
-
import {
|
|
19
|
-
akanCodePaths2
|
|
20
|
-
} from "./index-jje9qzyq.js";
|
|
24
|
+
codeAgentIsLoopback,
|
|
25
|
+
codeAgentHostListed,
|
|
26
|
+
codeAgentHostOf
|
|
27
|
+
} from "./index-75y7bcz4.js";
|
|
21
28
|
|
|
22
29
|
// pkgs/@akanjs/devkit/codeAgent/agent/AkanCodeServices.ts
|
|
23
30
|
import { existsSync as existsSync4, mkdirSync, mkdtempSync } from "fs";
|
|
@@ -162,6 +169,8 @@ var akanSystemPrompt2 = (profile) => {
|
|
|
162
169
|
lines.push("- Ask with `ask_user` when two readings of the request would lead to materially different work, and offer the options you can name. Do not ask for a choice that has an obvious default, and do not ask permission for work you were already asked to do \u2014 make the call, say the assumption, and carry on.");
|
|
163
170
|
if (profile.approval !== "never")
|
|
164
171
|
lines.push(`- Some tool calls need the user's approval (policy: ${profile.approval}). A refusal is an answer; do not retry it a different way.`);
|
|
172
|
+
if (profile.network.askOutside)
|
|
173
|
+
lines.push("- `web_fetch` to a host outside a short list of documentation sites, and a shell command that reaches the network (`curl`, `wget`, `ssh`, \u2026), wait for the user's approval. A refusal is an answer; do not retry it a different way.");
|
|
165
174
|
lines.push("- Secrets are refused at the tool boundary. If you need a value from `.env`, ask the user for it rather than looking for another way to read the file.", "", "## How to answer", "", "- Answer in as few words as carry the answer. A short question gets one sentence with no heading.", "- Do not open with what you are about to do, and do not close with a summary of what you did. The tool calls are already on the user's screen.", "- Skip headings, bold labels and bullet lists unless the answer is genuinely a list. Prose is shorter.", "- State a file as `path:line`. Do not paste a file back that the user can open.", "- Say what you could not do, and why, in one line. Do not offer alternatives nobody asked for.");
|
|
166
175
|
return lines.join(`
|
|
167
176
|
`);
|
|
@@ -262,7 +271,7 @@ class AkanCodeServices2 {
|
|
|
262
271
|
});
|
|
263
272
|
}
|
|
264
273
|
static async runtime(workspaceRoot, proxy = null) {
|
|
265
|
-
|
|
274
|
+
akanCodePaths2.ensureGlobalDir();
|
|
266
275
|
const runtime = await ModelRuntime.create({
|
|
267
276
|
authPath: proxy ? path4.join(mkdtempSync(path4.join(tmpdir(), "akan-code-proxy-")), "auth.json") : akanCodePaths2.authFile(),
|
|
268
277
|
modelsPath: akanCodePaths2.modelsFile()
|
|
@@ -309,7 +318,7 @@ class AkanCodeServices2 {
|
|
|
309
318
|
agentsFiles: options.profile.context.projectFiles ? AkanContextFiles.extend(agentsFiles, { workspaceRoot: options.workspaceRoot, cwd: options.cwd }) : agentsFiles
|
|
310
319
|
}),
|
|
311
320
|
appendSystemPrompt: [akanSystemPrompt2(options.profile)],
|
|
312
|
-
additionalExtensionPaths: present(akanCodePaths2.extensionsDir(options.workspaceRoot)),
|
|
321
|
+
additionalExtensionPaths: WorkspaceTrust.isTrusted(options.workspaceRoot, "extensions") ? present(akanCodePaths2.extensionsDir(options.workspaceRoot)) : [],
|
|
313
322
|
additionalSkillPaths: AkanCodeServices2.#skillPaths(options.profile, options.workspaceRoot),
|
|
314
323
|
extensionFactories: options.extensions
|
|
315
324
|
};
|
|
@@ -650,7 +659,7 @@ class AkanToolPack2 {
|
|
|
650
659
|
return { name: "akan-tools", factory: async (pi) => await this.#register(pi) };
|
|
651
660
|
}
|
|
652
661
|
async names() {
|
|
653
|
-
const { ContextRunner } = await import("./context.runner-
|
|
662
|
+
const { ContextRunner } = await import("./context.runner-rsnqnk9j.js");
|
|
654
663
|
return [
|
|
655
664
|
...new ContextRunner().listMcpTools(this.#options.mode).map((tool) => tool.name),
|
|
656
665
|
AkanToolPack2.verifyToolName
|
|
@@ -658,7 +667,7 @@ class AkanToolPack2 {
|
|
|
658
667
|
}
|
|
659
668
|
static verifyToolName = "akan_verify";
|
|
660
669
|
async#register(pi) {
|
|
661
|
-
const { ContextRunner } = await import("./context.runner-
|
|
670
|
+
const { ContextRunner } = await import("./context.runner-rsnqnk9j.js");
|
|
662
671
|
const runner = new ContextRunner;
|
|
663
672
|
const guidelineNames = await AkanToolPack2.#guidelineNames();
|
|
664
673
|
for (const tool of runner.listMcpTools(this.#options.mode, { guidelineNames })) {
|
|
@@ -696,7 +705,7 @@ class AkanToolPack2 {
|
|
|
696
705
|
}
|
|
697
706
|
static async#guidelineNames() {
|
|
698
707
|
try {
|
|
699
|
-
const { Prompter } = await import("./prompter-
|
|
708
|
+
const { Prompter } = await import("./prompter-qrwx1p17.js");
|
|
700
709
|
return await Prompter.listGuidelines();
|
|
701
710
|
} catch {
|
|
702
711
|
return [];
|
|
@@ -1156,7 +1165,11 @@ class McpToolPack2 {
|
|
|
1156
1165
|
if (options.profile.tools.mcp === "off")
|
|
1157
1166
|
return [];
|
|
1158
1167
|
const declared = Array.isArray(options.profile.tools.mcp) ? options.profile.tools.mcp : [];
|
|
1159
|
-
|
|
1168
|
+
if (WorkspaceTrust.isTrusted(options.workspaceRoot, "mcp"))
|
|
1169
|
+
return [...McpServerConfig.read(options.workspaceRoot), ...declared];
|
|
1170
|
+
const skipped = McpServerConfig.read(options.workspaceRoot, ["workspace"]).map((ref) => ref.name);
|
|
1171
|
+
options.onNotice?.(`Not started, because this repo's MCP servers are not approved: ${skipped.join(", ")}. Start akan code in a terminal to approve them, or pass --trust-workspace.`);
|
|
1172
|
+
return [...McpServerConfig.read(options.workspaceRoot, ["global"]), ...declared];
|
|
1160
1173
|
}
|
|
1161
1174
|
}
|
|
1162
1175
|
|
|
@@ -1344,6 +1357,7 @@ class DeepSeekWeb {
|
|
|
1344
1357
|
class WebToolPack2 {
|
|
1345
1358
|
static pageChars = 1e4;
|
|
1346
1359
|
static maxResults = 10;
|
|
1360
|
+
static maxRedirects = 5;
|
|
1347
1361
|
static #rememberedPages = 16;
|
|
1348
1362
|
#options;
|
|
1349
1363
|
#pages = new Map;
|
|
@@ -1466,8 +1480,9 @@ class WebToolPack2 {
|
|
|
1466
1480
|
return deepseek ? { name: "deepseek", search: (query, count, signal) => deepseek.search(query, count, signal) } : undefined;
|
|
1467
1481
|
}
|
|
1468
1482
|
async#read(url, signal) {
|
|
1483
|
+
const within = this.#boundOf(new URL(url).hostname);
|
|
1469
1484
|
const deepseek = this.#options.deepseek;
|
|
1470
|
-
if (deepseek && !await this.#isLocal(new URL(url).hostname)) {
|
|
1485
|
+
if (deepseek && !within && !await this.#isLocal(new URL(url).hostname)) {
|
|
1471
1486
|
try {
|
|
1472
1487
|
const page = await deepseek.fetch(url, signal);
|
|
1473
1488
|
return { status: 200, ok: true, title: page.title, text: page.content };
|
|
@@ -1476,11 +1491,50 @@ class WebToolPack2 {
|
|
|
1476
1491
|
throw error;
|
|
1477
1492
|
}
|
|
1478
1493
|
}
|
|
1479
|
-
const
|
|
1480
|
-
|
|
1481
|
-
redirect: "follow"
|
|
1482
|
-
|
|
1483
|
-
|
|
1494
|
+
const timeout = signal ? AbortSignal.any([signal, AbortSignal.timeout(20000)]) : AbortSignal.timeout(20000);
|
|
1495
|
+
if (!within) {
|
|
1496
|
+
const response = await fetch(url, { signal: timeout, redirect: "follow" });
|
|
1497
|
+
return {
|
|
1498
|
+
status: response.status,
|
|
1499
|
+
ok: response.ok,
|
|
1500
|
+
title: "",
|
|
1501
|
+
text: WebToolPack2.#readable(await response.text())
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
return await WebToolPack2.#readWithin(url, within, timeout);
|
|
1505
|
+
}
|
|
1506
|
+
#boundOf(hostname) {
|
|
1507
|
+
const { allowHosts, askOutside } = this.#options.profile.network;
|
|
1508
|
+
if (allowHosts?.length)
|
|
1509
|
+
return (host) => allowHosts.includes(host);
|
|
1510
|
+
const quiet = (host) => codeAgentIsLoopback(host) || codeAgentHostListed(host, askOutside ?? []);
|
|
1511
|
+
return askOutside && quiet(hostname) ? quiet : undefined;
|
|
1512
|
+
}
|
|
1513
|
+
static async#readWithin(url, within, signal) {
|
|
1514
|
+
let current = url;
|
|
1515
|
+
for (let hop = 0;hop <= WebToolPack2.maxRedirects; hop += 1) {
|
|
1516
|
+
const response = await fetch(current, { signal, redirect: "manual" });
|
|
1517
|
+
const location = response.headers.get("location");
|
|
1518
|
+
if (response.status < 300 || response.status >= 400 || !location)
|
|
1519
|
+
return {
|
|
1520
|
+
status: response.status,
|
|
1521
|
+
ok: response.ok,
|
|
1522
|
+
title: "",
|
|
1523
|
+
text: WebToolPack2.#readable(await response.text())
|
|
1524
|
+
};
|
|
1525
|
+
await response.body?.cancel();
|
|
1526
|
+
const next = new URL(location, current).href;
|
|
1527
|
+
const host = codeAgentHostOf(next);
|
|
1528
|
+
if (!host || !within(host))
|
|
1529
|
+
return {
|
|
1530
|
+
status: response.status,
|
|
1531
|
+
ok: false,
|
|
1532
|
+
title: "",
|
|
1533
|
+
text: `Redirected to ${next}, which this profile does not reach without asking. web_fetch that URL to follow it.`
|
|
1534
|
+
};
|
|
1535
|
+
current = next;
|
|
1536
|
+
}
|
|
1537
|
+
return { status: 310, ok: false, title: "", text: `More than ${WebToolPack2.maxRedirects} redirects.` };
|
|
1484
1538
|
}
|
|
1485
1539
|
#remember(url, page) {
|
|
1486
1540
|
this.#pages.delete(url);
|
|
@@ -1922,20 +1976,45 @@ class CodeAgentEventMapper2 {
|
|
|
1922
1976
|
}
|
|
1923
1977
|
|
|
1924
1978
|
// pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentGate.ts
|
|
1979
|
+
import { realpathSync } from "fs";
|
|
1980
|
+
import { homedir } from "os";
|
|
1925
1981
|
import path7 from "path";
|
|
1982
|
+
import { fileURLToPath } from "url";
|
|
1926
1983
|
var writeTools = new Set(["write", "edit"]);
|
|
1927
1984
|
var commandTools = new Set(["bash"]);
|
|
1985
|
+
var networkClients = /(?:^[ \t]*|[\n;&|(`{][ \t]*|\s-\w*c\s+['"][ \t]*|\s-exec(?:dir)?\s+)(?:(?:[A-Za-z_]\w*=\S*|sudo|env|command|exec|nohup|time|timeout|nice|watch|stdbuf|xargs|-\S+|\d\S*)[ \t]+)*(?:[^\s;&|()`'"]*\/)?(curl|wget|nc|ncat|netcat|socat|telnet|ssh|scp|sftp|rsync|ftp)(?=$|[\s;&|)`'"])/g;
|
|
1986
|
+
var urlPattern = /\b[a-z][a-z0-9+.-]*:\/\/[^\s'"`<>|;&()]+/gi;
|
|
1987
|
+
var hostPortPattern = /(?<=^|[\s'"=])(?:\[[0-9a-f:.]+\]|[a-z0-9.-]+):\d{1,5}(?=[/?#\s'"]|$)/gi;
|
|
1988
|
+
var ordinaryNames = ["index.ts", "a.ts", "a.tsx", "a.js", "a.json", "a.yaml", "a.md", "a.txt", "a.log", "README"];
|
|
1928
1989
|
|
|
1929
1990
|
class CodeAgentGate2 {
|
|
1930
1991
|
#profile;
|
|
1992
|
+
#realRoot;
|
|
1931
1993
|
#deny;
|
|
1932
1994
|
#allow;
|
|
1933
1995
|
#deniedFragments;
|
|
1996
|
+
#nameRules;
|
|
1934
1997
|
constructor(profile) {
|
|
1935
1998
|
this.#profile = profile;
|
|
1936
|
-
this.#
|
|
1999
|
+
this.#realRoot = CodeAgentGate2.#real(path7.resolve(profile.paths.root));
|
|
2000
|
+
const home = homedir();
|
|
2001
|
+
const codeHome = path7.resolve(akanCodePaths2.globalDir());
|
|
2002
|
+
const patterns = [
|
|
2003
|
+
...(profile.paths.deny ?? []).map((pattern) => pattern.startsWith("~/") ? path7.join(home, pattern.slice(2)) : pattern),
|
|
2004
|
+
...profile.paths.deny?.length ? [`${codeHome}/**`] : []
|
|
2005
|
+
];
|
|
2006
|
+
this.#deny = patterns.map((pattern) => new Bun.Glob(pattern));
|
|
1937
2007
|
this.#allow = (profile.paths.allow ?? []).map((pattern) => new Bun.Glob(pattern));
|
|
1938
|
-
this.#deniedFragments = [
|
|
2008
|
+
this.#deniedFragments = [
|
|
2009
|
+
...new Set((profile.paths.deny ?? []).flatMap(CodeAgentGate2.#expandBraces).flatMap((pattern) => CodeAgentGate2.#fragmentsOf(pattern, home)))
|
|
2010
|
+
].filter(Boolean);
|
|
2011
|
+
this.#nameRules = (profile.paths.deny ?? []).flatMap((pattern) => {
|
|
2012
|
+
const name = /^\*\*\/([^/]+)$/.exec(pattern)?.[1];
|
|
2013
|
+
if (!name || name === "**")
|
|
2014
|
+
return [];
|
|
2015
|
+
const samples = CodeAgentGate2.#expandBraces(name).map((entry) => entry.replace(/[*?]/g, "x"));
|
|
2016
|
+
return [{ glob: new Bun.Glob(name), samples }];
|
|
2017
|
+
});
|
|
1939
2018
|
}
|
|
1940
2019
|
verdict(toolName, args) {
|
|
1941
2020
|
const target = stringArg(args, "path");
|
|
@@ -1950,27 +2029,73 @@ class CodeAgentGate2 {
|
|
|
1950
2029
|
if (denied)
|
|
1951
2030
|
return { block: denied };
|
|
1952
2031
|
}
|
|
2032
|
+
const network = this.#networkApproval(toolName, args);
|
|
2033
|
+
if (network)
|
|
2034
|
+
return { approval: network, strict: true };
|
|
1953
2035
|
if (!this.#needsApproval(toolName))
|
|
1954
2036
|
return {};
|
|
1955
2037
|
return { approval: CodeAgentGate2.#summarize(toolName, args) };
|
|
1956
2038
|
}
|
|
1957
2039
|
#deniedCommandReason(command) {
|
|
1958
|
-
const hit = this.#deniedFragments.find((fragment) => command.includes(fragment));
|
|
2040
|
+
const hit = this.#deniedFragments.find((fragment) => command.includes(fragment)) ?? CodeAgentGate2.#wordsOf(command).find((word) => this.#namesDeniedFile(word));
|
|
1959
2041
|
if (!hit)
|
|
1960
2042
|
return;
|
|
1961
2043
|
return `The command names "${hit}", which the profile's deny list covers. Ask the user for the value instead of reading the file.`;
|
|
1962
2044
|
}
|
|
2045
|
+
#namesDeniedFile(word) {
|
|
2046
|
+
const expanded = CodeAgentGate2.#expandHome(word);
|
|
2047
|
+
const name = path7.basename(expanded);
|
|
2048
|
+
if (/[*?[{]/.test(name)) {
|
|
2049
|
+
const swept = new Bun.Glob(name);
|
|
2050
|
+
if (ordinaryNames.some((ordinary) => swept.match(ordinary)))
|
|
2051
|
+
return false;
|
|
2052
|
+
return this.#nameRules.some((rule) => rule.samples.some((sample) => swept.match(sample)));
|
|
2053
|
+
}
|
|
2054
|
+
const absolute = path7.resolve(this.#profile.paths.root, expanded);
|
|
2055
|
+
return this.#deny.some((glob) => glob.match(expanded) || glob.match(absolute));
|
|
2056
|
+
}
|
|
1963
2057
|
#deniedReason(target) {
|
|
1964
|
-
const absolute = path7.
|
|
1965
|
-
const relative = path7.relative(this.#profile.paths.root, absolute);
|
|
1966
|
-
if (relative.startsWith(
|
|
2058
|
+
const absolute = path7.resolve(this.#profile.paths.root, CodeAgentGate2.#expandPath(target));
|
|
2059
|
+
const relative = path7.relative(path7.resolve(this.#profile.paths.root), absolute);
|
|
2060
|
+
if (relative === ".." || relative.startsWith(`..${path7.sep}`) || path7.isAbsolute(relative))
|
|
1967
2061
|
return `Path is outside the agent root (${this.#profile.paths.root}).`;
|
|
1968
|
-
|
|
2062
|
+
const real = CodeAgentGate2.#real(absolute);
|
|
2063
|
+
const candidates = [
|
|
2064
|
+
[absolute, relative],
|
|
2065
|
+
[real, path7.relative(this.#realRoot, real)]
|
|
2066
|
+
];
|
|
2067
|
+
if (candidates.some(([candidate, rel]) => this.#deny.some((glob) => glob.match(candidate) || glob.match(rel))))
|
|
1969
2068
|
return "Path is on the profile's deny list (secrets and environment files are never readable).";
|
|
1970
2069
|
if (this.#allow.length && !this.#allow.some((glob) => glob.match(absolute) || glob.match(relative)))
|
|
1971
2070
|
return "Path is outside the profile's allow list.";
|
|
1972
2071
|
return;
|
|
1973
2072
|
}
|
|
2073
|
+
#networkApproval(toolName, args) {
|
|
2074
|
+
const quiet = this.#profile.network.askOutside;
|
|
2075
|
+
if (!quiet)
|
|
2076
|
+
return;
|
|
2077
|
+
if (toolName === "web_fetch") {
|
|
2078
|
+
const url = stringArg(args, "url");
|
|
2079
|
+
const host = url ? codeAgentHostOf(url) : undefined;
|
|
2080
|
+
if (!host || codeAgentIsLoopback(host) || codeAgentHostListed(host, quiet))
|
|
2081
|
+
return;
|
|
2082
|
+
return `fetch ${url}`;
|
|
2083
|
+
}
|
|
2084
|
+
const command = stringArg(args, "command");
|
|
2085
|
+
if (!command || !commandTools.has(toolName))
|
|
2086
|
+
return;
|
|
2087
|
+
const clients = [...command.matchAll(networkClients)].map((match) => match[1]);
|
|
2088
|
+
if (!clients.length)
|
|
2089
|
+
return;
|
|
2090
|
+
const hosts = [
|
|
2091
|
+
...[...command.matchAll(urlPattern)].map((match) => codeAgentHostOf(match[0])),
|
|
2092
|
+
...[...command.matchAll(hostPortPattern)].map((match) => codeAgentHostOf(`http://${match[0]}`))
|
|
2093
|
+
];
|
|
2094
|
+
const httpOnly = clients.every((client) => client === "curl" || client === "wget");
|
|
2095
|
+
if (httpOnly && hosts.length && hosts.every((host) => host && codeAgentIsLoopback(host)))
|
|
2096
|
+
return;
|
|
2097
|
+
return `reach the network: ${command.slice(0, 200)}`;
|
|
2098
|
+
}
|
|
1974
2099
|
#needsApproval(toolName) {
|
|
1975
2100
|
switch (this.#profile.approval) {
|
|
1976
2101
|
case "never":
|
|
@@ -1985,9 +2110,55 @@ class CodeAgentGate2 {
|
|
|
1985
2110
|
return false;
|
|
1986
2111
|
}
|
|
1987
2112
|
}
|
|
1988
|
-
static #
|
|
1989
|
-
const
|
|
1990
|
-
|
|
2113
|
+
static #expandPath(target) {
|
|
2114
|
+
const value = target.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "");
|
|
2115
|
+
if (/^file:\/\//.test(value)) {
|
|
2116
|
+
try {
|
|
2117
|
+
return fileURLToPath(value);
|
|
2118
|
+
} catch {
|
|
2119
|
+
return value;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
return CodeAgentGate2.#expandHome(value);
|
|
2123
|
+
}
|
|
2124
|
+
static #expandHome(value) {
|
|
2125
|
+
const home = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(value);
|
|
2126
|
+
return home ? path7.join(homedir(), value.slice(home[0].length)) : value;
|
|
2127
|
+
}
|
|
2128
|
+
static #real(absolute) {
|
|
2129
|
+
const rest = [];
|
|
2130
|
+
let head = absolute;
|
|
2131
|
+
for (;; ) {
|
|
2132
|
+
try {
|
|
2133
|
+
return path7.join(realpathSync(head), ...rest);
|
|
2134
|
+
} catch {
|
|
2135
|
+
const parent = path7.dirname(head);
|
|
2136
|
+
if (parent === head)
|
|
2137
|
+
return absolute;
|
|
2138
|
+
rest.unshift(path7.basename(head));
|
|
2139
|
+
head = parent;
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
static #wordsOf(command) {
|
|
2144
|
+
return command.split(/[\s;&|<>()`'"=,@]+/).filter(Boolean);
|
|
2145
|
+
}
|
|
2146
|
+
static #expandBraces(pattern) {
|
|
2147
|
+
const open = pattern.indexOf("{");
|
|
2148
|
+
const close = open >= 0 ? pattern.indexOf("}", open) : -1;
|
|
2149
|
+
if (close < 0)
|
|
2150
|
+
return [pattern];
|
|
2151
|
+
const head = pattern.slice(0, open);
|
|
2152
|
+
const tail = pattern.slice(close + 1);
|
|
2153
|
+
return pattern.slice(open + 1, close).split(",").flatMap((choice) => CodeAgentGate2.#expandBraces(`${head}${choice}${tail}`));
|
|
2154
|
+
}
|
|
2155
|
+
static #fragmentsOf(pattern, home) {
|
|
2156
|
+
if (pattern.startsWith("~/")) {
|
|
2157
|
+
const rest = pattern.slice(2).replace(/\/\*\*$/, "");
|
|
2158
|
+
return rest.includes("*") ? [] : ["~/", "$HOME/", "$" + "{HOME}/", `${home}/`].map((prefix) => `${prefix}${rest}`);
|
|
2159
|
+
}
|
|
2160
|
+
const trimmed = pattern.replace(/^\*\*\//, "").replace(/\/\*\*$/, "/").replace(/^\*+/, "").replace(/\*+$/, "");
|
|
2161
|
+
return trimmed.includes("*") ? [] : [trimmed];
|
|
1991
2162
|
}
|
|
1992
2163
|
static #summarize(toolName, args) {
|
|
1993
2164
|
const record = args ?? {};
|
|
@@ -2016,15 +2187,15 @@ class CodeAgentProxy {
|
|
|
2016
2187
|
throw new Error("AKAN_CODE_PROXY_URL needs AKAN_CODE_PROXY_TOKEN_FILE or AKAN_CODE_PROXY_TOKEN");
|
|
2017
2188
|
}
|
|
2018
2189
|
static fromEnv(profile) {
|
|
2019
|
-
const baseUrl =
|
|
2190
|
+
const baseUrl = AkanCodeEnv.get("AKAN_CODE_PROXY_URL")?.trim() || profile?.network.proxyBaseUrl;
|
|
2020
2191
|
if (!baseUrl)
|
|
2021
2192
|
return null;
|
|
2022
|
-
const providers = (
|
|
2193
|
+
const providers = (AkanCodeEnv.get("AKAN_CODE_PROXY_PROVIDERS") ?? akanCodeDefaultModel2.provider).split(",").map((provider) => provider.trim()).filter(Boolean);
|
|
2023
2194
|
return new CodeAgentProxy({
|
|
2024
2195
|
baseUrl,
|
|
2025
2196
|
providers,
|
|
2026
|
-
tokenFile:
|
|
2027
|
-
token:
|
|
2197
|
+
tokenFile: AkanCodeEnv.get("AKAN_CODE_PROXY_TOKEN_FILE")?.trim() || undefined,
|
|
2198
|
+
token: AkanCodeEnv.get("AKAN_CODE_PROXY_TOKEN")?.trim() || undefined
|
|
2028
2199
|
});
|
|
2029
2200
|
}
|
|
2030
2201
|
baseUrlFor(provider) {
|
|
@@ -2744,6 +2915,8 @@ Continue the task.`);
|
|
|
2744
2915
|
return this.#refuse(event.toolCallId, event.toolName, event.input, verdict.block);
|
|
2745
2916
|
if (!verdict.approval)
|
|
2746
2917
|
return;
|
|
2918
|
+
if (verdict.strict && !this.#profile.ui.canPrompt)
|
|
2919
|
+
return this.#refuse(event.toolCallId, event.toolName, event.input, "This reaches a host outside the profile's list, which needs the user's approval, and nobody can be asked in this session. Use a listed host, or say what you need fetched.");
|
|
2747
2920
|
const approved = await this.#requestApproval(event.toolCallId, event.toolName, event.input, verdict.approval);
|
|
2748
2921
|
if (approved)
|
|
2749
2922
|
return;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// pkgs/@akanjs/devkit/fileSys.ts
|
|
3
|
+
import { chmodSync, mkdirSync, statSync } from "fs";
|
|
3
4
|
import { lstat, rename, rm, stat } from "fs/promises";
|
|
4
5
|
import nodePath from "path";
|
|
5
6
|
import { fileURLToPath } from "url";
|
|
@@ -63,6 +64,20 @@ class FileSys2 {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
}
|
|
67
|
+
static ensurePrivateDir(dir) {
|
|
68
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
69
|
+
if (process.platform === "win32")
|
|
70
|
+
return dir;
|
|
71
|
+
const { mode, uid } = statSync(dir);
|
|
72
|
+
if ((mode & 63) === 0 || uid !== process.getuid?.())
|
|
73
|
+
return dir;
|
|
74
|
+
try {
|
|
75
|
+
chmodSync(dir, 448);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
FileSys2.logger.warn(`${dir} stays at mode ${(mode & 511).toString(8)}: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
return dir;
|
|
80
|
+
}
|
|
66
81
|
static async writeJson(path, content) {
|
|
67
82
|
return await Bun.file(path).write(`${JSON.stringify(content, null, 2)}
|
|
68
83
|
`);
|