@elaraai/east-codex-plugin 0.0.0-stage → 1.0.90

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.
@@ -0,0 +1,399 @@
1
+ // ../east-plugin/dist/lib/host.js
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ var isCodex = existsSync(fileURLToPath(new URL("../../.codex-plugin/plugin.json", import.meta.url)));
5
+ function hostText(text) {
6
+ return isCodex ? text.replaceAll("mcp__plugin_east_east__", "").replaceAll("/east:", "$east-codex-plugin:").replaceAll("Claude Code", "Codex") : text;
7
+ }
8
+
9
+ // ../east-plugin/dist/lib/hook-io.js
10
+ async function readHookInput() {
11
+ let input = "";
12
+ for await (const chunk of process.stdin) {
13
+ input += chunk;
14
+ }
15
+ return JSON.parse(input);
16
+ }
17
+ function writeHookOutput(hookEventName, additionalContext) {
18
+ const output = {
19
+ hookSpecificOutput: {
20
+ hookEventName,
21
+ additionalContext: hostText(additionalContext)
22
+ }
23
+ };
24
+ process.stdout.write(JSON.stringify(output));
25
+ }
26
+
27
+ // ../east-plugin/dist/lib/review.js
28
+ import { readFile as readFile2 } from "node:fs/promises";
29
+ import { existsSync as existsSync4, writeFileSync as writeFileSync2 } from "node:fs";
30
+ import { createHash as createHash2 } from "node:crypto";
31
+ import { tmpdir as tmpdir3 } from "node:os";
32
+ import { join as join4, dirname as dirname4, resolve as resolve2 } from "node:path";
33
+
34
+ // ../east-plugin/dist/lib/east-project.js
35
+ import { readFile } from "node:fs/promises";
36
+ import { join, dirname } from "node:path";
37
+ var PACKAGE_SKILL_MAP = {
38
+ "@elaraai/east": "east",
39
+ "@elaraai/east-node-std": "east-node-std",
40
+ "@elaraai/east-node-io": "east-node-io",
41
+ "@elaraai/east-py-datascience": "east-py-datascience",
42
+ "@elaraai/east-ui": "east-ui",
43
+ "@elaraai/e3": "e3",
44
+ "@elaraai/e3-ui": "e3-ui"
45
+ };
46
+ var PYTHON_SKILL_MAP = [
47
+ [/elaraai-east-py-datascience(?![\w-])/, "east-py-datascience"],
48
+ [/elaraai-east-py-std(?![\w-])/, "east-py-std"],
49
+ [/elaraai-east-py-io(?![\w-])/, "east-py-io"],
50
+ [/elaraai-east-py(?![\w-])/, "east-py"]
51
+ ];
52
+ async function findPackageJson(startDir) {
53
+ let dir = startDir;
54
+ while (true) {
55
+ try {
56
+ const content = await readFile(join(dir, "package.json"), "utf-8");
57
+ return JSON.parse(content);
58
+ } catch {
59
+ const parent = dirname(dir);
60
+ if (parent === dir)
61
+ return null;
62
+ dir = parent;
63
+ }
64
+ }
65
+ }
66
+ async function findPyProject(startDir) {
67
+ let dir = startDir;
68
+ let nearest = null;
69
+ while (true) {
70
+ try {
71
+ const text = await readFile(join(dir, "pyproject.toml"), "utf-8");
72
+ if (PYTHON_SKILL_MAP.some(([pattern]) => pattern.test(text)))
73
+ return text;
74
+ nearest ??= text;
75
+ } catch {
76
+ }
77
+ const parent = dirname(dir);
78
+ if (parent === dir)
79
+ return nearest;
80
+ dir = parent;
81
+ }
82
+ }
83
+ function detectEastSkills(pkg) {
84
+ if (!pkg)
85
+ return [];
86
+ const allDeps = {
87
+ ...pkg.dependencies,
88
+ ...pkg.devDependencies
89
+ };
90
+ const skills = [];
91
+ for (const [packageName, skillName] of Object.entries(PACKAGE_SKILL_MAP)) {
92
+ if (packageName in allDeps) {
93
+ skills.push(skillName);
94
+ }
95
+ }
96
+ return skills;
97
+ }
98
+ function detectPythonSkills(pyproject) {
99
+ if (pyproject === null)
100
+ return [];
101
+ const skills = [];
102
+ for (const [pattern, skill] of PYTHON_SKILL_MAP) {
103
+ if (pattern.test(pyproject))
104
+ skills.push(skill);
105
+ }
106
+ return skills;
107
+ }
108
+ async function getEastProjectInfo(cwd) {
109
+ const pkg = await findPackageJson(cwd);
110
+ const tsSkills = detectEastSkills(pkg);
111
+ const pySkills = detectPythonSkills(await findPyProject(cwd));
112
+ const languages = [];
113
+ if (tsSkills.length > 0)
114
+ languages.push("typescript");
115
+ if (pySkills.length > 0)
116
+ languages.push("python");
117
+ const skills = [...tsSkills, ...pySkills.filter((s) => !tsSkills.includes(s))];
118
+ return { isEast: skills.length > 0, skills, languages, pkg };
119
+ }
120
+
121
+ // ../east-plugin/dist/lib/diagnostics-client.js
122
+ import { createConnection } from "node:net";
123
+ import { spawn } from "node:child_process";
124
+ import { createHash } from "node:crypto";
125
+ import { tmpdir } from "node:os";
126
+ import { existsSync as existsSync2, unlinkSync } from "node:fs";
127
+ import { dirname as dirname2, join as join2, resolve } from "node:path";
128
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
129
+ function daemonSocket() {
130
+ const hash = createHash("sha1").update(daemonEntry()).digest("hex").slice(0, 16);
131
+ return join2(tmpdir(), `east-diag-${hash}.sock`);
132
+ }
133
+ function daemonEntry() {
134
+ return resolve(dirname2(fileURLToPath2(import.meta.url)), "..", "daemon", "server.js");
135
+ }
136
+ function tryRequest(socketPath, file, timeoutMs) {
137
+ return new Promise((resolveResult) => {
138
+ const conn = createConnection(socketPath);
139
+ let buffer = "";
140
+ let settled = false;
141
+ const settle = (result) => {
142
+ if (settled)
143
+ return;
144
+ settled = true;
145
+ clearTimeout(timer);
146
+ conn.destroy();
147
+ resolveResult(result);
148
+ };
149
+ const timer = setTimeout(() => settle({ kind: "timeout" }), timeoutMs);
150
+ timer.unref();
151
+ conn.on("connect", () => conn.write(`${JSON.stringify({ file })}
152
+ `));
153
+ conn.on("data", (chunk) => {
154
+ buffer += chunk.toString("utf8");
155
+ const newline = buffer.indexOf("\n");
156
+ if (newline < 0)
157
+ return;
158
+ try {
159
+ const response = JSON.parse(buffer.slice(0, newline));
160
+ settle(response.ok === true ? { kind: "text", text: response.text ?? "" } : { kind: "error" });
161
+ } catch {
162
+ settle({ kind: "error" });
163
+ }
164
+ });
165
+ conn.on("error", (err) => {
166
+ settle(err.code === "ECONNREFUSED" || err.code === "ENOENT" ? { kind: "refused" } : { kind: "error" });
167
+ });
168
+ });
169
+ }
170
+ function spawnDaemon(socketPath, workspace) {
171
+ const entry = daemonEntry();
172
+ if (!existsSync2(entry))
173
+ return;
174
+ try {
175
+ spawn(process.execPath, [entry], {
176
+ detached: true,
177
+ stdio: "ignore",
178
+ env: { ...process.env, EAST_DIAG_SOCKET: socketPath, EAST_DIAG_CWD: workspace }
179
+ }).unref();
180
+ } catch {
181
+ }
182
+ }
183
+ async function getDiagnosticsText(workspace, file, budgetMs = 4e3) {
184
+ const socketPath = daemonSocket();
185
+ const deadline = Date.now() + budgetMs;
186
+ let spawned = false;
187
+ while (Date.now() < deadline) {
188
+ const attempt = await tryRequest(socketPath, file, Math.min(1500, deadline - Date.now()));
189
+ if (attempt.kind === "text")
190
+ return attempt.text;
191
+ if (attempt.kind === "refused" && !spawned) {
192
+ if (existsSync2(socketPath)) {
193
+ try {
194
+ unlinkSync(socketPath);
195
+ } catch {
196
+ }
197
+ }
198
+ spawnDaemon(socketPath, workspace);
199
+ spawned = true;
200
+ }
201
+ await new Promise((r) => setTimeout(r, 200));
202
+ }
203
+ return null;
204
+ }
205
+
206
+ // ../east-diagnostics/dist/src/python-lint.js
207
+ import { execFile } from "node:child_process";
208
+ import { existsSync as existsSync3, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
209
+ import { tmpdir as tmpdir2 } from "node:os";
210
+ import { basename, dirname as dirname3, join as join3 } from "node:path";
211
+ var PYTHON_EAST_IMPORT = /^\s*(?:from\s+east(?:\.[\w.]+)?\s+import\b|import\s+east\b)/m;
212
+ function findEastPy(fromDir) {
213
+ const override = process.env["EAST_PY_LINT"];
214
+ if (override !== void 0 && override !== "")
215
+ return override;
216
+ let dir = fromDir;
217
+ for (; ; ) {
218
+ for (const candidate of [join3(dir, ".venv", "bin", "east-py"), join3(dir, ".venv", "Scripts", "east-py.exe")]) {
219
+ if (existsSync3(candidate))
220
+ return candidate;
221
+ }
222
+ const parent = dirname3(dir);
223
+ if (parent === dir)
224
+ return "east-py";
225
+ dir = parent;
226
+ }
227
+ }
228
+ function runEastPyLint(file, content, budgetMs = 4e3, command = findEastPy(dirname3(file))) {
229
+ let target = file;
230
+ let scratch = null;
231
+ if (content !== void 0) {
232
+ scratch = mkdtempSync(join3(tmpdir2(), "east-py-lint-"));
233
+ target = join3(scratch, basename(file));
234
+ writeFileSync(target, content, "utf-8");
235
+ }
236
+ return new Promise((resolveFindings) => {
237
+ execFile(
238
+ command,
239
+ ["lint", "--format", "json", target],
240
+ // UTF-8 stdio: python encodes a piped stdout in the locale's code page on Windows (cp1252), and the findings carry em dashes
241
+ { timeout: budgetMs, encoding: "utf-8", maxBuffer: 4 * 1024 * 1024, env: { ...process.env, PYTHONIOENCODING: "utf-8" } },
242
+ (error, stdout) => {
243
+ if (scratch !== null)
244
+ rmSync(scratch, { recursive: true, force: true });
245
+ if (error !== null && error.code !== 1) {
246
+ resolveFindings(null);
247
+ return;
248
+ }
249
+ let records;
250
+ try {
251
+ records = JSON.parse(stdout);
252
+ } catch {
253
+ resolveFindings(null);
254
+ return;
255
+ }
256
+ resolveFindings(Array.isArray(records) ? records : null);
257
+ }
258
+ );
259
+ });
260
+ }
261
+ function runEastPyCheck(file, budgetMs = 8e3, command = findEastPy(dirname3(file))) {
262
+ return new Promise((resolveFindings) => {
263
+ execFile(command, ["check", "--format", "json", "--only-if-enabled", file], { timeout: budgetMs, encoding: "utf-8", maxBuffer: 4 * 1024 * 1024, env: { ...process.env, PYTHONIOENCODING: "utf-8" } }, (error, stdout) => {
264
+ if (error !== null && error.code !== 1) {
265
+ resolveFindings(null);
266
+ return;
267
+ }
268
+ let records;
269
+ try {
270
+ records = JSON.parse(stdout);
271
+ } catch {
272
+ resolveFindings(null);
273
+ return;
274
+ }
275
+ resolveFindings(Array.isArray(records) ? records : null);
276
+ });
277
+ });
278
+ }
279
+ function renderPythonReview(records) {
280
+ if (records.length === 0)
281
+ return "";
282
+ const lines = records.map((r) => `- [${r.category}] ${r.line}:${r.column} (${r.rule}) ${r.message}`);
283
+ return ["<east-code-review>", "## East issues in this file", "", ...lines, "</east-code-review>"].join("\n");
284
+ }
285
+
286
+ // ../east-plugin/dist/lib/east-py-lint.js
287
+ async function getPythonDiagnosticsText(file, budgetMs = 4e3) {
288
+ const [rules, build] = await Promise.all([runEastPyLint(file, void 0, budgetMs), runEastPyCheck(file, budgetMs)]);
289
+ if (rules === null)
290
+ return null;
291
+ return renderPythonReview([...rules, ...build ?? []]);
292
+ }
293
+
294
+ // ../east-plugin/dist/lib/review.js
295
+ var EAST_IMPORT_PATTERN = /@elaraai\/east/;
296
+ var SKIP_PATH = /[/\\](node_modules|dist|build|\.venv|\.git)[/\\]/;
297
+ function reviewable(filePath) {
298
+ if (SKIP_PATH.test(filePath))
299
+ return false;
300
+ return /\.(py|ts|tsx|js)$/.test(filePath);
301
+ }
302
+ async function reviewFile(sessionId, filePath) {
303
+ if (!reviewable(filePath))
304
+ return null;
305
+ const python = filePath.endsWith(".py");
306
+ let content;
307
+ try {
308
+ content = await readFile2(filePath, "utf-8");
309
+ } catch {
310
+ return null;
311
+ }
312
+ if (!(python ? PYTHON_EAST_IMPORT : EAST_IMPORT_PATTERN).test(content))
313
+ return null;
314
+ const projectDir = dirname4(resolve2(filePath));
315
+ if (!python) {
316
+ const { isEast } = await getEastProjectInfo(projectDir);
317
+ if (!isEast)
318
+ return null;
319
+ }
320
+ const key = createHash2("sha1").update(`${sessionId}\0${filePath}\0`).update(content).digest("hex").slice(0, 20);
321
+ const marker = join4(tmpdir3(), `east-diag-seen-${key}`);
322
+ if (existsSync4(marker))
323
+ return null;
324
+ const text = python ? await getPythonDiagnosticsText(filePath) : await getDiagnosticsText(projectDir, filePath);
325
+ if (text === null)
326
+ return null;
327
+ try {
328
+ writeFileSync2(marker, "");
329
+ } catch {
330
+ }
331
+ return text;
332
+ }
333
+
334
+ // ../east-plugin/dist/lib/bash-writes.js
335
+ import { resolve as resolve3 } from "node:path";
336
+ function isRealPath(token) {
337
+ if (token === "" || token.startsWith("&"))
338
+ return false;
339
+ if (/^\d+$/.test(token))
340
+ return false;
341
+ return !token.startsWith("/dev/");
342
+ }
343
+ function unquote(token) {
344
+ const m = /^(['"])(.*)\1$/.exec(token);
345
+ return m?.[2] ?? token;
346
+ }
347
+ function segments(command) {
348
+ return command.split(/\|\||&&|[;|\n]/);
349
+ }
350
+ function lastToken(segment) {
351
+ const tokens = segment.trim().split(/\s+/).map(unquote).filter((t) => t !== "" && !t.startsWith("-"));
352
+ const last = tokens.at(-1);
353
+ return last !== void 0 && isRealPath(last) ? last : void 0;
354
+ }
355
+ function writtenPaths(command, cwd) {
356
+ const found = /* @__PURE__ */ new Set();
357
+ let dir = cwd;
358
+ const add = (path) => {
359
+ if (!isRealPath(path))
360
+ return;
361
+ found.add(dir === void 0 ? path : resolve3(dir, path));
362
+ };
363
+ for (const segment of segments(command)) {
364
+ const trimmed = segment.trim();
365
+ const moved = /^cd\s+(['"]?)([^\s'";|&<>]+)\1\s*$/.exec(trimmed);
366
+ if (moved !== null && dir !== void 0) {
367
+ dir = resolve3(dir, unquote(moved[2] ?? ""));
368
+ continue;
369
+ }
370
+ for (const match of trimmed.matchAll(/>>?\s*(['"]?)([^\s'";|&<>]+)\1/g))
371
+ add(unquote(match[2] ?? ""));
372
+ for (const match of trimmed.matchAll(/\btee\s+(?:-a\s+)?(['"]?)([^\s'";|&<>]+)\1/g))
373
+ add(unquote(match[2] ?? ""));
374
+ if (/^\s*(sed\s+(-[^\s]*\s+)*-i|cp|mv|install)\b/.test(trimmed)) {
375
+ const path = lastToken(trimmed);
376
+ if (path !== void 0)
377
+ add(path);
378
+ }
379
+ }
380
+ return [...found];
381
+ }
382
+
383
+ // ../east-plugin/dist/hooks/diagnose-bash.js
384
+ async function main() {
385
+ const event = await readHookInput();
386
+ const command = event.tool_input?.command;
387
+ if (typeof command !== "string" || command === "")
388
+ process.exit(0);
389
+ const candidates = writtenPaths(command, event.cwd || process.cwd()).filter(reviewable);
390
+ if (candidates.length === 0)
391
+ process.exit(0);
392
+ const reviews = await Promise.all(candidates.slice(0, 10).map(async (path) => ({ path, text: await reviewFile(event.session_id, path) })));
393
+ const blocks = reviews.filter((r) => r.text !== null && r.text !== "").map((r) => `### ${r.path}
394
+ ${r.text}`);
395
+ if (blocks.length === 0)
396
+ process.exit(0);
397
+ writeHookOutput("PostToolUse", blocks.join("\n\n"));
398
+ }
399
+ main().catch(() => process.exit(0));