foxfetch 0.1.8__tar.gz → 0.2.0__tar.gz

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.
@@ -134,24 +134,16 @@ DSH has a native plugin API, and the plugin is published on npm. It holds **no l
134
134
  starts the service once and reshapes results for the DSH UI.
135
135
 
136
136
  ```powershell
137
- $profile = "$env:USERPROFILE\.dsh\profiles\desktop"
138
-
139
- # 1. install the plugin into the profile
140
- Push-Location $profile
141
- pnpm add dsh-foxfetch
142
- Pop-Location
143
-
144
- # 2. register the bundle (keep the entries already there)
145
- $pkg = Get-Content "$profile\package.json" -Raw | ConvertFrom-Json
146
- if ($pkg.dsh.profile.bundles -notcontains "dsh-foxfetch") {
147
- $pkg.dsh.profile.bundles += "dsh-foxfetch"
148
- }
149
- $pkg | ConvertTo-Json -Depth 20 | Set-Content "$profile\package.json"
150
-
151
- # 3. restart DSH
137
+ pip install foxfetch # the service (step 1, if not done yet)
138
+ foxfetch dsh-install # the plugin, and the two JSON lines it needs
152
139
  ```
153
140
 
154
- `~/.dsh/profiles/desktop/package.json` should end up looking like this:
141
+ `foxfetch dsh-install` locates the profile (honours `DSH_HOME`), runs
142
+ `pnpm add dsh-foxfetch` (falling back to the pnpm bundled with DSH, then to `npm install`), and
143
+ writes the dependency plus the bundle entry into `package.json`. `--dry-run` shows the change
144
+ without writing anything, `--skip-pnpm` only patches the JSON.
145
+
146
+ The resulting `~/.dsh/profiles/desktop/package.json`:
155
147
 
156
148
  ```json
157
149
  {
@@ -172,18 +164,21 @@ $pkg | ConvertTo-Json -Depth 20 | Set-Content "$profile\package.json"
172
164
  }
173
165
  ```
174
166
 
175
- **`pnpm` is not on PATH?** DSH ships its own:
167
+ **No profile directory yet?** Start DSH once, quit it, then run the command — the profile is
168
+ created on first launch and a hand-made one would be overwritten.
169
+
170
+ Doing it by hand instead (any package manager):
176
171
 
177
172
  ```powershell
178
- $dsh = "$env:USERPROFILE\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies"
179
- $node = Join-Path $dsh "node\bin\node.exe"
180
- $pnpm = Join-Path $dsh "pnpm\bin\pnpm.cjs"
181
- & $node $pnpm add dsh-foxfetch
173
+ $profile = "$env:USERPROFILE\.dsh\profiles\desktop"
174
+ Push-Location $profile
175
+ pnpm add dsh-foxfetch
176
+ Pop-Location
177
+ # then add "dsh-foxfetch" to dsh.profile.bundles by hand and restart DSH
182
178
  ```
183
179
 
184
180
  **Editing the plugin itself?** Link a checkout instead of the published package — replace the
185
- dependency with `"dsh-foxfetch": "link:C:/Users/<you>/.dsh/plugins/dsh-foxfetch"` after
186
- `git clone https://github.com/zhuchongba-01/foxfetch` anywhere you like.
181
+ dependency with `"dsh-foxfetch": "link:C:/Users/<you>/foxfetch/dsh"` after cloning the repo.
187
182
 
188
183
  ### Anything else (opencode, gemini, zcode, custom)
189
184
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: foxfetch
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: Fetch pages through a real Firefox engine (ruyijs) for AI agents: pass bot checks, run the page's own JavaScript, then hand the identity to Chromium when a screenshot is needed.
5
5
  Project-URL: Homepage, https://github.com/zhuchongba-01/foxfetch
6
6
  Project-URL: Repository, https://github.com/zhuchongba-01/foxfetch
@@ -66,23 +66,23 @@ Description-Content-Type: text/markdown
66
66
  pip install foxfetch
67
67
  ```
68
68
 
69
- **DSH(DeepSeek Harness)安装指令:**
69
+ **DSH(DeepSeek Harness)安装指令** —— 一条就够:
70
70
 
71
71
  ```powershell
72
- cd "$env:USERPROFILE\.dsh\profiles\desktop"
73
- pnpm add dsh-foxfetch
72
+ foxfetch dsh-install
74
73
  ```
75
74
 
76
- 再把 `"dsh-foxfetch"` 加进该目录 `package.json` 的 `dsh.profile.bundles`,重启 DSH。
75
+ 它会把插件装进 DSH profile、并自动改好 `package.json`(依赖 + `dsh.profile.bundles`)。
76
+ 完事重启 DSH 即可。加 `--dry-run` 只看不改。
77
77
 
78
- **其余软件安装指令:**
78
+ **其余软件安装指令** —— 只写配置,不用装包:
79
79
 
80
80
  ```bash
81
81
  pi mcp add foxfetch -- python -m foxfetch serve # Pi
82
82
  claude mcp add foxfetch -- python -m foxfetch serve # Claude Code
83
83
  ```
84
84
 
85
- Codex 和其它 MCP 客户端只写配置、不装包,见[下文](#详细安装)。
85
+ Codex 和其它 MCP 客户端见[下文](#详细安装)。
86
86
 
87
87
  ## 验证
88
88
 
@@ -183,33 +183,21 @@ command = "python"
183
183
  args = ["-m", "foxfetch", "serve"]
184
184
  ```
185
185
 
186
- ### DeepSeek Harness
187
-
188
- DSH 有原生插件机制,所以给它装插件而不是 MCP 条目。插件里**没有任何逻辑** —— 它启动同一个
189
- Python 服务,只负责把结果整理成 DSH 的卡片样式。
190
-
191
- > **DSH 要装两样,不是一样**:服务(`pip`,第 1 步)**加上**插件(npm)。
192
- > 插件只是转发壳,没有服务会立刻报 `cannot start the Python service`。
186
+ ### DeepSeek Harness(DSH)
193
187
 
194
188
  ```powershell
195
- # 1. 服务(和别的宿主一样 —— 这步不能跳)
196
189
  pip install foxfetch
190
+ foxfetch dsh-install
191
+ ```
197
192
 
198
- # 2. 插件,装进 DSH 的 profile
199
- cd "$env:USERPROFILE\.dsh\profiles\desktop"
200
- pnpm add dsh-foxfetch
201
-
202
- # 3. 登记(保留文件里已有的条目)
203
- $pkg = Get-Content package.json -Raw | ConvertFrom-Json
204
- if ($pkg.dsh.profile.bundles -notcontains "dsh-foxfetch") {
205
- $pkg.dsh.profile.bundles += "dsh-foxfetch"
206
- }
207
- $pkg | ConvertTo-Json -Depth 20 | Set-Content package.json
193
+ `dsh-install` 做的事:
208
194
 
209
- # 4. 重启 DSH
210
- ```
195
+ 1. 找到 profile 目录(`%USERPROFILE%\.dsh\profiles\desktop`,可用 `DSH_HOME` 覆盖)
196
+ 2. 跑 `pnpm add dsh-foxfetch`(pnpm 不在就用 DSH 自带的;都没有则退回 `npm install`)
197
+ 3. 把 `"dsh-foxfetch"` 写进 `package.json` 的 `dependencies` 和 `dsh.profile.bundles`
198
+ 4. 打印重启提示;**不会**自动启动 DSH
211
199
 
212
- 改完 `package.json` 应该长这样:
200
+ 改完的 `package.json` 应该长这样:
213
201
 
214
202
  ```json
215
203
  {
@@ -230,18 +218,15 @@ $pkg | ConvertTo-Json -Depth 20 | Set-Content package.json
230
218
  }
231
219
  ```
232
220
 
233
- **`pnpm` 不在 PATH 里?** DSH 自带一份:
221
+ **profile 目录不存在?** 先启动一次 DSH(等主窗口出现)再退出,然后重跑这条命令 ——
222
+ DSH 首次启动时才生成 profile,手建会被它覆盖。
234
223
 
235
- ```powershell
236
- $dsh = "$env:USERPROFILE\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies"
237
- $node = Join-Path $dsh "node\bin\node.exe"
238
- $pnpm = Join-Path $dsh "pnpm\bin\pnpm.cjs"
239
- & $node $pnpm add dsh-foxfetch
240
- ```
224
+ **想改插件源码?** 把这个依赖换成 `"dsh-foxfetch": "link:C:/你的路径/foxfetch/dsh"`,
225
+ 再在那个目录跑一次 `pnpm install`。
241
226
 
242
- 重启 DSH 后工具列表里应该有 `foxfetch_probe`、`foxfetch_run`、`foxfetch_net`、
243
- `foxfetch_handoff`、`foxfetch_close`、`foxfetch_cleanup`、`foxfetch_status` —— 并且**没有**
244
- `mcp__foxfetch__*` 这种重复条目。
227
+ 重启 DSH 后工具列表里应有 `foxfetch_probe`、`foxfetch_run`、`foxfetch_net`、
228
+ `foxfetch_handoff`、`foxfetch_close`、`foxfetch_cleanup`、`foxfetch_status`,并且**没有**
229
+ `mcp__foxfetch__*` 这类重复条目。
245
230
 
246
231
  ### 其它 MCP 客户端
247
232
 
@@ -18,24 +18,24 @@ when a screenshot is needed.
18
18
  pip install foxfetch
19
19
  ```
20
20
 
21
- **DSH (DeepSeek Harness) install command:**
21
+ **DSH (DeepSeek Harness) install command** — one line:
22
22
 
23
23
  ```powershell
24
- cd "$env:USERPROFILE\.dsh\profiles\desktop"
25
- pnpm add dsh-foxfetch
24
+ foxfetch dsh-install
26
25
  ```
27
26
 
28
- Then add `"dsh-foxfetch"` to `dsh.profile.bundles` in that folder's `package.json` and restart
29
- DSH.
27
+ It installs the plugin into the DSH profile and edits `package.json` for you (dependency plus
28
+ `dsh.profile.bundles`). Restart DSH afterwards. Add `--dry-run` to see the change without
29
+ writing it.
30
30
 
31
- **Everything else install command:**
31
+ **Everything else install command** — config only, no package:
32
32
 
33
33
  ```bash
34
34
  pi mcp add foxfetch -- python -m foxfetch serve # Pi
35
35
  claude mcp add foxfetch -- python -m foxfetch serve # Claude Code
36
36
  ```
37
37
 
38
- Codex and other MCP clients need config only, no package — see [below](#detailed-install).
38
+ Codex and other MCP clients: see [below](#detailed-install).
39
39
 
40
40
  ## Verify
41
41
 
@@ -133,34 +133,21 @@ command = "python"
133
133
  args = ["-m", "foxfetch", "serve"]
134
134
  ```
135
135
 
136
- ### DeepSeek Harness
137
-
138
- DSH has a native plugin API, so it gets a real plugin instead of an MCP entry. The plugin holds
139
- no logic — it starts the same Python service and reshapes results for the DSH UI.
140
-
141
- > **DSH needs two installs, not one:** the service (`pip`, step 1) **and** the plugin (npm).
142
- > The plugin is only a forwarder; without the service it fails immediately with
143
- > `cannot start the Python service`.
136
+ ### DeepSeek Harness (DSH)
144
137
 
145
138
  ```powershell
146
- # 1. service (same as everyone else — do not skip this)
147
139
  pip install foxfetch
140
+ foxfetch dsh-install
141
+ ```
148
142
 
149
- # 2. plugin, into the DSH profile
150
- cd "$env:USERPROFILE\.dsh\profiles\desktop"
151
- pnpm add dsh-foxfetch
152
-
153
- # 3. register it (keep the entries already in the file)
154
- $pkg = Get-Content package.json -Raw | ConvertFrom-Json
155
- if ($pkg.dsh.profile.bundles -notcontains "dsh-foxfetch") {
156
- $pkg.dsh.profile.bundles += "dsh-foxfetch"
157
- }
158
- $pkg | ConvertTo-Json -Depth 20 | Set-Content package.json
143
+ `dsh-install` does this:
159
144
 
160
- # 4. restart DSH
161
- ```
145
+ 1. locates the profile (`%USERPROFILE%\.dsh\profiles\desktop`, overridable with `DSH_HOME`)
146
+ 2. runs `pnpm add dsh-foxfetch` (falls back to the pnpm DSH ships, then to `npm install`)
147
+ 3. writes `"dsh-foxfetch"` into `dependencies` **and** `dsh.profile.bundles` of `package.json`
148
+ 4. prints the restart note; it never starts DSH for you
162
149
 
163
- The result should look like this:
150
+ The resulting `package.json`:
164
151
 
165
152
  ```json
166
153
  {
@@ -181,18 +168,15 @@ The result should look like this:
181
168
  }
182
169
  ```
183
170
 
184
- `pnpm` not on PATH? DSH ships its own:
171
+ **No profile directory?** Start DSH once (wait for the main window), quit it, run the command
172
+ again — DSH creates the profile on first launch and would overwrite a hand-made one.
185
173
 
186
- ```powershell
187
- $dsh = "$env:USERPROFILE\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies"
188
- $node = Join-Path $dsh "node\bin\node.exe"
189
- $pnpm = Join-Path $dsh "pnpm\bin\pnpm.cjs"
190
- & $node $pnpm add dsh-foxfetch
191
- ```
174
+ **Editing the plugin?** Replace that dependency with
175
+ `"dsh-foxfetch": "link:C:/your/path/foxfetch/dsh"` and run `pnpm install` there.
192
176
 
193
177
  After restarting DSH the tool list shows `foxfetch_probe`, `foxfetch_run`, `foxfetch_net`,
194
178
  `foxfetch_handoff`, `foxfetch_close`, `foxfetch_cleanup`, `foxfetch_status` — and no
195
- `mcp__foxfetch__*` entries.
179
+ `mcp__foxfetch__*` duplicates.
196
180
 
197
181
  ### Any other MCP client
198
182
 
@@ -17,23 +17,23 @@
17
17
  pip install foxfetch
18
18
  ```
19
19
 
20
- **DSH(DeepSeek Harness)安装指令:**
20
+ **DSH(DeepSeek Harness)安装指令** —— 一条就够:
21
21
 
22
22
  ```powershell
23
- cd "$env:USERPROFILE\.dsh\profiles\desktop"
24
- pnpm add dsh-foxfetch
23
+ foxfetch dsh-install
25
24
  ```
26
25
 
27
- 再把 `"dsh-foxfetch"` 加进该目录 `package.json` 的 `dsh.profile.bundles`,重启 DSH。
26
+ 它会把插件装进 DSH profile、并自动改好 `package.json`(依赖 + `dsh.profile.bundles`)。
27
+ 完事重启 DSH 即可。加 `--dry-run` 只看不改。
28
28
 
29
- **其余软件安装指令:**
29
+ **其余软件安装指令** —— 只写配置,不用装包:
30
30
 
31
31
  ```bash
32
32
  pi mcp add foxfetch -- python -m foxfetch serve # Pi
33
33
  claude mcp add foxfetch -- python -m foxfetch serve # Claude Code
34
34
  ```
35
35
 
36
- Codex 和其它 MCP 客户端只写配置、不装包,见[下文](#详细安装)。
36
+ Codex 和其它 MCP 客户端见[下文](#详细安装)。
37
37
 
38
38
  ## 验证
39
39
 
@@ -134,33 +134,21 @@ command = "python"
134
134
  args = ["-m", "foxfetch", "serve"]
135
135
  ```
136
136
 
137
- ### DeepSeek Harness
138
-
139
- DSH 有原生插件机制,所以给它装插件而不是 MCP 条目。插件里**没有任何逻辑** —— 它启动同一个
140
- Python 服务,只负责把结果整理成 DSH 的卡片样式。
141
-
142
- > **DSH 要装两样,不是一样**:服务(`pip`,第 1 步)**加上**插件(npm)。
143
- > 插件只是转发壳,没有服务会立刻报 `cannot start the Python service`。
137
+ ### DeepSeek Harness(DSH)
144
138
 
145
139
  ```powershell
146
- # 1. 服务(和别的宿主一样 —— 这步不能跳)
147
140
  pip install foxfetch
141
+ foxfetch dsh-install
142
+ ```
148
143
 
149
- # 2. 插件,装进 DSH 的 profile
150
- cd "$env:USERPROFILE\.dsh\profiles\desktop"
151
- pnpm add dsh-foxfetch
152
-
153
- # 3. 登记(保留文件里已有的条目)
154
- $pkg = Get-Content package.json -Raw | ConvertFrom-Json
155
- if ($pkg.dsh.profile.bundles -notcontains "dsh-foxfetch") {
156
- $pkg.dsh.profile.bundles += "dsh-foxfetch"
157
- }
158
- $pkg | ConvertTo-Json -Depth 20 | Set-Content package.json
144
+ `dsh-install` 做的事:
159
145
 
160
- # 4. 重启 DSH
161
- ```
146
+ 1. 找到 profile 目录(`%USERPROFILE%\.dsh\profiles\desktop`,可用 `DSH_HOME` 覆盖)
147
+ 2. 跑 `pnpm add dsh-foxfetch`(pnpm 不在就用 DSH 自带的;都没有则退回 `npm install`)
148
+ 3. 把 `"dsh-foxfetch"` 写进 `package.json` 的 `dependencies` 和 `dsh.profile.bundles`
149
+ 4. 打印重启提示;**不会**自动启动 DSH
162
150
 
163
- 改完 `package.json` 应该长这样:
151
+ 改完的 `package.json` 应该长这样:
164
152
 
165
153
  ```json
166
154
  {
@@ -181,18 +169,15 @@ $pkg | ConvertTo-Json -Depth 20 | Set-Content package.json
181
169
  }
182
170
  ```
183
171
 
184
- **`pnpm` 不在 PATH 里?** DSH 自带一份:
172
+ **profile 目录不存在?** 先启动一次 DSH(等主窗口出现)再退出,然后重跑这条命令 ——
173
+ DSH 首次启动时才生成 profile,手建会被它覆盖。
185
174
 
186
- ```powershell
187
- $dsh = "$env:USERPROFILE\.dsh\dsh-runtimes\dsh-primary-runtime\dependencies"
188
- $node = Join-Path $dsh "node\bin\node.exe"
189
- $pnpm = Join-Path $dsh "pnpm\bin\pnpm.cjs"
190
- & $node $pnpm add dsh-foxfetch
191
- ```
175
+ **想改插件源码?** 把这个依赖换成 `"dsh-foxfetch": "link:C:/你的路径/foxfetch/dsh"`,
176
+ 再在那个目录跑一次 `pnpm install`。
192
177
 
193
- 重启 DSH 后工具列表里应该有 `foxfetch_probe`、`foxfetch_run`、`foxfetch_net`、
194
- `foxfetch_handoff`、`foxfetch_close`、`foxfetch_cleanup`、`foxfetch_status` —— 并且**没有**
195
- `mcp__foxfetch__*` 这种重复条目。
178
+ 重启 DSH 后工具列表里应有 `foxfetch_probe`、`foxfetch_run`、`foxfetch_net`、
179
+ `foxfetch_handoff`、`foxfetch_close`、`foxfetch_cleanup`、`foxfetch_status`,并且**没有**
180
+ `mcp__foxfetch__*` 这类重复条目。
196
181
 
197
182
  ### 其它 MCP 客户端
198
183
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "foxfetch"
7
- version = "0.1.8"
7
+ version = "0.2.0"
8
8
  description = "Fetch pages through a real Firefox engine (ruyijs) for AI agents: pass bot checks, run the page's own JavaScript, then hand the identity to Chromium when a screenshot is needed."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,5 +1,5 @@
1
1
  """foxfetch: read pages through a real Firefox engine when plain HTTP is not enough."""
2
2
 
3
- __version__ = "0.1.8"
3
+ __version__ = "0.2.0"
4
4
 
5
5
  __all__ = ["__version__"]
@@ -27,6 +27,9 @@ def main(argv: list[str] | None = None) -> int:
27
27
  sub = parser.add_subparsers(dest="command")
28
28
 
29
29
  sub.add_parser("serve", help="start the MCP stdio server (default)")
30
+ dsh_parser = sub.add_parser("dsh-install", help="install the DSH plugin into the DSH profile")
31
+ dsh_parser.add_argument("--dry-run", action="store_true", help="show the change without writing")
32
+ dsh_parser.add_argument("--skip-pnpm", action="store_true", help="only patch package.json")
30
33
  sub.add_parser("doctor", help="check python, ruyijs, mcp, chromium and artifact usage")
31
34
  sub.add_parser("status", help="list live contexts and artifact usage")
32
35
 
@@ -53,6 +56,10 @@ def main(argv: list[str] | None = None) -> int:
53
56
 
54
57
  serve()
55
58
  return 0
59
+ if command == "dsh-install":
60
+ from .dsh_install import install
61
+
62
+ return install(dry_run=args.dry_run, skip_pnpm=args.skip_pnpm)
56
63
  if command == "doctor":
57
64
  report = run_doctor()
58
65
  _print(report)
@@ -0,0 +1,185 @@
1
+ """`foxfetch dsh-install`: put the DSH plugin in place without hand-editing JSON.
2
+
3
+ DSH loads plugins through its profile: a dependency in `package.json` plus a name in
4
+ `dsh.profile.bundles`. Both are two lines of JSON that are easy to get wrong (wrong array,
5
+ duplicate entry, `link:` path with backslashes), so this module does it and verifies the result.
6
+
7
+ It never starts DSH: the harness has to be restarted by the caller, because a running instance
8
+ holds the old profile in memory.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import json
14
+ import os
15
+ import shutil
16
+ import subprocess
17
+ import sys
18
+ from pathlib import Path
19
+ from typing import Any
20
+
21
+ PACKAGE = "dsh-foxfetch"
22
+ BUNDLE = "dsh-foxfetch"
23
+
24
+
25
+ def dsh_home() -> Path:
26
+ override = os.environ.get("DSH_HOME")
27
+ if override:
28
+ return Path(override).expanduser()
29
+ if os.name == "nt":
30
+ local = os.environ.get("LOCALAPPDATA")
31
+ roaming = os.environ.get("APPDATA")
32
+ candidate = Path(os.path.expanduser("~")) / ".dsh"
33
+ # DSH uses ~/.dsh on every platform; LOCALAPPDATA/APPDATA are only a fallback
34
+ if candidate.is_dir() or not (local or roaming):
35
+ return candidate
36
+ return candidate
37
+ return Path.home() / ".dsh"
38
+
39
+
40
+ def profile_dir() -> Path:
41
+ return dsh_home() / "profiles" / "desktop"
42
+
43
+
44
+ def find_pnpm() -> list[str] | None:
45
+ """pnpm on PATH, the copy DSH ships with its runtime, or npm as a last resort.
46
+
47
+ DSH's profile is a workspace package, so npm installs it fine; pnpm is preferred because
48
+ that is what the harness itself uses and it keeps one lockfile per profile.
49
+ """
50
+ direct = shutil.which("pnpm")
51
+ if direct:
52
+ return [direct]
53
+ runtimes = dsh_home() / "dsh-runtimes"
54
+ if runtimes.is_dir():
55
+ for runtime in sorted(runtimes.iterdir()):
56
+ deps = runtime / "dependencies"
57
+ node = deps / "node" / "bin" / ("node.exe" if os.name == "nt" else "node")
58
+ pnpm = deps / "pnpm" / "bin" / "pnpm.cjs"
59
+ if node.is_file() and pnpm.is_file():
60
+ return [str(node), str(pnpm)]
61
+ npm = shutil.which("npm")
62
+ if npm:
63
+ return [npm, "install"]
64
+ return None
65
+
66
+
67
+ def read_manifest(path: Path) -> dict[str, Any]:
68
+ try:
69
+ data: Any = json.loads(path.read_text(encoding="utf-8"))
70
+ if not isinstance(data, dict):
71
+ raise SystemExit(f"{path} does not contain a JSON object")
72
+ return data
73
+ except FileNotFoundError:
74
+ return {}
75
+ except json.JSONDecodeError as error:
76
+ raise SystemExit(f"{path} is not valid JSON: {error}") from error
77
+
78
+
79
+ def plan(manifest: dict[str, Any]) -> tuple[bool, bool]:
80
+ """(needs_dependency, needs_bundle) for the current manifest."""
81
+ dependencies = manifest.setdefault("dependencies", {}) if manifest else {}
82
+ needs_dep = PACKAGE not in dependencies
83
+ dsh_section = manifest.get("dsh") or {}
84
+ bundles = ((dsh_section.get("profile") or {}).get("bundles")) or []
85
+ needs_bundle = BUNDLE not in bundles
86
+ return needs_dep, needs_bundle
87
+
88
+
89
+ def patch_manifest(manifest: dict[str, Any], *, install: bool) -> dict[str, Any]:
90
+ """Add the dependency and the bundle entry, keeping everything else untouched."""
91
+ dependencies = manifest.setdefault("dependencies", {})
92
+ if PACKAGE not in dependencies:
93
+ # A version range, not a link: pnpm resolves it from the registry, so updates are a
94
+ # single `pnpm update`. Local development uses `link:` and is documented separately.
95
+ dependencies[PACKAGE] = "^0.1.1" if install else dependencies.get(PACKAGE, "^0.1.1")
96
+ dsh_section = manifest.setdefault("dsh", {})
97
+ profile = dsh_section.setdefault("profile", {})
98
+ bundles = profile.setdefault("bundles", [])
99
+ if BUNDLE not in bundles:
100
+ bundles.append(BUNDLE)
101
+ return manifest
102
+
103
+
104
+ def run_pnpm(command: list[str], cwd: Path, *, dry_run: bool) -> int:
105
+ printable = " ".join(command)
106
+ print(f" $ {printable}")
107
+ if dry_run:
108
+ return 0
109
+ result = subprocess.run(command, cwd=str(cwd), check=False)
110
+ return result.returncode
111
+
112
+
113
+ def _say(*parts: object) -> None:
114
+ print(*parts, flush=True)
115
+
116
+
117
+ def install(*, dry_run: bool = False, skip_pnpm: bool = False) -> int:
118
+ profile = profile_dir()
119
+ _say(f"foxfetch → DSH plugin")
120
+ _say(f" profile: {profile}")
121
+ if not profile.is_dir():
122
+ print(
123
+ " ✗ that profile does not exist yet.\n"
124
+ " Start DSH once (let the main window appear), quit it, then run this again:\n"
125
+ " DSH creates profiles/desktop on its first launch and would overwrite a hand-made one.",
126
+ file=sys.stderr,
127
+ )
128
+ return 2
129
+
130
+ manifest_path = profile / "package.json"
131
+ manifest = read_manifest(manifest_path)
132
+ needs_dep, needs_bundle = plan(manifest)
133
+ print(f" dependency {PACKAGE}: {'missing' if needs_dep else 'already there'}")
134
+ print(f" bundle entry: {'missing' if needs_bundle else 'already there'}")
135
+ if not needs_dep and not needs_bundle:
136
+ print(" ✓ nothing to do; restart DSH if you have not since installing")
137
+ return 0
138
+
139
+ pnpm = find_pnpm()
140
+ if needs_dep and not skip_pnpm:
141
+ if pnpm is None:
142
+ print(
143
+ " ✗ pnpm not found (neither on PATH nor in ~/.dsh/dsh-runtimes).\n"
144
+ f" Install it, then run: pnpm add {PACKAGE}",
145
+ file=sys.stderr,
146
+ )
147
+ return 3
148
+ if pnpm[1:] == ["install"]:
149
+ command = [pnpm[0], "install", PACKAGE]
150
+ else:
151
+ command = [*pnpm, "add", PACKAGE]
152
+ code = run_pnpm(command, profile, dry_run=dry_run)
153
+ if code != 0:
154
+ print(f" ✗ pnpm add failed with exit {code}", file=sys.stderr)
155
+ return code
156
+
157
+ patched = patch_manifest(manifest, install=True)
158
+ if dry_run:
159
+ print(" would write package.json:")
160
+ print(json.dumps(patched, indent=2, ensure_ascii=False))
161
+ else:
162
+ manifest_path.write_text(json.dumps(patched, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
163
+ print(f" ✓ wrote {manifest_path.name}")
164
+
165
+ print()
166
+ print(" next: restart DSH, then ask it for `foxfetch_status`.")
167
+ print(" expected tools: foxfetch_probe, foxfetch_run, foxfetch_net, foxfetch_handoff,")
168
+ print(" foxfetch_close, foxfetch_cleanup, foxfetch_status")
169
+ print(" if the tools do not appear, check that ~/.dsh/profiles/desktop/node_modules/"
170
+ f"{PACKAGE} exists")
171
+ return 0
172
+
173
+
174
+ def main(argv: list[str] | None = None) -> int:
175
+ import argparse
176
+
177
+ parser = argparse.ArgumentParser(prog="foxfetch dsh-install", description=__doc__)
178
+ parser.add_argument("--dry-run", action="store_true", help="show the change without touching anything")
179
+ parser.add_argument("--skip-pnpm", action="store_true", help="only patch package.json")
180
+ args = parser.parse_args(argv)
181
+ return install(dry_run=args.dry_run, skip_pnpm=args.skip_pnpm)
182
+
183
+
184
+ if __name__ == "__main__":
185
+ raise SystemExit(main())
File without changes
File without changes
File without changes
File without changes