dsh-claimdiff 0.0.0-stage → 0.1.0

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/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # ClaimDiff for DeepSeek Harness
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A DeepSeek Harness plugin: a `ClaimDiff` button on the document preview toolbar that opens the change guide for the session's git repository in the right sidebar.
4
+
5
+ `src/host.mjs` starts the loopback panel server from `packages/cli` for the session's working directory; `src/client.mjs` shows it in an iframe. Both are thin shells: the panel, the checking and the account UI are the same code every other host uses.
6
+
7
+ The installable package (`package.json`, `cordis.patch.yml`, `locale/`, `host.js`, `client.js`) is generated by `scripts/package-harness.mjs` into `dist/harness/dsh-claimdiff/`. Names, descriptions and keywords come from `listing.json`.
package/client.js ADDED
@@ -0,0 +1,210 @@
1
+ window.__ModuleLoader__.load({ id: "dsh-claimdiff", factory: require => { const module = { exports: {} }; const exports = module.exports;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // packages/harness/src/client.mjs
22
+ var client_exports = {};
23
+ __export(client_exports, {
24
+ apply: () => apply,
25
+ inject: () => inject
26
+ });
27
+ module.exports = __toCommonJS(client_exports);
28
+ var import_react = require("react");
29
+
30
+ // packages/harness/src/shared.mjs
31
+ var packageName = true ? "dsh-claimdiff" : "dsh-claimdiff";
32
+ var kind = "claimdiff-guide";
33
+ var actionSlot = "sidebar.right.tab.document.actions";
34
+ var bodySlot = "sidebar.right.pane.tab";
35
+ var route = "/claimdiff-harness/session";
36
+ var prefix = "dsh-resource://file/session/";
37
+ function fileAddress(sessionId, absolutePath) {
38
+ const path = /^(?:[A-Z]:[\\/]|\\\\)/i.test(absolutePath) ? absolutePath.replaceAll("\\", "/") : absolutePath;
39
+ return prefix + encodeURIComponent(sessionId) + "/" + path.split("/").map(encodeURIComponent).join("/");
40
+ }
41
+ function selectedSession(address) {
42
+ if (typeof address !== "string" || !address.startsWith(prefix)) return;
43
+ try {
44
+ const sessionId = decodeURIComponent(address.slice(prefix.length).split("/")[0]);
45
+ if (sessionId) return { sessionId };
46
+ } catch {
47
+ }
48
+ }
49
+ var PANEL_URL = /^http:\/\/127\.0\.0\.1:\d+\/\?t=[A-Za-z0-9_-]{16,}$/;
50
+
51
+ // packages/harness/src/client.mjs
52
+ var inject = ["slots", "sidebarRight", "sidebarRightTabs"];
53
+ var zh = () => {
54
+ const docLang = typeof document !== "undefined" ? document.documentElement?.lang || "" : "";
55
+ const navLang = typeof navigator !== "undefined" ? navigator.language || "" : "";
56
+ return /^zh(?:[-_.]|$)/i.test(docLang || navLang);
57
+ };
58
+ var label = () => zh() ? "\u7528 ClaimDiff \u6838\u5BF9 AI \u7684\u6539\u52A8" : "Review the agent's changes in ClaimDiff";
59
+ var desktop = () => location.protocol === "dsh-app:" && location.hostname === "app";
60
+ var actionClass = "claimdiff-harness-open";
61
+ var LEASE_RENEW_MS = 5 * 6e4;
62
+ var request = (method, body) => fetch(route, {
63
+ method,
64
+ headers: { "content-type": "application/json" },
65
+ body: JSON.stringify(body),
66
+ keepalive: method === "DELETE"
67
+ });
68
+ function apply(ctx) {
69
+ const sessions = /* @__PURE__ */ new Map();
70
+ function session(tab) {
71
+ if (sessions.has(tab.signal)) return sessions.get(tab.signal).opened;
72
+ if (tab.signal.aborted) return Promise.reject(new Error("Closed ClaimDiff tab"));
73
+ const opened = request("POST", { address: tab.contentId }).then(async (response) => {
74
+ if (!response.ok) throw new Error("ClaimDiff panel is unavailable");
75
+ const data = await response.json();
76
+ if (typeof data.lease !== "string" || typeof data.url !== "string" || !PANEL_URL.test(data.url)) {
77
+ throw new Error("Invalid ClaimDiff panel address");
78
+ }
79
+ return data;
80
+ });
81
+ const renewal = setInterval(() => {
82
+ void opened.then(({ lease }) => request("POST", { action: "renew", lease })).catch(() => {
83
+ });
84
+ }, LEASE_RENEW_MS);
85
+ void opened.catch(() => {
86
+ clearInterval(renewal);
87
+ tab.signal.removeEventListener("abort", release);
88
+ sessions.delete(tab.signal);
89
+ });
90
+ function release() {
91
+ clearInterval(renewal);
92
+ tab.signal.removeEventListener("abort", release);
93
+ sessions.delete(tab.signal);
94
+ void opened.then(({ lease }) => request("DELETE", { lease })).catch(() => {
95
+ });
96
+ }
97
+ sessions.set(tab.signal, { opened, release });
98
+ tab.signal.addEventListener("abort", release, { once: true });
99
+ return opened;
100
+ }
101
+ function OpenAction({ absolutePath }) {
102
+ if (typeof absolutePath !== "string" || !absolutePath || !desktop() && !["127.0.0.1", "[::1]", "localhost"].includes(location.hostname)) return null;
103
+ return (0, import_react.createElement)("button", {
104
+ type: "button",
105
+ className: actionClass,
106
+ title: label(),
107
+ "aria-label": label(),
108
+ onClick(event) {
109
+ const sessionId = ctx.sidebarRight.mounted.getSnapshot();
110
+ if (!sessionId) return;
111
+ const target = ctx.sidebarRight.focusedTarget(event.currentTarget);
112
+ const paneId = target?.host === "dock" ? target.paneId : void 0;
113
+ ctx.sidebarRight.openResource(fileAddress(sessionId, absolutePath), { kind, paneId, preferNewPane: true });
114
+ }
115
+ }, "ClaimDiff");
116
+ }
117
+ function PanelBody({ useTabInfo }) {
118
+ const { tab } = useTabInfo();
119
+ const [view, setView] = (0, import_react.useState)({});
120
+ const frame = (0, import_react.useRef)(null);
121
+ (0, import_react.useEffect)(() => {
122
+ let mounted = true;
123
+ void session(tab).then(
124
+ ({ url }) => {
125
+ if (mounted) setView({ signal: tab.signal, url });
126
+ },
127
+ () => {
128
+ if (mounted) setView({ signal: tab.signal, failed: true });
129
+ }
130
+ );
131
+ return () => {
132
+ mounted = false;
133
+ };
134
+ }, [tab.signal, tab.contentId]);
135
+ (0, import_react.useEffect)(() => {
136
+ if (!desktop() || view.signal !== tab.signal || !view.url) return;
137
+ const origin = new URL(view.url).origin;
138
+ function openExternal(event) {
139
+ const { source, data } = event;
140
+ if (!source || source !== frame.current?.contentWindow || event.origin !== origin || data?.type !== "claimdiff:open-external" || typeof data.id !== "string" || tab.signal.aborted) return;
141
+ let ok = false;
142
+ try {
143
+ if (typeof data.url === "string" && new URL(data.url).protocol === "https:") {
144
+ window.open(data.url, "_blank", "noopener,noreferrer");
145
+ ok = true;
146
+ }
147
+ } catch {
148
+ }
149
+ source.postMessage({ type: "claimdiff:open-external", id: data.id, ok }, origin);
150
+ }
151
+ window.addEventListener("message", openExternal);
152
+ return () => window.removeEventListener("message", openExternal);
153
+ }, [tab.signal, view]);
154
+ if (view.signal !== tab.signal || !view.url) {
155
+ const failed = view.signal === tab.signal && view.failed;
156
+ const message = failed ? zh() ? "\u65E0\u6CD5\u6253\u5F00\u5BFC\u8BFB\u3002\u8BF7\u5728\u672C\u673A\u7684 git \u4ED3\u5E93\u91CC\u4F7F\u7528 ClaimDiff\u3002" : "Could not open the guide. Use ClaimDiff in a local git repository." : zh() ? "\u6B63\u5728\u6253\u5F00 ClaimDiff\u2026" : "Opening ClaimDiff\u2026";
157
+ return (0, import_react.createElement)("p", { role: failed ? "alert" : "status", style: { padding: 16 } }, message);
158
+ }
159
+ return (0, import_react.createElement)("iframe", {
160
+ ref: frame,
161
+ src: desktop() ? `${view.url}&external=host` : view.url,
162
+ title: "ClaimDiff",
163
+ referrerPolicy: "no-referrer",
164
+ sandbox: "allow-scripts allow-forms allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox",
165
+ style: { display: "block", width: "100%", height: "100%", border: 0 }
166
+ });
167
+ }
168
+ ctx.effect(() => ctx.sidebarRightTabs.register({
169
+ id: packageName,
170
+ kind,
171
+ canOpen: (address) => !!selectedSession(address),
172
+ title: () => "ClaimDiff",
173
+ keepMounted: true
174
+ }), "ClaimDiff sidebar tab");
175
+ ctx.effect(() => ctx.slots.inject(actionSlot, () => ctx.slots.register({
176
+ name: actionSlot,
177
+ id: packageName
178
+ }, OpenAction)), "ClaimDiff entry");
179
+ ctx.effect(() => ctx.slots.inject(bodySlot, () => ctx.slots.register({
180
+ name: bodySlot,
181
+ key: packageName
182
+ }, PanelBody)), "ClaimDiff sidebar panel");
183
+ ctx.effect(() => {
184
+ const style = document.createElement("style");
185
+ style.textContent = `
186
+ .${actionClass} { display: inline-flex; align-items: center; gap: 5px; height: 26px;
187
+ padding: 0 9px; border: 1px solid color-mix(in srgb, currentColor 20%, transparent); border-radius: 6px;
188
+ background: color-mix(in srgb, currentColor 8%, transparent); color: inherit;
189
+ font: inherit; font-size: 12px; font-weight: 500; white-space: nowrap; cursor: pointer; }
190
+ .${actionClass}:hover { background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 14%, transparent)); }
191
+ .${actionClass}:focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
192
+ `;
193
+ document.head.append(style);
194
+ return () => style.remove();
195
+ }, "ClaimDiff entry style");
196
+ ctx.effect(() => {
197
+ const releaseAll = () => {
198
+ for (const { release } of sessions.values()) release();
199
+ };
200
+ const pageHidden = (event) => {
201
+ if (!event.persisted) releaseAll();
202
+ };
203
+ window.addEventListener("pagehide", pageHidden);
204
+ return () => {
205
+ window.removeEventListener("pagehide", pageHidden);
206
+ releaseAll();
207
+ };
208
+ }, "ClaimDiff tab sessions");
209
+ }
210
+ return module.exports; } });
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: claimdiff
3
+ name: dsh-claimdiff