dsh-session-guard 0.1.2 → 0.1.3
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/CHANGELOG.ja.md +29 -29
- package/CHANGELOG.ko.md +29 -29
- package/CHANGELOG.md +44 -29
- package/INSTALL.ja.md +42 -42
- package/INSTALL.ko.md +42 -42
- package/INSTALL.md +44 -44
- package/INSTALL.zh.md +42 -42
- package/README.en.md +170 -170
- package/README.ja.md +106 -106
- package/README.ko.md +106 -106
- package/README.md +9 -0
- package/dsh.plugin.json +13 -0
- package/lib/client.js +270 -270
- package/package.json +95 -78
- package/src/bridge.js +76 -76
- package/src/client/index.ts +56 -56
- package/src/client/locales.ts +95 -95
- package/src/client/settings-card.tsx +191 -191
- package/src/client/status-badge.tsx +66 -66
- package/src/index.js +293 -293
- package/src/pause-gate.js +416 -416
- package/src/retry.js +202 -202
- package/src/settings.js +97 -97
- package/src/time.js +104 -104
package/README.en.md
CHANGED
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<strong>Peak auto session gate: weekend mode + peak auto-pause + session-level freeze + backend auto-retry</strong>
|
|
3
|
-
</p>
|
|
4
|
-
<p align="center">
|
|
5
|
-
<strong>English</strong> · <a href="README.md">中文</a> · <a href="README.ja.md">日本語</a> · <a href="README.ko.md">한국어</a>
|
|
6
|
-
</p>
|
|
7
|
-
<p align="center">
|
|
8
|
-
<a href="LICENSE"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-263146?style=flat-square"></a>
|
|
9
|
-
<img src="https://camo.githubusercontent.com/2c11fb2e0e14bb9985c5acbe61123a7441c5ee63aa27fa6e04e2a707ebfd6022/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6473682d2d706c7567696e2d72656164792d3437384342463f6c6f676f3d646565707365656b266c6f676f436f6c6f723d7768697465" alt="dsh-plugin" style="max-width: 100%;">
|
|
10
|
-
<img alt="Public beta" src="https://img.shields.io/badge/status-public%20beta-7da1de?style=flat-square">
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
# dsh-session-guard
|
|
14
|
-
|
|
15
|
-
- [English README](./README.en.md)
|
|
16
|
-
- [中文 README](./README.md)
|
|
17
|
-
- [日本語 README](./README.ja.md)
|
|
18
|
-
- [한국어 README](./README.ko.md)
|
|
19
|
-
- [Installation guide](./INSTALL.md)
|
|
20
|
-
- [中文安装指南](./INSTALL.zh.md)
|
|
21
|
-
- [日本語インストールガイド](./INSTALL.ja.md)
|
|
22
|
-
- [한국어 설치 안내](./INSTALL.ko.md)
|
|
23
|
-
- [Changelog](./CHANGELOG.md)
|
|
24
|
-
- [日本語 changelog](./CHANGELOG.ja.md)
|
|
25
|
-
- [한국어 changelog](./CHANGELOG.ko.md)
|
|
26
|
-
|
|
27
|
-
> **Compatibility note:** v0.1.1 ships Japanese (`ja`) and Korean (`ko`) dictionaries, but the current official DSH releases expose only `zh` and `en` through `LocaleRuntime`. On stock DSH, selecting `ja` or `ko` fails with `locale "<id>" is not registered`. These languages will work after official DSH adds the locale IDs. Advanced users can use a DSH fork that updates `LOCALE_IDS` and `LOCALES` labels, then rebuild.
|
|
28
|
-
|
|
29
|
-
> Automatically pause running sessions during peak pricing hours and resume during off-peak/weekend; pair with input-traffic's freeze button for **per-session** locking; backend **auto-retry** yields during freeze/gate. Core based on a custom session gate (`agent.cancel keepInbox + goals.pause + session/event safe boundary + followup resume`), no longer depending on dsh-task-control.
|
|
30
|
-
|
|
31
|
-
A cordis plugin assembled via the `dsh plugin` command and a bundle patch — no dsh source changes, no PR required.
|
|
32
|
-
|
|
33
|
-
> 💡 **Why recommended**: DeepSeek moved to **peak/off-peak billing** on 2026-08-17 — the peak window (Beijing time 09:00-12:00, 14:00-18:00) costs **2×** the off-peak rate. This plugin auto-pauses running sessions during peak and auto-resumes off-peak, saving up to **50%** on long-running sessions; manual freeze (via input-traffic button) provides per-session precision.
|
|
34
|
-
|
|
35
|
-
## Features
|
|
36
|
-
|
|
37
|
-
- **Weekend mode**: detects weekends (timezone-correct via `Intl.DateTimeFormat`, no裸 `getUTCDay()` Beijing-boundary 8-hour bug) → weekends ignore peak/off-peak, run freely.
|
|
38
|
-
- **Peak auto-pause (global)**: on peak entry (and not weekend), auto-pauses all running root sessions; off-peak auto-resumes all — **global switch, no manual action needed**.
|
|
39
|
-
- **Per-session freeze / resume**: `sessionGuard` redundant port + `POST /session-guard/rpc`, input-traffic freeze button per-session passthrough; also provides `/pause /resume /cancel` manual commands.
|
|
40
|
-
- **Backend auto-retry (D9)**: turn/end transient failures (error/429/max-tokens) auto-retry with adaptive backoff; permanent failures stop; **yields during freeze/gate**, never bypasses the session gate.
|
|
41
|
-
- **Fail-open**: custom session gate unavailable, session-guard not installed, settings service missing — all silently degrade, never crash on dependencies.
|
|
42
|
-
|
|
43
|
-
## Installation
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
dsh plugin --profile web add github:<owner>/dsh-session-guard
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Restart dsh web and refresh the page after installation.
|
|
50
|
-
|
|
51
|
-
## Settings (Settings → Plugins → session-guard, simple toggles)
|
|
52
|
-
|
|
53
|
-
| Toggle | Default | Description |
|
|
54
|
-
|---|---|---|
|
|
55
|
-
| `enabled` | on | **Peak auto-pause**: auto-pause running sessions during peak hours |
|
|
56
|
-
| `offPeakAutoResume` | on | **Off-peak auto-resume**: auto-resume paused sessions off-peak; off = no auto-resume (manual required) |
|
|
57
|
-
| `weekendMode` | on | **Weekend mode**: detect weekends → no auto-pause on weekends (no peak, run freely) |
|
|
58
|
-
| `queueFallback` | on | Fallback to lock-wait queue when custom session gate is unavailable (fail-open) |
|
|
59
|
-
| `retryEnabled` | off | **Auto-retry (backend)**: transient failure auto-resume (off by default, conservative) |
|
|
60
|
-
|
|
61
|
-
Additional configuration:
|
|
62
|
-
|
|
63
|
-
- `timezone` (default Asia/Shanghai) — used for **weekend detection** and badge display; **does not affect peak/off-peak detection** (always Beijing time);
|
|
64
|
-
- `peakWindows` (default 09:00–12:00 / 14:00–18:00) — peak windows in Beijing time (UTC+8), matching DeepSeek's official billing;
|
|
65
|
-
- `pauseMode` (`safe`/`force`), `pauseReason` (`wait`/`stop`);
|
|
66
|
-
- Retry parameters: `retryText`, `retryGraceMs`, `retryCooldownMs`, `retryBackoffFactor`, `retryBackoffMaxMs`, `retryMaxConsecutive`.
|
|
67
|
-
|
|
68
|
-
## Behavior
|
|
69
|
-
|
|
70
|
-
### Peak auto-gate (global)
|
|
71
|
-
|
|
72
|
-
- **Peak entry** (and not weekend): calls `gate.stopNextTurn` on all running root sessions — custom session gate truly pauses (doesn't interrupt reasoning, pauses at safe boundary before next tool dispatch), or falls back to lock-wait queue per `queueFallback`;
|
|
73
|
-
- **Off-peak / weekend**: `gate.resume` **all** sessions (auto-resume, no manual action) — controlled by `offPeakAutoResume` toggle;
|
|
74
|
-
- **Peak timezone**: hardcoded to Beijing time (`Asia/Shanghai`), matching DeepSeek's official billing basis — not affected by the `timezone` setting;
|
|
75
|
-
- State machine: single-instance `NORMAL ↔ PAUSED_PEAK` (`scheduler.js`), driven by a single 30s tick.
|
|
76
|
-
|
|
77
|
-
### Session locking (freeze)
|
|
78
|
-
|
|
79
|
-
- **Redundant port**: `ctx.provide('sessionGuard', service)` — `stopNextTurn(sessionId)` / `resume(sessionId)` / `lockQueue(sessionId)` / `unlockQueue(sessionId)` / `state(sessionId)`;
|
|
80
|
-
- **RPC bridge**: `POST /session-guard/rpc { action, sessionId }` — input-traffic freeze button calls `stopNextTurn` / `resume` per `sessionId`; silently skipped when session-guard is not installed (fail-open);
|
|
81
|
-
- **Manual commands**: `/pause [force|safe] [stop|wait]`, `/resume [confirm] [rerun|skip]`, `/cancel` —作用于调用它的会话.
|
|
82
|
-
|
|
83
|
-
### Backend auto-retry (D9)
|
|
84
|
-
|
|
85
|
-
Listens to `turn/end`, classifies failures:
|
|
86
|
-
|
|
87
|
-
- **Transient** (error/429/max-tokens) → adaptive backoff auto `followup(retryText)` resume;
|
|
88
|
-
- **Permanent** (auth/balance/model/context limit) → stop;
|
|
89
|
-
- **Yields during freeze/gate**: `isFrozen(sessionId)` true (queueLocked / paused / taskControl paused) → no retry;
|
|
90
|
-
- User intervention or successful turn resets consecutive failure count.
|
|
91
|
-
|
|
92
|
-
### Status badge (frontend display)
|
|
93
|
-
|
|
94
|
-
A **read-only** status badge is rendered on the right side of the composer input area, reflecting the current phase in real time:
|
|
95
|
-
|
|
96
|
-
| Phase | Label | CSS class | Meaning |
|
|
97
|
-
|---|---|---|---|
|
|
98
|
-
| `peak` | 高峰 | `sg-peak` | Weekday peak hours, sessions auto-paused |
|
|
99
|
-
| `off-peak` | 谷时 | `sg-off` | Off-peak hours, sessions running normally |
|
|
100
|
-
| `weekend` | 周末 | `sg-weekend` | Weekend (when weekend mode is on), ignore peak/off-peak |
|
|
101
|
-
|
|
102
|
-
- **Polling**: requests `GET /session-guard/status` every 15 seconds for the global `phase`;
|
|
103
|
-
- **Fail-open**: route unreachable, network error, or `enabled` off → badge silently hidden, no session affected;
|
|
104
|
-
- **Independent of input-traffic**: the badge is rendered by session-guard's client code alone — **input-traffic is not required**. input-traffic only provides the freeze button, which is unrelated to the badge;
|
|
105
|
-
- **Tooltip**: hovering shows `phase · timezone · weekend mode` (e.g. `周末 · Asia/Shanghai · 周末模式`).
|
|
106
|
-
|
|
107
|
-
### Timezone handling
|
|
108
|
-
|
|
109
|
-
- **Peak/off-peak detection**: always uses **Beijing time (UTC+8)** via `BILLING_TIMEZONE = 'Asia/Shanghai'`, matching DeepSeek's official billing basis. This is **hardcoded** and not affected by the `timezone` setting;
|
|
110
|
-
- **Weekend detection**: uses the user-configured `timezone` (e.g. `Asia/Tokyo`, `Asia/Seoul`), because "weekend" is a local concept;
|
|
111
|
-
- `Intl.DateTimeFormat` is used for timezone projection — invalid IANA timezone names throw `RangeError`, caught by fail-open and falling back to `Asia/Shanghai`;
|
|
112
|
-
- Peak windows are **left-closed, right-open** `[start, end)`, supporting cross-midnight windows (e.g. `22:00–06:00`);
|
|
113
|
-
- The `timezone` setting works identically across all UI languages (zh/en/ja/ko) — IANA timezone names are locale-independent.
|
|
114
|
-
|
|
115
|
-
### Coordination with input-traffic
|
|
116
|
-
|
|
117
|
-
- input-traffic's **freeze button** triggers via `sessionGuard.stopNextTurn` (RPC, per-session) on the server side;
|
|
118
|
-
- input-traffic **only does freeze enhancement** (queue freeze/unfreeze + composer block), retry is handled by this plugin's backend;
|
|
119
|
-
- Both share "session isolation" semantics: input-traffic freeze queue keyed by sessionId, session-guard RPC also keyed by sessionId.
|
|
120
|
-
|
|
121
|
-
## Redundant port `sessionGuard`
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
{
|
|
125
|
-
stopNextTurn(sessionId, opts),
|
|
126
|
-
resume(sessionId, opts),
|
|
127
|
-
lockQueue(sessionId, reason),
|
|
128
|
-
unlockQueue(sessionId),
|
|
129
|
-
state(sessionId),
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## HTTP routes
|
|
134
|
-
|
|
135
|
-
- `GET /session-guard/state?session=<id>` — session state
|
|
136
|
-
- `GET /session-guard/settings` — settings + taskControl availability
|
|
137
|
-
- `GET /session-guard/status` — global current phase (status badge polling)
|
|
138
|
-
- `GET /session-guard/diag` — runtime diagnostics
|
|
139
|
-
- `POST /session-guard/rpc` — `{ action: stopNextTurn|resume|lockQueue|unlockQueue|state, sessionId }`
|
|
140
|
-
|
|
141
|
-
## State storage
|
|
142
|
-
|
|
143
|
-
Per-session JSON: `$DSH_HOME/.dsh/session-guard/<sessionId>.json` (atomic write; `DSH_SESSION_GUARD_STATE_DIR` override).
|
|
144
|
-
|
|
145
|
-
## Tests
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
npm test # node --test tests/*.test.mjs (timezone/weekend/state-machine/session-gate/bridge/retry)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Modules
|
|
152
|
-
|
|
153
|
-
| File | Responsibility |
|
|
154
|
-
|---|---|
|
|
155
|
-
| `src/time.js` | Peak/weekend detection (timezone-correct) |
|
|
156
|
-
| `src/scheduler.js` | Pure state machine NORMAL ↔ PAUSED_PEAK |
|
|
157
|
-
| `src/pause-gate.js` | Custom session gate engine |
|
|
158
|
-
| `src/pause-store.js` | Custom pause state persistence |
|
|
159
|
-
| `src/gate.js` | Session gate driver (custom true pause / fallback lock queue, fail-open) |
|
|
160
|
-
| `src/bridge.js` | `sessionGuard` redundant port |
|
|
161
|
-
| `src/retry.js` | Backend auto-retry (failure classification/backoff/freeze yield) |
|
|
162
|
-
| `src/detect.js` | Auto-detection (host taskControl / client input-traffic bridge) |
|
|
163
|
-
| `src/store.js` | Per-session persistent state |
|
|
164
|
-
| `src/settings.js` | Settings sub-panel (schemastery schema + fail-open registration) |
|
|
165
|
-
| `src/index.js` | Host apply (settings/routes/tick/provide service/retry wiring) |
|
|
166
|
-
| `src/client/` | Browser half (status badge + settings card) |
|
|
167
|
-
|
|
168
|
-
## License
|
|
169
|
-
|
|
170
|
-
MIT — see [LICENSE](LICENSE).
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>Peak auto session gate: weekend mode + peak auto-pause + session-level freeze + backend auto-retry</strong>
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<strong>English</strong> · <a href="README.md">中文</a> · <a href="README.ja.md">日本語</a> · <a href="README.ko.md">한국어</a>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="LICENSE"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-263146?style=flat-square"></a>
|
|
9
|
+
<img src="https://camo.githubusercontent.com/2c11fb2e0e14bb9985c5acbe61123a7441c5ee63aa27fa6e04e2a707ebfd6022/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6473682d2d706c7567696e2d72656164792d3437384342463f6c6f676f3d646565707365656b266c6f676f436f6c6f723d7768697465" alt="dsh-plugin" style="max-width: 100%;">
|
|
10
|
+
<img alt="Public beta" src="https://img.shields.io/badge/status-public%20beta-7da1de?style=flat-square">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
# dsh-session-guard
|
|
14
|
+
|
|
15
|
+
- [English README](./README.en.md)
|
|
16
|
+
- [中文 README](./README.md)
|
|
17
|
+
- [日本語 README](./README.ja.md)
|
|
18
|
+
- [한국어 README](./README.ko.md)
|
|
19
|
+
- [Installation guide](./INSTALL.md)
|
|
20
|
+
- [中文安装指南](./INSTALL.zh.md)
|
|
21
|
+
- [日本語インストールガイド](./INSTALL.ja.md)
|
|
22
|
+
- [한국어 설치 안내](./INSTALL.ko.md)
|
|
23
|
+
- [Changelog](./CHANGELOG.md)
|
|
24
|
+
- [日本語 changelog](./CHANGELOG.ja.md)
|
|
25
|
+
- [한국어 changelog](./CHANGELOG.ko.md)
|
|
26
|
+
|
|
27
|
+
> **Compatibility note:** v0.1.1 ships Japanese (`ja`) and Korean (`ko`) dictionaries, but the current official DSH releases expose only `zh` and `en` through `LocaleRuntime`. On stock DSH, selecting `ja` or `ko` fails with `locale "<id>" is not registered`. These languages will work after official DSH adds the locale IDs. Advanced users can use a DSH fork that updates `LOCALE_IDS` and `LOCALES` labels, then rebuild.
|
|
28
|
+
|
|
29
|
+
> Automatically pause running sessions during peak pricing hours and resume during off-peak/weekend; pair with input-traffic's freeze button for **per-session** locking; backend **auto-retry** yields during freeze/gate. Core based on a custom session gate (`agent.cancel keepInbox + goals.pause + session/event safe boundary + followup resume`), no longer depending on dsh-task-control.
|
|
30
|
+
|
|
31
|
+
A cordis plugin assembled via the `dsh plugin` command and a bundle patch — no dsh source changes, no PR required.
|
|
32
|
+
|
|
33
|
+
> 💡 **Why recommended**: DeepSeek moved to **peak/off-peak billing** on 2026-08-17 — the peak window (Beijing time 09:00-12:00, 14:00-18:00) costs **2×** the off-peak rate. This plugin auto-pauses running sessions during peak and auto-resumes off-peak, saving up to **50%** on long-running sessions; manual freeze (via input-traffic button) provides per-session precision.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **Weekend mode**: detects weekends (timezone-correct via `Intl.DateTimeFormat`, no裸 `getUTCDay()` Beijing-boundary 8-hour bug) → weekends ignore peak/off-peak, run freely.
|
|
38
|
+
- **Peak auto-pause (global)**: on peak entry (and not weekend), auto-pauses all running root sessions; off-peak auto-resumes all — **global switch, no manual action needed**.
|
|
39
|
+
- **Per-session freeze / resume**: `sessionGuard` redundant port + `POST /session-guard/rpc`, input-traffic freeze button per-session passthrough; also provides `/pause /resume /cancel` manual commands.
|
|
40
|
+
- **Backend auto-retry (D9)**: turn/end transient failures (error/429/max-tokens) auto-retry with adaptive backoff; permanent failures stop; **yields during freeze/gate**, never bypasses the session gate.
|
|
41
|
+
- **Fail-open**: custom session gate unavailable, session-guard not installed, settings service missing — all silently degrade, never crash on dependencies.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
dsh plugin --profile web add github:<owner>/dsh-session-guard
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Restart dsh web and refresh the page after installation.
|
|
50
|
+
|
|
51
|
+
## Settings (Settings → Plugins → session-guard, simple toggles)
|
|
52
|
+
|
|
53
|
+
| Toggle | Default | Description |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `enabled` | on | **Peak auto-pause**: auto-pause running sessions during peak hours |
|
|
56
|
+
| `offPeakAutoResume` | on | **Off-peak auto-resume**: auto-resume paused sessions off-peak; off = no auto-resume (manual required) |
|
|
57
|
+
| `weekendMode` | on | **Weekend mode**: detect weekends → no auto-pause on weekends (no peak, run freely) |
|
|
58
|
+
| `queueFallback` | on | Fallback to lock-wait queue when custom session gate is unavailable (fail-open) |
|
|
59
|
+
| `retryEnabled` | off | **Auto-retry (backend)**: transient failure auto-resume (off by default, conservative) |
|
|
60
|
+
|
|
61
|
+
Additional configuration:
|
|
62
|
+
|
|
63
|
+
- `timezone` (default Asia/Shanghai) — used for **weekend detection** and badge display; **does not affect peak/off-peak detection** (always Beijing time);
|
|
64
|
+
- `peakWindows` (default 09:00–12:00 / 14:00–18:00) — peak windows in Beijing time (UTC+8), matching DeepSeek's official billing;
|
|
65
|
+
- `pauseMode` (`safe`/`force`), `pauseReason` (`wait`/`stop`);
|
|
66
|
+
- Retry parameters: `retryText`, `retryGraceMs`, `retryCooldownMs`, `retryBackoffFactor`, `retryBackoffMaxMs`, `retryMaxConsecutive`.
|
|
67
|
+
|
|
68
|
+
## Behavior
|
|
69
|
+
|
|
70
|
+
### Peak auto-gate (global)
|
|
71
|
+
|
|
72
|
+
- **Peak entry** (and not weekend): calls `gate.stopNextTurn` on all running root sessions — custom session gate truly pauses (doesn't interrupt reasoning, pauses at safe boundary before next tool dispatch), or falls back to lock-wait queue per `queueFallback`;
|
|
73
|
+
- **Off-peak / weekend**: `gate.resume` **all** sessions (auto-resume, no manual action) — controlled by `offPeakAutoResume` toggle;
|
|
74
|
+
- **Peak timezone**: hardcoded to Beijing time (`Asia/Shanghai`), matching DeepSeek's official billing basis — not affected by the `timezone` setting;
|
|
75
|
+
- State machine: single-instance `NORMAL ↔ PAUSED_PEAK` (`scheduler.js`), driven by a single 30s tick.
|
|
76
|
+
|
|
77
|
+
### Session locking (freeze)
|
|
78
|
+
|
|
79
|
+
- **Redundant port**: `ctx.provide('sessionGuard', service)` — `stopNextTurn(sessionId)` / `resume(sessionId)` / `lockQueue(sessionId)` / `unlockQueue(sessionId)` / `state(sessionId)`;
|
|
80
|
+
- **RPC bridge**: `POST /session-guard/rpc { action, sessionId }` — input-traffic freeze button calls `stopNextTurn` / `resume` per `sessionId`; silently skipped when session-guard is not installed (fail-open);
|
|
81
|
+
- **Manual commands**: `/pause [force|safe] [stop|wait]`, `/resume [confirm] [rerun|skip]`, `/cancel` —作用于调用它的会话.
|
|
82
|
+
|
|
83
|
+
### Backend auto-retry (D9)
|
|
84
|
+
|
|
85
|
+
Listens to `turn/end`, classifies failures:
|
|
86
|
+
|
|
87
|
+
- **Transient** (error/429/max-tokens) → adaptive backoff auto `followup(retryText)` resume;
|
|
88
|
+
- **Permanent** (auth/balance/model/context limit) → stop;
|
|
89
|
+
- **Yields during freeze/gate**: `isFrozen(sessionId)` true (queueLocked / paused / taskControl paused) → no retry;
|
|
90
|
+
- User intervention or successful turn resets consecutive failure count.
|
|
91
|
+
|
|
92
|
+
### Status badge (frontend display)
|
|
93
|
+
|
|
94
|
+
A **read-only** status badge is rendered on the right side of the composer input area, reflecting the current phase in real time:
|
|
95
|
+
|
|
96
|
+
| Phase | Label | CSS class | Meaning |
|
|
97
|
+
|---|---|---|---|
|
|
98
|
+
| `peak` | 高峰 | `sg-peak` | Weekday peak hours, sessions auto-paused |
|
|
99
|
+
| `off-peak` | 谷时 | `sg-off` | Off-peak hours, sessions running normally |
|
|
100
|
+
| `weekend` | 周末 | `sg-weekend` | Weekend (when weekend mode is on), ignore peak/off-peak |
|
|
101
|
+
|
|
102
|
+
- **Polling**: requests `GET /session-guard/status` every 15 seconds for the global `phase`;
|
|
103
|
+
- **Fail-open**: route unreachable, network error, or `enabled` off → badge silently hidden, no session affected;
|
|
104
|
+
- **Independent of input-traffic**: the badge is rendered by session-guard's client code alone — **input-traffic is not required**. input-traffic only provides the freeze button, which is unrelated to the badge;
|
|
105
|
+
- **Tooltip**: hovering shows `phase · timezone · weekend mode` (e.g. `周末 · Asia/Shanghai · 周末模式`).
|
|
106
|
+
|
|
107
|
+
### Timezone handling
|
|
108
|
+
|
|
109
|
+
- **Peak/off-peak detection**: always uses **Beijing time (UTC+8)** via `BILLING_TIMEZONE = 'Asia/Shanghai'`, matching DeepSeek's official billing basis. This is **hardcoded** and not affected by the `timezone` setting;
|
|
110
|
+
- **Weekend detection**: uses the user-configured `timezone` (e.g. `Asia/Tokyo`, `Asia/Seoul`), because "weekend" is a local concept;
|
|
111
|
+
- `Intl.DateTimeFormat` is used for timezone projection — invalid IANA timezone names throw `RangeError`, caught by fail-open and falling back to `Asia/Shanghai`;
|
|
112
|
+
- Peak windows are **left-closed, right-open** `[start, end)`, supporting cross-midnight windows (e.g. `22:00–06:00`);
|
|
113
|
+
- The `timezone` setting works identically across all UI languages (zh/en/ja/ko) — IANA timezone names are locale-independent.
|
|
114
|
+
|
|
115
|
+
### Coordination with input-traffic
|
|
116
|
+
|
|
117
|
+
- input-traffic's **freeze button** triggers via `sessionGuard.stopNextTurn` (RPC, per-session) on the server side;
|
|
118
|
+
- input-traffic **only does freeze enhancement** (queue freeze/unfreeze + composer block), retry is handled by this plugin's backend;
|
|
119
|
+
- Both share "session isolation" semantics: input-traffic freeze queue keyed by sessionId, session-guard RPC also keyed by sessionId.
|
|
120
|
+
|
|
121
|
+
## Redundant port `sessionGuard`
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
{
|
|
125
|
+
stopNextTurn(sessionId, opts),
|
|
126
|
+
resume(sessionId, opts),
|
|
127
|
+
lockQueue(sessionId, reason),
|
|
128
|
+
unlockQueue(sessionId),
|
|
129
|
+
state(sessionId),
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## HTTP routes
|
|
134
|
+
|
|
135
|
+
- `GET /session-guard/state?session=<id>` — session state
|
|
136
|
+
- `GET /session-guard/settings` — settings + taskControl availability
|
|
137
|
+
- `GET /session-guard/status` — global current phase (status badge polling)
|
|
138
|
+
- `GET /session-guard/diag` — runtime diagnostics
|
|
139
|
+
- `POST /session-guard/rpc` — `{ action: stopNextTurn|resume|lockQueue|unlockQueue|state, sessionId }`
|
|
140
|
+
|
|
141
|
+
## State storage
|
|
142
|
+
|
|
143
|
+
Per-session JSON: `$DSH_HOME/.dsh/session-guard/<sessionId>.json` (atomic write; `DSH_SESSION_GUARD_STATE_DIR` override).
|
|
144
|
+
|
|
145
|
+
## Tests
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npm test # node --test tests/*.test.mjs (timezone/weekend/state-machine/session-gate/bridge/retry)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Modules
|
|
152
|
+
|
|
153
|
+
| File | Responsibility |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `src/time.js` | Peak/weekend detection (timezone-correct) |
|
|
156
|
+
| `src/scheduler.js` | Pure state machine NORMAL ↔ PAUSED_PEAK |
|
|
157
|
+
| `src/pause-gate.js` | Custom session gate engine |
|
|
158
|
+
| `src/pause-store.js` | Custom pause state persistence |
|
|
159
|
+
| `src/gate.js` | Session gate driver (custom true pause / fallback lock queue, fail-open) |
|
|
160
|
+
| `src/bridge.js` | `sessionGuard` redundant port |
|
|
161
|
+
| `src/retry.js` | Backend auto-retry (failure classification/backoff/freeze yield) |
|
|
162
|
+
| `src/detect.js` | Auto-detection (host taskControl / client input-traffic bridge) |
|
|
163
|
+
| `src/store.js` | Per-session persistent state |
|
|
164
|
+
| `src/settings.js` | Settings sub-panel (schemastery schema + fail-open registration) |
|
|
165
|
+
| `src/index.js` | Host apply (settings/routes/tick/provide service/retry wiring) |
|
|
166
|
+
| `src/client/` | Browser half (status badge + settings card) |
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT — see [LICENSE](LICENSE).
|
package/README.ja.md
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<strong>ピーク自動セッションゲート:週末モード + ピーク自動一時停止 + セッション級凍結 + バックエンド自動リトライ</strong>
|
|
3
|
-
</p>
|
|
4
|
-
<p align="center">
|
|
5
|
-
<a href="README.en.md">English</a> · <a href="README.md">中文</a> · <strong>日本語</strong> · <a href="README.ko.md">한국어</a>
|
|
6
|
-
</p>
|
|
7
|
-
<p align="center">
|
|
8
|
-
<a href="LICENSE"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-263146?style=flat-square"></a>
|
|
9
|
-
<img src="https://camo.githubusercontent.com/2c11fb2e0e14bb9985c5acbe61123a7441c5ee63aa27fa6e04e2a707ebfd6022/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6473682d2d706c7567696e2d72656164792d3437384342463f6c6f676f3d646565707365656b266c6f676f436f6c6f723d7768697465" alt="dsh-plugin" style="max-width: 100%;">
|
|
10
|
-
<img alt="Public beta" src="https://img.shields.io/badge/status-public%20beta-7da1de?style=flat-square">
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
# dsh-session-guard
|
|
14
|
-
|
|
15
|
-
- [English README](./README.en.md)
|
|
16
|
-
- [中文 README](./README.md)
|
|
17
|
-
- [日本語 README](./README.ja.md)
|
|
18
|
-
- [한국어 README](./README.ko.md)
|
|
19
|
-
- [Installation guide](./INSTALL.md)
|
|
20
|
-
- [中文安装指南](./INSTALL.zh.md)
|
|
21
|
-
- [日本語インストールガイド](./INSTALL.ja.md)
|
|
22
|
-
- [한국어 설치 안내](./INSTALL.ko.md)
|
|
23
|
-
- [Changelog](./CHANGELOG.md)
|
|
24
|
-
- [日本語 changelog](./CHANGELOG.ja.md)
|
|
25
|
-
- [한국어 changelog](./CHANGELOG.ko.md)
|
|
26
|
-
|
|
27
|
-
> **互換性について:** v0.1.1 には日本語(`ja`)と韓国語(`ko`)の辞書が含まれていますが、現在の公式 DSH リリースは `LocaleRuntime` 経由で `zh` と `en` のみを提供しています。純正 DSH で `ja` または `ko` を選択すると `locale "<id>" is not registered` で失敗します。公式 DSH が对应的 locale ID を追加するまで利用できません。上級ユーザーは DSH フォークを保守して更新してください。
|
|
28
|
-
|
|
29
|
-
> ピーク課金時間帯に実行中のセッションを自動一時停止し、オフピーク/週末に自動再開。input-traffic の凍結ボタンと連携して**セッション級**ロックを実現。バックエンド**自動リトライ**は凍結/ゲート期間中は譲歩。カスタムセッションゲート(`agent.cancel keepInbox + goals.pause + session/event 安全境界 + followup 再開`)に基づき、dsh-task-control に依存しません。
|
|
30
|
-
|
|
31
|
-
`dsh plugin` コマンドで组装 + バンドルパッチで装配する cordis プラグイン。dsh ソース変更も PR も不要。
|
|
32
|
-
|
|
33
|
-
> 💡 **推奨理由**:DeepSeek は 2026-08-17 から**峰谷課金**を開始しました。ピーク時間帯の単価はオフピークの 2 倍。本プラグインはピーク時に実行セッションを自動一時停止、オフピーク時に自動再開し、長時間セッションの費用を最大 **50%** 削減。手動凍結(input-traffic ボタン経由)でセッションごとの精密制御が可能。
|
|
34
|
-
|
|
35
|
-
## 機能
|
|
36
|
-
|
|
37
|
-
- **週末モード**:`Intl.DateTimeFormat` で週末を正しく識別(タイムゾーン正確)→ 週末は峰谷を無視して自由実行。
|
|
38
|
-
- **ピーク自動一時停止(グローバル)**:ピーク入場時(かつ非週末)、全 running ルートセッションを自動一時停止。退峰時自動再開——**グローバルスイッチ、手動不要**。
|
|
39
|
-
- **セッション級凍結/再開**:`sessionGuard` 冗余ポート + `POST /session-guard/rpc`、input-traffic 凍結ボタンでセッションごと透伝。`/pause /resume /cancel` 手動コマンドも提供。
|
|
40
|
-
- **バックエンド自動リトライ(D9)**:turn/end 瞬時失敗(error/429/max-tokens)はアダプティブバックオフで自動再試行。永久失敗は停止。**凍結/ゲート期間中は譲歩**、セッションゲートを迂回しません。
|
|
41
|
-
- **fail-open**:カスタムセッションゲート利用不可、session-guard 未インストール、設定サービス欠如——すべて静的降格、依存でクラッシュしません。
|
|
42
|
-
|
|
43
|
-
## インストール
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
dsh plugin --profile web add github:<owner>/dsh-session-guard
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
インストール後 dsh web を再起動し、ページをリフレッシュ。
|
|
50
|
-
|
|
51
|
-
## 設定(設定 → プラグイン → session-guard)
|
|
52
|
-
|
|
53
|
-
| スイッチ | デフォルト | 説明 |
|
|
54
|
-
|---|---|---|
|
|
55
|
-
| `enabled` | on | **ピーク自動一時停止**:ピーク時間帯に実行セッションを自動一時停止 |
|
|
56
|
-
| `offPeakAutoResume` | on | **オフピーク自動再開**:オフピーク時に一時停止セッションを自動再開 |
|
|
57
|
-
| `weekendMode` | on | **週末モード**:週末を認識→週末は自動一時停止しない |
|
|
58
|
-
| `queueFallback` | on | カスタムセッションゲート利用不可時にロック待機キューにフォールバック(fail-open) |
|
|
59
|
-
| `retryEnabled` | off | **自動リトライ(バックエンド)**:瞬時失敗自動再試行(デフォルトオフ、保守的) |
|
|
60
|
-
|
|
61
|
-
追加設定:
|
|
62
|
-
|
|
63
|
-
- `timezone`(デフォルト Asia/Shanghai)——**週末判定**とバッジ表示に使用。**峰谷判定には影響しない**(峰谷は常に北京時間);
|
|
64
|
-
- `peakWindows`(デフォルト 09:00–12:00 / 14:00–18:00)——北京時間(UTC+8)の峰谷ウィンドウ。DeepSeek 公式課金と一致;
|
|
65
|
-
- `pauseMode`(`safe`/`force`)、`pauseReason`(`wait`/`stop`);
|
|
66
|
-
- リトライパラメータ:`retryText`、`retryGraceMs`、`retryCooldownMs`、`retryBackoffFactor`、`retryBackoffMaxMs`、`retryMaxConsecutive`。
|
|
67
|
-
|
|
68
|
-
## 動作
|
|
69
|
-
|
|
70
|
-
### ピーク自動ゲート(グローバル)
|
|
71
|
-
|
|
72
|
-
- **ピーク入り**(かつ非週末):全 running ルートセッションに `gate.stopNextTurn` を呼び出し——カスタムセッションゲートで真の一時停止(推論を中断せず、安全境界で一時停止)、`queueFallback` でロック待機キューにフォールバック;
|
|
73
|
-
- **退峰 / 週末**:`gate.resume` **全**セッション(自動再開、手動不要)——`offPeakAutoResume` スイッチで制御;
|
|
74
|
-
- **峰谷タイムゾーン**:常に北京時間(`Asia/Shanghai`)を使用。DeepSeek 公式課金基準に一致。`timezone` 設定の影響を受けません;
|
|
75
|
-
- 状態機械:単一インスタンス `NORMAL ↔ PAUSED_PEAK`(`scheduler.js`)、単一 30s tick で駆動。
|
|
76
|
-
|
|
77
|
-
### タイムゾーン処理
|
|
78
|
-
|
|
79
|
-
- **峰谷判定**:常に **北京時間(UTC+8)** を使用(`BILLING_TIMEZONE = 'Asia/Shanghai'`)。DeepSeek 公式課金基準。`timezone` 設定で変更不可(ハードコード);
|
|
80
|
-
- **週末判定**:ユーザー設定の `timezone`(例:`Asia/Tokyo`、`Asia/Seoul`)を使用。「週末」はローカル概念のため;
|
|
81
|
-
- `Intl.DateTimeFormat` でタイムゾーン投影。無効な IANA タイムゾーン名は `RangeError` で fail-open し `Asia/Shanghai` にフォールバック;
|
|
82
|
-
- 峰谷ウィンドウは**左閉右開** `[start, end)`。深夜跨ぎウィンドウ(例:`22:00–06:00`)対応。
|
|
83
|
-
|
|
84
|
-
### status-badge(フロントエンド表示)
|
|
85
|
-
|
|
86
|
-
コンポーザー入力エリア右側に**読み取り専用**のステータスバッジを表示:
|
|
87
|
-
|
|
88
|
-
| 階層 | ラベル | CSS クラス | 意味 |
|
|
89
|
-
|---|---|---|---|
|
|
90
|
-
| `peak` | 高峰 | `sg-peak` | 平日ピーク時間帯、セッション自動一時停止中 |
|
|
91
|
-
| `off-peak` | 谷時 | `sg-off` | オフピーク時間帯、セッション通常稼働 |
|
|
92
|
-
| `weekend` | 週末 | `sg-weekend` | 週末(週末モード有効時)、峰谷無視 |
|
|
93
|
-
|
|
94
|
-
- 15 秒ごとに `GET /session-guard/status` をポーリング;
|
|
95
|
-
- fail-open:ルート到達不可・ネットワークエラー・`enabled` オフ時→バッジ非表示;
|
|
96
|
-
- **input-traffic に依存しない**:session-guard クライアントコードが単独で描画。input-traffic は凍結ボタンのみ担当;
|
|
97
|
-
|
|
98
|
-
### input-traffic との連携
|
|
99
|
-
|
|
100
|
-
- input-traffic の**凍結ボタン**は `sessionGuard.stopNextTurn`(RPC、セッション経由)経由でサーバーサイドに伝達;
|
|
101
|
-
- input-traffic は**凍結強化のみ**(キュー凍結/解凍 + composer ブロック)、リトライは本プラグインのバックエンドが処理;
|
|
102
|
-
- 両方「セッション分離」セマンティスを共有:input-traffic 凍結キューは sessionId で分離、session-guard RPC も sessionId で分離。
|
|
103
|
-
|
|
104
|
-
## ライセンス
|
|
105
|
-
|
|
106
|
-
MIT — [LICENSE](LICENSE) 参照。
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>ピーク自動セッションゲート:週末モード + ピーク自動一時停止 + セッション級凍結 + バックエンド自動リトライ</strong>
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="README.en.md">English</a> · <a href="README.md">中文</a> · <strong>日本語</strong> · <a href="README.ko.md">한국어</a>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="LICENSE"><img alt="MIT License" src="https://img.shields.io/badge/license-MIT-263146?style=flat-square"></a>
|
|
9
|
+
<img src="https://camo.githubusercontent.com/2c11fb2e0e14bb9985c5acbe61123a7441c5ee63aa27fa6e04e2a707ebfd6022/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6473682d2d706c7567696e2d72656164792d3437384342463f6c6f676f3d646565707365656b266c6f676f436f6c6f723d7768697465" alt="dsh-plugin" style="max-width: 100%;">
|
|
10
|
+
<img alt="Public beta" src="https://img.shields.io/badge/status-public%20beta-7da1de?style=flat-square">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
# dsh-session-guard
|
|
14
|
+
|
|
15
|
+
- [English README](./README.en.md)
|
|
16
|
+
- [中文 README](./README.md)
|
|
17
|
+
- [日本語 README](./README.ja.md)
|
|
18
|
+
- [한국어 README](./README.ko.md)
|
|
19
|
+
- [Installation guide](./INSTALL.md)
|
|
20
|
+
- [中文安装指南](./INSTALL.zh.md)
|
|
21
|
+
- [日本語インストールガイド](./INSTALL.ja.md)
|
|
22
|
+
- [한국어 설치 안내](./INSTALL.ko.md)
|
|
23
|
+
- [Changelog](./CHANGELOG.md)
|
|
24
|
+
- [日本語 changelog](./CHANGELOG.ja.md)
|
|
25
|
+
- [한국어 changelog](./CHANGELOG.ko.md)
|
|
26
|
+
|
|
27
|
+
> **互換性について:** v0.1.1 には日本語(`ja`)と韓国語(`ko`)の辞書が含まれていますが、現在の公式 DSH リリースは `LocaleRuntime` 経由で `zh` と `en` のみを提供しています。純正 DSH で `ja` または `ko` を選択すると `locale "<id>" is not registered` で失敗します。公式 DSH が对应的 locale ID を追加するまで利用できません。上級ユーザーは DSH フォークを保守して更新してください。
|
|
28
|
+
|
|
29
|
+
> ピーク課金時間帯に実行中のセッションを自動一時停止し、オフピーク/週末に自動再開。input-traffic の凍結ボタンと連携して**セッション級**ロックを実現。バックエンド**自動リトライ**は凍結/ゲート期間中は譲歩。カスタムセッションゲート(`agent.cancel keepInbox + goals.pause + session/event 安全境界 + followup 再開`)に基づき、dsh-task-control に依存しません。
|
|
30
|
+
|
|
31
|
+
`dsh plugin` コマンドで组装 + バンドルパッチで装配する cordis プラグイン。dsh ソース変更も PR も不要。
|
|
32
|
+
|
|
33
|
+
> 💡 **推奨理由**:DeepSeek は 2026-08-17 から**峰谷課金**を開始しました。ピーク時間帯の単価はオフピークの 2 倍。本プラグインはピーク時に実行セッションを自動一時停止、オフピーク時に自動再開し、長時間セッションの費用を最大 **50%** 削減。手動凍結(input-traffic ボタン経由)でセッションごとの精密制御が可能。
|
|
34
|
+
|
|
35
|
+
## 機能
|
|
36
|
+
|
|
37
|
+
- **週末モード**:`Intl.DateTimeFormat` で週末を正しく識別(タイムゾーン正確)→ 週末は峰谷を無視して自由実行。
|
|
38
|
+
- **ピーク自動一時停止(グローバル)**:ピーク入場時(かつ非週末)、全 running ルートセッションを自動一時停止。退峰時自動再開——**グローバルスイッチ、手動不要**。
|
|
39
|
+
- **セッション級凍結/再開**:`sessionGuard` 冗余ポート + `POST /session-guard/rpc`、input-traffic 凍結ボタンでセッションごと透伝。`/pause /resume /cancel` 手動コマンドも提供。
|
|
40
|
+
- **バックエンド自動リトライ(D9)**:turn/end 瞬時失敗(error/429/max-tokens)はアダプティブバックオフで自動再試行。永久失敗は停止。**凍結/ゲート期間中は譲歩**、セッションゲートを迂回しません。
|
|
41
|
+
- **fail-open**:カスタムセッションゲート利用不可、session-guard 未インストール、設定サービス欠如——すべて静的降格、依存でクラッシュしません。
|
|
42
|
+
|
|
43
|
+
## インストール
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
dsh plugin --profile web add github:<owner>/dsh-session-guard
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
インストール後 dsh web を再起動し、ページをリフレッシュ。
|
|
50
|
+
|
|
51
|
+
## 設定(設定 → プラグイン → session-guard)
|
|
52
|
+
|
|
53
|
+
| スイッチ | デフォルト | 説明 |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `enabled` | on | **ピーク自動一時停止**:ピーク時間帯に実行セッションを自動一時停止 |
|
|
56
|
+
| `offPeakAutoResume` | on | **オフピーク自動再開**:オフピーク時に一時停止セッションを自動再開 |
|
|
57
|
+
| `weekendMode` | on | **週末モード**:週末を認識→週末は自動一時停止しない |
|
|
58
|
+
| `queueFallback` | on | カスタムセッションゲート利用不可時にロック待機キューにフォールバック(fail-open) |
|
|
59
|
+
| `retryEnabled` | off | **自動リトライ(バックエンド)**:瞬時失敗自動再試行(デフォルトオフ、保守的) |
|
|
60
|
+
|
|
61
|
+
追加設定:
|
|
62
|
+
|
|
63
|
+
- `timezone`(デフォルト Asia/Shanghai)——**週末判定**とバッジ表示に使用。**峰谷判定には影響しない**(峰谷は常に北京時間);
|
|
64
|
+
- `peakWindows`(デフォルト 09:00–12:00 / 14:00–18:00)——北京時間(UTC+8)の峰谷ウィンドウ。DeepSeek 公式課金と一致;
|
|
65
|
+
- `pauseMode`(`safe`/`force`)、`pauseReason`(`wait`/`stop`);
|
|
66
|
+
- リトライパラメータ:`retryText`、`retryGraceMs`、`retryCooldownMs`、`retryBackoffFactor`、`retryBackoffMaxMs`、`retryMaxConsecutive`。
|
|
67
|
+
|
|
68
|
+
## 動作
|
|
69
|
+
|
|
70
|
+
### ピーク自動ゲート(グローバル)
|
|
71
|
+
|
|
72
|
+
- **ピーク入り**(かつ非週末):全 running ルートセッションに `gate.stopNextTurn` を呼び出し——カスタムセッションゲートで真の一時停止(推論を中断せず、安全境界で一時停止)、`queueFallback` でロック待機キューにフォールバック;
|
|
73
|
+
- **退峰 / 週末**:`gate.resume` **全**セッション(自動再開、手動不要)——`offPeakAutoResume` スイッチで制御;
|
|
74
|
+
- **峰谷タイムゾーン**:常に北京時間(`Asia/Shanghai`)を使用。DeepSeek 公式課金基準に一致。`timezone` 設定の影響を受けません;
|
|
75
|
+
- 状態機械:単一インスタンス `NORMAL ↔ PAUSED_PEAK`(`scheduler.js`)、単一 30s tick で駆動。
|
|
76
|
+
|
|
77
|
+
### タイムゾーン処理
|
|
78
|
+
|
|
79
|
+
- **峰谷判定**:常に **北京時間(UTC+8)** を使用(`BILLING_TIMEZONE = 'Asia/Shanghai'`)。DeepSeek 公式課金基準。`timezone` 設定で変更不可(ハードコード);
|
|
80
|
+
- **週末判定**:ユーザー設定の `timezone`(例:`Asia/Tokyo`、`Asia/Seoul`)を使用。「週末」はローカル概念のため;
|
|
81
|
+
- `Intl.DateTimeFormat` でタイムゾーン投影。無効な IANA タイムゾーン名は `RangeError` で fail-open し `Asia/Shanghai` にフォールバック;
|
|
82
|
+
- 峰谷ウィンドウは**左閉右開** `[start, end)`。深夜跨ぎウィンドウ(例:`22:00–06:00`)対応。
|
|
83
|
+
|
|
84
|
+
### status-badge(フロントエンド表示)
|
|
85
|
+
|
|
86
|
+
コンポーザー入力エリア右側に**読み取り専用**のステータスバッジを表示:
|
|
87
|
+
|
|
88
|
+
| 階層 | ラベル | CSS クラス | 意味 |
|
|
89
|
+
|---|---|---|---|
|
|
90
|
+
| `peak` | 高峰 | `sg-peak` | 平日ピーク時間帯、セッション自動一時停止中 |
|
|
91
|
+
| `off-peak` | 谷時 | `sg-off` | オフピーク時間帯、セッション通常稼働 |
|
|
92
|
+
| `weekend` | 週末 | `sg-weekend` | 週末(週末モード有効時)、峰谷無視 |
|
|
93
|
+
|
|
94
|
+
- 15 秒ごとに `GET /session-guard/status` をポーリング;
|
|
95
|
+
- fail-open:ルート到達不可・ネットワークエラー・`enabled` オフ時→バッジ非表示;
|
|
96
|
+
- **input-traffic に依存しない**:session-guard クライアントコードが単独で描画。input-traffic は凍結ボタンのみ担当;
|
|
97
|
+
|
|
98
|
+
### input-traffic との連携
|
|
99
|
+
|
|
100
|
+
- input-traffic の**凍結ボタン**は `sessionGuard.stopNextTurn`(RPC、セッション経由)経由でサーバーサイドに伝達;
|
|
101
|
+
- input-traffic は**凍結強化のみ**(キュー凍結/解凍 + composer ブロック)、リトライは本プラグインのバックエンドが処理;
|
|
102
|
+
- 両方「セッション分離」セマンティスを共有:input-traffic 凍結キューは sessionId で分離、session-guard RPC も sessionId で分離。
|
|
103
|
+
|
|
104
|
+
## ライセンス
|
|
105
|
+
|
|
106
|
+
MIT — [LICENSE](LICENSE) 参照。
|