@allansantos-dev/smart-tool 0.9.47 → 0.9.48

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.48 - beta
4
+
5
+ - Smart Tool spawns far fewer Git processes. A Git view (`index_views.describe`, `pin`) is now resolved once per
6
+ repository and reused while the files that define it (HEAD, index, logs/HEAD, packed-refs, the branch ref) have not
7
+ moved: a stat of five files instead of three `git.exe` per call, also for `fresh` and `pin`. Concurrent callers of the
8
+ same repository share one resolution. A checkout or commit still changes the stamp, so it is detected and
9
+ `assert_current` still discards a result computed on another branch (`tests/test_view_sharing.py`).
10
+
3
11
  ## 0.9.47 - beta
4
12
 
5
13
  - 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.48 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):
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.48",
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/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.48"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7