droid-patch 0.6.0 → 0.7.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/README.md +92 -18
- package/README.zh-CN.md +92 -18
- package/dist/{alias-DKVU8DM_.mjs → alias-Bhigcbue.mjs} +28 -9
- package/dist/alias-Bhigcbue.mjs.map +1 -0
- package/dist/cli.mjs +1770 -36
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/alias-DKVU8DM_.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -32,6 +32,12 @@ npx droid-patch --websearch --standalone droid-local
|
|
|
32
32
|
# Patch with --reasoning-effort to enable reasoning for custom models
|
|
33
33
|
npx droid-patch --reasoning-effort droid-reasoning
|
|
34
34
|
|
|
35
|
+
# Patch with --statusline for a Claude-style terminal statusline
|
|
36
|
+
npx droid-patch --statusline droid-status
|
|
37
|
+
|
|
38
|
+
# Combine --websearch and --statusline
|
|
39
|
+
npx droid-patch --websearch --statusline droid-full-ui
|
|
40
|
+
|
|
35
41
|
# Combine multiple patches
|
|
36
42
|
npx droid-patch --is-custom --skip-login --websearch --reasoning-effort droid-full
|
|
37
43
|
|
|
@@ -57,20 +63,21 @@ npx droid-patch --skip-login -o /path/to/dir my-droid
|
|
|
57
63
|
|
|
58
64
|
### Available Options
|
|
59
65
|
|
|
60
|
-
| Option | Description
|
|
61
|
-
| --------------------- |
|
|
62
|
-
| `--is-custom` | Patch `isCustom:!0` to `isCustom:!1` (enables context compression for custom models)
|
|
63
|
-
| `--skip-login` | Bypass login by injecting a fake `FACTORY_API_KEY` into the binary
|
|
64
|
-
| `--api-base <url>` | Replace
|
|
65
|
-
| `--websearch` | Inject local WebSearch proxy with multiple search providers
|
|
66
|
-
| `--
|
|
67
|
-
| `--
|
|
68
|
-
| `--
|
|
69
|
-
| `--
|
|
70
|
-
|
|
|
71
|
-
| `-
|
|
72
|
-
|
|
|
73
|
-
|
|
|
66
|
+
| Option | Description |
|
|
67
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
68
|
+
| `--is-custom` | Patch `isCustom:!0` to `isCustom:!1` (enables context compression for custom models) |
|
|
69
|
+
| `--skip-login` | Bypass login by injecting a fake `FACTORY_API_KEY` into the binary |
|
|
70
|
+
| `--api-base <url>` | Replace API URL (standalone: binary patch, max 22 chars; with `--websearch`: proxy forward target, no limit) |
|
|
71
|
+
| `--websearch` | Inject local WebSearch proxy with multiple search providers |
|
|
72
|
+
| `--statusline` | Enable Claude-style terminal statusline (shows model, context, git info) |
|
|
73
|
+
| `--standalone` | Standalone mode: mock non-LLM Factory APIs (use with `--websearch`) |
|
|
74
|
+
| `--reasoning-effort` | Enable reasoning effort UI selector for custom models (set to high) |
|
|
75
|
+
| `--disable-telemetry` | Disable telemetry and Sentry error reporting |
|
|
76
|
+
| `--dry-run` | Verify patches without actually modifying the binary |
|
|
77
|
+
| `-p, --path <path>` | Path to the droid binary (default: `~/.droid/bin/droid`) |
|
|
78
|
+
| `-o, --output <dir>` | Output directory for patched binary (creates file without alias) |
|
|
79
|
+
| `--no-backup` | Skip creating backup of original binary |
|
|
80
|
+
| `-v, --verbose` | Enable verbose output |
|
|
74
81
|
|
|
75
82
|
### Manage Aliases and Files
|
|
76
83
|
|
|
@@ -164,13 +171,14 @@ Replaces all `process.env.FACTORY_API_KEY` references in the binary with a hardc
|
|
|
164
171
|
|
|
165
172
|
### `--api-base <url>`
|
|
166
173
|
|
|
167
|
-
|
|
174
|
+
Replace the Factory API base URL. Has different behavior depending on usage:
|
|
168
175
|
|
|
169
|
-
**
|
|
176
|
+
**1. Standalone (without `--websearch`)**
|
|
170
177
|
|
|
171
|
-
|
|
178
|
+
Binary patch to replace `https://api.factory.ai` with your custom URL.
|
|
172
179
|
|
|
173
|
-
**
|
|
180
|
+
- **Limitation**: URL must be 22 characters or less (same length as original URL)
|
|
181
|
+
- **Use case**: Direct API URL replacement without proxy
|
|
174
182
|
|
|
175
183
|
```bash
|
|
176
184
|
# Valid URLs (<=22 chars)
|
|
@@ -181,6 +189,19 @@ npx droid-patch --api-base "http://localhost:80" droid-local
|
|
|
181
189
|
npx droid-patch --api-base "http://my-long-domain.com:3000" droid # Error!
|
|
182
190
|
```
|
|
183
191
|
|
|
192
|
+
**2. With `--websearch`**
|
|
193
|
+
|
|
194
|
+
Sets the forward target URL for the WebSearch proxy by configuring the `FACTORY_API` variable in the proxy script.
|
|
195
|
+
|
|
196
|
+
- **No length limitation**: Any valid URL can be used
|
|
197
|
+
- **Use case**: Forward non-search requests to your custom LLM backend
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Forward to custom backend (no length limit)
|
|
201
|
+
npx droid-patch --websearch --api-base "http://127.0.0.1:20002" droid-custom
|
|
202
|
+
npx droid-patch --websearch --api-base "http://my-proxy.example.com:3000" droid-custom
|
|
203
|
+
```
|
|
204
|
+
|
|
184
205
|
### `--websearch`
|
|
185
206
|
|
|
186
207
|
Enables WebSearch functionality through a local proxy server that intercepts `/api/tools/exa/search` requests.
|
|
@@ -304,6 +325,49 @@ npx droid-patch --disable-telemetry droid-private
|
|
|
304
325
|
npx droid-patch --is-custom --skip-login --disable-telemetry droid-private
|
|
305
326
|
```
|
|
306
327
|
|
|
328
|
+
### `--statusline`
|
|
329
|
+
|
|
330
|
+
Enables a Claude-style statusline at the bottom of the terminal, displaying real-time session information.
|
|
331
|
+
|
|
332
|
+
**Purpose**: Provide at-a-glance visibility into model, context usage, git status, and token usage without interrupting the main UI.
|
|
333
|
+
|
|
334
|
+
**Features**:
|
|
335
|
+
|
|
336
|
+
- **Real-time context tracking**: Shows current token usage (cache read + new input)
|
|
337
|
+
- **Model info**: Displays the active model and provider
|
|
338
|
+
- **Token usage summary**: Shows session totals (In/Out/Cre/Read/Think) plus `LastOut` for the most recent reply
|
|
339
|
+
- **Git integration**: Shows current branch and diff summary (+insertions, -deletions)
|
|
340
|
+
- **Compaction indicator**: Shows when context compaction is in progress
|
|
341
|
+
- **PTY proxy architecture**: Reserves bottom row(s) for statusline without flickering
|
|
342
|
+
|
|
343
|
+
**How it works**:
|
|
344
|
+
|
|
345
|
+
1. A Python PTY wrapper intercepts terminal I/O and reserves bottom row(s)
|
|
346
|
+
2. A Node.js monitor script tails the Factory log file (`~/.factory/logs/droid-log-single.log`)
|
|
347
|
+
3. The monitor parses streaming token usage and emits statusline frames
|
|
348
|
+
4. The wrapper renders the latest frame on the reserved rows
|
|
349
|
+
|
|
350
|
+
**Usage**:
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
# Enable statusline only
|
|
354
|
+
npx droid-patch --statusline droid-status
|
|
355
|
+
|
|
356
|
+
# Combine with websearch
|
|
357
|
+
npx droid-patch --websearch --statusline droid-full-ui
|
|
358
|
+
|
|
359
|
+
# Combine with all features
|
|
360
|
+
npx droid-patch --is-custom --skip-login --websearch --statusline droid-ultimate
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**Example statusline display**:
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
Model: claude-sonnet-4-20250514 Prov: anthropic Ctx: 12345 (c8000+n4345) In:33 Out:1273 Cre:33.9k Read:25.9k Think:212 LastOut:130 ⎇ main (+10,-5) cwd: my-project
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
**Note**: The statusline requires Python 3 for the PTY wrapper. It works best in modern terminal emulators (iTerm2, Alacritty, Kitty, etc.). Apple Terminal is supported but uses a longer render interval to reduce flicker.
|
|
370
|
+
|
|
307
371
|
---
|
|
308
372
|
|
|
309
373
|
## WebSearch Configuration Guide
|
|
@@ -598,9 +662,18 @@ npx droid-patch --websearch --standalone droid-local
|
|
|
598
662
|
# Privacy mode: disable telemetry
|
|
599
663
|
npx droid-patch --disable-telemetry droid-private
|
|
600
664
|
|
|
665
|
+
# Statusline mode: Claude-style terminal statusline
|
|
666
|
+
npx droid-patch --statusline droid-status
|
|
667
|
+
|
|
668
|
+
# Websearch + Statusline: full UI experience
|
|
669
|
+
npx droid-patch --websearch --statusline droid-full-ui
|
|
670
|
+
|
|
601
671
|
# Full local setup: all features combined
|
|
602
672
|
npx droid-patch --is-custom --skip-login --websearch --standalone --disable-telemetry droid-full-local
|
|
603
673
|
|
|
674
|
+
# Ultimate setup: all features including statusline
|
|
675
|
+
npx droid-patch --is-custom --skip-login --websearch --standalone --statusline --disable-telemetry droid-ultimate
|
|
676
|
+
|
|
604
677
|
# Websearch with custom backend
|
|
605
678
|
npx droid-patch --websearch --api-base=http://127.0.0.1:20002 droid-custom
|
|
606
679
|
|
|
@@ -614,6 +687,7 @@ npx droid-patch list
|
|
|
614
687
|
# Clean up
|
|
615
688
|
npx droid-patch remove droid-search # remove single alias
|
|
616
689
|
npx droid-patch remove --flag=websearch # remove all websearch aliases
|
|
690
|
+
npx droid-patch remove --flag=statusline # remove all statusline aliases
|
|
617
691
|
npx droid-patch remove --flag=standalone # remove all standalone aliases
|
|
618
692
|
npx droid-patch remove --patch-version=0.4.0 # remove by droid-patch version
|
|
619
693
|
npx droid-patch clear # remove everything
|
package/README.zh-CN.md
CHANGED
|
@@ -32,6 +32,12 @@ npx droid-patch --websearch --standalone droid-local
|
|
|
32
32
|
# 使用 --reasoning-effort 为自定义模型启用推理功能
|
|
33
33
|
npx droid-patch --reasoning-effort droid-reasoning
|
|
34
34
|
|
|
35
|
+
# 使用 --statusline 启用 Claude 风格的终端状态栏
|
|
36
|
+
npx droid-patch --statusline droid-status
|
|
37
|
+
|
|
38
|
+
# 组合 --websearch 和 --statusline
|
|
39
|
+
npx droid-patch --websearch --statusline droid-full-ui
|
|
40
|
+
|
|
35
41
|
# 组合多个修补选项
|
|
36
42
|
npx droid-patch --is-custom --skip-login --websearch --reasoning-effort droid-full
|
|
37
43
|
|
|
@@ -57,20 +63,21 @@ npx droid-patch --skip-login -o /path/to/dir my-droid
|
|
|
57
63
|
|
|
58
64
|
### 可用选项
|
|
59
65
|
|
|
60
|
-
| 选项 | 说明
|
|
61
|
-
| --------------------- |
|
|
62
|
-
| `--is-custom` | 将 `isCustom:!0` 修改为 `isCustom:!1`(为自定义模型启用上下文压缩)
|
|
63
|
-
| `--skip-login` | 通过注入假的 `FACTORY_API_KEY` 跳过登录验证
|
|
64
|
-
| `--api-base <url>` |
|
|
65
|
-
| `--websearch` | 注入本地 WebSearch 代理,支持多个搜索提供商
|
|
66
|
-
| `--
|
|
67
|
-
| `--
|
|
68
|
-
| `--
|
|
69
|
-
| `--
|
|
70
|
-
|
|
|
71
|
-
| `-
|
|
72
|
-
|
|
|
73
|
-
|
|
|
66
|
+
| 选项 | 说明 |
|
|
67
|
+
| --------------------- | ----------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `--is-custom` | 将 `isCustom:!0` 修改为 `isCustom:!1`(为自定义模型启用上下文压缩) |
|
|
69
|
+
| `--skip-login` | 通过注入假的 `FACTORY_API_KEY` 跳过登录验证 |
|
|
70
|
+
| `--api-base <url>` | 替换 API URL(单独使用:二进制补丁,最多 22 字符;与 `--websearch` 配合:代理转发目标,无限制) |
|
|
71
|
+
| `--websearch` | 注入本地 WebSearch 代理,支持多个搜索提供商 |
|
|
72
|
+
| `--statusline` | 启用 Claude 风格的终端状态栏(显示模型、上下文、git 信息) |
|
|
73
|
+
| `--standalone` | 独立模式:mock 非 LLM 的 Factory API(与 `--websearch` 配合使用) |
|
|
74
|
+
| `--reasoning-effort` | 为自定义模型启用推理强度 UI 选择器(设置为 high) |
|
|
75
|
+
| `--disable-telemetry` | 禁用遥测数据上传和 Sentry 错误报告 |
|
|
76
|
+
| `--dry-run` | 验证修补但不实际修改二进制文件 |
|
|
77
|
+
| `-p, --path <path>` | droid 二进制文件路径(默认:`~/.droid/bin/droid`) |
|
|
78
|
+
| `-o, --output <dir>` | 修补后二进制文件的输出目录(直接创建文件,不创建别名) |
|
|
79
|
+
| `--no-backup` | 跳过创建原始二进制文件的备份 |
|
|
80
|
+
| `-v, --verbose` | 启用详细输出 |
|
|
74
81
|
|
|
75
82
|
### 管理别名和文件
|
|
76
83
|
|
|
@@ -164,13 +171,14 @@ export PATH="$HOME/.droid-patch/aliases:$PATH"
|
|
|
164
171
|
|
|
165
172
|
### `--api-base <url>`
|
|
166
173
|
|
|
167
|
-
|
|
174
|
+
替换 Factory API 基础 URL。根据使用方式有不同的行为:
|
|
168
175
|
|
|
169
|
-
|
|
176
|
+
**1. 单独使用(不与 `--websearch` 配合)**
|
|
170
177
|
|
|
171
|
-
|
|
178
|
+
通过二进制补丁将 `https://api.factory.ai` 替换为你的自定义 URL。
|
|
172
179
|
|
|
173
|
-
|
|
180
|
+
- **限制**:URL 必须不超过 22 个字符(与原始 URL 长度相同)
|
|
181
|
+
- **用途**:直接替换 API URL,不使用代理
|
|
174
182
|
|
|
175
183
|
```bash
|
|
176
184
|
# 有效的 URL(<=22 个字符)
|
|
@@ -181,6 +189,19 @@ npx droid-patch --api-base "http://localhost:80" droid-local
|
|
|
181
189
|
npx droid-patch --api-base "http://my-long-domain.com:3000" droid # 错误!
|
|
182
190
|
```
|
|
183
191
|
|
|
192
|
+
**2. 与 `--websearch` 配合使用**
|
|
193
|
+
|
|
194
|
+
通过配置代理脚本中的 `FACTORY_API` 变量来设置 WebSearch 代理的转发目标 URL。
|
|
195
|
+
|
|
196
|
+
- **无长度限制**:可以使用任何有效的 URL
|
|
197
|
+
- **用途**:将非搜索请求转发到你的自定义 LLM 后端
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# 转发到自定义后端(无长度限制)
|
|
201
|
+
npx droid-patch --websearch --api-base "http://127.0.0.1:20002" droid-custom
|
|
202
|
+
npx droid-patch --websearch --api-base "http://my-proxy.example.com:3000" droid-custom
|
|
203
|
+
```
|
|
204
|
+
|
|
184
205
|
### `--websearch`
|
|
185
206
|
|
|
186
207
|
通过本地代理服务器启用 WebSearch 功能,拦截 `/api/tools/exa/search` 请求。
|
|
@@ -304,6 +325,49 @@ npx droid-patch --disable-telemetry droid-private
|
|
|
304
325
|
npx droid-patch --is-custom --skip-login --disable-telemetry droid-private
|
|
305
326
|
```
|
|
306
327
|
|
|
328
|
+
### `--statusline`
|
|
329
|
+
|
|
330
|
+
在终端底部启用 Claude 风格的状态栏,实时显示会话信息。
|
|
331
|
+
|
|
332
|
+
**用途**:在不干扰主 UI 的情况下,一目了然地查看模型、上下文使用量、git 状态和 token 用量。
|
|
333
|
+
|
|
334
|
+
**特性**:
|
|
335
|
+
|
|
336
|
+
- **实时上下文追踪**:显示当前 token 使用量(缓存读取 + 新输入)
|
|
337
|
+
- **模型信息**:显示当前激活的模型和提供商
|
|
338
|
+
- **用量汇总**:显示会话累计(In/Out/Cre/Read/Think)并附带最近一次回复的 `LastOut`
|
|
339
|
+
- **Git 集成**:显示当前分支和差异摘要(+插入行数,-删除行数)
|
|
340
|
+
- **压缩指示器**:显示上下文压缩正在进行中
|
|
341
|
+
- **PTY 代理架构**:为状态栏预留底部行,避免闪烁
|
|
342
|
+
|
|
343
|
+
**工作原理**:
|
|
344
|
+
|
|
345
|
+
1. Python PTY 包装器拦截终端 I/O 并预留底部行
|
|
346
|
+
2. Node.js 监控脚本跟踪 Factory 日志文件(`~/.factory/logs/droid-log-single.log`)
|
|
347
|
+
3. 监控器解析流式 token 使用并输出状态栏帧
|
|
348
|
+
4. 包装器在预留行上渲染最新帧
|
|
349
|
+
|
|
350
|
+
**使用方法**:
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
# 仅启用状态栏
|
|
354
|
+
npx droid-patch --statusline droid-status
|
|
355
|
+
|
|
356
|
+
# 与 websearch 组合
|
|
357
|
+
npx droid-patch --websearch --statusline droid-full-ui
|
|
358
|
+
|
|
359
|
+
# 与所有功能组合
|
|
360
|
+
npx droid-patch --is-custom --skip-login --websearch --statusline droid-ultimate
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**状态栏显示示例**:
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
Model: claude-sonnet-4-20250514 Prov: anthropic Ctx: 12345 (c8000+n4345) In:33 Out:1273 Cre:33.9k Read:25.9k Think:212 LastOut:130 ⎇ main (+10,-5) cwd: my-project
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
**注意**:状态栏需要 Python 3 来运行 PTY 包装器。在现代终端模拟器(iTerm2、Alacritty、Kitty 等)中效果最佳。支持 Apple Terminal,但使用较长的渲染间隔以减少闪烁。
|
|
370
|
+
|
|
307
371
|
---
|
|
308
372
|
|
|
309
373
|
## WebSearch 配置指南
|
|
@@ -598,9 +662,18 @@ npx droid-patch --websearch --standalone droid-local
|
|
|
598
662
|
# 隐私模式:禁用遥测
|
|
599
663
|
npx droid-patch --disable-telemetry droid-private
|
|
600
664
|
|
|
665
|
+
# 状态栏模式:Claude 风格的终端状态栏
|
|
666
|
+
npx droid-patch --statusline droid-status
|
|
667
|
+
|
|
668
|
+
# Websearch + 状态栏:完整 UI 体验
|
|
669
|
+
npx droid-patch --websearch --statusline droid-full-ui
|
|
670
|
+
|
|
601
671
|
# 完全本地化:所有功能组合
|
|
602
672
|
npx droid-patch --is-custom --skip-login --websearch --standalone --disable-telemetry droid-full-local
|
|
603
673
|
|
|
674
|
+
# 终极设置:包含状态栏的所有功能
|
|
675
|
+
npx droid-patch --is-custom --skip-login --websearch --standalone --statusline --disable-telemetry droid-ultimate
|
|
676
|
+
|
|
604
677
|
# websearch + 自定义后端
|
|
605
678
|
npx droid-patch --websearch --api-base=http://127.0.0.1:20002 droid-custom
|
|
606
679
|
|
|
@@ -614,6 +687,7 @@ npx droid-patch list
|
|
|
614
687
|
# 清理
|
|
615
688
|
npx droid-patch remove droid-search # 删除单个别名
|
|
616
689
|
npx droid-patch remove --flag=websearch # 删除所有 websearch 别名
|
|
690
|
+
npx droid-patch remove --flag=statusline # 删除所有 statusline 别名
|
|
617
691
|
npx droid-patch remove --flag=standalone # 删除所有 standalone 别名
|
|
618
692
|
npx droid-patch remove --patch-version=0.4.0 # 按 droid-patch 版本删除
|
|
619
693
|
npx droid-patch clear # 删除所有
|
|
@@ -235,15 +235,16 @@ async function removeAliasMetadata(aliasName) {
|
|
|
235
235
|
/**
|
|
236
236
|
* Create a new metadata object with current timestamp
|
|
237
237
|
*/
|
|
238
|
-
function createMetadata(name, originalBinaryPath, patches,
|
|
238
|
+
function createMetadata(name, originalBinaryPath, patches, options) {
|
|
239
239
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
240
240
|
return {
|
|
241
241
|
name,
|
|
242
242
|
createdAt: now,
|
|
243
243
|
updatedAt: now,
|
|
244
244
|
originalBinaryPath,
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
aliasPath: options?.aliasPath,
|
|
246
|
+
droidPatchVersion: options?.droidPatchVersion,
|
|
247
|
+
droidVersion: options?.droidVersion,
|
|
247
248
|
patches
|
|
248
249
|
};
|
|
249
250
|
}
|
|
@@ -263,6 +264,7 @@ function formatPatches(patches) {
|
|
|
263
264
|
if (patches.reasoningEffort) applied.push("reasoningEffort");
|
|
264
265
|
if (patches.noTelemetry) applied.push("noTelemetry");
|
|
265
266
|
if (patches.standalone) applied.push("standalone");
|
|
267
|
+
if (patches.statusline) applied.push("statusline");
|
|
266
268
|
return applied.length > 0 ? applied.join(", ") : "(none)";
|
|
267
269
|
}
|
|
268
270
|
|
|
@@ -467,7 +469,7 @@ async function removeAlias(aliasName) {
|
|
|
467
469
|
if (existsSync(pathSymlink)) try {
|
|
468
470
|
if (lstatSync(pathSymlink).isSymbolicLink()) {
|
|
469
471
|
const target = await readlink(pathSymlink);
|
|
470
|
-
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy")) {
|
|
472
|
+
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) {
|
|
471
473
|
await unlink(pathSymlink);
|
|
472
474
|
console.log(styleText("green", ` Removed: ${pathSymlink}`));
|
|
473
475
|
removed = true;
|
|
@@ -519,6 +521,19 @@ async function removeAlias(aliasName) {
|
|
|
519
521
|
console.log(styleText("green", ` Removed legacy preload: ${preloadPath}`));
|
|
520
522
|
removed = true;
|
|
521
523
|
}
|
|
524
|
+
const statuslineDir = join(DROID_PATCH_DIR, "statusline");
|
|
525
|
+
const statuslineWrapperPath = join(statuslineDir, aliasName);
|
|
526
|
+
const statuslineMonitorPath = join(statuslineDir, `${aliasName}-statusline.js`);
|
|
527
|
+
if (existsSync(statuslineWrapperPath)) {
|
|
528
|
+
await unlink(statuslineWrapperPath);
|
|
529
|
+
console.log(styleText("green", ` Removed statusline wrapper: ${statuslineWrapperPath}`));
|
|
530
|
+
removed = true;
|
|
531
|
+
}
|
|
532
|
+
if (existsSync(statuslineMonitorPath)) {
|
|
533
|
+
await unlink(statuslineMonitorPath);
|
|
534
|
+
console.log(styleText("green", ` Removed statusline monitor: ${statuslineMonitorPath}`));
|
|
535
|
+
removed = true;
|
|
536
|
+
}
|
|
522
537
|
if (await removeAliasMetadata(aliasName)) {
|
|
523
538
|
console.log(styleText("green", ` Removed metadata`));
|
|
524
539
|
removed = true;
|
|
@@ -542,7 +557,7 @@ async function listAliases() {
|
|
|
542
557
|
try {
|
|
543
558
|
if (lstatSync(fullPath).isSymbolicLink()) {
|
|
544
559
|
const target = await readlink(fullPath);
|
|
545
|
-
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy")) aliases.push({
|
|
560
|
+
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) aliases.push({
|
|
546
561
|
name: file,
|
|
547
562
|
target,
|
|
548
563
|
location: pathDir,
|
|
@@ -797,7 +812,7 @@ async function removeAliasesByFilter(filter) {
|
|
|
797
812
|
try {
|
|
798
813
|
if (lstatSync(fullPath).isSymbolicLink()) {
|
|
799
814
|
const target = await readlink(fullPath);
|
|
800
|
-
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy")) aliasNames.add(file);
|
|
815
|
+
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) aliasNames.add(file);
|
|
801
816
|
}
|
|
802
817
|
} catch {}
|
|
803
818
|
}
|
|
@@ -832,6 +847,9 @@ async function removeAliasesByFilter(filter) {
|
|
|
832
847
|
case "websearch":
|
|
833
848
|
if (!patches.websearch) matches = false;
|
|
834
849
|
break;
|
|
850
|
+
case "statusline":
|
|
851
|
+
if (!patches.statusline) matches = false;
|
|
852
|
+
break;
|
|
835
853
|
case "reasoning-effort":
|
|
836
854
|
if (!patches.reasoningEffort) matches = false;
|
|
837
855
|
break;
|
|
@@ -882,7 +900,7 @@ async function clearAllAliases() {
|
|
|
882
900
|
try {
|
|
883
901
|
if (lstatSync(fullPath).isSymbolicLink()) {
|
|
884
902
|
const target = await readlink(fullPath);
|
|
885
|
-
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy")) aliasNames.add(file);
|
|
903
|
+
if (target.includes(".droid-patch/bins") || target.includes(".droid-patch/websearch") || target.includes(".droid-patch/proxy") || target.includes(".droid-patch/statusline")) aliasNames.add(file);
|
|
886
904
|
}
|
|
887
905
|
} catch {}
|
|
888
906
|
}
|
|
@@ -912,7 +930,8 @@ async function clearAllAliases() {
|
|
|
912
930
|
join(DROID_PATCH_DIR, "bins"),
|
|
913
931
|
join(DROID_PATCH_DIR, "aliases"),
|
|
914
932
|
join(DROID_PATCH_DIR, "proxy"),
|
|
915
|
-
join(DROID_PATCH_DIR, "websearch")
|
|
933
|
+
join(DROID_PATCH_DIR, "websearch"),
|
|
934
|
+
join(DROID_PATCH_DIR, "statusline")
|
|
916
935
|
];
|
|
917
936
|
for (const dir of dirsToClean) if (existsSync(dir)) try {
|
|
918
937
|
const files = readdirSync(dir);
|
|
@@ -958,4 +977,4 @@ async function clearAllAliases() {
|
|
|
958
977
|
|
|
959
978
|
//#endregion
|
|
960
979
|
export { removeAlias as a, restoreOriginal as c, listAllMetadata as d, loadAliasMetadata as f, listAliases as i, createMetadata as l, patchDroid as m, createAlias as n, removeAliasesByFilter as o, saveAliasMetadata as p, createAliasForWrapper as r, replaceOriginal as s, clearAllAliases as t, formatPatches as u };
|
|
961
|
-
//# sourceMappingURL=alias-
|
|
980
|
+
//# sourceMappingURL=alias-Bhigcbue.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alias-Bhigcbue.mjs","names":["results: PatchResult[]","positions: number[]","metaList: AliasMetadata[]","applied: string[]","exportLine: string","binaryDest","aliases: AliasInfo[]","matchingAliases: string[]"],"sources":["../src/patcher.ts","../src/metadata.ts","../src/alias.ts"],"sourcesContent":["import { readFile, writeFile, copyFile, chmod, stat } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { execSync } from \"node:child_process\";\nimport { styleText } from \"node:util\";\n\nexport interface Patch {\n name: string;\n description: string;\n pattern: Buffer;\n replacement: Buffer;\n}\n\nexport interface PatchOptions {\n inputPath: string;\n outputPath?: string;\n patches: Patch[];\n dryRun?: boolean;\n backup?: boolean;\n verbose?: boolean;\n}\n\ninterface PatchResult {\n name: string;\n found: number;\n positions?: number[];\n success: boolean;\n alreadyPatched?: boolean;\n}\n\nexport interface PatchDroidResult {\n success: boolean;\n dryRun?: boolean;\n results: PatchResult[];\n outputPath?: string;\n noPatchNeeded?: boolean;\n patchedCount?: number;\n}\n\nexport async function patchDroid(options: PatchOptions): Promise<PatchDroidResult> {\n const {\n inputPath,\n outputPath,\n patches,\n dryRun = false,\n backup = true,\n verbose = false,\n } = options;\n\n const finalOutputPath = outputPath || `${inputPath}.patched`;\n\n if (!existsSync(inputPath)) {\n throw new Error(`Binary not found: ${inputPath}`);\n }\n\n const stats = await stat(inputPath);\n const fileSizeMB = (stats.size / (1024 * 1024)).toFixed(2);\n\n console.log(styleText(\"white\", `[*] Reading binary: ${styleText(\"cyan\", inputPath)}`));\n console.log(styleText(\"white\", `[*] File size: ${styleText(\"cyan\", fileSizeMB)} MB`));\n console.log();\n\n const data = await readFile(inputPath);\n const buffer = Buffer.from(data);\n\n // Use a working buffer that gets updated after each patch application\n // This ensures later patches search against the already-patched content\n const workingBuffer = Buffer.from(buffer);\n\n const results: PatchResult[] = [];\n\n for (const patch of patches) {\n console.log(styleText(\"white\", `[*] Checking patch: ${styleText(\"yellow\", patch.name)}`));\n console.log(styleText(\"gray\", ` ${patch.description}`));\n\n // Search in the working buffer (which may have earlier patches applied)\n const positions = findAllPositions(workingBuffer, patch.pattern);\n\n if (positions.length === 0) {\n console.log(styleText(\"yellow\", ` ! Pattern not found - may already be patched`));\n results.push({\n name: patch.name,\n found: 0,\n success: false,\n alreadyPatched: workingBuffer.includes(patch.replacement),\n });\n\n const replacementPositions = findAllPositions(workingBuffer, patch.replacement);\n if (replacementPositions.length > 0) {\n console.log(\n styleText(\n \"blue\",\n ` ✓ Found ${replacementPositions.length} occurrences of patched pattern`,\n ),\n );\n console.log(styleText(\"blue\", ` ✓ Binary appears to be already patched`));\n results[results.length - 1].alreadyPatched = true;\n results[results.length - 1].success = true;\n }\n continue;\n }\n\n console.log(styleText(\"green\", ` ✓ Found ${positions.length} occurrences`));\n\n if (verbose) {\n for (const pos of positions.slice(0, 5)) {\n const context = getContext(workingBuffer, pos, patch.pattern.length, 25);\n console.log(\n styleText(\"gray\", ` @ 0x${pos.toString(16).padStart(8, \"0\")}: ...${context}...`),\n );\n }\n if (positions.length > 5) {\n console.log(styleText(\"gray\", ` ... and ${positions.length - 5} more`));\n }\n }\n\n // Apply patch immediately to working buffer so later patches see updated content\n if (!dryRun) {\n for (const pos of positions) {\n patch.replacement.copy(workingBuffer, pos);\n }\n }\n\n results.push({\n name: patch.name,\n found: positions.length,\n positions,\n success: true,\n });\n }\n\n console.log();\n\n if (dryRun) {\n console.log(styleText(\"blue\", \"─\".repeat(60)));\n console.log(styleText([\"blue\", \"bold\"], \" DRY RUN RESULTS\"));\n console.log(styleText(\"blue\", \"─\".repeat(60)));\n console.log();\n\n for (const result of results) {\n if (result.alreadyPatched) {\n console.log(styleText(\"blue\", ` [✓] ${result.name}: Already patched`));\n } else if (result.found > 0) {\n console.log(\n styleText(\"green\", ` [✓] ${result.name}: ${result.found} occurrences will be patched`),\n );\n } else {\n console.log(styleText(\"yellow\", ` [!] ${result.name}: Pattern not found`));\n }\n }\n\n return {\n success: results.every((r) => r.success || r.alreadyPatched),\n dryRun: true,\n results,\n };\n }\n\n const patchesNeeded = results.filter((r) => r.found > 0 && !r.alreadyPatched);\n\n if (patchesNeeded.length === 0) {\n const allPatched = results.every((r) => r.alreadyPatched);\n if (allPatched) {\n console.log(styleText(\"blue\", \"[*] All patches already applied. Binary is up to date.\"));\n return {\n success: true,\n outputPath: inputPath,\n results,\n noPatchNeeded: true,\n };\n }\n console.log(styleText(\"yellow\", \"[!] No patches could be applied.\"));\n return { success: false, results };\n }\n\n if (backup) {\n const backupPath = `${inputPath}.backup`;\n if (!existsSync(backupPath)) {\n await copyFile(inputPath, backupPath);\n console.log(styleText(\"white\", `[*] Created backup: ${styleText(\"cyan\", backupPath)}`));\n } else {\n console.log(styleText(\"gray\", `[*] Backup already exists: ${backupPath}`));\n }\n }\n\n console.log(styleText(\"white\", \"[*] Applying patches...\"));\n // Patches have already been applied to workingBuffer during the check phase\n // Count total patches applied\n const totalPatched = results.reduce((sum, r) => sum + (r.positions?.length || 0), 0);\n\n console.log(styleText(\"green\", `[*] Applied ${totalPatched} patches`));\n\n await writeFile(finalOutputPath, workingBuffer);\n console.log(\n styleText(\"white\", `[*] Patched binary saved: ${styleText(\"cyan\", finalOutputPath)}`),\n );\n\n await chmod(finalOutputPath, 0o755);\n console.log(styleText(\"gray\", \"[*] Set executable permission\"));\n\n console.log();\n console.log(styleText(\"white\", \"[*] Verifying patches...\"));\n const verifyBuffer = await readFile(finalOutputPath);\n\n let allVerified = true;\n for (const patch of patches) {\n const oldCount = findAllPositions(verifyBuffer, patch.pattern).length;\n const newCount = findAllPositions(verifyBuffer, patch.replacement).length;\n\n if (oldCount === 0) {\n console.log(styleText(\"green\", ` ✓ ${patch.name}: Verified (${newCount} patched)`));\n } else {\n console.log(styleText(\"red\", ` ✗ ${patch.name}: ${oldCount} occurrences not patched`));\n allVerified = false;\n }\n }\n\n if (allVerified) {\n console.log();\n console.log(styleText(\"green\", \"[+] All patches verified successfully!\"));\n }\n\n if (process.platform === \"darwin\") {\n console.log();\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${finalOutputPath}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(styleText(\"yellow\", \"[!] Could not re-sign binary\"));\n console.log(\n styleText(\n \"gray\",\n ` You may need to run: codesign --force --deep --sign - ${finalOutputPath}`,\n ),\n );\n }\n\n try {\n execSync(`xattr -cr \"${finalOutputPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n return {\n success: allVerified,\n outputPath: finalOutputPath,\n results,\n patchedCount: totalPatched,\n };\n}\n\nfunction findAllPositions(buffer: Buffer, pattern: Buffer): number[] {\n const positions: number[] = [];\n let pos = 0;\n\n while (true) {\n pos = buffer.indexOf(pattern, pos);\n if (pos === -1) break;\n positions.push(pos);\n pos += pattern.length;\n }\n\n return positions;\n}\n\nfunction getContext(\n buffer: Buffer,\n position: number,\n patternLength: number,\n contextSize: number,\n): string {\n const start = Math.max(0, position - contextSize);\n const end = Math.min(buffer.length, position + patternLength + contextSize);\n const slice = buffer.slice(start, end);\n\n let str = \"\";\n for (let i = 0; i < slice.length; i++) {\n const c = slice[i];\n if (c >= 32 && c < 127) {\n str += String.fromCharCode(c);\n } else {\n str += \".\";\n }\n }\n return str;\n}\n","/**\n * Alias Metadata Management\n *\n * Stores and retrieves metadata about created aliases, including\n * which patches were applied. This enables the `update` command\n * to re-apply the same patches when the original droid binary is updated.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, unlink, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\n/**\n * Metadata structure for an alias\n */\nexport interface AliasMetadata {\n /** Alias name */\n name: string;\n /** ISO timestamp when created */\n createdAt: string;\n /** ISO timestamp when last updated */\n updatedAt: string;\n /** Path to the original droid binary used for patching */\n originalBinaryPath: string;\n /** Path where the alias symlink was created */\n aliasPath?: string;\n /** droid-patch version used to create this alias */\n droidPatchVersion?: string;\n /** droid binary version */\n droidVersion?: string;\n /** Patches that were applied */\n patches: {\n isCustom: boolean;\n skipLogin: boolean;\n /** API base URL for binary patching or websearch forward target */\n apiBase: string | null;\n /** Whether websearch is enabled */\n websearch: boolean;\n /** Whether statusline wrapper is enabled */\n statusline?: boolean;\n /** @deprecated Old proxy field, kept for backward compatibility */\n proxy?: string | null;\n reasoningEffort: boolean;\n /** Whether telemetry/Sentry is disabled */\n noTelemetry?: boolean;\n /** Standalone mode: mock non-LLM Factory APIs */\n standalone?: boolean;\n };\n}\n\n// Directory for storing metadata files\nconst META_DIR = join(homedir(), \".droid-patch\", \"meta\");\n\n/**\n * Ensure metadata directory exists\n */\nasync function ensureMetaDir(): Promise<void> {\n if (!existsSync(META_DIR)) {\n await mkdir(META_DIR, { recursive: true });\n }\n}\n\n/**\n * Get the path to a metadata file for an alias\n */\nfunction getMetaPath(aliasName: string): string {\n return join(META_DIR, `${aliasName}.json`);\n}\n\n/**\n * Save alias metadata to disk\n */\nexport async function saveAliasMetadata(meta: AliasMetadata): Promise<void> {\n await ensureMetaDir();\n const metaPath = getMetaPath(meta.name);\n await writeFile(metaPath, JSON.stringify(meta, null, 2));\n}\n\n/**\n * Load alias metadata from disk\n * Returns null if metadata doesn't exist\n */\nexport async function loadAliasMetadata(aliasName: string): Promise<AliasMetadata | null> {\n const metaPath = getMetaPath(aliasName);\n if (!existsSync(metaPath)) {\n return null;\n }\n try {\n const content = await readFile(metaPath, \"utf-8\");\n return JSON.parse(content) as AliasMetadata;\n } catch {\n return null;\n }\n}\n\n/**\n * List all alias metadata\n */\nexport async function listAllMetadata(): Promise<AliasMetadata[]> {\n await ensureMetaDir();\n\n const files = await readdir(META_DIR);\n const metaList: AliasMetadata[] = [];\n\n for (const file of files) {\n if (!file.endsWith(\".json\")) continue;\n\n const aliasName = file.replace(/\\.json$/, \"\");\n const meta = await loadAliasMetadata(aliasName);\n if (meta) {\n metaList.push(meta);\n }\n }\n\n return metaList;\n}\n\n/**\n * Remove alias metadata\n */\nexport async function removeAliasMetadata(aliasName: string): Promise<boolean> {\n const metaPath = getMetaPath(aliasName);\n if (!existsSync(metaPath)) {\n return false;\n }\n try {\n await unlink(metaPath);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Create a new metadata object with current timestamp\n */\nexport function createMetadata(\n name: string,\n originalBinaryPath: string,\n patches: AliasMetadata[\"patches\"],\n options?: {\n droidPatchVersion?: string;\n droidVersion?: string;\n aliasPath?: string;\n },\n): AliasMetadata {\n const now = new Date().toISOString();\n return {\n name,\n createdAt: now,\n updatedAt: now,\n originalBinaryPath,\n aliasPath: options?.aliasPath,\n droidPatchVersion: options?.droidPatchVersion,\n droidVersion: options?.droidVersion,\n patches,\n };\n}\n\n/**\n * Format patches for display\n */\nexport function formatPatches(patches: AliasMetadata[\"patches\"]): string {\n const applied: string[] = [];\n if (patches.isCustom) applied.push(\"isCustom\");\n if (patches.skipLogin) applied.push(\"skipLogin\");\n // Show apiBase only when not using websearch (binary patch mode)\n if (patches.apiBase && !patches.websearch) applied.push(`apiBase(${patches.apiBase})`);\n // Show websearch with optional custom target\n if (patches.websearch) {\n const target = patches.apiBase || \"api.factory.ai\";\n applied.push(`websearch(${target})`);\n }\n // Support old proxy field for backward compatibility\n if (patches.proxy && !patches.websearch) applied.push(`websearch(${patches.proxy})`);\n if (patches.reasoningEffort) applied.push(\"reasoningEffort\");\n if (patches.noTelemetry) applied.push(\"noTelemetry\");\n if (patches.standalone) applied.push(\"standalone\");\n if (patches.statusline) applied.push(\"statusline\");\n return applied.length > 0 ? applied.join(\", \") : \"(none)\";\n}\n","import {\n existsSync,\n mkdirSync,\n readdirSync,\n unlinkSync,\n lstatSync,\n readFileSync,\n appendFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { symlink, readlink, unlink, copyFile, chmod } from \"node:fs/promises\";\nimport { join, basename, dirname } from \"node:path\";\nimport { homedir } from \"node:os\";\nimport { execSync } from \"node:child_process\";\nimport { styleText } from \"node:util\";\nimport { removeAliasMetadata, loadAliasMetadata, formatPatches } from \"./metadata.ts\";\n\nconst DROID_PATCH_DIR = join(homedir(), \".droid-patch\");\nconst ALIASES_DIR = join(DROID_PATCH_DIR, \"aliases\");\nconst BINS_DIR = join(DROID_PATCH_DIR, \"bins\");\n\nconst COMMON_PATH_DIRS = [\n join(homedir(), \".local/bin\"),\n join(homedir(), \"bin\"),\n join(homedir(), \".bin\"),\n \"/opt/homebrew/bin\",\n \"/usr/local/bin\",\n join(homedir(), \".npm-global/bin\"),\n join(homedir(), \".npm/bin\"),\n join(homedir(), \".pnpm-global/bin\"),\n join(homedir(), \".yarn/bin\"),\n join(homedir(), \".config/yarn/global/node_modules/.bin\"),\n join(homedir(), \".cargo/bin\"),\n join(homedir(), \"go/bin\"),\n join(homedir(), \".deno/bin\"),\n join(homedir(), \".bun/bin\"),\n join(homedir(), \".local/share/mise/shims\"),\n join(homedir(), \".asdf/shims\"),\n join(homedir(), \".nvm/current/bin\"),\n join(homedir(), \".volta/bin\"),\n join(homedir(), \".fnm/current/bin\"),\n];\n\nfunction ensureDirectories(): void {\n if (!existsSync(DROID_PATCH_DIR)) {\n mkdirSync(DROID_PATCH_DIR, { recursive: true });\n }\n if (!existsSync(ALIASES_DIR)) {\n mkdirSync(ALIASES_DIR, { recursive: true });\n }\n if (!existsSync(BINS_DIR)) {\n mkdirSync(BINS_DIR, { recursive: true });\n }\n}\n\nfunction checkPathInclusion(): boolean {\n const pathEnv = process.env.PATH || \"\";\n return pathEnv.split(\":\").includes(ALIASES_DIR);\n}\n\nexport function findWritablePathDir(): string | null {\n const pathEnv = process.env.PATH || \"\";\n const pathDirs = pathEnv.split(\":\");\n\n for (const dir of COMMON_PATH_DIRS) {\n if (pathDirs.includes(dir)) {\n try {\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const testFile = join(dir, `.droid-patch-test-${Date.now()}`);\n writeFileSync(testFile, \"\");\n unlinkSync(testFile);\n return dir;\n } catch {\n continue;\n }\n }\n }\n\n return null;\n}\n\nfunction getShellConfigPath(): string {\n const shell = process.env.SHELL || \"/bin/bash\";\n const shellName = basename(shell);\n\n switch (shellName) {\n case \"zsh\":\n return join(homedir(), \".zshrc\");\n case \"bash\": {\n const bashProfile = join(homedir(), \".bash_profile\");\n if (existsSync(bashProfile)) return bashProfile;\n return join(homedir(), \".bashrc\");\n }\n case \"fish\":\n return join(homedir(), \".config/fish/config.fish\");\n default:\n return join(homedir(), \".profile\");\n }\n}\n\nfunction isPathConfigured(shellConfigPath: string): boolean {\n if (!existsSync(shellConfigPath)) {\n return false;\n }\n\n try {\n const content = readFileSync(shellConfigPath, \"utf-8\");\n return content.includes(\".droid-patch/aliases\") || content.includes(\"droid-patch/aliases\");\n } catch {\n return false;\n }\n}\n\nfunction addPathToShellConfig(shellConfigPath: string, verbose = false): boolean {\n const shell = process.env.SHELL || \"/bin/bash\";\n const shellName = basename(shell);\n\n let exportLine: string;\n if (shellName === \"fish\") {\n exportLine = `\\n# Added by droid-patch\\nfish_add_path \"${ALIASES_DIR}\"\\n`;\n } else {\n exportLine = `\\n# Added by droid-patch\\nexport PATH=\"${ALIASES_DIR}:$PATH\"\\n`;\n }\n\n try {\n appendFileSync(shellConfigPath, exportLine);\n if (verbose) {\n console.log(styleText(\"gray\", ` Added PATH export to: ${shellConfigPath}`));\n }\n return true;\n } catch (error) {\n console.log(\n styleText(\"yellow\", `[!] Could not write to ${shellConfigPath}: ${(error as Error).message}`),\n );\n return false;\n }\n}\n\nexport interface CreateAliasResult {\n aliasPath: string;\n binaryPath: string;\n immediate?: boolean;\n}\n\nexport async function createAlias(\n patchedBinaryPath: string,\n aliasName: string,\n verbose = false,\n): Promise<CreateAliasResult> {\n ensureDirectories();\n\n console.log(styleText(\"white\", `[*] Creating alias: ${styleText(\"cyan\", aliasName)}`));\n\n const writablePathDir = findWritablePathDir();\n\n if (writablePathDir) {\n const targetPath = join(writablePathDir, aliasName);\n const binaryDest = join(BINS_DIR, `${aliasName}-patched`);\n await copyFile(patchedBinaryPath, binaryDest);\n await chmod(binaryDest, 0o755);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Stored binary: ${binaryDest}`));\n }\n\n if (existsSync(targetPath)) {\n await unlink(targetPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing: ${targetPath}`));\n }\n }\n\n await symlink(binaryDest, targetPath);\n\n if (process.platform === \"darwin\") {\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${binaryDest}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(styleText(\"yellow\", \"[!] Could not re-sign binary\"));\n }\n\n try {\n execSync(`xattr -cr \"${binaryDest}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log(styleText(\"green\", `[*] Created: ${targetPath} -> ${binaryDest}`));\n console.log();\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" ALIAS READY - NO ACTION REQUIRED!\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(\n styleText(\n \"white\",\n `The alias \"${styleText([\"cyan\", \"bold\"], aliasName)}\" is now available in ALL terminals.`,\n ),\n );\n console.log(styleText(\"gray\", `(Installed to: ${writablePathDir})`));\n\n return {\n aliasPath: targetPath,\n binaryPath: binaryDest,\n immediate: true,\n };\n }\n\n console.log(styleText(\"yellow\", \"[*] No writable PATH directory found, using fallback...\"));\n\n const binaryDest = join(BINS_DIR, `${aliasName}-patched`);\n await copyFile(patchedBinaryPath, binaryDest);\n await chmod(binaryDest, 0o755);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Copied binary to: ${binaryDest}`));\n }\n\n if (process.platform === \"darwin\") {\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${binaryDest}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(\n styleText(\"yellow\", \"[!] Could not re-sign binary. You may need to do this manually:\"),\n );\n console.log(styleText(\"gray\", ` codesign --force --deep --sign - \"${binaryDest}\"`));\n }\n\n try {\n execSync(`xattr -cr \"${binaryDest}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n const symlinkPath = join(ALIASES_DIR, aliasName);\n\n if (existsSync(symlinkPath)) {\n await unlink(symlinkPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing symlink`));\n }\n }\n\n await symlink(binaryDest, symlinkPath);\n await chmod(symlinkPath, 0o755);\n\n console.log(styleText(\"green\", `[*] Created symlink: ${symlinkPath} -> ${binaryDest}`));\n\n const shellConfig = getShellConfigPath();\n\n if (!checkPathInclusion()) {\n if (!isPathConfigured(shellConfig)) {\n console.log(styleText(\"white\", `[*] Configuring PATH in ${shellConfig}...`));\n\n if (addPathToShellConfig(shellConfig, verbose)) {\n console.log(styleText(\"green\", `[*] PATH configured successfully!`));\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" ACTION REQUIRED\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"To use the alias in this terminal, run:\"));\n console.log();\n console.log(styleText(\"cyan\", ` source ${shellConfig}`));\n console.log();\n console.log(styleText(\"gray\", \"Or simply open a new terminal window.\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n } else {\n const exportLine = `export PATH=\"${ALIASES_DIR}:$PATH\"`;\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" Manual PATH Configuration Required\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"Add this line to your shell config:\"));\n console.log(styleText(\"cyan\", ` ${exportLine}`));\n console.log();\n console.log(styleText(\"gray\", `Shell config file: ${shellConfig}`));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already configured in ${shellConfig}`));\n console.log();\n console.log(\n styleText(\n \"yellow\",\n `Note: Run \\`source ${shellConfig}\\` or open a new terminal to use the alias.`,\n ),\n );\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already includes aliases directory`));\n console.log();\n console.log(\n styleText(\n \"green\",\n `You can now use \"${styleText([\"cyan\", \"bold\"], aliasName)}\" command directly!`,\n ),\n );\n }\n\n return {\n aliasPath: symlinkPath,\n binaryPath: binaryDest,\n };\n}\n\nexport async function removeAlias(aliasName: string): Promise<void> {\n console.log(styleText(\"white\", `[*] Removing alias: ${styleText(\"cyan\", aliasName)}`));\n\n let removed = false;\n\n // Check common PATH directories for symlinks\n for (const pathDir of COMMON_PATH_DIRS) {\n const pathSymlink = join(pathDir, aliasName);\n if (existsSync(pathSymlink)) {\n try {\n const stats = lstatSync(pathSymlink);\n if (stats.isSymbolicLink()) {\n const target = await readlink(pathSymlink);\n // Support regular aliases, old websearch wrappers, and new proxy wrappers\n if (\n target.includes(\".droid-patch/bins\") ||\n target.includes(\".droid-patch/websearch\") ||\n target.includes(\".droid-patch/proxy\") ||\n target.includes(\".droid-patch/statusline\")\n ) {\n await unlink(pathSymlink);\n console.log(styleText(\"green\", ` Removed: ${pathSymlink}`));\n removed = true;\n }\n }\n } catch {\n // Ignore\n }\n }\n }\n\n // Check aliases directory\n const symlinkPath = join(ALIASES_DIR, aliasName);\n if (existsSync(symlinkPath)) {\n await unlink(symlinkPath);\n console.log(styleText(\"green\", ` Removed: ${symlinkPath}`));\n removed = true;\n }\n\n // Remove binary if exists\n const binaryPath = join(BINS_DIR, `${aliasName}-patched`);\n if (existsSync(binaryPath)) {\n await unlink(binaryPath);\n console.log(styleText(\"green\", ` Removed binary: ${binaryPath}`));\n removed = true;\n }\n\n // Remove new proxy wrapper and related files if exist\n const proxyDir = join(DROID_PATCH_DIR, \"proxy\");\n const proxyWrapperPath = join(proxyDir, aliasName);\n const proxyScriptPath = join(proxyDir, `${aliasName}-proxy.js`);\n\n if (existsSync(proxyWrapperPath)) {\n await unlink(proxyWrapperPath);\n console.log(styleText(\"green\", ` Removed wrapper: ${proxyWrapperPath}`));\n removed = true;\n }\n\n if (existsSync(proxyScriptPath)) {\n await unlink(proxyScriptPath);\n console.log(styleText(\"green\", ` Removed proxy script: ${proxyScriptPath}`));\n removed = true;\n }\n\n // Remove old websearch wrapper and related files if exist (backward compatibility)\n const websearchDir = join(DROID_PATCH_DIR, \"websearch\");\n const wrapperPath = join(websearchDir, aliasName);\n const oldProxyPath = join(websearchDir, `${aliasName}-proxy.js`);\n const preloadPath = join(websearchDir, `${aliasName}-preload.js`);\n\n if (existsSync(wrapperPath)) {\n await unlink(wrapperPath);\n console.log(styleText(\"green\", ` Removed legacy wrapper: ${wrapperPath}`));\n removed = true;\n }\n\n if (existsSync(oldProxyPath)) {\n await unlink(oldProxyPath);\n console.log(styleText(\"green\", ` Removed legacy proxy: ${oldProxyPath}`));\n removed = true;\n }\n\n if (existsSync(preloadPath)) {\n await unlink(preloadPath);\n console.log(styleText(\"green\", ` Removed legacy preload: ${preloadPath}`));\n removed = true;\n }\n\n // Remove statusline wrapper and monitor script if exist\n const statuslineDir = join(DROID_PATCH_DIR, \"statusline\");\n const statuslineWrapperPath = join(statuslineDir, aliasName);\n const statuslineMonitorPath = join(statuslineDir, `${aliasName}-statusline.js`);\n\n if (existsSync(statuslineWrapperPath)) {\n await unlink(statuslineWrapperPath);\n console.log(styleText(\"green\", ` Removed statusline wrapper: ${statuslineWrapperPath}`));\n removed = true;\n }\n\n if (existsSync(statuslineMonitorPath)) {\n await unlink(statuslineMonitorPath);\n console.log(styleText(\"green\", ` Removed statusline monitor: ${statuslineMonitorPath}`));\n removed = true;\n }\n\n // Remove metadata\n const metaRemoved = await removeAliasMetadata(aliasName);\n if (metaRemoved) {\n console.log(styleText(\"green\", ` Removed metadata`));\n removed = true;\n }\n\n if (!removed) {\n console.log(styleText(\"yellow\", ` Alias \"${aliasName}\" not found`));\n } else {\n console.log(styleText(\"green\", `[*] Alias \"${aliasName}\" removed successfully`));\n }\n}\n\nexport async function listAliases(): Promise<void> {\n ensureDirectories();\n\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Droid-Patch Aliases\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n interface AliasInfo {\n name: string;\n target: string;\n location: string;\n immediate: boolean;\n }\n\n const aliases: AliasInfo[] = [];\n\n for (const pathDir of COMMON_PATH_DIRS) {\n if (!existsSync(pathDir)) continue;\n\n try {\n const files = readdirSync(pathDir);\n for (const file of files) {\n const fullPath = join(pathDir, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n // Support regular aliases, old websearch wrappers, and new proxy wrappers\n if (\n target.includes(\".droid-patch/bins\") ||\n target.includes(\".droid-patch/websearch\") ||\n target.includes(\".droid-patch/proxy\") ||\n target.includes(\".droid-patch/statusline\")\n ) {\n aliases.push({\n name: file,\n target,\n location: pathDir,\n immediate: true,\n });\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n try {\n const files = readdirSync(ALIASES_DIR);\n\n for (const file of files) {\n const fullPath = join(ALIASES_DIR, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (!aliases.find((a) => a.name === file)) {\n aliases.push({\n name: file,\n target,\n location: ALIASES_DIR,\n immediate: false,\n });\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory doesn't exist or can't be read\n }\n\n if (aliases.length === 0) {\n console.log(styleText(\"gray\", \" No aliases configured.\"));\n console.log();\n console.log(styleText(\"gray\", \" Create one with: npx droid-patch --is-custom <alias-name>\"));\n } else {\n console.log(styleText(\"white\", ` Found ${aliases.length} alias(es):`));\n console.log();\n for (const alias of aliases) {\n const status = alias.immediate\n ? styleText(\"green\", \"✓ immediate\")\n : styleText(\"yellow\", \"requires source\");\n console.log(styleText(\"green\", ` • ${styleText([\"cyan\", \"bold\"], alias.name)} [${status}]`));\n console.log(styleText(\"gray\", ` → ${alias.target}`));\n\n // Load and display metadata\n const meta = await loadAliasMetadata(alias.name);\n if (meta) {\n // Version info\n const patchVer = meta.droidPatchVersion\n ? `droid-patch@${meta.droidPatchVersion}`\n : \"unknown\";\n const droidVer = meta.droidVersion ? `droid@${meta.droidVersion}` : \"unknown\";\n console.log(styleText(\"gray\", ` Versions: ${patchVer}, ${droidVer}`));\n\n // Flags/patches\n const flags = formatPatches(meta.patches);\n console.log(styleText(\"gray\", ` Flags: ${flags}`));\n\n // Created time\n if (meta.createdAt) {\n const date = new Date(meta.createdAt).toLocaleString();\n console.log(styleText(\"gray\", ` Created: ${date}`));\n }\n } else {\n console.log(styleText(\"yellow\", ` (no metadata - created by older version)`));\n }\n console.log();\n }\n }\n\n console.log();\n console.log(styleText(\"gray\", ` Aliases directory: ${ALIASES_DIR}`));\n console.log(\n styleText(\n \"gray\",\n ` PATH configured: ${checkPathInclusion() ? styleText(\"green\", \"Yes\") : styleText(\"yellow\", \"No\")}`,\n ),\n );\n console.log();\n}\n\nexport interface ReplaceOriginalResult {\n originalPath: string;\n backupPath: string;\n}\n\nexport async function replaceOriginal(\n patchedBinaryPath: string,\n originalPath: string,\n verbose = false,\n): Promise<ReplaceOriginalResult> {\n ensureDirectories();\n\n console.log(\n styleText(\"white\", `[*] Replacing original binary: ${styleText(\"cyan\", originalPath)}`),\n );\n\n const latestBackupPath = join(BINS_DIR, \"droid-original-latest\");\n\n if (!existsSync(latestBackupPath)) {\n await copyFile(originalPath, latestBackupPath);\n console.log(styleText(\"green\", `[*] Created backup: ${latestBackupPath}`));\n } else {\n if (verbose) {\n console.log(styleText(\"gray\", ` Backup already exists: ${latestBackupPath}`));\n }\n }\n\n await copyFile(patchedBinaryPath, originalPath);\n await chmod(originalPath, 0o755);\n console.log(styleText(\"green\", `[*] Replaced: ${originalPath}`));\n\n if (process.platform === \"darwin\") {\n try {\n console.log(styleText(\"gray\", \"[*] Re-signing binary for macOS...\"));\n execSync(`codesign --force --deep --sign - \"${originalPath}\"`, {\n stdio: \"pipe\",\n });\n console.log(styleText(\"green\", \"[*] Binary re-signed successfully\"));\n } catch {\n console.log(styleText(\"yellow\", \"[!] Could not re-sign binary. You may need to run:\"));\n console.log(styleText(\"gray\", ` codesign --force --deep --sign - \"${originalPath}\"`));\n }\n\n try {\n execSync(`xattr -cr \"${originalPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" REPLACEMENT COMPLETE\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"The patched binary is now active in all terminals.\"));\n console.log(styleText(\"white\", \"No need to restart or source anything!\"));\n console.log();\n console.log(styleText(\"gray\", `To restore the original, run:`));\n console.log(styleText(\"cyan\", ` npx droid-patch restore`));\n\n return {\n originalPath,\n backupPath: latestBackupPath,\n };\n}\n\n/**\n * Create alias for wrapper script\n * Unlike createAlias, this function creates symlink pointing to wrapper script\n * Used for features like websearch that require preprocessing\n */\nexport async function createAliasForWrapper(\n wrapperPath: string,\n aliasName: string,\n verbose = false,\n): Promise<CreateAliasResult> {\n ensureDirectories();\n\n console.log(styleText(\"white\", `[*] Creating alias: ${styleText(\"cyan\", aliasName)}`));\n\n const writablePathDir = findWritablePathDir();\n\n if (writablePathDir) {\n const targetPath = join(writablePathDir, aliasName);\n\n if (verbose) {\n console.log(styleText(\"gray\", ` Wrapper: ${wrapperPath}`));\n }\n\n if (existsSync(targetPath)) {\n await unlink(targetPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing: ${targetPath}`));\n }\n }\n\n await symlink(wrapperPath, targetPath);\n\n console.log(styleText(\"green\", `[*] Created: ${targetPath} -> ${wrapperPath}`));\n console.log();\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" ALIAS READY - NO ACTION REQUIRED!\"));\n console.log(styleText(\"green\", \"─\".repeat(60)));\n console.log();\n console.log(\n styleText(\n \"white\",\n `The alias \"${styleText([\"cyan\", \"bold\"], aliasName)}\" is now available in ALL terminals.`,\n ),\n );\n console.log(styleText(\"gray\", `(Installed to: ${writablePathDir})`));\n\n return {\n aliasPath: targetPath,\n binaryPath: wrapperPath,\n immediate: true,\n };\n }\n\n // Fallback: use ~/.droid-patch/aliases\n console.log(styleText(\"yellow\", \"[*] No writable PATH directory found, using fallback...\"));\n\n const symlinkPath = join(ALIASES_DIR, aliasName);\n\n if (existsSync(symlinkPath)) {\n await unlink(symlinkPath);\n if (verbose) {\n console.log(styleText(\"gray\", ` Removed existing symlink`));\n }\n }\n\n await symlink(wrapperPath, symlinkPath);\n\n console.log(styleText(\"green\", `[*] Created symlink: ${symlinkPath} -> ${wrapperPath}`));\n\n const shellConfig = getShellConfigPath();\n\n if (!checkPathInclusion()) {\n if (!isPathConfigured(shellConfig)) {\n console.log(styleText(\"white\", `[*] Configuring PATH in ${shellConfig}...`));\n\n if (addPathToShellConfig(shellConfig, verbose)) {\n console.log(styleText(\"green\", `[*] PATH configured successfully!`));\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" ACTION REQUIRED\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"To use the alias in this terminal, run:\"));\n console.log();\n console.log(styleText(\"cyan\", ` source ${shellConfig}`));\n console.log();\n console.log(styleText(\"gray\", \"Or simply open a new terminal window.\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n } else {\n const exportLine = `export PATH=\"${ALIASES_DIR}:$PATH\"`;\n console.log();\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log(styleText([\"yellow\", \"bold\"], \" Manual PATH Configuration Required\"));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n console.log();\n console.log(styleText(\"white\", \"Add this line to your shell config:\"));\n console.log(styleText(\"cyan\", ` ${exportLine}`));\n console.log();\n console.log(styleText(\"gray\", `Shell config file: ${shellConfig}`));\n console.log(styleText(\"yellow\", \"─\".repeat(60)));\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already configured in ${shellConfig}`));\n console.log();\n console.log(\n styleText(\n \"yellow\",\n `Note: Run \\`source ${shellConfig}\\` or open a new terminal to use the alias.`,\n ),\n );\n }\n } else {\n console.log(styleText(\"green\", `[*] PATH already includes aliases directory`));\n console.log();\n console.log(\n styleText(\n \"green\",\n `You can now use \"${styleText([\"cyan\", \"bold\"], aliasName)}\" command directly!`,\n ),\n );\n }\n\n return {\n aliasPath: symlinkPath,\n binaryPath: wrapperPath,\n };\n}\n\nexport async function restoreOriginal(originalPath: string): Promise<void> {\n ensureDirectories();\n\n const latestBackupPath = join(BINS_DIR, \"droid-original-latest\");\n\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Restore Original Droid\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n if (!existsSync(latestBackupPath)) {\n const localBackup = `${originalPath}.backup`;\n if (existsSync(localBackup)) {\n console.log(styleText(\"white\", `[*] Found local backup: ${localBackup}`));\n console.log(styleText(\"white\", `[*] Restoring to: ${originalPath}`));\n\n await copyFile(localBackup, originalPath);\n await chmod(originalPath, 0o755);\n\n if (process.platform === \"darwin\") {\n try {\n execSync(`codesign --force --deep --sign - \"${originalPath}\"`, {\n stdio: \"pipe\",\n });\n execSync(`xattr -cr \"${originalPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" RESTORE COMPLETE\"));\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log();\n console.log(styleText(\"green\", \"Original droid binary has been restored from local backup.\"));\n return;\n }\n\n console.log(styleText(\"red\", \"[!] No backup found.\"));\n console.log(styleText(\"gray\", ` Checked: ${latestBackupPath}`));\n console.log(styleText(\"gray\", ` Checked: ${localBackup}`));\n console.log();\n console.log(styleText(\"gray\", \"If you have a manual backup, restore it with:\"));\n console.log(styleText(\"cyan\", ` cp /path/to/backup ${originalPath}`));\n return;\n }\n\n console.log(styleText(\"white\", `[*] Restoring from: ${latestBackupPath}`));\n console.log(styleText(\"white\", `[*] Restoring to: ${originalPath}`));\n\n const targetDir = dirname(originalPath);\n if (!existsSync(targetDir)) {\n mkdirSync(targetDir, { recursive: true });\n }\n\n await copyFile(latestBackupPath, originalPath);\n await chmod(originalPath, 0o755);\n\n if (process.platform === \"darwin\") {\n try {\n execSync(`codesign --force --deep --sign - \"${originalPath}\"`, {\n stdio: \"pipe\",\n });\n execSync(`xattr -cr \"${originalPath}\"`, { stdio: \"pipe\" });\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log(styleText([\"green\", \"bold\"], \" RESTORE COMPLETE\"));\n console.log(styleText(\"green\", \"═\".repeat(60)));\n console.log();\n console.log(styleText(\"green\", \"Original droid binary has been restored.\"));\n console.log(styleText(\"green\", \"All terminals will now use the original version.\"));\n}\n\n/**\n * Filter options for removing aliases\n * Uses the same names as CLI options for consistency\n */\nexport type FilterFlag =\n | \"is-custom\"\n | \"skip-login\"\n | \"websearch\"\n | \"statusline\"\n | \"api-base\"\n | \"reasoning-effort\"\n | \"disable-telemetry\"\n | \"standalone\";\n\nexport interface RemoveFilterOptions {\n /** Remove aliases created by this droid-patch version */\n patchVersion?: string;\n /** Remove aliases for this droid version */\n droidVersion?: string;\n /** Remove aliases that have these flags enabled (all must match) */\n flags?: FilterFlag[];\n}\n\n/**\n * Remove aliases matching filter criteria\n */\nexport async function removeAliasesByFilter(filter: RemoveFilterOptions): Promise<void> {\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Remove Aliases by Filter\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n // Show filter criteria\n if (filter.patchVersion) {\n console.log(styleText(\"white\", ` Filter: droid-patch version = ${filter.patchVersion}`));\n }\n if (filter.droidVersion) {\n console.log(styleText(\"white\", ` Filter: droid version = ${filter.droidVersion}`));\n }\n if (filter.flags && filter.flags.length > 0) {\n console.log(styleText(\"white\", ` Filter: flags = ${filter.flags.join(\", \")}`));\n }\n console.log();\n\n // Collect all alias names\n const aliasNames = new Set<string>();\n\n // Check common PATH directories for symlinks\n for (const pathDir of COMMON_PATH_DIRS) {\n if (!existsSync(pathDir)) continue;\n\n try {\n const files = readdirSync(pathDir);\n for (const file of files) {\n const fullPath = join(pathDir, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (\n target.includes(\".droid-patch/bins\") ||\n target.includes(\".droid-patch/websearch\") ||\n target.includes(\".droid-patch/proxy\") ||\n target.includes(\".droid-patch/statusline\")\n ) {\n aliasNames.add(file);\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Check aliases directory\n if (existsSync(ALIASES_DIR)) {\n try {\n const files = readdirSync(ALIASES_DIR);\n for (const file of files) {\n const fullPath = join(ALIASES_DIR, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n aliasNames.add(file);\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Filter aliases by metadata\n const matchingAliases: string[] = [];\n\n for (const aliasName of aliasNames) {\n const meta = await loadAliasMetadata(aliasName);\n\n // If no metadata, skip (can't filter without metadata)\n if (!meta) {\n continue;\n }\n\n let matches = true;\n\n // Check droid-patch version\n if (filter.patchVersion && meta.droidPatchVersion !== filter.patchVersion) {\n matches = false;\n }\n\n // Check droid version\n if (filter.droidVersion && meta.droidVersion !== filter.droidVersion) {\n matches = false;\n }\n\n // Check flags (all specified flags must match)\n if (filter.flags && filter.flags.length > 0) {\n const patches = meta.patches;\n for (const flag of filter.flags) {\n switch (flag) {\n case \"is-custom\":\n if (!patches.isCustom) matches = false;\n break;\n case \"skip-login\":\n if (!patches.skipLogin) matches = false;\n break;\n case \"websearch\":\n if (!patches.websearch) matches = false;\n break;\n case \"statusline\":\n if (!patches.statusline) matches = false;\n break;\n case \"reasoning-effort\":\n if (!patches.reasoningEffort) matches = false;\n break;\n case \"api-base\":\n if (!patches.apiBase) matches = false;\n break;\n case \"disable-telemetry\":\n if (!patches.noTelemetry) matches = false;\n break;\n case \"standalone\":\n if (!patches.standalone) matches = false;\n break;\n }\n if (!matches) break;\n }\n }\n\n if (matches) {\n matchingAliases.push(aliasName);\n }\n }\n\n if (matchingAliases.length === 0) {\n console.log(styleText(\"yellow\", \" No aliases match the filter criteria.\"));\n console.log();\n return;\n }\n\n console.log(styleText(\"white\", ` Found ${matchingAliases.length} matching alias(es):`));\n for (const name of matchingAliases) {\n console.log(styleText(\"gray\", ` • ${name}`));\n }\n console.log();\n\n // Remove each matching alias\n for (const aliasName of matchingAliases) {\n await removeAlias(aliasName);\n console.log();\n }\n\n console.log(styleText(\"green\", `[*] Removed ${matchingAliases.length} alias(es)`));\n}\n\n/**\n * Clear all droid-patch aliases and related files\n */\nexport async function clearAllAliases(): Promise<void> {\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log(styleText([\"cyan\", \"bold\"], \" Clearing All Droid-Patch Data\"));\n console.log(styleText(\"cyan\", \"═\".repeat(60)));\n console.log();\n\n // Collect all alias names\n const aliasNames = new Set<string>();\n\n // Check common PATH directories for symlinks\n for (const pathDir of COMMON_PATH_DIRS) {\n if (!existsSync(pathDir)) continue;\n\n try {\n const files = readdirSync(pathDir);\n for (const file of files) {\n const fullPath = join(pathDir, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n const target = await readlink(fullPath);\n if (\n target.includes(\".droid-patch/bins\") ||\n target.includes(\".droid-patch/websearch\") ||\n target.includes(\".droid-patch/proxy\") ||\n target.includes(\".droid-patch/statusline\")\n ) {\n aliasNames.add(file);\n }\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n // Check aliases directory\n if (existsSync(ALIASES_DIR)) {\n try {\n const files = readdirSync(ALIASES_DIR);\n for (const file of files) {\n const fullPath = join(ALIASES_DIR, file);\n try {\n const stats = lstatSync(fullPath);\n if (stats.isSymbolicLink()) {\n aliasNames.add(file);\n }\n } catch {\n // Ignore\n }\n }\n } catch {\n // Directory can't be read\n }\n }\n\n if (aliasNames.size === 0) {\n console.log(styleText(\"yellow\", \" No aliases found.\"));\n } else {\n console.log(styleText(\"white\", ` Found ${aliasNames.size} alias(es) to remove:`));\n for (const name of aliasNames) {\n console.log(styleText(\"gray\", ` • ${name}`));\n }\n console.log();\n\n // Remove each alias\n for (const aliasName of aliasNames) {\n await removeAlias(aliasName);\n console.log();\n }\n }\n\n // Clean up directories (including legacy files)\n console.log(styleText(\"white\", \" Cleaning up directories...\"));\n const dirsToClean = [\n join(DROID_PATCH_DIR, \"bins\"),\n join(DROID_PATCH_DIR, \"aliases\"),\n join(DROID_PATCH_DIR, \"proxy\"),\n join(DROID_PATCH_DIR, \"websearch\"),\n join(DROID_PATCH_DIR, \"statusline\"),\n ];\n\n for (const dir of dirsToClean) {\n if (existsSync(dir)) {\n try {\n const files = readdirSync(dir);\n for (const file of files) {\n const fullPath = join(dir, file);\n try {\n await unlink(fullPath);\n console.log(styleText(\"green\", ` Removed: ${fullPath}`));\n } catch {\n // Ignore\n }\n }\n } catch {\n // Ignore\n }\n }\n }\n\n // Clean up legacy temp files from old versions\n const legacyTempFiles = [\"/tmp/droid-search-proxy.pid\", \"/tmp/droid-search-proxy.log\"];\n\n for (const tempFile of legacyTempFiles) {\n if (existsSync(tempFile)) {\n try {\n await unlink(tempFile);\n console.log(styleText(\"green\", ` Removed legacy: ${tempFile}`));\n } catch {\n // Ignore\n }\n }\n }\n\n // Clean up temp port files (pattern: /tmp/droid-websearch-*.port)\n try {\n const tmpFiles = readdirSync(\"/tmp\");\n for (const file of tmpFiles) {\n if (file.startsWith(\"droid-websearch-\") && file.endsWith(\".port\")) {\n const fullPath = join(\"/tmp\", file);\n try {\n await unlink(fullPath);\n console.log(styleText(\"green\", ` Removed temp: ${fullPath}`));\n } catch {\n // Ignore\n }\n }\n // Also clean old droid-search-proxy-*.port files\n if (file.startsWith(\"droid-search-proxy-\") && file.endsWith(\".port\")) {\n const fullPath = join(\"/tmp\", file);\n try {\n await unlink(fullPath);\n console.log(styleText(\"green\", ` Removed legacy temp: ${fullPath}`));\n } catch {\n // Ignore\n }\n }\n }\n } catch {\n // Ignore\n }\n\n // Clean up metadata file\n const metadataFile = join(DROID_PATCH_DIR, \"metadata.json\");\n if (existsSync(metadataFile)) {\n try {\n await unlink(metadataFile);\n console.log(styleText(\"green\", ` Removed: ${metadataFile}`));\n } catch {\n // Ignore\n }\n }\n\n console.log();\n console.log(styleText(\"green\", \"[*] All droid-patch data cleared successfully\"));\n}\n"],"mappings":";;;;;;;;AAsCA,eAAsB,WAAW,SAAkD;CACjF,MAAM,EACJ,WACA,YACA,SACA,SAAS,OACT,SAAS,MACT,UAAU,UACR;CAEJ,MAAM,kBAAkB,cAAc,GAAG,UAAU;AAEnD,KAAI,CAAC,W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