@akanjs/code 0.0.0 → 3.3.0-rc.70
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/README.ko.md +31 -0
- package/README.md +26 -4
- package/agent/AkanCodeCompaction.ts +49 -0
- package/agent/AkanCodeServices.ts +122 -0
- package/agent/AkanContextFiles.ts +94 -0
- package/agent/CodeAgent.ts +598 -0
- package/agent/CodeAgentAllowed.ts +35 -0
- package/agent/CodeAgentAsks.ts +66 -0
- package/agent/CodeAgentCommandLine.ts +372 -0
- package/agent/CodeAgentEventMapper.ts +225 -0
- package/agent/CodeAgentFrames.ts +57 -0
- package/agent/CodeAgentGate.ts +258 -0
- package/agent/CodeAgentProxy.ts +83 -0
- package/agent/CodeAgentRpcHost.ts +109 -0
- package/agent/CodeAgentRpcListener.ts +195 -0
- package/agent/CodeAgentStreamPrinter.ts +86 -0
- package/agent/CodeAgentSuspended.ts +85 -0
- package/agent/CodeAgentUi.ts +47 -0
- package/agent/CodeMailbox.ts +148 -0
- package/agent/CodeSessionFork.ts +56 -0
- package/agent/CodeSessionIndex.ts +78 -0
- package/agent/SubagentPool.ts +222 -0
- package/agent/WorkspaceTrust.ts +200 -0
- package/agent/akanCodeCompaction.test.ts +36 -0
- package/agent/akanCodeModel.ts +47 -0
- package/agent/akanCodeServices.test.ts +54 -0
- package/agent/akanContextFiles.test.ts +116 -0
- package/agent/akanSystemPrompt.ts +50 -0
- package/agent/codeAgent.test.ts +337 -0
- package/agent/codeAgentCommandLine.test.ts +212 -0
- package/agent/codeAgentContract.test.ts +757 -0
- package/agent/codeAgentHosts.ts +30 -0
- package/agent/codeAgentProxy.test.ts +125 -0
- package/agent/codeAgentRpcListener.test.ts +215 -0
- package/agent/codeAgentSuspended.test.ts +47 -0
- package/agent/codeMailbox.test.ts +76 -0
- package/agent/codeSessionFork.test.ts +58 -0
- package/agent/codeSessionIndex.test.ts +77 -0
- package/agent/consoleToStderr.ts +8 -0
- package/agent/jsonLines.ts +29 -0
- package/agent/stringArg.ts +5 -0
- package/bunfig.toml +2 -0
- package/feedback/DevLogFeedback.ts +82 -0
- package/feedback/PreviewFeedback.ts +46 -0
- package/feedback/TurnFeedback.ts +98 -0
- package/feedback/VerifyFeedback.ts +39 -0
- package/host/AkanCodeRunner.ts +297 -0
- package/host/CodeTrustPrompt.ts +57 -0
- package/host/codeRunnerPrompt.test.ts +181 -0
- package/host/hostGraph.test.ts +33 -0
- package/host/index.ts +2 -0
- package/index.ts +49 -0
- package/package.json +43 -9
- package/piDependencyPins.test.ts +45 -0
- package/test/preload.ts +3 -0
- package/tools/AkanCli.ts +56 -0
- package/tools/AkanCodePlugins.ts +145 -0
- package/tools/AkanEditScope.ts +53 -0
- package/tools/AkanEnvKeys.ts +50 -0
- package/tools/AkanToolPack.ts +87 -0
- package/tools/AkanVerifier.ts +30 -0
- package/tools/AskToolPack.ts +99 -0
- package/tools/DeepSeekWeb.ts +127 -0
- package/tools/MailToolPack.ts +76 -0
- package/tools/McpClient.ts +209 -0
- package/tools/McpOAuth.ts +233 -0
- package/tools/McpOAuthLoopback.ts +64 -0
- package/tools/McpServerConfig.ts +131 -0
- package/tools/McpSignIn.ts +158 -0
- package/tools/McpTokenStore.ts +128 -0
- package/tools/McpToolPack.ts +206 -0
- package/tools/SessionToolPack.ts +91 -0
- package/tools/WebToolPack.ts +315 -0
- package/tools/akanCodePlugins.test.ts +954 -0
- package/tools/askToolPack.test.ts +116 -0
- package/tools/deepSeekWeb.test.ts +113 -0
- package/tools/mcpOAuth.test.ts +648 -0
- package/tools/mcpServerConfig.test.ts +341 -0
- package/tsconfig.json +29 -0
- package/tui/CodeTui.tsx +394 -0
- package/tui/CodeTuiAgents.ts +65 -0
- package/tui/CodeTuiApp.test.tsx +251 -0
- package/tui/CodeTuiApp.tsx +312 -0
- package/tui/CodeTuiAutoCompact.ts +33 -0
- package/tui/CodeTuiClipboard.ts +94 -0
- package/tui/CodeTuiCommandRunner.ts +242 -0
- package/tui/CodeTuiCommands.ts +59 -0
- package/tui/CodeTuiEditor.ts +168 -0
- package/tui/CodeTuiFiles.ts +45 -0
- package/tui/CodeTuiFrame.ts +133 -0
- package/tui/CodeTuiLines.ts +117 -0
- package/tui/CodeTuiMarkdown.ts +159 -0
- package/tui/CodeTuiMcp.ts +111 -0
- package/tui/CodeTuiModels.ts +82 -0
- package/tui/CodeTuiMouse.ts +39 -0
- package/tui/CodeTuiOverlay.ts +148 -0
- package/tui/CodeTuiParts.ts +168 -0
- package/tui/CodeTuiPrompt.ts +271 -0
- package/tui/CodeTuiQuestion.ts +170 -0
- package/tui/codeTranscript.test.ts +445 -0
- package/tui/codeTui.test.tsx +1104 -0
- package/tui/codeTuiAgents.test.ts +61 -0
- package/tui/codeTuiClipboard.test.ts +16 -0
- package/tui/codeTuiCommands.test.ts +38 -0
- package/tui/codeTuiEditor.test.ts +122 -0
- package/tui/codeTuiFiles.test.ts +43 -0
- package/tui/codeTuiMarkdown.test.ts +91 -0
- package/tui/codeTuiMcp.test.ts +160 -0
- package/tui/codeTuiMouse.test.ts +61 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
|
|
3
|
+
const bare = (hostname: string) =>
|
|
4
|
+
hostname
|
|
5
|
+
.replace(/^\[|\]$/g, "")
|
|
6
|
+
.replace(/\.$/, "")
|
|
7
|
+
.toLowerCase();
|
|
8
|
+
|
|
9
|
+
// Loopback only: a private LAN address is another machine, and a request to it leaves this one.
|
|
10
|
+
export const codeAgentIsLoopback = (hostname: string) => {
|
|
11
|
+
const host = bare(hostname);
|
|
12
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
13
|
+
if (isIP(host) === 4) return host.startsWith("127.");
|
|
14
|
+
if (isIP(host) === 6) return host === "::1" || /^::ffff:(127\.\d+\.\d+\.\d+|7f[0-9a-f]{2}:[0-9a-f]{1,4})$/.test(host);
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const codeAgentHostListed = (hostname: string, hosts: readonly string[]) => {
|
|
19
|
+
const host = bare(hostname);
|
|
20
|
+
return hosts.some((entry) => host === entry || host.endsWith(`.${entry}`));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const codeAgentHostOf = (url: string) => {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = new URL(url);
|
|
26
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:" ? parsed.hostname : undefined;
|
|
27
|
+
} catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { chmodSync, mkdirSync, mkdtempSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { AkanCodeEnv, akanCodePaths } from "@akanjs/devkit/codeAgent";
|
|
6
|
+
import { AkanCodeServices } from "./AkanCodeServices";
|
|
7
|
+
import { akanCodeDefaultModel, akanCodeModel } from "./akanCodeModel";
|
|
8
|
+
import { CodeAgentProxy } from "./CodeAgentProxy";
|
|
9
|
+
|
|
10
|
+
const seen: { path: string; auth: string | null }[] = [];
|
|
11
|
+
let proxy: ReturnType<typeof Bun.serve>;
|
|
12
|
+
let home = "";
|
|
13
|
+
let realHome: string | undefined;
|
|
14
|
+
let realKey: string | undefined;
|
|
15
|
+
|
|
16
|
+
const chunk = (delta: object, finish: string | null = null) =>
|
|
17
|
+
`data: ${JSON.stringify({
|
|
18
|
+
id: "c1",
|
|
19
|
+
object: "chat.completion.chunk",
|
|
20
|
+
created: 0,
|
|
21
|
+
model: akanCodeDefaultModel.id,
|
|
22
|
+
choices: [{ index: 0, delta, finish_reason: finish }],
|
|
23
|
+
})}\n\n`;
|
|
24
|
+
|
|
25
|
+
beforeAll(() => {
|
|
26
|
+
home = mkdtempSync(path.join(tmpdir(), "akan-code-proxy-test-"));
|
|
27
|
+
realHome = process.env.AKAN_CODE_HOME;
|
|
28
|
+
realKey = process.env.DEEPSEEK_API_KEY;
|
|
29
|
+
process.env.AKAN_CODE_HOME = home;
|
|
30
|
+
process.env.DEEPSEEK_API_KEY = "real-provider-key-must-not-leave";
|
|
31
|
+
proxy = Bun.serve({
|
|
32
|
+
port: 0,
|
|
33
|
+
fetch: (req) => {
|
|
34
|
+
seen.push({ path: new URL(req.url).pathname, auth: req.headers.get("authorization") });
|
|
35
|
+
const body = `${chunk({ role: "assistant", content: "pong" })}${chunk({}, "stop")}data: [DONE]\n\n`;
|
|
36
|
+
return new Response(body, { headers: { "content-type": "text/event-stream" } });
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterAll(() => {
|
|
42
|
+
proxy.stop(true);
|
|
43
|
+
rmSync(home, { recursive: true, force: true });
|
|
44
|
+
if (realHome === undefined) delete process.env.AKAN_CODE_HOME;
|
|
45
|
+
else process.env.AKAN_CODE_HOME = realHome;
|
|
46
|
+
if (realKey === undefined) delete process.env.DEEPSEEK_API_KEY;
|
|
47
|
+
else process.env.DEEPSEEK_API_KEY = realKey;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("CodeAgentProxy", () => {
|
|
51
|
+
test("sends every request to the proxy with the token read from its file at that moment", async () => {
|
|
52
|
+
const tokenFile = path.join(home, "token");
|
|
53
|
+
writeFileSync(tokenFile, "session-token-1\n");
|
|
54
|
+
const codeProxy = new CodeAgentProxy({
|
|
55
|
+
baseUrl: `http://127.0.0.1:${proxy.port}/llm/{provider}/v1`,
|
|
56
|
+
providers: [akanCodeDefaultModel.provider],
|
|
57
|
+
tokenFile,
|
|
58
|
+
});
|
|
59
|
+
const runtime = await AkanCodeServices.runtime(home, codeProxy);
|
|
60
|
+
const model = await akanCodeModel(runtime);
|
|
61
|
+
expect(model?.provider).toBe("deepseek");
|
|
62
|
+
const context = { messages: [{ role: "user" as const, content: "ping", timestamp: Date.now() }] };
|
|
63
|
+
if (!model) throw new Error("no model");
|
|
64
|
+
const first = await runtime.completeSimple(model, context);
|
|
65
|
+
writeFileSync(tokenFile, "session-token-2\n");
|
|
66
|
+
await runtime.completeSimple(model, context);
|
|
67
|
+
expect(first.content).toEqual([expect.objectContaining({ type: "text", text: "pong" })]);
|
|
68
|
+
expect(seen.map((request) => request.auth)).toEqual(["Bearer session-token-1", "Bearer session-token-2"]);
|
|
69
|
+
expect(seen.every((request) => request.path.startsWith("/llm/deepseek/v1/"))).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("refuses to start with a proxy URL and no token source", () => {
|
|
73
|
+
expect(() => new CodeAgentProxy({ baseUrl: "https://proxy", providers: ["deepseek"] })).toThrow("TOKEN");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("AkanCodeEnv", () => {
|
|
78
|
+
const inRepo = (dotenv: string | null, run: () => void) => {
|
|
79
|
+
const repo = mkdtempSync(path.join(tmpdir(), "akan-code-env-"));
|
|
80
|
+
const cwd = process.cwd();
|
|
81
|
+
const had = process.env.AKAN_CODE_PROXY_URL;
|
|
82
|
+
try {
|
|
83
|
+
if (dotenv !== null) writeFileSync(path.join(repo, ".env"), dotenv);
|
|
84
|
+
process.chdir(repo);
|
|
85
|
+
process.env.AKAN_CODE_PROXY_URL = "https://proxy.example/{provider}";
|
|
86
|
+
run();
|
|
87
|
+
} finally {
|
|
88
|
+
process.chdir(cwd);
|
|
89
|
+
if (had === undefined) delete process.env.AKAN_CODE_PROXY_URL;
|
|
90
|
+
else process.env.AKAN_CODE_PROXY_URL = had;
|
|
91
|
+
rmSync(repo, { recursive: true, force: true });
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
test("a setting the repo's own dotenv file names is ignored, and the start warning says so", () => {
|
|
96
|
+
inRepo("export AKAN_CODE_PROXY_URL=placeholder\n", () => {
|
|
97
|
+
expect(AkanCodeEnv.get("AKAN_CODE_PROXY_URL")).toBeUndefined();
|
|
98
|
+
expect(CodeAgentProxy.fromEnv()).toBeNull();
|
|
99
|
+
expect(AkanCodeEnv.ignored()).toEqual([expect.stringContaining("AKAN_CODE_PROXY_URL is set in .env")]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("a setting from the shell is read when no dotenv file names it", () => {
|
|
104
|
+
inRepo("OTHER_KEY=placeholder\n", () => {
|
|
105
|
+
expect(AkanCodeEnv.get("AKAN_CODE_PROXY_URL")).toBe("https://proxy.example/{provider}");
|
|
106
|
+
expect(AkanCodeEnv.ignored()).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test.skipIf(process.platform === "win32")(
|
|
111
|
+
"the home directory is made owner-only, even one made looser before",
|
|
112
|
+
() => {
|
|
113
|
+
const loose = path.join(home, "loose-home");
|
|
114
|
+
mkdirSync(loose, { mode: 0o755 });
|
|
115
|
+
chmodSync(loose, 0o755);
|
|
116
|
+
process.env.AKAN_CODE_HOME = loose;
|
|
117
|
+
try {
|
|
118
|
+
akanCodePaths.ensureGlobalDir();
|
|
119
|
+
expect(statSync(loose).mode & 0o777).toBe(0o700);
|
|
120
|
+
} finally {
|
|
121
|
+
process.env.AKAN_CODE_HOME = home;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
});
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, rmSync, statSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import type { CodeAgentEvent } from "akanjs/common";
|
|
6
|
+
import type { CodeAgent } from "./CodeAgent";
|
|
7
|
+
import { CodeAgentRpcHost } from "./CodeAgentRpcHost";
|
|
8
|
+
import { CodeAgentRpcListener } from "./CodeAgentRpcListener";
|
|
9
|
+
|
|
10
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-rpc-"));
|
|
11
|
+
afterAll(() => rmSync(dir, { recursive: true, force: true }));
|
|
12
|
+
|
|
13
|
+
class FakeAgent {
|
|
14
|
+
seq = 0;
|
|
15
|
+
frames: CodeAgentEvent[] = [];
|
|
16
|
+
disposed = false;
|
|
17
|
+
aborted = false;
|
|
18
|
+
#listener: (event: CodeAgentEvent) => void = () => {};
|
|
19
|
+
on(listener: (event: CodeAgentEvent) => void) {
|
|
20
|
+
this.#listener = listener;
|
|
21
|
+
return () => {};
|
|
22
|
+
}
|
|
23
|
+
announce() {
|
|
24
|
+
this.emit();
|
|
25
|
+
}
|
|
26
|
+
emit() {
|
|
27
|
+
const event = { type: "idle", seq: ++this.seq } as CodeAgentEvent;
|
|
28
|
+
this.frames.push(event);
|
|
29
|
+
this.#listener(event);
|
|
30
|
+
}
|
|
31
|
+
async prompt() {
|
|
32
|
+
this.emit();
|
|
33
|
+
}
|
|
34
|
+
async abort() {
|
|
35
|
+
this.aborted = true;
|
|
36
|
+
}
|
|
37
|
+
async state({ sinceSeq }: { sinceSeq?: number } = {}) {
|
|
38
|
+
return { replayFrom: 0, frames: this.frames.filter((event) => event.seq > (sinceSeq ?? Number.MAX_SAFE_INTEGER)) };
|
|
39
|
+
}
|
|
40
|
+
dispose() {
|
|
41
|
+
this.disposed = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class Client {
|
|
46
|
+
lines: unknown[] = [];
|
|
47
|
+
readonly closed = Promise.withResolvers<void>();
|
|
48
|
+
#buffer = "";
|
|
49
|
+
#socket: Awaited<ReturnType<typeof Bun.connect>> | null = null;
|
|
50
|
+
static async connect(target: string | { port: number }) {
|
|
51
|
+
const client = new Client();
|
|
52
|
+
const socket = {
|
|
53
|
+
data: (_socket: unknown, data: Buffer) => {
|
|
54
|
+
client.#buffer += data.toString();
|
|
55
|
+
const parts = client.#buffer.split("\n");
|
|
56
|
+
client.#buffer = parts.pop() ?? "";
|
|
57
|
+
for (const part of parts) if (part) client.lines.push(JSON.parse(part));
|
|
58
|
+
},
|
|
59
|
+
close: () => client.closed.resolve(),
|
|
60
|
+
};
|
|
61
|
+
client.#socket = await (typeof target === "string"
|
|
62
|
+
? Bun.connect({ unix: target, socket })
|
|
63
|
+
: Bun.connect({ hostname: "127.0.0.1", port: target.port, socket }));
|
|
64
|
+
return client;
|
|
65
|
+
}
|
|
66
|
+
raw(text: string) {
|
|
67
|
+
this.#socket?.write(text);
|
|
68
|
+
}
|
|
69
|
+
send(id: string, command: object) {
|
|
70
|
+
this.#socket?.write(`${JSON.stringify({ id, command })}\n`);
|
|
71
|
+
}
|
|
72
|
+
async reply(id: string) {
|
|
73
|
+
for (let idx = 0; idx < 200; idx++) {
|
|
74
|
+
const found = this.lines.find((line) => (line as { id?: string }).id === id);
|
|
75
|
+
if (found) return found as { ok: boolean; data: { frames?: CodeAgentEvent[] } };
|
|
76
|
+
await Bun.sleep(5);
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`no reply ${id}`);
|
|
79
|
+
}
|
|
80
|
+
close() {
|
|
81
|
+
this.#socket?.end();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe("CodeAgentRpcListener", () => {
|
|
86
|
+
test("parses unix and tcp addresses, defaulting tcp to loopback", () => {
|
|
87
|
+
expect(CodeAgentRpcListener.parse("unix:/tmp/a.sock")).toEqual({ unix: "/tmp/a.sock" });
|
|
88
|
+
expect(CodeAgentRpcListener.parse("tcp:7000")).toEqual({ hostname: "127.0.0.1", port: 7000 });
|
|
89
|
+
expect(CodeAgentRpcListener.parse("tcp::7000")).toEqual({ hostname: "127.0.0.1", port: 7000 });
|
|
90
|
+
expect(CodeAgentRpcListener.parse("localhost:7000")).toEqual({ hostname: "localhost", port: 7000 });
|
|
91
|
+
expect(() => CodeAgentRpcListener.parse("tcp:nope")).toThrow("--rpc-listen");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("a bind other machines could reach is refused unless it is asked for", () => {
|
|
95
|
+
expect(() => CodeAgentRpcListener.parse("0.0.0.0:7000")).toThrow("--rpc-bind-any");
|
|
96
|
+
expect(() => CodeAgentRpcListener.parse("tcp:192.168.0.2:7000")).toThrow("--rpc-bind-any");
|
|
97
|
+
expect(CodeAgentRpcListener.parse("0.0.0.0:7000", { anyHost: true })).toEqual({ hostname: "0.0.0.0", port: 7000 });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("the agent outlives a dropped client, and the next one catches up by seq", async () => {
|
|
101
|
+
const agent = new FakeAgent();
|
|
102
|
+
const unix = path.join(dir, "agent.sock");
|
|
103
|
+
const listener = new CodeAgentRpcListener(new CodeAgentRpcHost(agent as unknown as CodeAgent, null), { unix });
|
|
104
|
+
listener.listen();
|
|
105
|
+
const served = listener.serve();
|
|
106
|
+
|
|
107
|
+
const first = await Client.connect(unix);
|
|
108
|
+
first.send("1", { type: "prompt", message: "hi" });
|
|
109
|
+
expect((await first.reply("1")).ok).toBe(true);
|
|
110
|
+
first.close();
|
|
111
|
+
await Bun.sleep(20);
|
|
112
|
+
agent.emit();
|
|
113
|
+
expect(agent.aborted).toBe(false);
|
|
114
|
+
|
|
115
|
+
const second = await Client.connect(unix);
|
|
116
|
+
second.send("2", { type: "get_state", sinceSeq: 2 });
|
|
117
|
+
const state = await second.reply("2");
|
|
118
|
+
expect(state.data.frames?.map((frame) => frame.seq)).toEqual([3]);
|
|
119
|
+
|
|
120
|
+
second.send("3", { type: "shutdown" });
|
|
121
|
+
await second.reply("3");
|
|
122
|
+
await served;
|
|
123
|
+
expect(agent.disposed).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("over tcp", () => {
|
|
127
|
+
const opened = () => {
|
|
128
|
+
const agent = new FakeAgent();
|
|
129
|
+
const listener = new CodeAgentRpcListener(new CodeAgentRpcHost(agent as unknown as CodeAgent, null), {
|
|
130
|
+
hostname: "127.0.0.1",
|
|
131
|
+
port: 0,
|
|
132
|
+
}).listen();
|
|
133
|
+
return { agent, listener, port: listener.port ?? 0 };
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
test("a connection opened with the token is answered, and one without it is closed unheard", async () => {
|
|
137
|
+
const { agent, listener, port } = opened();
|
|
138
|
+
try {
|
|
139
|
+
expect(listener.token).toMatch(/^[A-Za-z0-9_-]{43}$/);
|
|
140
|
+
const anonymous = await Client.connect({ port });
|
|
141
|
+
anonymous.send("1", { type: "prompt", message: "hi" });
|
|
142
|
+
await anonymous.closed.promise;
|
|
143
|
+
expect(anonymous.lines).toEqual([{ type: "reply", id: "auth", ok: false, error: "unauthorized" }]);
|
|
144
|
+
|
|
145
|
+
const wrong = await Client.connect({ port });
|
|
146
|
+
wrong.raw(`${JSON.stringify({ auth: "not-the-token" })}\n`);
|
|
147
|
+
await wrong.closed.promise;
|
|
148
|
+
expect(agent.seq).toBe(1);
|
|
149
|
+
|
|
150
|
+
const client = await Client.connect({ port });
|
|
151
|
+
client.raw(
|
|
152
|
+
`${JSON.stringify({ auth: listener.token })}\n${JSON.stringify({ id: "2", command: { type: "prompt", message: "hi" } })}\n`,
|
|
153
|
+
);
|
|
154
|
+
expect((await client.reply("auth")).ok).toBe(true);
|
|
155
|
+
expect((await client.reply("2")).ok).toBe(true);
|
|
156
|
+
expect(client.lines.findIndex((line) => (line as { id?: string }).id === "auth")).toBe(0);
|
|
157
|
+
client.close();
|
|
158
|
+
} finally {
|
|
159
|
+
listener.stop();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("a connection that speaks anything but a JSON frame is dropped at its first byte", async () => {
|
|
164
|
+
const { listener, port } = opened();
|
|
165
|
+
try {
|
|
166
|
+
const browser = await Client.connect({ port });
|
|
167
|
+
browser.raw("GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
|
|
168
|
+
await browser.closed.promise;
|
|
169
|
+
expect(browser.lines).toEqual([]);
|
|
170
|
+
} finally {
|
|
171
|
+
listener.stop();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("a connection that has not authenticated does not displace the client that has", async () => {
|
|
176
|
+
const { listener, port } = opened();
|
|
177
|
+
try {
|
|
178
|
+
const client = await Client.connect({ port });
|
|
179
|
+
client.raw(`${JSON.stringify({ auth: listener.token })}\n`);
|
|
180
|
+
await client.reply("auth");
|
|
181
|
+
const other = await Client.connect({ port });
|
|
182
|
+
other.raw("{");
|
|
183
|
+
await Bun.sleep(30);
|
|
184
|
+
client.send("3", { type: "get_state", sinceSeq: 0 });
|
|
185
|
+
expect((await client.reply("3")).ok).toBe(true);
|
|
186
|
+
other.close();
|
|
187
|
+
client.close();
|
|
188
|
+
} finally {
|
|
189
|
+
listener.stop();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test.skipIf(process.platform === "win32")(
|
|
195
|
+
"a unix socket is its owner's alone, and needs no token, though one is accepted",
|
|
196
|
+
async () => {
|
|
197
|
+
const agent = new FakeAgent();
|
|
198
|
+
const unix = path.join(dir, "owned.sock");
|
|
199
|
+
const listener = new CodeAgentRpcListener(new CodeAgentRpcHost(agent as unknown as CodeAgent, null), { unix });
|
|
200
|
+
listener.listen();
|
|
201
|
+
try {
|
|
202
|
+
expect(listener.token).toBeNull();
|
|
203
|
+
expect(statSync(unix).mode & 0o777).toBe(0o600);
|
|
204
|
+
const client = await Client.connect(unix);
|
|
205
|
+
client.raw(`${JSON.stringify({ auth: "anything" })}\n`);
|
|
206
|
+
expect((await client.reply("auth")).ok).toBe(true);
|
|
207
|
+
client.send("4", { type: "get_state", sinceSeq: 0 });
|
|
208
|
+
expect((await client.reply("4")).ok).toBe(true);
|
|
209
|
+
client.close();
|
|
210
|
+
} finally {
|
|
211
|
+
listener.stop();
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
);
|
|
215
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { CodeAgentSuspended } from "./CodeAgentSuspended";
|
|
6
|
+
|
|
7
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-suspended-"));
|
|
8
|
+
afterAll(() => rmSync(dir, { recursive: true, force: true }));
|
|
9
|
+
|
|
10
|
+
const question = {
|
|
11
|
+
questionId: "qx.1",
|
|
12
|
+
prompt: "Which app?",
|
|
13
|
+
kind: "select" as const,
|
|
14
|
+
options: [{ key: "a", label: "akan" }],
|
|
15
|
+
};
|
|
16
|
+
const approval = {
|
|
17
|
+
approvalId: "ax.2",
|
|
18
|
+
toolCallId: "c1",
|
|
19
|
+
name: "write",
|
|
20
|
+
summary: "write a.ts",
|
|
21
|
+
policy: "writes" as const,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("CodeAgentSuspended", () => {
|
|
25
|
+
test("a restarted worker reads back what it was waiting on, and each ask is taken once", () => {
|
|
26
|
+
const file = CodeAgentSuspended.fileOf(dir, "s1");
|
|
27
|
+
const before = new CodeAgentSuspended(file);
|
|
28
|
+
before.setQuestion(question);
|
|
29
|
+
before.addApproval(approval);
|
|
30
|
+
|
|
31
|
+
const after = new CodeAgentSuspended(file);
|
|
32
|
+
expect(after.question).toEqual(question);
|
|
33
|
+
expect(after.approvals).toEqual([approval]);
|
|
34
|
+
expect(after.takeQuestion("qx.1")).toEqual(question);
|
|
35
|
+
expect(after.takeQuestion("qx.1")).toBeUndefined();
|
|
36
|
+
expect(after.takeApproval("ax.2")).toEqual(approval);
|
|
37
|
+
expect(after.takeApproval("ax.2")).toBeUndefined();
|
|
38
|
+
expect(existsSync(file ?? "")).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("a memory session keeps its asks without touching disk", () => {
|
|
42
|
+
const memory = new CodeAgentSuspended(CodeAgentSuspended.fileOf(undefined, "s2"));
|
|
43
|
+
memory.setQuestion(question);
|
|
44
|
+
expect(memory.takeQuestion("other")).toBeUndefined();
|
|
45
|
+
expect(memory.takeQuestion("qx.1")).toEqual(question);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { CodeMailbox } from "./CodeMailbox";
|
|
6
|
+
|
|
7
|
+
const boxes: CodeMailbox[] = [];
|
|
8
|
+
const open = (dir: string, id: string, name: string, onMail: (mail: { text: string }) => void = () => undefined) => {
|
|
9
|
+
const box = new CodeMailbox(dir, id, name);
|
|
10
|
+
box.open("/repo", onMail);
|
|
11
|
+
boxes.push(box);
|
|
12
|
+
return box;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
for (const box of boxes.splice(0)) box.close();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("CodeMailbox", () => {
|
|
20
|
+
test("each session sees the others and not itself", () => {
|
|
21
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-mail-"));
|
|
22
|
+
const one = open(dir, "aaaa1111", "gateway-work");
|
|
23
|
+
const two = open(dir, "bbbb2222", "store-work");
|
|
24
|
+
expect(one.peers().map((peer) => peer.name)).toEqual(["store-work"]);
|
|
25
|
+
expect(two.peers().map((peer) => peer.name)).toEqual(["gateway-work"]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a message lands in the other session's inbox and is delivered once", async () => {
|
|
29
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-mail-"));
|
|
30
|
+
const got: string[] = [];
|
|
31
|
+
const one = open(dir, "aaaa1111", "gateway-work");
|
|
32
|
+
open(dir, "bbbb2222", "store-work", (mail) => got.push(mail.text));
|
|
33
|
+
one.send("bbbb2222", "the adapter moved to srvkit");
|
|
34
|
+
await Bun.sleep(CodeMailbox.pollMs + 400);
|
|
35
|
+
expect(got).toEqual(["the adapter moved to srvkit"]);
|
|
36
|
+
await Bun.sleep(CodeMailbox.pollMs + 200);
|
|
37
|
+
expect(got).toEqual(["the adapter moved to srvkit"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a session opening on a full inbox does not replay it", async () => {
|
|
41
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-mail-"));
|
|
42
|
+
open(dir, "cccc3333", "seeded").close();
|
|
43
|
+
const inbox = path.join(dir, "inbox", "cccc3333.jsonl");
|
|
44
|
+
writeFileSync(inbox, `${JSON.stringify({ from: "x", fromName: "x", text: "old" })}\n`);
|
|
45
|
+
const got: string[] = [];
|
|
46
|
+
open(dir, "cccc3333", "seeded", (mail) => got.push(mail.text));
|
|
47
|
+
await Bun.sleep(CodeMailbox.pollMs + 400);
|
|
48
|
+
expect(got).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("a session that stopped beating is not offered as somewhere to send", () => {
|
|
52
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-mail-"));
|
|
53
|
+
const one = open(dir, "aaaa1111", "alive");
|
|
54
|
+
const stale = { id: "dddd4444", name: "crashed", cwd: "/repo", pid: 1, at: Date.now() - CodeMailbox.staleMs * 2 };
|
|
55
|
+
writeFileSync(path.join(dir, "live", "dddd4444.json"), JSON.stringify(stale));
|
|
56
|
+
expect(one.peers()).toEqual([]);
|
|
57
|
+
expect(one.find("crashed")).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a name or the front of an id finds one peer, and an ambiguous one finds none", () => {
|
|
61
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-mail-"));
|
|
62
|
+
const one = open(dir, "aaaa1111", "alive");
|
|
63
|
+
open(dir, "bbbb2222", "store-work");
|
|
64
|
+
open(dir, "bbbb3333", "store-other");
|
|
65
|
+
expect(one.find("store-work")?.id).toBe("bbbb2222");
|
|
66
|
+
expect(one.find("bbbb2")?.id).toBe("bbbb2222");
|
|
67
|
+
expect(one.find("store")).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("a runaway exchange is stopped by the ceiling rather than by the disk", () => {
|
|
71
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-mail-"));
|
|
72
|
+
const one = open(dir, "aaaa1111", "alive");
|
|
73
|
+
for (let at = 0; at < CodeMailbox.sendsPerMinute; at += 1) one.send("bbbb2222", "ping");
|
|
74
|
+
expect(() => one.send("bbbb2222", "ping")).toThrow("a minute is the ceiling");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { CodeSessionFork } from "./CodeSessionFork";
|
|
6
|
+
import { CodeSessionIndex } from "./CodeSessionIndex";
|
|
7
|
+
|
|
8
|
+
const lines = (id: string) => [
|
|
9
|
+
JSON.stringify({ type: "session", version: 3, id, timestamp: "2026-09-20T14:35:32.579Z", cwd: "/repo" }),
|
|
10
|
+
JSON.stringify({ type: "session_info", id: "aa", parentId: null, name: "read-the-guard" }),
|
|
11
|
+
JSON.stringify({ type: "message", id: "bb", parentId: "aa", message: { role: "user", content: "who guards it" } }),
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const seed = () => {
|
|
15
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-fork-"));
|
|
16
|
+
const id = "01a0bf3e-6563-78f4-9017-c541ca067354";
|
|
17
|
+
const file = path.join(dir, `2026-09-20T14-35-32-579Z_${id}.jsonl`);
|
|
18
|
+
writeFileSync(file, `${lines(id).join("\n")}\n`);
|
|
19
|
+
return { dir, id, file };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const records = (file: string) =>
|
|
23
|
+
readFileSync(file, "utf8")
|
|
24
|
+
.split("\n")
|
|
25
|
+
.filter((line) => !!line.trim())
|
|
26
|
+
.map((line) => JSON.parse(line) as { type?: string; id?: string; name?: string });
|
|
27
|
+
|
|
28
|
+
describe("CodeSessionFork", () => {
|
|
29
|
+
test("the copy carries the conversation under an id of its own", () => {
|
|
30
|
+
const { dir, id, file } = seed();
|
|
31
|
+
const forked = CodeSessionFork.fork(dir, id);
|
|
32
|
+
expect(forked.id).not.toBe(id);
|
|
33
|
+
expect(forked.file).not.toBe(file);
|
|
34
|
+
const copied = records(forked.file);
|
|
35
|
+
expect(copied.find((record) => record.type === "session")?.id).toBe(forked.id);
|
|
36
|
+
expect(copied.filter((record) => record.type === "message").length).toBe(1);
|
|
37
|
+
expect(CodeSessionIndex.fileOf(dir, forked.id)).toBe(forked.file);
|
|
38
|
+
expect(CodeSessionIndex.fileOf(dir, id)).toBe(file);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("the original is left exactly as it was", () => {
|
|
42
|
+
const { dir, id, file } = seed();
|
|
43
|
+
const before = readFileSync(file, "utf8");
|
|
44
|
+
CodeSessionFork.fork(dir, id);
|
|
45
|
+
expect(readFileSync(file, "utf8")).toBe(before);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("the copy says it is one, and takes a name when given one", () => {
|
|
49
|
+
const { dir, id } = seed();
|
|
50
|
+
expect(records(CodeSessionFork.fork(dir, id).file).at(-1)?.name).toBe("read-the-guard-fork");
|
|
51
|
+
expect(records(CodeSessionFork.fork(dir, id, "try the other guard").file).at(-1)?.name).toBe("try the other guard");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("an id nothing on disk answers to is refused rather than opening a new session", () => {
|
|
55
|
+
const { dir } = seed();
|
|
56
|
+
expect(() => CodeSessionFork.fork(dir, "nope")).toThrow("No stored session nope");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { codeAgentSessionName } from "akanjs/common";
|
|
6
|
+
import { CodeSessionIndex } from "./CodeSessionIndex";
|
|
7
|
+
|
|
8
|
+
const write = (dir: string, id: string, lines: unknown[]) => {
|
|
9
|
+
const file = path.join(dir, `2026-09-20T10-00-00-000Z_${id}.jsonl`);
|
|
10
|
+
writeFileSync(file, `${lines.map((line) => JSON.stringify(line)).join("\n")}\n`);
|
|
11
|
+
return file;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const session = (id: string) => ({ type: "session", version: 3, id, cwd: "/repo" });
|
|
15
|
+
const user = (text: string) => ({ type: "message", message: { role: "user", content: [{ type: "text", text }] } });
|
|
16
|
+
const assistant = (text: string) => ({
|
|
17
|
+
type: "message",
|
|
18
|
+
message: { role: "assistant", content: [{ type: "text", text }] },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("CodeSessionIndex", () => {
|
|
22
|
+
test("reads the name, the opening ask and how many turns a session holds", () => {
|
|
23
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-sessions-"));
|
|
24
|
+
write(dir, "s1", [
|
|
25
|
+
session("s1"),
|
|
26
|
+
user("add a comment module"),
|
|
27
|
+
assistant("done"),
|
|
28
|
+
user("now wire it up"),
|
|
29
|
+
{ type: "session_info", name: "add-a-comment-module" },
|
|
30
|
+
{ type: "session_info", name: "comment-module" },
|
|
31
|
+
]);
|
|
32
|
+
const [entry] = CodeSessionIndex.list(dir);
|
|
33
|
+
expect(entry?.id).toBe("s1");
|
|
34
|
+
expect(entry?.name).toBe("comment-module");
|
|
35
|
+
expect(entry?.opening).toBe("add a comment module");
|
|
36
|
+
expect(entry?.turns).toBe(2);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("a file that is not a session is skipped rather than listed as a blank one", () => {
|
|
40
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-sessions-"));
|
|
41
|
+
writeFileSync(path.join(dir, "notes.txt"), "not a session");
|
|
42
|
+
write(dir, "s2", [{ type: "model_change", provider: "deepseek" }, user("hi")]);
|
|
43
|
+
write(dir, "s3", [session("s3"), user("hi")]);
|
|
44
|
+
expect(CodeSessionIndex.list(dir).map((entry) => entry.id)).toEqual(["s3"]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("a session past the read limit is still listed, from its opening lines", () => {
|
|
48
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-sessions-"));
|
|
49
|
+
const filler = assistant("x".repeat(64 * 1024));
|
|
50
|
+
write(dir, "big", [session("big"), user("port the dashboard"), ...Array.from({ length: 10 }, () => filler)]);
|
|
51
|
+
const [entry] = CodeSessionIndex.list(dir);
|
|
52
|
+
expect(entry?.id).toBe("big");
|
|
53
|
+
expect(entry?.opening).toBe("port the dashboard");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("an id resolves to its file, and an unknown one to nothing", () => {
|
|
57
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-sessions-"));
|
|
58
|
+
const file = write(dir, "s4", [session("s4"), user("hi")]);
|
|
59
|
+
expect(CodeSessionIndex.fileOf(dir, "s4")).toBe(file);
|
|
60
|
+
expect(CodeSessionIndex.fileOf(dir, "s5")).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("a missing directory lists nothing instead of throwing", () => {
|
|
64
|
+
expect(CodeSessionIndex.list(path.join(tmpdir(), "akan-sessions-missing"))).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("codeAgentSessionName", () => {
|
|
69
|
+
test("names a session after what it was asked, in one glanceable line", () => {
|
|
70
|
+
expect(codeAgentSessionName("Add a comment module to apps/minimal")).toBe("add-a-comment-module-to-apps-minimal");
|
|
71
|
+
expect(codeAgentSessionName("Add a comment module to apps/minimal and wire up its dictionary")).toBe(
|
|
72
|
+
"add-a-comment-module-to-apps-minimal-and",
|
|
73
|
+
);
|
|
74
|
+
expect(codeAgentSessionName("안녕, 모듈 하나 만들어줘")).toBe("안녕-모듈-하나-만들어줘");
|
|
75
|
+
expect(codeAgentSessionName("```ts\nconst a = 1;\n```")).toBe("session");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Console } from "node:console";
|
|
2
|
+
|
|
3
|
+
// Bun's native `console` writes to fd 1 directly, past the engine's stdout guard, corrupting the RPC stream.
|
|
4
|
+
// Must be the first import of an RPC entry: ESM evaluates imports first, so an inline assignment runs too late.
|
|
5
|
+
globalThis.console = new Console({
|
|
6
|
+
stdout: process.stderr,
|
|
7
|
+
stderr: process.stderr,
|
|
8
|
+
}) as unknown as typeof globalThis.console;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { closeSync, openSync, readFileSync, readSync, statSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
const readHead = (file: string, maxBytes: number) => {
|
|
4
|
+
const fd = openSync(file, "r");
|
|
5
|
+
try {
|
|
6
|
+
const head = Buffer.alloc(maxBytes);
|
|
7
|
+
return head.subarray(0, readSync(fd, head, 0, maxBytes, 0)).toString("utf8");
|
|
8
|
+
} finally {
|
|
9
|
+
closeSync(fd);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const readJsonLines = (file: string, maxBytes?: number) => {
|
|
14
|
+
try {
|
|
15
|
+
const text =
|
|
16
|
+
maxBytes !== undefined && statSync(file).size > maxBytes ? readHead(file, maxBytes) : readFileSync(file, "utf8");
|
|
17
|
+
return text.split("\n").filter((line) => !!line.trim());
|
|
18
|
+
} catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const parseJsonLine = <T>(line: string) => {
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(line) as T;
|
|
26
|
+
} catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
};
|