@allansantos-dev/smart-tool 0.9.65 → 0.9.66
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/CHANGELOG.md +14 -0
- package/README.md +6 -4
- package/daemon_launcher.py +4 -4
- package/endpoint_sync.py +4 -2
- package/install.py +2 -2
- package/package.json +1 -1
- package/smart_tool_daemon.py +23 -9
- package/version.py +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.66 - beta
|
|
4
|
+
|
|
5
|
+
- A daemon that starts while its port is busy retries that port for a few seconds, re-checking `/health`, before it
|
|
6
|
+
moves to the next candidate. A restart that overlapped the shutdown of the old daemon, two starts at once or a
|
|
7
|
+
loaded machine used to move the daemon to another port and rewrite the client files, leaving open Claude Code
|
|
8
|
+
sessions calling the old hook address (`smart_tool_daemon.py`, `tests/test_endpoint_sync.py`). The port preferred
|
|
9
|
+
at start also reads the Codex MCP address when Claude Code holds none (`endpoint_sync.py`).
|
|
10
|
+
- `daemon.json` is written whole (temporary file and replace) and a daemon removes it at exit only when its `pid` is
|
|
11
|
+
the one recorded, so an old daemon closing late no longer erases the announcement of the new one.
|
|
12
|
+
- The launcher and the installer take a daemon as up only when `/health` answers `status: ok`, not on any HTTP 200
|
|
13
|
+
from another program that now holds a stale port (`daemon_launcher.py`, `install.py`). The launcher waits up to
|
|
14
|
+
20 s for a start, enough for the port retry.
|
|
15
|
+
- README: the setup address and the port rule describe `daemon.json`.
|
|
16
|
+
|
|
3
17
|
## 0.9.65 - beta
|
|
4
18
|
|
|
5
19
|
- An entry paragraph of `functional.md` and `simple.md` records the code it was written for (`code="..."` in its
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ registered as the `playwright` server where this machine lets a browser be drive
|
|
|
17
17
|
An optional hook routes the agent's native Grep/Glob/Read/Bash/WebSearch/WebFetch calls to these tools when they
|
|
18
18
|
are cheaper, or just tells the agent what Smart Tool would do.
|
|
19
19
|
|
|
20
|
-
**Status:** 0.9.
|
|
20
|
+
**Status:** 0.9.66 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
|
|
21
21
|
|
|
22
22
|
## How it works
|
|
23
23
|
|
|
@@ -83,7 +83,7 @@ gateway such as Ollama, nothing about your code leaves the machine.
|
|
|
83
83
|
## Install
|
|
84
84
|
|
|
85
85
|
```powershell
|
|
86
|
-
npx @allansantos-dev/smart-tool@0.9.
|
|
86
|
+
npx @allansantos-dev/smart-tool@0.9.66 install
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Updates install themselves, on by default: the tray checks npm when it starts (at logon) and every 24 h, and when there
|
|
@@ -105,7 +105,9 @@ version came out minutes ago); `~/.smart-tool` is kept. It downloads [uv](https:
|
|
|
105
105
|
verified) and a private Python 3.12 into `~/.smart-tool/runtime`, with nothing added to `PATH` and, in the registry, only two per-user (HKCU) keys that make the notification buttons work, then
|
|
106
106
|
copies Smart Tool to `%LOCALAPPDATA%\Programs\SmartTool` with its own virtual environment,
|
|
107
107
|
installs the web runtime, registers a per-user Scheduled Task that starts the tray at logon and starts the daemon on
|
|
108
|
-
`http://127.0.0.1:8765
|
|
108
|
+
`http://127.0.0.1:8765`. A busy port is retried for a few seconds (the old daemon may still be closing) and the port
|
|
109
|
+
the clients already hold is kept; another free port is used, and announced in `~/.smart-tool/data/daemon.json`, only
|
|
110
|
+
when a program keeps the port.
|
|
109
111
|
|
|
110
112
|
State lives in `~/.smart-tool`: `config.json`, your model adapters in `adapters/` and indexes, caches and logs in
|
|
111
113
|
`data/`. Secrets (API keys) are encrypted with Windows DPAPI for your user.
|
|
@@ -123,7 +125,7 @@ are left out of the request and the code that reads the answer keeps enforcing t
|
|
|
123
125
|
|
|
124
126
|
## Set up
|
|
125
127
|
|
|
126
|
-
Open the setup screen from the tray icon ("Open settings") or at `http://127.0.0.1:8765/setup
|
|
128
|
+
Open the setup screen from the tray icon ("Open settings") or at `/setup` on the daemon address in `~/.smart-tool/data/daemon.json` (`http://127.0.0.1:8765/setup` by default). It opens on
|
|
127
129
|
**Overview**: everything Smart Tool needs, checked on this machine, with what needs you first and a button that takes
|
|
128
130
|
you to the fix. The side menu groups the rest under Connect (Agents, Models, Web search), Behavior (Agent rules,
|
|
129
131
|
Redirects) and Maintenance (Setup audit, Startup).
|
package/daemon_launcher.py
CHANGED
|
@@ -5,7 +5,7 @@ caído neste ambiente por isso mesmo), este cliente sobe o processo sozinho se e
|
|
|
5
5
|
fora do ar, protegido por lockfile contra corrida entre sessões simultâneas.
|
|
6
6
|
|
|
7
7
|
Contrato de registry (mesmo formato usado pelo probe de grafo em `capabilities.py`):
|
|
8
|
-
`~/.smart-tool/data/daemon.json` = `{"url": "http://127.0.0.1:<porta>"}` —
|
|
8
|
+
`~/.smart-tool/data/daemon.json` = `{"url": "http://127.0.0.1:<porta>", "pid": <pid>, "port": <porta>}` —
|
|
9
9
|
`url` é a base do daemon; o endpoint MCP em si é `<url>/mcp`.
|
|
10
10
|
"""
|
|
11
11
|
import json
|
|
@@ -47,8 +47,8 @@ def health(url, timeout=1):
|
|
|
47
47
|
toda tool call do agente paga antes de seguir."""
|
|
48
48
|
try:
|
|
49
49
|
with urllib.request.urlopen(url.rstrip("/") + "/health", timeout=timeout) as resp:
|
|
50
|
-
return resp.status == 200
|
|
51
|
-
except (urllib.error.URLError, OSError, ValueError):
|
|
50
|
+
return resp.status == 200 and json.loads(resp.read()).get("status") == "ok"
|
|
51
|
+
except (urllib.error.URLError, OSError, ValueError, AttributeError):
|
|
52
52
|
return False
|
|
53
53
|
|
|
54
54
|
|
|
@@ -117,7 +117,7 @@ def updating():
|
|
|
117
117
|
return False
|
|
118
118
|
|
|
119
119
|
|
|
120
|
-
def ensure_daemon_running(wait_seconds=
|
|
120
|
+
def ensure_daemon_running(wait_seconds=20):
|
|
121
121
|
"""Retorna a URL base do daemon (sem `/mcp`), subindo o processo se necessário."""
|
|
122
122
|
info = read_registry()
|
|
123
123
|
if info and health(info["url"]):
|
package/endpoint_sync.py
CHANGED
|
@@ -250,9 +250,11 @@ def run_cli(command):
|
|
|
250
250
|
|
|
251
251
|
|
|
252
252
|
def known_port():
|
|
253
|
-
"""Port the Claude Code MCP entry already points to, so a fallback bind can reuse it without
|
|
253
|
+
"""Port the Claude Code MCP entry (else the Codex one) already points to, so a fallback bind can reuse it without
|
|
254
|
+
any rewrite."""
|
|
255
|
+
held = registrations()
|
|
254
256
|
try:
|
|
255
|
-
parsed = urllib.parse.urlsplit(
|
|
257
|
+
parsed = urllib.parse.urlsplit(held["claude"] or held["codex"] or "")
|
|
256
258
|
return parsed.port if parsed.hostname == "127.0.0.1" else None
|
|
257
259
|
except ValueError:
|
|
258
260
|
return None
|
package/install.py
CHANGED
|
@@ -129,8 +129,8 @@ def _daemon_up():
|
|
|
129
129
|
try:
|
|
130
130
|
url = json.loads(REGISTRY.read_text(encoding="utf-8"))["url"]
|
|
131
131
|
with _OPENER.open(url + "/health", timeout=1) as response:
|
|
132
|
-
return response.status == 200
|
|
133
|
-
except (OSError, ValueError, KeyError):
|
|
132
|
+
return response.status == 200 and json.loads(response.read()).get("status") == "ok"
|
|
133
|
+
except (OSError, ValueError, KeyError, AttributeError):
|
|
134
134
|
return False
|
|
135
135
|
|
|
136
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allansantos-dev/smart-tool",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.66",
|
|
4
4
|
"description": "Local MCP server that gives coding agents (Claude Code, Codex) cheaper, sharper tools than their built-in search. Windows.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Allan Santos",
|
package/smart_tool_daemon.py
CHANGED
|
@@ -35,6 +35,7 @@ import uuid
|
|
|
35
35
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
36
36
|
|
|
37
37
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
38
|
+
import atomic_io
|
|
38
39
|
import browser_control
|
|
39
40
|
import capabilities
|
|
40
41
|
import client_hooks
|
|
@@ -93,6 +94,8 @@ MCP_MAX_REQUEST_BYTES = 10 * 1024 * 1024
|
|
|
93
94
|
MCP_STREAM_AFTER_S = 10
|
|
94
95
|
MCP_KEEPALIVE_S = 15
|
|
95
96
|
_BOUND_PORT = DEFAULT_PORT
|
|
97
|
+
BIND_WAIT_S = 8
|
|
98
|
+
BIND_RETRY_S = 0.25
|
|
96
99
|
|
|
97
100
|
DDG_SEARCH_SCRIPT = web_search_adapters.DDG_SEARCH_SCRIPT
|
|
98
101
|
CAMOUFOX_VENV_PYTHON = web_search_adapters.CAMOUFOX_VENV_PYTHON
|
|
@@ -4621,14 +4624,18 @@ class MCPHandler(BaseHTTPRequestHandler):
|
|
|
4621
4624
|
|
|
4622
4625
|
def _write_registry(port):
|
|
4623
4626
|
os.makedirs(RUN_DIR, exist_ok=True)
|
|
4624
|
-
|
|
4625
|
-
json.dump({"url": f"http://127.0.0.1:{port}", "pid": os.getpid(), "port": port}, f)
|
|
4627
|
+
atomic_io.write_text(REGISTRY_PATH, json.dumps({"url": f"http://127.0.0.1:{port}", "pid": os.getpid(), "port": port}))
|
|
4626
4628
|
|
|
4627
4629
|
|
|
4628
4630
|
def _remove_registry():
|
|
4631
|
+
"""Removes the announcement only when this process wrote it: an old daemon exiting after its successor announced
|
|
4632
|
+
itself must not erase the successor's entry."""
|
|
4629
4633
|
try:
|
|
4634
|
+
with open(REGISTRY_PATH, encoding="utf-8") as f:
|
|
4635
|
+
if json.load(f).get("pid") != os.getpid():
|
|
4636
|
+
return
|
|
4630
4637
|
os.remove(REGISTRY_PATH)
|
|
4631
|
-
except OSError:
|
|
4638
|
+
except (OSError, ValueError, AttributeError):
|
|
4632
4639
|
pass
|
|
4633
4640
|
|
|
4634
4641
|
|
|
@@ -4652,13 +4659,20 @@ def _bind_server():
|
|
|
4652
4659
|
"""The port clients already know, then the default port, then any free port (announced in daemon.json and synced
|
|
4653
4660
|
to the clients by endpoint_sync). A connected session keeps the URL it started with, so a restart that moved
|
|
4654
4661
|
back to the default would cut every session on the known port. A port held by another live Smart Tool stops this
|
|
4655
|
-
start instead of duplicating it.
|
|
4662
|
+
start instead of duplicating it. A busy port is retried for BIND_WAIT_S before the next candidate: the daemon it
|
|
4663
|
+
belonged to may still be shutting down in a restart, or too loaded to answer the health check, and moving on then
|
|
4664
|
+
strands every client that wrote the old port."""
|
|
4656
4665
|
for port in dict.fromkeys(p for p in (endpoint_sync.known_port(), DEFAULT_PORT, 0) if p is not None):
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4666
|
+
deadline = time.monotonic() + (BIND_WAIT_S if port else 0)
|
|
4667
|
+
while True:
|
|
4668
|
+
try:
|
|
4669
|
+
return _ExclusiveThreadingHTTPServer(("127.0.0.1", port), MCPHandler)
|
|
4670
|
+
except OSError:
|
|
4671
|
+
if port and _smart_tool_answers(port):
|
|
4672
|
+
raise SystemExit(f"Smart Tool is already running on port {port}.")
|
|
4673
|
+
if time.monotonic() >= deadline:
|
|
4674
|
+
break
|
|
4675
|
+
time.sleep(BIND_RETRY_S)
|
|
4662
4676
|
raise OSError("No local port available for the daemon.")
|
|
4663
4677
|
|
|
4664
4678
|
|
package/version.py
CHANGED