dsh-sidebar-reader 1.0.1 → 1.1.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 +174 -148
- package/README.zh.md +174 -148
- package/lib/client.js +77 -5
- package/lib/index.js +27 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,148 +1,174 @@
|
|
|
1
|
-
# dsh-sidebar-reader
|
|
2
|
-
|
|
3
|
-
[English](README.md) | [中文](README.zh.md)
|
|
4
|
-
|
|
5
|
-
Let your model read the **current session's** sidebar on demand: the active tab, official right-sidebar tabs, terminal screens, and browser page text.
|
|
6
|
-
|
|
7
|
-
Once installed, just tell the model "read my sidebar" or "show me my terminal" — the model triggers a capture through the plugin's command channel and receives a snapshot within seconds.
|
|
8
|
-
|
|
9
|
-
## How it works
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
model ──POST /sidebar-reader/command──▶ host route (lib/index.js)
|
|
13
|
-
client polls every 2s
|
|
14
|
-
▼
|
|
15
|
-
client capture (lib/client.js, runs in the Web UI)
|
|
16
|
-
├── active tab (sidebarRight.active(), active pane's active tab)
|
|
17
|
-
├── right-sidebar tabs (sidebarRight.openTabs, current session only)
|
|
18
|
-
├── terminal screens (remote.terminal.attach, first
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
37
|
-
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
1
|
+
# dsh-sidebar-reader
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Let your model read the **current session's** sidebar on demand: the active tab, official right-sidebar tabs, terminal screens, and browser page text.
|
|
6
|
+
|
|
7
|
+
Once installed, just tell the model "read my sidebar" or "show me my terminal" — the model triggers a capture through the plugin's command channel and receives a snapshot within seconds.
|
|
8
|
+
|
|
9
|
+
## How it works
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
model ──POST /sidebar-reader/command──▶ host route (lib/index.js)
|
|
13
|
+
client polls every 2s
|
|
14
|
+
▼
|
|
15
|
+
client capture (lib/client.js, runs in the Web UI)
|
|
16
|
+
├── active tab (sidebarRight.active(), active pane's active tab)
|
|
17
|
+
├── right-sidebar tabs (sidebarRight.openTabs, current session only)
|
|
18
|
+
├── terminal screens (remote.terminal.attach, first snapshot → ANSI-free,
|
|
19
|
+
│ incremental vs. the previous read)
|
|
20
|
+
└── web page text (webview innerText, desktop only)
|
|
21
|
+
│
|
|
22
|
+
client ──POST /sidebar-reader/latest──▶ host keeps the latest snapshot only
|
|
23
|
+
model ◀──GET /sidebar-reader/latest─── host
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Agent tool (auto-registered)
|
|
27
|
+
|
|
28
|
+
The plugin's host side registers a native agent tool **`sidebar_read`** with the DSH tool registry: it appears in every new session's tool list automatically, and one call returns the full snapshot — no HTTP, no configuration. The "prefer this over pwsh/web_fetch for terminal or page questions" preference is encoded in the tool description itself.
|
|
29
|
+
|
|
30
|
+
The only parameter is `delta` (default `true`): terminal screens are incremental after the first read. Pass `delta: false` when you need every terminal's complete screen again.
|
|
31
|
+
|
|
32
|
+
The HTTP endpoints below remain as a fallback channel.
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
| Channel | Source | Notes |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| Active tab | `sidebarRight.active()` | The active pane's active tab (id / kind / title / contentId), plus `expanded` telling whether the column is showing |
|
|
39
|
+
| Right-sidebar tabs | `sidebarRight.openTabs` live snapshot | Every open tab of the current session (`tabId` / `kind` / `contentId`) |
|
|
40
|
+
| Terminal screens | `remote.terminal.attach` first snapshot frame | Full screen including scrollback, ANSI-stripped, then incremental (see below); input control is released right after reading |
|
|
41
|
+
| Web page text | Sidebar browser webview `innerText` | **Desktop (Electron) only**; strict mode, see below |
|
|
42
|
+
|
|
43
|
+
### Three passes on terminal text
|
|
44
|
+
|
|
45
|
+
A raw xterm screen is a poor thing to hand a model: it is full of color/cursor escapes, it repeats the whole scrollback on every read, and it can be arbitrarily long. So every terminal screen goes through three passes in `lib/client.js`:
|
|
46
|
+
|
|
47
|
+
| Pass | What it does | Why |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `stripAnsi` | Drops ANSI/OSC escape sequences and invisible control characters | Escapes are pure token cost and unreadable |
|
|
50
|
+
| `screenDelta` | Remembers each terminal's last reported screen (per terminal id) and returns only the new part; falls back to the common line prefix when the screen was redrawn; returns the whole screen when nothing matches, so text is never lost | Repeated reads cost a fraction of the context |
|
|
51
|
+
| `capScreen` | Keeps only the tail, max 500 lines / 20 000 chars per terminal | Scrollback can be huge; the newest output is at the bottom |
|
|
52
|
+
|
|
53
|
+
Each terminal entry therefore carries `screen` (clean text), `delta` (`false` = this is a complete screen, i.e. the first read of that terminal or an explicit `delta:false`) and `truncated` (`true` = the caps kicked in). `delta:false` also refreshes the delta baseline, so the next incremental read stays consistent.
|
|
54
|
+
|
|
55
|
+
### Strict mode for web page text
|
|
56
|
+
|
|
57
|
+
The page is read only when **the active tab is a browser** *and* **the column is expanded**. Otherwise `page` is `null`.
|
|
58
|
+
|
|
59
|
+
Why: when a sidebar browser tab moves to the background, its webview stays in the DOM with zero width, and the fallback picker would still return it — the model would receive a page the user is not looking at. `null` is better than the wrong page.
|
|
60
|
+
|
|
61
|
+
## What you get
|
|
62
|
+
|
|
63
|
+
| What you are looking at | Readable | Notes |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| A page in the sidebar browser | ✅ title + URL + text | Must be the active browser tab, with the column expanded |
|
|
66
|
+
| A file / document tab | ⚠️ address only | You get its `contentId` (e.g. `dsh-resource://file/...`); read the file by that path |
|
|
67
|
+
| A terminal | ✅ screen text | ANSI-free; first read is the full screen, later reads add only new lines (max 500 lines / 20k chars per terminal) |
|
|
68
|
+
| Plain web build (browser access) | ❌ page text | No webview; tabs and terminals still work |
|
|
69
|
+
|
|
70
|
+
## Snapshot example
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"page": { "title": "…", "url": "https://…", "text": "…", "chars": 1235 },
|
|
75
|
+
"right": {
|
|
76
|
+
"sessionId": "session-…",
|
|
77
|
+
"expanded": true,
|
|
78
|
+
"active": { "id": "tab5", "type": "browser", "title": "Browser", "path": "sidebar://browser/…" },
|
|
79
|
+
"tabs": [
|
|
80
|
+
{ "id": "tab3", "type": "files", "path": "sidebar://files" },
|
|
81
|
+
{ "id": "tab5", "type": "browser", "path": "sidebar://browser/…" }
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"terminals": {
|
|
85
|
+
"sessionId": "session-…",
|
|
86
|
+
"terminals": [
|
|
87
|
+
{ "id": "…", "title": "…", "state": "running", "screen": "…", "delta": false, "truncated": false }
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"commandId": "cmd-…",
|
|
91
|
+
"receivedAt": "2026-11-08T13:11:42.350Z"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Design disciplines:
|
|
96
|
+
|
|
97
|
+
1. **Scope** — everything is filtered to the session on screen before leaving the browser; other sessions are unreadable;
|
|
98
|
+
2. **Never throws** — each channel degrades independently; one failing channel doesn't break the others;
|
|
99
|
+
3. **Transparent** — a toast is shown on every read;
|
|
100
|
+
4. **Revocable** — all side effects live in `ctx.effect` and are cleaned up when the plugin is disabled.
|
|
101
|
+
|
|
102
|
+
## Install
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
# From a plugin market (dshmarket / the official Discover tab, once listed): search "Sidebar Reader"
|
|
106
|
+
# or via CLI:
|
|
107
|
+
dsh plugin --profile <your-profile> add dsh-sidebar-reader
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
On the official DSH Desktop app, install from the app's own **Settings → Plugins** (or clone this repo anywhere and point the plugin manager's local install at the folder).
|
|
111
|
+
|
|
112
|
+
## Requirements
|
|
113
|
+
|
|
114
|
+
- **DSH >= 0.2.1-rc.2** (terminal capture uses `remote.terminal.attach`; on 0.2.0-rc.2 the plugin loads and tabs work, but terminal capture errors out — that version still called it `follow`)
|
|
115
|
+
- **No better-sidebar required** — official services only (`sidebarRight`, `remote.terminal`)
|
|
116
|
+
- Web page text is desktop-only; the web build still gets the active tab, tabs and terminals
|
|
117
|
+
|
|
118
|
+
## Compatibility
|
|
119
|
+
|
|
120
|
+
| Host version | Loads | Active tab | Sidebar tabs | Terminals | Web page text |
|
|
121
|
+
|---|---|---|---|---|---|
|
|
122
|
+
| 0.2.1-rc.2 ~ 0.2.2-rc.3 | ✅ | ✅ | ✅ | ✅ | desktop ✅ / web ❌ |
|
|
123
|
+
| 0.2.0-rc.2 | ✅ | ⚠️ | ✅ | ❌ (API renamed follow→attach) | desktop ✅ / web ❌ |
|
|
124
|
+
|
|
125
|
+
Verified: all four channels on 0.2.1-rc.5 and on 0.2.2-rc.3 (with the incremental terminal read); install + composition + client module registration on 0.2.1-rc.2 and 0.2.2-rc.1 (`scripts/test-plugin.ps1`).
|
|
126
|
+
|
|
127
|
+
## Development & testing
|
|
128
|
+
|
|
129
|
+
Two Windows PowerShell scripts ship with the repo, plus one Node test:
|
|
130
|
+
|
|
131
|
+
```powershell
|
|
132
|
+
# 1) Smoke test against a running GUI port: host route + client polling + snapshot
|
|
133
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/check-plugin.ps1 -Port 53233
|
|
134
|
+
|
|
135
|
+
# 2) Multi-version compatibility test: isolated directory + DSH_HOME per version
|
|
136
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/test-plugin.ps1 -Version 0.2.1-rc.2 -Port 6123
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
# 3) Unit tests for the terminal text passes (stripAnsi / capScreen / screenDelta)
|
|
141
|
+
node scripts/test-text-helpers.mjs
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Two traps worth knowing:
|
|
145
|
+
|
|
146
|
+
- **Client changes require a page refresh**: the host swaps the bundle immediately (rev changes), but a module already loaded in the page is not replaced — HMR graph sync only adds/removes entries, it does not replace an existing one;
|
|
147
|
+
- **The `id` in `__ModuleLoader__.load({ id })` must equal the npm package name** (including scope). DSH's client module system matches registrations by package name; a mismatch fails silently — `sidebar_read` still answers, but every capture times out.
|
|
148
|
+
|
|
149
|
+
## Privacy & security
|
|
150
|
+
|
|
151
|
+
- Reads the current session only; other sessions' data never leaves the browser;
|
|
152
|
+
- Everything stays on your machine: host routes sit on loopback HTTP (`/sidebar-reader/*`), no browser auth, nothing leaves the machine;
|
|
153
|
+
- Every read is announced with a toast — no silent capture;
|
|
154
|
+
- No telemetry, no external requests.
|
|
155
|
+
|
|
156
|
+
## Host routes (prefix `/sidebar-reader`)
|
|
157
|
+
|
|
158
|
+
| Endpoint | Method | Purpose |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| `/health` | GET | Self-check: snapshot present? command pending? |
|
|
161
|
+
| `/latest` | GET | Model reads the snapshot (404 when empty) |
|
|
162
|
+
| `/latest` | POST | Client submits a snapshot (replace-only-latest) |
|
|
163
|
+
| `/command` | GET | Client claims a command (consume-on-read) |
|
|
164
|
+
| `/command` | POST | Model issues a command |
|
|
165
|
+
|
|
166
|
+
## Changelog
|
|
167
|
+
|
|
168
|
+
- **1.1.0** — terminal reads are now context-cheap: screens are ANSI-stripped, incremental after the first read (`delta`, with a `delta:false` escape hatch), and capped at 500 lines / 20 000 chars per terminal; added `scripts/test-text-helpers.mjs`; verified end-to-end on DSH 0.2.2-rc.3.
|
|
169
|
+
- **1.0.1** — fixed the client module registration id not matching the package name (previously the client never loaded on any host, surfacing as `capture timed out`); `tabs[].id` now carries the real `tabId`; added `right.active` (the active tab) and `right.expanded`; web page text is now strict mode (`null` unless a browser tab is active and the column is expanded).
|
|
170
|
+
- **1.0.0** — first release.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
[MIT](LICENSE)
|
package/README.zh.md
CHANGED
|
@@ -1,148 +1,174 @@
|
|
|
1
|
-
# dsh-sidebar-reader
|
|
2
|
-
|
|
3
|
-
[English](README.md) | 中文
|
|
4
|
-
|
|
5
|
-
让模型按需读取**当前会话**的侧边栏:当前选中的标签、官方右侧栏标签、终端屏幕、浏览器网页正文。
|
|
6
|
-
|
|
7
|
-
装好后对模型说一句「读一下我的侧边栏」或「看我开着的终端」,模型通过插件的命令通道触发一次采集,几秒内就能拿到快照。
|
|
8
|
-
|
|
9
|
-
## 工作原理
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
模型 ──POST /sidebar-reader/command──▶ 宿主路由 (lib/index.js)
|
|
13
|
-
│ 客户端每 2s 轮询领命令
|
|
14
|
-
▼
|
|
15
|
-
客户端采集 (lib/client.js,跑在 Web UI 里)
|
|
16
|
-
├── 当前选中标签(sidebarRight.active(),活动窗格的活动标签)
|
|
17
|
-
├── 官方右侧栏标签(sidebarRight.openTabs,按当前会话过滤)
|
|
18
|
-
├── 终端屏幕(remote.terminal.attach
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
37
|
-
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
1
|
+
# dsh-sidebar-reader
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
让模型按需读取**当前会话**的侧边栏:当前选中的标签、官方右侧栏标签、终端屏幕、浏览器网页正文。
|
|
6
|
+
|
|
7
|
+
装好后对模型说一句「读一下我的侧边栏」或「看我开着的终端」,模型通过插件的命令通道触发一次采集,几秒内就能拿到快照。
|
|
8
|
+
|
|
9
|
+
## 工作原理
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
模型 ──POST /sidebar-reader/command──▶ 宿主路由 (lib/index.js)
|
|
13
|
+
│ 客户端每 2s 轮询领命令
|
|
14
|
+
▼
|
|
15
|
+
客户端采集 (lib/client.js,跑在 Web UI 里)
|
|
16
|
+
├── 当前选中标签(sidebarRight.active(),活动窗格的活动标签)
|
|
17
|
+
├── 官方右侧栏标签(sidebarRight.openTabs,按当前会话过滤)
|
|
18
|
+
├── 终端屏幕(remote.terminal.attach,取首个全屏快照 → 去 ANSI、
|
|
19
|
+
│ 与上次读取比只留增量)
|
|
20
|
+
└── 网页正文(webview innerText,仅桌面端)
|
|
21
|
+
│
|
|
22
|
+
客户端 ──POST /sidebar-reader/latest──▶ 宿主只保留最新一份
|
|
23
|
+
模型 ◀──GET /sidebar-reader/latest──── 宿主
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 模型工具(自动注册)
|
|
27
|
+
|
|
28
|
+
插件宿主侧会向 DSH 工具注册表注册一个原生 agent 工具 **`sidebar_read`**:每个新会话的工具清单里自动出现,模型一次调用即拿到全量快照,无需任何 HTTP 调用或配置。「读终端/网页先走侧边栏」的偏好直接编码在工具描述里。
|
|
29
|
+
|
|
30
|
+
唯一参数是 `delta`(缺省 `true`):终端屏幕从第二次读取起只回增量。需要重新拿到每个终端的完整屏幕时传 `delta: false`。
|
|
31
|
+
|
|
32
|
+
下方 HTTP 端点保留为兜底通道。
|
|
33
|
+
|
|
34
|
+
## 功能
|
|
35
|
+
|
|
36
|
+
| 采集路 | 来源 | 说明 |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| 当前选中标签 | `sidebarRight.active()` | 活动窗格的活动标签(id / kind / title / contentId),并带 `expanded` 表示侧栏是否展开 |
|
|
39
|
+
| 右侧栏标签 | `sidebarRight.openTabs` 活快照 | 当前会话打开的全部标签(`tabId` / `kind` / `contentId`),**只取当前会话** |
|
|
40
|
+
| 终端屏幕 | `remote.terminal.attach` 首帧快照 | 含滚动缓冲的完整屏幕,去 ANSI 后按增量回传(见下);读完立即断开归还输入权 |
|
|
41
|
+
| 网页正文 | 侧栏浏览器 webview 的 `innerText` | **仅桌面端(Electron)**;严格模式,见下 |
|
|
42
|
+
|
|
43
|
+
### 终端文本的三道处理
|
|
44
|
+
|
|
45
|
+
xterm 的原始屏幕并不适合直接喂模型:夹着大量颜色/光标转义、每次读取都把整屏滚动缓冲重复一遍、长度还可能很长。所以每块屏幕在 `lib/client.js` 里过三道:
|
|
46
|
+
|
|
47
|
+
| 处理 | 做什么 | 为什么 |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `stripAnsi` | 去掉 ANSI/OSC 转义序列与不可见控制符 | 转义纯属 token 浪费,模型也读不懂 |
|
|
50
|
+
| `screenDelta` | 按终端 id 记住上次回传的屏幕,本次只回新增部分;界面重绘时退化为按行的公共前缀;完全对不上就整屏回传(不丢文本) | 连续读取只花原来零头的上下文 |
|
|
51
|
+
| `capScreen` | 只保留尾部,单终端上限 500 行 / 2 万字 | 滚动缓冲可能极长,最新输出在末尾 |
|
|
52
|
+
|
|
53
|
+
因此每个终端条目带三个字段:`screen`(干净文本)、`delta`(`false` = 这是完整屏幕,即该终端首次读取或显式要了全屏)、`truncated`(`true` = 触发了行/字符上限)。`delta:false` 同时会刷新增量基准,下一轮增量仍然对得上。
|
|
54
|
+
|
|
55
|
+
### 网页正文的「严格模式」
|
|
56
|
+
|
|
57
|
+
只有满足两条时才读网页:**当前选中的标签是 browser**,且**侧栏处于展开状态**。否则 `page` 一律为 `null`。
|
|
58
|
+
|
|
59
|
+
原因:侧栏把没选中的浏览器标签收进后台时,webview 仍留在 DOM 里(宽度为 0),兜底逻辑会把它当成「最后一个」读回来——模型就会拿到用户根本没在看的页面。宁可给 `null`,也不给错的那一页。
|
|
60
|
+
|
|
61
|
+
## 能读到什么
|
|
62
|
+
|
|
63
|
+
| 你在看的东西 | 能读到 | 说明 |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| 侧栏浏览器里的网页 | ✅ 标题 + URL + 正文 | 必须是当前选中的 browser 标签,且侧栏展开 |
|
|
66
|
+
| 侧栏里的文件/文档标签 | ⚠️ 只有地址 | 给的是 `contentId`(如 `dsh-resource://file/...`),正文要按路径另外读 |
|
|
67
|
+
| 终端 | ✅ 屏幕文本 | 去 ANSI;首次整屏,之后只回新增行(单终端上限 500 行 / 2 万字) |
|
|
68
|
+
| 纯 Web 版 DSH(浏览器访问) | ❌ 网页正文 | 没有 webview;标签与终端仍可读 |
|
|
69
|
+
|
|
70
|
+
## 快照示例
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"page": { "title": "…", "url": "https://…", "text": "…", "chars": 1235 },
|
|
75
|
+
"right": {
|
|
76
|
+
"sessionId": "session-…",
|
|
77
|
+
"expanded": true,
|
|
78
|
+
"active": { "id": "tab5", "type": "browser", "title": "浏览器", "path": "sidebar://browser/…" },
|
|
79
|
+
"tabs": [
|
|
80
|
+
{ "id": "tab3", "type": "files", "path": "sidebar://files" },
|
|
81
|
+
{ "id": "tab5", "type": "browser", "path": "sidebar://browser/…" }
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"terminals": {
|
|
85
|
+
"sessionId": "session-…",
|
|
86
|
+
"terminals": [
|
|
87
|
+
{ "id": "…", "title": "…", "state": "running", "screen": "…", "delta": false, "truncated": false }
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"commandId": "cmd-…",
|
|
91
|
+
"receivedAt": "2026-11-08T13:11:42.350Z"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
四条设计纪律:
|
|
96
|
+
|
|
97
|
+
1. **作用域**:所有数据先按「屏幕上的会话」过滤才出浏览器,别的会话读不到;
|
|
98
|
+
2. **永不抛错**:各采集路独立降级,一路坏了其余照常返回;
|
|
99
|
+
3. **透明**:每次读取界面都弹 toast,用户看得见;
|
|
100
|
+
4. **可撤销**:所有副作用挂在 `ctx.effect` 上,禁用插件即干净退场。
|
|
101
|
+
|
|
102
|
+
## 安装
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
# 插件市场(dshmarket 或官方发现页收录后)里搜索 Sidebar Reader
|
|
106
|
+
# 或命令行:
|
|
107
|
+
dsh plugin --profile <你的profile> add dsh-sidebar-reader
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
官方 DSH Desktop 桌面端请在应用自身的 **设置 → 插件** 里安装(或把本仓库克隆到任意目录,用插件管理的本地安装指向该目录)。
|
|
111
|
+
|
|
112
|
+
## 要求
|
|
113
|
+
|
|
114
|
+
- **DSH >= 0.2.1-rc.2**(终端读取依赖 `remote.terminal.attach`;0.2.0-rc.2 能加载、侧栏标签可用,但终端采集会报错——该版本的接口还叫 `follow`)
|
|
115
|
+
- **不依赖 better-sidebar**——只用官方服务(`sidebarRight`、`remote.terminal`)
|
|
116
|
+
- 网页正文读取仅桌面端;Web 版(浏览器访问)可用当前选中标签 + 标签列表 + 终端
|
|
117
|
+
|
|
118
|
+
## 兼容性
|
|
119
|
+
|
|
120
|
+
| 宿主版本 | 加载 | 选中标签 | 侧栏标签 | 终端 | 网页正文 |
|
|
121
|
+
|---|---|---|---|---|---|
|
|
122
|
+
| 0.2.1-rc.2 ~ 0.2.2-rc.3 | ✅ | ✅ | ✅ | ✅ | 桌面 ✅ / Web ❌ |
|
|
123
|
+
| 0.2.0-rc.2 | ✅ | ⚠️ | ✅ | ❌(接口改名 follow→attach) | 桌面 ✅ / Web ❌ |
|
|
124
|
+
|
|
125
|
+
实测说明:0.2.1-rc.5 与 0.2.2-rc.3(含终端增量读取)上四路全功能实测通过;0.2.1-rc.2 与 0.2.2-rc.1 完成了安装、组合与客户端模块注册验证(`scripts/test-plugin.ps1`)。
|
|
126
|
+
|
|
127
|
+
## 开发与测试
|
|
128
|
+
|
|
129
|
+
仓库自带两个脚本(Windows PowerShell):
|
|
130
|
+
|
|
131
|
+
```powershell
|
|
132
|
+
# 1) 冒烟测试:对着已经跑起来的 GUI 端口,验证宿主+客户端+快照三件事
|
|
133
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/check-plugin.ps1 -Port 53233
|
|
134
|
+
|
|
135
|
+
# 2) 多版本兼容测试:每个版本独立目录 + 独立 DSH_HOME,不动你正在用的桌面端
|
|
136
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/test-plugin.ps1 -Version 0.2.1-rc.2 -Port 6123
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
# 3) 终端文本三道处理的单元测试(stripAnsi / capScreen / screenDelta)
|
|
141
|
+
node scripts/test-text-helpers.mjs
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
两个容易踩的坑:
|
|
145
|
+
|
|
146
|
+
- **改了客户端代码必须刷新页面**:宿主会立刻换掉 bundle(rev 变化),但页面里已加载的模块不会自己替换——HMR 的图同步只处理「新增/删除 entry」,不处理「已有 entry 替换」;
|
|
147
|
+
- **`lib/client.js` 里 `__ModuleLoader__.load({ id })` 的 id 必须等于 npm 包名**(含 scope)。DSH 的客户端模块系统按包名匹配注册,写错会静默加载失败——表现是 `sidebar_read` 能调、但每次 `capture timed out`。
|
|
148
|
+
|
|
149
|
+
## 隐私与安全
|
|
150
|
+
|
|
151
|
+
- 只读当前会话的数据,跨会话内容不出浏览器;
|
|
152
|
+
- 全部数据只落本机:宿主路由挂在 loopback HTTP(`/sidebar-reader/*`)上,不过浏览器鉴权、不出机器;
|
|
153
|
+
- 每次读取都有 toast 提示,无静默采集;
|
|
154
|
+
- 无遥测、无外部请求。
|
|
155
|
+
|
|
156
|
+
## 宿主路由(前缀 `/sidebar-reader`)
|
|
157
|
+
|
|
158
|
+
| 端点 | 方法 | 用途 |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| `/health` | GET | 自检:有无快照、有无待领命令 |
|
|
161
|
+
| `/latest` | GET | 模型读快照(无快照 404) |
|
|
162
|
+
| `/latest` | POST | 客户端交快照(整体替换,只留最新) |
|
|
163
|
+
| `/command` | GET | 客户端领命令(消费即清空,一条命令只执行一次) |
|
|
164
|
+
| `/command` | POST | 模型下发命令 |
|
|
165
|
+
|
|
166
|
+
## 更新日志
|
|
167
|
+
|
|
168
|
+
- **1.1.0** — 终端读取改为省上下文的形态:屏幕去 ANSI、首次之后只回增量(`delta`,可用 `delta:false` 要全屏)、单终端上限 500 行 / 2 万字;新增 `scripts/test-text-helpers.mjs`;在 DSH 0.2.2-rc.3 上端到端实测通过。
|
|
169
|
+
- **1.0.1** — 修复客户端模块注册 id 与包名不一致(此前任何宿主上客户端都不会加载,表现为 `capture timed out`);`tabs[].id` 改用真实 `tabId`;新增 `right.active`(当前选中标签)与 `right.expanded`;网页正文改为严格模式(非 browser 标签或侧栏收起时返回 `null`)。
|
|
170
|
+
- **1.0.0** — 首个版本。
|
|
171
|
+
|
|
172
|
+
## 许可
|
|
173
|
+
|
|
174
|
+
[MIT](LICENSE)
|
package/lib/client.js
CHANGED
|
@@ -149,6 +149,61 @@ window.__ModuleLoader__.load({
|
|
|
149
149
|
return await response.json().catch(() => null);
|
|
150
150
|
}
|
|
151
151
|
//#endregion
|
|
152
|
+
//#region src/client/text.ts
|
|
153
|
+
// 终端屏文本的三道处理(省上下文,也更好读):
|
|
154
|
+
// 1. stripAnsi 去掉 ANSI/OSC 控制序列——xterm 快照里夹着大量颜色/光标转义,
|
|
155
|
+
// 模型读它们纯属浪费 token;
|
|
156
|
+
// 2. screenDelta 每个终端记住上次回传的屏幕,本次只回新增部分(首次仍是全屏);
|
|
157
|
+
// 3. capScreen 按行/字符双重截断,只保留尾部——滚动缓冲可能很长。
|
|
158
|
+
const TERMINAL_MAX_LINES = 500;
|
|
159
|
+
const TERMINAL_MAX_CHARS = 20000;
|
|
160
|
+
|
|
161
|
+
/** 去掉 ANSI/OSC 控制序列与不可见控制符,只留可读文本。 */
|
|
162
|
+
function stripAnsi(text) {
|
|
163
|
+
return String(text ?? "")
|
|
164
|
+
.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g, "")
|
|
165
|
+
.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "")
|
|
166
|
+
.replace(/\u009b[0-?]*[ -/]*[@-~]/g, "")
|
|
167
|
+
.replace(/\u001b[@-Z\\-_]/g, "")
|
|
168
|
+
.replace(/\r\n/g, "\n")
|
|
169
|
+
.replace(/\r/g, "\n")
|
|
170
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** 按行/字符双重截断,只保留尾部(终端里最新内容在下面)。 */
|
|
174
|
+
function capScreen(text, maxLines, maxChars) {
|
|
175
|
+
let s = String(text ?? "");
|
|
176
|
+
const lines = s.split("\n");
|
|
177
|
+
let truncated = false;
|
|
178
|
+
if (lines.length > maxLines) {
|
|
179
|
+
s = lines.slice(lines.length - maxLines).join("\n");
|
|
180
|
+
truncated = true;
|
|
181
|
+
}
|
|
182
|
+
if (s.length > maxChars) {
|
|
183
|
+
s = "…" + s.slice(s.length - maxChars);
|
|
184
|
+
truncated = true;
|
|
185
|
+
}
|
|
186
|
+
return { text: s, truncated };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 每个终端记住上一次回传的屏幕,本次只回新增部分。
|
|
191
|
+
* 先按整串前缀比;不像追加(如界面重绘、清屏)就退化为按行的公共前缀。
|
|
192
|
+
* 注意 delta 文本一律先算再截断:屏幕本身才参与前缀比较,回传的只是增量。
|
|
193
|
+
*/
|
|
194
|
+
const lastScreens = new Map();
|
|
195
|
+
function screenDelta(terminalId, screen) {
|
|
196
|
+
const prev = lastScreens.get(terminalId) ?? "";
|
|
197
|
+
lastScreens.set(terminalId, screen);
|
|
198
|
+
if (prev.length === 0) return { text: screen, delta: false };
|
|
199
|
+
if (screen.startsWith(prev)) return { text: screen.slice(prev.length), delta: true };
|
|
200
|
+
const a = prev.split("\n");
|
|
201
|
+
const b = screen.split("\n");
|
|
202
|
+
let i = 0;
|
|
203
|
+
while (i < a.length && i < b.length && a[i] === b[i]) i += 1;
|
|
204
|
+
return { text: b.slice(i).join("\n"), delta: true };
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
152
207
|
//#region src/client/terminals.ts
|
|
153
208
|
/**
|
|
154
209
|
* 只读窥探本会话每个宿主保留的终端:
|
|
@@ -160,8 +215,14 @@ window.__ModuleLoader__.load({
|
|
|
160
215
|
* - attach 的帧可能是裸帧,也可能包一层 {value:帧},两种都兼容;
|
|
161
216
|
* - 读完立即 abort:断开连接释放终端输入权(副作用:GUI 终端视图
|
|
162
217
|
* 会显示「接管输入」按钮,用户点一下即恢复)。
|
|
218
|
+
*
|
|
219
|
+
* 每块屏幕一律先 stripAnsi;options.delta !== false 时再折算成「相对上次
|
|
220
|
+
* 回传的增量」(首次仍是全屏),最后按行/字符截断。屏幕本身(去转义后)
|
|
221
|
+
* 才是 delta 的比较基准,截断只作用于回传文本。
|
|
222
|
+
* @param options - { delta?: boolean },缺省为增量模式。
|
|
163
223
|
*/
|
|
164
|
-
async function terminalScreens(ctx) {
|
|
224
|
+
async function terminalScreens(ctx, options) {
|
|
225
|
+
const delta = options === void 0 || options.delta !== false;
|
|
165
226
|
try {
|
|
166
227
|
const sessionId = currentSessionId(ctx);
|
|
167
228
|
if (sessionId === null) return { error: "no session is on screen" };
|
|
@@ -182,11 +243,21 @@ window.__ModuleLoader__.load({
|
|
|
182
243
|
// 帧形状归一:裸帧或 {value:帧} 包裹都unwrap成裸帧再判 type。
|
|
183
244
|
const unwrapped = frame !== null && typeof frame === "object" && frame.value !== null && typeof frame.value === "object" && "type" in frame.value ? frame.value : frame;
|
|
184
245
|
if (unwrapped !== null && typeof unwrapped === "object" && unwrapped.type === "snapshot") {
|
|
246
|
+
const raw = typeof unwrapped.screen === "string" ? unwrapped.screen : null;
|
|
247
|
+
const clean = raw === null ? null : stripAnsi(raw);
|
|
248
|
+
let part = { text: clean, delta: false };
|
|
249
|
+
if (clean !== null) {
|
|
250
|
+
if (delta) part = screenDelta(info.id, clean);
|
|
251
|
+
else lastScreens.set(info.id, clean); // 全屏模式也要刷新基准,下一轮增量才对得上
|
|
252
|
+
}
|
|
253
|
+
const capped = clean === null ? { text: null, truncated: false } : capScreen(part.text, TERMINAL_MAX_LINES, TERMINAL_MAX_CHARS);
|
|
185
254
|
terminals.push({
|
|
186
255
|
id: info.id,
|
|
187
256
|
title: typeof info.title === "string" ? info.title : null,
|
|
188
257
|
state: typeof info.state === "string" ? info.state : null,
|
|
189
|
-
screen:
|
|
258
|
+
screen: capped.text, // 已去 ANSI;增量模式下只有自上次读取以来的新增部分
|
|
259
|
+
delta: part.delta, // false = 这一屏是完整屏幕(首次读取,或模型显式要全屏)
|
|
260
|
+
truncated: capped.truncated // true = 超出行/字符上限,只保留了尾部
|
|
190
261
|
});
|
|
191
262
|
break; // 只取基线快照,后续增量帧不消费
|
|
192
263
|
}
|
|
@@ -218,7 +289,7 @@ window.__ModuleLoader__.load({
|
|
|
218
289
|
* (宽度为 0),findSidebarWebview 的兜底会把它当成"最后一个"读回来——于是模型会
|
|
219
290
|
* 拿到用户并没有在看的页面。宁可在非浏览器标签/收起状态下给 null,也不给错的那一页。
|
|
220
291
|
*/
|
|
221
|
-
async function capture(ctx, commandId) {
|
|
292
|
+
async function capture(ctx, commandId, options) {
|
|
222
293
|
const right = rightSidebarState(ctx);
|
|
223
294
|
const activeType = right !== null && typeof right === "object" && right.active !== null && typeof right.active === "object"
|
|
224
295
|
? right.active.type
|
|
@@ -234,7 +305,7 @@ window.__ModuleLoader__.load({
|
|
|
234
305
|
text: page.text
|
|
235
306
|
},
|
|
236
307
|
right,
|
|
237
|
-
terminals: await terminalScreens(ctx),
|
|
308
|
+
terminals: await terminalScreens(ctx, options),
|
|
238
309
|
commandId: commandId ?? null // 带回命令 id,模型可核对命令-快照对应关系
|
|
239
310
|
};
|
|
240
311
|
const receipt = await sendSnapshot(payload);
|
|
@@ -287,7 +358,8 @@ window.__ModuleLoader__.load({
|
|
|
287
358
|
try {
|
|
288
359
|
const command = await fetchCommand();
|
|
289
360
|
if (command === null || command === void 0 || command.id === null || command.id === void 0) return;
|
|
290
|
-
|
|
361
|
+
// 命令里带 delta(缺省 true):模型要全屏时宿主下发的就是 false。
|
|
362
|
+
const { payload } = await capture(ctx, command.id, { delta: command.delta !== false });
|
|
291
363
|
const tabCount = Array.isArray(payload.right?.tabs) ? payload.right.tabs.length : 0;
|
|
292
364
|
toast("模型读取了侧边栏(" + String(tabCount) + " 个标签页" + (payload.page ? ",含网页" : "") + ")", true);
|
|
293
365
|
} catch (error) {
|
package/lib/index.js
CHANGED
|
@@ -36,14 +36,31 @@ const SIDEBAR_READ_TOOL = {
|
|
|
36
36
|
"including scrollback), and the sidebar browser web page text. Use this BEFORE shelling out " +
|
|
37
37
|
"via pwsh or web_fetch whenever the user asks about their terminal or a page they opened in " +
|
|
38
38
|
"the sidebar browser. Reads only the current session; data never leaves this machine; the " +
|
|
39
|
-
"user sees a toast on every read. Web page text is desktop-only (null in a plain browser)."
|
|
40
|
-
|
|
39
|
+
"user sees a toast on every read. Web page text is desktop-only (null in a plain browser). " +
|
|
40
|
+
"Terminal screens come back ANSI-free and incremental: after the first read of a terminal, " +
|
|
41
|
+
"each screen holds only the lines added since the previous read (delta:true), capped at 500 " +
|
|
42
|
+
"lines / 20000 chars; pass delta:false to get complete screens again.",
|
|
43
|
+
parameters: {
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: {
|
|
46
|
+
delta: {
|
|
47
|
+
type: "boolean",
|
|
48
|
+
description:
|
|
49
|
+
"Terminal screens are incremental by default: after the first read of a terminal, each " +
|
|
50
|
+
"screen contains only the lines added since the previous read. Pass false to force a " +
|
|
51
|
+
"complete screen for every terminal (use it when you lost track of earlier output, or " +
|
|
52
|
+
"after the screen was cleared)."
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
41
56
|
output: { schema: { type: "string" }, render: (_args, value) => [{ type: "text", text: value }] },
|
|
42
57
|
timeoutMs: 20000,
|
|
43
|
-
async execute(
|
|
58
|
+
async execute(args, exec) {
|
|
44
59
|
// 与 GET /latest?refresh=1 同一逻辑:下发命令 → 轮询 latest.commandId 对上 → 返回快照。
|
|
45
60
|
const id = "cmd-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 8);
|
|
46
|
-
|
|
61
|
+
// delta 缺省开:首次读取本来就是全屏,之后只回新增部分(省上下文)。
|
|
62
|
+
const delta = !(args !== void 0 && args !== null && args.delta === false);
|
|
63
|
+
pendingCommand = { id, action: "capture", delta, at: new Date().toISOString() };
|
|
47
64
|
const deadline = Date.now() + 15000;
|
|
48
65
|
while (Date.now() < deadline) {
|
|
49
66
|
exec.signal.throwIfAborted();
|
|
@@ -118,14 +135,16 @@ function apply(ctx) {
|
|
|
118
135
|
// 模型读取快照。带 ?refresh=1 时自动触发一轮采集并等它回来:
|
|
119
136
|
// 下发命令 → 每 300ms 检查 latest.commandId 是否对上 → 对上即返回新快照。
|
|
120
137
|
// 模型因此只需一次 GET;不带 refresh 保持原语义(立即返回现有快照)。
|
|
121
|
-
const
|
|
138
|
+
const params = new URL(req.url ?? "/", "http://localhost").searchParams;
|
|
139
|
+
const refresh = params.get("refresh") === "1";
|
|
122
140
|
if (!refresh) {
|
|
123
141
|
if (latest === null) json(res, req, 404, { error: "nothing captured yet; add ?refresh=1 to trigger a capture" });
|
|
124
142
|
else json(res, req, 200, latest);
|
|
125
143
|
return;
|
|
126
144
|
}
|
|
127
145
|
const id = "cmd-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 8);
|
|
128
|
-
|
|
146
|
+
// delta 同样缺省开;?delta=0 表示这次要全屏。
|
|
147
|
+
pendingCommand = { id, action: "capture", delta: params.get("delta") !== "0", at: new Date().toISOString() };
|
|
129
148
|
const deadline = Date.now() + 10000;
|
|
130
149
|
while (Date.now() < deadline) {
|
|
131
150
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
@@ -155,6 +174,8 @@ function apply(ctx) {
|
|
|
155
174
|
pendingCommand = {
|
|
156
175
|
id: "cmd-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 8),
|
|
157
176
|
action: "capture",
|
|
177
|
+
// body.delta === false 时才要全屏;缺省增量。
|
|
178
|
+
delta: !(body !== null && body !== void 0 && typeof body === "object" && body.delta === false),
|
|
158
179
|
at: new Date().toISOString()
|
|
159
180
|
};
|
|
160
181
|
json(res, req, 200, { ok: true, id: pendingCommand.id });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sidebar-reader",
|
|
3
3
|
"description": "Let the model read the current session's sidebar on demand: the active tab, official right-sidebar tabs, terminal screens and browser page text.",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"license": "MIT",
|