@junerver/dsh-workspace 0.0.0-stage → 1.0.4
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.md +120 -2
- package/client.js +435 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +31 -0
- package/icon.svg +5 -0
- package/index.js +245 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +66 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 侯文君
|
|
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.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-workspace
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [DeepSeek Harness](https://github.com/deepseek-ai) (DSH) plugin bundle that lets you **move a conversation into a directory workspace from the sidebar** — by dragging the row onto a workspace, or from the row's menu.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# install into a DSH profile
|
|
7
|
+
dsh plugin add @junerver/dsh-workspace
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
<sub>Not sure of your install route? The bundle also installs from a local directory through **Plugins → Add plugin**.</sub>
|
|
11
|
+
|
|
12
|
+
## Why this exists
|
|
13
|
+
|
|
14
|
+
DSH decides which workspace a session belongs to by comparing the session header's `cwd` with each registered workspace directory. That header field is immutable: once a conversation started in the default workspace, no amount of reordering can put it under another directory workspace — the recorded directory still points at the old one. Dragging a session between workspace groups is simply not offered.
|
|
15
|
+
|
|
16
|
+
This plugin fills that gap.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
- **Drag** — press and drag any conversation row in the sidebar, then move over a target workspace group (its header, or any conversation inside it). The group highlights; release to move.
|
|
21
|
+
- **Menu** — hover the row and click the folder-arrow button, or open the row's `⋯` menu and choose **Move to workspace…**, then pick a workspace.
|
|
22
|
+
|
|
23
|
+
A short toast confirms the result at the top of the window, naming the target workspace.
|
|
24
|
+
|
|
25
|
+
## How it works
|
|
26
|
+
|
|
27
|
+
Because the session header cannot be rewritten in place, a move is a **safe migration copy**:
|
|
28
|
+
|
|
29
|
+
1. A new session is created inside the target workspace, seeded from the source conversation's history up to its last completed turn — the same seeding a fork uses.
|
|
30
|
+
2. The new session is attached to the target workspace.
|
|
31
|
+
3. The original session is archived and the migrated copy is opened.
|
|
32
|
+
|
|
33
|
+
Nothing is overwritten: the source log stays intact, and unarchiving it from **View options → All conversations** undoes the move.
|
|
34
|
+
|
|
35
|
+
### Host side
|
|
36
|
+
|
|
37
|
+
`index.js` registers one command and one tool over the same implementation:
|
|
38
|
+
|
|
39
|
+
| Surface | Name | Notes |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| Host command | `/move-workspace-to <workspaceId>` | Driven by the sidebar through the existing `commands.execute` Remote bridge. |
|
|
42
|
+
| Agent tool | `move_session_to_workspace` | `session_id`, `workspace_id`, optional `dry_run` to preview the plan. |
|
|
43
|
+
|
|
44
|
+
The seed is built from plain JSON values and the migration always cuts at a `turn/end`, so the inherited prefix is balanced and needs no synthetic turn closers. The bundle imports nothing from the DSH installation — a bundle resolved from a registry has no route to `@deepseek-ai/*`, so every service is reached through `ctx`.
|
|
45
|
+
|
|
46
|
+
### Client side
|
|
47
|
+
|
|
48
|
+
`client.js` contributes three slot entries:
|
|
49
|
+
|
|
50
|
+
| Slot | Entry | Purpose |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `sidebar.workspaces.session.row.action` | `workspace-move` (150) | Hover button on each session row. |
|
|
53
|
+
| `sidebar.workspaces.session.menu.item` | `workspace-move` (520) | `⋯` menu row. |
|
|
54
|
+
| `shell.overlay` | `workspace-move-overlay` (900) | Workspace chooser dialog, toast, and drag hint. |
|
|
55
|
+
|
|
56
|
+
Drag targeting resolves against the sidebar's own structural keys — `data-row-key="session:<id>"` and `data-row-key="workspace:<id>"` — rather than a floating panel, so a narrow window cannot cover the drop targets. The overlay layer is `pointer-events: none`, so it never intercepts the drag.
|
|
57
|
+
|
|
58
|
+
## Limitations
|
|
59
|
+
|
|
60
|
+
- The migrated conversation is a **new session** (new id); the original id is not reused.
|
|
61
|
+
- Only completed turns are carried over; an in-progress turn is not included.
|
|
62
|
+
- A session with no completed turn cannot be migrated.
|
|
63
|
+
- Sessions already in the target workspace are left untouched.
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
No build step — the published files are the sources.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm run check # bundle structure, module faces, patch, locales
|
|
71
|
+
npm run pack:dry # inspect the tarball contents
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Release
|
|
75
|
+
|
|
76
|
+
Releases are published from GitHub Actions over OIDC ([npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)), so no `NPM_TOKEN` secret exists in this repository.
|
|
77
|
+
|
|
78
|
+
1. Bump `version` in `package.json` and commit.
|
|
79
|
+
2. Push a matching tag:
|
|
80
|
+
```bash
|
|
81
|
+
git tag v1.0.5 && git push origin v1.0.5
|
|
82
|
+
```
|
|
83
|
+
3. `.github/workflows/publish.yml` verifies the tag against the manifest, runs `npm run check`, and publishes with provenance.
|
|
84
|
+
|
|
85
|
+
**The very first version must be published by hand** — npm has no pending-publisher state, so a trusted publisher can only be configured for a package that already exists:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm login
|
|
89
|
+
npm publish --access public
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then, on npmjs.com → the package → **Settings → Trusted publisher**, add:
|
|
93
|
+
|
|
94
|
+
| Field | Value |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| Publisher | GitHub Actions |
|
|
97
|
+
| Organization / user | `junerver` |
|
|
98
|
+
| Repository | `dsh-workspace` |
|
|
99
|
+
| Workflow filename | `publish.yml` |
|
|
100
|
+
| Environment | *(leave empty)* |
|
|
101
|
+
| Allowed actions | `npm publish` **and** `npm stage publish` |
|
|
102
|
+
|
|
103
|
+
Every field is case-sensitive and is not validated when saved — a mismatch surfaces only as a 404 at publish time. A newly added trusted publisher expires unless its first publish succeeds within two days.
|
|
104
|
+
|
|
105
|
+
## Files
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
package.json bundle manifest (Host plugin + Web client module)
|
|
109
|
+
cordis.patch.yml Loader patch inserting the plugin row
|
|
110
|
+
index.js Host: migration, /move-workspace-to, move_session_to_workspace
|
|
111
|
+
client.js Web: drag targeting, row action, menu row, chooser, toast
|
|
112
|
+
locale/en.json Plugin Manager title/description (English)
|
|
113
|
+
locale/zh.json Plugin Manager title/description (Chinese)
|
|
114
|
+
docs/DETAIL.md Detail page shown in Plugin Manager
|
|
115
|
+
icon.svg Plugin icon
|
|
116
|
+
scripts/check.mjs Offline structure and module-face checks (CI)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT
|
package/client.js
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: '@junerver/dsh-workspace',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
|
|
7
|
+
/* ------------------------------------------------------------------ *
|
|
8
|
+
* Shared UI state (module scope): a tiny external store the slot
|
|
9
|
+
* components subscribe to. `bridge` is filled in by apply().
|
|
10
|
+
* ------------------------------------------------------------------ */
|
|
11
|
+
let state = {
|
|
12
|
+
drag: null, // session id currently being dragged from a sidebar row
|
|
13
|
+
choose: null, // session id whose workspace chooser is open
|
|
14
|
+
label: '', // display label of that session
|
|
15
|
+
busy: false,
|
|
16
|
+
error: null,
|
|
17
|
+
notice: null, // { text, error }
|
|
18
|
+
};
|
|
19
|
+
const listeners = new Set();
|
|
20
|
+
function emit() { for (const l of Array.from(listeners)) { try { l(); } catch (_) { /* ignore */ } } }
|
|
21
|
+
function patch(next) { state = Object.assign({}, state, next); emit(); }
|
|
22
|
+
function subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); }
|
|
23
|
+
function useStore() {
|
|
24
|
+
const [, force] = React.useReducer((x) => x + 1, 0);
|
|
25
|
+
React.useEffect(() => subscribe(force), []);
|
|
26
|
+
return state;
|
|
27
|
+
}
|
|
28
|
+
let noticeTimer = null;
|
|
29
|
+
function showNotice(text, error) {
|
|
30
|
+
patch({ notice: { text, error: error === true } });
|
|
31
|
+
if (noticeTimer !== null) clearTimeout(noticeTimer);
|
|
32
|
+
noticeTimer = setTimeout(() => { noticeTimer = null; patch({ notice: null }); }, 4000);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const bridge = { move: null, close: null, workspaces: null, sessionsList: null };
|
|
36
|
+
|
|
37
|
+
const CSS = `
|
|
38
|
+
.wsm-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.38);z-index:2147483000;pointer-events:auto}
|
|
39
|
+
.wsm-panel{position:fixed;pointer-events:auto;z-index:2147483001;background:var(--dsw-alias-bg-overlay,#1e1f22);color:var(--dsw-alias-label-primary,#eee);border:1px solid var(--dsw-alias-border-l2,#3a3b3f);border-radius:12px;box-shadow:0 12px 40px rgba(0,0,0,.45);padding:14px;box-sizing:border-box;font:13px/1.4 system-ui,-apple-system,"Segoe UI",sans-serif;display:flex;flex-direction:column;gap:10px}
|
|
40
|
+
.wsm-panel-choose{left:50%;top:50%;transform:translate(-50%,-50%);width:min(440px,90vw);max-height:76vh}
|
|
41
|
+
.wsm-title{font-weight:600;font-size:14px}
|
|
42
|
+
.wsm-sub{color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px;word-break:break-all}
|
|
43
|
+
.wsm-list{display:flex;flex-direction:column;gap:6px;overflow:auto;min-height:40px}
|
|
44
|
+
.wsm-item{padding:8px 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1,#2c2d31);background:var(--dsw-alias-bg-layer-1,#26272b);cursor:pointer}
|
|
45
|
+
.wsm-item:hover{border-color:var(--dsw-alias-brand-primary,#4a9eff);background:var(--dsw-alias-bg-layer-2,#2e3036)}
|
|
46
|
+
.wsm-item-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
47
|
+
.wsm-item-path{color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
48
|
+
.wsm-empty{color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px;padding:10px}
|
|
49
|
+
.wsm-cancel{align-self:flex-end;background:transparent;border:1px solid var(--dsw-alias-border-l1,#2c2d31);color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:8px;padding:6px 12px;cursor:pointer;font:inherit}
|
|
50
|
+
.wsm-error{color:var(--dsw-alias-state-error-primary,#e5484d);font-size:12px;word-break:break-all}
|
|
51
|
+
.wsm-busy{color:var(--dsw-alias-label-secondary,#9aa0a6);font-size:12px}
|
|
52
|
+
/* Toast/hint follow the host convention: top-centred, pointer-transparent,
|
|
53
|
+
host toast tokens, and a short fade-out. */
|
|
54
|
+
.wsm-stack{position:fixed;pointer-events:none;top:40px;left:50%;transform:translateX(-50%);z-index:2147483002;display:flex;flex-direction:column;align-items:center;gap:8px;width:max-content;max-width:min(640px,calc(100vw - 48px))}
|
|
55
|
+
.wsm-toast{display:flex;align-items:center;gap:10px;box-sizing:border-box;width:max-content;max-width:100%;padding:12px 16px;border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-toast-bg,var(--dsw-alias-bg-overlay,#1e1f22));color:var(--dsw-alias-toast-label,var(--dsw-alias-label-primary,#eee));font:14px/22px system-ui,-apple-system,"Segoe UI",sans-serif;box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.28));animation:wsm-toast-in 160ms ease,wsm-toast-out 260ms ease 3.6s forwards}
|
|
56
|
+
.wsm-toast-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
57
|
+
.wsm-toast-icon{display:inline-flex;flex:0 0 auto;align-items:center;justify-content:center;width:18px;height:18px}
|
|
58
|
+
.wsm-toast-ok .wsm-toast-icon{color:var(--dsw-alias-state-success-primary,#3fb950)}
|
|
59
|
+
.wsm-toast-err .wsm-toast-icon{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
60
|
+
.wsm-hint{display:flex;align-items:center;gap:8px;box-sizing:border-box;width:max-content;max-width:100%;padding:8px 14px;border-radius:999px;background:var(--dsw-alias-toast-bg,var(--dsw-alias-bg-overlay,#1e1f22));color:var(--dsw-alias-label-secondary,#9aa0a6);font:13px/20px system-ui,-apple-system,"Segoe UI",sans-serif;box-shadow:var(--dsw-shadow-lv3,0 6px 18px rgba(0,0,0,.22));animation:wsm-toast-in 160ms ease}
|
|
61
|
+
.wsm-hint-err{color:var(--dsw-alias-state-error-primary,#e5484d)}
|
|
62
|
+
@keyframes wsm-toast-in{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:none}}
|
|
63
|
+
@keyframes wsm-toast-out{to{opacity:0;visibility:hidden}}
|
|
64
|
+
@media (prefers-reduced-motion:reduce){.wsm-toast,.wsm-hint{animation:none}}
|
|
65
|
+
.wsm-grip{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border-radius:6px;border:none;background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);cursor:pointer;padding:0}
|
|
66
|
+
.wsm-grip:hover{background:var(--dsw-alias-bg-layer-2,#2e3036);color:var(--dsw-alias-label-primary,#eee)}
|
|
67
|
+
.wsm-menu-item{display:flex;width:100%;align-items:center;gap:8px;padding:6px 10px;border:none;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer;border-radius:6px}
|
|
68
|
+
.wsm-menu-item:hover{background:var(--dsw-alias-bg-layer-2,#2e3036)}
|
|
69
|
+
.wsm-drop-row{outline:2px solid var(--dsw-alias-brand-primary,#4a9eff) !important;outline-offset:-2px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,#2e3036) !important}
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
function ensureStyle() {
|
|
73
|
+
if (typeof document === 'undefined') return;
|
|
74
|
+
if (document.getElementById('wsm-style') !== null) return;
|
|
75
|
+
const el = document.createElement('style');
|
|
76
|
+
el.id = 'wsm-style';
|
|
77
|
+
el.textContent = CSS;
|
|
78
|
+
document.head.appendChild(el);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function workspaceSnapshot() {
|
|
82
|
+
try {
|
|
83
|
+
return bridge.workspaces ? bridge.workspaces() : { items: [], archivedSessionIds: [] };
|
|
84
|
+
} catch (_) {
|
|
85
|
+
return { items: [], archivedSessionIds: [] };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isArchived(sessionId) {
|
|
90
|
+
const snap = workspaceSnapshot();
|
|
91
|
+
return Array.isArray(snap.archivedSessionIds) && snap.archivedSessionIds.indexOf(sessionId) !== -1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function labelFor(sessionId) {
|
|
95
|
+
if (state.label) return state.label;
|
|
96
|
+
try {
|
|
97
|
+
const list = bridge.sessionsList ? bridge.sessionsList() : null;
|
|
98
|
+
const summary = list && list.byId ? list.byId[sessionId] : null;
|
|
99
|
+
if (summary) return summary.displayTitle || summary.title || sessionId;
|
|
100
|
+
} catch (_) { /* ignore */ }
|
|
101
|
+
return sessionId;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* ------------------------------ icons ------------------------------ */
|
|
105
|
+
function MoveIcon() {
|
|
106
|
+
return h('svg', {
|
|
107
|
+
width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none',
|
|
108
|
+
stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
109
|
+
'aria-hidden': true,
|
|
110
|
+
},
|
|
111
|
+
h('path', { d: 'M3 7a2 2 0 0 1 2-2h4l2 2h6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z' }),
|
|
112
|
+
h('path', { d: 'M9 13h6M13 10l3 3-3 3' }),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function CheckIcon() {
|
|
117
|
+
return h('svg', {
|
|
118
|
+
width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none',
|
|
119
|
+
stroke: 'currentColor', strokeWidth: 2.4, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
120
|
+
'aria-hidden': true,
|
|
121
|
+
}, h('path', { d: 'M20 6L9 17l-5-5' }));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function WarnIcon() {
|
|
125
|
+
return h('svg', {
|
|
126
|
+
width: 16, height: 16, viewBox: '0 0 24 24', fill: 'none',
|
|
127
|
+
stroke: 'currentColor', strokeWidth: 2.2, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
128
|
+
'aria-hidden': true,
|
|
129
|
+
},
|
|
130
|
+
h('circle', { cx: 12, cy: 12, r: 9 }),
|
|
131
|
+
h('path', { d: 'M12 7.5v5M12 16.2v.1' }),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* --------------------- sidebar hover action button ----------------- */
|
|
136
|
+
function RowAction(props) {
|
|
137
|
+
const sessionId = props.sessionId;
|
|
138
|
+
const displayTitle = props.displayTitle;
|
|
139
|
+
if (sessionId === undefined || isArchived(sessionId)) return null;
|
|
140
|
+
return h('button', {
|
|
141
|
+
type: 'button',
|
|
142
|
+
className: 'wsm-grip',
|
|
143
|
+
title: '移动到工作区…',
|
|
144
|
+
'aria-label': '移动到工作区…',
|
|
145
|
+
onClick: (event) => {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
patch({ choose: sessionId, label: displayTitle || '', error: null });
|
|
149
|
+
},
|
|
150
|
+
}, h(MoveIcon));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* ------------------------ sidebar menu item ------------------------ */
|
|
154
|
+
function MenuItem(props) {
|
|
155
|
+
const sessionId = props.sessionId;
|
|
156
|
+
const displayTitle = props.displayTitle;
|
|
157
|
+
const useMenuOpenState = props.useMenuOpenState;
|
|
158
|
+
// Call the hook unconditionally, before any early return.
|
|
159
|
+
let setOpen = null;
|
|
160
|
+
try { const pair = useMenuOpenState ? useMenuOpenState() : null; setOpen = pair ? pair[1] : null; } catch (_) { /* ignore */ }
|
|
161
|
+
if (sessionId === undefined || isArchived(sessionId)) return null;
|
|
162
|
+
return h('button', {
|
|
163
|
+
type: 'button',
|
|
164
|
+
role: 'menuitem',
|
|
165
|
+
className: 'wsm-menu-item',
|
|
166
|
+
onClick: () => {
|
|
167
|
+
if (setOpen) setOpen(false);
|
|
168
|
+
patch({ choose: sessionId, label: displayTitle || '', error: null });
|
|
169
|
+
},
|
|
170
|
+
}, h(MoveIcon), h('span', null, '移动到工作区…'));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* ----------------------------- overlay ---------------------------- */
|
|
174
|
+
// The drag experience targets the real sidebar workspace groups directly;
|
|
175
|
+
// the overlay only renders a non-blocking hint (and the click chooser).
|
|
176
|
+
function Overlay() {
|
|
177
|
+
const s = useStore();
|
|
178
|
+
|
|
179
|
+
React.useEffect(() => {
|
|
180
|
+
if (s.choose === null) return undefined;
|
|
181
|
+
const onKey = (event) => { if (event.key === 'Escape') bridge.close(); };
|
|
182
|
+
document.addEventListener('keydown', onKey, true);
|
|
183
|
+
return () => document.removeEventListener('keydown', onKey, true);
|
|
184
|
+
}, [s.choose]);
|
|
185
|
+
|
|
186
|
+
const stack = [];
|
|
187
|
+
if (s.notice) {
|
|
188
|
+
stack.push(h('div', {
|
|
189
|
+
key: 'notice',
|
|
190
|
+
className: 'wsm-toast ' + (s.notice.error ? 'wsm-toast-err' : 'wsm-toast-ok'),
|
|
191
|
+
role: 'status',
|
|
192
|
+
'aria-live': 'polite',
|
|
193
|
+
},
|
|
194
|
+
h('span', { className: 'wsm-toast-icon' }, s.notice.error ? h(WarnIcon) : h(CheckIcon)),
|
|
195
|
+
h('span', { className: 'wsm-toast-text' }, s.notice.text),
|
|
196
|
+
));
|
|
197
|
+
}
|
|
198
|
+
if (s.choose === null && s.drag !== null) {
|
|
199
|
+
const hint = s.busy
|
|
200
|
+
? '正在迁移…'
|
|
201
|
+
: (s.error ? s.error : '松开鼠标,把会话放到高亮的工作区');
|
|
202
|
+
stack.push(h('div', {
|
|
203
|
+
key: 'hint',
|
|
204
|
+
className: 'wsm-hint' + (s.error ? ' wsm-hint-err' : ''),
|
|
205
|
+
}, s.error ? h(WarnIcon) : h(MoveIcon), h('span', null, hint)));
|
|
206
|
+
}
|
|
207
|
+
const overlay = stack.length === 0
|
|
208
|
+
? null
|
|
209
|
+
: h('div', { className: 'wsm-stack' }, stack);
|
|
210
|
+
|
|
211
|
+
if (s.choose === null) return overlay;
|
|
212
|
+
|
|
213
|
+
const sessionId = s.choose;
|
|
214
|
+
const snap = workspaceSnapshot();
|
|
215
|
+
const items = Array.isArray(snap.items) ? snap.items : [];
|
|
216
|
+
const current = items.find((w) => Array.isArray(w.sessionIds) && w.sessionIds.indexOf(sessionId) !== -1);
|
|
217
|
+
const currentId = current ? String(current.workspaceId) : null;
|
|
218
|
+
const targets = items.filter((w) => String(w.workspaceId) !== currentId);
|
|
219
|
+
|
|
220
|
+
const list = targets.length === 0
|
|
221
|
+
? h('div', { className: 'wsm-empty', key: 'empty' }, '没有其他工作区可移动。')
|
|
222
|
+
: h('div', { className: 'wsm-list', key: 'list' }, targets.map((w) => {
|
|
223
|
+
const id = String(w.workspaceId);
|
|
224
|
+
return h('div', {
|
|
225
|
+
key: id,
|
|
226
|
+
className: 'wsm-item',
|
|
227
|
+
onClick: () => bridge.move(sessionId, id),
|
|
228
|
+
},
|
|
229
|
+
h('div', { className: 'wsm-item-title' }, w.title || w.displayTitle || w.path || id),
|
|
230
|
+
h('div', { className: 'wsm-item-path' }, w.path || ''),
|
|
231
|
+
);
|
|
232
|
+
}));
|
|
233
|
+
|
|
234
|
+
return h(React.Fragment, null,
|
|
235
|
+
h('div', { className: 'wsm-backdrop', key: 'bd', onClick: () => bridge.close() }),
|
|
236
|
+
h('div', {
|
|
237
|
+
key: 'panel',
|
|
238
|
+
className: 'wsm-panel wsm-panel-choose',
|
|
239
|
+
onClick: (event) => event.stopPropagation(),
|
|
240
|
+
},
|
|
241
|
+
h('div', { className: 'wsm-title' }, '移动到工作区'),
|
|
242
|
+
h('div', { className: 'wsm-sub' }, labelFor(sessionId)),
|
|
243
|
+
list,
|
|
244
|
+
s.busy ? h('div', { className: 'wsm-busy' }, '正在迁移…') : null,
|
|
245
|
+
s.error ? h('div', { className: 'wsm-error' }, s.error) : null,
|
|
246
|
+
h('button', { type: 'button', className: 'wsm-cancel', onClick: () => bridge.close() }, '取消'),
|
|
247
|
+
),
|
|
248
|
+
overlay,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
inject: ['slots', 'sessions', 'workspaces', 'uiWorkspace', 'remote', 'remote.commands'],
|
|
254
|
+
apply(ctx) {
|
|
255
|
+
ensureStyle();
|
|
256
|
+
const sessions = ctx.sessions;
|
|
257
|
+
const workspaces = ctx.workspaces;
|
|
258
|
+
const uiWorkspace = ctx.uiWorkspace;
|
|
259
|
+
|
|
260
|
+
bridge.workspaces = () => workspaces.list.getSnapshot();
|
|
261
|
+
bridge.sessionsList = () => sessions.list.getSnapshot();
|
|
262
|
+
bridge.close = () => patch({ choose: null, drag: null, error: null, busy: false });
|
|
263
|
+
|
|
264
|
+
const currentWorkspaceOf = (sessionId) => {
|
|
265
|
+
try {
|
|
266
|
+
const snap = workspaces.list.getSnapshot();
|
|
267
|
+
const items = Array.isArray(snap.items) ? snap.items : [];
|
|
268
|
+
const w = items.find((item) => Array.isArray(item.sessionIds) && item.sessionIds.indexOf(sessionId) !== -1);
|
|
269
|
+
return w ? String(w.workspaceId) : null;
|
|
270
|
+
} catch (_) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
bridge.move = async (sessionId, workspaceId) => {
|
|
276
|
+
if (state.busy) return;
|
|
277
|
+
patch({ busy: true, error: null });
|
|
278
|
+
try {
|
|
279
|
+
const newSessionId = await sessions.using(sessionId, { source: 'workspaceMove' }, async () => {
|
|
280
|
+
const result = await ctx.remote.commands.execute(sessionId, '/move-workspace-to ' + workspaceId, []);
|
|
281
|
+
if (!result.ok) throw new Error((result.error && result.error.message) || '命令调用失败');
|
|
282
|
+
const execution = result.value;
|
|
283
|
+
if (!execution) throw new Error('未找到迁移命令');
|
|
284
|
+
if (execution.result.kind === 'error') throw new Error(execution.result.text || '迁移失败');
|
|
285
|
+
const text = execution.result.text || '';
|
|
286
|
+
if (text.indexOf('already::') === 0) return text.slice('already::'.length).trim();
|
|
287
|
+
const idx = text.lastIndexOf('::');
|
|
288
|
+
return idx >= 0 ? text.slice(idx + 2).trim() : undefined;
|
|
289
|
+
});
|
|
290
|
+
if (!newSessionId) throw new Error('迁移命令未返回新会话 ID');
|
|
291
|
+
try {
|
|
292
|
+
await uiWorkspace.archiveSession(sessionId);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.warn('[workspace-move] source archive failed', error);
|
|
295
|
+
}
|
|
296
|
+
patch({ busy: false, choose: null, drag: null, error: null });
|
|
297
|
+
let targetName = '';
|
|
298
|
+
try {
|
|
299
|
+
const snap = workspaces.list.getSnapshot();
|
|
300
|
+
const hit = (snap.items || []).find((w) => String(w.workspaceId) === String(workspaceId));
|
|
301
|
+
if (hit) targetName = hit.title || hit.displayTitle || hit.path || '';
|
|
302
|
+
} catch (_) { /* ignore */ }
|
|
303
|
+
showNotice(targetName ? '已将会话迁移到「' + targetName + '」' : '已将会话迁移到目标工作区', false);
|
|
304
|
+
try { uiWorkspace.openSession(newSessionId); } catch (error) { console.warn('[workspace-move] open new session failed', error); }
|
|
305
|
+
} catch (error) {
|
|
306
|
+
patch({ busy: false, error: (error && error.message) ? error.message : String(error) });
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/* --- Drag: hit-test the real sidebar rows via structural keys --- *
|
|
311
|
+
* Session rows carry data-row-key="session:<id>"; workspace group
|
|
312
|
+
* headers carry data-row-key="workspace:<id>". This lets a drag
|
|
313
|
+
* resolve its target directly on the sidebar (no floating panel that
|
|
314
|
+
* would cover the list on narrow windows). */
|
|
315
|
+
let highlightedEl = null;
|
|
316
|
+
function setHighlight(el) {
|
|
317
|
+
if (highlightedEl === el) return;
|
|
318
|
+
if (highlightedEl && highlightedEl.classList) highlightedEl.classList.remove('wsm-drop-row');
|
|
319
|
+
highlightedEl = el;
|
|
320
|
+
if (el && el.classList) el.classList.add('wsm-drop-row');
|
|
321
|
+
}
|
|
322
|
+
function closestKey(event, prefix) {
|
|
323
|
+
const target = event.target;
|
|
324
|
+
if (!target || typeof target.closest !== 'function') return null;
|
|
325
|
+
const el = target.closest('[data-row-key^="' + prefix + '"]');
|
|
326
|
+
if (!el) return null;
|
|
327
|
+
const raw = el.getAttribute('data-row-key') || '';
|
|
328
|
+
return { el: el, key: raw.slice(prefix.length) };
|
|
329
|
+
}
|
|
330
|
+
// Resolve the target workspace from whatever sidebar row is under the pointer.
|
|
331
|
+
function targetWorkspace(event) {
|
|
332
|
+
const target = event.target;
|
|
333
|
+
if (!target || typeof target.closest !== 'function') return null;
|
|
334
|
+
if (target.closest('.wsm-panel')) return null; // chooser panel handles itself
|
|
335
|
+
const header = closestKey(event, 'workspace:');
|
|
336
|
+
if (header) {
|
|
337
|
+
if (!header.key) return null; // Ungrouped header cannot receive sessions
|
|
338
|
+
return { key: header.key, el: header.el };
|
|
339
|
+
}
|
|
340
|
+
const sessionRow = closestKey(event, 'session:');
|
|
341
|
+
if (sessionRow && sessionRow.key) {
|
|
342
|
+
const key = currentWorkspaceOf(sessionRow.key);
|
|
343
|
+
if (!key) return null;
|
|
344
|
+
const el = document.querySelector('[data-row-key="workspace:' + key + '"]');
|
|
345
|
+
return { key: key, el: el };
|
|
346
|
+
}
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const onDragStart = (event) => {
|
|
351
|
+
const row = closestKey(event, 'session:');
|
|
352
|
+
let id = row && row.key ? row.key : '';
|
|
353
|
+
const valid = /^session-[0-9a-zA-Z-]+$/;
|
|
354
|
+
if (!valid.test(id)) {
|
|
355
|
+
try {
|
|
356
|
+
const dt = event.dataTransfer;
|
|
357
|
+
const data = dt ? (dt.getData('text/plain') || dt.getData('text')) : '';
|
|
358
|
+
if (valid.test(data)) id = data;
|
|
359
|
+
} catch (_) { /* ignore */ }
|
|
360
|
+
}
|
|
361
|
+
if (!valid.test(id) || isArchived(id)) return;
|
|
362
|
+
let label = '';
|
|
363
|
+
try {
|
|
364
|
+
const summary = sessions.list.getSnapshot().byId[id];
|
|
365
|
+
if (summary) label = summary.displayTitle || summary.title || '';
|
|
366
|
+
} catch (_) { /* ignore */ }
|
|
367
|
+
patch({ drag: id, label: label, error: null });
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const onDragOver = (event) => {
|
|
371
|
+
if (state.drag === null) return;
|
|
372
|
+
const t = targetWorkspace(event);
|
|
373
|
+
if (t === null) {
|
|
374
|
+
setHighlight(null);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
event.preventDefault();
|
|
378
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'move';
|
|
379
|
+
if (t.key === currentWorkspaceOf(state.drag)) {
|
|
380
|
+
setHighlight(null); // already in this workspace: no-op target
|
|
381
|
+
} else {
|
|
382
|
+
setHighlight(t.el || null);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const onDrop = (event) => {
|
|
387
|
+
if (state.drag === null) return;
|
|
388
|
+
const t = targetWorkspace(event);
|
|
389
|
+
if (t === null) {
|
|
390
|
+
setHighlight(null);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
event.preventDefault();
|
|
394
|
+
event.stopPropagation();
|
|
395
|
+
const sessionId = state.drag;
|
|
396
|
+
setHighlight(null);
|
|
397
|
+
if (t.key === currentWorkspaceOf(sessionId)) {
|
|
398
|
+
patch({ drag: null, error: null });
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
bridge.move(sessionId, t.key);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const onDragEnd = () => {
|
|
405
|
+
setHighlight(null);
|
|
406
|
+
if (state.drag !== null) patch({ drag: null });
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
document.addEventListener('dragstart', onDragStart, false);
|
|
410
|
+
document.addEventListener('dragover', onDragOver, false);
|
|
411
|
+
document.addEventListener('drop', onDrop, false);
|
|
412
|
+
document.addEventListener('dragend', onDragEnd, false);
|
|
413
|
+
ctx.effect(() => () => {
|
|
414
|
+
setHighlight(null);
|
|
415
|
+
document.removeEventListener('dragstart', onDragStart, false);
|
|
416
|
+
document.removeEventListener('dragover', onDragOver, false);
|
|
417
|
+
document.removeEventListener('drop', onDrop, false);
|
|
418
|
+
document.removeEventListener('dragend', onDragEnd, false);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
ctx.slots.inject('sidebar.workspaces.session.row.action', () => ctx.slots.register({
|
|
422
|
+
name: 'sidebar.workspaces.session.row.action', id: 'workspace-move', order: 150,
|
|
423
|
+
}, RowAction));
|
|
424
|
+
|
|
425
|
+
ctx.slots.inject('sidebar.workspaces.session.menu.item', () => ctx.slots.register({
|
|
426
|
+
name: 'sidebar.workspaces.session.menu.item', id: 'workspace-move', order: 520,
|
|
427
|
+
}, MenuItem));
|
|
428
|
+
|
|
429
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
430
|
+
name: 'shell.overlay', id: 'workspace-move-overlay', order: 900,
|
|
431
|
+
}, Overlay));
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
},
|
|
435
|
+
});
|
package/cordis.patch.yml
ADDED
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Move conversation to workspace
|
|
2
|
+
|
|
3
|
+
DSH groups a session under the workspace whose directory matches the `cwd` recorded, immutably, in the session's header. A conversation that started in the default workspace therefore cannot be dropped into another directory workspace by reordering — its recorded directory still points at the default one.
|
|
4
|
+
|
|
5
|
+
This plugin makes that move possible from the sidebar.
|
|
6
|
+
|
|
7
|
+
## How to use
|
|
8
|
+
|
|
9
|
+
- **Drag:** press and drag any conversation row in the sidebar. While dragging, move over a workspace group (its header, or any conversation inside it); that group lights up and releasing the row moves the conversation there.
|
|
10
|
+
- **Menu:** hover the row and click the folder-arrow button, or open the row's ⋯ menu and choose **Move to workspace…**, then pick a workspace.
|
|
11
|
+
|
|
12
|
+
## What it actually does
|
|
13
|
+
|
|
14
|
+
Because the header directory cannot be rewritten in place, the move is a **safe migration copy**:
|
|
15
|
+
|
|
16
|
+
1. A new session is created inside the target workspace, seeded from the source conversation's history up to its last completed turn (the same seeding a fork uses).
|
|
17
|
+
2. The new session is attached to the target workspace.
|
|
18
|
+
3. The original session is archived, and the migrated copy is opened.
|
|
19
|
+
|
|
20
|
+
Nothing is overwritten and the original log is preserved: you can unarchive it from **View options → All conversations** to undo.
|
|
21
|
+
|
|
22
|
+
## Limitations
|
|
23
|
+
|
|
24
|
+
- The migrated conversation is a **new session** (new id); the original id is not reused.
|
|
25
|
+
- Only completed turns are carried over; an in-progress turn is not included.
|
|
26
|
+
- A session with no completed turn cannot be migrated.
|
|
27
|
+
- Sessions already in the target workspace are left untouched.
|
|
28
|
+
|
|
29
|
+
## Agent tool
|
|
30
|
+
|
|
31
|
+
The same operation is exposed to the agent as `move_session_to_workspace` (`session_id`, `workspace_id`, optional `dry_run`). `dry_run: true` returns the plan without creating anything.
|
package/icon.svg
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Move conversation to workspace">
|
|
2
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="#1f6feb"/>
|
|
3
|
+
<path d="M12 21a4 4 0 0 1 4-4h9l4 4h15a4 4 0 0 1 4 4v20a4 4 0 0 1-4 4H16a4 4 0 0 1-4-4z" fill="#ffffff" fill-opacity="0.16" stroke="#ffffff" stroke-width="2.5" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M26 34h14M34 28l6 6-6 6" fill="none" stroke="#ffffff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the "move conversation to workspace" bundle.
|
|
3
|
+
*
|
|
4
|
+
* A DSH session's workspace membership is derived from the immutable `cwd` in
|
|
5
|
+
* the session header, so an already-recorded conversation cannot be re-homed by
|
|
6
|
+
* editing that header. This plugin therefore performs a safe, reversible
|
|
7
|
+
* *migration copy*: it creates a brand-new session inside the target workspace
|
|
8
|
+
* whose history is seeded from the source conversation (exactly the mechanism a
|
|
9
|
+
* fork uses), attaches it to the target workspace, and lets the caller archive
|
|
10
|
+
* the original.
|
|
11
|
+
*
|
|
12
|
+
* Two callers share one implementation:
|
|
13
|
+
* - a Host command `move-workspace-to` (the sidebar UI drives it through the
|
|
14
|
+
* existing `commands.execute` Remote bridge), and
|
|
15
|
+
* - a Host tool `move_session_to_workspace` (agent-callable, with a `dry_run`
|
|
16
|
+
* mode that only plans).
|
|
17
|
+
*
|
|
18
|
+
* The seed is built with plain values only: the migration always cuts at a
|
|
19
|
+
* `turn/end`, so the inherited prefix is balanced and needs no synthetic
|
|
20
|
+
* closers. Branded ids are compile-time brands with no runtime identity, so raw
|
|
21
|
+
* strings and numbers are accepted by the Host services. This keeps the bundle
|
|
22
|
+
* free of imports from the DSH installation, which a workspace-linked bundle
|
|
23
|
+
* cannot resolve through Node directly.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { randomUUID } from 'node:crypto'
|
|
27
|
+
|
|
28
|
+
/** Cordis plugin name. */
|
|
29
|
+
export const name = 'workspace-move'
|
|
30
|
+
|
|
31
|
+
/** Services the plugin needs. */
|
|
32
|
+
export const inject = ['commands', 'tools', 'agents', 'workspaceRegistry', 'agentDefaultModel', 'sessionQuery']
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Index of the last completed `turn/end` event, i.e. the boundary to inherit through.
|
|
36
|
+
* @param {readonly {type: string}[]} events contiguous session events from seq 0.
|
|
37
|
+
* @returns the boundary sequence, or undefined when the session has no completed turn.
|
|
38
|
+
*/
|
|
39
|
+
function lastCompletedBoundary(events) {
|
|
40
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
41
|
+
if (events[i].type === 'turn/end') return i
|
|
42
|
+
}
|
|
43
|
+
return undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Build a fork seed ending exactly at `boundarySeq` (a `turn/end`), appending the
|
|
48
|
+
* inherited marker. The prefix is balanced, so no synthetic turn closers apply.
|
|
49
|
+
* @param {readonly any[]} events contiguous session events from seq 0.
|
|
50
|
+
* @param {number} boundarySeq inclusive sequence to inherit through.
|
|
51
|
+
* @returns {any[]} the seed array.
|
|
52
|
+
*/
|
|
53
|
+
function buildSeed(events, boundarySeq) {
|
|
54
|
+
const prefix = events.slice(0, boundarySeq + 1)
|
|
55
|
+
const last = events[boundarySeq]
|
|
56
|
+
prefix.push({
|
|
57
|
+
type: 'session/end-seed',
|
|
58
|
+
seq: boundarySeq + 1,
|
|
59
|
+
time: last.time,
|
|
60
|
+
data: { inherited: true },
|
|
61
|
+
})
|
|
62
|
+
return prefix
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Build the creation-time Agent setup for the source session's preset.
|
|
67
|
+
* @param {any} ctx Host context.
|
|
68
|
+
* @param {string | null | undefined} presetId preset recorded on the source session, if any.
|
|
69
|
+
* @returns {Promise<{ agentPreset?: string, setup?: (agentCtx: any) => any }>}
|
|
70
|
+
*/
|
|
71
|
+
async function compositionFor(ctx, presetId) {
|
|
72
|
+
const presets = ctx.get('agentPresets')
|
|
73
|
+
if (presets === undefined) return { setup: undefined }
|
|
74
|
+
const resolvedId = (await presets.resolve(presetId === null ? undefined : presetId)).id
|
|
75
|
+
return {
|
|
76
|
+
agentPreset: resolvedId,
|
|
77
|
+
setup: async (agentCtx) => {
|
|
78
|
+
await presets.mount(agentCtx, resolvedId)
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Provider/model/reasoning accessors that follow the current default selection. */
|
|
84
|
+
function defaultAgentOptions(ctx) {
|
|
85
|
+
const defaults = ctx.agentDefaultModel
|
|
86
|
+
return {
|
|
87
|
+
get provider() { return defaults.currentSelection().provider },
|
|
88
|
+
get model() { return defaults.currentSelection().model },
|
|
89
|
+
get reasoningEffort() { return defaults.currentSelection().reasoningEffort },
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Core migration: seed a new session in `targetWorkspaceId` from `source` history.
|
|
95
|
+
* @param {any} ctx Host context.
|
|
96
|
+
* @param {{ id: string, events: readonly any[], preset?: string | null }} source source session facts.
|
|
97
|
+
* @param {string} targetWorkspaceId target workspace id.
|
|
98
|
+
* @param {boolean} dryRun when true, plan only and create nothing.
|
|
99
|
+
*/
|
|
100
|
+
async function migrate(ctx, source, targetWorkspaceId, dryRun) {
|
|
101
|
+
if (typeof targetWorkspaceId !== 'string' || targetWorkspaceId.trim() === '') {
|
|
102
|
+
return { ok: false, error: '缺少目标工作区 ID' }
|
|
103
|
+
}
|
|
104
|
+
const targetId = targetWorkspaceId.trim()
|
|
105
|
+
let workspace
|
|
106
|
+
try {
|
|
107
|
+
workspace = ctx.workspaceRegistry.get(targetId)
|
|
108
|
+
} catch {
|
|
109
|
+
workspace = undefined
|
|
110
|
+
}
|
|
111
|
+
if (workspace === undefined) {
|
|
112
|
+
return { ok: false, error: `目标工作区不存在: ${targetId}` }
|
|
113
|
+
}
|
|
114
|
+
if (workspace.sessionIds.includes(source.id)) {
|
|
115
|
+
return { ok: true, alreadyThere: true, targetPath: workspace.path, workspaceTitle: workspace.title }
|
|
116
|
+
}
|
|
117
|
+
const boundary = lastCompletedBoundary(source.events)
|
|
118
|
+
if (boundary === undefined) {
|
|
119
|
+
return { ok: false, error: '该会话还没有已完成的回合,无法迁移。' }
|
|
120
|
+
}
|
|
121
|
+
let seed
|
|
122
|
+
try {
|
|
123
|
+
seed = buildSeed(source.events, boundary)
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return { ok: false, error: `构造迁移种子失败: ${String((error && error.message) || error)}` }
|
|
126
|
+
}
|
|
127
|
+
const composition = await compositionFor(ctx, source.preset)
|
|
128
|
+
const plan = {
|
|
129
|
+
ok: true,
|
|
130
|
+
targetPath: workspace.path,
|
|
131
|
+
workspaceTitle: workspace.title,
|
|
132
|
+
boundarySeq: boundary,
|
|
133
|
+
seedEvents: seed.length,
|
|
134
|
+
agentPreset: composition.agentPreset,
|
|
135
|
+
}
|
|
136
|
+
if (dryRun) return { ...plan, dryRun: true }
|
|
137
|
+
|
|
138
|
+
const newSessionId = `session-${randomUUID()}`
|
|
139
|
+
try {
|
|
140
|
+
await ctx.agents.create({
|
|
141
|
+
sessionId: newSessionId,
|
|
142
|
+
seed,
|
|
143
|
+
inheritedEventCount: boundary + 1,
|
|
144
|
+
meta: {
|
|
145
|
+
cwd: workspace.path,
|
|
146
|
+
isSeeded: true,
|
|
147
|
+
...(composition.agentPreset === undefined ? {} : { agentPreset: composition.agentPreset }),
|
|
148
|
+
},
|
|
149
|
+
agentOptions: defaultAgentOptions(ctx),
|
|
150
|
+
...(composition.setup === undefined ? {} : { setup: composition.setup }),
|
|
151
|
+
})
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return { ok: false, error: `创建迁移会话失败: ${String((error && error.message) || error)}` }
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
await workspace.attachSession(newSessionId)
|
|
157
|
+
} catch (error) {
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
newSessionId,
|
|
161
|
+
error: `已创建迁移会话 ${newSessionId},但加入工作区失败: ${String((error && error.message) || error)}`,
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { ...plan, newSessionId }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Register the sidebar command and the agent tool.
|
|
169
|
+
* @param {any} ctx Host context.
|
|
170
|
+
*/
|
|
171
|
+
export function apply(ctx) {
|
|
172
|
+
ctx.effect(() => ctx.commands.register({
|
|
173
|
+
name: 'move-workspace-to',
|
|
174
|
+
description: 'Move this conversation into a directory workspace (safe migration copy).',
|
|
175
|
+
recordInput: false,
|
|
176
|
+
handler: async ({ agent, rawInput }) => {
|
|
177
|
+
const session = agent.session
|
|
178
|
+
const presets = ctx.get('agentPresets')
|
|
179
|
+
const preset = presets === undefined ? undefined : presets.presetForSession(session)
|
|
180
|
+
const result = await migrate(
|
|
181
|
+
ctx,
|
|
182
|
+
{ id: session.id, events: session.snapshotEvents(), preset },
|
|
183
|
+
rawInput.trim(),
|
|
184
|
+
false,
|
|
185
|
+
)
|
|
186
|
+
if (!result.ok) return { kind: 'error', text: result.error }
|
|
187
|
+
if (result.alreadyThere) return { kind: 'success', text: `already::${session.id}` }
|
|
188
|
+
return { kind: 'success', text: `moved::${result.newSessionId}` }
|
|
189
|
+
},
|
|
190
|
+
}))
|
|
191
|
+
|
|
192
|
+
ctx.effect(() => ctx.tools.register({
|
|
193
|
+
name: 'move_session_to_workspace',
|
|
194
|
+
description: 'Move a conversation into an existing directory workspace by creating a migrated copy (history seeded, original left for the caller to archive). Use dry_run to preview the plan without creating anything.',
|
|
195
|
+
parameters: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
additionalProperties: false,
|
|
198
|
+
properties: {
|
|
199
|
+
session_id: { type: 'string', description: 'Source conversation session id to migrate.' },
|
|
200
|
+
workspace_id: { type: 'string', description: 'Target workspace id (from the sidebar workspaces).' },
|
|
201
|
+
dry_run: { type: 'boolean', description: 'Only compute and return the migration plan; create nothing.' },
|
|
202
|
+
},
|
|
203
|
+
required: ['session_id', 'workspace_id'],
|
|
204
|
+
},
|
|
205
|
+
output: {
|
|
206
|
+
schema: {
|
|
207
|
+
type: 'object',
|
|
208
|
+
additionalProperties: true,
|
|
209
|
+
properties: {
|
|
210
|
+
ok: { type: 'boolean' },
|
|
211
|
+
newSessionId: { type: 'string' },
|
|
212
|
+
targetPath: { type: 'string' },
|
|
213
|
+
boundarySeq: { type: 'number' },
|
|
214
|
+
seedEvents: { type: 'number' },
|
|
215
|
+
dryRun: { type: 'boolean' },
|
|
216
|
+
error: { type: 'string' },
|
|
217
|
+
},
|
|
218
|
+
required: ['ok'],
|
|
219
|
+
},
|
|
220
|
+
render: (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }],
|
|
221
|
+
},
|
|
222
|
+
async execute(args) {
|
|
223
|
+
// Explicit disposal instead of `using`, so the file parses on every Node
|
|
224
|
+
// the registry might run it under, not only those with explicit resource
|
|
225
|
+
// management.
|
|
226
|
+
const observation = await ctx.sessionQuery.observeSession(args.session_id)
|
|
227
|
+
try {
|
|
228
|
+
const preset = observation.projections === undefined
|
|
229
|
+
? undefined
|
|
230
|
+
: observation.projections.values.agentPreset
|
|
231
|
+
const result = await migrate(
|
|
232
|
+
ctx,
|
|
233
|
+
{ id: observation.header.id, events: observation.events, preset },
|
|
234
|
+
args.workspace_id,
|
|
235
|
+
args.dry_run === true,
|
|
236
|
+
)
|
|
237
|
+
if (!result.ok) throw new Error(result.error)
|
|
238
|
+
return result
|
|
239
|
+
} finally {
|
|
240
|
+
if (typeof observation[Symbol.dispose] === 'function') observation[Symbol.dispose]()
|
|
241
|
+
else if (typeof observation.dispose === 'function') await observation.dispose()
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
}))
|
|
245
|
+
}
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junerver/dsh-workspace",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "DSH plugin: move a conversation into a directory workspace from the sidebar (drag or menu).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./client": "./client.js",
|
|
10
|
+
"./locale/*.json": "./locale/*.json",
|
|
11
|
+
"./icon": "./icon.svg"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"client.js",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"locale/*.json",
|
|
18
|
+
"docs",
|
|
19
|
+
"icon.svg",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"check": "node scripts/check.mjs",
|
|
25
|
+
"pack:dry": "npm pack --dry-run",
|
|
26
|
+
"prepublishOnly": "npm run check"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"dsh",
|
|
30
|
+
"dsh-plugin",
|
|
31
|
+
"dsh-bundle",
|
|
32
|
+
"deepseek-harness",
|
|
33
|
+
"workspace",
|
|
34
|
+
"session",
|
|
35
|
+
"sidebar",
|
|
36
|
+
"drag-and-drop",
|
|
37
|
+
"工作区",
|
|
38
|
+
"会话",
|
|
39
|
+
"拖拽"
|
|
40
|
+
],
|
|
41
|
+
"author": "junerver",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/junerver/dsh-workspace.git"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/junerver/dsh-workspace#readme",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/junerver/dsh-workspace/issues"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20.0.0"
|
|
56
|
+
},
|
|
57
|
+
"dsh": {
|
|
58
|
+
"bundle": { "patch": "./cordis.patch.yml" },
|
|
59
|
+
"client": {
|
|
60
|
+
"platform": "web",
|
|
61
|
+
"immediately": true,
|
|
62
|
+
"inject": [
|
|
63
|
+
"@deepseek-ai/dsh-client-ui-workspace",
|
|
64
|
+
"@deepseek-ai/dsh-client-ui-commands"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|