@akanjs/devkit 3.3.0-rc.6 → 3.3.0-rc.8
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/CHANGELOG.md +186 -0
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanConfig/akanConfig.test.ts +55 -7
- package/akanConfig/akanConfig.ts +12 -65
- package/akanConfig/dockerImage.ts +17 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/frontendBuild/buildRouteClient.test.ts +2 -7
- package/frontendBuild/clientEntryDiscovery.ts +2 -2
- package/frontendBuild/devBarrelImports.test.ts +30 -0
- package/frontendBuild/devBarrelImports.ts +2 -2
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.ts +8 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/mobile/nativeConfig.test.ts +79 -0
- package/mobile/nativeConfig.ts +35 -6
- package/package.json +14 -169
- package/packageExports.test.ts +38 -24
- package/transforms/barrelAnalyzer.ts +2 -2
- package/transforms/transforms.test.ts +3 -3
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workspace/getRelatedCnsts.ts +7 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { CodeAgentCommandLine } from "./CodeAgentCommandLine";
|
|
3
|
+
|
|
4
|
+
const names = (line: string) => CodeAgentCommandLine.allowable(line);
|
|
5
|
+
|
|
6
|
+
describe("CodeAgentCommandLine.allowable", () => {
|
|
7
|
+
test("a command is named by its program, and by its sub-command where that is what matters", () => {
|
|
8
|
+
expect(names("ls -la apps")).toEqual(["ls"]);
|
|
9
|
+
expect(names("git status --short")).toEqual(["git status"]);
|
|
10
|
+
expect(names("bun test --isolate ./a.test.ts")).toEqual(["bun test"]);
|
|
11
|
+
expect(names("bun x cowsay hi")).toEqual(["bun x"]);
|
|
12
|
+
expect(names("kubectl get pods -n web")).toEqual(["kubectl get"]);
|
|
13
|
+
expect(names("akan verify @akanjs/cli")).toEqual(["akan verify"]);
|
|
14
|
+
expect(names("bunx tsc --noEmit")).toEqual(["bunx tsc"]);
|
|
15
|
+
expect(names("./scripts/check.sh --all")).toEqual(["./scripts/check.sh"]);
|
|
16
|
+
expect(names("/usr/bin/git diff")).toEqual(["/usr/bin/git diff"]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("a harmless variable set in front of a command does not change its name", () => {
|
|
20
|
+
expect(names("CI=1 NODE_ENV=test bun test")).toEqual(["bun test"]);
|
|
21
|
+
expect(
|
|
22
|
+
names("FORCE_COLOR=0 NO_COLOR=1 TZ=UTC LANG=C LC_ALL=C.UTF-8 TERM=dumb DEBUG=app:* PORT=3000 bun test"),
|
|
23
|
+
).toEqual(["bun test"]);
|
|
24
|
+
expect(names("CI=1; ls")).toEqual(["ls"]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("any other variable set in front of a command, or one whose value is not a plain word, has no name to remember", () => {
|
|
28
|
+
for (const line of [
|
|
29
|
+
"GIT_SSH_COMMAND='ssh -i key' git status",
|
|
30
|
+
"PATH=/tmp/bin git status",
|
|
31
|
+
"GIT_PAGER=less git log",
|
|
32
|
+
"LD_PRELOAD=./x.so ls",
|
|
33
|
+
"BASH_ENV=./x.sh ls",
|
|
34
|
+
"NODE_OPTIONS=--require=./x.js bun test",
|
|
35
|
+
"CI=1 PATH=/tmp/bin ls",
|
|
36
|
+
"PATH=/tmp/bin; git status",
|
|
37
|
+
'CI="1" bun test',
|
|
38
|
+
"CI=\\1 bun test",
|
|
39
|
+
"CI=$X bun test",
|
|
40
|
+
"CI=$(date) bun test",
|
|
41
|
+
"CI+=1 bun test",
|
|
42
|
+
"TZ=~/zone ls",
|
|
43
|
+
"'CI=1' ls",
|
|
44
|
+
])
|
|
45
|
+
expect(names(line)).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("every command of a compound line is named once", () => {
|
|
49
|
+
expect(names("cd apps && bun test; git status | head -5 || git status")).toEqual([
|
|
50
|
+
"cd",
|
|
51
|
+
"bun test",
|
|
52
|
+
"git status",
|
|
53
|
+
"head",
|
|
54
|
+
]);
|
|
55
|
+
expect(names("(cd apps && ls) & wait")).toEqual(["cd", "ls", "wait"]);
|
|
56
|
+
expect(names('echo "at $(git rev-parse HEAD)" $(date +%s)')).toEqual(["git rev-parse", "date", "echo"]);
|
|
57
|
+
expect(names("bun test\ngit diff --stat")).toEqual(["bun test", "git diff"]);
|
|
58
|
+
expect(names("bun test \\\n --bail # stop early")).toEqual(["bun test"]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("quotes keep a separator inside an argument, and are read through in a program's name", () => {
|
|
62
|
+
expect(names(`git commit -m "fix: a && b; c | d"`)).toEqual(["git commit"]);
|
|
63
|
+
expect(names(`grep -rn 'a|b' src`)).toEqual(["grep"]);
|
|
64
|
+
expect(names(`'git' "status"`)).toEqual(["git status"]);
|
|
65
|
+
expect(names(`echo \\; done`)).toEqual(["echo"]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("a redirection is read past when it writes no file", () => {
|
|
69
|
+
expect(names("bun test 2>&1 | tail -20")).toEqual(["bun test", "tail"]);
|
|
70
|
+
expect(names("bun test > /dev/null 2>&1")).toEqual(["bun test"]);
|
|
71
|
+
expect(names("bun test &>/dev/null")).toEqual(["bun test"]);
|
|
72
|
+
expect(names("sort < names.txt")).toEqual(["sort"]);
|
|
73
|
+
expect(names("grep -c x <<< hello")).toEqual(["grep"]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("a line that writes a file through a redirection has no name to remember", () => {
|
|
77
|
+
for (const line of ["echo hi > out.txt", "echo hi >> ~/.zshrc", "bun test 2> err.log", "ls &> all.log", "ls >&out"])
|
|
78
|
+
expect(names(line)).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("the always-asked commands have no name to remember, however they are spelled", () => {
|
|
82
|
+
for (const line of [
|
|
83
|
+
"curl https://example.com",
|
|
84
|
+
"ssh deploy@host",
|
|
85
|
+
"git push",
|
|
86
|
+
"git push origin main",
|
|
87
|
+
"/usr/bin/git push",
|
|
88
|
+
`git "push" -f`,
|
|
89
|
+
"g''it pu\\sh",
|
|
90
|
+
"rm -rf build",
|
|
91
|
+
"/bin/rm a.txt",
|
|
92
|
+
"RM a.txt",
|
|
93
|
+
"sudo ls",
|
|
94
|
+
"env FOO=1 ls",
|
|
95
|
+
"timeout 5 bun test",
|
|
96
|
+
"ls | xargs wc -l",
|
|
97
|
+
"sh -c 'ls'",
|
|
98
|
+
"bash scripts/x.sh",
|
|
99
|
+
"eval ls",
|
|
100
|
+
"ls && rm a.txt",
|
|
101
|
+
"echo $(curl https://example.com)",
|
|
102
|
+
'echo "$(rm a.txt)"',
|
|
103
|
+
"(git push)",
|
|
104
|
+
])
|
|
105
|
+
expect(names(line)).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("a command the shell itself uses to run another, or to set what a later one runs, has no name to remember", () => {
|
|
109
|
+
for (const line of [
|
|
110
|
+
"builtin eval ls",
|
|
111
|
+
"source ./x.sh",
|
|
112
|
+
". ./x.sh",
|
|
113
|
+
"trap 'ls' EXIT",
|
|
114
|
+
"alias a='ls'",
|
|
115
|
+
"coproc ls",
|
|
116
|
+
"export PATH=/tmp/bin",
|
|
117
|
+
"declare -x A=1",
|
|
118
|
+
"typeset -x A=1",
|
|
119
|
+
"readonly A=1",
|
|
120
|
+
"ls && export CI=1",
|
|
121
|
+
])
|
|
122
|
+
expect(names(line)).toBeUndefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("a redirection that opens a connection has no name to remember", () => {
|
|
126
|
+
for (const line of [
|
|
127
|
+
"bun test </dev/tcp/host/80",
|
|
128
|
+
"bun test < /dev/udp/host/53",
|
|
129
|
+
"cat <//dev/tcp/host/80",
|
|
130
|
+
"ls > /dev/tcp/host/80",
|
|
131
|
+
"ls 3<>/dev/tcp/host/80",
|
|
132
|
+
"sort < $FILE",
|
|
133
|
+
])
|
|
134
|
+
expect(names(line)).toBeUndefined();
|
|
135
|
+
expect(names('grep -c x <<< "$VALUE"')).toEqual(["grep"]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("a command that sends something out of the machine has no name to remember", () => {
|
|
139
|
+
for (const line of [
|
|
140
|
+
"npm publish",
|
|
141
|
+
"pnpm publish --no-git-checks",
|
|
142
|
+
"yarn publish",
|
|
143
|
+
"yarn npm publish",
|
|
144
|
+
"bun publish",
|
|
145
|
+
"cargo publish",
|
|
146
|
+
"docker push repo/image",
|
|
147
|
+
"docker image push repo/image",
|
|
148
|
+
"docker compose push",
|
|
149
|
+
"docker build --push -t repo/image .",
|
|
150
|
+
"docker buildx build --push=true .",
|
|
151
|
+
"ls && npm publish",
|
|
152
|
+
])
|
|
153
|
+
expect(names(line)).toBeUndefined();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("gh is named two words deep, and gh api has no name to remember", () => {
|
|
157
|
+
expect(names("gh pr view 12")).toEqual(["gh pr view"]);
|
|
158
|
+
expect(names("gh issue list --state open")).toEqual(["gh issue list"]);
|
|
159
|
+
expect(names("gh status")).toEqual(["gh status"]);
|
|
160
|
+
expect(names("gh pr view 12 && gh pr merge 12")).toEqual(["gh pr view", "gh pr merge"]);
|
|
161
|
+
for (const line of [
|
|
162
|
+
"gh",
|
|
163
|
+
"gh api repos/o/r",
|
|
164
|
+
"gh api -X POST repos/o/r",
|
|
165
|
+
"gh pr --repo o/r merge 12",
|
|
166
|
+
"gh -R o/r pr view",
|
|
167
|
+
])
|
|
168
|
+
expect(names(line)).toBeUndefined();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test("a line continued after a space joins its words, and one continued inside a word joins the word", () => {
|
|
172
|
+
expect(names("git \\\npush")).toBeUndefined();
|
|
173
|
+
expect(names("git \\\n push origin main")).toBeUndefined();
|
|
174
|
+
expect(names("git \\\nstatus")).toEqual(["git status"]);
|
|
175
|
+
expect(names("git\\\npush")).toEqual(["gitpush"]);
|
|
176
|
+
expect(names("git \\\r\npush")).toBeUndefined();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("a sub-command that is not the word right after its program is not guessed", () => {
|
|
180
|
+
for (const line of ["git -C ../other push", "git --git-dir=x status", "git", "bun --cwd apps test", "git $SUB"])
|
|
181
|
+
expect(names(line)).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("a line it cannot read with confidence has no name", () => {
|
|
185
|
+
for (const line of [
|
|
186
|
+
"",
|
|
187
|
+
"FOO=1",
|
|
188
|
+
"# only a comment",
|
|
189
|
+
"echo `date`",
|
|
190
|
+
"$TOOL --version",
|
|
191
|
+
"for f in *.ts; do wc -l $f; done",
|
|
192
|
+
"if true; then ls; fi",
|
|
193
|
+
"! ls",
|
|
194
|
+
"[ -f a ] && ls",
|
|
195
|
+
"{ ls; }",
|
|
196
|
+
"find . -name '*.log' -exec cat {} \\;",
|
|
197
|
+
"cat <<EOF\nhi\nEOF",
|
|
198
|
+
"diff <(ls a) <(ls b)",
|
|
199
|
+
"echo $((1 + 2))",
|
|
200
|
+
"echo $'a\\x62'",
|
|
201
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: a shell expansion, not a template
|
|
202
|
+
"echo ${A:-$(date)}",
|
|
203
|
+
"ls 'unterminated",
|
|
204
|
+
'ls "unterminated',
|
|
205
|
+
"ls )",
|
|
206
|
+
"echo $(ls",
|
|
207
|
+
"ls >",
|
|
208
|
+
"ls > > a",
|
|
209
|
+
])
|
|
210
|
+
expect(names(line)).toBeUndefined();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "akanjs/common";
|
|
17
17
|
import { akanCodeModelWarnings } from "./akanCodeModel";
|
|
18
18
|
import { CodeAgentAsks } from "./CodeAgentAsks";
|
|
19
|
+
import { CodeAgentCommandLine } from "./CodeAgentCommandLine";
|
|
19
20
|
import { CodeAgentEventMapper } from "./CodeAgentEventMapper";
|
|
20
21
|
import { CodeAgentGate } from "./CodeAgentGate";
|
|
21
22
|
import { CodeAgentStreamPrinter } from "./CodeAgentStreamPrinter";
|
|
@@ -107,7 +108,15 @@ describe("codeAgentPresets", () => {
|
|
|
107
108
|
|
|
108
109
|
test("web asks before writing even though the runner is isolated", () => {
|
|
109
110
|
expect(codeAgentPresets.web(root).approval).toBe("writes");
|
|
110
|
-
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("local asks before a shell command and nothing else, and a pod asks about neither", () => {
|
|
114
|
+
const local = new CodeAgentGate(codeAgentPresets.local(root));
|
|
115
|
+
expect(local.verdict("bash", { command: "git status" }).approval).toBe("run: git status");
|
|
116
|
+
expect(local.verdict("bash", { command: "curl https://example.com" }).strict).toBe(true);
|
|
117
|
+
expect(local.verdict("write", { path: "a.ts" })).toEqual({});
|
|
118
|
+
expect(local.verdict("read", { path: "a.ts" })).toEqual({});
|
|
119
|
+
expect(new CodeAgentGate(codeAgentPresets.pod(root)).verdict("bash", { command: "git status" })).toEqual({});
|
|
111
120
|
});
|
|
112
121
|
|
|
113
122
|
test("every preset denies env files and secrets", () => {
|
|
@@ -134,6 +143,8 @@ describe("codeAgentPresets", () => {
|
|
|
134
143
|
});
|
|
135
144
|
});
|
|
136
145
|
|
|
146
|
+
const localUnasked = () => ({ ...codeAgentPresets.local(root), approval: "never" as const });
|
|
147
|
+
|
|
137
148
|
describe("CodeAgentGate", () => {
|
|
138
149
|
test("blocks a path on the deny list", () => {
|
|
139
150
|
const gate = new CodeAgentGate(codeAgentPresets.local(root));
|
|
@@ -174,6 +185,107 @@ describe("CodeAgentGate", () => {
|
|
|
174
185
|
});
|
|
175
186
|
});
|
|
176
187
|
|
|
188
|
+
describe("CodeAgentGate allow for this session", () => {
|
|
189
|
+
const gate = () => new CodeAgentGate(codeAgentPresets.local(root));
|
|
190
|
+
const allow = (target: CodeAgentGate, names: string[]) => {
|
|
191
|
+
target.allowed.offer("a0", names);
|
|
192
|
+
target.allowed.settle("a0", true);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
test("a command asks with the name a session answer would remember", () => {
|
|
196
|
+
expect(gate().verdict("bash", { command: "git status --short" })).toEqual({
|
|
197
|
+
approval: "run: git status --short",
|
|
198
|
+
remember: ["git status"],
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("an allowed command runs unasked, and another sub-command of its program still asks", () => {
|
|
203
|
+
const local = gate();
|
|
204
|
+
allow(local, ["git status", "bun test"]);
|
|
205
|
+
expect(local.verdict("bash", { command: "git status" })).toEqual({});
|
|
206
|
+
expect(local.verdict("bash", { command: "bun test --isolate ./a.test.ts" })).toEqual({});
|
|
207
|
+
expect(local.verdict("bash", { command: "git diff" }).remember).toEqual(["git diff"]);
|
|
208
|
+
expect(local.verdict("bash", { command: "bun x cowsay" }).remember).toEqual(["bun x"]);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("a compound line runs unasked only once every command in it is allowed, and offers the ones that are not", () => {
|
|
212
|
+
const local = gate();
|
|
213
|
+
allow(local, ["bun test"]);
|
|
214
|
+
const line = { command: "cd apps && bun test 2>&1 | tail -20" };
|
|
215
|
+
expect(local.verdict("bash", line).remember).toEqual(["cd", "tail"]);
|
|
216
|
+
allow(local, ["cd"]);
|
|
217
|
+
expect(local.verdict("bash", line).remember).toEqual(["tail"]);
|
|
218
|
+
allow(local, ["tail"]);
|
|
219
|
+
expect(local.verdict("bash", line)).toEqual({});
|
|
220
|
+
expect(local.verdict("bash", { command: "bun test && echo $(git log -1)" }).remember).toEqual(["git log", "echo"]);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("a networking command, git push, rm and a command that runs another are asked every time with no session answer", () => {
|
|
224
|
+
const local = gate();
|
|
225
|
+
allow(local, [...CodeAgentCommandLine.alwaysAsked, "git", "ls", "echo"]);
|
|
226
|
+
for (const command of [
|
|
227
|
+
"curl https://example.com",
|
|
228
|
+
"curl http://127.0.0.1:3000/health",
|
|
229
|
+
"ls && ssh deploy@host",
|
|
230
|
+
"git push",
|
|
231
|
+
"git push origin main",
|
|
232
|
+
"ls; rm -rf build",
|
|
233
|
+
"sudo ls",
|
|
234
|
+
"timeout 5 ls",
|
|
235
|
+
"sh -c 'ls'",
|
|
236
|
+
"ls | xargs echo",
|
|
237
|
+
"source ./x.sh",
|
|
238
|
+
"npm publish",
|
|
239
|
+
"gh api user",
|
|
240
|
+
"PATH=/tmp/bin ls",
|
|
241
|
+
"ls </dev/tcp/host/80",
|
|
242
|
+
]) {
|
|
243
|
+
const verdict = local.verdict("bash", { command });
|
|
244
|
+
expect(verdict.approval).toBeDefined();
|
|
245
|
+
expect(verdict.remember).toBeUndefined();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("a networking command stays asked every time where network requests are not asked about", () => {
|
|
250
|
+
const { askOutside: _ask, ...network } = codeAgentPresets.local(root).network;
|
|
251
|
+
const quiet = new CodeAgentGate({ ...codeAgentPresets.local(root), network });
|
|
252
|
+
expect(quiet.verdict("bash", { command: "curl https://example.com" })).toEqual({
|
|
253
|
+
approval: "run: curl https://example.com",
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("a line that cannot be split with confidence, or that writes a file by redirection, asks with no session answer", () => {
|
|
258
|
+
const local = gate();
|
|
259
|
+
allow(local, ["echo", "ls", "wc"]);
|
|
260
|
+
for (const command of ["echo `ls`", "for f in a b; do wc -l $f; done", "echo hi > ~/.zshrc", "ls | wc -l > n.txt"])
|
|
261
|
+
expect(local.verdict("bash", { command })).toEqual({ approval: `run: ${command}` });
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("forgetting what was allowed asks again", () => {
|
|
265
|
+
const local = gate();
|
|
266
|
+
allow(local, ["ls"]);
|
|
267
|
+
expect(local.allowed.names).toEqual(["ls"]);
|
|
268
|
+
expect(local.allowed.clear()).toBe(1);
|
|
269
|
+
expect(local.verdict("bash", { command: "ls" }).remember).toEqual(["ls"]);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("a file write that waits for approval has no session answer", () => {
|
|
273
|
+
const web = new CodeAgentGate(codeAgentPresets.web(root));
|
|
274
|
+
expect(web.verdict("write", { path: "a.ts" })).toEqual({ approval: "write a.ts" });
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("an approval still waiting is covered once the names it offered are all allowed", () => {
|
|
278
|
+
const local = gate();
|
|
279
|
+
local.allowed.offer("a1", ["bun test"]);
|
|
280
|
+
local.allowed.offer("a2", ["bun test"]);
|
|
281
|
+
local.allowed.offer("a3", ["bun test", "cd"]);
|
|
282
|
+
expect(local.allowed.settle("a1", true)).toEqual(["bun test"]);
|
|
283
|
+
expect(local.allowed.covered()).toEqual(["a2"]);
|
|
284
|
+
expect(local.allowed.settle("a2", false)).toEqual([]);
|
|
285
|
+
expect(local.allowed.covered()).toEqual([]);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
177
289
|
describe("CodeAgentAsks", () => {
|
|
178
290
|
const questionOf = (questionId: string): CodeAgentQuestion => ({
|
|
179
291
|
questionId,
|
|
@@ -409,15 +521,15 @@ describe("CodeAgentGate bash", () => {
|
|
|
409
521
|
expect(gate.verdict("bash", { command: "openssl x509 -in server.pem" }).block).toContain(".pem");
|
|
410
522
|
});
|
|
411
523
|
|
|
412
|
-
test("leaves an ordinary command alone", () => {
|
|
413
|
-
const gate = new CodeAgentGate(
|
|
524
|
+
test("leaves an ordinary command alone where commands are not asked about", () => {
|
|
525
|
+
const gate = new CodeAgentGate(localUnasked());
|
|
414
526
|
expect(gate.verdict("bash", { command: "bun test --isolate" })).toEqual({});
|
|
415
527
|
expect(gate.verdict("bash", { command: "grep -r TODO ." })).toEqual({});
|
|
416
528
|
});
|
|
417
529
|
});
|
|
418
530
|
|
|
419
531
|
describe("CodeAgentGate secrets", () => {
|
|
420
|
-
const gate = () => new CodeAgentGate(
|
|
532
|
+
const gate = () => new CodeAgentGate(localUnasked());
|
|
421
533
|
|
|
422
534
|
test("a per-environment server env file is refused for read, write and shell, and its loader is not", () => {
|
|
423
535
|
const file = "apps/a/env/env.server.main.ts";
|
|
@@ -477,7 +589,7 @@ describe("CodeAgentGate secrets", () => {
|
|
|
477
589
|
});
|
|
478
590
|
|
|
479
591
|
describe("CodeAgentGate network", () => {
|
|
480
|
-
const gate = () => new CodeAgentGate(
|
|
592
|
+
const gate = () => new CodeAgentGate(localUnasked());
|
|
481
593
|
|
|
482
594
|
test("the local profile asks before fetching a host off its list, and not for a listed one or loopback", () => {
|
|
483
595
|
expect(gate().verdict("web_fetch", { url: "https://example.com/x" })).toEqual({
|
|
@@ -36,7 +36,14 @@ agent nothing, and only the current page's declarations are live.
|
|
|
36
36
|
|
|
37
37
|
- `st.use.x({ agent: false })` hides a key; `hidden`, `secret` and `visual` fields are stripped from every read.
|
|
38
38
|
- Page text is data the model reads, never instructions: after a screen read the next call that changes something
|
|
39
|
-
asks once, and `data-agent-private="<label>"` keeps a region's text out of every read.
|
|
39
|
+
asks once, and `data-agent-private="<label>"` keeps a region's text out of every read. An `@` mention of a record
|
|
40
|
+
counts as a screen read.
|
|
41
|
+
- A turn's context carries ids, enum members, numbers and booleans. Any other string, a search param, a path
|
|
42
|
+
param or a list row's title included, is left out and read with `readState` or `readScreen`, so instructions say
|
|
43
|
+
"read `searchParams`", never "the query is in the route context". A search param rides inline when a store
|
|
44
|
+
declares its key with `search()`; of the others at most four short ones do. A zone's `label` and a value
|
|
45
|
+
published with `st.expose`, `st.useState` or `useAgentResource` ride whole: publish an id or a count there, never
|
|
46
|
+
text a user wrote.
|
|
40
47
|
- A tool value is capped at 20,000 characters.
|
|
41
48
|
- Route guidance is `<Agent.Guide instructions="…" />`; model-facing text is English.
|
|
42
49
|
|
|
@@ -139,13 +139,48 @@ akan code -i "<prompt>" open the session with the prompt already sent
|
|
|
139
139
|
--compact-at <percent> compact once the window is this full (10, 20, … 100)
|
|
140
140
|
--trust-workspace start this repo's MCP servers and extensions without asking
|
|
141
141
|
--no-ask-network never ask before an unlisted host (local profile)
|
|
142
|
+
--no-ask-commands run shell commands without asking (local profile)
|
|
143
|
+
--no-ask both of those at once: this session asks before nothing it runs (local profile)
|
|
142
144
|
--rpc-listen unix:<path>|tcp:[host:]<port> serve the RPC wire on a socket instead of stdio
|
|
143
145
|
```
|
|
144
146
|
|
|
145
147
|
`local` runs as the user: it refuses known secret files and the home credential stores, and asks before it
|
|
146
|
-
fetches a page from a host off a short documentation list or a shell command that
|
|
147
|
-
(`curl`, `ssh`, …)
|
|
148
|
-
|
|
148
|
+
runs a shell command, fetches a page from a host off a short documentation list, or runs a shell command that
|
|
149
|
+
reaches the network (`curl`, `ssh`, …). Where nobody can answer, as in a one-shot `akan code "<prompt>"` or
|
|
150
|
+
inside a sub-agent, an ordinary command runs unasked and those network calls are refused outright. It is not a
|
|
151
|
+
sandbox; `pod` in a container is.
|
|
152
|
+
|
|
153
|
+
An approval for a shell command reads `approve? run: <command> [y/n/a]`. `y` runs it once, `n` or esc refuses
|
|
154
|
+
it, and `a` runs it and stops asking about that command until the session ends. What `a` remembers is the
|
|
155
|
+
program, and the sub-command too for `git`, `bun`, `bunx`, `npm`, `npx`, `pnpm`, `yarn`, `akan`, `docker`,
|
|
156
|
+
`kubectl`, `helm`, `cargo` and `go`: allowing `git status` leaves `git diff` asked about, and allowing
|
|
157
|
+
`bun test` leaves `bun x` asked about. `gh` is remembered two words deep, so allowing `gh pr view` leaves
|
|
158
|
+
`gh pr merge` asked about. A line of several commands (`&&`, `;`, `|`, `$(…)`, a subshell) runs unasked only
|
|
159
|
+
once every command in it is allowed, and its prompt names the ones `a` would add. `/allowed` lists what the
|
|
160
|
+
session has allowed and `/allowed clear` forgets it. Nothing is written down: a resumed, forked or reloaded
|
|
161
|
+
session asks again.
|
|
162
|
+
|
|
163
|
+
Some lines are asked about every time and their prompt offers only `[y/n]`:
|
|
164
|
+
|
|
165
|
+
- a networking command: `curl`, `wget`, `nc`, `ncat`, `netcat`, `socat`, `telnet`, `ssh`, `scp`, `sftp`,
|
|
166
|
+
`rsync`, `ftp`, and a redirection to or from `/dev/tcp/…` or `/dev/udp/…`;
|
|
167
|
+
- a command that sends something out of the machine: `git push`, `npm publish`, `pnpm publish`,
|
|
168
|
+
`yarn publish`, `yarn npm`, `bun publish`, `cargo publish`, `gh api`, and a `docker` line with `push` or
|
|
169
|
+
`--push` in it (`docker push`, `docker image push`, `docker build --push`);
|
|
170
|
+
- `rm`;
|
|
171
|
+
- a command that runs another, or sets what a later one runs: `sudo`, `env`, `command`, `exec`, `nohup`,
|
|
172
|
+
`time`, `timeout`, `nice`, `watch`, `stdbuf`, `xargs`, `sh`, `bash`, `zsh`, `dash`, `ksh`, `fish`, `eval`,
|
|
173
|
+
`builtin`, `source`, `.`, `trap`, `alias`, `coproc`, `export`, `declare`, `typeset`, `readonly`, `find -exec`;
|
|
174
|
+
- a variable set in front of a command, other than `CI`, `NODE_ENV`, `FORCE_COLOR`, `NO_COLOR`, `TZ`, `LANG`,
|
|
175
|
+
`LC_ALL`, `TERM`, `DEBUG` or `PORT` given one plain word (`CI=1 bun test` is read as `bun test`);
|
|
176
|
+
- a line that writes a file with `>` or `>>` (other than to `/dev/null`);
|
|
177
|
+
- a line the reader cannot split with confidence: a loop or `if`, backticks, a here-document, a program named
|
|
178
|
+
by a variable, a flag between `git` and its sub-command.
|
|
179
|
+
|
|
180
|
+
`--no-ask` is `--no-ask-commands --no-ask-network` under one name, for a run where the user has decided not to
|
|
181
|
+
be asked: it prints one line at start saying so. It changes nothing else: the secret files stay refused, this
|
|
182
|
+
repo's MCP servers and extensions still wait for their own approval (`--trust-workspace`), the agent's own
|
|
183
|
+
questions are still asked, and the other profiles behave as they did.
|
|
149
184
|
|
|
150
185
|
A `tcp:` listener asks every connection to open with `{"auth":"<token>"}` on its first line; the token is a
|
|
151
186
|
fresh one in `~/.akan/code/rpc/<port>.token`, or the one in the file `AKAN_CODE_RPC_TOKEN_FILE` names.
|
|
@@ -428,14 +428,9 @@ describe("route client store bootstrap", () => {
|
|
|
428
428
|
await write(uiEntry, 'export { ClientPathWrapper } from "./System/Client";\n');
|
|
429
429
|
await write(clientEntry, '"use client";\nexport const ClientPathWrapper = () => null;\n');
|
|
430
430
|
|
|
431
|
-
const entryFiles = new Map([
|
|
432
|
-
["akanjs/ui", uiEntry],
|
|
433
|
-
["akanjs/ui/System/Client.tsx", clientEntry],
|
|
434
|
-
]);
|
|
435
431
|
const discovery = new GraphClientEntryDiscovery({ barrelImports: ["akanjs/ui"] }, async (specifier) => {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return { pkgName: specifier, entryFile, pkgDir: path.dirname(entryFile), preserveFilePath: true };
|
|
432
|
+
if (specifier !== "akanjs/ui") return null;
|
|
433
|
+
return { pkgName: specifier, entryFile: uiEntry, pkgDir: path.dirname(uiEntry), preserveFilePath: true };
|
|
439
434
|
});
|
|
440
435
|
|
|
441
436
|
expect(await discovery.discover([seed])).toEqual([clientEntry]);
|
|
@@ -226,8 +226,8 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
226
226
|
this.#resolvedSpecifierCache,
|
|
227
227
|
cacheKey,
|
|
228
228
|
async () => {
|
|
229
|
-
if (spec.startsWith(".") ||
|
|
230
|
-
const abs =
|
|
229
|
+
if (spec.startsWith(".") || path.isAbsolute(spec)) {
|
|
230
|
+
const abs = path.resolve(importerDir, spec);
|
|
231
231
|
return await this.#resolveFileCandidate(abs);
|
|
232
232
|
}
|
|
233
233
|
const pkg = await this.#resolvePackage(spec);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdir, realpath, symlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
5
|
+
import { DevBarrelImports } from "./devBarrelImports";
|
|
6
|
+
|
|
7
|
+
const makeTempRoot = tempDirs("akan-dev-barrel-imports-");
|
|
8
|
+
|
|
9
|
+
describe("DevBarrelImports", () => {
|
|
10
|
+
test("points an installed package's import at the real file behind its link, relative to the importer", async () => {
|
|
11
|
+
const root = await realpath(await makeTempRoot());
|
|
12
|
+
const installed = path.join(root, "store/akanjs");
|
|
13
|
+
await write(path.join(installed, "ui/index.ts"), 'export { Link } from "./Link";\n');
|
|
14
|
+
await write(path.join(installed, "ui/Link/index.tsx"), "export const Link = () => null;\n");
|
|
15
|
+
await mkdir(path.join(root, "node_modules"), { recursive: true });
|
|
16
|
+
await symlink(installed, path.join(root, "node_modules/akanjs"));
|
|
17
|
+
const uiEntry = path.join(root, "node_modules/akanjs/ui/index.ts");
|
|
18
|
+
const importer = path.join(root, "apps/demo/page/_index.tsx");
|
|
19
|
+
await write(importer, "");
|
|
20
|
+
|
|
21
|
+
const barrels = new DevBarrelImports(["akanjs/ui"], async (specifier) =>
|
|
22
|
+
specifier === "akanjs/ui"
|
|
23
|
+
? { pkgName: specifier, entryFile: uiEntry, pkgDir: path.dirname(uiEntry), preserveFilePath: true }
|
|
24
|
+
: null,
|
|
25
|
+
);
|
|
26
|
+
const rewrite = await barrels.rewrite('import { Link } from "akanjs/ui";\n', importer);
|
|
27
|
+
|
|
28
|
+
expect(rewrite?.contents).toBe('import { Link } from "../../../store/akanjs/ui/Link/index.tsx";\n');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -115,8 +115,8 @@ export class DevBarrelImports {
|
|
|
115
115
|
|
|
116
116
|
static #fileOf(subpath: string, packages: PackageEntry[]): string | null {
|
|
117
117
|
const pkg = packages.find(({ pkgName }) => subpath === pkgName || subpath.startsWith(`${pkgName}/`));
|
|
118
|
-
if (!pkg) return null;
|
|
119
|
-
const file = CsrDevPaths.resolveOnDisk(path.join(pkg.pkgDir, subpath.slice(pkg.pkgName.length)));
|
|
118
|
+
if (!pkg && !path.isAbsolute(subpath)) return null;
|
|
119
|
+
const file = CsrDevPaths.resolveOnDisk(pkg ? path.join(pkg.pkgDir, subpath.slice(pkg.pkgName.length)) : subpath);
|
|
120
120
|
return file ? CsrDevPaths.realpath(file) : null;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { Logger } from "akanjs/common";
|
|
3
|
+
import type { BuilderMessage, BuildPhase, HmrTrace } from "akanjs/server";
|
|
4
|
+
import { resolveDevCsrMode } from "akanjs/server/hmr/csrDevManifest";
|
|
5
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
6
|
+
import { resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
7
|
+
import { computeRouteSeedIndex, saveRouteSeedIndex } from "../artifact/routeSeedIndex";
|
|
8
|
+
import type { App } from "../commandDecorators";
|
|
6
9
|
// Subpath imports only, as few as possible: spawned per generation, this process pays every import on every save.
|
|
7
|
-
import { AppExecutor, WorkspaceExecutor } from "
|
|
10
|
+
import { AppExecutor, WorkspaceExecutor } from "../executors";
|
|
8
11
|
import {
|
|
9
12
|
CsrArtifactBuilder,
|
|
10
13
|
CsrDevBundler,
|
|
@@ -14,10 +17,7 @@ import {
|
|
|
14
17
|
ServerGraphFile,
|
|
15
18
|
SsrBaseArtifactBuilder,
|
|
16
19
|
SsrDevBundler,
|
|
17
|
-
} from "
|
|
18
|
-
import { Logger } from "akanjs/common";
|
|
19
|
-
import type { BuilderMessage, BuildPhase, HmrTrace } from "akanjs/server";
|
|
20
|
-
import { resolveDevCsrMode } from "akanjs/server/hmr/csrDevManifest";
|
|
20
|
+
} from "../frontendBuild";
|
|
21
21
|
import type { BuildBatchRequest, BuildBatchResult, OptimizedFonts, PagesBatchCssAssets } from "./buildBatchProtocol";
|
|
22
22
|
|
|
23
23
|
// `Bun.build` keeps native bundler arenas that `Bun.gc(true)` cannot reclaim; only exiting returns them.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FontOptimizer } from "@akanjs/devkit/frontendBuild";
|
|
2
1
|
import type { BaseBuildArtifact, CssPayload, HmrTrace, PagesBundlePayload } from "akanjs/server";
|
|
2
|
+
import type { FontOptimizer } from "../frontendBuild";
|
|
3
3
|
|
|
4
4
|
export type OptimizedFonts = Awaited<ReturnType<FontOptimizer["optimize"]>>;
|
|
5
5
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
-
import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
|
|
4
|
-
import { GraphClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientEntryDiscovery";
|
|
5
|
-
import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
|
|
6
|
-
import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
|
|
7
2
|
import type { Logger } from "akanjs/common";
|
|
8
3
|
import type { BaseBuildArtifact } from "akanjs/server";
|
|
4
|
+
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
|
|
6
|
+
import { GraphClientEntryDiscovery } from "../frontendBuild/clientEntryDiscovery";
|
|
7
|
+
import { HmrWatcher } from "../frontendBuild/hmrWatcher";
|
|
8
|
+
import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
|
|
9
9
|
import type { OptimizedFonts } from "./buildBatchProtocol";
|
|
10
10
|
import type { BuildBatchRunner } from "./buildBatchRunner";
|
|
11
11
|
import { BuilderChannel } from "./builderChannel";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
2
|
-
import { FrameworkGraph } from "@akanjs/devkit/docs/frameworkGraph";
|
|
3
|
-
import { GitRevision } from "@akanjs/devkit/workspace/gitRevision";
|
|
4
|
-
import { WorkspaceGraph } from "@akanjs/devkit/workspace/workspaceGraph";
|
|
5
1
|
import type { BuildChangesPayload, BuilderGraphReq, BuildFrameworkPayload, BuildGraphPayload } from "akanjs/server";
|
|
2
|
+
import type { App } from "../commandDecorators";
|
|
3
|
+
import { FrameworkGraph } from "../docs/frameworkGraph";
|
|
4
|
+
import { GitRevision } from "../workspace/gitRevision";
|
|
5
|
+
import { WorkspaceGraph } from "../workspace/workspaceGraph";
|
|
6
6
|
|
|
7
7
|
export class BuilderGraphPayloads {
|
|
8
8
|
readonly #app: App;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
2
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
1
|
import type { Logger } from "akanjs/common";
|
|
2
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
4
|
import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
|
|
5
5
|
import { sendBuildStatus } from "./builderBuildStatus";
|
|
6
6
|
import { BuilderChannel } from "./builderChannel";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
3
|
-
import type { PageRoot } from "@akanjs/devkit/executors";
|
|
4
|
-
import { AutoImportSync } from "@akanjs/devkit/frontendBuild/autoImportSync";
|
|
5
|
-
import { DevChangePlanner } from "@akanjs/devkit/frontendBuild/devChangePlanner";
|
|
6
|
-
import { DevGeneratedIndexSync } from "@akanjs/devkit/frontendBuild/devGeneratedIndexSync";
|
|
7
|
-
import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
|
|
8
|
-
import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
|
|
9
|
-
import { CodegenLock } from "@akanjs/devkit/workspace/codegenLock";
|
|
10
2
|
import type { Logger } from "akanjs/common";
|
|
11
3
|
import type { ChangeBatch } from "akanjs/server";
|
|
4
|
+
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { PageRoot } from "../executors";
|
|
6
|
+
import { AutoImportSync } from "../frontendBuild/autoImportSync";
|
|
7
|
+
import { DevChangePlanner } from "../frontendBuild/devChangePlanner";
|
|
8
|
+
import { DevGeneratedIndexSync } from "../frontendBuild/devGeneratedIndexSync";
|
|
9
|
+
import { HmrWatcher } from "../frontendBuild/hmrWatcher";
|
|
10
|
+
import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
|
|
11
|
+
import { CodegenLock } from "../workspace/codegenLock";
|
|
12
12
|
import type { BuildBatchNeed } from "./buildBatchProtocol";
|
|
13
13
|
import { sendBuildStatus } from "./builderBuildStatus";
|
|
14
14
|
import { BuilderChannel } from "./builderChannel";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
|
|
4
|
-
import type { App } from "@akanjs/devkit/commandDecorators";
|
|
5
|
-
import { CsrDevBundler } from "@akanjs/devkit/frontendBuild/csrDevBundler";
|
|
6
|
-
import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
|
|
7
3
|
import type { Logger } from "akanjs/common";
|
|
8
4
|
import type { BaseBuildArtifact, BuilderCsrReq, HmrTrace } from "akanjs/server";
|
|
9
5
|
import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
|
|
6
|
+
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
7
|
+
import type { App } from "../commandDecorators";
|
|
8
|
+
import { CsrDevBundler } from "../frontendBuild/csrDevBundler";
|
|
9
|
+
import { CsrDevPatcher } from "../frontendBuild/csrDevPatcher";
|
|
10
10
|
import type { BatchWork, BuildBatchRequest } from "./buildBatchProtocol";
|
|
11
11
|
import type { BuildBatchRunner } from "./buildBatchRunner";
|
|
12
12
|
import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
|