npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dsh-context-window-tuner

v0.1.0

Published

DeepSeek Harness plugin: inspect and tune every model's context window, with hardware-aware recommendations for local models.

Readme

dsh-context-window-tuner

一个 DeepSeek Harness (DSH) 插件:在一个页面里查看并调整所有模型的上下文窗口长度;对本地模型,根据模型量级(参数量、量化、权重体积、模型上限)和本机硬件(内存、显存)自动给出推荐值,同时允许手动填写任意值。

仅修改 DSH 用来计算上下文压力、触发自动压缩的窗口元数据;不会代替推理服务自身的 num_ctx。Ollama 的额外注意事项见下文。


功能

  • 一个页面看全:列出所有已注册提供方(ctx.llm.listProviders())下的模型,以及当前生效的上下文窗口。
  • 本地模型推荐:读取 Ollama /api/tags 的参数量、量化、权重文件大小、模型最大上下文;结合本机 RAM / 显存计算“模型装得下多少 KV 缓存”,给出推荐 token 数。
  • 手动覆盖:每个模型都可以输入任意合法值(1024–4194304)并立即写回。
  • 一键采纳:单个模型的“推荐”按钮,或“本地模型全部采用推荐”批量写入。
  • 清除覆盖:删除本插件写入的值,回退到提供方默认值。
  • 可写才显示:没有可写配置的模型会显示为只读,不会凭空修改。
  • 热生效:通过 DSH 的 settings 服务写回配置,适配器在下一次模型请求时读取新值。

界面位置

打开 设置 → 上下文窗口(Settings 侧栏新增的一节)。页面包含:

  1. 硬件摘要(CPU、内存、最大独立显卡及显存);
  2. 搜索与“仅本地模型”过滤;
  3. 模型表格:当前值 / 推荐值 / 手动设置 / 清除;
  4. “本地模型全部采用推荐”。

写回后页面会自动刷新,并显示实际生效的值。

推荐算法

对本地模型:

权重体积  W = 端点报告的 GGUF 文件大小,或 参数量 × 量化密度
KV/token  K = 按参数规模的保守估算(f16 KV 缓存)
可用预算  B = max(显存 × 0.9, 内存 × 0.72)   (优先显存,模型放不下时退回内存)
推荐 token = (B − W − 1.4 GB 运行时预留) / K
  • 结果向下取整到 1024 的倍数(≥32K 时取 4096 的倍数);
  • 不超过模型自身声明的最大上下文(Ollama 的 details.context_length);
  • 低于 2048 时固定为 2048,并标记“硬件余量不足”。

不同参数量对应的 KV/token 是保守估计(例如 7–10B 约 144 KB/token、12–16B 约 192 KB/token、24–40B 约 256 KB/token),因此推荐值偏保守,不会为了更大的窗口把显存/内存榨干。

写回位置

DSH 没有统一的模型注册表,每个适配器自己保存配置。插件按提供方的配置形状选择写入点:

| 提供方 / 插件 | 写回位置 | | --- | --- | | dsh-llm-local(provider 名 = 端点 key) | llm-local 配置的 endpoints.<key>.models[] | | dsh-local-model(provider local) | dsh-local-model 配置的 models[] | | llm-pi-ai 自建路由 | providers.<id>.models[](已有条目按索引只改 contextWindow) | | llm-pi-ai 目录路由 | providers.<id>.modelOverrides.<model>.contextWindow | | llm-deepseek | models[] |

写入全部经由 settings.mutate,因此会落到当前 profile 的 cordis.patch.yml,与在“设置 → 模型”里手改等价;已有模型字段(maxTokens、reasoningEfforts、compat 等)会保留。

安装

方式一:link 到 profile(开发/本地使用)

cd "$env:USERPROFILE\.dsh\profiles\desktop"

# 让 profile 能解析到包(Windows 下也可用目录联接)
#   依赖:在 package.json 的 dependencies 里加入
#   "dsh-context-window-tuner": "link:E:/AI/work-2/dsh-context-window-tuner"

# bundles 里追加:
#   "dsh-context-window-tuner"

# 最后重启 DSH(或在启用 HMR 的 profile 里等待自动重组)

若使用插件管理页的“从本地路径安装”,选择本目录即可;它会用 link: 记录依赖并启用 bundle。

方式二:从 npm 安装(发布后)

dsh plugin --profile desktop add dsh-context-window-tuner

方式三:手动

  1. 把本目录放到任意位置;
  2. 在 profile 的 package.json 中把它加入 dependencies(link:<绝对路径>)和 dsh.profile.bundles;
  3. 重启 DSH。

与 Ollama 的配合

DSH 的上下文窗口决定DSH 允许把多少 token 发出去、何时触发压缩。Ollama 自身还有服务端 num_ctx:

  • 若 Ollama 的 num_ctx 小于本插件设置的值,服务端会先截断,页面里的窗口就“名不副实”;
  • 建议让 OLLAMA_CONTEXT_LENGTH(或每个模型的 num_ctx)不小于这里的设置值;
  • 插件会在页面底部提示这一点。

插件不会修改 Ollama 服务端参数,也不会发送请求。

诊断

设置环境变量 DSH_CONTEXT_WINDOW_DEBUG=1 后,插件会把激活、路由注册和错误写入系统临时目录下的 dsh-context-window-tuner-debug.log(默认关闭)。

其它排查点:

  • 页面 404 / 无法加载:确认插件 bundle 已加入 dsh.profile.bundles,并已重启或完成 HMR 重组;
  • “没有可写的配置项”:该提供方由没有声明配置形状的适配器提供,插件不会猜测;
  • 写入被拒绝:设置服务返回的冲突/校验信息会显示在对应行下方;外部同时修改 cordis.patch.yml 时刷新后重试即可。

开发

cd dsh-context-window-tuner

# 单元测试(推荐算法、写回计划、硬件解析、端到端 handle)
node --import ./tests/hooks.mjs tests/run.test.mjs

# 浏览器半身:注册与首次渲染冒烟
node tests/client.test.mjs

# 不经过 DSH,直接读取真实硬件与真实 Ollama,打印推荐表
node scripts/probe.mjs
node scripts/probe.mjs http://127.0.0.1:11434 qwen3

目录结构:

lib/
  index.js       宿主端:HTTP 路由、状态汇总、写回编排
  client.js      浏览器端:设置页「上下文窗口」
  hardware.js    RAM / 显存检测(Windows 注册表、Linux、macOS)
  ollama.js      Ollama /api/tags 元数据
  recommend.js   纯函数推荐算法
  targets.js     配置形状识别与 settings 写入计划
tests/           单元与端到端测试
scripts/probe.mjs 离线自检

打包与发布

npm 上的 dsh-context-window 已被另一个项目占用,因此本插件发布名为 dsh-context-window-tuner;功能与页面名称不变。

cd E:\AI\work-2\dsh-context-window-tuner

# 1) 生成可发布的 tarball(不需要登录)
npm pack --cache ../.npm-cache --pack-destination dist
#    dist/dsh-context-window-tuner-0.1.0.tgz

# 2) 从 tarball 安装到 profile(本地分发)
dsh plugin --profile desktop add ./dist/dsh-context-window-tuner-0.1.0.tgz

# 3) 发布到 npm(需要先登录并有该包名权限)
npm login
npm publish --access public

发布后即可在插件市场/命令行安装:

dsh plugin --profile desktop add dsh-context-window-tuner

许可

MIT