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

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,347 @@
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/hooks/diagnose.js
335
+ async function main() {
336
+ const event = await readHookInput();
337
+ const filePath = event.tool_input?.file_path;
338
+ if (filePath === void 0)
339
+ process.exit(0);
340
+ if (event.tool_name !== "Read" && !filePath.endsWith(".py"))
341
+ process.exit(0);
342
+ const text = await reviewFile(event.session_id, filePath);
343
+ if (text === null || text === "")
344
+ process.exit(0);
345
+ writeHookOutput("PostToolUse", text);
346
+ }
347
+ main().catch(() => process.exit(0));
@@ -0,0 +1,100 @@
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
+ function writeHookDecision(hookEventName, decision, reason) {
27
+ const output = {
28
+ hookSpecificOutput: {
29
+ hookEventName,
30
+ permissionDecision: decision,
31
+ permissionDecisionReason: hostText(reason)
32
+ }
33
+ };
34
+ process.stdout.write(JSON.stringify(output));
35
+ }
36
+
37
+ // ../east-plugin/dist/lib/search-guidance.js
38
+ var EAST_GUIDANCE = {
39
+ searchTool: "mcp__plugin_east_east__search_east_examples",
40
+ getTool: "mcp__plugin_east_east__get_east_example",
41
+ corpus: "East",
42
+ scope: "@elaraai"
43
+ };
44
+ function bare(tool) {
45
+ const at = tool.lastIndexOf("__");
46
+ return at < 0 ? tool : tool.slice(at + 2);
47
+ }
48
+ function gateText(g) {
49
+ return [
50
+ `STOP: no ${g.corpus} example search on record in this session, and this is ${g.corpus} code.`,
51
+ `Before writing or changing ${g.corpus} code, search the tested example index \u2014 it is the API reference:`,
52
+ `1. \`${g.searchTool}\` with what you are about to do (language: "python" for east-py, "typescript" otherwise); summaries come back \u2014 id, signature, inputs and result.`,
53
+ `2. \`${g.getTool}\` for the one or two that match, and pattern your code on them.`,
54
+ `Do not read node_modules/${g.scope}/** or *.examples.ts files instead: the index is the same corpus, exact and far cheaper. Every ${g.corpus} skill requires this step.`
55
+ ].join("\n");
56
+ }
57
+ function readText(g) {
58
+ return [
59
+ `Note: the ${g.corpus} example index is the API reference \u2014 \`${g.searchTool}\` (then \`${bare(g.getTool)}\`) returns the same tested programs as the ${g.corpus} packages' examples and type declarations, exact, printed in TypeScript or python, at a fraction of the tokens.`,
60
+ `Reading \`.d.ts\` signatures or sweeping \`*.examples.ts\` files reliably produces broken ${g.corpus} code that still type-checks: the signatures omit the runtime rules. Search instead, and read a specific file only when the search pointed you at it.`
61
+ ].join("\n");
62
+ }
63
+ function corpusReadFor(scope) {
64
+ const escaped = scope.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
65
+ const packagePath = new RegExp(`[/\\\\]node_modules[/\\\\]${escaped}[/\\\\]`);
66
+ const packagePattern = new RegExp(`(^|[/\\\\])node_modules[/\\\\]${escaped}([/\\\\]|$)`);
67
+ const examplesFile = /\.examples\.tsx?$/;
68
+ return (tool, input) => {
69
+ const file = typeof input["file_path"] === "string" ? input["file_path"] : "";
70
+ const dir = typeof input["path"] === "string" ? input["path"] : "";
71
+ const pattern = typeof input["pattern"] === "string" ? input["pattern"] : "";
72
+ return tool === "Read" ? packagePath.test(file) || examplesFile.test(file) : packagePath.test(dir) || packagePattern.test(pattern) || /\.examples\.tsx?/.test(pattern);
73
+ };
74
+ }
75
+ var GATE_TEXT = gateText(EAST_GUIDANCE);
76
+ var READ_TEXT = readText(EAST_GUIDANCE);
77
+ var isExampleCorpusRead = corpusReadFor(EAST_GUIDANCE.scope);
78
+
79
+ // ../east-plugin/dist/lib/search-hooks.js
80
+ var EAST_READ_REMINDER = { readText: READ_TEXT, isCorpusRead: isExampleCorpusRead };
81
+ function preReadReminder(event, options) {
82
+ return options.isCorpusRead(event.tool_name ?? "", event.tool_input ?? {}) ? { decision: "context", text: options.readText } : null;
83
+ }
84
+ function writeSearchHookReply(hookEventName, reply) {
85
+ if (reply.decision === "deny")
86
+ writeHookDecision(hookEventName, "deny", reply.text);
87
+ else
88
+ writeHookOutput(hookEventName, reply.text);
89
+ }
90
+ async function runPreReadReminder(options) {
91
+ const reply = preReadReminder(await readHookInput(), options);
92
+ if (reply !== null)
93
+ writeSearchHookReply("PreToolUse", reply);
94
+ }
95
+
96
+ // ../east-plugin/dist/hooks/pre-read.js
97
+ runPreReadReminder(EAST_READ_REMINDER).catch(() => process.exit(0));
98
+ export {
99
+ READ_TEXT
100
+ };
@@ -0,0 +1,247 @@
1
+ // ../east-plugin/dist/lib/search-hooks.js
2
+ import { readFile as readFile3 } from "node:fs/promises";
3
+ import { existsSync as existsSync2, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join as join2 } from "node:path";
6
+
7
+ // ../east-diagnostics/dist/src/python-lint.js
8
+ var PYTHON_EAST_IMPORT = /^\s*(?:from\s+east(?:\.[\w.]+)?\s+import\b|import\s+east\b)/m;
9
+
10
+ // ../east-plugin/dist/lib/host.js
11
+ import { existsSync } from "node:fs";
12
+ import { fileURLToPath } from "node:url";
13
+ var isCodex = existsSync(fileURLToPath(new URL("../../.codex-plugin/plugin.json", import.meta.url)));
14
+ function hostText(text) {
15
+ return isCodex ? text.replaceAll("mcp__plugin_east_east__", "").replaceAll("/east:", "$east-codex-plugin:").replaceAll("Claude Code", "Codex") : text;
16
+ }
17
+
18
+ // ../east-plugin/dist/lib/hook-io.js
19
+ async function readHookInput() {
20
+ let input = "";
21
+ for await (const chunk of process.stdin) {
22
+ input += chunk;
23
+ }
24
+ return JSON.parse(input);
25
+ }
26
+ function writeHookOutput(hookEventName, additionalContext) {
27
+ const output = {
28
+ hookSpecificOutput: {
29
+ hookEventName,
30
+ additionalContext: hostText(additionalContext)
31
+ }
32
+ };
33
+ process.stdout.write(JSON.stringify(output));
34
+ }
35
+ function writeHookDecision(hookEventName, decision, reason) {
36
+ const output = {
37
+ hookSpecificOutput: {
38
+ hookEventName,
39
+ permissionDecision: decision,
40
+ permissionDecisionReason: hostText(reason)
41
+ }
42
+ };
43
+ process.stdout.write(JSON.stringify(output));
44
+ }
45
+
46
+ // ../east-plugin/dist/lib/east-project.js
47
+ import { readFile } from "node:fs/promises";
48
+ import { join, dirname } from "node:path";
49
+ var PACKAGE_SKILL_MAP = {
50
+ "@elaraai/east": "east",
51
+ "@elaraai/east-node-std": "east-node-std",
52
+ "@elaraai/east-node-io": "east-node-io",
53
+ "@elaraai/east-py-datascience": "east-py-datascience",
54
+ "@elaraai/east-ui": "east-ui",
55
+ "@elaraai/e3": "e3",
56
+ "@elaraai/e3-ui": "e3-ui"
57
+ };
58
+ var PYTHON_SKILL_MAP = [
59
+ [/elaraai-east-py-datascience(?![\w-])/, "east-py-datascience"],
60
+ [/elaraai-east-py-std(?![\w-])/, "east-py-std"],
61
+ [/elaraai-east-py-io(?![\w-])/, "east-py-io"],
62
+ [/elaraai-east-py(?![\w-])/, "east-py"]
63
+ ];
64
+ async function findPackageJson(startDir) {
65
+ let dir = startDir;
66
+ while (true) {
67
+ try {
68
+ const content = await readFile(join(dir, "package.json"), "utf-8");
69
+ return JSON.parse(content);
70
+ } catch {
71
+ const parent = dirname(dir);
72
+ if (parent === dir)
73
+ return null;
74
+ dir = parent;
75
+ }
76
+ }
77
+ }
78
+ async function findPyProject(startDir) {
79
+ let dir = startDir;
80
+ let nearest = null;
81
+ while (true) {
82
+ try {
83
+ const text = await readFile(join(dir, "pyproject.toml"), "utf-8");
84
+ if (PYTHON_SKILL_MAP.some(([pattern]) => pattern.test(text)))
85
+ return text;
86
+ nearest ??= text;
87
+ } catch {
88
+ }
89
+ const parent = dirname(dir);
90
+ if (parent === dir)
91
+ return nearest;
92
+ dir = parent;
93
+ }
94
+ }
95
+ function detectEastSkills(pkg) {
96
+ if (!pkg)
97
+ return [];
98
+ const allDeps = {
99
+ ...pkg.dependencies,
100
+ ...pkg.devDependencies
101
+ };
102
+ const skills = [];
103
+ for (const [packageName, skillName] of Object.entries(PACKAGE_SKILL_MAP)) {
104
+ if (packageName in allDeps) {
105
+ skills.push(skillName);
106
+ }
107
+ }
108
+ return skills;
109
+ }
110
+ function detectPythonSkills(pyproject) {
111
+ if (pyproject === null)
112
+ return [];
113
+ const skills = [];
114
+ for (const [pattern, skill] of PYTHON_SKILL_MAP) {
115
+ if (pattern.test(pyproject))
116
+ skills.push(skill);
117
+ }
118
+ return skills;
119
+ }
120
+ async function getEastProjectInfo(cwd) {
121
+ const pkg = await findPackageJson(cwd);
122
+ const tsSkills = detectEastSkills(pkg);
123
+ const pySkills = detectPythonSkills(await findPyProject(cwd));
124
+ const languages = [];
125
+ if (tsSkills.length > 0)
126
+ languages.push("typescript");
127
+ if (pySkills.length > 0)
128
+ languages.push("python");
129
+ const skills = [...tsSkills, ...pySkills.filter((s) => !tsSkills.includes(s))];
130
+ return { isEast: skills.length > 0, skills, languages, pkg };
131
+ }
132
+
133
+ // ../east-plugin/dist/lib/transcript.js
134
+ import { readFile as readFile2 } from "node:fs/promises";
135
+ var SEARCH_TOOLS = ["mcp__plugin_east_east__search_east_examples", "mcp__plugin_east_east__get_east_example", "mcp__east__search_east_examples", "mcp__east__get_east_example"];
136
+ async function searchedInTranscript(transcriptPath, tools = SEARCH_TOOLS) {
137
+ let raw;
138
+ try {
139
+ raw = await readFile2(transcriptPath, "utf-8");
140
+ } catch {
141
+ return false;
142
+ }
143
+ return tools.some((tool) => raw.includes(`"name":"${tool}"`) || raw.includes(`"name": "${tool}"`));
144
+ }
145
+
146
+ // ../east-plugin/dist/lib/search-guidance.js
147
+ var EAST_GUIDANCE = {
148
+ searchTool: "mcp__plugin_east_east__search_east_examples",
149
+ getTool: "mcp__plugin_east_east__get_east_example",
150
+ corpus: "East",
151
+ scope: "@elaraai"
152
+ };
153
+ function bare(tool) {
154
+ const at = tool.lastIndexOf("__");
155
+ return at < 0 ? tool : tool.slice(at + 2);
156
+ }
157
+ function gateText(g) {
158
+ return [
159
+ `STOP: no ${g.corpus} example search on record in this session, and this is ${g.corpus} code.`,
160
+ `Before writing or changing ${g.corpus} code, search the tested example index \u2014 it is the API reference:`,
161
+ `1. \`${g.searchTool}\` with what you are about to do (language: "python" for east-py, "typescript" otherwise); summaries come back \u2014 id, signature, inputs and result.`,
162
+ `2. \`${g.getTool}\` for the one or two that match, and pattern your code on them.`,
163
+ `Do not read node_modules/${g.scope}/** or *.examples.ts files instead: the index is the same corpus, exact and far cheaper. Every ${g.corpus} skill requires this step.`
164
+ ].join("\n");
165
+ }
166
+ function readText(g) {
167
+ return [
168
+ `Note: the ${g.corpus} example index is the API reference \u2014 \`${g.searchTool}\` (then \`${bare(g.getTool)}\`) returns the same tested programs as the ${g.corpus} packages' examples and type declarations, exact, printed in TypeScript or python, at a fraction of the tokens.`,
169
+ `Reading \`.d.ts\` signatures or sweeping \`*.examples.ts\` files reliably produces broken ${g.corpus} code that still type-checks: the signatures omit the runtime rules. Search instead, and read a specific file only when the search pointed you at it.`
170
+ ].join("\n");
171
+ }
172
+ function corpusReadFor(scope) {
173
+ const escaped = scope.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
174
+ const packagePath = new RegExp(`[/\\\\]node_modules[/\\\\]${escaped}[/\\\\]`);
175
+ const packagePattern = new RegExp(`(^|[/\\\\])node_modules[/\\\\]${escaped}([/\\\\]|$)`);
176
+ const examplesFile = /\.examples\.tsx?$/;
177
+ return (tool, input) => {
178
+ const file = typeof input["file_path"] === "string" ? input["file_path"] : "";
179
+ const dir = typeof input["path"] === "string" ? input["path"] : "";
180
+ const pattern = typeof input["pattern"] === "string" ? input["pattern"] : "";
181
+ return tool === "Read" ? packagePath.test(file) || examplesFile.test(file) : packagePath.test(dir) || packagePattern.test(pattern) || /\.examples\.tsx?/.test(pattern);
182
+ };
183
+ }
184
+ var GATE_TEXT = gateText(EAST_GUIDANCE);
185
+ var READ_TEXT = readText(EAST_GUIDANCE);
186
+ var isExampleCorpusRead = corpusReadFor(EAST_GUIDANCE.scope);
187
+
188
+ // ../east-plugin/dist/lib/search-hooks.js
189
+ var EAST_SEARCH_GATE = {
190
+ searchTools: SEARCH_TOOLS,
191
+ gateText: GATE_TEXT,
192
+ isCorpusCode: (code, python) => (python ? PYTHON_EAST_IMPORT : /@elaraai\/east/).test(code),
193
+ isProject: async (cwd, python) => python || (await getEastProjectInfo(cwd)).isEast,
194
+ markerPrefix: "east-search-seen",
195
+ requireSearchEnv: "EAST_REQUIRE_SEARCH"
196
+ };
197
+ async function preWriteGate(event, options) {
198
+ const cwd = event.cwd || process.cwd();
199
+ const filePath = event.tool_input?.file_path;
200
+ if (!filePath)
201
+ return null;
202
+ const python = filePath.endsWith(".py");
203
+ if (!python && !filePath.endsWith(".ts") && !filePath.endsWith(".tsx") && !filePath.endsWith(".js"))
204
+ return null;
205
+ let code = "";
206
+ if (event.tool_name === "Write") {
207
+ code = event.tool_input?.content ?? "";
208
+ } else if (event.tool_name === "Edit") {
209
+ try {
210
+ code = await readFile3(filePath, "utf-8");
211
+ } catch {
212
+ code = event.tool_input?.new_string ?? "";
213
+ }
214
+ }
215
+ if (!options.isCorpusCode(code, python))
216
+ return null;
217
+ if (options.isProject !== void 0 && !await options.isProject(cwd, python))
218
+ return null;
219
+ const marker = join2(tmpdir(), `${options.markerPrefix}-${event.session_id}`);
220
+ if (existsSync2(marker))
221
+ return null;
222
+ if (event.transcript_path && await searchedInTranscript(event.transcript_path, options.searchTools)) {
223
+ try {
224
+ writeFileSync(marker, options.searchTools.join("\n"));
225
+ } catch {
226
+ }
227
+ return null;
228
+ }
229
+ return { decision: process.env[options.requireSearchEnv] === "deny" ? "deny" : "context", text: options.gateText };
230
+ }
231
+ function writeSearchHookReply(hookEventName, reply) {
232
+ if (reply.decision === "deny")
233
+ writeHookDecision(hookEventName, "deny", reply.text);
234
+ else
235
+ writeHookOutput(hookEventName, reply.text);
236
+ }
237
+ async function runPreWriteGate(options) {
238
+ const reply = await preWriteGate(await readHookInput(), options);
239
+ if (reply !== null)
240
+ writeSearchHookReply("PreToolUse", reply);
241
+ }
242
+
243
+ // ../east-plugin/dist/hooks/pre-write.js
244
+ runPreWriteGate(EAST_SEARCH_GATE).catch(() => process.exit(0));
245
+ export {
246
+ GATE_TEXT
247
+ };