dsh-limit-break 1.0.1 → 1.2.0
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 +64 -0
- package/LICENSE +21 -21
- package/MAINTAIN.md +132 -0
- package/README.md +98 -80
- package/cordis.patch.yml +13 -13
- package/lib/index.js +577 -462
- package/package.json +5 -2
- package/tools/maintain.py +326 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-limit-break",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Durable cross-session memory and a fetch ladder that survives hostname-keyed blocking — four small tools for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
"lib/",
|
|
13
13
|
"cordis.patch.yml",
|
|
14
14
|
"README.md",
|
|
15
|
-
"LICENSE"
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"tools/",
|
|
17
|
+
"MAINTAIN.md",
|
|
18
|
+
"CHANGELOG.md"
|
|
16
19
|
],
|
|
17
20
|
"keywords": [
|
|
18
21
|
"deepseek",
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""dsh-limit-break maintenance kit.
|
|
3
|
+
|
|
4
|
+
One script, three verbs. Every verb prints something a human can read and
|
|
5
|
+
writes JSON next to the memory store so the next round can diff against it.
|
|
6
|
+
|
|
7
|
+
python tools/maintain.py status # where the plugin stands, right now
|
|
8
|
+
python tools/maintain.py probe # re-measure the environment, diff vs last
|
|
9
|
+
python tools/maintain.py verify # contract test + install sanity
|
|
10
|
+
|
|
11
|
+
The loop this belongs to (see MAINTAIN.md):
|
|
12
|
+
probe -> find a limit that moved
|
|
13
|
+
break -> prove it with a measurement, not an opinion
|
|
14
|
+
evolve -> turn it into a tool or a fix
|
|
15
|
+
publish-> version, npm, git, listing
|
|
16
|
+
record -> facts.json + CHANGELOG
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import platform
|
|
23
|
+
import socket
|
|
24
|
+
import subprocess
|
|
25
|
+
import sys
|
|
26
|
+
import time
|
|
27
|
+
import urllib.error
|
|
28
|
+
import urllib.request
|
|
29
|
+
from datetime import datetime, timezone, timedelta
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
HOME = Path(os.environ.get("DSH_HOME", Path.home() / ".dsh"))
|
|
33
|
+
TZ = timezone(timedelta(hours=8))
|
|
34
|
+
PKG = "dsh-limit-break"
|
|
35
|
+
REPO = "Ma354/dsh-limit-break"
|
|
36
|
+
LIST_REPO = "awesome-dsh-plugin/awesome-dsh-plugin"
|
|
37
|
+
HERE = Path(__file__).resolve().parent.parent # .../dsh-limit-break
|
|
38
|
+
PROFILE = HOME / "profiles" / "desktop"
|
|
39
|
+
STORE = HOME / "memory"
|
|
40
|
+
BASELINE = STORE / "baseline-limit-break.json"
|
|
41
|
+
GPU_LIBS = Path(r"D:\deepseek-harness\default-workspace\capability-demo\breakthrough\gpu\libs")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def now() -> str:
|
|
45
|
+
return datetime.now(TZ).isoformat(timespec="seconds")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get(url: str, timeout: float = 12.0):
|
|
49
|
+
"""-> (http_code, seconds, body_text). Never raises."""
|
|
50
|
+
t0 = time.time()
|
|
51
|
+
req = urllib.request.Request(url, headers={"User-Agent": f"{PKG}-maintain/1"})
|
|
52
|
+
try:
|
|
53
|
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
|
54
|
+
return r.status, time.time() - t0, r.read().decode("utf-8", "replace")
|
|
55
|
+
except urllib.error.HTTPError as e:
|
|
56
|
+
return e.code, time.time() - t0, ""
|
|
57
|
+
except Exception as e: # noqa: BLE001
|
|
58
|
+
return f"ERR:{type(e).__name__}", time.time() - t0, ""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_json(url: str):
|
|
62
|
+
code, secs, body = get(url)
|
|
63
|
+
if isinstance(code, int) and 200 <= code < 300:
|
|
64
|
+
try:
|
|
65
|
+
return code, secs, json.loads(body)
|
|
66
|
+
except Exception: # noqa: BLE001
|
|
67
|
+
pass
|
|
68
|
+
return code, secs, None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def sh(cmd: list[str], timeout: float = 30.0) -> str:
|
|
72
|
+
try:
|
|
73
|
+
p = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
74
|
+
return (p.stdout or "").strip() or (p.stderr or "").strip()
|
|
75
|
+
except Exception as e: # noqa: BLE001
|
|
76
|
+
return f"ERR:{type(e).__name__}"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# --------------------------------------------------------------------------- status
|
|
80
|
+
def cmd_status() -> int:
|
|
81
|
+
out: dict = {"checked_at": now(), "problems": []}
|
|
82
|
+
|
|
83
|
+
local = {}
|
|
84
|
+
try:
|
|
85
|
+
local = json.loads((PROFILE / "node_modules" / PKG / "package.json").read_text(encoding="utf-8"))
|
|
86
|
+
except Exception: # noqa: BLE001
|
|
87
|
+
out["problems"].append("installed copy missing under the profile")
|
|
88
|
+
out["installed_version"] = local.get("version")
|
|
89
|
+
out["installed_has_bundle"] = bool(local.get("dsh", {}).get("bundle"))
|
|
90
|
+
|
|
91
|
+
prof = {}
|
|
92
|
+
try:
|
|
93
|
+
prof = json.loads((PROFILE / "package.json").read_text(encoding="utf-8"))
|
|
94
|
+
except Exception: # noqa: BLE001
|
|
95
|
+
pass
|
|
96
|
+
bundles = prof.get("dsh", {}).get("profile", {}).get("bundles", [])
|
|
97
|
+
out["in_dependencies"] = prof.get("dependencies", {}).get(PKG)
|
|
98
|
+
out["in_bundles"] = PKG in bundles
|
|
99
|
+
out["bundle_position"] = bundles.index(PKG) if PKG in bundles else None
|
|
100
|
+
if not out["in_bundles"]:
|
|
101
|
+
out["problems"].append("not listed in dsh.profile.bundles -> the app will never load it")
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
repo_ver = json.loads((HERE / "package.json").read_text(encoding="utf-8")).get("version")
|
|
105
|
+
except Exception: # noqa: BLE001
|
|
106
|
+
repo_ver = None
|
|
107
|
+
out["repo_version"] = repo_ver
|
|
108
|
+
|
|
109
|
+
code, _, reg = get_json(f"https://registry.npmjs.org/{PKG}?t={int(time.time())}")
|
|
110
|
+
out["npm_http"] = code
|
|
111
|
+
if reg:
|
|
112
|
+
out["npm_latest"] = reg.get("dist-tags", {}).get("latest")
|
|
113
|
+
out["npm_versions"] = sorted(reg.get("versions", {}))
|
|
114
|
+
if out["npm_latest"] != out["installed_version"]:
|
|
115
|
+
out["problems"].append(
|
|
116
|
+
f"drift: installed {out['installed_version']} != npm latest {out['npm_latest']}")
|
|
117
|
+
if repo_ver and repo_ver != out["npm_latest"]:
|
|
118
|
+
out["problems"].append(
|
|
119
|
+
f"release pending: repo at {repo_ver}, npm latest {out['npm_latest']} (needs npm publish)")
|
|
120
|
+
else:
|
|
121
|
+
out["problems"].append(f"npm registry unreachable ({code})")
|
|
122
|
+
|
|
123
|
+
code, _, gh = get_json(f"https://api.github.com/repos/{REPO}")
|
|
124
|
+
out["github_http"] = code
|
|
125
|
+
if gh:
|
|
126
|
+
out["github_pushed_at"] = gh.get("pushed_at")
|
|
127
|
+
out["github_stars"] = gh.get("stargazers_count")
|
|
128
|
+
out["github_description"] = gh.get("description")
|
|
129
|
+
|
|
130
|
+
code, _, raw = get(f"https://raw.githubusercontent.com/{LIST_REPO}/main/data/plugins/Ma354__{PKG}.yml")
|
|
131
|
+
out["listing_http"] = code
|
|
132
|
+
out["listed_in_market"] = code == 200
|
|
133
|
+
|
|
134
|
+
code, _, prs = get_json(
|
|
135
|
+
f"https://api.github.com/search/issues?q=repo:{LIST_REPO}+is:pr+{PKG}+in:title")
|
|
136
|
+
if prs and prs.get("items"):
|
|
137
|
+
pr = prs["items"][0]
|
|
138
|
+
out["pr"] = {"number": pr["number"], "state": pr["state"], "merged": bool(pr.get("pull_request", {}).get("merged_at")),
|
|
139
|
+
"url": pr["html_url"]}
|
|
140
|
+
if not out["listed_in_market"]:
|
|
141
|
+
out["problems"].append(f"market listing not live yet (PR #{pr['number']} {pr['state']})")
|
|
142
|
+
else:
|
|
143
|
+
out["pr"] = None
|
|
144
|
+
|
|
145
|
+
log = STORE / "plugin-load.log"
|
|
146
|
+
if log.exists():
|
|
147
|
+
lines = [l for l in log.read_text(encoding="utf-8").splitlines() if l.strip()]
|
|
148
|
+
if lines:
|
|
149
|
+
try:
|
|
150
|
+
out["last_mount"] = json.loads(lines[-1])
|
|
151
|
+
except Exception: # noqa: BLE001
|
|
152
|
+
out["last_mount"] = lines[-1]
|
|
153
|
+
|
|
154
|
+
print(json.dumps(out, ensure_ascii=False, indent=2))
|
|
155
|
+
return 0
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# ---------------------------------------------------------------------------- probe
|
|
159
|
+
def _cupy_probe() -> dict:
|
|
160
|
+
res: dict = {}
|
|
161
|
+
if not GPU_LIBS.exists():
|
|
162
|
+
return {"available": False, "why": f"libs dir missing: {GPU_LIBS}"}
|
|
163
|
+
sys.path.insert(0, str(GPU_LIBS))
|
|
164
|
+
binx = GPU_LIBS / "bin"
|
|
165
|
+
if binx.exists() and hasattr(os, "add_dll_directory"):
|
|
166
|
+
try:
|
|
167
|
+
os.add_dll_directory(str(binx))
|
|
168
|
+
except Exception: # noqa: BLE001
|
|
169
|
+
pass
|
|
170
|
+
try:
|
|
171
|
+
import cupy as cp # noqa: F401
|
|
172
|
+
except Exception as e: # noqa: BLE001
|
|
173
|
+
return {"available": False, "why": f"{type(e).__name__}: {e}"}
|
|
174
|
+
try:
|
|
175
|
+
dev = cp.cuda.Device(0)
|
|
176
|
+
props = cp.cuda.runtime.getDeviceProperties(0)
|
|
177
|
+
res["device"] = props["name"].decode() if isinstance(props["name"], bytes) else str(props["name"])
|
|
178
|
+
res["vram_mib"] = round(dev.mem_info[1] / 2**20, 1)
|
|
179
|
+
n = 1 << 26
|
|
180
|
+
x = cp.random.random(n, dtype=cp.float32)
|
|
181
|
+
y = cp.random.random(n, dtype=cp.float32)
|
|
182
|
+
for _ in range(3): # warm up kernels + allocator
|
|
183
|
+
cp.count_nonzero(x * x + y * y <= 1.0)
|
|
184
|
+
cp.cuda.Stream.null.synchronize()
|
|
185
|
+
best = min(_mc_once(cp, x, y, n) for _ in range(3))
|
|
186
|
+
res["mc_samples_per_sec"] = round(n / best)
|
|
187
|
+
res["mc_seconds"] = round(best, 4)
|
|
188
|
+
res["available"] = True
|
|
189
|
+
except Exception as e: # noqa: BLE001
|
|
190
|
+
res["available"] = False
|
|
191
|
+
res["why"] = f"runtime: {type(e).__name__}: {e}"
|
|
192
|
+
return res
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _mc_once(cp, x, y, n):
|
|
196
|
+
cp.cuda.Stream.null.synchronize()
|
|
197
|
+
t0 = time.perf_counter()
|
|
198
|
+
cp.count_nonzero(x * x + y * y <= 1.0)
|
|
199
|
+
cp.cuda.Stream.null.synchronize()
|
|
200
|
+
return time.perf_counter() - t0
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _cpu_gflops() -> float | None:
|
|
204
|
+
try:
|
|
205
|
+
import numpy as np
|
|
206
|
+
n = 1024
|
|
207
|
+
a = np.random.random((n, n))
|
|
208
|
+
b = np.random.random((n, n))
|
|
209
|
+
a @ b
|
|
210
|
+
t0 = time.perf_counter()
|
|
211
|
+
for _ in range(3):
|
|
212
|
+
a @ b
|
|
213
|
+
dt = (time.perf_counter() - t0) / 3
|
|
214
|
+
return round(2 * n ** 3 / dt / 1e9, 1)
|
|
215
|
+
except Exception: # noqa: BLE001
|
|
216
|
+
return None
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
NET_PROBES = [
|
|
220
|
+
("baseline.example", "https://example.com/"),
|
|
221
|
+
("npm", "https://registry.npmjs.org/"),
|
|
222
|
+
("github-api", "https://api.github.com/"),
|
|
223
|
+
("wikipedia-direct", "https://en.wikipedia.org/wiki/Artificial_intelligence"),
|
|
224
|
+
("wikimedia-api", "https://api.wikimedia.org/core/v1/wikipedia/en/page/Artificial_intelligence"),
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def cmd_probe() -> int:
|
|
229
|
+
snap: dict = {"probed_at": now(), "host": socket.gethostname()}
|
|
230
|
+
snap["os"] = f"{platform.system()} {platform.release()}"
|
|
231
|
+
snap["python"] = platform.python_version()
|
|
232
|
+
node = Path(r"D:\dsh文件\resources\runtime\primary-runtime\dependencies\node\bin\node.exe")
|
|
233
|
+
snap["node"] = sh([str(node), "-v"]) if node.exists() else "missing"
|
|
234
|
+
snap["cpu_threads"] = os.cpu_count()
|
|
235
|
+
snap["cpu_gflops"] = _cpu_gflops()
|
|
236
|
+
|
|
237
|
+
nvsmi = sh(["nvidia-smi", "--query-gpu=name,memory.total,driver_version",
|
|
238
|
+
"--format=csv,noheader"], timeout=20)
|
|
239
|
+
snap["nvidia_smi"] = nvsmi or "unavailable"
|
|
240
|
+
snap["cupy"] = _cupy_probe()
|
|
241
|
+
|
|
242
|
+
ppt = Path(r"C:\Program Files\Microsoft Office\Root\Office16\POWERPNT.EXE")
|
|
243
|
+
snap["powerpoint_com"] = ppt.exists()
|
|
244
|
+
lo = Path(r"D:\dsh文件\resources\app.asar.unpacked\dsh\node_modules\@deepseek-ai\libreoffice-kit\lib\cli.js")
|
|
245
|
+
snap["libreoffice_kit"] = lo.exists()
|
|
246
|
+
|
|
247
|
+
net = {}
|
|
248
|
+
for name, url in NET_PROBES:
|
|
249
|
+
code, secs, body = get(url, timeout=8.0)
|
|
250
|
+
net[name] = {"code": code, "seconds": round(secs, 3), "bytes": len(body)}
|
|
251
|
+
snap["network"] = net
|
|
252
|
+
|
|
253
|
+
try:
|
|
254
|
+
import shutil
|
|
255
|
+
free, total = shutil.disk_usage("D:\\")
|
|
256
|
+
snap["disk_d_free_gib"] = round(free / 2**30, 1)
|
|
257
|
+
snap["disk_d_total_gib"] = round(total / 2**30, 1)
|
|
258
|
+
except Exception: # noqa: BLE001
|
|
259
|
+
pass
|
|
260
|
+
|
|
261
|
+
prev = None
|
|
262
|
+
if BASELINE.exists():
|
|
263
|
+
try:
|
|
264
|
+
prev = json.loads(BASELINE.read_text(encoding="utf-8"))
|
|
265
|
+
except Exception: # noqa: BLE001
|
|
266
|
+
prev = None
|
|
267
|
+
|
|
268
|
+
diffs: list[str] = []
|
|
269
|
+
if prev:
|
|
270
|
+
if prev.get("cupy", {}).get("available") != snap["cupy"].get("available"):
|
|
271
|
+
diffs.append(f"cupy availability {prev['cupy'].get('available')} -> {snap['cupy'].get('available')}")
|
|
272
|
+
p_mc = (prev.get("cupy") or {}).get("mc_samples_per_sec")
|
|
273
|
+
n_mc = snap["cupy"].get("mc_samples_per_sec")
|
|
274
|
+
if p_mc and n_mc and abs(n_mc - p_mc) / p_mc > 0.25:
|
|
275
|
+
diffs.append(f"gpu mc throughput {p_mc} -> {n_mc} (>25%)")
|
|
276
|
+
if prev.get("cpu_threads") != snap["cpu_threads"]:
|
|
277
|
+
diffs.append(f"cpu threads {prev.get('cpu_threads')} -> {snap['cpu_threads']}")
|
|
278
|
+
for k, v in snap["network"].items():
|
|
279
|
+
pv = (prev.get("network") or {}).get(k, {}).get("code")
|
|
280
|
+
if pv != v["code"]:
|
|
281
|
+
diffs.append(f"network {k}: {pv} -> {v['code']}")
|
|
282
|
+
if prev.get("powerpoint_com") != snap["powerpoint_com"]:
|
|
283
|
+
diffs.append("powerpoint COM availability changed")
|
|
284
|
+
snap["previous_probed_at"] = prev.get("probed_at")
|
|
285
|
+
else:
|
|
286
|
+
diffs.append("no previous baseline - this run becomes the baseline")
|
|
287
|
+
|
|
288
|
+
snap["diffs_vs_previous"] = diffs
|
|
289
|
+
STORE.mkdir(parents=True, exist_ok=True)
|
|
290
|
+
BASELINE.write_text(json.dumps(snap, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
291
|
+
print(json.dumps(snap, ensure_ascii=False, indent=2))
|
|
292
|
+
print(f"\nbaseline written to {BASELINE}", file=sys.stderr)
|
|
293
|
+
return 0
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
# --------------------------------------------------------------------------- verify
|
|
297
|
+
def cmd_verify() -> int:
|
|
298
|
+
node = Path(r"D:\dsh文件\resources\runtime\primary-runtime\dependencies\node\bin\node.exe")
|
|
299
|
+
test = HERE.parent / "test_plugin.mjs"
|
|
300
|
+
if not test.exists():
|
|
301
|
+
test = Path(r"D:\deepseek-harness\default-workspace\capability-demo\plugin\test_plugin.mjs")
|
|
302
|
+
if not test.exists():
|
|
303
|
+
print(json.dumps({"contract_test": "SKIP", "why": f"test file not found near {HERE}"}))
|
|
304
|
+
return 1
|
|
305
|
+
p = subprocess.run([str(node), str(test)], capture_output=True, text=True, timeout=120)
|
|
306
|
+
print(json.dumps({
|
|
307
|
+
"checked_at": now(),
|
|
308
|
+
"contract_test": "PASS" if p.returncode == 0 else "FAIL",
|
|
309
|
+
"returncode": p.returncode,
|
|
310
|
+
"stdout": (p.stdout or "").strip()[-1500:],
|
|
311
|
+
"stderr": (p.stderr or "").strip()[-800:],
|
|
312
|
+
}, ensure_ascii=False, indent=2))
|
|
313
|
+
return 0 if p.returncode == 0 else 1
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def main() -> int:
|
|
317
|
+
verb = (sys.argv[1] if len(sys.argv) > 1 else "").lower()
|
|
318
|
+
table = {"status": cmd_status, "probe": cmd_probe, "verify": cmd_verify}
|
|
319
|
+
if verb not in table:
|
|
320
|
+
print(__doc__)
|
|
321
|
+
return 2
|
|
322
|
+
return table[verb]()
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
if __name__ == "__main__":
|
|
326
|
+
sys.exit(main())
|