@akanjs/cli 3.3.0-rc.0 → 3.3.0-rc.10

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.
Files changed (115) hide show
  1. package/.build-stamp +2 -2
  2. package/CodeAgent-cqbf9gsv.js +11 -0
  3. package/{CodeAgentRpcHost-6dzfkvsc.js → CodeAgentRpcHost-pwps2d67.js} +1 -1
  4. package/{CodeTui-zee8atsr.js → CodeTui-ehdr4hgw.js} +46 -6
  5. package/TunnelShare-0p4dy89e.js +16 -0
  6. package/{agent.command-x65f2ags.js → agent.command-x55ncdjm.js} +20 -22
  7. package/akanCode.js +7 -7
  8. package/appExecutor-1ctzymwa.js +11 -0
  9. package/{application.command-azbd1pb2.js → application.command-xpntxnh8.js} +18 -20
  10. package/{applicationBuildRunner-trfxv3pd.js → applicationBuildRunner-19c76791.js} +16 -13
  11. package/buildBatch.proc.js +19 -19
  12. package/{cloud.command-gapp4634.js → cloud.command-p3ybjes7.js} +19 -24
  13. package/cloud.script-0dsyd10v.js +30 -0
  14. package/{code.command-5smx61yf.js → code.command-m6skj1kj.js} +34 -19
  15. package/{context.command-ym5jbkny.js → context.command-3c3nv0d6.js} +20 -22
  16. package/context.runner-yyp7a112.js +32 -0
  17. package/csrArtifactBuilder-mdh9ykn2.js +9 -0
  18. package/{index-2ny1e95c.js → dependencyScanner-93g8tk0r.js} +6 -5
  19. package/{fileSys-q22646yc.js → fileSys-e5mwt73x.js} +1 -1
  20. package/frameworkGraph-aneq2nwy.js +8 -0
  21. package/{guideline.command-zwypaqsh.js → guideline.command-725fq5p0.js} +8 -8
  22. package/guidelines/agentRule/agentRule.instruction.md +46 -7
  23. package/guidelines/akanApi/akanApi.instruction.md +7 -2
  24. package/guidelines/conventions/core.md +6 -11
  25. package/guidelines/conventions/rules/app.md +1 -2
  26. package/guidelines/conventions/rules/auth.md +18 -27
  27. package/guidelines/conventions/rules/config.md +15 -46
  28. package/guidelines/conventions/rules/page.md +19 -34
  29. package/guidelines/conventions/rules/server.md +1 -4
  30. package/guidelines/conventions/rules/ssr.md +3 -4
  31. package/guidelines/conventions/rules/ts.md +2 -1
  32. package/guidelines/cssRule/cssRule.instruction.md +3 -0
  33. package/guidelines/errorCodes/errorCodes.instruction.md +4 -0
  34. package/guidelines/mcpRule/mcpRule.instruction.md +11 -4
  35. package/guidelines/pageRule/pageRule.instruction.md +6 -53
  36. package/guidelines/runtimeRule/runtimeRule.instruction.md +68 -4
  37. package/incrementalBuilder.proc.js +24 -18
  38. package/{index-nc3br31y.js → index-22bwg8hy.js} +2 -2
  39. package/{index-9f3reh2y.js → index-2v38x3ad.js} +12 -1
  40. package/{index-67sd09ag.js → index-3a3vy2xy.js} +8 -8
  41. package/{index-p7beqww9.js → index-3fmzz9sf.js} +18 -18
  42. package/{index-9wh04mqy.js → index-3mj5trqc.js} +65 -11
  43. package/{index-7wf8snar.js → index-3r1crbct.js} +1 -1
  44. package/{index-41a03gkj.js → index-3zkhg65e.js} +19 -19
  45. package/{index-2jmvfa62.js → index-4r8dgm4x.js} +3 -3
  46. package/{index-jek2re5k.js → index-4yvtqcme.js} +8 -8
  47. package/{index-j0wr4e32.js → index-5ahe641t.js} +9 -9
  48. package/{index-0dm25wvf.js → index-7ssr7wq4.js} +1 -1
  49. package/{index-dmcpetwe.js → index-8bta5pnr.js} +98 -23
  50. package/{index-z92zm3wd.js → index-9a9t77hz.js} +29 -11
  51. package/{index-3txdtztz.js → index-9gjcbp2g.js} +1 -1
  52. package/{index-8jtqfye2.js → index-a4gcdffy.js} +488 -53
  53. package/{index-xwwex8rf.js → index-cbm9gzgx.js} +5 -5
  54. package/{index-j6jjmn2r.js → index-ckcc9ab3.js} +62 -21
  55. package/{index-w1zexzpx.js → index-crd99zqs.js} +1 -1
  56. package/{index-612fdtbk.js → index-f4jydw2x.js} +1 -1
  57. package/{index-4ss4gkv3.js → index-fagjtk6m.js} +2 -2
  58. package/{index-ebn9kgea.js → index-fjqapyex.js} +45 -16
  59. package/{index-h901f24n.js → index-h8w1n11r.js} +5 -5
  60. package/{index-275a4r3n.js → index-hxg6ctk2.js} +12 -16
  61. package/{index-78y75t0a.js → index-j2wq064m.js} +6 -7
  62. package/{index-knpm8sdm.js → index-j3fqs8rc.js} +1 -1
  63. package/{index-kfvjzk8r.js → index-kbnvyhy4.js} +3 -3
  64. package/{index-6dzjer7p.js → index-m303nhv6.js} +6 -6
  65. package/{index-dadwp2aw.js → index-nmdmkjt2.js} +271 -39
  66. package/{index-2yn3r67f.js → index-nnmw56fz.js} +6 -6
  67. package/{index-a860mx0m.js → index-pr9nypg7.js} +24 -24
  68. package/{index-s885g0jj.js → index-pyjkbg8e.js} +3 -3
  69. package/{index-zmd9xxgd.js → index-q63nbpv7.js} +3 -3
  70. package/{index-v7ajmsh3.js → index-qecrqpt6.js} +4 -21
  71. package/{index-gt8phqpt.js → index-rdcgz02t.js} +4 -4
  72. package/{index-j592zfqc.js → index-rt7q20sj.js} +1 -1
  73. package/{index-baccvws5.js → index-se7n78fh.js} +1 -1
  74. package/{index-s4nvxpzm.js → index-sxbsrndq.js} +1 -1
  75. package/{index-k6vwww45.js → index-t23dgyaf.js} +7 -7
  76. package/{index-71y6176j.js → index-v16gj2as.js} +86 -66
  77. package/{index-0s7w2085.js → index-vnk1qwgr.js} +4 -4
  78. package/{index-z96ks033.js → index-wkwe91sn.js} +169 -51
  79. package/{index-ybcb9wc8.js → index-wxqp1amd.js} +9 -9
  80. package/{index-p5zh7pmc.js → index-xv3pvdw4.js} +1 -1
  81. package/{index-zfnz878d.js → index-yey1envc.js} +1 -1
  82. package/{index-by2tvsq6.js → index-zyjztrvc.js} +1 -1
  83. package/index.js +30 -28
  84. package/{libExecutor-jc6f8hm6.js → libExecutor-n8hpm8s7.js} +3 -3
  85. package/{library.command-nxvesvhb.js → library.command-8abb26pg.js} +8 -8
  86. package/{localRegistry.command-xz62e4ng.js → localRegistry.command-sa211m1z.js} +18 -23
  87. package/{module.command-aaws9byg.js → module.command-z3cwjf0p.js} +10 -10
  88. package/{package.command-j7hv26p0.js → package.command-akynhtee.js} +9 -12
  89. package/package.json +3 -2
  90. package/{page.command-7yffs7n9.js → page.command-3fpdavk9.js} +8 -8
  91. package/{pipeline.command-7yk0zcng.js → pipeline.command-ca95n8rd.js} +7 -7
  92. package/{pkgExecutor-arxmvx4t.js → pkgExecutor-a73q41vx.js} +3 -3
  93. package/{primitive.command-7a1pt715.js → primitive.command-xwe9ggnf.js} +11 -11
  94. package/{projectTypecheck-f4qhbecd.js → projectTypecheck-7g542ymk.js} +1 -1
  95. package/{prompter-qyggfhqd.js → prompter-d33wmdpa.js} +2 -2
  96. package/{quality.command-c6mvrjh1.js → quality.command-7wz7y8z1.js} +9 -9
  97. package/{repair.command-093adzt9.js → repair.command-dej1qtfq.js} +10 -10
  98. package/{scalar.command-2ex84spb.js → scalar.command-z9qfxnvm.js} +9 -9
  99. package/skills/akan-agent/SKILL.md +8 -1
  100. package/skills/akan-code/SKILL.md +38 -3
  101. package/skills/akan-page/SKILL.md +18 -13
  102. package/skills/akan-runtime/SKILL.md +21 -16
  103. package/skills/akan-service/SKILL.md +2 -2
  104. package/{subspace.command-4n4n4jpv.js → subspace.command-9wekm4gn.js} +11 -13
  105. package/templates/localDev/docker-compose.yaml.template +2 -2
  106. package/{tunnel.command-f7ep1qfa.js → tunnel.command-cxc4h3j8.js} +10 -12
  107. package/{verify.command-zrkxnvct.js → verify.command-j0w9dr5c.js} +15 -17
  108. package/{workflow.command-ks16jegk.js → workflow.command-yt4sz04b.js} +15 -15
  109. package/{workspace.command-ahhfpaag.js → workspace.command-8mp4mcp2.js} +34 -38
  110. package/CodeAgent-fx6088tv.js +0 -11
  111. package/TunnelShare-9ry4vh0y.js +0 -18
  112. package/appExecutor-79azsb2w.js +0 -11
  113. package/cloud.script-3b401efv.js +0 -35
  114. package/context.runner-kctbfsde.js +0 -34
  115. package/dependencyScanner-ge10gb52.js +0 -8
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  AkanCodeEnv,
4
4
  akanCodePaths2
5
- } from "./index-p5zh7pmc.js";
5
+ } from "./index-xv3pvdw4.js";
6
6
  import {
7
7
  akanCodeDefaultModel2,
8
8
  akanCodeModel2,
@@ -10,7 +10,7 @@ import {
10
10
  akanCodeModelWarnings2,
11
11
  McpServerConfig,
12
12
  WorkspaceTrust
13
- } from "./index-0dm25wvf.js";
13
+ } from "./index-7ssr7wq4.js";
14
14
  import {
15
15
  PreviewView2,
16
16
  stripAnsi
@@ -19,7 +19,7 @@ import {
19
19
  SubagentPool2,
20
20
  McpSignIn,
21
21
  AkanCodeCompaction2
22
- } from "./index-nc3br31y.js";
22
+ } from "./index-22bwg8hy.js";
23
23
  import {
24
24
  codeAgentIsLoopback,
25
25
  codeAgentHostListed,
@@ -676,7 +676,7 @@ class AkanToolPack2 {
676
676
  return { name: "akan-tools", factory: async (pi) => await this.#register(pi) };
677
677
  }
678
678
  async names() {
679
- const { ContextRunner } = await import("./context.runner-kctbfsde.js");
679
+ const { ContextRunner } = await import("./context.runner-yyp7a112.js");
680
680
  return [
681
681
  ...new ContextRunner().listMcpTools(this.#options.mode).map((tool) => tool.name),
682
682
  AkanToolPack2.verifyToolName
@@ -684,7 +684,7 @@ class AkanToolPack2 {
684
684
  }
685
685
  static verifyToolName = "akan_verify";
686
686
  async#register(pi) {
687
- const { ContextRunner } = await import("./context.runner-kctbfsde.js");
687
+ const { ContextRunner } = await import("./context.runner-yyp7a112.js");
688
688
  const runner = new ContextRunner;
689
689
  const guidelineNames = await AkanToolPack2.#guidelineNames();
690
690
  for (const tool of runner.listMcpTools(this.#options.mode, { guidelineNames })) {
@@ -722,7 +722,7 @@ class AkanToolPack2 {
722
722
  }
723
723
  static async#guidelineNames() {
724
724
  try {
725
- const { Prompter } = await import("./prompter-qyggfhqd.js");
725
+ const { Prompter } = await import("./prompter-d33wmdpa.js");
726
726
  return await Prompter.listGuidelines();
727
727
  } catch {
728
728
  return [];
@@ -2002,16 +2002,426 @@ class CodeAgentEventMapper2 {
2002
2002
  // pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentGate.ts
2003
2003
  import { realpathSync } from "fs";
2004
2004
  import { homedir } from "os";
2005
- import path7 from "path";
2005
+ import path8 from "path";
2006
2006
  import { fileURLToPath } from "url";
2007
+
2008
+ // pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentAllowed.ts
2009
+ class CodeAgentAllowed {
2010
+ #names = new Set;
2011
+ #offers = new Map;
2012
+ get names() {
2013
+ return [...this.#names].sort();
2014
+ }
2015
+ missing(names) {
2016
+ return names.filter((name) => !this.#names.has(name));
2017
+ }
2018
+ offer(approvalId, names) {
2019
+ this.#offers.set(approvalId, names);
2020
+ }
2021
+ settle(approvalId, remember) {
2022
+ const names = this.#offers.get(approvalId) ?? [];
2023
+ this.#offers.delete(approvalId);
2024
+ if (!remember)
2025
+ return [];
2026
+ for (const name of names)
2027
+ this.#names.add(name);
2028
+ return names;
2029
+ }
2030
+ covered() {
2031
+ return [...this.#offers].filter(([, names]) => !this.missing(names).length).map(([approvalId]) => approvalId);
2032
+ }
2033
+ clear() {
2034
+ const count = this.#names.size;
2035
+ this.#names.clear();
2036
+ return count;
2037
+ }
2038
+ }
2039
+
2040
+ // pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentCommandLine.ts
2041
+ import path7 from "path";
2042
+
2043
+ class CodeAgentCommandLine {
2044
+ static networkClients = [
2045
+ "curl",
2046
+ "wget",
2047
+ "nc",
2048
+ "ncat",
2049
+ "netcat",
2050
+ "socat",
2051
+ "telnet",
2052
+ "ssh",
2053
+ "scp",
2054
+ "sftp",
2055
+ "rsync",
2056
+ "ftp"
2057
+ ];
2058
+ static wrappers = [
2059
+ "sudo",
2060
+ "env",
2061
+ "command",
2062
+ "exec",
2063
+ "nohup",
2064
+ "time",
2065
+ "timeout",
2066
+ "nice",
2067
+ "watch",
2068
+ "stdbuf",
2069
+ "xargs"
2070
+ ];
2071
+ static alwaysAsked = new Set([
2072
+ ...CodeAgentCommandLine.networkClients,
2073
+ ...CodeAgentCommandLine.wrappers,
2074
+ "sh",
2075
+ "bash",
2076
+ "zsh",
2077
+ "dash",
2078
+ "ksh",
2079
+ "fish",
2080
+ "eval",
2081
+ "builtin",
2082
+ "source",
2083
+ ".",
2084
+ "trap",
2085
+ "alias",
2086
+ "coproc",
2087
+ "export",
2088
+ "declare",
2089
+ "typeset",
2090
+ "readonly",
2091
+ "rm",
2092
+ "git push",
2093
+ "npm publish",
2094
+ "pnpm publish",
2095
+ "yarn publish",
2096
+ "yarn npm",
2097
+ "bun publish",
2098
+ "cargo publish",
2099
+ "docker push",
2100
+ "gh api"
2101
+ ]);
2102
+ static harmlessVariables = new Set([
2103
+ "CI",
2104
+ "NODE_ENV",
2105
+ "FORCE_COLOR",
2106
+ "NO_COLOR",
2107
+ "TZ",
2108
+ "LANG",
2109
+ "LC_ALL",
2110
+ "TERM",
2111
+ "DEBUG",
2112
+ "PORT"
2113
+ ]);
2114
+ static #subcommandDepth = new Map([
2115
+ ["git", 1],
2116
+ ["bun", 1],
2117
+ ["bunx", 1],
2118
+ ["npm", 1],
2119
+ ["npx", 1],
2120
+ ["pnpm", 1],
2121
+ ["yarn", 1],
2122
+ ["akan", 1],
2123
+ ["docker", 1],
2124
+ ["kubectl", 1],
2125
+ ["helm", 1],
2126
+ ["cargo", 1],
2127
+ ["go", 1],
2128
+ ["gh", 2]
2129
+ ]);
2130
+ static #reserved = new Set([
2131
+ "if",
2132
+ "then",
2133
+ "else",
2134
+ "elif",
2135
+ "fi",
2136
+ "for",
2137
+ "while",
2138
+ "until",
2139
+ "do",
2140
+ "done",
2141
+ "case",
2142
+ "esac",
2143
+ "select",
2144
+ "function",
2145
+ "in",
2146
+ "coproc"
2147
+ ]);
2148
+ static #runsItsArguments = new Set(["-exec", "-execdir", "-ok", "-okdir"]);
2149
+ static #assignment = /^([A-Za-z_]\w*)(\+?=)(.*)$/s;
2150
+ static #plainValue = /^[\w@%+.,:/*-]*$/;
2151
+ static #socketPath = /^\/+dev\/+(?:tcp|udp)\//i;
2152
+ static #program = /^[\w@%+.,:/~-]+$/;
2153
+ static #subcommand = /^[A-Za-z0-9@][\w@.:/-]*$/;
2154
+ static #redirectOperator = /^(?:<<<|<<|<>|<&|<|>>|>&|>\||>)/;
2155
+ #line;
2156
+ #commands = [];
2157
+ #at;
2158
+ #words = [];
2159
+ #word;
2160
+ #redirect;
2161
+ constructor(line, at = 0) {
2162
+ this.#line = line;
2163
+ this.#at = at;
2164
+ }
2165
+ static allowable(line) {
2166
+ const parsed = new CodeAgentCommandLine(line);
2167
+ if (!parsed.#read())
2168
+ return;
2169
+ const names = [];
2170
+ for (const words of parsed.#commands) {
2171
+ const name = CodeAgentCommandLine.#nameOf(words);
2172
+ if (!name)
2173
+ return;
2174
+ names.push(name);
2175
+ }
2176
+ return names.length ? [...new Set(names)] : undefined;
2177
+ }
2178
+ static #nameOf(words) {
2179
+ const [program] = words;
2180
+ if (!program || program.expands || !CodeAgentCommandLine.#program.test(program.text))
2181
+ return;
2182
+ const base = path7.posix.basename(program.text).toLowerCase();
2183
+ if (CodeAgentCommandLine.#reserved.has(base) || CodeAgentCommandLine.alwaysAsked.has(base))
2184
+ return;
2185
+ if (words.some((word) => CodeAgentCommandLine.#runsItsArguments.has(word.text)))
2186
+ return;
2187
+ if (base === "docker" && words.some((word) => word.text === "push" || word.text.startsWith("--push")))
2188
+ return;
2189
+ const depth = CodeAgentCommandLine.#subcommandDepth.get(base);
2190
+ if (!depth)
2191
+ return program.text;
2192
+ const subs = words.slice(1, 1 + depth);
2193
+ if (!subs.length || subs.some((sub) => sub.expands || !CodeAgentCommandLine.#subcommand.test(sub.text)))
2194
+ return;
2195
+ const names = subs.map((_, idx) => subs.slice(0, idx + 1).map((sub) => sub.text).join(" "));
2196
+ if (names.some((name) => CodeAgentCommandLine.alwaysAsked.has(`${base} ${name}`)))
2197
+ return;
2198
+ return `${program.text} ${names.at(-1)}`;
2199
+ }
2200
+ static #harmless(word) {
2201
+ const [, name = "", operator, value = ""] = CodeAgentCommandLine.#assignment.exec(word.text) ?? [];
2202
+ if (operator !== "=" || word.quoted || word.expands)
2203
+ return false;
2204
+ return CodeAgentCommandLine.harmlessVariables.has(name) && CodeAgentCommandLine.#plainValue.test(value);
2205
+ }
2206
+ #read(close) {
2207
+ while (this.#at < this.#line.length) {
2208
+ const char = this.#line[this.#at] ?? "";
2209
+ if (char === close) {
2210
+ this.#at += 1;
2211
+ return this.#endCommand();
2212
+ }
2213
+ if (!this.#step(char))
2214
+ return false;
2215
+ }
2216
+ return close === undefined && this.#endCommand();
2217
+ }
2218
+ #step(char) {
2219
+ const next = this.#line[this.#at + 1];
2220
+ switch (char) {
2221
+ case " ":
2222
+ case "\t":
2223
+ this.#at += 1;
2224
+ return this.#endWord();
2225
+ case `
2226
+ `:
2227
+ case ";":
2228
+ this.#at += 1;
2229
+ return this.#endCommand();
2230
+ case "&":
2231
+ if (next === ">") {
2232
+ this.#at += 1;
2233
+ return this.#endWord() && this.#redirection();
2234
+ }
2235
+ this.#at += next === "&" ? 2 : 1;
2236
+ return this.#endCommand();
2237
+ case "|":
2238
+ this.#at += next === "|" || next === "&" ? 2 : 1;
2239
+ return this.#endCommand();
2240
+ case "(":
2241
+ if (this.#word)
2242
+ return false;
2243
+ this.#at += 1;
2244
+ return this.#endCommand() && this.#nested();
2245
+ case "<":
2246
+ case ">":
2247
+ return this.#redirection();
2248
+ case "'":
2249
+ return this.#single();
2250
+ case '"':
2251
+ return this.#double();
2252
+ case "$":
2253
+ return this.#dollar();
2254
+ case ")":
2255
+ case "`":
2256
+ return false;
2257
+ case "\\":
2258
+ if (next === undefined)
2259
+ return false;
2260
+ this.#at += 2;
2261
+ if (next === `
2262
+ `)
2263
+ return true;
2264
+ this.#quote();
2265
+ this.#append(next);
2266
+ return true;
2267
+ case "#":
2268
+ if (this.#word)
2269
+ break;
2270
+ while (this.#at < this.#line.length && this.#line[this.#at] !== `
2271
+ `)
2272
+ this.#at += 1;
2273
+ return true;
2274
+ }
2275
+ this.#at += 1;
2276
+ this.#append(char);
2277
+ return true;
2278
+ }
2279
+ #append(text) {
2280
+ this.#word ??= { text: "", expands: false, quoted: false };
2281
+ this.#word.text += text;
2282
+ }
2283
+ #quote() {
2284
+ this.#append("");
2285
+ if (this.#word)
2286
+ this.#word.quoted = true;
2287
+ }
2288
+ #expand() {
2289
+ this.#append("");
2290
+ if (this.#word)
2291
+ this.#word.expands = true;
2292
+ }
2293
+ #endWord() {
2294
+ const word = this.#word;
2295
+ const redirect = this.#redirect;
2296
+ if (!word)
2297
+ return true;
2298
+ this.#word = undefined;
2299
+ if (!redirect) {
2300
+ this.#words.push(word);
2301
+ return true;
2302
+ }
2303
+ this.#redirect = undefined;
2304
+ if (redirect === "here")
2305
+ return true;
2306
+ if (word.expands)
2307
+ return false;
2308
+ if (redirect === "read")
2309
+ return !CodeAgentCommandLine.#socketPath.test(word.text);
2310
+ return redirect === "dup" ? /^(?:\d+|-)$/.test(word.text) : word.text === "/dev/null";
2311
+ }
2312
+ #endCommand() {
2313
+ if (!this.#endWord() || this.#redirect)
2314
+ return false;
2315
+ const from = this.#words.findIndex((word) => !CodeAgentCommandLine.#assignment.test(word.text));
2316
+ const assigned = from < 0 ? this.#words : this.#words.slice(0, from);
2317
+ if (!assigned.every((word) => CodeAgentCommandLine.#harmless(word)))
2318
+ return false;
2319
+ if (from >= 0)
2320
+ this.#commands.push(this.#words.slice(from));
2321
+ this.#words = [];
2322
+ return true;
2323
+ }
2324
+ #redirection() {
2325
+ if (this.#word && !this.#word.expands && !this.#word.quoted && /^\d+$/.test(this.#word.text))
2326
+ this.#word = undefined;
2327
+ else if (!this.#endWord())
2328
+ return false;
2329
+ const operator = CodeAgentCommandLine.#redirectOperator.exec(this.#line.slice(this.#at, this.#at + 3))?.[0] ?? "";
2330
+ this.#at += operator.length;
2331
+ if (!operator || operator === "<<" || this.#redirect || this.#line[this.#at] === "(")
2332
+ return false;
2333
+ if (operator === "<<<")
2334
+ this.#redirect = "here";
2335
+ else if (operator === "<")
2336
+ this.#redirect = "read";
2337
+ else
2338
+ this.#redirect = operator.endsWith("&") ? "dup" : "write";
2339
+ return true;
2340
+ }
2341
+ #single() {
2342
+ const end = this.#line.indexOf("'", this.#at + 1);
2343
+ if (end < 0)
2344
+ return false;
2345
+ this.#quote();
2346
+ this.#append(this.#line.slice(this.#at + 1, end));
2347
+ this.#at = end + 1;
2348
+ return true;
2349
+ }
2350
+ #double() {
2351
+ this.#at += 1;
2352
+ this.#quote();
2353
+ while (this.#at < this.#line.length) {
2354
+ const char = this.#line[this.#at] ?? "";
2355
+ if (char === '"') {
2356
+ this.#at += 1;
2357
+ return true;
2358
+ }
2359
+ if (char === "`")
2360
+ return false;
2361
+ if (char === "$") {
2362
+ if (!this.#dollar())
2363
+ return false;
2364
+ continue;
2365
+ }
2366
+ if (char !== "\\") {
2367
+ this.#at += 1;
2368
+ this.#append(char);
2369
+ continue;
2370
+ }
2371
+ const next = this.#line[this.#at + 1];
2372
+ if (next === undefined)
2373
+ return false;
2374
+ this.#at += 2;
2375
+ if (next !== `
2376
+ `)
2377
+ this.#append('$`"\\'.includes(next) ? next : `\\${next}`);
2378
+ }
2379
+ return false;
2380
+ }
2381
+ #dollar() {
2382
+ const rest = this.#line.slice(this.#at + 1);
2383
+ if (rest.startsWith("((") || rest.startsWith("'") || rest.startsWith('"'))
2384
+ return false;
2385
+ if (rest.startsWith("(")) {
2386
+ this.#at += 2;
2387
+ this.#expand();
2388
+ return this.#nested();
2389
+ }
2390
+ if (rest.startsWith("{")) {
2391
+ const end = rest.indexOf("}");
2392
+ if (end < 0 || /[$`]/.test(rest.slice(1, end)))
2393
+ return false;
2394
+ this.#at += end + 2;
2395
+ this.#expand();
2396
+ return true;
2397
+ }
2398
+ const name = /^(?:\w+|[?!#@*$-])/.exec(rest)?.[0];
2399
+ this.#at += 1 + (name?.length ?? 0);
2400
+ if (name)
2401
+ this.#expand();
2402
+ else
2403
+ this.#append("$");
2404
+ return true;
2405
+ }
2406
+ #nested() {
2407
+ const inner = new CodeAgentCommandLine(this.#line, this.#at);
2408
+ const read = inner.#read(")");
2409
+ this.#at = inner.#at;
2410
+ this.#commands.push(...inner.#commands);
2411
+ return read;
2412
+ }
2413
+ }
2414
+
2415
+ // pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentGate.ts
2007
2416
  var writeTools = new Set(["write", "edit"]);
2008
2417
  var commandTools = new Set(["bash"]);
2009
- 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;
2418
+ var networkClients = new RegExp(String.raw`(?:^[ \t]*|[\n;&|(\`{][ \t]*|\s-\w*c\s+['"][ \t]*|\s-exec(?:dir)?\s+)(?:(?:[A-Za-z_]\w*=\S*|${CodeAgentCommandLine.wrappers.join("|")}|-\S+|\d\S*)[ \t]+)*(?:[^\s;&|()\`'"]*\/)?(${CodeAgentCommandLine.networkClients.join("|")})(?=$|[\s;&|)\`'"])`, "g");
2010
2419
  var urlPattern = /\b[a-z][a-z0-9+.-]*:\/\/[^\s'"`<>|;&()]+/gi;
2011
2420
  var hostPortPattern = /(?<=^|[\s'"=])(?:\[[0-9a-f:.]+\]|[a-z0-9.-]+):\d{1,5}(?=[/?#\s'"]|$)/gi;
2012
2421
  var ordinaryNames = ["index.ts", "a.ts", "a.tsx", "a.js", "a.json", "a.yaml", "a.md", "a.txt", "a.log", "README"];
2013
2422
 
2014
2423
  class CodeAgentGate2 {
2424
+ allowed = new CodeAgentAllowed;
2015
2425
  #profile;
2016
2426
  #realRoot;
2017
2427
  #deny;
@@ -2020,11 +2430,11 @@ class CodeAgentGate2 {
2020
2430
  #nameRules;
2021
2431
  constructor(profile) {
2022
2432
  this.#profile = profile;
2023
- this.#realRoot = CodeAgentGate2.#real(path7.resolve(profile.paths.root));
2433
+ this.#realRoot = CodeAgentGate2.#real(path8.resolve(profile.paths.root));
2024
2434
  const home = homedir();
2025
- const codeHome = path7.resolve(akanCodePaths2.globalDir());
2435
+ const codeHome = path8.resolve(akanCodePaths2.globalDir());
2026
2436
  const patterns = [
2027
- ...(profile.paths.deny ?? []).map((pattern) => pattern.startsWith("~/") ? path7.join(home, pattern.slice(2)) : pattern),
2437
+ ...(profile.paths.deny ?? []).map((pattern) => pattern.startsWith("~/") ? path8.join(home, pattern.slice(2)) : pattern),
2028
2438
  ...profile.paths.deny?.length ? [`${codeHome}/**`] : []
2029
2439
  ];
2030
2440
  this.#deny = patterns.map((pattern) => new Bun.Glob(pattern));
@@ -2058,7 +2468,17 @@ class CodeAgentGate2 {
2058
2468
  return { approval: network, strict: true };
2059
2469
  if (!this.#needsApproval(toolName))
2060
2470
  return {};
2061
- return { approval: CodeAgentGate2.#summarize(toolName, args) };
2471
+ const names = command && commandTools.has(toolName) ? CodeAgentGate2.#allowable(command) : undefined;
2472
+ const remember = names && this.allowed.missing(names);
2473
+ if (remember && !remember.length)
2474
+ return {};
2475
+ return { approval: CodeAgentGate2.#summarize(toolName, args), ...remember ? { remember } : {} };
2476
+ }
2477
+ static #allowable(command) {
2478
+ return CodeAgentGate2.#networkClientsIn(command).length ? undefined : CodeAgentCommandLine.allowable(command);
2479
+ }
2480
+ static #networkClientsIn(command) {
2481
+ return [...command.matchAll(networkClients)].map((match) => match[1]);
2062
2482
  }
2063
2483
  #deniedCommandReason(command) {
2064
2484
  const hit = this.#deniedFragments.find((fragment) => command.includes(fragment)) ?? CodeAgentGate2.#wordsOf(command).find((word) => this.#namesDeniedFile(word));
@@ -2068,25 +2488,25 @@ class CodeAgentGate2 {
2068
2488
  }
2069
2489
  #namesDeniedFile(word) {
2070
2490
  const expanded = CodeAgentGate2.#expandHome(word);
2071
- const name = path7.basename(expanded);
2491
+ const name = path8.basename(expanded);
2072
2492
  if (/[*?[{]/.test(name)) {
2073
2493
  const swept = new Bun.Glob(name);
2074
2494
  if (ordinaryNames.some((ordinary) => swept.match(ordinary)))
2075
2495
  return false;
2076
2496
  return this.#nameRules.some((rule) => rule.samples.some((sample) => swept.match(sample)));
2077
2497
  }
2078
- const absolute = path7.resolve(this.#profile.paths.root, expanded);
2498
+ const absolute = path8.resolve(this.#profile.paths.root, expanded);
2079
2499
  return this.#deny.some((glob) => glob.match(expanded) || glob.match(absolute));
2080
2500
  }
2081
2501
  #deniedReason(target) {
2082
- const absolute = path7.resolve(this.#profile.paths.root, CodeAgentGate2.#expandPath(target));
2083
- const relative = path7.relative(path7.resolve(this.#profile.paths.root), absolute);
2084
- if (relative === ".." || relative.startsWith(`..${path7.sep}`) || path7.isAbsolute(relative))
2502
+ const absolute = path8.resolve(this.#profile.paths.root, CodeAgentGate2.#expandPath(target));
2503
+ const relative = path8.relative(path8.resolve(this.#profile.paths.root), absolute);
2504
+ if (relative === ".." || relative.startsWith(`..${path8.sep}`) || path8.isAbsolute(relative))
2085
2505
  return `Path is outside the agent root (${this.#profile.paths.root}).`;
2086
2506
  const real = CodeAgentGate2.#real(absolute);
2087
2507
  const candidates = [
2088
2508
  [absolute, relative],
2089
- [real, path7.relative(this.#realRoot, real)]
2509
+ [real, path8.relative(this.#realRoot, real)]
2090
2510
  ];
2091
2511
  if (candidates.some(([candidate, rel]) => this.#deny.some((glob) => glob.match(candidate) || glob.match(rel))))
2092
2512
  return "Path is on the profile's deny list (secrets and environment files are never readable).";
@@ -2108,7 +2528,7 @@ class CodeAgentGate2 {
2108
2528
  const command = stringArg(args, "command");
2109
2529
  if (!command || !commandTools.has(toolName))
2110
2530
  return;
2111
- const clients = [...command.matchAll(networkClients)].map((match) => match[1]);
2531
+ const clients = CodeAgentGate2.#networkClientsIn(command);
2112
2532
  if (!clients.length)
2113
2533
  return;
2114
2534
  const hosts = [
@@ -2147,19 +2567,19 @@ class CodeAgentGate2 {
2147
2567
  }
2148
2568
  static #expandHome(value) {
2149
2569
  const home = /^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/.exec(value);
2150
- return home ? path7.join(homedir(), value.slice(home[0].length)) : value;
2570
+ return home ? path8.join(homedir(), value.slice(home[0].length)) : value;
2151
2571
  }
2152
2572
  static #real(absolute) {
2153
2573
  const rest = [];
2154
2574
  let head = absolute;
2155
2575
  for (;; ) {
2156
2576
  try {
2157
- return path7.join(realpathSync(head), ...rest);
2577
+ return path8.join(realpathSync(head), ...rest);
2158
2578
  } catch {
2159
- const parent = path7.dirname(head);
2579
+ const parent = path8.dirname(head);
2160
2580
  if (parent === head)
2161
2581
  return absolute;
2162
- rest.unshift(path7.basename(head));
2582
+ rest.unshift(path8.basename(head));
2163
2583
  head = parent;
2164
2584
  }
2165
2585
  }
@@ -2254,7 +2674,7 @@ class CodeAgentProxy {
2254
2674
 
2255
2675
  // pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentSuspended.ts
2256
2676
  import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync4, rmSync, writeFileSync } from "fs";
2257
- import path8 from "path";
2677
+ import path9 from "path";
2258
2678
 
2259
2679
  class CodeAgentSuspended {
2260
2680
  #file;
@@ -2264,7 +2684,7 @@ class CodeAgentSuspended {
2264
2684
  this.#state = CodeAgentSuspended.#read(file);
2265
2685
  }
2266
2686
  static fileOf(sessionDir, sessionId) {
2267
- return sessionDir ? path8.join(sessionDir, `${sessionId}.suspended.json`) : null;
2687
+ return sessionDir ? path9.join(sessionDir, `${sessionId}.suspended.json`) : null;
2268
2688
  }
2269
2689
  get question() {
2270
2690
  return this.#state.question;
@@ -2309,7 +2729,7 @@ class CodeAgentSuspended {
2309
2729
  rmSync(this.#file, { force: true });
2310
2730
  return;
2311
2731
  }
2312
- mkdirSync2(path8.dirname(this.#file), { recursive: true });
2732
+ mkdirSync2(path9.dirname(this.#file), { recursive: true });
2313
2733
  writeFileSync(this.#file, `${JSON.stringify(this.#state)}
2314
2734
  `);
2315
2735
  }
@@ -2376,7 +2796,7 @@ import {
2376
2796
  statSync as statSync5,
2377
2797
  writeFileSync as writeFileSync2
2378
2798
  } from "fs";
2379
- import path9 from "path";
2799
+ import path10 from "path";
2380
2800
  class CodeMailbox2 {
2381
2801
  static staleMs = 20000;
2382
2802
  static beatMs = 5000;
@@ -2395,11 +2815,11 @@ class CodeMailbox2 {
2395
2815
  this.#name = name;
2396
2816
  }
2397
2817
  get inbox() {
2398
- return path9.join(this.#dir, "inbox", `${this.#id}.jsonl`);
2818
+ return path10.join(this.#dir, "inbox", `${this.#id}.jsonl`);
2399
2819
  }
2400
2820
  open(cwd, onMail) {
2401
- mkdirSync3(path9.join(this.#dir, "live"), { recursive: true });
2402
- mkdirSync3(path9.join(this.#dir, "inbox"), { recursive: true });
2821
+ mkdirSync3(path10.join(this.#dir, "live"), { recursive: true });
2822
+ mkdirSync3(path10.join(this.#dir, "inbox"), { recursive: true });
2403
2823
  this.#read = readJsonLines(this.inbox).length;
2404
2824
  this.beat(cwd);
2405
2825
  this.#beat = setInterval(() => this.beat(cwd), CodeMailbox2.beatMs);
@@ -2416,7 +2836,7 @@ class CodeMailbox2 {
2416
2836
  this.#beat = null;
2417
2837
  this.#poll = null;
2418
2838
  try {
2419
- rmSync2(path9.join(this.#dir, "live", `${this.#id}.json`), { force: true });
2839
+ rmSync2(path10.join(this.#dir, "live", `${this.#id}.json`), { force: true });
2420
2840
  } catch {}
2421
2841
  }
2422
2842
  rename(name, cwd) {
@@ -2426,15 +2846,15 @@ class CodeMailbox2 {
2426
2846
  beat(cwd) {
2427
2847
  const peer = { id: this.#id, name: this.#name, cwd, pid: process.pid, at: Date.now() };
2428
2848
  try {
2429
- writeFileSync2(path9.join(this.#dir, "live", `${this.#id}.json`), JSON.stringify(peer));
2849
+ writeFileSync2(path10.join(this.#dir, "live", `${this.#id}.json`), JSON.stringify(peer));
2430
2850
  } catch {}
2431
2851
  }
2432
2852
  peers() {
2433
- const dir = path9.join(this.#dir, "live");
2853
+ const dir = path10.join(this.#dir, "live");
2434
2854
  if (!existsSync8(dir))
2435
2855
  return [];
2436
2856
  const now = Date.now();
2437
- return readdirSync3(dir).filter((entry) => entry.endsWith(".json")).map((entry) => CodeMailbox2.#peer(path9.join(dir, entry))).filter((peer) => !!peer && peer.id !== this.#id && now - peer.at < CodeMailbox2.staleMs).sort((left, right) => right.at - left.at);
2857
+ return readdirSync3(dir).filter((entry) => entry.endsWith(".json")).map((entry) => CodeMailbox2.#peer(path10.join(dir, entry))).filter((peer) => !!peer && peer.id !== this.#id && now - peer.at < CodeMailbox2.staleMs).sort((left, right) => right.at - left.at);
2438
2858
  }
2439
2859
  find(target) {
2440
2860
  const needle = target.trim().toLowerCase();
@@ -2452,8 +2872,8 @@ class CodeMailbox2 {
2452
2872
  throw new Error(`Too many messages: ${CodeMailbox2.sendsPerMinute} a minute is the ceiling.`);
2453
2873
  this.#sent.push(now);
2454
2874
  const mail = { at: now, from: this.#id, fromName: this.#name, text };
2455
- mkdirSync3(path9.join(this.#dir, "inbox"), { recursive: true });
2456
- appendFileSync(path9.join(this.#dir, "inbox", `${to}.jsonl`), `${JSON.stringify(mail)}
2875
+ mkdirSync3(path10.join(this.#dir, "inbox"), { recursive: true });
2876
+ appendFileSync(path10.join(this.#dir, "inbox", `${to}.jsonl`), `${JSON.stringify(mail)}
2457
2877
  `);
2458
2878
  }
2459
2879
  #drain() {
@@ -2477,7 +2897,7 @@ class CodeMailbox2 {
2477
2897
  // pkgs/@akanjs/devkit/codeAgent/agent/CodeSessionFork.ts
2478
2898
  import { randomBytes } from "crypto";
2479
2899
  import { readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
2480
- import path10 from "path";
2900
+ import path11 from "path";
2481
2901
  import { codeAgentSessionName } from "akanjs/common";
2482
2902
  class CodeSessionFork2 {
2483
2903
  static fork(dir, id, name) {
@@ -2497,7 +2917,7 @@ class CodeSessionFork2 {
2497
2917
  first.id = forked;
2498
2918
  first.timestamp = at.toISOString();
2499
2919
  records.push(CodeSessionFork2.#named(records, name ?? CodeSessionFork2.#nameOf(records), at));
2500
- const file = path10.join(dir, `${at.toISOString().replace(/[:.]/g, "-")}_${forked}.jsonl`);
2920
+ const file = path11.join(dir, `${at.toISOString().replace(/[:.]/g, "-")}_${forked}.jsonl`);
2501
2921
  writeFileSync3(file, `${records.map((record) => JSON.stringify(record)).join(`
2502
2922
  `)}
2503
2923
  `);
@@ -2521,6 +2941,14 @@ class CodeSessionFork2 {
2521
2941
  }
2522
2942
 
2523
2943
  // pkgs/@akanjs/devkit/codeAgent/agent/CodeAgent.ts
2944
+ var textOf = (content) => {
2945
+ if (typeof content === "string")
2946
+ return content.trim();
2947
+ if (!Array.isArray(content))
2948
+ return "";
2949
+ return content.map((part) => typeof part === "object" && part && ("text" in part) ? String(part.text) : "").join("").trim();
2950
+ };
2951
+
2524
2952
  class CodeAgent2 {
2525
2953
  #profile;
2526
2954
  #gate;
@@ -2615,6 +3043,9 @@ class CodeAgent2 {
2615
3043
  get profile() {
2616
3044
  return this.#profile;
2617
3045
  }
3046
+ get allowed() {
3047
+ return this.#gate.allowed;
3048
+ }
2618
3049
  get canSeeImages() {
2619
3050
  const model = this.#session?.model;
2620
3051
  return model ? akanCodeModelSupportsImages2(model) : false;
@@ -2695,19 +3126,12 @@ ${mail.text}`).catch((error) => this.#emit({ type: "notice", level: "error", mes
2695
3126
  for (const message of session.messages) {
2696
3127
  if (message.role !== "user" && message.role !== "assistant")
2697
3128
  continue;
2698
- const text = CodeAgent2.#textOf(message.content);
3129
+ const text = textOf(message.content);
2699
3130
  if (text)
2700
3131
  this.#emit({ type: "message", turnId, role: message.role, text });
2701
3132
  }
2702
3133
  this.#emitContextNow();
2703
3134
  }
2704
- static #textOf(content) {
2705
- if (typeof content === "string")
2706
- return content.trim();
2707
- if (!Array.isArray(content))
2708
- return "";
2709
- return content.map((part) => typeof part === "object" && part && ("text" in part) ? String(part.text) : "").join("").trim();
2710
- }
2711
3135
  on(listener) {
2712
3136
  this.#listeners.add(listener);
2713
3137
  return () => this.#listeners.delete(listener);
@@ -2756,9 +3180,13 @@ ${mail.text}`).catch((error) => this.#emit({ type: "notice", level: "error", mes
2756
3180
  Continue the task.`);
2757
3181
  return true;
2758
3182
  }
2759
- async approve(approvalId, approved) {
3183
+ async approve(approvalId, approved, remember) {
2760
3184
  if (this.#asks.resolveApproval(approvalId, approved)) {
2761
- this.#emit({ type: "approval_resolved", approvalId, approved });
3185
+ const remembered = this.allowed.settle(approvalId, approved && remember === "session");
3186
+ this.#emit({ type: "approval_resolved", approvalId, approved, ...remembered.length ? { remembered } : {} });
3187
+ for (const covered of this.allowed.covered())
3188
+ if (this.#asks.resolveApproval(covered, true))
3189
+ this.#emit({ type: "approval_resolved", approvalId: covered, approved: true });
2762
3190
  return true;
2763
3191
  }
2764
3192
  if (this.#profile.interaction.approval !== "suspend")
@@ -2941,7 +3369,7 @@ Continue the task.`);
2941
3369
  return;
2942
3370
  if (verdict.strict && !this.#profile.ui.canPrompt)
2943
3371
  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.");
2944
- const approved = await this.#requestApproval(event.toolCallId, event.toolName, event.input, verdict.approval);
3372
+ const approved = await this.#requestApproval(event.toolCallId, event.toolName, verdict.approval, verdict.remember);
2945
3373
  if (approved)
2946
3374
  return;
2947
3375
  return this.#refuse(event.toolCallId, event.toolName, event.input, "The user declined this action.");
@@ -2954,24 +3382,31 @@ Continue the task.`);
2954
3382
  this.#emit(body);
2955
3383
  return { block: true, reason };
2956
3384
  }
2957
- async#requestApproval(toolCallId, name, args, summary) {
3385
+ async#requestApproval(toolCallId, name, summary, offered) {
2958
3386
  if (!this.#profile.ui.canPrompt)
2959
3387
  return true;
2960
3388
  const approvalId = this.#asks.nextId("a");
3389
+ const suspends = this.#profile.interaction.approval === "suspend";
3390
+ const remember = suspends ? undefined : offered;
2961
3391
  const request = {
2962
3392
  approvalId,
2963
3393
  toolCallId,
2964
3394
  name,
2965
3395
  summary: codeAgentClip6(summary, codeAgentLabelChars2),
2966
- policy: this.#profile.approval
3396
+ policy: this.#profile.approval,
3397
+ ...remember ? { remember } : {}
2967
3398
  };
2968
3399
  this.#emit({ type: "approval", request });
2969
- if (this.#profile.interaction.approval === "suspend") {
3400
+ if (suspends) {
2970
3401
  this.#suspended.addApproval(request);
2971
3402
  this.#mapper.noteOutcome("awaiting");
2972
3403
  return false;
2973
3404
  }
2974
- return await this.#asks.openApproval(approvalId);
3405
+ if (remember)
3406
+ this.allowed.offer(approvalId, remember);
3407
+ const approved = await this.#asks.openApproval(approvalId);
3408
+ this.allowed.settle(approvalId, false);
3409
+ return approved;
2975
3410
  }
2976
3411
  async ask(spec) {
2977
3412
  const question = { questionId: this.#asks.nextId("q"), ...spec };