@elaraai/east-plugin 1.0.98 → 1.0.100
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/dist/lib/search.d.ts +6 -0
- package/dist/lib/search.d.ts.map +1 -1
- package/dist/lib/search.js +9 -1
- package/dist/lib/search.js.map +1 -1
- package/dist/mcp/example-tools.js +1 -1
- package/dist/mcp/example-tools.js.map +1 -1
- package/index.json +13340 -482
- package/package.json +3 -3
- package/scripts/render-python.py +111 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elaraai/east-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.100",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "East's agent plugin runtime — the example index generator, the example search and its MCP tools, the search-first hooks and the Codex skill adapter — for a Claude Code or Codex plugin that builds on East's.",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
44
44
|
"minisearch": "^7.1.2",
|
|
45
45
|
"zod": "^3.0.0",
|
|
46
|
-
"@elaraai/east": "1.0.
|
|
47
|
-
"@elaraai/east-diagnostics": "1.0.
|
|
46
|
+
"@elaraai/east": "1.0.100",
|
|
47
|
+
"@elaraai/east-diagnostics": "1.0.100"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^22.18.1",
|
package/scripts/render-python.py
CHANGED
|
@@ -14,6 +14,19 @@ the generator, from an environment where ``east`` imports::
|
|
|
14
14
|
Every entry with an ``ir`` gets its ``python``; entries without one (UI,
|
|
15
15
|
hand-written stubs) are left alone. The file is rewritten in place.
|
|
16
16
|
|
|
17
|
+
Each program example is also printed as **eager** python where it can be: the
|
|
18
|
+
same code over East values rather than inside an ``East.function``, since an
|
|
19
|
+
eager method and its expression twin are one builtin under one name. A body of
|
|
20
|
+
bindings and a ``return`` — ``x = b.let(literal, T)`` becoming
|
|
21
|
+
``x = coerce_to(literal, T)``, ``x = b.let(expr)`` becoming ``x = expr``,
|
|
22
|
+
callbacks left as the bodies they are — is rewritten so, then RUN, and kept as
|
|
23
|
+
an entry of its own (``<id>:eager``, package ``east-values``, searched only when
|
|
24
|
+
named: another job than writing an East function) only when it returns
|
|
25
|
+
the example's result: an eager rendering is tested as it is made. Core East's
|
|
26
|
+
examples alone (a platform package's would run its effects, a file written or a
|
|
27
|
+
request sent, as it is checked), and no async one; a body that needs the block
|
|
28
|
+
anywhere else (``b.if_``, a loop, a ``b.match_``) has none.
|
|
29
|
+
|
|
17
30
|
A platform call prints as the implementing package's own function and a
|
|
18
31
|
struct or variant type the package names prints by that name (#667) — the
|
|
19
32
|
python reading of what the TypeScript rendering spells through the
|
|
@@ -24,9 +37,11 @@ skipped with a warning and its calls print as declarations.
|
|
|
24
37
|
|
|
25
38
|
from __future__ import annotations
|
|
26
39
|
|
|
40
|
+
import ast
|
|
27
41
|
import json
|
|
28
42
|
import sys
|
|
29
43
|
from pathlib import Path
|
|
44
|
+
from typing import Any
|
|
30
45
|
|
|
31
46
|
from east.codegen import Providers, to_python_source
|
|
32
47
|
from east.serialization.json import decode_json_for
|
|
@@ -51,6 +66,7 @@ def main(argv: list[str]) -> int:
|
|
|
51
66
|
print(f"[!] {package} does not import here ({e}); its calls print as declarations",
|
|
52
67
|
file=sys.stderr)
|
|
53
68
|
rendered = 0
|
|
69
|
+
eager: list[dict[str, Any]] = []
|
|
54
70
|
for entry in data["entries"]:
|
|
55
71
|
ir = entry.get("ir")
|
|
56
72
|
if ir is None:
|
|
@@ -58,10 +74,104 @@ def main(argv: list[str]) -> int:
|
|
|
58
74
|
name = entry["id"].rsplit(":", 1)[1]
|
|
59
75
|
entry["python"] = to_python_source(decode(ir.encode("utf-8")), name=name, providers=providers)
|
|
60
76
|
rendered += 1
|
|
77
|
+
made = eager_entry(entry)
|
|
78
|
+
if made is not None:
|
|
79
|
+
eager.append(made)
|
|
80
|
+
data["entries"] = [e for e in data["entries"] if not e["id"].endswith(":eager")] + eager
|
|
61
81
|
path.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
62
|
-
print(f"[+] Rendered {rendered} example(s) as python in {path}", file=sys.stderr)
|
|
82
|
+
print(f"[+] Rendered {rendered} example(s) as python in {path}, {len(eager)} of them eagerly", file=sys.stderr)
|
|
63
83
|
return 0
|
|
64
84
|
|
|
65
85
|
|
|
86
|
+
def _binding(stmt: ast.stmt) -> tuple[str, ast.Call] | None:
|
|
87
|
+
"""``x = b.let(…)`` / ``x = b.const(…)``: the name and the call, else None."""
|
|
88
|
+
if not (isinstance(stmt, ast.Assign) and len(stmt.targets) == 1 and isinstance(stmt.targets[0], ast.Name)):
|
|
89
|
+
return None
|
|
90
|
+
call = stmt.value
|
|
91
|
+
if (isinstance(call, ast.Call) and isinstance(call.func, ast.Attribute) and isinstance(call.func.value, ast.Name)
|
|
92
|
+
and call.func.value.id == "b" and call.func.attr in ("let", "const") and not call.keywords and 1 <= len(call.args) <= 2):
|
|
93
|
+
return stmt.targets[0].id, call
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _uses_block(node: ast.AST) -> bool:
|
|
98
|
+
"""Whether a node reads the block ``b`` outside the callbacks (lambdas) it holds."""
|
|
99
|
+
if isinstance(node, ast.Lambda):
|
|
100
|
+
return False
|
|
101
|
+
if isinstance(node, ast.Name) and node.id == "b":
|
|
102
|
+
return True
|
|
103
|
+
return any(_uses_block(child) for child in ast.iter_child_nodes(node))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def eager_source(python: str) -> str | None:
|
|
107
|
+
"""A program example's python printing rewritten as eager code, or None when its body needs the block.
|
|
108
|
+
|
|
109
|
+
The printed module is the imports and one ``@East.function`` taking only
|
|
110
|
+
the block; its body must be bindings (``b.let`` / ``b.const``) and a final
|
|
111
|
+
``return``. The result is the imports, ``coerce_to`` among them, the
|
|
112
|
+
bindings as plain assignments and ``result = <the returned expression>``.
|
|
113
|
+
"""
|
|
114
|
+
module = ast.parse(python)
|
|
115
|
+
imports = [n for n in module.body if isinstance(n, (ast.Import, ast.ImportFrom))]
|
|
116
|
+
functions = [n for n in module.body if isinstance(n, ast.FunctionDef)]
|
|
117
|
+
if len(functions) != 1 or len(module.body) != len(imports) + 1:
|
|
118
|
+
return None
|
|
119
|
+
fn = functions[0]
|
|
120
|
+
if [a.arg for a in fn.args.args] != ["b"] or not fn.body or not isinstance(fn.body[-1], ast.Return) or fn.body[-1].value is None:
|
|
121
|
+
return None
|
|
122
|
+
lines: list[str] = []
|
|
123
|
+
for stmt in fn.body[:-1]:
|
|
124
|
+
bound = _binding(stmt)
|
|
125
|
+
if bound is None:
|
|
126
|
+
return None
|
|
127
|
+
target, call = bound
|
|
128
|
+
if any(_uses_block(arg) for arg in call.args):
|
|
129
|
+
return None
|
|
130
|
+
value = ast.unparse(call.args[0])
|
|
131
|
+
lines.append(f"{target} = coerce_to({value}, {ast.unparse(call.args[1])})" if len(call.args) == 2 else f"{target} = {value}")
|
|
132
|
+
returned = fn.body[-1].value
|
|
133
|
+
if _uses_block(returned):
|
|
134
|
+
return None
|
|
135
|
+
lines.append(f"result = {ast.unparse(returned)}")
|
|
136
|
+
head = "\n".join(ast.unparse(n) for n in imports)
|
|
137
|
+
return f"{head}\nfrom east import coerce_to\n\n" + "\n".join(lines) + "\n"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def eager_entry(entry: dict[str, Any]) -> dict[str, Any] | None:
|
|
141
|
+
"""The eager entry for a program example, run and checked against its result; None when it has none or it differs."""
|
|
142
|
+
# Core East alone: a platform package's example runs its effects (a file, a fetch) as it is checked.
|
|
143
|
+
signature = entry.get("signature") or {}
|
|
144
|
+
if entry.get("skill") != "east" or signature.get("inputs") or signature.get("async"):
|
|
145
|
+
return None
|
|
146
|
+
source = eager_source(entry["python"])
|
|
147
|
+
if source is None:
|
|
148
|
+
return None
|
|
149
|
+
scope: dict[str, Any] = {}
|
|
150
|
+
try:
|
|
151
|
+
exec(compile(source, entry["id"], "exec"), scope) # noqa: S102 — the index's own examples, printed here
|
|
152
|
+
result = scope["result"]
|
|
153
|
+
out_type = eval(entry["signature"]["output"], scope) # noqa: S307 — a type the printer wrote
|
|
154
|
+
expected = decode_json_for(out_type)(entry["returns"].encode("utf-8"))
|
|
155
|
+
from east import East
|
|
156
|
+
if not East.equal(out_type, result, expected):
|
|
157
|
+
return None
|
|
158
|
+
except Exception: # noqa: BLE001 — an example that does not run eagerly is left out, not failed
|
|
159
|
+
return None
|
|
160
|
+
return {
|
|
161
|
+
**{k: entry[k] for k in ("skill", "suite", "test", "keywords", "returns") if k in entry},
|
|
162
|
+
"id": f"{entry['id']}:eager",
|
|
163
|
+
"skill": "east-py",
|
|
164
|
+
"package": "east-values",
|
|
165
|
+
"file": entry.get("file"),
|
|
166
|
+
"keywords": [*entry.get("keywords", []), "eager", "East values", "value"],
|
|
167
|
+
"imports": [],
|
|
168
|
+
"languages": ["python"],
|
|
169
|
+
"python": "# The same example over East values: each eager method runs in east-c now.\n" + source,
|
|
170
|
+
"signature": entry["signature"],
|
|
171
|
+
"inputs": entry.get("inputs"),
|
|
172
|
+
"builtins": entry.get("builtins"),
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
66
176
|
if __name__ == "__main__":
|
|
67
177
|
sys.exit(main(sys.argv))
|