dsh-context-fold 0.1.0 → 0.1.2
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 +289 -136
- package/lib/index.js +7 -6
- 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,14 +1,42 @@
|
|
|
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
|
|
2
|
-
/**
|
|
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");
|
|
15
|
+
/**
|
|
16
|
+
* Fetch the report for one session.
|
|
17
|
+
*
|
|
18
|
+
* Failures are reported rather than swallowed: before the routes existed the
|
|
19
|
+
* tab rendered "no report available", which reads like "this session folded
|
|
20
|
+
* nothing" instead of "the request never landed".
|
|
21
|
+
*
|
|
22
|
+
* @param sessionId - session to report on.
|
|
23
|
+
* @returns the payload, or a message describing why there is none.
|
|
24
|
+
*/
|
|
3
25
|
async function fetchReport(sessionId) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
26
|
+
let response;
|
|
27
|
+
try {
|
|
28
|
+
response = await fetch("/api/context-fold/report", {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "content-type": "application/json" },
|
|
31
|
+
body: JSON.stringify({ sessionId })
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return { error: `request failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
35
|
+
}
|
|
36
|
+
const body = await response.json().catch(() => void 0);
|
|
37
|
+
if (!response.ok) return { error: body?.error ?? `HTTP ${String(response.status)}` };
|
|
38
|
+
if (body?.ok !== true || body.value === void 0) return { error: body?.error ?? "the server returned no value" };
|
|
39
|
+
return { report: body.value };
|
|
12
40
|
}
|
|
13
41
|
/** Fetch the full text behind one fold. */
|
|
14
42
|
async function fetchOriginal(sessionId, locator) {
|
|
@@ -33,48 +61,97 @@ function signed(value) {
|
|
|
33
61
|
const rounded = Math.round(value * 10) / 10;
|
|
34
62
|
return `${rounded > 0 ? "+" : ""}${num(rounded)}`;
|
|
35
63
|
}
|
|
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;
|
|
64
|
+
/** Read the active session id out of the slot props. */
|
|
65
|
+
function sessionIdOf(props) {
|
|
66
|
+
const value = props?.sessionId;
|
|
67
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
69
68
|
}
|
|
69
|
+
/** Inline styles, kept as plain objects because no CSS module ships here. */
|
|
70
|
+
const styles = {
|
|
71
|
+
root: {
|
|
72
|
+
padding: "12px",
|
|
73
|
+
font: "13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace",
|
|
74
|
+
overflow: "auto",
|
|
75
|
+
height: "100%"
|
|
76
|
+
},
|
|
77
|
+
title: {
|
|
78
|
+
fontWeight: 600,
|
|
79
|
+
marginBottom: "8px"
|
|
80
|
+
},
|
|
81
|
+
muted: { color: "#888" },
|
|
82
|
+
box: {
|
|
83
|
+
marginBottom: "12px",
|
|
84
|
+
padding: "8px",
|
|
85
|
+
border: "1px solid #333",
|
|
86
|
+
borderRadius: "6px"
|
|
87
|
+
},
|
|
88
|
+
heading: {
|
|
89
|
+
fontWeight: 600,
|
|
90
|
+
marginBottom: "6px"
|
|
91
|
+
},
|
|
92
|
+
table: { borderCollapse: "collapse" },
|
|
93
|
+
labelCell: {
|
|
94
|
+
padding: "1px 12px 1px 0",
|
|
95
|
+
color: "#aaa"
|
|
96
|
+
},
|
|
97
|
+
warning: {
|
|
98
|
+
marginTop: "6px",
|
|
99
|
+
color: "#facc15"
|
|
100
|
+
},
|
|
101
|
+
error: {
|
|
102
|
+
marginTop: "6px",
|
|
103
|
+
color: "#f87171"
|
|
104
|
+
},
|
|
105
|
+
reread: {
|
|
106
|
+
marginTop: "6px",
|
|
107
|
+
color: "#f87171"
|
|
108
|
+
},
|
|
109
|
+
fold: {
|
|
110
|
+
marginBottom: "6px",
|
|
111
|
+
padding: "6px",
|
|
112
|
+
border: "1px solid #2a2a2a",
|
|
113
|
+
borderRadius: "6px"
|
|
114
|
+
},
|
|
115
|
+
foldSummary: { cursor: "pointer" },
|
|
116
|
+
inlinePre: {
|
|
117
|
+
whiteSpace: "pre-wrap",
|
|
118
|
+
margin: "6px 0",
|
|
119
|
+
color: "#bbb",
|
|
120
|
+
maxHeight: "12em",
|
|
121
|
+
overflow: "auto"
|
|
122
|
+
},
|
|
123
|
+
originalPre: {
|
|
124
|
+
whiteSpace: "pre-wrap",
|
|
125
|
+
margin: "6px 0",
|
|
126
|
+
color: "#ddd",
|
|
127
|
+
maxHeight: "24em",
|
|
128
|
+
overflow: "auto",
|
|
129
|
+
borderTop: "1px dashed #333",
|
|
130
|
+
paddingTop: "6px"
|
|
131
|
+
},
|
|
132
|
+
locator: {
|
|
133
|
+
color: "#666",
|
|
134
|
+
fontSize: "11px",
|
|
135
|
+
wordBreak: "break-all"
|
|
136
|
+
},
|
|
137
|
+
notRecoverable: {
|
|
138
|
+
color: "#f87171",
|
|
139
|
+
fontSize: "11px"
|
|
140
|
+
},
|
|
141
|
+
detailsToggle: {
|
|
142
|
+
cursor: "pointer",
|
|
143
|
+
color: "#888",
|
|
144
|
+
marginTop: "6px"
|
|
145
|
+
},
|
|
146
|
+
assumptionList: {
|
|
147
|
+
margin: "4px 0 0 16px",
|
|
148
|
+
padding: 0,
|
|
149
|
+
color: "#999"
|
|
150
|
+
}
|
|
151
|
+
};
|
|
70
152
|
/** 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";
|
|
153
|
+
function Summary(props) {
|
|
154
|
+
const cf = props.report.counterfactual;
|
|
78
155
|
const rows = [
|
|
79
156
|
["Folded content, now", `${num(cf.tokensNow)} tokens`],
|
|
80
157
|
["If it had stayed unfolded", `${num(cf.tokensIfUnfolded)} tokens`],
|
|
@@ -84,93 +161,144 @@ function renderSummary(report) {
|
|
|
84
161
|
["Prefix invalidation cost", signed(-cf.invalidationCost)],
|
|
85
162
|
["Net", signed(cf.netSaving)]
|
|
86
163
|
];
|
|
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;
|
|
164
|
+
return react.createElement("section", { style: styles.box }, react.createElement("div", {
|
|
165
|
+
style: styles.heading,
|
|
166
|
+
key: "h"
|
|
167
|
+
}, "Token comparison (estimate)"), react.createElement("table", {
|
|
168
|
+
style: styles.table,
|
|
169
|
+
key: "t"
|
|
170
|
+
}, ...rows.map(([label, value]) => react.createElement("tr", { key: label }, react.createElement("td", { style: styles.labelCell }, label), react.createElement("td", label === "Net" ? { style: {
|
|
171
|
+
fontWeight: 600,
|
|
172
|
+
color: cf.netSaving >= 0 ? "#4ade80" : "#f87171"
|
|
173
|
+
} } : null, value)))), react.createElement("div", {
|
|
174
|
+
style: styles.warning,
|
|
175
|
+
key: "f"
|
|
176
|
+
}, 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", {
|
|
177
|
+
style: styles.reread,
|
|
178
|
+
key: "r"
|
|
179
|
+
}, `Re-read signals: ${String(props.report.reReads)} — folded content was fetched again after being folded.`) : null);
|
|
124
180
|
}
|
|
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
|
-
|
|
181
|
+
/** One fold row; the original text loads when the row is opened. */
|
|
182
|
+
function FoldItem(props) {
|
|
183
|
+
const { fold, sessionId } = props;
|
|
184
|
+
const [original, setOriginal] = react.useState(null);
|
|
185
|
+
const onToggle = (event) => {
|
|
186
|
+
if (event.currentTarget?.open !== true || original !== null) return;
|
|
187
|
+
const locator = fold.locator;
|
|
188
|
+
if (locator === void 0) return;
|
|
189
|
+
setOriginal("");
|
|
190
|
+
fetchOriginal(sessionId, locator).then((text) => {
|
|
191
|
+
setOriginal(text ?? "(could not read the stored original)");
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
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"}`;
|
|
195
|
+
const children = [react.createElement("summary", {
|
|
196
|
+
style: styles.foldSummary,
|
|
197
|
+
key: "s"
|
|
198
|
+
}, summary), react.createElement("pre", {
|
|
199
|
+
style: styles.inlinePre,
|
|
200
|
+
key: "i"
|
|
201
|
+
}, fold.inline)];
|
|
202
|
+
if (fold.locator !== void 0) {
|
|
203
|
+
children.push(react.createElement("div", {
|
|
204
|
+
style: styles.locator,
|
|
205
|
+
key: "l"
|
|
206
|
+
}, fold.locator));
|
|
207
|
+
if (original !== null) children.push(react.createElement("pre", {
|
|
208
|
+
style: styles.originalPre,
|
|
209
|
+
key: "o"
|
|
210
|
+
}, original));
|
|
211
|
+
} else if (!fold.recoverable) children.push(react.createElement("div", {
|
|
212
|
+
style: styles.notRecoverable,
|
|
213
|
+
key: "w"
|
|
214
|
+
}, "No recovery path: the original is in the session log but no tool exposes it."));
|
|
215
|
+
return react.createElement("details", {
|
|
216
|
+
style: styles.fold,
|
|
217
|
+
onToggle
|
|
218
|
+
}, ...children);
|
|
219
|
+
}
|
|
220
|
+
/** The per-fold list. */
|
|
221
|
+
function FoldList(props) {
|
|
222
|
+
const { report, sessionId } = props;
|
|
223
|
+
const heading = react.createElement("div", {
|
|
224
|
+
style: styles.heading,
|
|
225
|
+
key: "h"
|
|
226
|
+
}, `Folded content (${String(report.folds.length)})`);
|
|
227
|
+
if (report.folds.length === 0) return react.createElement("section", null, heading, react.createElement("div", {
|
|
228
|
+
style: styles.muted,
|
|
229
|
+
key: "e"
|
|
230
|
+
}, "Nothing has been folded in this session yet."));
|
|
231
|
+
return react.createElement("section", null, heading, ...report.folds.map((fold) => react.createElement(FoldItem, {
|
|
232
|
+
key: String(fold.seq),
|
|
233
|
+
sessionId,
|
|
234
|
+
fold
|
|
235
|
+
})));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The tab body.
|
|
239
|
+
*
|
|
240
|
+
* The active session id arrives through the standard slot props, and the report
|
|
241
|
+
* is refetched whenever that id changes because the tab outlives navigation.
|
|
242
|
+
*/
|
|
243
|
+
function ContextFoldTab(props) {
|
|
244
|
+
const sessionId = sessionIdOf(props);
|
|
245
|
+
const [state, setState] = react.useState({ status: "loading" });
|
|
246
|
+
react.useEffect(() => {
|
|
247
|
+
if (sessionId === void 0) {
|
|
248
|
+
setState({ status: "empty" });
|
|
249
|
+
return;
|
|
170
250
|
}
|
|
171
|
-
|
|
251
|
+
let cancelled = false;
|
|
252
|
+
setState({ status: "loading" });
|
|
253
|
+
fetchReport(sessionId).then((result) => {
|
|
254
|
+
if (cancelled) return;
|
|
255
|
+
setState("report" in result ? {
|
|
256
|
+
status: "ready",
|
|
257
|
+
report: result.report
|
|
258
|
+
} : {
|
|
259
|
+
status: "error",
|
|
260
|
+
error: result.error
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
return () => {
|
|
264
|
+
cancelled = true;
|
|
265
|
+
};
|
|
266
|
+
}, [sessionId]);
|
|
267
|
+
const children = [react.createElement("div", {
|
|
268
|
+
style: styles.title,
|
|
269
|
+
key: "title"
|
|
270
|
+
}, "Context fold")];
|
|
271
|
+
if (sessionId === void 0) children.push(react.createElement("div", {
|
|
272
|
+
style: styles.muted,
|
|
273
|
+
key: "m"
|
|
274
|
+
}, "No active session."));
|
|
275
|
+
else if (state.status === "loading") children.push(react.createElement("div", {
|
|
276
|
+
style: styles.muted,
|
|
277
|
+
key: "m"
|
|
278
|
+
}, "Loading…"));
|
|
279
|
+
else if (state.status === "error") children.push(react.createElement("div", {
|
|
280
|
+
style: styles.error,
|
|
281
|
+
key: "e"
|
|
282
|
+
}, `Could not load the report: ${state.error ?? "unknown"}`));
|
|
283
|
+
else if (state.status !== "ready" || state.report === void 0) children.push(react.createElement("div", {
|
|
284
|
+
style: styles.muted,
|
|
285
|
+
key: "m"
|
|
286
|
+
}, "This session has no folds to report."));
|
|
287
|
+
else {
|
|
288
|
+
children.push(react.createElement(Summary, {
|
|
289
|
+
key: "summary",
|
|
290
|
+
report: state.report
|
|
291
|
+
}));
|
|
292
|
+
children.push(react.createElement(FoldList, {
|
|
293
|
+
key: "folds",
|
|
294
|
+
sessionId,
|
|
295
|
+
report: state.report
|
|
296
|
+
}));
|
|
172
297
|
}
|
|
173
|
-
return
|
|
298
|
+
return react.createElement("div", {
|
|
299
|
+
className: "context-fold-tab",
|
|
300
|
+
style: styles.root
|
|
301
|
+
}, ...children);
|
|
174
302
|
}
|
|
175
303
|
/** Client plugin name. */
|
|
176
304
|
const name = "context-fold-client";
|
|
@@ -179,14 +307,39 @@ const inject = ["slots", "locale"];
|
|
|
179
307
|
/**
|
|
180
308
|
* Mount the conversation tab.
|
|
181
309
|
*
|
|
310
|
+
* Dictionaries are registered from inside this bundle: the locale service reads
|
|
311
|
+
* them from the plugin registry, not from `locale/*.json` on disk.
|
|
312
|
+
*
|
|
182
313
|
* @param ctx - client plugin context.
|
|
183
314
|
*/
|
|
184
315
|
function apply(ctx) {
|
|
316
|
+
const registerDictionaries = () => {
|
|
317
|
+
ctx.locale.register(NS, {
|
|
318
|
+
zh,
|
|
319
|
+
en
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
if (typeof ctx.effect === "function") ctx.effect(registerDictionaries, "context-fold: dictionaries");
|
|
323
|
+
else registerDictionaries();
|
|
324
|
+
const t = (key) => {
|
|
325
|
+
try {
|
|
326
|
+
return ctx.locale.bind(NS)(key) || (en[key] ?? key);
|
|
327
|
+
} catch {
|
|
328
|
+
return en[key] ?? key;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
185
331
|
ctx.slots.inject("conversation.view", () => ctx.slots.register({
|
|
186
332
|
name: "conversation.view",
|
|
187
333
|
id: "context-fold",
|
|
188
334
|
order: 40,
|
|
189
|
-
|
|
190
|
-
|
|
335
|
+
locale: NS,
|
|
336
|
+
label: () => t("tab.contextFold")
|
|
337
|
+
}, ContextFoldTab));
|
|
191
338
|
}
|
|
192
|
-
|
|
339
|
+
exports.apply = apply;
|
|
340
|
+
exports.inject = inject;
|
|
341
|
+
exports.name = name;
|
|
342
|
+
|
|
343
|
+
return module.exports;
|
|
344
|
+
},
|
|
345
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1525,11 +1525,12 @@ function json(value, status = 200) {
|
|
|
1525
1525
|
/**
|
|
1526
1526
|
* Register the two read-only routes the tab uses.
|
|
1527
1527
|
*
|
|
1528
|
-
* @param
|
|
1528
|
+
* @param connection - the host `connection` service (its `fetch.register` is the route registrar).
|
|
1529
1529
|
* @param deps - session and spill access.
|
|
1530
1530
|
* @returns a disposer for both routes.
|
|
1531
1531
|
*/
|
|
1532
|
-
function registerRoutes(
|
|
1532
|
+
function registerRoutes(connection, deps) {
|
|
1533
|
+
const register = connection.fetch.register.bind(connection.fetch);
|
|
1533
1534
|
const report = register({
|
|
1534
1535
|
path: "/api/context-fold/report",
|
|
1535
1536
|
methods: ["POST"],
|
|
@@ -1720,18 +1721,18 @@ function apply(ctx, rawConfig = {}) {
|
|
|
1720
1721
|
});
|
|
1721
1722
|
ctx.inject(["connection"], (scope) => {
|
|
1722
1723
|
const connection = scope.connection;
|
|
1723
|
-
if (connection === void 0) {
|
|
1724
|
-
ctx.logger.warn("context-fold: no ctx.connection
|
|
1724
|
+
if (connection === void 0 || typeof connection.fetch?.register !== "function") {
|
|
1725
|
+
ctx.logger.warn("context-fold: no ctx.connection.fetch.register; the conversation tab has no data source");
|
|
1725
1726
|
return;
|
|
1726
1727
|
}
|
|
1727
1728
|
const tokenMeter = ctx.get("tokenMeter");
|
|
1728
|
-
registerRoutes(connection, {
|
|
1729
|
+
ctx.effect(() => registerRoutes(connection, {
|
|
1729
1730
|
sessionOf: (id) => {
|
|
1730
1731
|
return ctx.get("sessions")?.get(id);
|
|
1731
1732
|
},
|
|
1732
1733
|
estimateMessage: (message) => tokenMeter === void 0 ? 0 : tokenMeter.estimateMessage(message),
|
|
1733
1734
|
...ctx.get("spillStore") === void 0 ? {} : { spillStore: ctx.get("spillStore") }
|
|
1734
|
-
});
|
|
1735
|
+
}), "context-fold: conversation tab routes");
|
|
1735
1736
|
});
|
|
1736
1737
|
ctx.on("session/disposed", (session) => {
|
|
1737
1738
|
states.delete(session.header.id);
|
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.2",
|
|
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": {
|