dsh-git-desk 0.18.0 → 0.18.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.
Files changed (2) hide show
  1. package/client.js +70 -3
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -8,6 +8,50 @@ window.__ModuleLoader__.load({
8
8
  const NS = 'git';
9
9
  const GIT_TAB_ID = 'dsh-git';
10
10
 
11
+ const FILE_ADDRESS_PREFIX = 'dsh-resource://file/session/';
12
+ const isAbsoluteWorkspacePath = (path) =>
13
+ path.startsWith('/') || /^[A-Za-z]:[/\\]/.test(path) || path.startsWith('\\\\');
14
+ const encodeAddressPath = (path) =>
15
+ path
16
+ .replace(/\\/g, '/')
17
+ .replace(/^(?:\.\/)+/, '')
18
+ .split('/')
19
+ .map((segment) => encodeURIComponent(segment))
20
+ .join('/');
21
+ const sessionFileAddress = (sessionId, path) =>
22
+ `${FILE_ADDRESS_PREFIX}${encodeURIComponent(sessionId)}/${encodeAddressPath(path)}`;
23
+ /**
24
+ * The address for a path as the Git panel holds it, matching the harness util.
25
+ * @param {string} sessionId - the Session the path is read in.
26
+ * @param {string | undefined} cwd - that Session's workspace root.
27
+ * @param {string} path - absolute or workspace-relative path.
28
+ * @returns {string} the `dsh-resource://file/...` address.
29
+ */
30
+ function fileAddressFor(sessionId, cwd, path) {
31
+ const normalized = path.replace(/\\/g, '/');
32
+ if (!isAbsoluteWorkspacePath(normalized)) return sessionFileAddress(sessionId, normalized);
33
+ const root = cwd === undefined ? '' : cwd.replace(/\\/g, '/').replace(/\/+$/, '');
34
+ if (root !== '' && normalized === root) return sessionFileAddress(sessionId, '');
35
+ if (root !== '' && normalized.startsWith(`${root}/`)) {
36
+ return sessionFileAddress(sessionId, normalized.slice(root.length + 1));
37
+ }
38
+ return sessionFileAddress(sessionId, normalized);
39
+ }
40
+ /**
41
+ * The working-tree line of the first change in a diff.
42
+ * @param {{ rows?: Array<{ l: number | null, r: number | null, k: string }> }} diff - the diff.
43
+ * @returns {number} a 1-based line.
44
+ */
45
+ function openDiffLine(diff) {
46
+ const rows = diff?.rows ?? [];
47
+ const index = rows.findIndex((row) => row.k !== 'ctx');
48
+ if (index < 0) return 1;
49
+ for (let i = index; i < rows.length; i += 1) {
50
+ if (rows[i].r !== null && rows[i].r !== undefined) return rows[i].r;
51
+ }
52
+ return 1;
53
+ }
54
+
11
55
  const EN = {
12
56
  'panel': 'Git',
13
57
  'mode.changes': 'Changes',
@@ -47,6 +91,7 @@ window.__ModuleLoader__.load({
47
91
  'action.revertBlock': 'Revert block to the staged version',
48
92
  'action.refresh': 'Refresh',
49
93
  'action.back': 'Back to changes',
94
+ 'action.openEditor': 'Open in editor',
50
95
  'action.prevChange': 'Previous change',
51
96
  'action.nextChange': 'Next change',
52
97
  'action.close': 'Close',
@@ -282,6 +327,7 @@ window.__ModuleLoader__.load({
282
327
  'action.revertBlock': '将区块还原为已暂存版本',
283
328
  'action.refresh': '刷新',
284
329
  'action.back': '返回更改',
330
+ 'action.openEditor': '在编辑器中打开',
285
331
  'action.prevChange': '上一个更改',
286
332
  'action.nextChange': '下一个更改',
287
333
  'action.close': '关闭',
@@ -838,6 +884,7 @@ window.__ModuleLoader__.load({
838
884
  chevronUp: 'M6 15l6-6 6 6',
839
885
  sparkles: 'M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9zM18.5 15l.9 2.1 2.1.9-2.1.9-.9 2.1-.9-2.1-2.1-.9 2.1-.9z',
840
886
  file: 'M14 3H7a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V7zM14 3v4h4',
887
+ code: 'M8 7l-5 5 5 5M16 7l5 5-5 5',
841
888
  warning: 'M12 3l9 16H3zM12 9v5M12 17v.5',
842
889
  check: 'M5 12l5 5L20 7',
843
890
  folder: 'M3 6a1 1 0 0 1 1-1h5l2 2h8a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1z',
@@ -1550,6 +1597,7 @@ button[data-forge-header]{display:none}
1550
1597
  onRefresh,
1551
1598
  onBlock,
1552
1599
  onResolve,
1600
+ onOpen,
1553
1601
  message,
1554
1602
  onMessage,
1555
1603
  onCommit,
@@ -1944,6 +1992,7 @@ button[data-forge-header]{display:none}
1944
1992
  renamed: selection.renamed === true,
1945
1993
  compact,
1946
1994
  onBack,
1995
+ onOpen,
1947
1996
  })
1948
1997
  : h(Empty, {
1949
1998
  icon: h(Icon, { path: paths.file, size: 28 }),
@@ -1955,7 +2004,7 @@ button[data-forge-header]{display:none}
1955
2004
  );
1956
2005
  }
1957
2006
 
1958
- function DiffView({ t, diff, loading, layout, onLayout, onBlock, onResolve, busy, selectionKey, renamed, compact, onBack }) {
2007
+ function DiffView({ t, diff, loading, layout, onLayout, onBlock, onResolve, busy, selectionKey, renamed, compact, onBack, onOpen }) {
1959
2008
  const bodyRef = useRef(null);
1960
2009
  const [changeNav, setChangeNav] = useState({ index: -1, canPrev: false, canNext: false });
1961
2010
  const blocks = useMemo(() => {
@@ -2134,6 +2183,13 @@ button[data-forge-header]{display:none}
2134
2183
  h(
2135
2184
  'div',
2136
2185
  { className: 'gitp-diff-actions' },
2186
+ onOpen !== undefined && !diff.binary
2187
+ ? h(IconButton, {
2188
+ label: t('action.openEditor'),
2189
+ icon: paths.code,
2190
+ onClick: () => onOpen(diff),
2191
+ })
2192
+ : null,
2137
2193
  diff.conflict
2138
2194
  ? null
2139
2195
  : h(
@@ -3797,7 +3853,7 @@ button[data-forge-header]{display:none}
3797
3853
  );
3798
3854
  }
3799
3855
 
3800
- function GitPanel({ call, t, useWorkspaces, useSessions, sessionId, useTabInfo }) {
3856
+ function GitPanel({ call, t, useWorkspaces, useSessions, sessionId, useTabInfo, sidebarRight }) {
3801
3857
  const { tab } = useTabInfo();
3802
3858
  const reportVisible = visibilityOf(sessionId).set;
3803
3859
 
@@ -3871,6 +3927,16 @@ button[data-forge-header]{display:none}
3871
3927
  const [refreshToken, setRefreshToken] = useState(0);
3872
3928
  const [repos, setRepos] = useState([]);
3873
3929
  const [repoRoot, setRepoRoot] = useState(null);
3930
+ const openInEditor = (current) => {
3931
+ if (repoRoot === null || sidebarRight === undefined) return;
3932
+ const line = openDiffLine(current);
3933
+ const address = fileAddressFor(
3934
+ sessionId,
3935
+ session === undefined ? undefined : session.cwd,
3936
+ `${repoRoot}/${current.path}`,
3937
+ );
3938
+ sidebarRight.openResource(address, { params: { line } });
3939
+ };
3874
3940
  const [repoNonce, setRepoNonce] = useState(0);
3875
3941
  const [repoMenu, setRepoMenu] = useState(false);
3876
3942
  const [newBranchOpen, setNewBranchOpen] = useState(false);
@@ -4553,6 +4619,7 @@ button[data-forge-header]{display:none}
4553
4619
  },
4554
4620
  onBlock: blockAction,
4555
4621
  onResolve: resolve,
4622
+ onOpen: openInEditor,
4556
4623
  message,
4557
4624
  onMessage: setMessage,
4558
4625
  onCommit: doCommit,
@@ -5073,7 +5140,7 @@ button[data-forge-header]{display:none}
5073
5140
  name: 'sidebar.right.pane.tab',
5074
5141
  key: GIT_TAB_ID,
5075
5142
  locale: NS,
5076
- inject: () => ({ call, t }),
5143
+ inject: () => ({ call, t, sidebarRight: ctx.sidebarRight }),
5077
5144
  },
5078
5145
  GitPanel,
5079
5146
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-git-desk",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "type": "module",
5
5
  "description": "Git desk for DeepSeek Harness: a right-sidebar Git workbench with full-file side-by-side diffs, block staging, commits, history, branches, stash, and sync.",
6
6
  "keywords": [