fix(dsh): slim packaged runtime and surface startup errors
This commit is contained in:
1 parent
df250e04ba
commit
caa79e7fcf
7 files changed
+159
-5
No files matched your search
@@ -3,11 +3,14 @@
|
||||
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
import win32com.client.gencache
|
||||
|
||||
|
||||
project_root = Path(SPECPATH).parent
|
||||
sys.path.insert(0, str(project_root / 'packaging'))
|
||||
from dsh_runtime_staging import stage_node_modules
|
||||
generated_root = project_root / "build" / "DxPartReplace-generated"
|
||||
generated_root.mkdir(parents=True, exist_ok=True)
|
||||
viewdraw_api = win32com.client.gencache.EnsureModule(
|
||||
@@ -38,11 +41,13 @@ if (dsh_root / 'issue-bootstrap.json').is_file():
|
||||
if (dsh_root / 'node_modules' / '@deepseek-ai' / 'dsh' / 'package.json').is_file():
|
||||
if not (dsh_root / 'issue-bootstrap.json').is_file():
|
||||
raise RuntimeError('Provision the DSH issue-only reporter before packaging the native assistant.')
|
||||
staged_node_modules = stage_node_modules(
|
||||
dsh_root / 'node_modules', generated_root / 'dsh-node_modules')
|
||||
legacy_runtime_datas.extend([
|
||||
(str(dsh_root / 'start.mjs'), 'dsh-runtime'),
|
||||
(str(dsh_root / 'package.json'), 'dsh-runtime'),
|
||||
(str(dsh_root / 'task-plugin'), 'dsh-runtime/task-plugin'),
|
||||
(str(dsh_root / 'node_modules'), 'dsh-runtime/node_modules'),
|
||||
(str(staged_node_modules), 'dsh-runtime/node_modules'),
|
||||
(shutil.which('node'), 'dsh-runtime'),
|
||||
(str(project_root / 'licenses' / 'DeepSeek-Harness-MIT.txt'), 'licenses'),
|
||||
])
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"""Create a small, Windows-only copy of the installed DSH Node runtime."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
_PRUNED_DIRS = frozenset({
|
||||
".bin", ".cache", ".github", "__tests__", "benchmark", "benchmarks",
|
||||
"coverage", "example", "examples", "test", "tests",
|
||||
})
|
||||
_PRUNED_SUFFIXES = frozenset({".map", ".ts", ".tsx"})
|
||||
_PRUNED_NAMES = frozenset({"changelog", "changelog.md", "history.md", "readme", "readme.md"})
|
||||
|
||||
|
||||
def _matches(value: str, rule: str) -> bool:
|
||||
return value.casefold() == rule.lstrip("!").casefold()
|
||||
|
||||
|
||||
def _compatible(package: Path, *, platform: str, arch: str) -> bool:
|
||||
try:
|
||||
value = json.loads((package / "package.json").read_text(encoding="utf8"))
|
||||
except (OSError, ValueError, TypeError):
|
||||
return True
|
||||
if not isinstance(value, dict):
|
||||
return True
|
||||
for field, current in (("os", platform), ("cpu", arch)):
|
||||
rules = value.get(field)
|
||||
if not isinstance(rules, list):
|
||||
continue
|
||||
if any(isinstance(rule, str) and rule.startswith("!") and _matches(current, rule)
|
||||
for rule in rules):
|
||||
return False
|
||||
positive = [rule for rule in rules if isinstance(rule, str) and not rule.startswith("!")]
|
||||
if positive and not any(_matches(current, rule) for rule in positive):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _ignore(directory: str, names: list[str], *, platform: str, arch: str) -> set[str]:
|
||||
ignored: set[str] = set()
|
||||
for name in names:
|
||||
path = Path(directory) / name
|
||||
if path.is_dir():
|
||||
if name.casefold() in _PRUNED_DIRS or not _compatible(path, platform=platform, arch=arch):
|
||||
ignored.add(name)
|
||||
elif Path(name).suffix.casefold() in _PRUNED_SUFFIXES or name.casefold() in _PRUNED_NAMES:
|
||||
ignored.add(name)
|
||||
return ignored
|
||||
|
||||
|
||||
def stage_node_modules(source: Path, destination: Path, *, platform: str = "win32", arch: str = "x64") -> Path:
|
||||
"""Stage runtime packages without other-platform binaries or documentation."""
|
||||
source = Path(source)
|
||||
destination = Path(destination)
|
||||
if not (source / "@deepseek-ai" / "dsh" / "package.json").is_file():
|
||||
raise FileNotFoundError("DSH runtime package is not installed")
|
||||
if destination.exists():
|
||||
shutil.rmtree(destination)
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
def link_or_copy(source_file: str, destination_file: str) -> None:
|
||||
try:
|
||||
os.link(source_file, destination_file)
|
||||
except OSError:
|
||||
shutil.copy2(source_file, destination_file)
|
||||
|
||||
shutil.copytree(source, destination, ignore=lambda directory, names: _ignore(
|
||||
directory, names, platform=platform, arch=arch), copy_function=link_or_copy,
|
||||
symlinks=False)
|
||||
return destination
|
||||
Reference in new issue
Block a user