dsh-context-fold 0.1.0 → 0.1.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 +21 -21
- package/cordis.patch.yml +6 -6
- package/icon.svg +6 -6
- package/lib/client.d.ts +23 -2
- package/lib/client.js +254 -127
- package/locale/en.json +9 -9
- package/locale/zh.json +9 -9
- package/package.json +8 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 niechao136
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 niechao136
|
|
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/cordis.patch.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# dsh-context-fold bundle layer: the plugin needs no configuration to start, so this patch only
|
|
2
|
-
# inserts the row. Per-session tuning lives in the profile's own cordis.patch.yml, under this entry's
|
|
3
|
-
# `config` (see README §Configuration).
|
|
4
|
-
- insert:
|
|
5
|
-
- id: context-fold
|
|
6
|
-
name: dsh-context-fold
|
|
1
|
+
# dsh-context-fold bundle layer: the plugin needs no configuration to start, so this patch only
|
|
2
|
+
# inserts the row. Per-session tuning lives in the profile's own cordis.patch.yml, under this entry's
|
|
3
|
+
# `config` (see README §Configuration).
|
|
4
|
+
- insert:
|
|
5
|
+
- id: context-fold
|
|
6
|
+
name: dsh-context-fold
|
package/icon.svg
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
|
2
|
-
<path d="M4 6h16" />
|
|
3
|
-
<path d="M4 12h16" />
|
|
4
|
-
<path d="M4 18h7" />
|
|
5
|
-
<path d="M15 16l2 2 4-4" />
|
|
6
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
|
|
2
|
+
<path d="M4 6h16" />
|
|
3
|
+
<path d="M4 12h16" />
|
|
4
|
+
<path d="M4 18h7" />
|
|
5
|
+
<path d="M15 16l2 2 4-4" />
|
|
6
|
+
</svg>
|
package/lib/client.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-context-fold",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
1
6
|
/**
|
|
2
7
|
* `conversation.view` tab: what this plugin folded, what it saved, and the full
|
|
3
8
|
* text behind each fold.
|
|
@@ -20,6 +25,14 @@
|
|
|
20
25
|
* The original text of every fold is shown on demand, fetched by its recovery
|
|
21
26
|
* path, so the tab doubles as the answer to "what exactly did it remove".
|
|
22
27
|
*
|
|
28
|
+
* ## How this file is shipped
|
|
29
|
+
*
|
|
30
|
+
* `tsdown` wraps the output in the shell's module-factory form
|
|
31
|
+
* (`window.__ModuleLoader__.load({id, factory(require){…}})`), which is the only
|
|
32
|
+
* shape the client module system executes. Imports are therefore converted into
|
|
33
|
+
* `require` calls resolved against the shared platform module table, and the
|
|
34
|
+
* plugin's exports (`name`/`inject`/`apply`) are what the factory returns.
|
|
35
|
+
*
|
|
23
36
|
* @module dsh-context-fold/client
|
|
24
37
|
*/
|
|
25
38
|
/** One fold row as the server reports it. */
|
|
@@ -78,8 +91,10 @@ interface ClientContext {
|
|
|
78
91
|
register(descriptor: Record<string, unknown>, render: (props: unknown) => unknown): unknown;
|
|
79
92
|
};
|
|
80
93
|
locale: {
|
|
81
|
-
|
|
94
|
+
register(namespace: string, dictionaries: Record<string, Record<string, string>>): unknown;
|
|
95
|
+
bind(namespace: string): (key: string) => string;
|
|
82
96
|
};
|
|
97
|
+
effect?(run: () => unknown, label?: string): unknown;
|
|
83
98
|
}
|
|
84
99
|
/** Client plugin name. */
|
|
85
100
|
declare const name = "context-fold-client";
|
|
@@ -88,7 +103,13 @@ declare const inject: string[];
|
|
|
88
103
|
/**
|
|
89
104
|
* Mount the conversation tab.
|
|
90
105
|
*
|
|
106
|
+
* Dictionaries are registered from inside this bundle: the locale service reads
|
|
107
|
+
* them from the plugin registry, not from `locale/*.json` on disk.
|
|
108
|
+
*
|
|
91
109
|
* @param ctx - client plugin context.
|
|
92
110
|
*/
|
|
93
111
|
declare function apply(ctx: ClientContext): void;
|
|
94
|
-
export { FoldReportPayload, FoldRow, apply, inject, name };
|
|
112
|
+
export { FoldReportPayload, FoldRow, apply, inject, name };
|
|
113
|
+
return module.exports;
|
|
114
|
+
},
|
|
115
|
+
});
|
package/lib/client.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-context-fold",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
7
|
// src/client.ts
|
|
8
|
+
/** Locale namespace owned by this plugin's client half. */
|
|
9
|
+
const NS = "contextFold";
|
|
10
|
+
/** Dictionary: keep keys aligned with `locale/*.json`. */
|
|
11
|
+
const zh = { "tab.contextFold": "上下文折叠" };
|
|
12
|
+
/** Dictionary: keep keys aligned with `locale/*.json`. */
|
|
13
|
+
const en = { "tab.contextFold": "Context fold" };
|
|
14
|
+
const react = require("react");
|
|
2
15
|
/** Fetch the report for one session. */
|
|
3
16
|
async function fetchReport(sessionId) {
|
|
4
17
|
const response = await fetch("/api/context-fold/report", {
|
|
@@ -33,48 +46,93 @@ function signed(value) {
|
|
|
33
46
|
const rounded = Math.round(value * 10) / 10;
|
|
34
47
|
return `${rounded > 0 ? "+" : ""}${num(rounded)}`;
|
|
35
48
|
}
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* called from any client runtime, and depending on a specific React bundle would
|
|
41
|
-
* couple this package to one shell version.
|
|
42
|
-
*
|
|
43
|
-
* @param props - slot props carrying the active session id.
|
|
44
|
-
* @returns an element or a node tree.
|
|
45
|
-
*/
|
|
46
|
-
function renderTab(props) {
|
|
47
|
-
const sessionId = props?.sessionId;
|
|
48
|
-
const root = document.createElement("div");
|
|
49
|
-
root.className = "context-fold-tab";
|
|
50
|
-
root.style.cssText = "padding:12px;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;overflow:auto;height:100%";
|
|
51
|
-
const title = document.createElement("div");
|
|
52
|
-
title.textContent = "Context fold";
|
|
53
|
-
title.style.cssText = "font-weight:600;margin-bottom:8px";
|
|
54
|
-
root.append(title);
|
|
55
|
-
const status = document.createElement("div");
|
|
56
|
-
status.style.cssText = "color:#888";
|
|
57
|
-
status.textContent = sessionId === void 0 ? "No active session." : "Loading…";
|
|
58
|
-
root.append(status);
|
|
59
|
-
if (sessionId !== void 0) fetchReport(sessionId).then((report) => {
|
|
60
|
-
root.replaceChildren(title);
|
|
61
|
-
if (report === void 0) {
|
|
62
|
-
status.textContent = "No report available for this session.";
|
|
63
|
-
root.append(status);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
root.append(renderSummary(report), renderFolds(sessionId, report));
|
|
67
|
-
});
|
|
68
|
-
return root;
|
|
49
|
+
/** Read the active session id out of the slot props. */
|
|
50
|
+
function sessionIdOf(props) {
|
|
51
|
+
const value = props?.sessionId;
|
|
52
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
69
53
|
}
|
|
54
|
+
/** Inline styles, kept as plain objects because no CSS module ships here. */
|
|
55
|
+
const styles = {
|
|
56
|
+
root: {
|
|
57
|
+
padding: "12px",
|
|
58
|
+
font: "13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace",
|
|
59
|
+
overflow: "auto",
|
|
60
|
+
height: "100%"
|
|
61
|
+
},
|
|
62
|
+
title: {
|
|
63
|
+
fontWeight: 600,
|
|
64
|
+
marginBottom: "8px"
|
|
65
|
+
},
|
|
66
|
+
muted: { color: "#888" },
|
|
67
|
+
box: {
|
|
68
|
+
marginBottom: "12px",
|
|
69
|
+
padding: "8px",
|
|
70
|
+
border: "1px solid #333",
|
|
71
|
+
borderRadius: "6px"
|
|
72
|
+
},
|
|
73
|
+
heading: {
|
|
74
|
+
fontWeight: 600,
|
|
75
|
+
marginBottom: "6px"
|
|
76
|
+
},
|
|
77
|
+
table: { borderCollapse: "collapse" },
|
|
78
|
+
labelCell: {
|
|
79
|
+
padding: "1px 12px 1px 0",
|
|
80
|
+
color: "#aaa"
|
|
81
|
+
},
|
|
82
|
+
warning: {
|
|
83
|
+
marginTop: "6px",
|
|
84
|
+
color: "#facc15"
|
|
85
|
+
},
|
|
86
|
+
reread: {
|
|
87
|
+
marginTop: "6px",
|
|
88
|
+
color: "#f87171"
|
|
89
|
+
},
|
|
90
|
+
fold: {
|
|
91
|
+
marginBottom: "6px",
|
|
92
|
+
padding: "6px",
|
|
93
|
+
border: "1px solid #2a2a2a",
|
|
94
|
+
borderRadius: "6px"
|
|
95
|
+
},
|
|
96
|
+
foldSummary: { cursor: "pointer" },
|
|
97
|
+
inlinePre: {
|
|
98
|
+
whiteSpace: "pre-wrap",
|
|
99
|
+
margin: "6px 0",
|
|
100
|
+
color: "#bbb",
|
|
101
|
+
maxHeight: "12em",
|
|
102
|
+
overflow: "auto"
|
|
103
|
+
},
|
|
104
|
+
originalPre: {
|
|
105
|
+
whiteSpace: "pre-wrap",
|
|
106
|
+
margin: "6px 0",
|
|
107
|
+
color: "#ddd",
|
|
108
|
+
maxHeight: "24em",
|
|
109
|
+
overflow: "auto",
|
|
110
|
+
borderTop: "1px dashed #333",
|
|
111
|
+
paddingTop: "6px"
|
|
112
|
+
},
|
|
113
|
+
locator: {
|
|
114
|
+
color: "#666",
|
|
115
|
+
fontSize: "11px",
|
|
116
|
+
wordBreak: "break-all"
|
|
117
|
+
},
|
|
118
|
+
notRecoverable: {
|
|
119
|
+
color: "#f87171",
|
|
120
|
+
fontSize: "11px"
|
|
121
|
+
},
|
|
122
|
+
detailsToggle: {
|
|
123
|
+
cursor: "pointer",
|
|
124
|
+
color: "#888",
|
|
125
|
+
marginTop: "6px"
|
|
126
|
+
},
|
|
127
|
+
assumptionList: {
|
|
128
|
+
margin: "4px 0 0 16px",
|
|
129
|
+
padding: 0,
|
|
130
|
+
color: "#999"
|
|
131
|
+
}
|
|
132
|
+
};
|
|
70
133
|
/** The counterfactual summary block. */
|
|
71
|
-
function
|
|
72
|
-
const cf = report.counterfactual;
|
|
73
|
-
const box = document.createElement("section");
|
|
74
|
-
box.style.cssText = "margin-bottom:12px;padding:8px;border:1px solid #333;border-radius:6px";
|
|
75
|
-
const heading = document.createElement("div");
|
|
76
|
-
heading.textContent = "Token comparison (estimate)";
|
|
77
|
-
heading.style.cssText = "font-weight:600;margin-bottom:6px";
|
|
134
|
+
function Summary(props) {
|
|
135
|
+
const cf = props.report.counterfactual;
|
|
78
136
|
const rows = [
|
|
79
137
|
["Folded content, now", `${num(cf.tokensNow)} tokens`],
|
|
80
138
|
["If it had stayed unfolded", `${num(cf.tokensIfUnfolded)} tokens`],
|
|
@@ -84,93 +142,137 @@ function renderSummary(report) {
|
|
|
84
142
|
["Prefix invalidation cost", signed(-cf.invalidationCost)],
|
|
85
143
|
["Net", signed(cf.netSaving)]
|
|
86
144
|
];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const assumptions = document.createElement("details");
|
|
104
|
-
const summary = document.createElement("summary");
|
|
105
|
-
summary.textContent = "Assumptions";
|
|
106
|
-
summary.style.cssText = "cursor:pointer;color:#888;margin-top:6px";
|
|
107
|
-
assumptions.append(summary);
|
|
108
|
-
const list = document.createElement("ul");
|
|
109
|
-
list.style.cssText = "margin:4px 0 0 16px;padding:0;color:#999";
|
|
110
|
-
for (const assumption of cf.assumptions) {
|
|
111
|
-
const item = document.createElement("li");
|
|
112
|
-
item.textContent = assumption;
|
|
113
|
-
list.append(item);
|
|
114
|
-
}
|
|
115
|
-
assumptions.append(list);
|
|
116
|
-
box.append(heading, table, freshness, assumptions);
|
|
117
|
-
if (report.reReads > 0) {
|
|
118
|
-
const reread = document.createElement("div");
|
|
119
|
-
reread.style.cssText = "margin-top:6px;color:#f87171";
|
|
120
|
-
reread.textContent = `Re-read signals: ${String(report.reReads)} — folded content was fetched again after being folded.`;
|
|
121
|
-
box.append(reread);
|
|
122
|
-
}
|
|
123
|
-
return box;
|
|
145
|
+
return react.createElement("section", { style: styles.box }, react.createElement("div", {
|
|
146
|
+
style: styles.heading,
|
|
147
|
+
key: "h"
|
|
148
|
+
}, "Token comparison (estimate)"), react.createElement("table", {
|
|
149
|
+
style: styles.table,
|
|
150
|
+
key: "t"
|
|
151
|
+
}, ...rows.map(([label, value]) => react.createElement("tr", { key: label }, react.createElement("td", { style: styles.labelCell }, label), react.createElement("td", label === "Net" ? { style: {
|
|
152
|
+
fontWeight: 600,
|
|
153
|
+
color: cf.netSaving >= 0 ? "#4ade80" : "#f87171"
|
|
154
|
+
} } : null, value)))), react.createElement("div", {
|
|
155
|
+
style: styles.warning,
|
|
156
|
+
key: "f"
|
|
157
|
+
}, cf.hasRealUsage ? `Priced against this session's real usage${cf.cacheReadShare === void 0 ? "" : ` (cache-read share ${(cf.cacheReadShare * 100).toFixed(1)}%)`}.` : "This session reported NO provider usage — every figure here is heuristic token counts, not a bill."), react.createElement("details", { key: "a" }, react.createElement("summary", { style: styles.detailsToggle }, "Assumptions"), react.createElement("ul", { style: styles.assumptionList }, ...cf.assumptions.map((assumption, index) => react.createElement("li", { key: String(index) }, assumption)))), props.report.reReads > 0 ? react.createElement("div", {
|
|
158
|
+
style: styles.reread,
|
|
159
|
+
key: "r"
|
|
160
|
+
}, `Re-read signals: ${String(props.report.reReads)} — folded content was fetched again after being folded.`) : null);
|
|
124
161
|
}
|
|
125
|
-
/**
|
|
126
|
-
function
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
162
|
+
/** One fold row; the original text loads when the row is opened. */
|
|
163
|
+
function FoldItem(props) {
|
|
164
|
+
const { fold, sessionId } = props;
|
|
165
|
+
const [original, setOriginal] = react.useState(null);
|
|
166
|
+
const onToggle = (event) => {
|
|
167
|
+
if (event.currentTarget?.open !== true || original !== null) return;
|
|
168
|
+
const locator = fold.locator;
|
|
169
|
+
if (locator === void 0) return;
|
|
170
|
+
setOriginal("");
|
|
171
|
+
fetchOriginal(sessionId, locator).then((text) => {
|
|
172
|
+
setOriginal(text ?? "(could not read the stored original)");
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const summary = `${fold.kind === "reasoning" ? "reasoning" : fold.toolName ?? "tool"} · turn ${String(fold.turn)}.${String(fold.step)} · ${num(fold.charsBefore)} → ${num(fold.charsAfter)} chars · ${fold.recoverable ? "recoverable" : "NOT recoverable"}`;
|
|
176
|
+
const children = [react.createElement("summary", {
|
|
177
|
+
style: styles.foldSummary,
|
|
178
|
+
key: "s"
|
|
179
|
+
}, summary), react.createElement("pre", {
|
|
180
|
+
style: styles.inlinePre,
|
|
181
|
+
key: "i"
|
|
182
|
+
}, fold.inline)];
|
|
183
|
+
if (fold.locator !== void 0) {
|
|
184
|
+
children.push(react.createElement("div", {
|
|
185
|
+
style: styles.locator,
|
|
186
|
+
key: "l"
|
|
187
|
+
}, fold.locator));
|
|
188
|
+
if (original !== null) children.push(react.createElement("pre", {
|
|
189
|
+
style: styles.originalPre,
|
|
190
|
+
key: "o"
|
|
191
|
+
}, original));
|
|
192
|
+
} else if (!fold.recoverable) children.push(react.createElement("div", {
|
|
193
|
+
style: styles.notRecoverable,
|
|
194
|
+
key: "w"
|
|
195
|
+
}, "No recovery path: the original is in the session log but no tool exposes it."));
|
|
196
|
+
return react.createElement("details", {
|
|
197
|
+
style: styles.fold,
|
|
198
|
+
onToggle
|
|
199
|
+
}, ...children);
|
|
200
|
+
}
|
|
201
|
+
/** The per-fold list. */
|
|
202
|
+
function FoldList(props) {
|
|
203
|
+
const { report, sessionId } = props;
|
|
204
|
+
const heading = react.createElement("div", {
|
|
205
|
+
style: styles.heading,
|
|
206
|
+
key: "h"
|
|
207
|
+
}, `Folded content (${String(report.folds.length)})`);
|
|
208
|
+
if (report.folds.length === 0) return react.createElement("section", null, heading, react.createElement("div", {
|
|
209
|
+
style: styles.muted,
|
|
210
|
+
key: "e"
|
|
211
|
+
}, "Nothing has been folded in this session yet."));
|
|
212
|
+
return react.createElement("section", null, heading, ...report.folds.map((fold) => react.createElement(FoldItem, {
|
|
213
|
+
key: String(fold.seq),
|
|
214
|
+
sessionId,
|
|
215
|
+
fold
|
|
216
|
+
})));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The tab body.
|
|
220
|
+
*
|
|
221
|
+
* The active session id arrives through the standard slot props, and the report
|
|
222
|
+
* is refetched whenever that id changes because the tab outlives navigation.
|
|
223
|
+
*/
|
|
224
|
+
function ContextFoldTab(props) {
|
|
225
|
+
const sessionId = sessionIdOf(props);
|
|
226
|
+
const [state, setState] = react.useState({ status: "loading" });
|
|
227
|
+
react.useEffect(() => {
|
|
228
|
+
if (sessionId === void 0) {
|
|
229
|
+
setState({ status: "empty" });
|
|
230
|
+
return;
|
|
170
231
|
}
|
|
171
|
-
|
|
232
|
+
let cancelled = false;
|
|
233
|
+
setState({ status: "loading" });
|
|
234
|
+
fetchReport(sessionId).then((report) => {
|
|
235
|
+
if (cancelled) return;
|
|
236
|
+
setState(report === void 0 ? { status: "empty" } : {
|
|
237
|
+
status: "ready",
|
|
238
|
+
report
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
return () => {
|
|
242
|
+
cancelled = true;
|
|
243
|
+
};
|
|
244
|
+
}, [sessionId]);
|
|
245
|
+
const children = [react.createElement("div", {
|
|
246
|
+
style: styles.title,
|
|
247
|
+
key: "title"
|
|
248
|
+
}, "Context fold")];
|
|
249
|
+
if (sessionId === void 0) children.push(react.createElement("div", {
|
|
250
|
+
style: styles.muted,
|
|
251
|
+
key: "m"
|
|
252
|
+
}, "No active session."));
|
|
253
|
+
else if (state.status === "loading") children.push(react.createElement("div", {
|
|
254
|
+
style: styles.muted,
|
|
255
|
+
key: "m"
|
|
256
|
+
}, "Loading…"));
|
|
257
|
+
else if (state.status !== "ready" || state.report === void 0) children.push(react.createElement("div", {
|
|
258
|
+
style: styles.muted,
|
|
259
|
+
key: "m"
|
|
260
|
+
}, "No report available for this session."));
|
|
261
|
+
else {
|
|
262
|
+
children.push(react.createElement(Summary, {
|
|
263
|
+
key: "summary",
|
|
264
|
+
report: state.report
|
|
265
|
+
}));
|
|
266
|
+
children.push(react.createElement(FoldList, {
|
|
267
|
+
key: "folds",
|
|
268
|
+
sessionId,
|
|
269
|
+
report: state.report
|
|
270
|
+
}));
|
|
172
271
|
}
|
|
173
|
-
return
|
|
272
|
+
return react.createElement("div", {
|
|
273
|
+
className: "context-fold-tab",
|
|
274
|
+
style: styles.root
|
|
275
|
+
}, ...children);
|
|
174
276
|
}
|
|
175
277
|
/** Client plugin name. */
|
|
176
278
|
const name = "context-fold-client";
|
|
@@ -179,14 +281,39 @@ const inject = ["slots", "locale"];
|
|
|
179
281
|
/**
|
|
180
282
|
* Mount the conversation tab.
|
|
181
283
|
*
|
|
284
|
+
* Dictionaries are registered from inside this bundle: the locale service reads
|
|
285
|
+
* them from the plugin registry, not from `locale/*.json` on disk.
|
|
286
|
+
*
|
|
182
287
|
* @param ctx - client plugin context.
|
|
183
288
|
*/
|
|
184
289
|
function apply(ctx) {
|
|
290
|
+
const registerDictionaries = () => {
|
|
291
|
+
ctx.locale.register(NS, {
|
|
292
|
+
zh,
|
|
293
|
+
en
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
if (typeof ctx.effect === "function") ctx.effect(registerDictionaries, "context-fold: dictionaries");
|
|
297
|
+
else registerDictionaries();
|
|
298
|
+
const t = (key) => {
|
|
299
|
+
try {
|
|
300
|
+
return ctx.locale.bind(NS)(key) || (en[key] ?? key);
|
|
301
|
+
} catch {
|
|
302
|
+
return en[key] ?? key;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
185
305
|
ctx.slots.inject("conversation.view", () => ctx.slots.register({
|
|
186
306
|
name: "conversation.view",
|
|
187
307
|
id: "context-fold",
|
|
188
308
|
order: 40,
|
|
189
|
-
|
|
190
|
-
|
|
309
|
+
locale: NS,
|
|
310
|
+
label: () => t("tab.contextFold")
|
|
311
|
+
}, ContextFoldTab));
|
|
191
312
|
}
|
|
192
|
-
|
|
313
|
+
exports.apply = apply;
|
|
314
|
+
exports.inject = inject;
|
|
315
|
+
exports.name = name;
|
|
316
|
+
|
|
317
|
+
return module.exports;
|
|
318
|
+
},
|
|
319
|
+
});
|
package/locale/en.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "Context Fold (dsh-context-fold)",
|
|
4
|
-
"description": "Stage-boundary folding of completed tool results and historical reasoning: conclusions stay in the window, full text moves to a spill file, and /context-fold reports savings and re-reads."
|
|
5
|
-
},
|
|
6
|
-
"tab": {
|
|
7
|
-
"contextFold": "Context fold"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Context Fold (dsh-context-fold)",
|
|
4
|
+
"description": "Stage-boundary folding of completed tool results and historical reasoning: conclusions stay in the window, full text moves to a spill file, and /context-fold reports savings and re-reads."
|
|
5
|
+
},
|
|
6
|
+
"tab": {
|
|
7
|
+
"contextFold": "Context fold"
|
|
8
|
+
}
|
|
9
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "上下文折叠 (dsh-context-fold)",
|
|
4
|
-
"description": "阶段边界的 tool 结果与历史 reasoning 折叠:结论留在窗口里,正文落到 spill 文件,用 /context-fold 报告折叠量与被重读次数。"
|
|
5
|
-
},
|
|
6
|
-
"tab": {
|
|
7
|
-
"contextFold": "上下文折叠"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "上下文折叠 (dsh-context-fold)",
|
|
4
|
+
"description": "阶段边界的 tool 结果与历史 reasoning 折叠:结论留在窗口里,正文落到 spill 文件,用 /context-fold 报告折叠量与被重读次数。"
|
|
5
|
+
},
|
|
6
|
+
"tab": {
|
|
7
|
+
"contextFold": "上下文折叠"
|
|
8
|
+
}
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context-fold",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "dsh-context-fold: stage-boundary folding of completed tool results into a conclusion plus a spill path, deterministic and replay-safe.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -35,6 +35,13 @@
|
|
|
35
35
|
"dsh": {
|
|
36
36
|
"bundle": {
|
|
37
37
|
"patch": "./cordis.patch.yml"
|
|
38
|
+
},
|
|
39
|
+
"client": {
|
|
40
|
+
"platform": "web",
|
|
41
|
+
"inject": [
|
|
42
|
+
"@deepseek-ai/dsh-client-locale",
|
|
43
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
44
|
+
]
|
|
38
45
|
}
|
|
39
46
|
},
|
|
40
47
|
"peerDependencies": {
|