dsh-session-span 0.0.0-stage → 1.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cks
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,63 @@
1
+ # dsh-session-span
2
+
3
+ [简体中文](README.md) | **English**
4
+
5
+ ## Introduction
6
+
7
+ When work is organized as one task per session, two questions come up regularly: how much time this task has taken so far, and when it began. The current sidebar shows only the time since the most recent message, so neither question can be answered from it. This plugin therefore adds only the start time and the total elapsed time of the session, and nothing else.
8
+
9
+ ## Features
10
+
11
+ The Session hover card in the sidebar gains two lines:
12
+
13
+ - **Elapsed time**: the time from the first message to the present. It continues to accumulate while the session is idle and updates every 30 seconds while the card is open.
14
+ - **First message time**: shown in the device time zone, with a date format that follows the interface language (for example `2026-11-19 09:12` in English).
15
+
16
+ ```
17
+ Session title
18
+ C:\Users\Administrator
19
+ 3 minutes ago Existing: time since the most recent message
20
+ Elapsed 3 h 12 min This plugin: time since the first message
21
+ First message 2026-11-19 10:57 This plugin: when it began
22
+ ● Running
23
+ ```
24
+
25
+ ## Installation
26
+
27
+ In the application, open **Settings → Plugins → Add plugin**, enter `dsh-session-span`, and enable the **Session elapsed time** bundle.
28
+
29
+ In a `web` or other profile managed from a shell:
30
+
31
+ ```sh
32
+ dsh plugin --profile web add dsh-session-span
33
+ ```
34
+
35
+ The Desktop profile is managed by the application, so install from the Plugins page there.
36
+
37
+ Requirements: DSH `>=0.2.2-rc.3` and Node `>=22.6`. The package has no dependencies and no installation scripts.
38
+
39
+ ## How the start time is determined
40
+
41
+ - The start time is the first message in the session log that was initiated by the user or by a scheduled task. A session created by a scheduled task therefore also has a start time.
42
+ - A session created by forking another session uses its own creation time, not the first message of the original session.
43
+ - The duration is computed and cached by DSH on the Host from the complete session log, and is delivered with the session summary to the sidebar. Paging, compaction, and restarts do not change the result.
44
+ - Sessions that existed before the plugin was installed have no cached result. The first hover reads it once, after which it is cached; for sessions with a long log, this section may appear slightly later on that first hover.
45
+
46
+ ## Notes and limitations
47
+
48
+ - The value is the actual elapsed time, including the periods when the session was idle. To see the time actually spent executing, the statistics bar below the composer shows the sum of model time and tool time.
49
+ - The plugin does not inject content into the model and does not send data outside; apart from the computed start time it stores no state.
50
+ - It can be disabled or removed in **Settings → Plugins**, and the hover card returns to its original content.
51
+
52
+ ## Development
53
+
54
+ The package is published as is, with no build step: the Host side is a plain ESM module, and the client side is a browser module registered into the `sidebar.session.row.hover` slot.
55
+
56
+ ```sh
57
+ # point a profile at this checkout
58
+ dsh plugin --profile web add /absolute/path/to/this/directory
59
+ ```
60
+
61
+ ## License
62
+
63
+ MIT
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # dsh-session-span
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **简体中文** | [English](README.en.md)
4
+
5
+ ## 引言
6
+
7
+ 按“一个任务对应一个会话”的方式工作时,往往会关心两件事:这项任务已经投入了多少时间,以及它是从什么时候开始的。当前版本的侧边栏只显示最近一条消息距今的时间,无法回答这两个问题。为此,本插件只补充会话的起始时间与总用时,不涉及其他功能。
8
+
9
+ ## 功能
10
+
11
+ 在侧边栏会话行的悬停卡片中增加两行信息:
12
+
13
+ - **会话已用时**:从第一条消息到当前时刻的时间;会话空闲期间继续累计,卡片打开期间每 30 秒更新一次。
14
+ - **第一条消息时间**:按设备所在时区显示,日期格式随界面语言变化(英文界面为 `2026-11-19 09:12`)。
15
+
16
+ ```
17
+ 会话名称
18
+ C:\Users\Administrator
19
+ 3 分钟前 原有信息:最近一条消息距今的时间
20
+ 已用时 3 小时 12 分 本插件:从第一条消息至今
21
+ 第一条消息 2026年11月19日 10:57 本插件:起始时间
22
+ ● 运行中
23
+ ```
24
+
25
+ ## 安装
26
+
27
+ 在应用内打开「设置 → 插件 → 添加插件」,填写 `dsh-session-span`,然后启用「会话历时」插件包。
28
+
29
+ 在由命令行管理的 `web` 等配置中安装:
30
+
31
+ ```sh
32
+ dsh plugin --profile web add dsh-session-span
33
+ ```
34
+
35
+ 桌面版的配置由应用管理,请在应用内的插件页面安装。
36
+
37
+ 运行要求:DSH `>=0.2.2-rc.3`,Node `>=22.6`。本插件没有依赖,也没有安装脚本。
38
+
39
+ ## 起始时间的确定方式
40
+
41
+ - 起始时间为会话记录中第一条由用户或定时任务发起的消息。由定时任务创建的会话同样具有起始时间。
42
+ - 由其他会话分叉得到的会话,以自身的创建时间为起始时间,不沿用原会话的第一条消息。
43
+ - 该时长由 DSH 在宿主侧根据完整的会话记录计算并缓存,随会话摘要供侧边栏读取,因此分页、压缩与重启都不会改变结果。
44
+ - 插件安装之前已经存在的会话没有缓存结果,首次悬停时会读取一次,此后结果被缓存;记录较长的会话,首次悬停时该部分可能稍后出现。
45
+
46
+ ## 说明与限制
47
+
48
+ - 显示的是实际经过的时间,包含会话空闲的时段。若需要了解实际执行所花费的时间,输入框下方的统计栏显示的是模型用时与工具用时之和。
49
+ - 本插件不向模型注入内容,不向外部发送数据;除计算出的起始时间外不保存其他状态。
50
+ - 可在「设置 → 插件」中停用或卸载,悬停卡片会恢复原有内容。
51
+
52
+ ## 开发
53
+
54
+ 本包按现状发布,没有构建步骤:宿主侧为普通 ESM 模块,客户端为注册到 `sidebar.session.row.hover` 插槽的浏览器模块。
55
+
56
+ ```sh
57
+ # 让某个配置指向本仓库
58
+ dsh plugin --profile web add /absolute/path/to/this/directory
59
+ ```
60
+
61
+ ## 许可
62
+
63
+ MIT
package/client.js ADDED
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Browser half of the Session-span bundle.
3
+ *
4
+ * Contributes one section to the Sidebar Session-row hover card: how long the
5
+ * conversation has been running since its first prompt, plus that start time.
6
+ * The start itself comes from the Host `sessionSpan` projection; this module
7
+ * only formats and ticks a clock while the card is open.
8
+ *
9
+ * The card is mounted only while it is open, so the interval below never runs
10
+ * for a row nobody is looking at.
11
+ */
12
+ window.__ModuleLoader__.load({
13
+ id: 'dsh-session-span',
14
+ factory(require) {
15
+ const React = require('react');
16
+ const h = React.createElement;
17
+
18
+ /** Dictionary namespace owned by this plugin. */
19
+ const NS = 'sessionSpan';
20
+
21
+ const zh = {
22
+ 'span.label': '已用时 {duration}',
23
+ 'span.since': '第一条消息 {time}',
24
+ 'span.date': '{y}年{m}月{d}日',
25
+ 'span.lessThanMinute': '不到 1 分钟',
26
+ 'span.minutes': '{minutes} 分钟',
27
+ 'span.hours': '{hours} 小时 {minutes} 分',
28
+ 'span.days': '{days} 天 {hours} 小时',
29
+ };
30
+
31
+ const en = {
32
+ 'span.label': 'Elapsed {duration}',
33
+ 'span.since': 'First message {time}',
34
+ 'span.date': '{y}-{m}-{d}',
35
+ 'span.lessThanMinute': 'less than a minute',
36
+ 'span.minutes': '{minutes} min',
37
+ 'span.hours': '{hours} h {minutes} min',
38
+ 'span.days': '{days} d {hours} h',
39
+ };
40
+
41
+ const ja = {
42
+ 'span.label': '経過 {duration}',
43
+ 'span.since': '最初のメッセージ {time}',
44
+ 'span.date': '{y}年{m}月{d}日',
45
+ 'span.lessThanMinute': '1 分未満',
46
+ 'span.minutes': '{minutes} 分',
47
+ 'span.hours': '{hours} 時間 {minutes} 分',
48
+ 'span.days': '{days} 日 {hours} 時間',
49
+ };
50
+
51
+ const es = {
52
+ 'span.label': 'Tiempo transcurrido {duration}',
53
+ 'span.since': 'Primer mensaje {time}',
54
+ 'span.date': '{d}/{m}/{y}',
55
+ 'span.lessThanMinute': 'menos de un minuto',
56
+ 'span.minutes': '{minutes} min',
57
+ 'span.hours': '{hours} h {minutes} min',
58
+ 'span.days': '{days} d {hours} h',
59
+ };
60
+
61
+ const fr = {
62
+ 'span.label': 'Durée {duration}',
63
+ 'span.since': 'Premier message {time}',
64
+ 'span.date': '{d}/{m}/{y}',
65
+ 'span.lessThanMinute': 'moins d’une minute',
66
+ 'span.minutes': '{minutes} min',
67
+ 'span.hours': '{hours} h {minutes} min',
68
+ 'span.days': '{days} j {hours} h',
69
+ };
70
+
71
+ const de = {
72
+ 'span.label': 'Dauer {duration}',
73
+ 'span.since': 'Erste Nachricht {time}',
74
+ 'span.date': '{d}.{m}.{y}',
75
+ 'span.lessThanMinute': 'weniger als eine Minute',
76
+ 'span.minutes': '{minutes} Min.',
77
+ 'span.hours': '{hours} Std. {minutes} Min.',
78
+ 'span.days': '{days} T. {hours} Std.',
79
+ };
80
+
81
+ const ru = {
82
+ 'span.label': 'Длительность {duration}',
83
+ 'span.since': 'Первое сообщение {time}',
84
+ 'span.date': '{d}.{m}.{y}',
85
+ 'span.lessThanMinute': 'меньше минуты',
86
+ 'span.minutes': '{minutes} мин',
87
+ 'span.hours': '{hours} ч {minutes} мин',
88
+ 'span.days': '{days} д {hours} ч',
89
+ };
90
+
91
+ const pt = {
92
+ 'span.label': 'Duração {duration}',
93
+ 'span.since': 'Primeira mensagem {time}',
94
+ 'span.date': '{d}/{m}/{y}',
95
+ 'span.lessThanMinute': 'menos de um minuto',
96
+ 'span.minutes': '{minutes} min',
97
+ 'span.hours': '{hours} h {minutes} min',
98
+ 'span.days': '{days} d {hours} h',
99
+ };
100
+
101
+ /** Pad a number to two digits without consulting the browser locale. */
102
+ const pad2 = (value) => String(value).padStart(2, '0');
103
+
104
+ /**
105
+ * Absolute start stamp in the device zone. The date part goes through the
106
+ * dictionary (the message-clock pattern), so the card follows the app
107
+ * locale instead of the browser language.
108
+ */
109
+ function startStamp(epochMs, t) {
110
+ const d = new Date(epochMs);
111
+ const date = t('span.date', { y: d.getFullYear(), m: d.getMonth() + 1, d: d.getDate() });
112
+ return `${date} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
113
+ }
114
+
115
+ /** Elapsed wall time in at most two units: minutes, then hours, then days. */
116
+ function duration(ms, t) {
117
+ const totalMinutes = Math.floor(Math.max(0, ms) / 60_000);
118
+ if (totalMinutes < 1) return t('span.lessThanMinute');
119
+ const days = Math.floor(totalMinutes / 1_440);
120
+ const hours = Math.floor((totalMinutes % 1_440) / 60);
121
+ const minutes = totalMinutes % 60;
122
+ if (days > 0) return t('span.days', { days, hours });
123
+ if (hours > 0) return t('span.hours', { hours, minutes });
124
+ return t('span.minutes', { minutes });
125
+ }
126
+
127
+ /**
128
+ * One hover-card section: the elapsed wall time and the first-message stamp.
129
+ * @param props.sessionId - Session this row shows.
130
+ * @param props.useSessions - selector hook over the Session list.
131
+ * @param props.refreshProjections - non-activating projection read for a row
132
+ * whose value was never computed in this profile.
133
+ * @param props.t - this namespace's translator.
134
+ */
135
+ function SessionSpanSection({ sessionId, useSessions, refreshProjections, t }) {
136
+ const readValue = typeof useSessions === 'function' ? useSessions : () => undefined;
137
+ const translate = typeof t === 'function' ? t : (key) => key;
138
+ const startedAt = readValue((state) => {
139
+ if (state === undefined || state === null) return undefined;
140
+ const row = state.byId === undefined ? undefined : state.byId[sessionId];
141
+ const values = row === undefined ? undefined : row.projectionValues;
142
+ if (values !== undefined && values !== null && values.sessionSpan !== undefined) {
143
+ return values.sessionSpan;
144
+ }
145
+ const block = state.projectionsBySession === undefined
146
+ ? undefined
147
+ : state.projectionsBySession[sessionId];
148
+ return block === undefined || block.values === undefined ? undefined : block.values.sessionSpan;
149
+ });
150
+
151
+ const [now, setNow] = React.useState(() => Date.now());
152
+ React.useEffect(() => {
153
+ const timer = setInterval(() => { setNow(Date.now()) }, 30_000);
154
+ return () => { clearInterval(timer) };
155
+ }, []);
156
+
157
+ // A row whose projection was never folded (installed after the row
158
+ // existed) is read once through the non-activating projection endpoint;
159
+ // the store then feeds the same selector.
160
+ const asked = React.useRef(false);
161
+ React.useEffect(() => {
162
+ if (startedAt !== undefined || asked.current) return;
163
+ if (typeof refreshProjections !== 'function') return;
164
+ asked.current = true;
165
+ try {
166
+ Promise.resolve(refreshProjections(sessionId)).catch(() => {});
167
+ } catch {
168
+ // A rejected read leaves the section hidden; the next hover retries.
169
+ }
170
+ }, [startedAt, sessionId, refreshProjections]);
171
+
172
+ // `undefined` means "no value yet"; null means the Session has no
173
+ // starting prompt (blank Session, import, or only synthetic context).
174
+ if (startedAt === undefined || startedAt === null || !Number.isFinite(startedAt)) return null;
175
+
176
+ const text = duration(now - startedAt, translate);
177
+ return h(
178
+ 'div',
179
+ {
180
+ 'data-session-span': '',
181
+ style: {
182
+ display: 'flex',
183
+ flexDirection: 'column',
184
+ gap: '2px',
185
+ fontSize: '12px',
186
+ lineHeight: '16px',
187
+ color: 'var(--dsw-alias-hovercard-label-secondary)',
188
+ },
189
+ },
190
+ h('span', null, translate('span.label', { duration: text })),
191
+ h(
192
+ 'span',
193
+ { style: { color: 'var(--dsw-alias-hovercard-label-tertiary)' } },
194
+ translate('span.since', { time: startStamp(startedAt, translate) }),
195
+ ),
196
+ );
197
+ }
198
+
199
+ return {
200
+ inject: ['slots', 'locale', 'sessions'],
201
+ apply(ctx) {
202
+ ctx.effect(
203
+ () => ctx.locale.register(NS, { zh, en, ja, es, fr, de, ru, pt }),
204
+ 'session-span: dictionaries',
205
+ );
206
+ ctx.slots.inject('sidebar.session.row.hover', () => ctx.slots.register({
207
+ name: 'sidebar.session.row.hover',
208
+ id: 'session-span',
209
+ order: 5,
210
+ locale: NS,
211
+ inject: () => ({
212
+ refreshProjections: (sessionId) => ctx.sessions.refreshProjections(sessionId),
213
+ }),
214
+ }, SessionSpanSection));
215
+ },
216
+ };
217
+ },
218
+ });
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: session-span
3
+ name: dsh-session-span
package/icon.svg ADDED
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
2
+ <circle cx="18" cy="18" r="9.6" fill="none" stroke="#247bbf" stroke-width="2.6"/>
3
+ <path d="M18 12.2V18l4 2.6" fill="none" stroke="#247bbf" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>
4
+ </svg>
package/index.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Host half of the Session-span bundle.
3
+ *
4
+ * Publishes the start of a Session conversation as the `sessionSpan`
5
+ * projection: the committed time of its first prompt on the append surface, or
6
+ * the fork's own creation time when the Session inherited a parent prefix.
7
+ * The value is folded over the complete durable log once, so the Web UI can
8
+ * render "how long has this conversation been running" for every Session row
9
+ * without reading the log again.
10
+ *
11
+ * Only the fold lives here; delivery (list summaries, control baselines, and
12
+ * the persisted projection cache) belongs to the projection seam.
13
+ */
14
+
15
+ /**
16
+ * Both schemas are validated with `parse` only by the projection registry, and
17
+ * the shapes are plain JSON this plugin owns, so a pass-through validator is
18
+ * enough and keeps the bundle dependency-free.
19
+ */
20
+ const passthrough = { parse: value => value }
21
+
22
+ /**
23
+ * Message sources that start a conversation on the human's behalf. A scheduled
24
+ * task delivers its prompt as a `schedule` source, so a task-owned Session has
25
+ * a start even when no human typed the first message.
26
+ */
27
+ const STARTING_SOURCES = new Set(['user', 'schedule'])
28
+
29
+ /** The projection registry is the plugin's whole purpose. */
30
+ export const inject = ['sessionProjections']
31
+
32
+ /**
33
+ * Register the `sessionSpan` unit; the registration is an effect on this
34
+ * plugin's fiber, so unloading removes the key.
35
+ * @param ctx - registrant context carrying the projection registry.
36
+ * @returns when the unit is registered.
37
+ */
38
+ export async function apply(ctx) {
39
+ await ctx.sessionProjections.register({
40
+ key: 'sessionSpan',
41
+ stateVersion: 1,
42
+ stateSchema: passthrough,
43
+ init: (header, inheritedEventCount) => ({
44
+ // A fork inherits its parent's events, so its first prompt predates this
45
+ // conversation; the fork's own header time is the only honest start.
46
+ startedAt: inheritedEventCount > 0 ? header.createdAt : null,
47
+ }),
48
+ apply: (state, event) => {
49
+ if (state.startedAt !== null) return state
50
+ if (event.type !== 'user/message') return state
51
+ const source = event.data?.source
52
+ if (source === undefined || !STARTING_SOURCES.has(source.kind)) return state
53
+ const content = event.data?.content
54
+ if (!Array.isArray(content) || content.length === 0) return state
55
+ return { startedAt: event.time }
56
+ },
57
+ wire: {
58
+ viewSchema: passthrough,
59
+ /** Epoch milliseconds, or null while no starting prompt exists yet. */
60
+ view: state => state.startedAt,
61
+ // The Session list row carries this value, which is how the sidebar
62
+ // hover card reads it without activating anything.
63
+ summary: true,
64
+ },
65
+ })
66
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Session elapsed time",
4
+ "description": "Shows the time elapsed since a session's first message, and that start time, in the sidebar Session hover card. The start time is the first message in the session log initiated by the user or by a scheduled task; a forked session uses its own creation time. The value is the actual elapsed time, including periods when the session was idle. Sessions that existed before installation are read once on first hover and cached afterwards."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "会话历时",
4
+ "description": "在侧边栏会话行的悬停卡片中显示会话从第一条消息至今的用时,以及第一条消息的时间。起始时间为会话记录中第一条由用户或定时任务发起的消息;由其他会话分叉得到的会话,以自身的创建时间为起始时间。所显示的是实际经过的时间,包含会话空闲的时段。插件安装之前已经存在的会话,首次悬停时读取一次结果,此后结果被缓存。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "dsh-session-span",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "在侧边栏会话行的悬停卡片中显示会话的已用时长与起始时间 / Session elapsed time and start time in the sidebar hover card.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "cks <940962289@qq.com>",
8
+ "keywords": [
9
+ "dsh-plugin",
10
+ "deepseek-harness",
11
+ "dsh",
12
+ "plugin",
13
+ "session",
14
+ "elapsed-time"
15
+ ],
16
+ "homepage": "https://github.com/aNoWhale/dsh-session-span#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/aNoWhale/dsh-session-span.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/aNoWhale/dsh-session-span/issues"
23
+ },
24
+ "engines": {
25
+ "node": ">=22.6",
26
+ "dsh": ">=0.2.2-rc.3"
27
+ },
28
+ "exports": {
29
+ ".": "./index.js",
30
+ "./client": "./client.js",
31
+ "./locale/*.json": "./locale/*.json",
32
+ "./icon": "./icon.svg"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "client.js",
37
+ "cordis.patch.yml",
38
+ "locale/*.json",
39
+ "icon.svg",
40
+ "README.md",
41
+ "README.en.md",
42
+ "LICENSE"
43
+ ],
44
+ "dsh": {
45
+ "bundle": { "patch": "./cordis.patch.yml" },
46
+ "client": {
47
+ "platform": "web",
48
+ "immediately": true,
49
+ "inject": ["@deepseek-ai/dsh-client-ui-workspace"]
50
+ }
51
+ }
52
+ }