@textcortex/zenocode 0.1.2 → 0.1.4
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.md +31 -0
- package/package.json +8 -8
- package/scripts/branding-patch.mjs +112 -3
- package/scripts/branding-patch.test.mjs +17 -0
- package/scripts/build-branded-opencode.mjs +520 -78
- package/scripts/build-branded-opencode.test.mjs +25 -0
- package/scripts/{run-codecortex.mjs → run-zenocode.mjs} +323 -80
- package/scripts/run-zenocode.test.mjs +224 -0
- package/scripts/run-codecortex.test.mjs +0 -59
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import {
|
|
8
|
+
buildPaddedLogoSnippet,
|
|
9
|
+
patchLogoSnippetText,
|
|
10
|
+
} from "./branding-patch.mjs";
|
|
11
|
+
import {
|
|
12
|
+
buildOpenCodeConfig,
|
|
13
|
+
canRecoverRuntimeSessionFromTranscript,
|
|
14
|
+
buildZenocodeBanner,
|
|
15
|
+
chooseDefaults,
|
|
16
|
+
runRuntimeWithSessionRecovery,
|
|
17
|
+
writePrivateJsonFile,
|
|
18
|
+
} from "./run-zenocode.mjs";
|
|
19
|
+
|
|
20
|
+
test("chooseDefaults prefers kimi k2.5 thinking for Zenocode", () => {
|
|
21
|
+
const defaults = chooseDefaults({
|
|
22
|
+
"glm-5": {},
|
|
23
|
+
"kimi-k2-5-thinking": {},
|
|
24
|
+
"gpt-5-2": {},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
assert.deepEqual(defaults, {
|
|
28
|
+
model: "kimi-k2-5-thinking",
|
|
29
|
+
smallModel: "kimi-k2-5-thinking",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("buildOpenCodeConfig includes an openai stub for fallback runtime auth plugins", () => {
|
|
34
|
+
const config = buildOpenCodeConfig({
|
|
35
|
+
baseUrl: "http://127.0.0.1:8080",
|
|
36
|
+
providerID: "textcortex",
|
|
37
|
+
model: "kimi-k2-5-thinking",
|
|
38
|
+
smallModel: "kimi-k2-5-thinking",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
assert.deepEqual(config.enabled_providers, ["textcortex"]);
|
|
42
|
+
assert.equal(config.model, "textcortex/kimi-k2-5-thinking");
|
|
43
|
+
assert.ok(config.provider.openai);
|
|
44
|
+
assert.deepEqual(config.provider.openai.models, {});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("buildZenocodeBanner renders block logo art instead of plain text", () => {
|
|
48
|
+
const banner = buildZenocodeBanner();
|
|
49
|
+
|
|
50
|
+
assert.match(banner, /▀▀█/);
|
|
51
|
+
assert.match(banner, /█▀▀/);
|
|
52
|
+
assert.match(banner, /█▄▄/);
|
|
53
|
+
assert.doesNotMatch(banner, /\bZenocode\b/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("patchLogoSnippetText upgrades previously branded Zenocode logos", () => {
|
|
57
|
+
const legacyTextLogoSnippet = `var logo = {
|
|
58
|
+
left: [" ", " Zenocode ", " Zenocode ", " "],
|
|
59
|
+
right: [" ", " ", " ", " "]
|
|
60
|
+
};
|
|
61
|
+
var marks = "_^~";`;
|
|
62
|
+
|
|
63
|
+
const result = patchLogoSnippetText(buildPaddedLogoSnippet(legacyTextLogoSnippet));
|
|
64
|
+
|
|
65
|
+
assert.equal(result.patched, true);
|
|
66
|
+
assert.match(result.text, /\\u2580\\u2580\\u2588/);
|
|
67
|
+
assert.match(result.text, /\\u2588\\u2580\\u2580/);
|
|
68
|
+
assert.doesNotMatch(result.text, /\\\\u2580/);
|
|
69
|
+
assert.doesNotMatch(result.text, /Zenocode/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("patchLogoSnippetText upgrades double-escaped Zenocode glyph logos", () => {
|
|
73
|
+
const brokenGlyphLogoSnippet = String.raw`var logo = {
|
|
74
|
+
left: [" "," \\u2580\\u2580\\u2588 \\u2588\\u2580\\u2580 \\u2588\\u2584 \\u2588 \\u2588\\u2580\\u2588"," \\u2588\\u2584\\u2584 \\u2588\\u2588\\u2584 \\u2588 \\u2580\\u2588 \\u2588\\u2584\\u2588"," "],
|
|
75
|
+
right: [" "," \\u2588\\u2580\\u2580 \\u2588\\u2580\\u2588 \\u2588\\u2580\\u2584 \\u2588\\u2580\\u2580"," \\u2588\\u2584\\u2584 \\u2588\\u2584\\u2588 \\u2588\\u2584\\u2580 \\u2588\\u2588\\u2584"," "]
|
|
76
|
+
};
|
|
77
|
+
var marks = "_^~";`;
|
|
78
|
+
|
|
79
|
+
const result = patchLogoSnippetText(buildPaddedLogoSnippet(brokenGlyphLogoSnippet));
|
|
80
|
+
|
|
81
|
+
assert.equal(result.patched, true);
|
|
82
|
+
assert.match(result.text, /\\u2580\\u2580\\u2588/);
|
|
83
|
+
assert.match(result.text, /\\u2588\\u2580\\u2580/);
|
|
84
|
+
assert.doesNotMatch(result.text, /\\\\u2580/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("writePrivateJsonFile stores credentials with private permissions", async (t) => {
|
|
88
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "zenocode-runtime-"));
|
|
89
|
+
const credentialsPath = path.join(tempDir, "runtime", "credentials.json");
|
|
90
|
+
|
|
91
|
+
t.after(async () => {
|
|
92
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
await writePrivateJsonFile(credentialsPath, { access_token: "secret-token" });
|
|
96
|
+
|
|
97
|
+
const saved = JSON.parse(await fs.readFile(credentialsPath, "utf-8"));
|
|
98
|
+
assert.equal(saved.access_token, "secret-token");
|
|
99
|
+
|
|
100
|
+
if (process.platform !== "win32") {
|
|
101
|
+
const dirMode = (await fs.stat(path.dirname(credentialsPath))).mode & 0o777;
|
|
102
|
+
const fileMode = (await fs.stat(credentialsPath)).mode & 0o777;
|
|
103
|
+
|
|
104
|
+
assert.equal(dirMode, 0o700);
|
|
105
|
+
assert.equal(fileMode, 0o600);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("canRecoverRuntimeSessionFromTranscript detects expired session output", () => {
|
|
110
|
+
const transcript = [
|
|
111
|
+
"\u001b[2J\u001b[H",
|
|
112
|
+
"cool, is there anything about zenocode?",
|
|
113
|
+
"",
|
|
114
|
+
'Unauthorized: {"detail":"Token has expired"}',
|
|
115
|
+
].join("\n");
|
|
116
|
+
|
|
117
|
+
assert.equal(canRecoverRuntimeSessionFromTranscript(transcript), true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("runRuntimeWithSessionRecovery reruns login after runtime session expiry", async () => {
|
|
121
|
+
const events = [];
|
|
122
|
+
let launchCount = 0;
|
|
123
|
+
|
|
124
|
+
const result = await runRuntimeWithSessionRecovery({
|
|
125
|
+
args: ["run"],
|
|
126
|
+
baseUrl: "http://127.0.0.1:8080",
|
|
127
|
+
token: "token-1",
|
|
128
|
+
childOptions: {
|
|
129
|
+
cwd: process.cwd(),
|
|
130
|
+
env: {},
|
|
131
|
+
},
|
|
132
|
+
canAutoLoginRuntime: true,
|
|
133
|
+
runLogin: async (baseUrl, loginArgs) => {
|
|
134
|
+
events.push(["login", baseUrl, loginArgs]);
|
|
135
|
+
},
|
|
136
|
+
resolveTokenFn: async () => {
|
|
137
|
+
events.push(["resolve-token"]);
|
|
138
|
+
return "token-2";
|
|
139
|
+
},
|
|
140
|
+
resolveStoredBaseUrlFn: async () => {
|
|
141
|
+
events.push(["resolve-base-url"]);
|
|
142
|
+
return "https://api.textcortex.com";
|
|
143
|
+
},
|
|
144
|
+
prepareRuntimeFn: async (baseUrl, token) => {
|
|
145
|
+
events.push(["prepare", baseUrl, token]);
|
|
146
|
+
return "kimi-k2-5-thinking";
|
|
147
|
+
},
|
|
148
|
+
launchRuntimeFn: async ({ childOptions }) => {
|
|
149
|
+
launchCount += 1;
|
|
150
|
+
events.push(["launch", launchCount, childOptions.env.TEXTCORTEX_API_KEY]);
|
|
151
|
+
if (launchCount === 1) {
|
|
152
|
+
return { expiredSession: true };
|
|
153
|
+
}
|
|
154
|
+
return { code: 0, signal: null, expiredSession: false };
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
assert.deepEqual(events, [
|
|
159
|
+
["launch", 1, "token-1"],
|
|
160
|
+
["login", "http://127.0.0.1:8080", []],
|
|
161
|
+
["resolve-token"],
|
|
162
|
+
["resolve-base-url"],
|
|
163
|
+
["prepare", "https://api.textcortex.com", "token-2"],
|
|
164
|
+
["launch", 2, "token-2"],
|
|
165
|
+
]);
|
|
166
|
+
assert.deepEqual(result, { code: 0, signal: null, expiredSession: false });
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("logout removes legacy credential fallbacks as well as Zenocode credentials", async (t) => {
|
|
170
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "zenocode-logout-"));
|
|
171
|
+
const zenocodeHome = path.join(tempDir, ".zenocode");
|
|
172
|
+
const codecortexHome = path.join(tempDir, ".codecortex");
|
|
173
|
+
const repoCredentialsPath = path.join(tempDir, ".credentials.json");
|
|
174
|
+
const runtimeCredentialsPath = path.join(zenocodeHome, "credentials.json");
|
|
175
|
+
const legacyRuntimeCredentialsPath = path.join(codecortexHome, "credentials.json");
|
|
176
|
+
const scriptPath = new URL("./run-zenocode.mjs", import.meta.url);
|
|
177
|
+
|
|
178
|
+
t.after(async () => {
|
|
179
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await fs.mkdir(path.dirname(runtimeCredentialsPath), { recursive: true });
|
|
183
|
+
await fs.mkdir(path.dirname(legacyRuntimeCredentialsPath), { recursive: true });
|
|
184
|
+
await fs.writeFile(runtimeCredentialsPath, JSON.stringify({ access_token: "current" }));
|
|
185
|
+
await fs.writeFile(
|
|
186
|
+
legacyRuntimeCredentialsPath,
|
|
187
|
+
JSON.stringify({ access_token: "legacy" }),
|
|
188
|
+
);
|
|
189
|
+
await fs.writeFile(repoCredentialsPath, JSON.stringify({ access_token: "repo" }));
|
|
190
|
+
|
|
191
|
+
const result = await new Promise((resolve, reject) => {
|
|
192
|
+
const child = spawn(
|
|
193
|
+
process.execPath,
|
|
194
|
+
[scriptPath.pathname, "logout"],
|
|
195
|
+
{
|
|
196
|
+
cwd: tempDir,
|
|
197
|
+
env: {
|
|
198
|
+
...process.env,
|
|
199
|
+
ZENOCODE_HOME: zenocodeHome,
|
|
200
|
+
CODECORTEX_HOME: codecortexHome,
|
|
201
|
+
},
|
|
202
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
let stdout = "";
|
|
206
|
+
let stderr = "";
|
|
207
|
+
child.stdout.on("data", (chunk) => {
|
|
208
|
+
stdout += String(chunk);
|
|
209
|
+
});
|
|
210
|
+
child.stderr.on("data", (chunk) => {
|
|
211
|
+
stderr += String(chunk);
|
|
212
|
+
});
|
|
213
|
+
child.on("error", reject);
|
|
214
|
+
child.on("exit", (code, signal) => resolve({ code, signal, stdout, stderr }));
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
assert.equal(result.code, 0);
|
|
218
|
+
await assert.rejects(fs.stat(runtimeCredentialsPath), { code: "ENOENT" });
|
|
219
|
+
await assert.rejects(fs.stat(legacyRuntimeCredentialsPath), { code: "ENOENT" });
|
|
220
|
+
assert.deepEqual(
|
|
221
|
+
JSON.parse(await fs.readFile(repoCredentialsPath, "utf-8")),
|
|
222
|
+
{ access_token: "repo" },
|
|
223
|
+
);
|
|
224
|
+
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import test from "node:test";
|
|
6
|
-
import {
|
|
7
|
-
buildOpenCodeConfig,
|
|
8
|
-
chooseDefaults,
|
|
9
|
-
writePrivateJsonFile,
|
|
10
|
-
} from "./run-codecortex.mjs";
|
|
11
|
-
|
|
12
|
-
test("chooseDefaults prefers kimi k2.5 thinking for Zenocode", () => {
|
|
13
|
-
const defaults = chooseDefaults({
|
|
14
|
-
"glm-5": {},
|
|
15
|
-
"kimi-k2-5-thinking": {},
|
|
16
|
-
"gpt-5-2": {},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
assert.deepEqual(defaults, {
|
|
20
|
-
model: "kimi-k2-5-thinking",
|
|
21
|
-
smallModel: "kimi-k2-5-thinking",
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("buildOpenCodeConfig includes an openai stub for fallback runtime auth plugins", () => {
|
|
26
|
-
const config = buildOpenCodeConfig({
|
|
27
|
-
baseUrl: "http://127.0.0.1:8080",
|
|
28
|
-
providerID: "textcortex",
|
|
29
|
-
model: "kimi-k2-5-thinking",
|
|
30
|
-
smallModel: "kimi-k2-5-thinking",
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
assert.deepEqual(config.enabled_providers, ["textcortex"]);
|
|
34
|
-
assert.equal(config.model, "textcortex/kimi-k2-5-thinking");
|
|
35
|
-
assert.ok(config.provider.openai);
|
|
36
|
-
assert.deepEqual(config.provider.openai.models, {});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("writePrivateJsonFile stores credentials with private permissions", async (t) => {
|
|
40
|
-
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "zenocode-runtime-"));
|
|
41
|
-
const credentialsPath = path.join(tempDir, "runtime", "credentials.json");
|
|
42
|
-
|
|
43
|
-
t.after(async () => {
|
|
44
|
-
await fs.rm(tempDir, { recursive: true, force: true });
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await writePrivateJsonFile(credentialsPath, { access_token: "secret-token" });
|
|
48
|
-
|
|
49
|
-
const saved = JSON.parse(await fs.readFile(credentialsPath, "utf-8"));
|
|
50
|
-
assert.equal(saved.access_token, "secret-token");
|
|
51
|
-
|
|
52
|
-
if (process.platform !== "win32") {
|
|
53
|
-
const dirMode = (await fs.stat(path.dirname(credentialsPath))).mode & 0o777;
|
|
54
|
-
const fileMode = (await fs.stat(credentialsPath)).mode & 0o777;
|
|
55
|
-
|
|
56
|
-
assert.equal(dirMode, 0o700);
|
|
57
|
-
assert.equal(fileMode, 0o600);
|
|
58
|
-
}
|
|
59
|
-
});
|