clikernel 0.2.22__tar.gz → 0.2.23__tar.gz
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.
- {clikernel-0.2.22 → clikernel-0.2.23}/CHANGELOG.md +8 -0
- {clikernel-0.2.22/clikernel.egg-info → clikernel-0.2.23}/PKG-INFO +6 -5
- {clikernel-0.2.22 → clikernel-0.2.23}/README.md +3 -2
- clikernel-0.2.23/clikernel/__init__.py +1 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel/_modidx.py +2 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel/core.py +28 -20
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel/mcp.py +17 -9
- clikernel-0.2.23/clikernel/skill.py +20 -0
- clikernel-0.2.23/clikernel/startup.py +15 -0
- {clikernel-0.2.22 → clikernel-0.2.23/clikernel.egg-info}/PKG-INFO +6 -5
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel.egg-info/SOURCES.txt +1 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel.egg-info/requires.txt +2 -2
- {clikernel-0.2.22 → clikernel-0.2.23}/pyproject.toml +2 -2
- {clikernel-0.2.22 → clikernel-0.2.23}/tests/test_clikernel.py +26 -9
- clikernel-0.2.22/clikernel/__init__.py +0 -1
- clikernel-0.2.22/clikernel/skill.py +0 -19
- {clikernel-0.2.22 → clikernel-0.2.23}/LICENSE +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/MANIFEST.in +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel/cli.py +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel/login.py +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel/rules.py +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel.egg-info/dependency_links.txt +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel.egg-info/entry_points.txt +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/clikernel.egg-info/top_level.txt +0 -0
- {clikernel-0.2.22 → clikernel-0.2.23}/setup.cfg +0 -0
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- do not remove -->
|
|
4
4
|
|
|
5
|
+
## 0.2.23
|
|
6
|
+
|
|
7
|
+
### New Features
|
|
8
|
+
|
|
9
|
+
- Move standard kernel startup into clikernel and add local docs() MCP tool ([#72](https://github.com/AnswerDotAI/clikernel/pull/72)), thanks to [@jph00](https://github.com/jph00)
|
|
10
|
+
- Default omitted host to local gateway for HOSTED tools and update current gateway on create/use_kernel ([#71](https://github.com/AnswerDotAI/clikernel/issues/71))
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## 0.2.22
|
|
6
14
|
|
|
7
15
|
### New Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clikernel
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.23
|
|
4
4
|
Summary: Serve persistent Jupyter kernels to LLMs as concise text, over MCP or a plain stream protocol
|
|
5
5
|
Author: clikernel contributors
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -11,11 +11,11 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
11
11
|
Requires-Python: >=3.11
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: fastcore>=2.3.
|
|
14
|
+
Requires-Dist: fastcore>=2.3.15
|
|
15
15
|
Requires-Dist: jupyasyncclient>=0.2.32
|
|
16
16
|
Requires-Dist: mcpmini>=0.0.5
|
|
17
17
|
Requires-Dist: jupygate>=0.1.0
|
|
18
|
-
Requires-Dist: ipymini>=0.1.
|
|
18
|
+
Requires-Dist: ipymini>=0.1.31
|
|
19
19
|
Requires-Dist: httpx
|
|
20
20
|
Requires-Dist: execnb>=0.3.5
|
|
21
21
|
Provides-Extra: dev
|
|
@@ -68,9 +68,10 @@ The router caps text replies to `--maxout` UTF-8 bytes (default 40,000; pass `0`
|
|
|
68
68
|
|
|
69
69
|
## Configuration
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Optional files under `$XDG_CONFIG_HOME/clikernel/` configure the router, usually under `~/.config/clikernel/`, or under the directory `clikernel-mcp --cfgdir` names:
|
|
72
72
|
|
|
73
|
-
- `
|
|
73
|
+
- `extra-docs/` holds `.md`, `.txt`, or `.py` (module docstring) files returned alongside the built-in `clikernel` guide by the local `docs()` MCP tool, wrapped in `𝍁...𝍁`.
|
|
74
|
+
- `startup.py` runs in each Python kernel clikernel creates after the built-in standard toolkit startup, with `__file__` set to its path. Output appears in the reply announcing the kernel unless `--quiet` is set.
|
|
74
75
|
- `gateways.toml` names remote gateways and configures authentication without putting tokens in tool arguments:
|
|
75
76
|
|
|
76
77
|
``` toml
|
|
@@ -43,9 +43,10 @@ The router caps text replies to `--maxout` UTF-8 bytes (default 40,000; pass `0`
|
|
|
43
43
|
|
|
44
44
|
## Configuration
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Optional files under `$XDG_CONFIG_HOME/clikernel/` configure the router, usually under `~/.config/clikernel/`, or under the directory `clikernel-mcp --cfgdir` names:
|
|
47
47
|
|
|
48
|
-
- `
|
|
48
|
+
- `extra-docs/` holds `.md`, `.txt`, or `.py` (module docstring) files returned alongside the built-in `clikernel` guide by the local `docs()` MCP tool, wrapped in `𝍁...𝍁`.
|
|
49
|
+
- `startup.py` runs in each Python kernel clikernel creates after the built-in standard toolkit startup, with `__file__` set to its path. Output appears in the reply announcing the kernel unless `--quiet` is set.
|
|
49
50
|
- `gateways.toml` names remote gateways and configures authentication without putting tokens in tool arguments:
|
|
50
51
|
|
|
51
52
|
``` toml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.23"
|
|
@@ -17,6 +17,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
17
17
|
'clikernel.core.cfg_dir': ('api/core.html#cfg_dir', 'clikernel/core.py'),
|
|
18
18
|
'clikernel.core.gateways': ('api/core.html#gateways', 'clikernel/core.py'),
|
|
19
19
|
'clikernel.core.resolve': ('api/core.html#resolve', 'clikernel/core.py'),
|
|
20
|
+
'clikernel.core.read_docs': ('api/core.html#read_docs', 'clikernel/core.py'),
|
|
21
|
+
'clikernel.core.boot_calls': ('api/core.html#boot_calls', 'clikernel/core.py'),
|
|
20
22
|
'clikernel.core.startup_src': ('api/core.html#startup_src', 'clikernel/core.py'),
|
|
21
23
|
'clikernel.core.session_defaults': ('api/core.html#session_defaults', 'clikernel/core.py')},
|
|
22
24
|
'clikernel.mcp': { 'clikernel.mcp': ('api/mcp.html', 'clikernel/mcp.py'),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[Jupygate](https://github.com/AnswerDotAI/jupygate) hosts kernels and serves MCP requests at `POST /mcp`. `clikernel` runs alongside it for the duration of a conversation, routing stdio MCP or stream-protocol requests to local or named remote gateways.
|
|
4
4
|
|
|
5
|
-
`gateways.toml` under `$XDG_CONFIG_HOME/clikernel/` (`~/.config/clikernel/`)
|
|
5
|
+
`gateways.toml`, `extra-docs/`, and optional `startup.py` under `$XDG_CONFIG_HOME/clikernel/` (`~/.config/clikernel/`) configure remote gateways, extra router-served docs, and additional kernel startup. `session_defaults` packages built-in Python startup defaults plus optional `startup.py` as source so startup runs remotely without sharing files; local sessions also forward `cwd` and `os.environ`.
|
|
6
6
|
|
|
7
7
|
`Gateway` owns one MCP session on one gateway. `default_gateway` connects to `CLIKERNEL_HOST` (remote-safe defaults), else tries the local `DEFAULT_URL`, else spawns a disposable child gateway (which the caller must stop). Ending a session stops its `autoclose` kernels while leaving attached or `autoclose=False` kernels running.
|
|
8
8
|
|
|
@@ -12,15 +12,16 @@
|
|
|
12
12
|
# - title: Gateway sessions and configuration
|
|
13
13
|
|
|
14
14
|
from contextlib import suppress
|
|
15
|
+
from importlib.resources import files
|
|
15
16
|
from pathlib import Path
|
|
16
|
-
import
|
|
17
|
+
import ast, httpx, os
|
|
17
18
|
|
|
18
19
|
from fastcore.xdg import xdg_config_home
|
|
19
20
|
from jupyasyncclient import start_gateway
|
|
20
21
|
from mcpmini.core import HTTPTransport, jreq
|
|
21
|
-
from . import __version__
|
|
22
|
+
from . import __version__, skill
|
|
22
23
|
|
|
23
|
-
__all__ = ['Gateway', 'default_gateway', 'resolve', 'gateways', 'cfg_dir', 'startup_src', 'session_defaults', 'DEFAULT_URL']
|
|
24
|
+
__all__ = ['Gateway', 'default_gateway', 'resolve', 'gateways', 'cfg_dir', 'read_docs', 'boot_calls', 'startup_src', 'session_defaults', 'DEFAULT_URL']
|
|
24
25
|
|
|
25
26
|
DEFAULT_URL = 'http://127.0.0.1:8787'
|
|
26
27
|
|
|
@@ -154,27 +155,34 @@ def resolve(
|
|
|
154
155
|
def _with_file(src, path): return f"__file__ = {str(path)!r}\ntry: exec(compile({src!r}, __file__, 'exec'))\nfinally: del __file__"
|
|
155
156
|
|
|
156
157
|
|
|
157
|
-
|
|
158
|
-
import ast
|
|
159
|
-
import ipymini.term.display # chkstyle: ignore
|
|
160
|
-
run = shell.run_ast_nodes
|
|
161
|
-
async def run_ast_nodes(nodelist, cell_name, interactivity='last_expr', **kwargs):
|
|
162
|
-
if interactivity != 'all': return await run(nodelist, cell_name, interactivity, **kwargs)
|
|
163
|
-
for n in nodelist:
|
|
164
|
-
if await run([n], cell_name, 'last' if isinstance(n, ast.Expr) else 'none', **kwargs): return True
|
|
165
|
-
return False
|
|
166
|
-
shell.run_ast_nodes = run_ast_nodes
|
|
167
|
-
shell.ast_node_interactivity = 'all'
|
|
158
|
+
_DOC_EXTS = {'.md', '.txt', '.py'}
|
|
168
159
|
|
|
169
|
-
|
|
160
|
+
def read_docs(
|
|
161
|
+
cfgdir:str|Path=None, # Config directory for `extra-docs/` lookup (default `cfg_dir()`)
|
|
162
|
+
) -> str: # Combined `clikernel` and `extra-docs/` text with `# <name>` headers
|
|
163
|
+
"Read the built-in `clikernel` usage doc followed by every configured file in `extra-docs/`."
|
|
164
|
+
sections = [f"# clikernel\n\n{(skill.__doc__ or '').strip()}"]
|
|
165
|
+
ed = (Path(cfgdir) if cfgdir else cfg_dir())/'extra-docs'
|
|
166
|
+
if ed.is_dir():
|
|
167
|
+
for p in sorted(ed.iterdir()):
|
|
168
|
+
if not (p.is_file() and p.suffix in _DOC_EXTS): continue
|
|
169
|
+
txt = p.read_text()
|
|
170
|
+
body = (ast.get_docstring(ast.parse(txt)) or '').strip() if p.suffix == '.py' else txt.strip()
|
|
171
|
+
if body: sections.append(f'# {p.name}\n\n{body}')
|
|
172
|
+
return '\n\n'.join(sections)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def boot_calls() -> tuple[str, ...]: # Parallel MCP `docs()` and kernel `doc(...)` bootstrap calls
|
|
176
|
+
"Return the standard `docs()` and kernel `doc(...)` bootstrap calls."
|
|
177
|
+
return ('docs()', 'doc(pysk)', 'doc(edsk)', 'doc(dsk)', 'doc(exh)', 'doc(rgsk)', 'list_pyskills()')
|
|
170
178
|
|
|
171
179
|
|
|
172
180
|
def startup_src(
|
|
173
181
|
cfgdir:str|Path=None, # Config directory checked for optional `startup.py` (default `cfg_dir()`)
|
|
174
182
|
) -> str: # Combined Python startup source sent to `jupygate`
|
|
175
|
-
"Build Python
|
|
183
|
+
"Build standard Python startup defaults followed by optional user `startup.py` source."
|
|
176
184
|
d = Path(cfgdir) if cfgdir else cfg_dir()
|
|
177
|
-
parts = [
|
|
185
|
+
parts = [files('clikernel').joinpath('startup.py').read_text()]
|
|
178
186
|
if (p := d/'startup.py').exists(): parts.append(_with_file(p.read_text(), p))
|
|
179
187
|
return '\n'.join(parts)
|
|
180
188
|
|
|
@@ -184,8 +192,8 @@ def session_defaults(
|
|
|
184
192
|
quiet:bool=False, # Suppress startup output in gateway replies
|
|
185
193
|
local:bool=True, # Include local `cwd` and `os.environ` (set `False` for remote gateways)
|
|
186
194
|
) -> dict: # `jupygate` initialization defaults dict
|
|
187
|
-
"Build `jupygate` session defaults: `startup`, `quiet`, plus `cwd`/`env` when `local=True` or
|
|
195
|
+
"Build `jupygate` session defaults: `startup`, `quiet`, plus `cwd`/`env` when `local=True` or harness session ids when remote."
|
|
188
196
|
d = dict(startup=startup_src(cfgdir), quiet=quiet)
|
|
189
197
|
if local: d.update(cwd=os.getcwd(), env=dict(os.environ))
|
|
190
|
-
elif
|
|
198
|
+
elif env := {k: v for k in ('CLAUDE_CODE_SESSION_ID', 'CODEX_THREAD_ID') if (v := os.environ.get(k))}: d['env'] = env
|
|
191
199
|
return d
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Route stdio MCP requests to `jupygate` gateways with per-agent isolation, cell rules, and output paging.
|
|
2
2
|
|
|
3
|
-
`clikernel-mcp` (`main`) serves one `Router` over stdio. The router reads tool schemas from the local gateway, adds `host` to `list_kernels`, `use_kernel`, and `create`, and maintains an isolated gateway session per `(host, agent)` pair (closing idle subagent sessions after `agent_idle` seconds).
|
|
3
|
+
`clikernel-mcp` (`main`) serves one `Router` over stdio. The router reads tool schemas from the local gateway, adds `host` to `list_kernels`, `use_kernel`, and `create`, adds a local `docs` tool serving `clikernel.skill` and `~/.config/clikernel/extra-docs/`, and maintains an isolated gateway session per `(host, agent)` pair (closing idle subagent sessions after `agent_idle` seconds).
|
|
4
4
|
|
|
5
5
|
Before forwarding `exec`, the router intercepts `%cont` / `%cont <id>` to page through replies truncated past `maxout` UTF-8 bytes, and checks all other cells against `clikernel.rules` (attaching advisory notes or blocking forbidden cells). Images past 5 MiB total base64 in one reply are replaced by text notices. On EOF, `SIGTERM`, or exit, `Router.aclose` closes every session, removes temporary overflow files, and stops any owned child gateway.
|
|
6
6
|
"""
|
|
@@ -15,13 +15,15 @@ from fastcore.basics import first
|
|
|
15
15
|
from fastcore.script import call_parse, store_true
|
|
16
16
|
from mcpmini.core import jerr, jresp, serve_stdio
|
|
17
17
|
from . import __version__
|
|
18
|
-
from .core import DEFAULT_URL, Gateway, default_gateway, resolve, session_defaults
|
|
18
|
+
from .core import DEFAULT_URL, Gateway, default_gateway, read_docs, resolve, session_defaults
|
|
19
19
|
from .rules import scan
|
|
20
20
|
|
|
21
21
|
__all__ = ['Router', 'main', 'hook', 'agent_input', 'HOST_PARAM', 'HOSTED', 'MAXOUT', 'AGENT_IDLE', 'AGENT_KERNEL']
|
|
22
22
|
|
|
23
|
-
HOST_PARAM = {'type': 'string', 'description': 'Gateway to target: a gateways.toml name
|
|
23
|
+
HOST_PARAM = {'type': 'string', 'description': 'Gateway to target: a gateways.toml name; omit or empty for the default local gateway'}
|
|
24
24
|
HOSTED = ('list_kernels', 'use_kernel', 'create')
|
|
25
|
+
_DOCS_TOOL = dict(name='docs', description='Return clikernel usage docs and all configured extra docs (call if not in full in context).', inputSchema=dict(type='object', properties={}))
|
|
26
|
+
_DOCS_HINT = 'Run `docs()` if clikernel and extra docs are not in full in context.'
|
|
25
27
|
MAXOUT = 40_000
|
|
26
28
|
AGENT_IDLE = 1800
|
|
27
29
|
AGENT_KERNEL = "New kernel for this subagent: names from any other kernel, the parent's included, aren't defined here."
|
|
@@ -138,13 +140,14 @@ class Router:
|
|
|
138
140
|
with suppress(Exception): await s.aclose()
|
|
139
141
|
|
|
140
142
|
async def tools(self) -> list[dict]:
|
|
141
|
-
"Return local gateway tools with `host` added to `HOSTED` tools
|
|
143
|
+
"Return local gateway tools with `host` added to `HOSTED` tools, `create.kernel` enum unconstrained, and the local `docs` tool."
|
|
142
144
|
ts = await (await self.session()).tools()
|
|
143
145
|
for t in ts:
|
|
144
146
|
props = t['inputSchema'].setdefault('properties', {})
|
|
145
147
|
if t['name'] in HOSTED: props['host'] = dict(HOST_PARAM)
|
|
146
148
|
if t['name'] == 'create' and 'kernel' in props: props['kernel'].pop('enum', None)
|
|
147
|
-
return ts
|
|
149
|
+
return [*ts, _DOCS_TOOL]
|
|
150
|
+
|
|
148
151
|
|
|
149
152
|
def _cap_text(self, content, agent, note=''):
|
|
150
153
|
note_blk = [dict(type='text', text=note)] if note else []
|
|
@@ -230,19 +233,22 @@ class Router:
|
|
|
230
233
|
r = await s.call('create', **kw)
|
|
231
234
|
if r.get('isError'): return r
|
|
232
235
|
self._agent_gen[key] = gen + 1
|
|
233
|
-
|
|
236
|
+
content = [dict(type='text', text=AGENT_KERNEL), *r['content']]
|
|
237
|
+
return _stack(content + [dict(type='text', text=_DOCS_HINT)]) if not self.quiet else content
|
|
234
238
|
|
|
235
239
|
async def _dispatch_call(self, id, msg):
|
|
236
240
|
args = msg['params'].setdefault('arguments', {})
|
|
237
241
|
agent = args.pop('agent', None) or None
|
|
238
242
|
tool = msg['params']['name']
|
|
243
|
+
if tool == 'docs':
|
|
244
|
+
args.pop('cwd', None)
|
|
245
|
+
return jresp(id, dict(content=self._cap_text([dict(type='text', text=f'𝍁{read_docs(self.cfgdir)}𝍁')], agent)))
|
|
239
246
|
if tool == 'exec' and (m := _CONT_RE.match(args.get('code', '').strip())): return jresp(id, self._cont(agent, m.group(1)))
|
|
240
247
|
fired = scan(args.get('code', '')) if tool == 'exec' else []
|
|
241
248
|
if blocks := [r.note for r in fired if r.block]:
|
|
242
249
|
return jresp(id, dict(isError=True, content=[dict(type='text', text=' '.join(blocks) + ' (If the block seems wrong here, tell your user.)')]))
|
|
243
|
-
has_host = 'host' in args
|
|
244
250
|
host = args.pop('host', '') or ''
|
|
245
|
-
h = host if
|
|
251
|
+
h = host if tool in HOSTED else self.cur.setdefault(agent, self.cur.get(None, ''))
|
|
246
252
|
if h or os.environ.get('CLIKERNEL_HOST'): args.pop('cwd', None)
|
|
247
253
|
cwd = args.pop('cwd', None) if tool == 'exec' else None
|
|
248
254
|
gen = self._agent_gen.get((h, agent), 0) if agent is not None else 0
|
|
@@ -258,11 +264,13 @@ class Router:
|
|
|
258
264
|
finally: self.inflight.pop(id, None)
|
|
259
265
|
if res and 'result' in res:
|
|
260
266
|
if not res['result'].get('isError'):
|
|
261
|
-
if
|
|
267
|
+
if tool in ('use_kernel', 'create'): self.cur[agent] = h
|
|
262
268
|
if agent is None and tool in ('create', 'use_kernel', 'delete_kernel'):
|
|
263
269
|
if tool == 'create' and (k := args.get('kernel')): self._main_kernel[h] = k
|
|
264
270
|
else: self._main_kernel.pop(h, None)
|
|
265
271
|
content = _cap_images(res['result']['content'])
|
|
272
|
+
if tool == 'create' and not res['result'].get('isError') and not self.quiet:
|
|
273
|
+
content = _stack(content + [dict(type='text', text=_DOCS_HINT)])
|
|
266
274
|
note = ''.join(f'<note>\n{r.note}\n</note>\n' for r in fired) if fired and not self.quiet else ''
|
|
267
275
|
res['result']['content'] = self._cap_text(content, agent, note=note)
|
|
268
276
|
return res
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
r"""Use `clikernel` MCP as the default persistent Python workspace for file/notebook reads and edits, exploration, library checks, data reshaping and debugging. Read before writing, running or debugging Python with `clikernel` connected.
|
|
2
|
+
|
|
3
|
+
- prefer: clikernel over `python -c`/heredocs; pyskills (rgapi `rg` `fd` `ls`; ghapi: GitHub, git) over shell; shell: project tests, builds, non-Python tools
|
|
4
|
+
- `docs()`: returns `𝍁`-wrapped `clikernel` plus `~/.config/clikernel/extra-docs/` locally from router (no remote install)
|
|
5
|
+
- outlive conversation: `create(kernel="py", autoclose=false)`, tell user id; if reply shows conversation-started gateway, say so /needs a lasting gateway
|
|
6
|
+
- existing or user's solveit kernel: `list_kernels` → `use_kernel(id)`
|
|
7
|
+
- `restart`: reruns startup, redo interactive setup; `interrupt` keeps state
|
|
8
|
+
- subagents: own kernel (auto-created on first `exec`, startup run, no parent vars, isolated create/restart/switch, culled after 30m idle)
|
|
9
|
+
- `host=`: `~/.config/clikernel/gateways.toml` names; later `exec` stays on that host
|
|
10
|
+
- `--maxout`: `len(v)` first; overflow returns first chunk + temp file; `%cont` or `%cont <id>` in `exec` for next chunk; huge: `rg`/`open_doc` on temp file
|
|
11
|
+
|
|
12
|
+
### Python
|
|
13
|
+
|
|
14
|
+
- magics work, `%%bash` too; `%cd` (expands `~`), not `os.chdir`
|
|
15
|
+
- startup: `ast_node_interactivity='all'` (top-level expressions display bare, loops/blocks silent in `ipymini`, startup can override; not `print()` or separator headers), `init_journal()`, installed standard toolkit, then optional `~/.config/clikernel/startup.py`
|
|
16
|
+
- state: imports, helpers, root/path vars persist; paths relative to cwd, `~`, or saved vars (no repeated full paths); `NameError` for own name: restarted or attached, redo setup
|
|
17
|
+
- after `ship-export` or module edit: `importlib.reload`, re-import held names (`from x import y` keeps old object); `@patch` refreshes; restart only if held instance's class changed
|
|
18
|
+
- loaded behavior: call it, never `inspect.getsource` /reads disk
|
|
19
|
+
- try plain import or call before env changes, monkeypatching, or extra setup
|
|
20
|
+
"""
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
if (ip := get_ipython()): ip.ast_node_interactivity = 'all'
|
|
2
|
+
try:
|
|
3
|
+
from fastcore.utils import *
|
|
4
|
+
from fastcore.tools import init_journal
|
|
5
|
+
init_journal()
|
|
6
|
+
# chkstyle: off
|
|
7
|
+
from pyskills import list_pyskills, doc, xdir, info_md
|
|
8
|
+
from fastcore.editskill import *
|
|
9
|
+
from aidialog.dlgskill import *
|
|
10
|
+
from exhash.skill import *
|
|
11
|
+
from rgapi.skill import *
|
|
12
|
+
import pyskills.skill as pysk, fastcore.editskill as edsk, aidialog.dlgskill as dsk, exhash.skill as exh, rgapi.skill as rgsk
|
|
13
|
+
# chkstyle: on
|
|
14
|
+
print('Kernel imports are loaded, including rg/fd/ls from rgapi. Run any of these not in full in context (parallel separate calls):\ndoc(pysk)\ndoc(edsk)\ndoc(dsk)\ndoc(exh)\ndoc(rgsk)\nlist_pyskills()')
|
|
15
|
+
except ModuleNotFoundError as e: print(f'Incomplete kernel env ({e.name} missing); install fastcore, pyskills, aidialog, exhash, rgapi for full tools.')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clikernel
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.23
|
|
4
4
|
Summary: Serve persistent Jupyter kernels to LLMs as concise text, over MCP or a plain stream protocol
|
|
5
5
|
Author: clikernel contributors
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -11,11 +11,11 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
11
11
|
Requires-Python: >=3.11
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: fastcore>=2.3.
|
|
14
|
+
Requires-Dist: fastcore>=2.3.15
|
|
15
15
|
Requires-Dist: jupyasyncclient>=0.2.32
|
|
16
16
|
Requires-Dist: mcpmini>=0.0.5
|
|
17
17
|
Requires-Dist: jupygate>=0.1.0
|
|
18
|
-
Requires-Dist: ipymini>=0.1.
|
|
18
|
+
Requires-Dist: ipymini>=0.1.31
|
|
19
19
|
Requires-Dist: httpx
|
|
20
20
|
Requires-Dist: execnb>=0.3.5
|
|
21
21
|
Provides-Extra: dev
|
|
@@ -68,9 +68,10 @@ The router caps text replies to `--maxout` UTF-8 bytes (default 40,000; pass `0`
|
|
|
68
68
|
|
|
69
69
|
## Configuration
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Optional files under `$XDG_CONFIG_HOME/clikernel/` configure the router, usually under `~/.config/clikernel/`, or under the directory `clikernel-mcp --cfgdir` names:
|
|
72
72
|
|
|
73
|
-
- `
|
|
73
|
+
- `extra-docs/` holds `.md`, `.txt`, or `.py` (module docstring) files returned alongside the built-in `clikernel` guide by the local `docs()` MCP tool, wrapped in `𝍁...𝍁`.
|
|
74
|
+
- `startup.py` runs in each Python kernel clikernel creates after the built-in standard toolkit startup, with `__file__` set to its path. Output appears in the reply announcing the kernel unless `--quiet` is set.
|
|
74
75
|
- `gateways.toml` names remote gateways and configures authentication without putting tokens in tool arguments:
|
|
75
76
|
|
|
76
77
|
``` toml
|
|
@@ -9,7 +9,7 @@ from jupyasyncclient import start_gateway
|
|
|
9
9
|
from mcpmini.core import jreq, jtool
|
|
10
10
|
|
|
11
11
|
from clikernel.cli import _MARKER, _read_block, _response
|
|
12
|
-
from clikernel.core import DEFAULT_URL, Gateway, default_gateway, resolve, session_defaults
|
|
12
|
+
from clikernel.core import DEFAULT_URL, Gateway, boot_calls, default_gateway, read_docs, resolve, session_defaults
|
|
13
13
|
from clikernel.mcp import HOSTED, MAXOUT, Router, _cap_images, _hook_response, _page, agent_input
|
|
14
14
|
from clikernel.rules import RULES, scan
|
|
15
15
|
|
|
@@ -108,6 +108,13 @@ def test_config_and_gateway():
|
|
|
108
108
|
(cfgd/'gateways.toml').write_text(f'[gateways.solveit]\nurl = "https://s.example.com/rusty"\ntoken_file = "{cfgd/"session"}"\nverify = false\n[gateways.bad]\nurl = "https://x"\ntoken = "a"\ntoken_env = "B"\n')
|
|
109
109
|
(cfgd/'startup.py').write_text('base = 42\nprint("ready, file", __file__.rsplit("/", 1)[-1])\n')
|
|
110
110
|
|
|
111
|
+
(cfgd/'extra-docs').mkdir()
|
|
112
|
+
(cfgd/'extra-docs'/'note.md').write_text('hello\n')
|
|
113
|
+
(cfgd/'extra-docs'/'guide.py').write_text('"""Guide body."""\nx = 1\n')
|
|
114
|
+
docs_txt = read_docs(cfgd)
|
|
115
|
+
assert docs_txt.startswith('# clikernel\n\n') and '# guide.py\n\nGuide body.' in docs_txt and '# note.md\n\nhello' in docs_txt
|
|
116
|
+
assert boot_calls()[:2] == ('docs()', 'doc(pysk)')
|
|
117
|
+
|
|
111
118
|
assert resolve() == (DEFAULT_URL, os.environ.get('CLIKERNEL_TOKEN'), True)
|
|
112
119
|
assert resolve('http://h:1/p') == ('http://h:1/p', os.environ.get('CLIKERNEL_TOKEN'), True)
|
|
113
120
|
assert resolve('solveit', cfgd) == ('https://s.example.com/rusty', 'T', False)
|
|
@@ -116,8 +123,8 @@ def test_config_and_gateway():
|
|
|
116
123
|
|
|
117
124
|
d = session_defaults(cfgd)
|
|
118
125
|
assert 'ready, file' in d['startup'] and 'cwd' in d and 'env' in d
|
|
119
|
-
with modified_env(CLAUDE_CODE_SESSION_ID='s1'): remote = session_defaults(cfgd, local=False)
|
|
120
|
-
assert remote['env'] == {'CLAUDE_CODE_SESSION_ID': 's1'} and 'cwd' not in remote
|
|
126
|
+
with modified_env(CLAUDE_CODE_SESSION_ID='s1', CODEX_THREAD_ID='t1'): remote = session_defaults(cfgd, local=False)
|
|
127
|
+
assert remote['env'] == {'CLAUDE_CODE_SESSION_ID': 's1', 'CODEX_THREAD_ID': 't1'} and 'cwd' not in remote
|
|
121
128
|
|
|
122
129
|
g = start_gateway()
|
|
123
130
|
gw2 = None
|
|
@@ -127,7 +134,8 @@ def test_config_and_gateway():
|
|
|
127
134
|
assert 'protocolVersion' in gw.info and gw.info.get('jupygate')
|
|
128
135
|
banner = await gw.text('create', kernel='py')
|
|
129
136
|
kid = re.search(r'created kernel (\w+)', banner).group(1)
|
|
130
|
-
assert 'ready, file startup.py' in banner
|
|
137
|
+
assert 'ready, file startup.py' in banner and 'doc(pysk)' in banner
|
|
138
|
+
assert await gw.text('exec', code="import os; bool(os.environ.get('EDIT_JOURNAL'))") == 'True'
|
|
131
139
|
out = await gw.text('exec', code='base\nfor i in range(3): i*10\nbase+1')
|
|
132
140
|
assert re.findall(r'\d+', out) == ['42', '43']
|
|
133
141
|
assert await gw.text('exec', code="import os; os.environ['CLIK_DEMO']") == 'via-defaults'
|
|
@@ -186,6 +194,8 @@ def test_router_and_stream_cli():
|
|
|
186
194
|
with tempfile.TemporaryDirectory() as td:
|
|
187
195
|
cfgd = Path(td)
|
|
188
196
|
(cfgd/'startup.py').write_text('base = 42; print("ready")\n')
|
|
197
|
+
(cfgd/'extra-docs').mkdir()
|
|
198
|
+
(cfgd/'extra-docs'/'guide.py').write_text('"""Extra guide."""\nx = 1\n')
|
|
189
199
|
g, g2 = start_gateway(), start_gateway()
|
|
190
200
|
(cfgd/'gateways.toml').write_text(f'[gateways.alt]\nurl = "{g2.url}"\n')
|
|
191
201
|
router = Router(cfgd, url=g.url)
|
|
@@ -200,11 +210,15 @@ def test_router_and_stream_cli():
|
|
|
200
210
|
assert all('host' in byname[n]['inputSchema']['properties'] for n in HOSTED)
|
|
201
211
|
assert 'host' not in byname['exec']['inputSchema']['properties']
|
|
202
212
|
assert 'enum' not in byname['create']['inputSchema']['properties']['kernel']
|
|
213
|
+
assert byname['docs']['inputSchema']['properties'] == {}
|
|
214
|
+
cdoc = await text('docs', agent='sub1', cwd='/tmp')
|
|
215
|
+
assert cdoc.startswith('𝍁# clikernel\n\n') and cdoc.endswith('𝍁') and '# guide.py\n\nExtra guide.' in cdoc
|
|
203
216
|
|
|
204
217
|
init = await router.dispatch(jreq('initialize', 1, protocolVersion='2025-11-25', capabilities={}, clientInfo=dict(name='t', version='0')))
|
|
205
218
|
assert init['result']['serverInfo']['name'] == 'clikernel' and init['result']['protocolVersion'] == '2025-11-25'
|
|
206
219
|
|
|
207
|
-
|
|
220
|
+
created = await text('create', kernel='py')
|
|
221
|
+
assert 'ready' in created and 'docs()' in created
|
|
208
222
|
assert await text('exec', code='base') == '42'
|
|
209
223
|
|
|
210
224
|
assert 'ready' in await text('create', kernel='py', host='alt')
|
|
@@ -212,15 +226,18 @@ def test_router_and_stream_cli():
|
|
|
212
226
|
assert await text('exec', code='marker') == '7'
|
|
213
227
|
cwd_dir = (cfgd/'proj').resolve()
|
|
214
228
|
cwd_dir.mkdir()
|
|
215
|
-
await text('create', kernel='py',
|
|
229
|
+
await text('create', kernel='py', agent='cwd-test', cwd=str(cwd_dir))
|
|
216
230
|
assert await text('exec', code='import os; os.getcwd()', agent='cwd-test') == str(cwd_dir)
|
|
217
231
|
await text('create', kernel='py', host='alt', agent='cwd-test', cwd='/nonexistent/local/path')
|
|
218
232
|
assert await text('exec', code='import os; os.getcwd()', agent='cwd-test') != '/nonexistent/local/path'
|
|
233
|
+
await text('delete_kernel', agent='cwd-test')
|
|
234
|
+
await text('create', kernel='py', agent='cwd-test', cwd=str(cwd_dir))
|
|
235
|
+
assert await text('exec', code='import os; os.getcwd()', agent='cwd-test') == str(cwd_dir)
|
|
219
236
|
|
|
220
|
-
kid = re.search(r'^(\S+) .*<- current$', await text('list_kernels'
|
|
221
|
-
assert (await call('use_kernel', kernel='nonexistent'
|
|
237
|
+
kid = re.search(r'^(\S+) .*<- current$', await text('list_kernels'), re.M).group(1)
|
|
238
|
+
assert (await call('use_kernel', kernel='nonexistent')).get('isError')
|
|
222
239
|
assert await text('exec', code='marker') == '7'
|
|
223
|
-
await text('use_kernel', kernel=kid
|
|
240
|
+
await text('use_kernel', kernel=kid)
|
|
224
241
|
assert 'NameError' in await text('exec', code='marker') and await text('exec', code='base') == '42'
|
|
225
242
|
|
|
226
243
|
img_r = await call('exec', code='from PIL import Image\nImage.new("RGB", (60, 40), "red")')
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.22"
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
r"""Use `clikernel` MCP as the default persistent Python workspace for file/notebook reads and edits, exploration, library checks, data reshaping and debugging. Imports and variables carry across calls. Read before writing, running or debugging Python with `clikernel` connected.
|
|
2
|
-
|
|
3
|
-
- prefer: clikernel over one-off scripts (`python -c`, heredocs); pyskills over shell (rgapi `rg` `fd` `ls`; ghapi: GitHub, git); shell: project tests, builds, non-Python tools
|
|
4
|
-
- outlive conversation: `create(kernel="py", autoclose=false)`, tell user its id; reply shows gateway started by this conversation: say so /kernel needs a lasting gateway
|
|
5
|
-
- earlier or user's solveit kernel: `list_kernels` → `use_kernel(id)`
|
|
6
|
-
- `restart`: reruns that kernel's startup; redo interactive setup; `interrupt` keeps state
|
|
7
|
-
- `host=` names: `~/.config/clikernel/gateways.toml`; later `exec` stays on that host
|
|
8
|
-
- replies >`--maxout` bytes: first chunk inline + full-output temp file; `%cont` or `%cont <id>` in `exec` for next chunk; huge: `rg`/`open_doc` on temp file
|
|
9
|
-
|
|
10
|
-
### Python
|
|
11
|
-
|
|
12
|
-
- magics work, `%%bash` too; `%cd` (expands `~`), not `os.chdir`
|
|
13
|
-
- display: every top-level expression displays bare (blocks don't; `clikernel` default, startup can override), not `print()` or separator headers
|
|
14
|
-
- state: imports, helpers, root/path vars persist across calls; paths: relative to cwd, `~`, or saved vars (no repeated full paths); `NameError` for your name: restarted or attached: redo setup
|
|
15
|
-
- outputs up to `--maxout`: `len(v)` first
|
|
16
|
-
- after `nbdev-export` or module edit: `importlib.reload`, re-import held names (`from x import y` keeps old object); `@patch` refreshes; restart only if a held instance's class changed
|
|
17
|
-
- loaded behavior: call it, never `inspect.getsource` /reads disk
|
|
18
|
-
- before env changes, monkeypatching, extra setup: try the plain import or call
|
|
19
|
-
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|