@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,263 @@
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/east-project.js
28
+ import { readFile } from "node:fs/promises";
29
+ import { join, dirname } from "node:path";
30
+ var PACKAGE_SKILL_MAP = {
31
+ "@elaraai/east": "east",
32
+ "@elaraai/east-node-std": "east-node-std",
33
+ "@elaraai/east-node-io": "east-node-io",
34
+ "@elaraai/east-py-datascience": "east-py-datascience",
35
+ "@elaraai/east-ui": "east-ui",
36
+ "@elaraai/e3": "e3",
37
+ "@elaraai/e3-ui": "e3-ui"
38
+ };
39
+ var PYTHON_SKILL_MAP = [
40
+ [/elaraai-east-py-datascience(?![\w-])/, "east-py-datascience"],
41
+ [/elaraai-east-py-std(?![\w-])/, "east-py-std"],
42
+ [/elaraai-east-py-io(?![\w-])/, "east-py-io"],
43
+ [/elaraai-east-py(?![\w-])/, "east-py"]
44
+ ];
45
+ async function findPackageJson(startDir) {
46
+ let dir = startDir;
47
+ while (true) {
48
+ try {
49
+ const content = await readFile(join(dir, "package.json"), "utf-8");
50
+ return JSON.parse(content);
51
+ } catch {
52
+ const parent = dirname(dir);
53
+ if (parent === dir)
54
+ return null;
55
+ dir = parent;
56
+ }
57
+ }
58
+ }
59
+ async function findPyProject(startDir) {
60
+ let dir = startDir;
61
+ let nearest = null;
62
+ while (true) {
63
+ try {
64
+ const text = await readFile(join(dir, "pyproject.toml"), "utf-8");
65
+ if (PYTHON_SKILL_MAP.some(([pattern]) => pattern.test(text)))
66
+ return text;
67
+ nearest ??= text;
68
+ } catch {
69
+ }
70
+ const parent = dirname(dir);
71
+ if (parent === dir)
72
+ return nearest;
73
+ dir = parent;
74
+ }
75
+ }
76
+ function detectEastSkills(pkg) {
77
+ if (!pkg)
78
+ return [];
79
+ const allDeps = {
80
+ ...pkg.dependencies,
81
+ ...pkg.devDependencies
82
+ };
83
+ const skills = [];
84
+ for (const [packageName, skillName] of Object.entries(PACKAGE_SKILL_MAP)) {
85
+ if (packageName in allDeps) {
86
+ skills.push(skillName);
87
+ }
88
+ }
89
+ return skills;
90
+ }
91
+ function detectPythonSkills(pyproject) {
92
+ if (pyproject === null)
93
+ return [];
94
+ const skills = [];
95
+ for (const [pattern, skill] of PYTHON_SKILL_MAP) {
96
+ if (pattern.test(pyproject))
97
+ skills.push(skill);
98
+ }
99
+ return skills;
100
+ }
101
+ async function getEastProjectInfo(cwd) {
102
+ const pkg = await findPackageJson(cwd);
103
+ const tsSkills = detectEastSkills(pkg);
104
+ const pySkills = detectPythonSkills(await findPyProject(cwd));
105
+ const languages = [];
106
+ if (tsSkills.length > 0)
107
+ languages.push("typescript");
108
+ if (pySkills.length > 0)
109
+ languages.push("python");
110
+ const skills = [...tsSkills, ...pySkills.filter((s) => !tsSkills.includes(s))];
111
+ return { isEast: skills.length > 0, skills, languages, pkg };
112
+ }
113
+
114
+ // ../east-plugin/dist/lib/diagnostics-client.js
115
+ import { createConnection } from "node:net";
116
+ import { spawn } from "node:child_process";
117
+ import { createHash } from "node:crypto";
118
+ import { tmpdir } from "node:os";
119
+ import { existsSync as existsSync2, unlinkSync } from "node:fs";
120
+ import { dirname as dirname2, join as join2, resolve } from "node:path";
121
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
122
+ function daemonSocket() {
123
+ const hash = createHash("sha1").update(daemonEntry()).digest("hex").slice(0, 16);
124
+ return join2(tmpdir(), `east-diag-${hash}.sock`);
125
+ }
126
+ function daemonEntry() {
127
+ return resolve(dirname2(fileURLToPath2(import.meta.url)), "..", "daemon", "server.js");
128
+ }
129
+ function spawnDaemon(socketPath, workspace) {
130
+ const entry = daemonEntry();
131
+ if (!existsSync2(entry))
132
+ return;
133
+ try {
134
+ spawn(process.execPath, [entry], {
135
+ detached: true,
136
+ stdio: "ignore",
137
+ env: { ...process.env, EAST_DIAG_SOCKET: socketPath, EAST_DIAG_CWD: workspace }
138
+ }).unref();
139
+ } catch {
140
+ }
141
+ }
142
+ function warmDaemon(workspace) {
143
+ const socketPath = daemonSocket();
144
+ const conn = createConnection(socketPath);
145
+ conn.on("connect", () => conn.destroy());
146
+ conn.on("error", (err) => {
147
+ conn.destroy();
148
+ if (err.code === "ECONNREFUSED" || err.code === "ENOENT") {
149
+ if (existsSync2(socketPath)) {
150
+ try {
151
+ unlinkSync(socketPath);
152
+ } catch {
153
+ }
154
+ }
155
+ spawnDaemon(socketPath, workspace);
156
+ }
157
+ });
158
+ }
159
+
160
+ // ../east-plugin/dist/lib/east-rules-context.js
161
+ var EAST_RULES_CONTEXT = [
162
+ "What the East linter checks \u2014 the editor language server, ESLint `east/east-rules`, and the preemptive `<east-code-review>` all run the SAME rule set, so author to these from the start. Inside an `East.function` / `$`-block, the code must be East all the way down:",
163
+ "",
164
+ "Host-vs-East (most common):",
165
+ "- no-host-in-east-block \u2014 avoid host TypeScript inside a block (`a + b`, `cond ? a : b`, `a && b`, `arr[i]`, a JS `for`/`if` that builds IR, a TS helper/closure call, a `${x}` string template); use East instead: `a.add(b)`, `cond.ifElse(() => a, () => b)`, `a.and(() => b)`, `coll.get(i)`, `$.for(...)` / `data.map(($, x) => \u2026)`, `East.str`.",
166
+ "- no-module-scope-east-macro \u2014 avoid a module-scope TS helper that returns East IR or a composite string key like `(o, l) => `${o}|${l}``; make a real `East.function`, or model typed / nested East data.",
167
+ "- no-compile-time-data-injection \u2014 avoid reading data at module load (`node:fs`, `readFileSync`, `JSON.parse`, `process.env`); load at runtime via `e3.input` / datasets / a platform task.",
168
+ "- no-compile-time-seed-data \u2014 avoid computing an `e3.input` seed in host code (a Map filled by loops, `{ a: num(cfg.x) }`); pass a small literal / empty default and parse real data at runtime (`blob.decodeCsv` in a task).",
169
+ "",
170
+ "Bindings & values:",
171
+ "- no-let-const-in-expression \u2014 avoid burying `$.let`/`$.const` mid-expression (a struct-field value, call argument, array element); declare it on its own line and reuse the binding.",
172
+ "- no-redundant-east-cast \u2014 avoid a cast / generic / wrapper the East type already governs: `$.let(x as T, T)`, `$.let(new Map<K, V>(), DictType(...))`, `$.let(East.value(x, T), T)`; drop it.",
173
+ "- prefer-explicit-east-type \u2014 avoid an under-determined `$.let([])` / `$.let({})` / `$.let(new Map())`; give the East type, e.g. `$.let([], ArrayType(IntegerType))`.",
174
+ "- no-untracked-east-data \u2014 avoid a bare JS literal in an East-typed slot inside a block; bind it with `$.const`/`$.let`.",
175
+ "- no-reinlined-east-binding \u2014 avoid reusing an East `Expr` held in a JS `const` across a block (it re-inlines per use); bind it once with `$.let`/`$.const`.",
176
+ "- no-unexecuted-east-expression \u2014 avoid a bare East expression statement; execute it with `$(expr)` or bind it.",
177
+ "",
178
+ "Variants, types, imports, UI:",
179
+ '- prefer-some-none \u2014 avoid `variant("some", x)` / `variant("none", null)`; use `some(x)` / `none`.',
180
+ '- no-handrolled-variant \u2014 avoid a hand-rolled `{ type: "x", value: v }`; use `variant("x", v)`.',
181
+ "- no-east-namespaced-type \u2014 avoid `East.IntegerType`; import `IntegerType` and use it bare.",
182
+ "- prefer-let-const-over-east-value \u2014 avoid `East.value(...)` inside a block; use `$.let`/`$.const`.",
183
+ "- prefer-jsx-over-factory-call \u2014 in a `.tsx` file, avoid `Foo.Root(...)`; author the `<Foo>` tag.",
184
+ "- no-relative-src-import \u2014 avoid importing another package via `../src` or `@elaraai/x/src`; use its published package name."
185
+ ].join("\n");
186
+ var EAST_RULES_CONTEXT_PY = [
187
+ "What the East python linter checks \u2014 `east-py lint`, the flake8 `EAS` codes and the language server all run the SAME rules, so author to these from the start. Inside an `East.function` body the code must be East all the way down, and most of these are BUILD-TIME REFUSALS said early, not style notes:",
188
+ "",
189
+ "Body shape (the strict surface):",
190
+ "- body-takes-block-first \u2014 every body takes the block first: `lambda b, x: \u2026` / `def f(b, x)`, never `lambda x: \u2026`; the block is for statements, so `b.price` is not a field read.",
191
+ "- no-statement-on-outer-block \u2014 inside a nested body use THAT body's block: `lambda b: b.assign(...)`, not `lambda _b: b.assign(...)` reaching outward.",
192
+ "- no-discarded-expression \u2014 a bare expression statement is built and thrown away; append it with `b.do(...)` or return it.",
193
+ "",
194
+ "Python that cannot be traced (the build refuses these):",
195
+ "- no-python-boolean \u2014 avoid `and` / `or` / `not` / `if` / `in` / `len()` / iteration / `int()` / `float()` over an expression; use `&`, `|`, `~`, `b.if_(...)` / `East.if_else(...)`, and the expression's own methods.",
196
+ "- no-python-formatting \u2014 avoid f-strings / `str()` / `format()` / `%` over an expression; build strings with `+`, or `East.String.print(T, value)`.",
197
+ "- no-operator-fork \u2014 avoid `//`, `%`, `**` and `a[-1]` on an expression; call `East.Integer.divide` / `remainder` / `pow`, and spell the element you mean.",
198
+ "- no-python-round \u2014 avoid `round(x)` (ties-to-even); call `East.Float.round_half` / `round_floor` / `round_ceil` / `round_trunc`.",
199
+ "- no-python-work \u2014 avoid an eager callback reaching for a module, an installed package, or a python `def` doing work; express it in East.",
200
+ "- no-deprecated-alias \u2014 use the canonical spelling (e.g. `.reduce()`, not `.fold()`).",
201
+ "",
202
+ "Bindings & values:",
203
+ "- no-let-const-in-expression \u2014 give `b.let` / `b.const` its own statement; don't bury a declaration inside an expression.",
204
+ "- prefer-explicit-east-type \u2014 a bare python list / set / tuple in `b.let(...)` / `b.const(...)` cannot be lifted (the build refuses it, empty or not); pass the East type, e.g. `b.let([], ArrayType(IntegerType))`, or build it with `East.new_array`.",
205
+ "- no-untracked-east-data \u2014 avoid a plain python literal local reaching an expression's method; bind it with `b.const(rows, Type)`.",
206
+ "- no-redundant-east-cast \u2014 avoid `b.let(East.value(x, T), T)`; pass the value and type to `b.let` directly.",
207
+ "- prefer-let-const-over-east-value \u2014 inside a body declare with `b.const(value, Type)` / `b.let`, not `East.value(...)`.",
208
+ "",
209
+ "Variants & comparison:",
210
+ '- prefer-some-none \u2014 avoid `variant("some", x)` / `variant("none", None)`; use `some(x)` / `none`.',
211
+ '- no-handrolled-variant \u2014 avoid a `{"type": \u2026, "value": \u2026}` dict reaching East (a body, `East.value`, `coerce_to`, `array`); use `variant("Tag", value, Type)` \u2014 the encoder needs what it constructs.',
212
+ "- no-host-comparison-on-east-values \u2014 outside a body, never `<` / `>` a decoded variant or option: it raises TypeError; use `compare_for(T)` / `less_for(T)` (and `make_east_key(T)` for `sorted`). `==` is structural and fine.",
213
+ "",
214
+ "Build time vs runtime (python computing what East should declare):",
215
+ "- no-build-time-clock \u2014 avoid `datetime.now()` / `time.time()` at module scope; author the constant, or read the clock at runtime (a platform function, or `east_py_std`'s `time_now()` in a body).",
216
+ "- no-compile-time-data-injection \u2014 avoid `open()` / `json.load` / `os.environ` at module import when the result reaches East; load at runtime (an e3 input, a dataset, a platform function, `east_py_std`'s `env_get`).",
217
+ '- no-inline-credentials \u2014 avoid a literal password / token; read it at runtime \u2014 `east_py_std`\'s `env_get("YOUR_VAR")` in a body, `os.environ` in a platform function \u2014 since IR is content-addressed and replicated.',
218
+ '- no-module-scope-east-macro \u2014 avoid a module-scope helper a body calls to build IR, or to assemble a composite `f"{a}|{b}"` key; make it an `East.function`, or model typed / nested East data.',
219
+ "- no-python-east-data \u2014 avoid assembling East rows with a module-scope comprehension or loop; write them out, or produce them at runtime.",
220
+ "- no-python-string-building \u2014 avoid an f-string assembling an East string constant (a regex, a template, a key); spell the constant out.",
221
+ "- no-derived-struct-fields \u2014 avoid declaring a type from another type's fields; a declaration is a wire format, so spell the fields.",
222
+ "- no-python-data-work \u2014 avoid a python helper doing the parse / strip / null-check / coerce work on an expression a body hands it; express it in East."
223
+ ].join("\n");
224
+ function eastRulesContextFor(languages) {
225
+ const python = languages.includes("python");
226
+ const typescript = languages.includes("typescript") || !python;
227
+ const parts = [];
228
+ if (typescript)
229
+ parts.push(EAST_RULES_CONTEXT);
230
+ if (python)
231
+ parts.push(EAST_RULES_CONTEXT_PY);
232
+ return parts.join("\n\n");
233
+ }
234
+
235
+ // ../east-plugin/dist/hooks/session-start.js
236
+ async function main() {
237
+ const event = await readHookInput();
238
+ const cwd = event.cwd || process.cwd();
239
+ const { isEast, skills, languages } = await getEastProjectInfo(cwd);
240
+ if (!isEast)
241
+ process.exit(0);
242
+ warmDaemon(cwd);
243
+ const skillList = skills.map((s) => `/east:${s}`).join(", ");
244
+ const context = [
245
+ "This is an East project. East is a statically typed, expression-based language embedded in TypeScript \u2014 its patterns differ from regular TypeScript, so don't assume TS idioms carry over.",
246
+ "",
247
+ 'East + e3 solutions are decision-oriented: they exist to improve a business decision and show the evidence behind it ("decisions, not dashboards"). The platform is a stack \u2014 an economic ontology (the typed model of the business) at the hub, an Integrate / Reason / Compute engine beneath it, and UI / agent / API surfaces above. Design top-down from the decision.',
248
+ "",
249
+ `Available East skills: ${skillList}. Invoke the relevant skill when writing East programs \u2014 they provide type-safe API patterns and examples. Each skill ends with a "Related skills" list; load those too when a task spans layers.`,
250
+ "Always available regardless of dependencies: /east:east-design (architect a solution before coding), /east:east-ontology (model the business as an economic ontology), /east:east-project (scaffold + run the build/deploy lifecycle).",
251
+ "",
252
+ "Finding East API usage (required):",
253
+ '- Before writing or changing East code, search the tested example index: call `mcp__plugin_east_east__search_east_examples` for each capability you are about to use (language: "python" for east-py, "typescript" otherwise) \u2014 summaries come back first \u2014 then `mcp__plugin_east_east__get_east_example` for the one that matches, and pattern your code on it. Nothing is injected for you; the search is the step, and every East skill requires it.',
254
+ "- Do NOT read `node_modules/@elaraai/**` or `*.examples.ts` files wholesale, and do not reason from `.d.ts` signatures: the index holds the same programs, exact and far cheaper, printed in either language from their IR. The signatures omit the runtime rules that make East code correct.",
255
+ "",
256
+ "Preemptive diagnostics:",
257
+ "- After you read or edit an East file, the plugin injects an `<east-code-review>` block listing TypeScript errors and East-specific idiom issues. Treat it as authoritative and fix what it flags \u2014 it's preemptive, so resolving it now avoids build-and-retry loops later. The rules it enforces are summarised below; write to them up front.",
258
+ "",
259
+ eastRulesContextFor(languages)
260
+ ].join("\n");
261
+ writeHookOutput("SessionStart", context);
262
+ }
263
+ main().catch(() => process.exit(0));
@@ -0,0 +1,212 @@
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/east-project.js
28
+ import { readFile } from "node:fs/promises";
29
+ import { join, dirname } from "node:path";
30
+ var PACKAGE_SKILL_MAP = {
31
+ "@elaraai/east": "east",
32
+ "@elaraai/east-node-std": "east-node-std",
33
+ "@elaraai/east-node-io": "east-node-io",
34
+ "@elaraai/east-py-datascience": "east-py-datascience",
35
+ "@elaraai/east-ui": "east-ui",
36
+ "@elaraai/e3": "e3",
37
+ "@elaraai/e3-ui": "e3-ui"
38
+ };
39
+ var PYTHON_SKILL_MAP = [
40
+ [/elaraai-east-py-datascience(?![\w-])/, "east-py-datascience"],
41
+ [/elaraai-east-py-std(?![\w-])/, "east-py-std"],
42
+ [/elaraai-east-py-io(?![\w-])/, "east-py-io"],
43
+ [/elaraai-east-py(?![\w-])/, "east-py"]
44
+ ];
45
+ async function findPackageJson(startDir) {
46
+ let dir = startDir;
47
+ while (true) {
48
+ try {
49
+ const content = await readFile(join(dir, "package.json"), "utf-8");
50
+ return JSON.parse(content);
51
+ } catch {
52
+ const parent = dirname(dir);
53
+ if (parent === dir)
54
+ return null;
55
+ dir = parent;
56
+ }
57
+ }
58
+ }
59
+ async function findPyProject(startDir) {
60
+ let dir = startDir;
61
+ let nearest = null;
62
+ while (true) {
63
+ try {
64
+ const text = await readFile(join(dir, "pyproject.toml"), "utf-8");
65
+ if (PYTHON_SKILL_MAP.some(([pattern]) => pattern.test(text)))
66
+ return text;
67
+ nearest ??= text;
68
+ } catch {
69
+ }
70
+ const parent = dirname(dir);
71
+ if (parent === dir)
72
+ return nearest;
73
+ dir = parent;
74
+ }
75
+ }
76
+ function detectEastSkills(pkg) {
77
+ if (!pkg)
78
+ return [];
79
+ const allDeps = {
80
+ ...pkg.dependencies,
81
+ ...pkg.devDependencies
82
+ };
83
+ const skills = [];
84
+ for (const [packageName, skillName] of Object.entries(PACKAGE_SKILL_MAP)) {
85
+ if (packageName in allDeps) {
86
+ skills.push(skillName);
87
+ }
88
+ }
89
+ return skills;
90
+ }
91
+ function detectPythonSkills(pyproject) {
92
+ if (pyproject === null)
93
+ return [];
94
+ const skills = [];
95
+ for (const [pattern, skill] of PYTHON_SKILL_MAP) {
96
+ if (pattern.test(pyproject))
97
+ skills.push(skill);
98
+ }
99
+ return skills;
100
+ }
101
+ async function getEastProjectInfo(cwd) {
102
+ const pkg = await findPackageJson(cwd);
103
+ const tsSkills = detectEastSkills(pkg);
104
+ const pySkills = detectPythonSkills(await findPyProject(cwd));
105
+ const languages = [];
106
+ if (tsSkills.length > 0)
107
+ languages.push("typescript");
108
+ if (pySkills.length > 0)
109
+ languages.push("python");
110
+ const skills = [...tsSkills, ...pySkills.filter((s) => !tsSkills.includes(s))];
111
+ return { isEast: skills.length > 0, skills, languages, pkg };
112
+ }
113
+
114
+ // ../east-plugin/dist/lib/east-rules-context.js
115
+ var EAST_RULES_CONTEXT = [
116
+ "What the East linter checks \u2014 the editor language server, ESLint `east/east-rules`, and the preemptive `<east-code-review>` all run the SAME rule set, so author to these from the start. Inside an `East.function` / `$`-block, the code must be East all the way down:",
117
+ "",
118
+ "Host-vs-East (most common):",
119
+ "- no-host-in-east-block \u2014 avoid host TypeScript inside a block (`a + b`, `cond ? a : b`, `a && b`, `arr[i]`, a JS `for`/`if` that builds IR, a TS helper/closure call, a `${x}` string template); use East instead: `a.add(b)`, `cond.ifElse(() => a, () => b)`, `a.and(() => b)`, `coll.get(i)`, `$.for(...)` / `data.map(($, x) => \u2026)`, `East.str`.",
120
+ "- no-module-scope-east-macro \u2014 avoid a module-scope TS helper that returns East IR or a composite string key like `(o, l) => `${o}|${l}``; make a real `East.function`, or model typed / nested East data.",
121
+ "- no-compile-time-data-injection \u2014 avoid reading data at module load (`node:fs`, `readFileSync`, `JSON.parse`, `process.env`); load at runtime via `e3.input` / datasets / a platform task.",
122
+ "- no-compile-time-seed-data \u2014 avoid computing an `e3.input` seed in host code (a Map filled by loops, `{ a: num(cfg.x) }`); pass a small literal / empty default and parse real data at runtime (`blob.decodeCsv` in a task).",
123
+ "",
124
+ "Bindings & values:",
125
+ "- no-let-const-in-expression \u2014 avoid burying `$.let`/`$.const` mid-expression (a struct-field value, call argument, array element); declare it on its own line and reuse the binding.",
126
+ "- no-redundant-east-cast \u2014 avoid a cast / generic / wrapper the East type already governs: `$.let(x as T, T)`, `$.let(new Map<K, V>(), DictType(...))`, `$.let(East.value(x, T), T)`; drop it.",
127
+ "- prefer-explicit-east-type \u2014 avoid an under-determined `$.let([])` / `$.let({})` / `$.let(new Map())`; give the East type, e.g. `$.let([], ArrayType(IntegerType))`.",
128
+ "- no-untracked-east-data \u2014 avoid a bare JS literal in an East-typed slot inside a block; bind it with `$.const`/`$.let`.",
129
+ "- no-reinlined-east-binding \u2014 avoid reusing an East `Expr` held in a JS `const` across a block (it re-inlines per use); bind it once with `$.let`/`$.const`.",
130
+ "- no-unexecuted-east-expression \u2014 avoid a bare East expression statement; execute it with `$(expr)` or bind it.",
131
+ "",
132
+ "Variants, types, imports, UI:",
133
+ '- prefer-some-none \u2014 avoid `variant("some", x)` / `variant("none", null)`; use `some(x)` / `none`.',
134
+ '- no-handrolled-variant \u2014 avoid a hand-rolled `{ type: "x", value: v }`; use `variant("x", v)`.',
135
+ "- no-east-namespaced-type \u2014 avoid `East.IntegerType`; import `IntegerType` and use it bare.",
136
+ "- prefer-let-const-over-east-value \u2014 avoid `East.value(...)` inside a block; use `$.let`/`$.const`.",
137
+ "- prefer-jsx-over-factory-call \u2014 in a `.tsx` file, avoid `Foo.Root(...)`; author the `<Foo>` tag.",
138
+ "- no-relative-src-import \u2014 avoid importing another package via `../src` or `@elaraai/x/src`; use its published package name."
139
+ ].join("\n");
140
+ var EAST_RULES_CONTEXT_PY = [
141
+ "What the East python linter checks \u2014 `east-py lint`, the flake8 `EAS` codes and the language server all run the SAME rules, so author to these from the start. Inside an `East.function` body the code must be East all the way down, and most of these are BUILD-TIME REFUSALS said early, not style notes:",
142
+ "",
143
+ "Body shape (the strict surface):",
144
+ "- body-takes-block-first \u2014 every body takes the block first: `lambda b, x: \u2026` / `def f(b, x)`, never `lambda x: \u2026`; the block is for statements, so `b.price` is not a field read.",
145
+ "- no-statement-on-outer-block \u2014 inside a nested body use THAT body's block: `lambda b: b.assign(...)`, not `lambda _b: b.assign(...)` reaching outward.",
146
+ "- no-discarded-expression \u2014 a bare expression statement is built and thrown away; append it with `b.do(...)` or return it.",
147
+ "",
148
+ "Python that cannot be traced (the build refuses these):",
149
+ "- no-python-boolean \u2014 avoid `and` / `or` / `not` / `if` / `in` / `len()` / iteration / `int()` / `float()` over an expression; use `&`, `|`, `~`, `b.if_(...)` / `East.if_else(...)`, and the expression's own methods.",
150
+ "- no-python-formatting \u2014 avoid f-strings / `str()` / `format()` / `%` over an expression; build strings with `+`, or `East.String.print(T, value)`.",
151
+ "- no-operator-fork \u2014 avoid `//`, `%`, `**` and `a[-1]` on an expression; call `East.Integer.divide` / `remainder` / `pow`, and spell the element you mean.",
152
+ "- no-python-round \u2014 avoid `round(x)` (ties-to-even); call `East.Float.round_half` / `round_floor` / `round_ceil` / `round_trunc`.",
153
+ "- no-python-work \u2014 avoid an eager callback reaching for a module, an installed package, or a python `def` doing work; express it in East.",
154
+ "- no-deprecated-alias \u2014 use the canonical spelling (e.g. `.reduce()`, not `.fold()`).",
155
+ "",
156
+ "Bindings & values:",
157
+ "- no-let-const-in-expression \u2014 give `b.let` / `b.const` its own statement; don't bury a declaration inside an expression.",
158
+ "- prefer-explicit-east-type \u2014 a bare python list / set / tuple in `b.let(...)` / `b.const(...)` cannot be lifted (the build refuses it, empty or not); pass the East type, e.g. `b.let([], ArrayType(IntegerType))`, or build it with `East.new_array`.",
159
+ "- no-untracked-east-data \u2014 avoid a plain python literal local reaching an expression's method; bind it with `b.const(rows, Type)`.",
160
+ "- no-redundant-east-cast \u2014 avoid `b.let(East.value(x, T), T)`; pass the value and type to `b.let` directly.",
161
+ "- prefer-let-const-over-east-value \u2014 inside a body declare with `b.const(value, Type)` / `b.let`, not `East.value(...)`.",
162
+ "",
163
+ "Variants & comparison:",
164
+ '- prefer-some-none \u2014 avoid `variant("some", x)` / `variant("none", None)`; use `some(x)` / `none`.',
165
+ '- no-handrolled-variant \u2014 avoid a `{"type": \u2026, "value": \u2026}` dict reaching East (a body, `East.value`, `coerce_to`, `array`); use `variant("Tag", value, Type)` \u2014 the encoder needs what it constructs.',
166
+ "- no-host-comparison-on-east-values \u2014 outside a body, never `<` / `>` a decoded variant or option: it raises TypeError; use `compare_for(T)` / `less_for(T)` (and `make_east_key(T)` for `sorted`). `==` is structural and fine.",
167
+ "",
168
+ "Build time vs runtime (python computing what East should declare):",
169
+ "- no-build-time-clock \u2014 avoid `datetime.now()` / `time.time()` at module scope; author the constant, or read the clock at runtime (a platform function, or `east_py_std`'s `time_now()` in a body).",
170
+ "- no-compile-time-data-injection \u2014 avoid `open()` / `json.load` / `os.environ` at module import when the result reaches East; load at runtime (an e3 input, a dataset, a platform function, `east_py_std`'s `env_get`).",
171
+ '- no-inline-credentials \u2014 avoid a literal password / token; read it at runtime \u2014 `east_py_std`\'s `env_get("YOUR_VAR")` in a body, `os.environ` in a platform function \u2014 since IR is content-addressed and replicated.',
172
+ '- no-module-scope-east-macro \u2014 avoid a module-scope helper a body calls to build IR, or to assemble a composite `f"{a}|{b}"` key; make it an `East.function`, or model typed / nested East data.',
173
+ "- no-python-east-data \u2014 avoid assembling East rows with a module-scope comprehension or loop; write them out, or produce them at runtime.",
174
+ "- no-python-string-building \u2014 avoid an f-string assembling an East string constant (a regex, a template, a key); spell the constant out.",
175
+ "- no-derived-struct-fields \u2014 avoid declaring a type from another type's fields; a declaration is a wire format, so spell the fields.",
176
+ "- no-python-data-work \u2014 avoid a python helper doing the parse / strip / null-check / coerce work on an expression a body hands it; express it in East."
177
+ ].join("\n");
178
+ function eastRulesContextFor(languages) {
179
+ const python = languages.includes("python");
180
+ const typescript = languages.includes("typescript") || !python;
181
+ const parts = [];
182
+ if (typescript)
183
+ parts.push(EAST_RULES_CONTEXT);
184
+ if (python)
185
+ parts.push(EAST_RULES_CONTEXT_PY);
186
+ return parts.join("\n\n");
187
+ }
188
+
189
+ // ../east-plugin/dist/hooks/subagent-start.js
190
+ async function main() {
191
+ const event = await readHookInput();
192
+ const cwd = event.cwd || process.cwd();
193
+ const { isEast, skills, languages } = await getEastProjectInfo(cwd);
194
+ if (!isEast)
195
+ process.exit(0);
196
+ const skillList = skills.map((s) => `/east:${s}`).join(", ");
197
+ const packageList = skills.map((s) => s.startsWith("east-py") ? `elaraai-${s}` : `@elaraai/${s}`).join(", ");
198
+ const context = [
199
+ `This is an East project using ${packageList}.`,
200
+ "",
201
+ "When working with East code:",
202
+ '- REQUIRED before writing or modifying East code: call `mcp__plugin_east_east__search_east_examples` for each capability you are about to use (language: "python" for east-py, "typescript" otherwise), then `mcp__plugin_east_east__get_east_example` for the one that matches. Nothing is injected for you; the search is the step.',
203
+ "- Do NOT read `node_modules/@elaraai/**` or `*.examples.ts` files wholesale, and do not reason from `.d.ts` signatures \u2014 the index holds the same programs, exact and cheaper, printed in either language from their IR.",
204
+ "- After you read or edit an East file, the plugin injects an `<east-code-review>` block (TypeScript errors + East idiom issues). Treat it as authoritative and fix what it flags; the rules are summarised below so you can write to them up front.",
205
+ "- East is a statically typed, expression-based language embedded in TypeScript \u2014 it has unique patterns that differ from regular TypeScript.",
206
+ `- Available skills: ${skillList}`,
207
+ "",
208
+ eastRulesContextFor(languages)
209
+ ].join("\n");
210
+ writeHookOutput("SubagentStart", context);
211
+ }
212
+ main().catch(() => process.exit(0));