@allansantos-dev/smart-tool 0.9.49 → 0.9.51
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 +17 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/toast_notice.py +13 -1
- package/tray.py +14 -6
- package/update_check.py +8 -3
- package/update_splash.py +10 -7
- package/version.py +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.51 - beta
|
|
4
|
+
|
|
5
|
+
- The automatic update installs the version the tray announced (`npx --yes @allansantos-dev/smart-tool@<version>
|
|
6
|
+
install`) instead of `@latest`. With `@latest`, npx could reuse an older package left in its cache and install that,
|
|
7
|
+
moving the install back a version. The update notices given to the user and to agent sessions ("To update now,
|
|
8
|
+
run: ...") name the same pinned command, and the update screen refuses to start without the version to install
|
|
9
|
+
instead of falling back to `@latest` (`tests/test_update_splash.py`, `tests/test_update_check.py`).
|
|
10
|
+
|
|
11
|
+
## 0.9.50 - beta
|
|
12
|
+
|
|
13
|
+
- Windows refused the setup-audit toast of a project whose path made the toast tag longer than 64 characters
|
|
14
|
+
(`ToastNotification.Tag` limit since the Creators Update); before 0.9.49 that refusal became a second notification
|
|
15
|
+
"Could not show a Smart Tool notice". `toast_notice.show` now fits a longer tag to 64 characters (its start plus a hash
|
|
16
|
+
of the whole, so each project still replaces its own toast), and each notice in `_show_notices` is shown on its own: a
|
|
17
|
+
refused one goes to `tray.log` and the next ones are still shown. The toast script no longer writes PowerShell's
|
|
18
|
+
progress records, so a refusal in the log reads as the error itself (`tests/test_tray_notices.py`).
|
|
19
|
+
|
|
3
20
|
## 0.9.49 - beta
|
|
4
21
|
|
|
5
22
|
- No more "Could not show a Smart Tool notice: [WinError 10061]" right after logon. The tray's notice loop asked the
|
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.51 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
|
|
21
21
|
|
|
22
22
|
## How it works
|
|
23
23
|
|
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.51",
|
|
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/toast_notice.py
CHANGED
|
@@ -7,6 +7,7 @@ only HKCU keys (no admin): one AppUserModelId key (name and icon of the toast) a
|
|
|
7
7
|
write the config file, never state held by the tray.
|
|
8
8
|
"""
|
|
9
9
|
import base64
|
|
10
|
+
import hashlib
|
|
10
11
|
import os
|
|
11
12
|
import subprocess
|
|
12
13
|
import sys
|
|
@@ -15,10 +16,12 @@ from xml.sax.saxutils import quoteattr, escape
|
|
|
15
16
|
|
|
16
17
|
APP_ID = "SmartTool.Notifications"
|
|
17
18
|
PROTOCOL = "smart-tool-action"
|
|
19
|
+
TAG_MAX = 64
|
|
18
20
|
ACTION_SCRIPT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "notice_action.py")
|
|
19
21
|
|
|
20
22
|
_SHOW_SCRIPT = r"""
|
|
21
23
|
$ErrorActionPreference = 'Stop'
|
|
24
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
22
25
|
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
|
|
23
26
|
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
|
|
24
27
|
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
|
@@ -84,6 +87,15 @@ def toast_xml(title, lines, buttons):
|
|
|
84
87
|
+ (f'<actions>{actions}</actions>' if actions else '') + '</toast>')
|
|
85
88
|
|
|
86
89
|
|
|
90
|
+
def _fit_tag(tag):
|
|
91
|
+
"""Windows refuses a toast whose Tag is longer than 64 characters. A longer tag (one built from a project path) keeps
|
|
92
|
+
its start and ends in a hash of the whole, so each project still replaces its own toast."""
|
|
93
|
+
if len(tag) <= TAG_MAX:
|
|
94
|
+
return tag
|
|
95
|
+
digest = hashlib.sha256(tag.encode("utf-8")).hexdigest()[:24]
|
|
96
|
+
return tag[:TAG_MAX - len(digest) - 1] + "~" + digest
|
|
97
|
+
|
|
98
|
+
|
|
87
99
|
def show(title, lines, buttons, tag=None):
|
|
88
100
|
"""Shows the toast; raises RuntimeError with PowerShell's message when Windows refuses it."""
|
|
89
101
|
if sys.platform != "win32":
|
|
@@ -91,7 +103,7 @@ def show(title, lines, buttons, tag=None):
|
|
|
91
103
|
register()
|
|
92
104
|
script = base64.b64encode(_SHOW_SCRIPT.encode("utf-16-le")).decode("ascii")
|
|
93
105
|
env = {**os.environ, "SMART_TOOL_TOAST_XML": toast_xml(title, lines, buttons),
|
|
94
|
-
"SMART_TOOL_TOAST_APPID": APP_ID, "SMART_TOOL_TOAST_TAG": tag or ""}
|
|
106
|
+
"SMART_TOOL_TOAST_APPID": APP_ID, "SMART_TOOL_TOAST_TAG": _fit_tag(tag or "")}
|
|
95
107
|
done = subprocess.run(
|
|
96
108
|
["powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", script],
|
|
97
109
|
env=env, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=30,
|
package/tray.py
CHANGED
|
@@ -145,6 +145,14 @@ def _poll_loop(icon):
|
|
|
145
145
|
time.sleep(POLL_INTERVAL_S)
|
|
146
146
|
|
|
147
147
|
|
|
148
|
+
def _toast(title, lines, buttons, tag):
|
|
149
|
+
"""One notice: a toast Windows refuses goes to `tray.log` and does not keep the next notices from being shown."""
|
|
150
|
+
try:
|
|
151
|
+
toast_notice.show(title, lines, buttons, tag=tag)
|
|
152
|
+
except Exception as exc:
|
|
153
|
+
_log(f"notice {tag}: {type(exc).__name__}: {exc}")
|
|
154
|
+
|
|
155
|
+
|
|
148
156
|
def _show_notices(icon, notices):
|
|
149
157
|
"""Shows a toast for each pending notice: the new-default-models offer, each model over the failure limit and each
|
|
150
158
|
project whose scheduled setup audit found new errors or warnings."""
|
|
@@ -152,23 +160,23 @@ def _show_notices(icon, notices):
|
|
|
152
160
|
if offer:
|
|
153
161
|
lines = [f"{role}: {change['current']} -> {change['new']}" for role, change in offer["changes"].items()]
|
|
154
162
|
nonce = offer["nonce"]
|
|
155
|
-
|
|
163
|
+
_toast(i18n.t("Smart Tool has new recommended models"), lines, [
|
|
156
164
|
(i18n.t("Apply now"), toast_notice.action_uri("models-apply", n=nonce)),
|
|
157
165
|
(i18n.t("Don't show again"), toast_notice.action_uri("models-decline", n=nonce)),
|
|
158
|
-
],
|
|
166
|
+
], "models-upgrade")
|
|
159
167
|
for row in notices.get("failing") or []:
|
|
160
168
|
last = row.get("last_error") or i18n.t("see the failure log in the settings")
|
|
161
|
-
|
|
169
|
+
_toast(
|
|
162
170
|
i18n.t("{model} is failing", model=row["model"]),
|
|
163
171
|
[i18n.t("{errors} of {calls} calls failed in 24 h as {role}.", errors=row["errors"], calls=row["calls"],
|
|
164
172
|
role=row["role"]), last[:160]],
|
|
165
173
|
[(i18n.t("Switch model"), toast_notice.action_uri("open-setup", section="models")),
|
|
166
174
|
(i18n.t("Mute 7 days"), toast_notice.action_uri("mute-model", model=row["model"]))],
|
|
167
|
-
|
|
175
|
+
"model-failing:" + row["model"])
|
|
168
176
|
for row in notices.get("audit") or []:
|
|
169
177
|
title, lines = setup_audit.toast_text(row)
|
|
170
|
-
|
|
171
|
-
|
|
178
|
+
_toast(title, lines, [(i18n.t("Open the audit"), toast_notice.action_uri("open-setup", section="audit"))],
|
|
179
|
+
"setup-audit:" + row["project"])
|
|
172
180
|
|
|
173
181
|
|
|
174
182
|
def _log(text):
|
package/update_check.py
CHANGED
|
@@ -20,7 +20,6 @@ import version
|
|
|
20
20
|
|
|
21
21
|
PACKAGE = "@allansantos-dev/smart-tool"
|
|
22
22
|
REGISTRY_URL = "https://registry.npmjs.org/@allansantos-dev%2Fsmart-tool/latest"
|
|
23
|
-
UPDATE_COMMAND = f"npx --yes {PACKAGE}@latest install"
|
|
24
23
|
SITE_URL = "https://allansantos-dv.github.io/smart-tool/"
|
|
25
24
|
STATE_PATH = os.path.join(paths.DATA_DIR, "update-state.json")
|
|
26
25
|
UPDATE_LOG = os.path.join(paths.DATA_DIR, "update.log")
|
|
@@ -42,6 +41,12 @@ def newer_version(timeout=10):
|
|
|
42
41
|
return latest if _parts(latest) > _parts(version.VERSION) else None
|
|
43
42
|
|
|
44
43
|
|
|
44
|
+
def update_command(target):
|
|
45
|
+
"""The npx command that installs version target, as told to the user and to agent sessions. Pinned rather than
|
|
46
|
+
`@latest`, which lets npx reuse an older package from its cache."""
|
|
47
|
+
return f"npx --yes {PACKAGE}@{target} install"
|
|
48
|
+
|
|
49
|
+
|
|
45
50
|
def env_opted_out():
|
|
46
51
|
"""SMART_TOOL_AUTO_UPDATE set to off, 0, false or no."""
|
|
47
52
|
return os.environ.get(ENV_OPT_OUT, "").strip().lower() in ("off", "0", "false", "no")
|
|
@@ -144,10 +149,10 @@ def notices(now=None):
|
|
|
144
149
|
else "automatic updates are now off")
|
|
145
150
|
found.append((f"failed:{failed}",
|
|
146
151
|
f"The automatic update of Smart Tool to {failed} failed; {version.VERSION} is still installed "
|
|
147
|
-
f"and {retry}. To update now, run: {
|
|
152
|
+
f"and {retry}. To update now, run: {update_command(failed)}"))
|
|
148
153
|
elif latest and _parts(latest) > _parts(version.VERSION):
|
|
149
154
|
how = ("the tray installs it automatically" if automatic_enabled()
|
|
150
|
-
else f"automatic updates are off (tray switch or {ENV_OPT_OUT}=off); to update, run: {
|
|
155
|
+
else f"automatic updates are off (tray switch or {ENV_OPT_OUT}=off); to update, run: {update_command(latest)}")
|
|
151
156
|
found.append((f"available:{latest}",
|
|
152
157
|
f"Smart Tool {latest} is available on npm (installed: {version.VERSION}); {how}."))
|
|
153
158
|
return found
|
package/update_splash.py
CHANGED
|
@@ -47,18 +47,19 @@ def step_for(line):
|
|
|
47
47
|
return None
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
def install_command():
|
|
51
|
-
"""argv of the update: the
|
|
50
|
+
def install_command(target):
|
|
51
|
+
"""argv of the update: the npx command a user types, through cmd.exe because npx is a .cmd script, for the version
|
|
52
|
+
the tray announced. `@latest` would let npx reuse an older package from its cache and install that instead."""
|
|
52
53
|
npx = node_locator.which("npx.cmd")
|
|
53
54
|
if not npx:
|
|
54
55
|
raise RuntimeError(i18n.t("Node.js (npx) was not found; install Node.js and try again."))
|
|
55
|
-
return ["cmd.exe", "/d", "/c", npx, "--yes", f"{update_check.PACKAGE}@
|
|
56
|
+
return ["cmd.exe", "/d", "/c", npx, "--yes", f"{update_check.PACKAGE}@{target}", "install"], npx
|
|
56
57
|
|
|
57
58
|
|
|
58
|
-
def run_install(lines):
|
|
59
|
+
def run_install(lines, target):
|
|
59
60
|
"""Runs the install command hidden, puts each output line on `lines`, writes them to update_check.UPDATE_LOG and returns
|
|
60
61
|
(exit code, last non-empty line). Kills the whole process tree after TIMEOUT_S."""
|
|
61
|
-
command, npx = install_command()
|
|
62
|
+
command, npx = install_command(target)
|
|
62
63
|
os.makedirs(os.path.dirname(update_check.UPDATE_LOG), exist_ok=True)
|
|
63
64
|
last = ""
|
|
64
65
|
with open(update_check.UPDATE_LOG, "w", encoding="utf-8") as log:
|
|
@@ -150,7 +151,9 @@ class Splash:
|
|
|
150
151
|
|
|
151
152
|
def main(argv):
|
|
152
153
|
"""Shows the screen, runs the update and reports the outcome; returns the installer's exit code."""
|
|
153
|
-
|
|
154
|
+
if len(argv) < 2:
|
|
155
|
+
raise SystemExit("usage: update_splash.py <version>: the version to install, as announced by the tray")
|
|
156
|
+
target = argv[1]
|
|
154
157
|
if not _single_instance():
|
|
155
158
|
return 0
|
|
156
159
|
splash = Splash(target)
|
|
@@ -158,7 +161,7 @@ def main(argv):
|
|
|
158
161
|
|
|
159
162
|
def work():
|
|
160
163
|
try:
|
|
161
|
-
outcome["code"], outcome["last"] = run_install(lines)
|
|
164
|
+
outcome["code"], outcome["last"] = run_install(lines, target)
|
|
162
165
|
except Exception as exc:
|
|
163
166
|
outcome["code"], outcome["last"] = 1, f"{type(exc).__name__}: {exc}"
|
|
164
167
|
|
package/version.py
CHANGED