@allansantos-dev/smart-tool 0.9.17 → 0.9.18

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.18 - beta
4
+
5
+ - Updates are no longer applied only at logon. The tray checks npm at start and every 24 h and installs a newer
6
+ version as soon as it sees it (on by default); a version that failed to install is tried again 24 h later instead of
7
+ never. `SMART_TOOL_AUTO_UPDATE=off` turns automatic updates off, like the tray switch.
8
+ - Nothing about updates is hidden. The tray notifies when a newer version is available, when it starts updating, when
9
+ Smart Tool was updated (from which version to which) and when an update failed. Agent sessions get the same line once
10
+ on their first `smart_search`, with the link to the changes, and the SessionStart report (when on) shows it to you
11
+ at session start.
12
+
3
13
  ## 0.9.17 - beta
4
14
 
5
15
  - The agent learns the setup audit result without asking for it. On its first `smart_search` of a session, once per
package/README.md CHANGED
@@ -15,7 +15,7 @@ registered as the `playwright` server where this machine lets a browser be drive
15
15
  An optional hook routes the agent's native Grep/Glob/Read/Bash/WebSearch/WebFetch calls to these tools when they
16
16
  are cheaper, or just tells the agent what Smart Tool would do.
17
17
 
18
- **Status:** 0.9.17 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
18
+ **Status:** 0.9.18 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
19
19
 
20
20
  ## How it works
21
21
 
@@ -76,9 +76,13 @@ gateway such as Ollama, nothing about your code leaves the machine.
76
76
  npx @allansantos-dev/smart-tool@latest install
77
77
  ```
78
78
 
79
- Updates install themselves: when the tray starts (at logon) and npm has a newer version, it runs this same command in
80
- a visible console, once per version; the tray menu has "Update to X" (or "Check for updates") on demand and an
81
- "Update automatically" switch. Running the command by hand also updates; `~/.smart-tool` is kept. It downloads [uv](https://docs.astral.sh/uv/) (checksum
79
+ Updates install themselves, on by default: the tray checks npm when it starts (at logon) and every 24 h, and when there
80
+ is a newer version it runs this same command in a visible console (once per version; a failed version is tried again
81
+ after 24 h, with the previous version kept). You are told each time: a Windows notification from the tray (newer version,
82
+ updating, updated, update failed), and agent sessions get the same line on their first `smart_search` (and at session
83
+ start when the SessionStart report is on, shown to you too) with the link to the changes. The tray menu has "Update to
84
+ X" (or "Check for updates") on demand and an "Update automatically" switch; `SMART_TOOL_AUTO_UPDATE=off` also turns
85
+ automatic updates off, and the newer-version notice then carries the command to run. Running the command by hand also updates; `~/.smart-tool` is kept. It downloads [uv](https://docs.astral.sh/uv/) (checksum
82
86
  verified) and a private Python 3.12 into `~/.smart-tool/runtime`, with nothing added to `PATH` or the registry, then
83
87
  copies Smart Tool to `%LOCALAPPDATA%\Programs\SmartTool` with its own virtual environment,
84
88
  installs the web runtime, registers a per-user Scheduled Task that starts the tray at logon and starts the daemon on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allansantos-dev/smart-tool",
3
- "version": "0.9.17",
3
+ "version": "0.9.18",
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",
@@ -68,6 +68,7 @@ import local_embedder
68
68
  import web_search_health
69
69
  import web_fetch
70
70
  import version
71
+ import update_check
71
72
  import gateway
72
73
  import hook_decision
73
74
  import endpoint_sync
@@ -1313,6 +1314,7 @@ def _pending_notices(session, client, project_root):
1313
1314
  pending = []
1314
1315
  if session["hook_notice"] and "hook" not in delivered:
1315
1316
  pending.append(("hook", session["hook_notice"]))
1317
+ pending += [(key, f"{text} Tell the user.") for key, text in _update_notices() if key not in delivered]
1316
1318
  key = "audit:" + setup_audit.index_key(project_root)
1317
1319
  if key not in delivered and not client_hooks.audit_hook_installed(client):
1318
1320
  text = setup_audit.session_notice(project_root)
@@ -1321,6 +1323,16 @@ def _pending_notices(session, client, project_root):
1321
1323
  return pending
1322
1324
 
1323
1325
 
1326
+ def _update_notices():
1327
+ """Update notices (updated, failed, newer version on npm); an unreadable state file is logged, not raised, so a
1328
+ search never fails over it."""
1329
+ try:
1330
+ return update_check.notices()
1331
+ except Exception as exc:
1332
+ _log(f"update notices unavailable: {type(exc).__name__}: {exc}")
1333
+ return []
1334
+
1335
+
1324
1336
  def _smart_search_arguments(arguments):
1325
1337
  if not isinstance(arguments, dict):
1326
1338
  raise ValueError("smart_search requires its arguments as a JSON object")
@@ -3388,17 +3400,23 @@ def _pretool_hook(handler):
3388
3400
 
3389
3401
  def _session_audit_hook(handler):
3390
3402
  """SessionStart output for the audit report hook: the stored audit notice of the session's folder as
3391
- additionalContext, or `{}` when nothing is stored or it holds no error or warning. Never runs an audit."""
3403
+ additionalContext, and the update notices both as systemMessage (shown to the user) and as context; `{}` when
3404
+ there is nothing to say. Never runs an audit."""
3392
3405
  try:
3393
3406
  payload = json.loads(handler._read_body(HOOK_MAX_BODY_BYTES) or b"{}")
3394
3407
  cwd = payload.get("cwd")
3395
3408
  text = setup_audit.session_notice(cwd) if isinstance(cwd, str) and os.path.isdir(cwd) else ""
3396
3409
  except Exception as exc:
3397
3410
  _log(f"SessionStart audit hook without a report: {type(exc).__name__}: {exc}")
3411
+ text = ""
3412
+ updates = " ".join(notice for _key, notice in _update_notices())
3413
+ context = " ".join(part for part in (updates, text) if part)
3414
+ if not context:
3398
3415
  return {}
3399
- if not text:
3400
- return {}
3401
- return {"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": text}}
3416
+ output = {"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": context}}
3417
+ if updates:
3418
+ output["systemMessage"] = updates
3419
+ return output
3402
3420
 
3403
3421
 
3404
3422
  _TOOL_HANDLERS = {
@@ -3823,6 +3841,10 @@ def main():
3823
3841
  server = _bind_server()
3824
3842
  _BOUND_PORT = server.server_address[1]
3825
3843
  threading.Thread(target=_probe_capabilities, daemon=True).start()
3844
+ try:
3845
+ update_check.note_running_version()
3846
+ except Exception as exc:
3847
+ _log(f"running version not recorded: {type(exc).__name__}: {exc}")
3826
3848
  _write_registry(_BOUND_PORT)
3827
3849
  atexit.register(_remove_registry)
3828
3850
  try:
package/tray.py CHANGED
@@ -111,24 +111,48 @@ def _poll_loop(icon):
111
111
  time.sleep(POLL_INTERVAL_S)
112
112
 
113
113
 
114
+ def _announce_start(icon):
115
+ """Tells the user, once per start, that Smart Tool was just updated or that the last automatic update failed."""
116
+ updated = update_check.note_running_version()
117
+ if updated:
118
+ icon.notify(f"Smart Tool updated from {updated['from']} to {updated['to']}.", "Smart Tool")
119
+ failed = update_check.failed_update()
120
+ if failed:
121
+ icon.notify(f"The update to {failed} failed; Smart Tool {version.VERSION} is still installed. "
122
+ "It is tried again in 24 h, or now from this menu.", "Smart Tool")
123
+
124
+
114
125
  def _update_loop(icon):
115
- """Checks npm at start and every 24 h. At start (logon, before agent sessions use the daemon) a newer version is
116
- installed right away when auto_update is on; later checks only notify and offer it in the menu."""
117
- first = True
126
+ """Checks npm at start and every 24 h. A newer version is installed right away when automatic updates are on (once
127
+ per version, again 24 h after a failed try); otherwise the user is told and the menu offers it."""
128
+ try:
129
+ _announce_start(icon)
130
+ except Exception as exc:
131
+ icon.notify(f"Could not read the update state: {exc}", "Smart Tool")
118
132
  while True:
119
133
  try:
120
134
  latest = update_check.newer_version()
121
135
  except Exception:
122
136
  latest = None
123
- if latest and latest != _state["update"]:
137
+ else:
138
+ try:
139
+ update_check.record_check(latest)
140
+ except Exception as exc:
141
+ icon.notify(f"Could not save the update check: {exc}", "Smart Tool")
142
+ if latest:
143
+ known = latest == _state["update"]
124
144
  _state["update"] = latest
125
145
  icon.update_menu()
126
- if first and config.auto_update() and update_check.should_auto_update(latest):
127
- icon.notify(f"Updating Smart Tool to {latest}...", "Smart Tool")
146
+ try:
147
+ automatic = update_check.automatic_enabled() and update_check.should_auto_update(latest)
148
+ except Exception as exc:
149
+ automatic = False
150
+ icon.notify(f"Automatic update skipped: {exc}", "Smart Tool")
151
+ if automatic:
152
+ icon.notify(f"Updating Smart Tool from {version.VERSION} to {latest}...", "Smart Tool")
128
153
  update_check.run_update(latest, automatic=True)
129
- else:
154
+ elif not known:
130
155
  icon.notify(f"Smart Tool {latest} is available: use \"Update to {latest}\" in this menu.", "Smart Tool")
131
- first = False
132
156
  time.sleep(UPDATE_CHECK_INTERVAL_S)
133
157
 
134
158
 
@@ -162,12 +186,16 @@ def _update_now(icon, item):
162
186
 
163
187
  def _auto_update_checked(item):
164
188
  try:
165
- return config.auto_update()
189
+ return update_check.automatic_enabled()
166
190
  except Exception:
167
191
  return False
168
192
 
169
193
 
170
194
  def _toggle_auto_update(icon, item):
195
+ if update_check.env_opted_out():
196
+ icon.notify(f"{update_check.ENV_OPT_OUT}=off is set: automatic updates stay off until it is removed.",
197
+ "Smart Tool")
198
+ return
171
199
  try:
172
200
  config.update_config(lambda cfg: cfg.__setitem__("auto_update", not config.auto_update(cfg)))
173
201
  except Exception as exc:
package/update_check.py CHANGED
@@ -1,5 +1,10 @@
1
- """Newer Smart Tool release on npm and the update itself: the tray runs the same install command a user would, in a
2
- visible console, at startup (once per version, when auto_update is on) or on demand from its menu."""
1
+ """Newer Smart Tool release on npm and the update itself: the tray checks npm at start and every 24 h and, when
2
+ automatic updates are on (the default), runs the same install command a user would, in a visible console. A failed
3
+ version is tried again after 24 h. What happened (newer version available, updated, update failed) is told to the
4
+ user by the tray and to agent sessions by the daemon, from the state file, without contacting npm again.
5
+
6
+ Automatic updates are turned off by the tray switch (config `auto_update`) or by SMART_TOOL_AUTO_UPDATE=off; the
7
+ newer-version notice still shows then, with the command to update by hand."""
3
8
  import json
4
9
  import os
5
10
  import subprocess
@@ -7,13 +12,18 @@ import time
7
12
  import urllib.request
8
13
 
9
14
  import atomic_io
15
+ import config
10
16
  import paths
11
17
  import version
12
18
 
13
19
  PACKAGE = "@allansantos-dev/smart-tool"
14
20
  REGISTRY_URL = "https://registry.npmjs.org/@allansantos-dev%2Fsmart-tool/latest"
15
21
  UPDATE_COMMAND = f"npx --yes {PACKAGE}@latest install"
22
+ CHANGELOG_URL = "https://github.com/AllanSantos-DV/smart-tool-dist/blob/main/CHANGELOG.md"
16
23
  STATE_PATH = os.path.join(paths.DATA_DIR, "update-state.json")
24
+ ENV_OPT_OUT = "SMART_TOOL_AUTO_UPDATE"
25
+ RETRY_AFTER_S = 24 * 3600
26
+ UPDATED_NOTICE_S = 24 * 3600
17
27
 
18
28
 
19
29
  def _parts(value):
@@ -29,27 +39,108 @@ def newer_version(timeout=10):
29
39
  return latest if _parts(latest) > _parts(version.VERSION) else None
30
40
 
31
41
 
32
- def attempted():
33
- """Version the last automatic update went for, or None."""
42
+ def env_opted_out():
43
+ """SMART_TOOL_AUTO_UPDATE set to off, 0, false or no."""
44
+ return os.environ.get(ENV_OPT_OUT, "").strip().lower() in ("off", "0", "false", "no")
45
+
46
+
47
+ def automatic_enabled(cfg=None):
48
+ """Automatic updates are on: the tray switch (config `auto_update`, on by default) and no environment opt-out."""
49
+ return not env_opted_out() and config.auto_update(cfg)
50
+
51
+
52
+ def _state():
34
53
  try:
35
54
  with open(STATE_PATH, encoding="utf-8") as stream:
36
- return json.load(stream).get("attempted")
55
+ return json.load(stream)
37
56
  except FileNotFoundError:
57
+ return {}
58
+
59
+
60
+ def _save(state):
61
+ os.makedirs(os.path.dirname(STATE_PATH), exist_ok=True)
62
+ atomic_io.write_secret_text(STATE_PATH, json.dumps(state))
63
+
64
+
65
+ def attempted():
66
+ """Version the last automatic update went for, or None."""
67
+ return _state().get("attempted")
68
+
69
+
70
+ def should_auto_update(latest, now=None):
71
+ """An automatic update runs once per version and again 24 h after a failed try: when it fails, the installer
72
+ restores the previous version and restarts the tray, which would otherwise try the same version on every start."""
73
+ if not latest:
74
+ return False
75
+ state = _state()
76
+ if state.get("attempted") != latest:
77
+ return True
78
+ return (now or time.time()) - state.get("at", 0) >= RETRY_AFTER_S
79
+
80
+
81
+ def record_check(latest):
82
+ """Stores the result of an npm check (the newer version, or None) for the notices read without network."""
83
+ state = _state()
84
+ state.update(latest=latest, checked_at=time.time())
85
+ _save(state)
86
+
87
+
88
+ def note_running_version(now=None):
89
+ """Called when the tray and the daemon start: a version different from the one that ran last is recorded as an
90
+ update (from, to, at) for the updated notice; the very first run records nothing. Returns the update record when
91
+ this call found it, else None."""
92
+ state = _state()
93
+ running = state.get("running")
94
+ if running == version.VERSION:
38
95
  return None
96
+ state["running"] = version.VERSION
97
+ found = None
98
+ if running:
99
+ found = state["updated"] = {"from": running, "to": version.VERSION, "at": now or time.time()}
100
+ _save(state)
101
+ return found
102
+
103
+
104
+ def failed_update():
105
+ """The version an automatic update went for and did not install (the previous version is still running), else
106
+ None."""
107
+ target = _state().get("attempted")
108
+ return target if target and _parts(target) > _parts(version.VERSION) else None
39
109
 
40
110
 
41
- def should_auto_update(latest):
42
- """An automatic update runs once per version: when it fails, the installer restores the previous version and
43
- restarts the tray, which would otherwise try the same version again on every start."""
44
- return bool(latest) and attempted() != latest
111
+ def notices(now=None):
112
+ """[(key, text)] about updates, for the user and the agent: Smart Tool updated in the last 24 h, the last
113
+ automatic update failed, or a newer version is on npm. Reads only the state file."""
114
+ now = now or time.time()
115
+ state = _state()
116
+ found = []
117
+ updated = state.get("updated") or {}
118
+ if updated.get("to") == version.VERSION and now - updated.get("at", 0) < UPDATED_NOTICE_S:
119
+ found.append((f"updated:{version.VERSION}",
120
+ f"Smart Tool was updated from {updated['from']} to {version.VERSION}. Changes: {CHANGELOG_URL}"))
121
+ failed = failed_update()
122
+ latest = state.get("latest")
123
+ if failed:
124
+ retry = ("the tray tries again 24 h after the failed try" if automatic_enabled()
125
+ else "automatic updates are now off")
126
+ found.append((f"failed:{failed}",
127
+ f"The automatic update of Smart Tool to {failed} failed; {version.VERSION} is still installed "
128
+ f"and {retry}. To update now, run: {UPDATE_COMMAND}"))
129
+ elif latest and _parts(latest) > _parts(version.VERSION):
130
+ how = ("the tray installs it automatically" if automatic_enabled()
131
+ else f"automatic updates are off (tray switch or {ENV_OPT_OUT}=off); to update, run: {UPDATE_COMMAND}")
132
+ found.append((f"available:{latest}",
133
+ f"Smart Tool {latest} is available on npm (installed: {version.VERSION}); {how}."))
134
+ return found
45
135
 
46
136
 
47
137
  def run_update(latest, automatic):
48
138
  """Starts the install command in its own visible console, detached from the tray (the installer stops and restarts
49
139
  the tray). The console closes on success and stays open with the error on failure."""
50
140
  if automatic:
51
- os.makedirs(os.path.dirname(STATE_PATH), exist_ok=True)
52
- atomic_io.write_secret_text(STATE_PATH, json.dumps({"attempted": latest, "at": time.time()}))
141
+ state = _state()
142
+ state.update(attempted=latest, at=time.time())
143
+ _save(state)
53
144
  flags = getattr(subprocess, "CREATE_NEW_CONSOLE", 0) | getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
54
145
  command = f'title Smart Tool update to {latest} && {UPDATE_COMMAND} || pause'
55
146
  subprocess.Popen(["cmd.exe", "/c", command], creationflags=flags, close_fds=True,
package/version.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Single source of the Smart Tool version and of the User-Agent sent to public APIs."""
2
2
  import re
3
3
 
4
- VERSION = "0.9.17"
4
+ VERSION = "0.9.18"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7