@allansantos-dev/smart-tool 0.9.47 → 0.9.49

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,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.49 - beta
4
+
5
+ - No more "Could not show a Smart Tool notice: [WinError 10061]" right after logon. The tray's notice loop asked the
6
+ daemon at once, using the address of the previous run from the registry, before the daemon was listening, and turned the
7
+ refused connection into a notification. Now a daemon that is not accepting connections yet (or no address yet) is asked
8
+ again every 15 s without showing anything; any other failure is written to `tray.log` in the data folder, once per
9
+ message, never shown as another notification. The same boot ordering applied to the update check: with no network yet
10
+ at logon it waited 24 h for the next try; it now retries every 5 min until npm answers (`tests/test_tray_notices.py`).
11
+
12
+ ## 0.9.48 - beta
13
+
14
+ - Smart Tool spawns far fewer Git processes. A Git view (`index_views.describe`, `pin`) is now resolved once per
15
+ repository and reused while the files that define it (HEAD, index, logs/HEAD, packed-refs, the branch ref) have not
16
+ moved: a stat of five files instead of three `git.exe` per call, also for `fresh` and `pin`. Concurrent callers of the
17
+ same repository share one resolution. A checkout or commit still changes the stamp, so it is detected and
18
+ `assert_current` still discards a result computed on another branch (`tests/test_view_sharing.py`).
19
+
3
20
  ## 0.9.47 - beta
4
21
 
5
22
  - The update window names the browser check ("Checking the browsers…") while the installer verifies Camoufox and
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.47 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
20
+ **Status:** 0.9.49 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
21
21
 
22
22
  ## How it works
23
23
 
package/index_views.py CHANGED
@@ -5,12 +5,15 @@ import hashlib
5
5
  import os
6
6
  import shutil
7
7
  import subprocess
8
+ import threading
8
9
  import time
9
10
 
10
11
  import project_identity
11
12
 
12
13
  _PINNED = contextvars.ContextVar('smart_index_view', default=None)
13
14
  _CACHE = {}
15
+ _LOCKS = {}
16
+ _LOCKS_GUARD = threading.Lock()
14
17
 
15
18
 
16
19
  class ViewChanged(RuntimeError):
@@ -54,15 +57,42 @@ def _stamp(view):
54
57
  return tuple(result)
55
58
 
56
59
 
60
+ def _lock_for(key):
61
+ with _LOCKS_GUARD:
62
+ return _LOCKS.setdefault(key, threading.Lock())
63
+
64
+
65
+ def _validated(key):
66
+ """The cached view of `key` while it is still the current one: a Git view until the files that define it move (a stat
67
+ of five files, no process), a folder without Git for one second."""
68
+ old = _CACHE.get(key)
69
+ if not old:
70
+ return None
71
+ if old[1].get('git'):
72
+ return None if stamp_changed(old[1]) else old[1]
73
+ return old[1] if time.monotonic()-old[0] < 1 else None
74
+
75
+
57
76
  def describe(root, fresh=False):
77
+ """Git view of `root`. `fresh` asks for a check, not for a new resolution: a cached Git view whose stamp (HEAD, index,
78
+ logs/HEAD, packed-refs, the ref file) did not move is still the current one and costs no git process. Concurrent
79
+ callers of the same root share one resolution: the others wait for the lock and find the view it cached."""
58
80
  root = project_identity.display_root(root)
59
81
  key = project_identity.canonical_root(root)
60
82
  pinned = _PINNED.get()
61
83
  if pinned and pinned['root'] == key and not fresh:
62
84
  return pinned
63
- old = _CACHE.get(key)
64
- if not fresh and old and time.monotonic()-old[0] < 1:
65
- return old[1]
85
+ cached = _validated(key)
86
+ if cached:
87
+ return cached
88
+ with _lock_for(key):
89
+ cached = _validated(key)
90
+ if cached:
91
+ return cached
92
+ return _resolve(root, key)
93
+
94
+
95
+ def _resolve(root, key):
66
96
  view = {'root': key, 'git': False, 'view_id': 'workspace', 'label': 'Folder without Git',
67
97
  'branch': None, 'commit': None}
68
98
  if _git_marker(root):
@@ -864,7 +864,6 @@
864
864
  "Could not open the projects: {error}": "Não foi possível abrir os projetos: {error}",
865
865
  "Could not select the folder: {error}": "Não foi possível selecionar a pasta: {error}",
866
866
  "Failed to change automatic start: {error}": "Não foi possível mudar a inicialização automática: {error}",
867
- "Could not show a Smart Tool notice: {error}": "Não foi possível mostrar um aviso do Smart Tool: {error}",
868
867
  "Could not save the update check: {error}": "Não foi possível salvar a verificação de atualização: {error}",
869
868
  "Automatic update skipped: {error}": "Atualização automática ignorada: {error}",
870
869
  "Smart Tool {version} is available: use \"Update to {version}\" in this menu.": "O Smart Tool {version} está disponível: use \"Atualizar para {version}\" neste menu.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allansantos-dev/smart-tool",
3
- "version": "0.9.47",
3
+ "version": "0.9.49",
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/tray.py CHANGED
@@ -12,6 +12,7 @@ import os
12
12
  import sys
13
13
  import threading
14
14
  import time
15
+ import urllib.error
15
16
  import urllib.request
16
17
  import webbrowser
17
18
 
@@ -23,6 +24,7 @@ import autostart
23
24
  import config
24
25
  import daemon_launcher
25
26
  import i18n
27
+ import paths
26
28
  import setup_audit
27
29
  import toast_notice
28
30
  import update_check
@@ -31,6 +33,10 @@ import version
31
33
  POLL_INTERVAL_S = 45
32
34
  UPDATE_CHECK_INTERVAL_S = 24 * 3600
33
35
  NOTICE_INTERVAL_S = 600
36
+ NOTICE_RETRY_S = 15
37
+ UPDATE_RETRY_S = 300
38
+ NOTICE_UNREACHABLE_LOG_S = 600
39
+ LOG_PATH = os.path.join(paths.DATA_DIR, "tray.log")
34
40
  SETUP_URL = "http://127.0.0.1:8765/setup"
35
41
 
36
42
  _STATE_LOCK = threading.Lock()
@@ -165,22 +171,55 @@ def _show_notices(icon, notices):
165
171
  tag="setup-audit:" + row["project"])
166
172
 
167
173
 
174
+ def _log(text):
175
+ """Appends a line to `tray.log` in the data folder: what the tray cannot tell with a notification (a notice that could
176
+ not be fetched or shown) is kept where the user can read it, never turned into another notification."""
177
+ try:
178
+ os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True)
179
+ with open(LOG_PATH, "a", encoding="utf-8") as log:
180
+ log.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} {text}\n")
181
+ except OSError:
182
+ pass # no console and no other channel here; a full disk must not kill the notice thread
183
+
184
+
185
+ def _daemon_not_ready(exc):
186
+ """The daemon is not accepting connections yet (refused, reset or no answer in time), as right after boot, when the
187
+ registry still holds the address of the previous run. An HTTP answer, even an error, is not that."""
188
+ if isinstance(exc, urllib.error.HTTPError):
189
+ return False
190
+ reason = exc.reason if isinstance(exc, urllib.error.URLError) else exc
191
+ return isinstance(reason, (ConnectionError, TimeoutError))
192
+
193
+
168
194
  def _notice_loop(icon):
169
195
  """Asks the daemon every 10 minutes whether a toast is due. The daemon decides (once a day per notice) and marks it
170
- announced, so a restart of the tray never repeats one."""
196
+ announced, so a restart of the tray never repeats one. While the daemon is still starting the question is asked again
197
+ every few seconds and nothing is shown: the tray icon already says "starting". Any other failure goes to `tray.log`."""
198
+ waiting_since = None
171
199
  while True:
200
+ delay = NOTICE_INTERVAL_S
172
201
  try:
173
202
  daemon_url = (daemon_launcher.read_registry() or {}).get("url")
174
203
  if daemon_url:
175
204
  request = urllib.request.Request(daemon_url.rstrip("/") + "/setup/notices", data=b"{}", method="POST",
176
205
  headers={"Content-Type": "application/json"})
177
206
  with urllib.request.urlopen(request, timeout=60) as response:
178
- _show_notices(icon, json.load(response))
207
+ notices = json.load(response)
208
+ waiting_since = None
209
+ _show_notices(icon, notices)
210
+ else:
211
+ delay = NOTICE_RETRY_S
179
212
  except Exception as exc:
180
- if str(exc) != _state.get("notice_error"):
213
+ if _daemon_not_ready(exc):
214
+ delay = NOTICE_RETRY_S
215
+ waiting_since = waiting_since if waiting_since is not None else time.monotonic()
216
+ if time.monotonic() - waiting_since >= NOTICE_UNREACHABLE_LOG_S and not _state.get("notice_unreachable"):
217
+ _state["notice_unreachable"] = True
218
+ _log(f"notices: the daemon has not answered for {NOTICE_UNREACHABLE_LOG_S // 60} min: {exc}")
219
+ elif str(exc) != _state.get("notice_error"):
181
220
  _state["notice_error"] = str(exc)
182
- _notify(icon, "Could not show a Smart Tool notice: {error}", error=exc)
183
- time.sleep(NOTICE_INTERVAL_S)
221
+ _log(f"notices: could not fetch or show them: {type(exc).__name__}: {exc}")
222
+ time.sleep(delay)
184
223
 
185
224
 
186
225
  def _announce_start(icon):
@@ -197,17 +236,20 @@ def _announce_start(icon):
197
236
 
198
237
 
199
238
  def _update_loop(icon):
200
- """Checks npm at start and every 24 h. A newer version is installed right away when automatic updates are on (once
239
+ """Checks npm at start and every 24 h (every 5 min while npm cannot be reached, as when the network is not up yet right
240
+ after boot; nothing is shown for that). A newer version is installed right away when automatic updates are on (once
201
241
  per version, again 24 h after a failed try); otherwise the user is told and the menu offers it."""
202
242
  try:
203
243
  _announce_start(icon)
204
244
  except Exception as exc:
205
245
  _notify(icon, "Could not read the update state: {error}", error=exc)
206
246
  while True:
247
+ unreachable = False
207
248
  try:
208
249
  latest = update_check.newer_version()
209
250
  except Exception:
210
251
  latest = None
252
+ unreachable = True
211
253
  else:
212
254
  try:
213
255
  update_check.record_check(latest)
@@ -228,7 +270,7 @@ def _update_loop(icon):
228
270
  elif not known:
229
271
  _notify(icon, "Smart Tool {version} is available: use \"Update to {version}\" in this menu.",
230
272
  version=latest)
231
- time.sleep(UPDATE_CHECK_INTERVAL_S)
273
+ time.sleep(UPDATE_RETRY_S if unreachable else UPDATE_CHECK_INTERVAL_S)
232
274
 
233
275
 
234
276
  def _update_label(item):
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.47"
4
+ VERSION = "0.9.49"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7