clikernel 0.2.3__tar.gz → 0.2.5__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.
@@ -2,6 +2,20 @@
2
2
 
3
3
  <!-- do not remove -->
4
4
 
5
+ ## 0.2.5
6
+
7
+ ### New Features
8
+
9
+ - restart now re-runs startup.py and reinstalls inspectors on client-created kernels; attached kernels still restart bare ([#37](https://github.com/AnswerDotAI/clikernel/issues/37))
10
+
11
+
12
+ ## 0.2.4
13
+
14
+ ### New Features
15
+
16
+ - Swap jupygate for rustygate; add optional verify flag for self-signed TLS gateways ([#36](https://github.com/AnswerDotAI/clikernel/issues/36))
17
+
18
+
5
19
  ## 0.2.3
6
20
 
7
21
  ### New Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clikernel
3
- Version: 0.2.3
3
+ Version: 0.2.5
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: Apache-2.0
@@ -18,7 +18,7 @@ Requires-Dist: aidialog>=0.0.7
18
18
  Requires-Dist: pillow
19
19
  Provides-Extra: dev
20
20
  Requires-Dist: fastship; extra == "dev"
21
- Requires-Dist: jupygate>=0.0.1; extra == "dev"
21
+ Requires-Dist: rustygate>=0.1.1; extra == "dev"
22
22
  Dynamic: license-file
23
23
 
24
24
  # clikernel
@@ -26,7 +26,7 @@ Dynamic: license-file
26
26
 
27
27
  <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
28
28
 
29
- `clikernel` gives an LLM agent a persistent Python workbench built from two processes. A [jupygate](https://github.com/AnswerDotAI/jupygate) server runs all the time and hosts real Jupyter kernels ([ipymini](https://github.com/AnswerDotAI/ipymini) by default); kernels live there and persist until explicitly stopped. `clikernel` itself starts and stops with each conversation: a small translator the MCP host launches, speaking MCP to the model and the Jupyter kernels API to the gateway. Outputs come back as concise text — a bare `42` for a single result, tagged sections for several, tracebacks ANSI-stripped and capped.
29
+ `clikernel` gives an LLM agent a persistent Python workbench built from two processes. A gateway ([rustygate](https://github.com/AnswerDotAI/rustygate)) runs all the time and hosts real Jupyter kernels ([ipymini](https://github.com/AnswerDotAI/ipymini) by default); kernels live there and persist until explicitly stopped. `clikernel` itself starts and stops with each conversation: a small translator the MCP host launches, speaking MCP to the model and the Jupyter kernels API to the gateway. Outputs come back as concise text — a bare `42` for a single result, tagged sections for several, tracebacks ANSI-stripped and capped.
30
30
 
31
31
  Because kernels outlive conversations, an agent can `connect` back to yesterday’s kernel (or the user’s live solveit kernel) and find its state intact. Kernels created or attached explicitly are never stopped implicitly: only `stop_kernel` ends them. The one exception is the auto kernel: an `execute` with nothing connected creates a kernel scoped to the conversation, stopped again when the conversation ends or the agent connects elsewhere. Creating a kernel runs the user’s `startup.py` and installs their `inspectors.py` cell-checking rules, delivered as source so remote kernels get the same setup as local ones.
32
32
 
@@ -36,10 +36,10 @@ Because kernels outlive conversations, an agent can `connect` back to yesterday
36
36
  pip install clikernel
37
37
  ```
38
38
 
39
- Plus the resident side: [jupygate](https://github.com/AnswerDotAI/jupygate) and a kernel ([ipymini](https://github.com/AnswerDotAI/ipymini) by default). Start the gateway (and keep it running, e.g. via launchd/systemd):
39
+ Plus the resident side: [rustygate](https://github.com/AnswerDotAI/rustygate) and a kernel ([ipymini](https://github.com/AnswerDotAI/ipymini) by default). Start the gateway (and keep it running, e.g. via launchd/systemd):
40
40
 
41
41
  ``` sh
42
- jupygate --port 8787
42
+ rustygate --port 8787
43
43
  ```
44
44
 
45
45
  ## Use with an MCP host
@@ -50,7 +50,7 @@ Register the stdio server with your MCP host, e.g. for Claude Code:
50
50
  claude mcp add clikernel -- clikernel-mcp
51
51
  ```
52
52
 
53
- The tools mirror jupygate’s kernel API plus one composite: `connect` (create a fresh kernel — running `startup.py` and installing inspectors — or attach to an existing one by id), `execute` (run code, get concise text), `list_kernels`, `stop_kernel`, `restart`, and `interrupt`. An `execute` with no kernel connected auto-creates one, scoped to the conversation: it stops at conversation end, or when `connect` moves elsewhere. Kernels made or attached with an explicit `connect` are stopped only by `stop_kernel` — a later conversation reattaches by id and continues where the last one stopped. `$CLIKERNEL_HOST` overrides the default gateway (`http://127.0.0.1:8787`).
53
+ The tools mirror the gateway’s kernel API plus one composite: `connect` (create a fresh kernel — running `startup.py` and installing inspectors — or attach to an existing one by id), `execute` (run code, get concise text), `list_kernels`, `stop_kernel`, `restart`, and `interrupt`. An `execute` with no kernel connected auto-creates one, scoped to the conversation: it stops at conversation end, or when `connect` moves elsewhere. Kernels made or attached with an explicit `connect` are stopped only by `stop_kernel` — a later conversation reattaches by id and continues where the last one stopped. `$CLIKERNEL_HOST` overrides the default gateway (`http://127.0.0.1:8787`).
54
54
 
55
55
  ## Configuration
56
56
 
@@ -64,6 +64,7 @@ Three optional files in `$XDG_CONFIG_HOME/clikernel/` (usually `~/.config/cliker
64
64
  [gateways.solveit]
65
65
  url = "https://solveit.example.com/gate"
66
66
  token_env = "SOLVEIT_TOKEN"
67
+ verify = false # optional: accept a self-signed certificate
67
68
  ```
68
69
 
69
70
  ## The stream protocol
@@ -3,7 +3,7 @@
3
3
 
4
4
  <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
5
5
 
6
- `clikernel` gives an LLM agent a persistent Python workbench built from two processes. A [jupygate](https://github.com/AnswerDotAI/jupygate) server runs all the time and hosts real Jupyter kernels ([ipymini](https://github.com/AnswerDotAI/ipymini) by default); kernels live there and persist until explicitly stopped. `clikernel` itself starts and stops with each conversation: a small translator the MCP host launches, speaking MCP to the model and the Jupyter kernels API to the gateway. Outputs come back as concise text — a bare `42` for a single result, tagged sections for several, tracebacks ANSI-stripped and capped.
6
+ `clikernel` gives an LLM agent a persistent Python workbench built from two processes. A gateway ([rustygate](https://github.com/AnswerDotAI/rustygate)) runs all the time and hosts real Jupyter kernels ([ipymini](https://github.com/AnswerDotAI/ipymini) by default); kernels live there and persist until explicitly stopped. `clikernel` itself starts and stops with each conversation: a small translator the MCP host launches, speaking MCP to the model and the Jupyter kernels API to the gateway. Outputs come back as concise text — a bare `42` for a single result, tagged sections for several, tracebacks ANSI-stripped and capped.
7
7
 
8
8
  Because kernels outlive conversations, an agent can `connect` back to yesterday’s kernel (or the user’s live solveit kernel) and find its state intact. Kernels created or attached explicitly are never stopped implicitly: only `stop_kernel` ends them. The one exception is the auto kernel: an `execute` with nothing connected creates a kernel scoped to the conversation, stopped again when the conversation ends or the agent connects elsewhere. Creating a kernel runs the user’s `startup.py` and installs their `inspectors.py` cell-checking rules, delivered as source so remote kernels get the same setup as local ones.
9
9
 
@@ -13,10 +13,10 @@ Because kernels outlive conversations, an agent can `connect` back to yesterday
13
13
  pip install clikernel
14
14
  ```
15
15
 
16
- Plus the resident side: [jupygate](https://github.com/AnswerDotAI/jupygate) and a kernel ([ipymini](https://github.com/AnswerDotAI/ipymini) by default). Start the gateway (and keep it running, e.g. via launchd/systemd):
16
+ Plus the resident side: [rustygate](https://github.com/AnswerDotAI/rustygate) and a kernel ([ipymini](https://github.com/AnswerDotAI/ipymini) by default). Start the gateway (and keep it running, e.g. via launchd/systemd):
17
17
 
18
18
  ``` sh
19
- jupygate --port 8787
19
+ rustygate --port 8787
20
20
  ```
21
21
 
22
22
  ## Use with an MCP host
@@ -27,7 +27,7 @@ Register the stdio server with your MCP host, e.g. for Claude Code:
27
27
  claude mcp add clikernel -- clikernel-mcp
28
28
  ```
29
29
 
30
- The tools mirror jupygate’s kernel API plus one composite: `connect` (create a fresh kernel — running `startup.py` and installing inspectors — or attach to an existing one by id), `execute` (run code, get concise text), `list_kernels`, `stop_kernel`, `restart`, and `interrupt`. An `execute` with no kernel connected auto-creates one, scoped to the conversation: it stops at conversation end, or when `connect` moves elsewhere. Kernels made or attached with an explicit `connect` are stopped only by `stop_kernel` — a later conversation reattaches by id and continues where the last one stopped. `$CLIKERNEL_HOST` overrides the default gateway (`http://127.0.0.1:8787`).
30
+ The tools mirror the gateway’s kernel API plus one composite: `connect` (create a fresh kernel — running `startup.py` and installing inspectors — or attach to an existing one by id), `execute` (run code, get concise text), `list_kernels`, `stop_kernel`, `restart`, and `interrupt`. An `execute` with no kernel connected auto-creates one, scoped to the conversation: it stops at conversation end, or when `connect` moves elsewhere. Kernels made or attached with an explicit `connect` are stopped only by `stop_kernel` — a later conversation reattaches by id and continues where the last one stopped. `$CLIKERNEL_HOST` overrides the default gateway (`http://127.0.0.1:8787`).
31
31
 
32
32
  ## Configuration
33
33
 
@@ -41,6 +41,7 @@ Three optional files in `$XDG_CONFIG_HOME/clikernel/` (usually `~/.config/cliker
41
41
  [gateways.solveit]
42
42
  url = "https://solveit.example.com/gate"
43
43
  token_env = "SOLVEIT_TOKEN"
44
+ verify = false # optional: accept a self-signed certificate
44
45
  ```
45
46
 
46
47
  ## The stream protocol
@@ -3,9 +3,9 @@
3
3
  Modules:
4
4
 
5
5
  - `clikernel.cli`: The stream-protocol frontend: the service on stdin/stdout for token-reading clients
6
- - `clikernel.core`: Connect to jupygate-hosted kernels and turn execution into concise text
6
+ - `clikernel.core`: Connect to gateway-hosted kernels and turn execution into concise text
7
7
  - `clikernel.mcp`: The MCP frontend: `Client` as tools on stdio
8
8
  - `clikernel.skill`: Use the persistent `clikernel` MCP session as the default workspace for any task advanced through live Python execution -- stateful inspection, file-editing workflows, debugging, experiments, API probes, data transforms, or notebook-style work. Read this before writing, running, or debugging Python code in a session with `clikernel` connected.
9
9
  - `clikernel.stream`: Streaming JSON-lines worker protocol: nbformat-shaped output events, and a supervisor for select-based UIs."""
10
10
 
11
- __version__ = "0.2.3"
11
+ __version__ = "0.2.5"
@@ -16,6 +16,7 @@ d = { 'settings': { 'branch': 'main',
16
16
  'clikernel.cli.serve_stream': ('cli.html#serve_stream', 'clikernel/cli.py')},
17
17
  'clikernel.core': { 'clikernel.core.Client': ('core.html#client', 'clikernel/core.py'),
18
18
  'clikernel.core.Client.__init__': ('core.html#client.__init__', 'clikernel/core.py'),
19
+ 'clikernel.core.Client._setup': ('core.html#client._setup', 'clikernel/core.py'),
19
20
  'clikernel.core.Client._use': ('core.html#client._use', 'clikernel/core.py'),
20
21
  'clikernel.core.Client.aclose': ('core.html#client.aclose', 'clikernel/core.py'),
21
22
  'clikernel.core.Client.connect': ('core.html#client.connect', 'clikernel/core.py'),
@@ -1,6 +1,6 @@
1
1
  """The stream-protocol frontend: the service on stdin/stdout for token-reading clients
2
2
 
3
- The `clikernel` command: the delimiter-framed stdin/stdout protocol v1 established (documented in the README, rationale unchanged — a client that reads stdout as tokens wants no echo, a cheap ack byte, and a per-process random delimiter to read until). The protocol machinery ports from v1 verbatim; underneath, the process is now a thin client of a jupygate kernel. Run bare it creates a kernel and stops it again on exit — whoever ran the command made that decision by running it — while `--kernel` attaches to an existing kernel and leaves it exactly as found. Ctrl-C during a long cell translates into a kernel interrupt, jupyter-console style, instead of killing the process.
3
+ The `clikernel` command: the delimiter-framed stdin/stdout protocol v1 established (documented in the README, rationale unchanged — a client that reads stdout as tokens wants no echo, a cheap ack byte, and a per-process random delimiter to read until). The protocol machinery ports from v1 verbatim; underneath, the process is now a thin client of a gateway kernel. Run bare it creates a kernel and stops it again on exit — whoever ran the command made that decision by running it — while `--kernel` attaches to an existing kernel and leaves it exactly as found. Ctrl-C during a long cell translates into a kernel interrupt, jupyter-console style, instead of killing the process.
4
4
 
5
5
  Docs: https://AnswerDotAI.github.io/clikernel/cli.html.md"""
6
6
 
@@ -120,10 +120,10 @@ _EXITS = ('exit', 'exit()', 'quit', 'quit()')
120
120
 
121
121
  @call_parse
122
122
  def main(
123
- host:str='', # Gateway: empty for the default local jupygate, a `gateways.toml` name, or a URL
123
+ host:str='', # Gateway: empty for the local default, a `gateways.toml` name, or a URL
124
124
  kernel:str='', # Kernel id (or unique prefix) to attach to; empty creates a kernel, stopped again on exit
125
125
  ):
126
- "The `clikernel` console script: the stream protocol over one jupygate kernel"
126
+ "The `clikernel` console script: the stream protocol over one gateway kernel"
127
127
  signal.signal(signal.SIGINT, signal.default_int_handler)
128
128
  print("please wait, loading...", flush=True)
129
129
  loop = asyncio.new_event_loop()
@@ -1,13 +1,13 @@
1
- """Connect to jupygate-hosted kernels and turn execution into concise text
1
+ """Connect to gateway-hosted kernels and turn execution into concise text
2
2
 
3
- clikernel is the LLM side of a two-process design: jupygate runs all the time and hosts the kernels; clikernel starts and stops with each conversation and holds nothing but a pointer. This module is the whole client: gateway resolution from `gateways.toml`, the concise-text rendering contract (ANSI-stripped, capped tracebacks), delivery of `startup.py` and `inspectors.py` into freshly created kernels, and `Client` — connect (create or attach), execute, interrupt, restart, stop, list. The MCP and CLI frontends are thin faces over `Client`; nothing here creates or kills a kernel except when asked, and the one scoped kill is opt-in: a kernel created with `auto=True` belongs to its client, ended by that client's next `connect` or by the frontend on the way out.
3
+ clikernel is the LLM side of a two-process design: a gateway ([rustygate](https://github.com/AnswerDotAI/rustygate)) runs all the time and hosts the kernels; clikernel starts and stops with each conversation and holds nothing but a pointer. This module is the whole client: gateway resolution from `gateways.toml`, the concise-text rendering contract (ANSI-stripped, capped tracebacks), delivery of `startup.py` and `inspectors.py` into freshly created kernels, and `Client` — connect (create or attach), execute, interrupt, restart, stop, list. The MCP and CLI frontends are thin faces over `Client`; nothing here creates or kills a kernel except when asked, and the one scoped kill is opt-in: a kernel created with `auto=True` belongs to its client, ended by that client's next `connect` or by the frontend on the way out.
4
4
 
5
5
  Docs: https://AnswerDotAI.github.io/clikernel/core.html.md"""
6
6
 
7
7
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
8
8
 
9
9
  # %% auto #0
10
- __all__ = ['DEFAULT_URL', 'MAXLEN', 'STATE_LOST', 'cfg_dir', 'gateways', 'resolve', 'Client']
10
+ __all__ = ['DEFAULT_URL', 'MAXLEN', 'STATE_LOST', 'STATE_LOST_SETUP', 'cfg_dir', 'gateways', 'resolve', 'Client']
11
11
 
12
12
  # %% ../nbs/00_core.ipynb #2b3b7f4a
13
13
  import os, tomllib
@@ -25,17 +25,17 @@ def cfg_dir():
25
25
  return xdg_config_home()/'clikernel'
26
26
 
27
27
  def gateways(cfgdir=None):
28
- "Named gateways from `gateways.toml`: `{name: {url, token | token_env}}`"
28
+ "Named gateways from `gateways.toml`: `{name: {url, token | token_env, verify}}`"
29
29
  p = (Path(cfgdir) if cfgdir else cfg_dir())/'gateways.toml'
30
30
  return tomllib.loads(p.read_text()).get('gateways', {}) if p.exists() else {}
31
31
 
32
32
  def resolve(host='', cfgdir=None):
33
- "`(url, token)` for `host`: empty = the default local gateway, a URL = itself, else a `gateways.toml` name"
34
- if not host: return os.environ.get('CLIKERNEL_HOST', DEFAULT_URL), os.environ.get('CLIKERNEL_TOKEN')
35
- if '://' in host: return host, os.environ.get('CLIKERNEL_TOKEN')
33
+ "`(url, token, verify)` for `host`: empty = the default local gateway, a URL = itself, else a `gateways.toml` name"
34
+ if not host: return os.environ.get('CLIKERNEL_HOST', DEFAULT_URL), os.environ.get('CLIKERNEL_TOKEN'), True
35
+ if '://' in host: return host, os.environ.get('CLIKERNEL_TOKEN'), True
36
36
  g = gateways(cfgdir).get(host)
37
37
  if g is None: raise ValueError(f"unknown gateway {host!r}: not a URL, and not in {cfg_dir()/'gateways.toml'}")
38
- return g['url'], g.get('token') or os.environ.get(g.get('token_env','')) or None
38
+ return g['url'], g.get('token') or os.environ.get(g.get('token_env','')) or None, g.get('verify', True)
39
39
 
40
40
 
41
41
  # %% ../nbs/00_core.ipynb #0d846754
@@ -92,10 +92,11 @@ def _inspector_setup(src):
92
92
 
93
93
  # %% ../nbs/00_core.ipynb #33b7bc28
94
94
  STATE_LOST = 'NOTE: the kernel restarted with a fresh interpreter: all session state is lost (imports, variables, monkeypatches). Redo any setup the task still needs.'
95
+ STATE_LOST_SETUP = 'NOTE: the kernel restarted with a fresh interpreter: startup.py has been re-run (its imports are back), but all other session state is lost (variables, monkeypatches, other imports). Redo what the task still needs.'
95
96
 
96
97
  class Client:
97
98
  "One conversation's connection: a gateway manager, and the current kernel"
98
- def __init__(self, cfgdir=None): self.cfgdir,self.mgr,self.kc,self.kid,self.auto = cfgdir,None,None,None,False
99
+ def __init__(self, cfgdir=None): self.cfgdir,self.mgr,self.kc,self.kid,self.auto,self.made = cfgdir,None,None,None,False,False
99
100
 
100
101
  async def _use(self, mgr, kid):
101
102
  "Point at `kid` on `mgr`, dropping any previous ws (never the kernel)"
@@ -106,6 +107,20 @@ class Client:
106
107
  await self.kc.wait_for_ready(timeout=30)
107
108
 
108
109
  # %% ../nbs/00_core.ipynb #94497e4a
110
+ @patch
111
+ async def _setup(self:Client):
112
+ "Deliver `startup.py` and `inspectors.py` to the current kernel, returning startup's output"
113
+ out = ''
114
+ d = Path(self.cfgdir) if self.cfgdir else cfg_dir()
115
+ if (p := d/'startup.py').exists(): out = await self.execute(_startup_src(p.read_text(), p))
116
+ if (p := d/'inspectors.py').exists():
117
+ res = await self.execute(_inspector_setup(p.read_text()))
118
+ if res: # a load failure is fatal: refusing to run beats running uninspected
119
+ await self.mgr.shutdown_kernel(self.kid)
120
+ self.kc,self.kid,self.auto,self.made = None,None,False,False
121
+ raise RuntimeError(f'inspectors.py failed to load; kernel stopped:\n{res}')
122
+ return out
123
+
109
124
  @patch
110
125
  async def connect(self:Client, host='', kernel='', auto=False):
111
126
  "Connect to a gateway (create a kernel, or attach to `kernel` by id prefix); the pointer aims at it afterwards; `auto` marks a created kernel as client-scoped"
@@ -113,28 +128,22 @@ async def connect(self:Client, host='', kernel='', auto=False):
113
128
  if self.auto: # scoped to this client: any new connect ends it, even one already dead
114
129
  try: await self.stop()
115
130
  except Exception as e:
116
- self.kc,self.kid,self.auto = None,None,False
131
+ self.kc,self.kid,self.auto,self.made = None,None,False,False
117
132
  note = f'\nnote: stopping the auto kernel failed ({e})'
118
- url,tok = resolve(host, self.cfgdir)
119
- mgr = JupyAsyncMultiKernelManager(url, token=tok)
133
+ url,tok,ver = resolve(host, self.cfgdir)
134
+ mgr = JupyAsyncMultiKernelManager(url, token=tok, verify=ver)
120
135
  ks = await mgr.list_kernels() # verify reachability and auth now, loudly
121
136
  if kernel:
122
137
  kid = first(k['id'] for k in ks if k['id'].startswith(kernel))
123
138
  if not kid: raise ValueError(f'no kernel matching {kernel!r} on {url}: {[k["id"][:8] for k in ks]}')
124
139
  await self._use(mgr, kid)
140
+ self.made = False
125
141
  return f'connected to existing kernel {kid} on {url}' + note
126
142
  kw = dict(cwd=os.getcwd(), env=dict(os.environ)) if not host else {} # the default gateway is local by definition: kernels start where, and as, the conversation lives (cwd and environment - so kernel-side tools that key state to the conversation, like llmdojo's doc-state, resolve it correctly)
127
143
  kid = await mgr.start_kernel(**kw)
128
144
  await self._use(mgr, kid)
129
- out = ''
130
- d = Path(self.cfgdir) if self.cfgdir else cfg_dir()
131
- if (p := d/'startup.py').exists(): out = await self.execute(_startup_src(p.read_text(), p))
132
- if (p := d/'inspectors.py').exists():
133
- res = await self.execute(_inspector_setup(p.read_text()))
134
- if res: # a load failure is fatal: refusing to start beats running uninspected
135
- await self.mgr.shutdown_kernel(kid)
136
- self.kc,self.kid = None,None
137
- raise RuntimeError(f'inspectors.py failed to load; kernel stopped:\n{res}')
145
+ self.made = True
146
+ out = await self._setup()
138
147
  self.auto = auto
139
148
  return f'created kernel {kid} on {url}' + (f'\n{out}' if out.strip() else '') + note
140
149
 
@@ -156,8 +165,8 @@ async def execute(self:Client, code):
156
165
  async def list_kernels(self:Client, host=''):
157
166
  "One line per kernel on the gateway (the current one if `host` is empty and connected)"
158
167
  if host or self.mgr is None:
159
- url,tok = resolve(host, self.cfgdir)
160
- mgr = JupyAsyncMultiKernelManager(url, token=tok)
168
+ url,tok,ver = resolve(host, self.cfgdir)
169
+ mgr = JupyAsyncMultiKernelManager(url, token=tok, verify=ver)
161
170
  ks = await mgr.list_kernels()
162
171
  await mgr.aclose()
163
172
  else: ks = await self.mgr.list_kernels()
@@ -175,16 +184,18 @@ async def stop(self:Client, kernel=''):
175
184
  await self.mgr.shutdown_kernel(kid)
176
185
  if kid == self.kid:
177
186
  await self.kc.aclose()
178
- self.kc,self.kid,self.auto = None,None,False
187
+ self.kc,self.kid,self.auto,self.made = None,None,False,False
179
188
  return f'stopped kernel {kid}'
180
189
 
181
190
  @patch
182
191
  async def restart(self:Client):
183
- "Restart the current kernel: same id, fresh interpreter"
192
+ "Restart the current kernel: same id, fresh interpreter; a kernel this client created gets `startup.py` and `inspectors.py` again"
184
193
  if not self.kc: return 'no kernel: call `connect` first'
185
194
  await self.mgr.restart_kernel(self.kid)
186
195
  await self.kc.wait_for_ready(timeout=30)
187
- return STATE_LOST
196
+ if not self.made: return STATE_LOST
197
+ out = await self._setup()
198
+ return STATE_LOST_SETUP + (f'\n{out}' if out.strip() else '')
188
199
 
189
200
  @patch
190
201
  async def interrupt(self:Client):
@@ -33,7 +33,7 @@ def mk_server(c:Client):
33
33
  "An `MCPServer` whose tools close over `c`: connect, execute, and the lifecycle verbs"
34
34
  alock = asyncio.Lock()
35
35
  async def connect(
36
- host:str='', # Gateway: empty for the default local jupygate, a `gateways.toml` name, or a URL
36
+ host:str='', # Gateway: empty for the local default, a `gateways.toml` name, or a URL
37
37
  kernel:str='', # Kernel id (or unique prefix) to attach to; empty creates a fresh kernel
38
38
  )->str:
39
39
  "Connect to a kernel. With `kernel`: attach to that existing kernel exactly as it is (nothing is run) - this is how a later conversation returns to live state, and how to reach a kernel someone else created. Without: create a fresh kernel, run the user's startup.py in it, and install their inspectors; the reply includes the new kernel's id (reusable in a later `connect`) and the startup output. Kernels made or attached this way persist until explicitly stopped: disconnecting, switching, and conversation end never kill them. (Connecting also immediately stops the auto kernel, if `execute` had created one.)"
@@ -67,7 +67,7 @@ def mk_server(c:Client):
67
67
  return await c.stop(kernel)
68
68
 
69
69
  async def restart()->str:
70
- "Kill the current kernel's process and start a fresh one under the same id: `sys.modules` genuinely reset, all session state discarded. Use for a clean slate, after rebuilding a native extension, or after a reload left stale classes behind (symptoms: `isinstance` mysteriously failing, a class missing a method you know it has). Also works when `execute` is stuck. After restarting, redo any imports/setup the task still needs."
70
+ "Kill the current kernel's process and start a fresh one under the same id: `sys.modules` genuinely reset, all session state discarded. Use for a clean slate, after rebuilding a native extension, or after a reload left stale classes behind (symptoms: `isinstance` mysteriously failing, a class missing a method you know it has). Also works when `execute` is stuck. A kernel this conversation created gets startup.py re-run and inspectors reinstalled (the reply says so); an attached kernel restarts bare, as found."
71
71
  return await c.restart()
72
72
 
73
73
  async def interrupt()->str:
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Core idea
4
4
 
5
- clikernel connects this conversation to Jupyter kernels hosted by a jupygate server that runs all the time, independently of any conversation. State lasts the whole conversation -- imports, live objects, monkeypatches, cached results -- and a kernel you `connect` explicitly persists across conversations too. Treat it as a notebook-style workbench, not a one-shot script runner.
5
+ clikernel connects this conversation to Jupyter kernels hosted by a gateway server (rustygate) that runs all the time, independently of any conversation. State lasts the whole conversation -- imports, live objects, monkeypatches, cached results -- and a kernel you `connect` explicitly persists across conversations too. Treat it as a notebook-style workbench, not a one-shot script runner.
6
6
 
7
7
  Prefer it over one-off Python scripts (`python -c`, shell heredocs) whenever you need to inspect runtime behavior, test an idea, call a Python API, examine package state, run a live probe, or iterate on an implementation detail. Prefer in-kernel tools over shell equivalents when they exist: file search and directory listing go through the `rgapi` pyskill (`rg()`/`fd()`/`ls()`), and GitHub and local git work through the `ghapi` pyskill, when those are installed. Shell commands remain the right tool for project test/build commands and non-Python tools. Run them through the harness's shell tool, never `subprocess`/`os.system` from the kernel, which would bypass the harness's permission hooks.
8
8
 
@@ -14,9 +14,9 @@ The lifecycle has one implicit convenience and no implicit destruction beyond it
14
14
  - Returning to earlier work (the user asks to continue where a previous conversation left off, or to use their solveit kernel): `list_kernels` to see what's running, then `connect` with the kernel id (or unique prefix). Attach runs nothing -- the kernel's live state is the point.
15
15
  - End of work: an auto kernel stops itself with the conversation. `stop_kernel` an explicitly created kernel when it was for this task only; leave it running if the user wants to return to it, and tell the user its id so they can.
16
16
 
17
- `restart` gives the current kernel a genuinely fresh interpreter under the same id (redo imports after it); `interrupt` stops a too-long `execute` while keeping state. If a reply says the kernel died, `connect` again. If `connect` fails because the gateway is unreachable, the jupygate server is not running -- report that to the user rather than working around it.
17
+ `restart` gives the current kernel a genuinely fresh interpreter under the same id (a kernel this conversation created gets `startup.py` and inspectors again; redo any other setup); `interrupt` stops a too-long `execute` while keeping state. If a reply says the kernel died, `connect` again. If `connect` fails because the gateway is unreachable, the gateway server is not running -- report that to the user rather than working around it.
18
18
 
19
- Remote gateways (a jupygate or solveit instance elsewhere) are the same verbs with a `host`: a name from `~/.config/clikernel/gateways.toml` (`[gateways.<name>]` tables with `url` and `token` or `token_env`) or a URL. Tokens live in the config file, never in tool arguments.
19
+ Remote gateways (a rustygate or solveit instance elsewhere) are the same verbs with a `host`: a name from `~/.config/clikernel/gateways.toml` (`[gateways.<name>]` tables with `url`, `token` or `token_env`, and optional `verify = false` for self-signed TLS) or a URL. Tokens live in the config file, never in tool arguments.
20
20
 
21
21
  # Notebook magics
22
22
 
@@ -7,7 +7,7 @@ line in (`{"op":"exec","id":n,"code":...}`, `{"op":"complete","id":n,"code":...,
7
7
  (stream/display_data/execute_result/error) arrive as `out` events with the
8
8
  nbformat dict intact (mime bundles included), then a `done` event. Interrupt is
9
9
  not on the wire: the supervisor sends SIGINT to the worker process, which the
10
- worker maps to a kernel interrupt. The worker connects to jupygate (URL as
10
+ worker maps to a kernel interrupt. The worker connects to a gateway (URL as
11
11
  argv[0], default local; a kernel id as argv[1] attaches instead of creating),
12
12
  so the compact protocol exercises the full real stack -- which is its point:
13
13
  a self-contained test client, and a reminder to keep the layers flexible.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clikernel
3
- Version: 0.2.3
3
+ Version: 0.2.5
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: Apache-2.0
@@ -18,7 +18,7 @@ Requires-Dist: aidialog>=0.0.7
18
18
  Requires-Dist: pillow
19
19
  Provides-Extra: dev
20
20
  Requires-Dist: fastship; extra == "dev"
21
- Requires-Dist: jupygate>=0.0.1; extra == "dev"
21
+ Requires-Dist: rustygate>=0.1.1; extra == "dev"
22
22
  Dynamic: license-file
23
23
 
24
24
  # clikernel
@@ -26,7 +26,7 @@ Dynamic: license-file
26
26
 
27
27
  <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
28
28
 
29
- `clikernel` gives an LLM agent a persistent Python workbench built from two processes. A [jupygate](https://github.com/AnswerDotAI/jupygate) server runs all the time and hosts real Jupyter kernels ([ipymini](https://github.com/AnswerDotAI/ipymini) by default); kernels live there and persist until explicitly stopped. `clikernel` itself starts and stops with each conversation: a small translator the MCP host launches, speaking MCP to the model and the Jupyter kernels API to the gateway. Outputs come back as concise text — a bare `42` for a single result, tagged sections for several, tracebacks ANSI-stripped and capped.
29
+ `clikernel` gives an LLM agent a persistent Python workbench built from two processes. A gateway ([rustygate](https://github.com/AnswerDotAI/rustygate)) runs all the time and hosts real Jupyter kernels ([ipymini](https://github.com/AnswerDotAI/ipymini) by default); kernels live there and persist until explicitly stopped. `clikernel` itself starts and stops with each conversation: a small translator the MCP host launches, speaking MCP to the model and the Jupyter kernels API to the gateway. Outputs come back as concise text — a bare `42` for a single result, tagged sections for several, tracebacks ANSI-stripped and capped.
30
30
 
31
31
  Because kernels outlive conversations, an agent can `connect` back to yesterday’s kernel (or the user’s live solveit kernel) and find its state intact. Kernels created or attached explicitly are never stopped implicitly: only `stop_kernel` ends them. The one exception is the auto kernel: an `execute` with nothing connected creates a kernel scoped to the conversation, stopped again when the conversation ends or the agent connects elsewhere. Creating a kernel runs the user’s `startup.py` and installs their `inspectors.py` cell-checking rules, delivered as source so remote kernels get the same setup as local ones.
32
32
 
@@ -36,10 +36,10 @@ Because kernels outlive conversations, an agent can `connect` back to yesterday
36
36
  pip install clikernel
37
37
  ```
38
38
 
39
- Plus the resident side: [jupygate](https://github.com/AnswerDotAI/jupygate) and a kernel ([ipymini](https://github.com/AnswerDotAI/ipymini) by default). Start the gateway (and keep it running, e.g. via launchd/systemd):
39
+ Plus the resident side: [rustygate](https://github.com/AnswerDotAI/rustygate) and a kernel ([ipymini](https://github.com/AnswerDotAI/ipymini) by default). Start the gateway (and keep it running, e.g. via launchd/systemd):
40
40
 
41
41
  ``` sh
42
- jupygate --port 8787
42
+ rustygate --port 8787
43
43
  ```
44
44
 
45
45
  ## Use with an MCP host
@@ -50,7 +50,7 @@ Register the stdio server with your MCP host, e.g. for Claude Code:
50
50
  claude mcp add clikernel -- clikernel-mcp
51
51
  ```
52
52
 
53
- The tools mirror jupygate’s kernel API plus one composite: `connect` (create a fresh kernel — running `startup.py` and installing inspectors — or attach to an existing one by id), `execute` (run code, get concise text), `list_kernels`, `stop_kernel`, `restart`, and `interrupt`. An `execute` with no kernel connected auto-creates one, scoped to the conversation: it stops at conversation end, or when `connect` moves elsewhere. Kernels made or attached with an explicit `connect` are stopped only by `stop_kernel` — a later conversation reattaches by id and continues where the last one stopped. `$CLIKERNEL_HOST` overrides the default gateway (`http://127.0.0.1:8787`).
53
+ The tools mirror the gateway’s kernel API plus one composite: `connect` (create a fresh kernel — running `startup.py` and installing inspectors — or attach to an existing one by id), `execute` (run code, get concise text), `list_kernels`, `stop_kernel`, `restart`, and `interrupt`. An `execute` with no kernel connected auto-creates one, scoped to the conversation: it stops at conversation end, or when `connect` moves elsewhere. Kernels made or attached with an explicit `connect` are stopped only by `stop_kernel` — a later conversation reattaches by id and continues where the last one stopped. `$CLIKERNEL_HOST` overrides the default gateway (`http://127.0.0.1:8787`).
54
54
 
55
55
  ## Configuration
56
56
 
@@ -64,6 +64,7 @@ Three optional files in `$XDG_CONFIG_HOME/clikernel/` (usually `~/.config/cliker
64
64
  [gateways.solveit]
65
65
  url = "https://solveit.example.com/gate"
66
66
  token_env = "SOLVEIT_TOKEN"
67
+ verify = false # optional: accept a self-signed certificate
67
68
  ```
68
69
 
69
70
  ## The stream protocol
@@ -6,4 +6,4 @@ pillow
6
6
 
7
7
  [dev]
8
8
  fastship
9
- jupygate>=0.0.1
9
+ rustygate>=0.1.1
@@ -26,7 +26,7 @@ dependencies = [
26
26
  [project.optional-dependencies]
27
27
  dev = [
28
28
  "fastship",
29
- "jupygate>=0.0.1",
29
+ "rustygate>=0.1.1",
30
30
  ]
31
31
 
32
32
 
@@ -1,14 +1,14 @@
1
- "The stream protocol round trip: a real worker subprocess against an in-thread jupygate."
1
+ "The stream protocol round trip: a real worker subprocess against a spawned rustygate."
2
2
  import select, sys, time
3
3
  import pytest
4
4
 
5
5
 
6
6
  @pytest.fixture(scope="module")
7
7
  def gateway():
8
- from jupygate.core import create_app, serve
9
- server = serve(create_app(), port=0, in_thread=True)
10
- yield server.url
11
- server.should_exit = True
8
+ from rustygate.tools import start_gateway
9
+ g = start_gateway()
10
+ yield g.url
11
+ g.stop()
12
12
 
13
13
 
14
14
  def _drain_until(w, pred, timeout=30):
File without changes
File without changes
File without changes