dsh-session-autarchive 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.en.md +104 -0
- package/README.md +103 -2
- package/assets/icon-180.png +0 -0
- package/cordis.patch.yml +5 -0
- package/index.js +506 -0
- package/invariant.js +10 -0
- package/lib/client.js +342 -0
- package/package.json +63 -4
- package/scripts/build-client.mjs +80 -0
- package/scripts/smoke.mjs +225 -0
- package/src/entry.jsx +367 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-session-autarchive contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# dsh-session-autarchive
|
|
2
|
+
|
|
3
|
+
<img src="assets/icon-180.png" width="96" align="right" alt="dsh-session-autarchive">
|
|
4
|
+
|
|
5
|
+
[中文](README.md) | **English**
|
|
6
|
+
|
|
7
|
+
Archives sessions that have gone unused for longer than a configurable number of days (5 by default). Archived sessions, pinned sessions (exempt by default), and sessions marked "do not auto-archive" are skipped. A session context-menu item marks a single session, and a field in General settings changes the threshold.
|
|
8
|
+
|
|
9
|
+
## Where it shows up
|
|
10
|
+
|
|
11
|
+
| Where | What it looks like | What it does |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| Session context menu | One row, "Do not auto-archive", next to Pin / Rename / Fork / Archive | Click once to mark, again to unmark |
|
|
14
|
+
| Session row start | A small shield on marked sessions | Shows at a glance that the session is protected |
|
|
15
|
+
| Hover card | One line, "Not auto-archived" | Same, with text |
|
|
16
|
+
| General settings | A row at the bottom, "Auto-archive after (days)" | Saved on blur or Enter, writes the same host field |
|
|
17
|
+
|
|
18
|
+
## How it decides and runs
|
|
19
|
+
|
|
20
|
+
- **Decision**: scan `$DSH_HOME/sessions/<workspace>/session-*` directories, take the newest file time inside each as "last activity". Sessions older than the threshold (5 days by default), not yet archived, not on the protected list, and not pinned (pinning is exempt by default) become pending sessions.
|
|
21
|
+
- **Execution**: the host runs a round every 10 minutes (the first one 60 seconds after start, so it keeps running even with no window open); the browser half polls the pending list every 5 minutes and archives through the official channel when it is available, so the sidebar updates immediately.
|
|
22
|
+
- Archiving goes through the official `archiveSession` call. It does not delete data: archived sessions stay in the archive list and can be restored.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
dsh plugin --profile desktop add github:taoziliyouchong/dsh-session-autarchive
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Restart DSH afterwards. Replace `desktop` with your own profile name if you use another one.
|
|
31
|
+
|
|
32
|
+
Compatible with DSH 0.2.1-rc.5 (tested); 0.3 and later are not guaranteed.
|
|
33
|
+
|
|
34
|
+
Once published to npm, this also works:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
dsh plugin --profile desktop add dsh-session-autarchive
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**It is enabled by default with a 5-day threshold.** Installing it starts archiving by that rule. To turn it off first:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
# tool dsh-session-autarchive, action=config, enabled=false
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Tool
|
|
47
|
+
|
|
48
|
+
The tool is named `dsh-session-autarchive` and takes five actions:
|
|
49
|
+
|
|
50
|
+
| action | What it does |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `status` (default) | Configuration summary, pending sessions, protected list, last run |
|
|
53
|
+
| `run` | Archive the pending sessions now; `dryRun: true` lists them without touching anything |
|
|
54
|
+
| `protect` | Mark one session "do not auto-archive" (needs `sessionId`) |
|
|
55
|
+
| `unprotect` | Remove the mark |
|
|
56
|
+
| `config` | Change `days`, `enabled`, `exemptPinned` |
|
|
57
|
+
|
|
58
|
+
## Data files
|
|
59
|
+
|
|
60
|
+
All under `$DSH_HOME/session-autarchive/`:
|
|
61
|
+
|
|
62
|
+
| File | Written by | Notes |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `protected.json` | protect / unprotect only | The single source of the protected list. The archive timer never writes it, so a run cannot wash the marks away. |
|
|
65
|
+
| `state.json` | archive rounds, config | Switch, threshold, pin exemption, last run result; holds no list. |
|
|
66
|
+
| `audit.log` | list changes, every round | One line each, so a lost mark can be traced by time. |
|
|
67
|
+
|
|
68
|
+
Writes are temp-file-then-rename, and reads retry — a half-written file is never mistaken for "no list" and overwritten with defaults.
|
|
69
|
+
|
|
70
|
+
## How it works
|
|
71
|
+
|
|
72
|
+
- The host half registers four local routes: `GET /dsh-session-autarchive/api/state`, `POST .../protect`, `POST .../config`, `POST .../run`. Loopback addresses only (`127.*`, `::1`, `::ffff:127.*`); anything else gets 403, a wrong method gets 405.
|
|
73
|
+
- The browser half mounts four slots (menu row, row start, hover card, settings row). Services are probed with `ctx.get`; when one is missing that entry is skipped and the others still mount.
|
|
74
|
+
- No network access, nothing uploaded. Decisions use local file times only.
|
|
75
|
+
|
|
76
|
+
## Known limits
|
|
77
|
+
|
|
78
|
+
- Without a `workspaceRegistry` service on the host side, the host can only list pending sessions and cannot archive by itself; the browser half then executes through the official channel.
|
|
79
|
+
- Only sessions stored under `$DSH_HOME/sessions` are considered.
|
|
80
|
+
- Do not install another auto-archive plugin alongside this one: the same UI slots can only be claimed once, and duplicates show the menu row and the settings row twice.
|
|
81
|
+
- Enabled by default: it starts archiving at the 5-day threshold right after install. To watch first, set `enabled` to `false` or raise `days`.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
The source has two halves:
|
|
86
|
+
|
|
87
|
+
- `index.js` — host side (decision, archiving, four routes, the tool)
|
|
88
|
+
- `src/entry.jsx` — browser side (menu row, row shield, hover line, settings row, the 5-minute fast path)
|
|
89
|
+
|
|
90
|
+
Editing `src/entry.jsx` requires rebuilding. `lib/client.js` is a build artifact committed to the repository; without it the UI does not load:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm install
|
|
94
|
+
npm run build:client # regenerate lib/client.js
|
|
95
|
+
npm run check:client # verify the committed artifact matches the source
|
|
96
|
+
npm run smoke # structure / bundle manifest / registration / authorization / state / artifact
|
|
97
|
+
npm run check # syntax
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The smoke run uses a temporary `$DSH_HOME`; it never reads or changes your session data. Build rules: keep `react` and `react/jsx-runtime` external (the DSH client module table provides them); the `id` inside the `window.__ModuleLoader__.load({ id, factory })` envelope must equal the package name.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-session-autarchive
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="assets/icon-180.png" width="96" align="right" alt="dsh-session-autarchive">
|
|
4
|
+
|
|
5
|
+
**中文** | [English](README.en.md)
|
|
6
|
+
|
|
7
|
+
把长期没动过的会话自动归档。按会话档的最后写入时间算天数,默认 5 天;已归档、置顶(可关)、标记「不自动归档」的都跳过。侧栏会话右键菜单给单个会话加标记,通用设置里改天数。
|
|
8
|
+
|
|
9
|
+
## 界面上的三处
|
|
10
|
+
|
|
11
|
+
| 位置 | 样子 | 作用 |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| 会话右键菜单 | 与「置顶会话/重命名/分叉会话/归档会话」并列的一行「不自动归档」 | 点一次标记,再点一次取消 |
|
|
14
|
+
| 会话行首 | 被标记的会话多一个小盾牌 | 一眼看出这条不会被自动归档 |
|
|
15
|
+
| 悬停卡片 | 一行「不会被自动归档」 | 同上,带文字说明 |
|
|
16
|
+
| 通用设置 | 最底一行「自动归档天数」 | 失焦或回车即保存,写的是宿主同一个字段 |
|
|
17
|
+
|
|
18
|
+
## 判定与执行
|
|
19
|
+
|
|
20
|
+
- **判定**:扫 `$DSH_HOME/sessions/<工作区>/session-*` 目录,取目录内最新文件时间当「最后活动」;超过阈值(默认 5 天)、未归档、不在保护名单、非置顶(置顶豁免默认开)的就是待归档的会话。
|
|
21
|
+
- **执行**:宿主每 10 分钟跑一轮(启动 60 秒后第一次,窗口没开也照常跑);浏览器半边每 5 分钟拉一次待归档清单,拿到官方归档通道就当场归档,侧栏立即刷新。
|
|
22
|
+
- 归档走官方 `archiveSession`,不是删数据。归档后的会话在侧栏归档列表里,可以恢复。
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
dsh plugin --profile desktop add github:taoziliyouchong/dsh-session-autarchive
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
装完重启 DSH。用别的 profile 就把 `desktop` 换成你的 profile 名。
|
|
31
|
+
|
|
32
|
+
兼容:DSH 0.2.1-rc.5 实测通过;0.3 起不保证。
|
|
33
|
+
|
|
34
|
+
发布到 npm 之后也可以:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
dsh plugin --profile desktop add dsh-session-autarchive
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**注意:默认开启,阈值 5 天。** 装好就会开始按这个口径归档。不想让它动,先关掉:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
# 工具 dsh-session-autarchive,action=config,enabled=false
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 工具
|
|
47
|
+
|
|
48
|
+
工具名 `dsh-session-autarchive`,五个动作:
|
|
49
|
+
|
|
50
|
+
| action | 做什么 |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `status`(默认) | 配置摘要、当前待归档会话、保护名单、最近一次执行 |
|
|
53
|
+
| `run` | 立刻归档当前待归档会话;`dryRun: true` 只列清单不动手 |
|
|
54
|
+
| `protect` | 标记单个会话「不自动归档」(要 `sessionId`) |
|
|
55
|
+
| `unprotect` | 取消标记 |
|
|
56
|
+
| `config` | 改 `days`(天数)、`enabled`(开关)、`exemptPinned`(置顶是否豁免) |
|
|
57
|
+
|
|
58
|
+
## 数据文件
|
|
59
|
+
|
|
60
|
+
都在 `$DSH_HOME/session-autarchive/`:
|
|
61
|
+
|
|
62
|
+
| 文件 | 写它的地方 | 说明 |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `protected.json` | 只有 protect/unprotect | 保护名单的唯一来源。自动归档那条定时链不碰它,怎么跑都洗不掉标记。 |
|
|
65
|
+
| `state.json` | 定时归档、config | 开关、阈值、置顶豁免、最近一次执行结果;不存名单。 |
|
|
66
|
+
| `audit.log` | 名单改动、每轮归档 | 一行一条,标记哪天没了可以对着时间查。 |
|
|
67
|
+
|
|
68
|
+
写入一律「临时文件 + 改名」,读盘失败会重试——不会把半截文件当成「没有名单」再把默认值写回去。
|
|
69
|
+
|
|
70
|
+
## 机制
|
|
71
|
+
|
|
72
|
+
- 宿主半边注册四条本机路由:`GET /dsh-session-autarchive/api/state`、`POST .../protect`、`POST .../config`、`POST .../run`。只接受回环地址(`127.*`、`::1`、`::ffff:127.*`),远程访问一律 403;方法不对 405。
|
|
73
|
+
- 浏览器半边用 `ctx.slots` 挂四个座位(菜单行、行首、悬停、设置行),服务探测一律 `ctx.get`,拿不到就跳过,不影响其他入口。
|
|
74
|
+
- 不联网、不上传任何内容;判定只用本地文件时间。
|
|
75
|
+
|
|
76
|
+
## 已知限制
|
|
77
|
+
|
|
78
|
+
- 宿主侧没有 `workspaceRegistry` 服务时,只能列出待归档会话、不能自己归档;此时由浏览器半边走官方通道执行。
|
|
79
|
+
- 只扫 `$DSH_HOME/sessions` 下的会话档;不在这个目录里的会话不参与判定。
|
|
80
|
+
- 不要与另一个自动归档插件同时安装:同一组界面座位只能挂一份,重复安装会出现两行菜单和两行设置。
|
|
81
|
+
- 默认开启:装好就会按 5 天阈值归档。想先观察,把 `enabled` 改成 `false`,或把 `days` 调大。
|
|
82
|
+
|
|
83
|
+
## 开发
|
|
84
|
+
|
|
85
|
+
源码分两半:
|
|
86
|
+
|
|
87
|
+
- `index.js` —— 宿主半边(判定、归档、四条路由、工具)
|
|
88
|
+
- `src/entry.jsx` —— 浏览器半边(菜单行、行首盾牌、悬停说明、设置行、5 分钟快通道)
|
|
89
|
+
|
|
90
|
+
改过 `src/entry.jsx` 必须重新打包。`lib/client.js` 是提交进仓库的构建产物,缺了它界面不会加载:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm install
|
|
94
|
+
npm run build:client # 重新生成 lib/client.js
|
|
95
|
+
npm run check:client # 比对新产物与已提交产物是否一致
|
|
96
|
+
npm run smoke # 结构 / 组合声明 / 注册 / 鉴权 / 状态读写 / 产物
|
|
97
|
+
npm run check # 语法
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
冒烟全程用临时 `$DSH_HOME`,不读也不改你的会话数据。打包要求:`react` 与 `react/jsx-runtime` 保持 external(由 DSH 客户端模块表提供);产物外壳 `window.__ModuleLoader__.load({ id, factory })` 里的 `id` 必须等于包名。
|
|
101
|
+
|
|
102
|
+
## 许可
|
|
103
|
+
|
|
104
|
+
MIT
|
|
Binary file
|