@laoyuehanni/dsh-git-worktree 0.4.2 → 0.4.3
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 +10 -0
- package/README.zh.md +10 -0
- package/lib/client.js +171 -25
- package/lib/client.js.map +1 -1
- package/lib/git.d.ts +12 -2
- package/lib/git.js +22 -10
- package/lib/routes.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,16 @@ dsh plugin --profile web add @laoyuehanni/dsh-git-worktree
|
|
|
49
49
|
|
|
50
50
|
> The package declares `dsh.bundle`, so `add` wires the plugin into the profile's layer stack automatically — no config editing needed. The compiled `lib/` ships in the npm tarball, so installs work out of the box without any build step. Requires the `web` profile (`dsh web`).
|
|
51
51
|
|
|
52
|
+
### From npm — dsh 0.1.2-alpha.x host
|
|
53
|
+
|
|
54
|
+
The `latest` line above tracks the stable host (rc series). If you run a dsh **0.1.2 alpha** host, install the dedicated compatibility build instead:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
dsh plugin --profile web add @laoyuehanni/dsh-git-worktree@dsh-alpha
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> `@dsh-alpha` is a dist-tag (not a literal version), so the registry resolves it to the latest compatibility build — currently `0.4.1-dsh-0.1.2-alpha.3`. Its peer range is pinned to `>=0.1.2-alpha.3 <0.2.0`, while the stable line stays on the rc peers: the two channels never get mixed by a plain `update`, and `dsh plugin update` keeps pulling from the matching channel only. Upgrading your host back to the stable line? Remove this package first, then install the default one from the section above.
|
|
61
|
+
|
|
52
62
|
### From a local directory (development)
|
|
53
63
|
|
|
54
64
|
```sh
|
package/README.zh.md
CHANGED
|
@@ -49,6 +49,16 @@ dsh plugin --profile web add @laoyuehanni/dsh-git-worktree
|
|
|
49
49
|
|
|
50
50
|
> 包声明了 `dsh.bundle`,`add` 会自动把插件挂进 profile 的层栈,无需手动改配置。编译产物 `lib/` 随 npm 包分发,安装开箱即用,无需任何构建步骤。需要 `web` profile(`dsh web`)。
|
|
51
51
|
|
|
52
|
+
### 从 npm 安装 —— dsh 0.1.2-alpha.x 宿主
|
|
53
|
+
|
|
54
|
+
上面的 `latest` 通道面向稳定宿主(rc 系列)。若你运行的是 dsh **0.1.2 alpha** 宿主,请改装专用兼容版本:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
dsh plugin --profile web add @laoyuehanni/dsh-git-worktree@dsh-alpha
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> `@dsh-alpha` 是 dist-tag(不是字面版本号),registry 会解析为最新的兼容构建——当前为 `0.4.1-dsh-0.1.2-alpha.3`。其 peer 范围锁定 `>=0.1.2-alpha.3 <0.2.0`,而稳定线保持在 rc peer 上:普通 `update` 不会把两条通道混装,`dsh plugin update` 也只会从对应通道拉取。宿主升回稳定线时,先移除此包,再按上一小节安装默认版本。
|
|
61
|
+
|
|
52
62
|
### 从本地目录安装(开发调试用)
|
|
53
63
|
|
|
54
64
|
```sh
|
package/lib/client.js
CHANGED
|
@@ -2768,6 +2768,110 @@ window.__ModuleLoader__.load({
|
|
|
2768
2768
|
localStorage.setItem(VIEW_STORAGE_KEY, JSON.stringify(prefs));
|
|
2769
2769
|
} catch {}
|
|
2770
2770
|
}
|
|
2771
|
+
/** localStorage key of the grouping switch's last-known value (browser-local). */
|
|
2772
|
+
const GROUP_BOOT_STORAGE_KEY = "dsh-git-worktree.sidebar.groupSidebar";
|
|
2773
|
+
/**
|
|
2774
|
+
* Read the grouping switch's last-known value. The seat mounts from this on
|
|
2775
|
+
* startup so the sidebar renders grouped IMMEDIATELY, without waiting for the
|
|
2776
|
+
* settings document to cross from the Host — the settings scope is the
|
|
2777
|
+
* authority and corrects a stale value once it lands. undefined = no record
|
|
2778
|
+
* (first visit; the composition default "on" is used).
|
|
2779
|
+
*/
|
|
2780
|
+
function loadGroupSidebarBoot() {
|
|
2781
|
+
if (typeof localStorage === "undefined") return void 0;
|
|
2782
|
+
try {
|
|
2783
|
+
const raw = localStorage.getItem(GROUP_BOOT_STORAGE_KEY);
|
|
2784
|
+
if (raw === "1") return true;
|
|
2785
|
+
if (raw === "0") return false;
|
|
2786
|
+
return;
|
|
2787
|
+
} catch {
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
/** Persist the grouping switch's last-known value; write failures stay silent. */
|
|
2792
|
+
function saveGroupSidebarBoot(enabled) {
|
|
2793
|
+
if (typeof localStorage === "undefined") return;
|
|
2794
|
+
try {
|
|
2795
|
+
localStorage.setItem(GROUP_BOOT_STORAGE_KEY, enabled ? "1" : "0");
|
|
2796
|
+
} catch {}
|
|
2797
|
+
}
|
|
2798
|
+
/** localStorage key of the last successful /group facts batch (browser-local). */
|
|
2799
|
+
const FACTS_STORAGE_KEY = "dsh-git-worktree.sidebar.facts.v1";
|
|
2800
|
+
/** Parse one WorkspaceGitFacts value; undefined = malformed. */
|
|
2801
|
+
function parseWorkspaceGitFacts(value) {
|
|
2802
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
2803
|
+
const record = value;
|
|
2804
|
+
if (typeof record.repoRoot !== "string" || record.repoRoot === "") return void 0;
|
|
2805
|
+
if (typeof record.repoName !== "string") return void 0;
|
|
2806
|
+
if (record.branch !== null && typeof record.branch !== "string") return void 0;
|
|
2807
|
+
if (typeof record.main !== "boolean") return void 0;
|
|
2808
|
+
return {
|
|
2809
|
+
repoRoot: record.repoRoot,
|
|
2810
|
+
repoName: record.repoName,
|
|
2811
|
+
branch: record.branch,
|
|
2812
|
+
main: record.main
|
|
2813
|
+
};
|
|
2814
|
+
}
|
|
2815
|
+
/** Parse a facts map; any malformed entry discards the whole batch. */
|
|
2816
|
+
function parseFactsRecord(value) {
|
|
2817
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
2818
|
+
const out = {};
|
|
2819
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
2820
|
+
if (entry === null) {
|
|
2821
|
+
out[key] = null;
|
|
2822
|
+
continue;
|
|
2823
|
+
}
|
|
2824
|
+
const parsed = parseWorkspaceGitFacts(entry);
|
|
2825
|
+
if (parsed === void 0) return null;
|
|
2826
|
+
out[key] = parsed;
|
|
2827
|
+
}
|
|
2828
|
+
return out;
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* Read the last successful /group facts batch. The sidebar consults this
|
|
2832
|
+
* whenever the workspace path signature is known (including the frame the
|
|
2833
|
+
* pending-empty baseline becomes the real list), so a page refresh never
|
|
2834
|
+
* flashes the degraded flat list while git probes run; the fresh probe
|
|
2835
|
+
* overwrites both the view and this cache. A poisoned entry (wrong value
|
|
2836
|
+
* shape) discards the whole batch rather than grouping under `repo:undefined`.
|
|
2837
|
+
*/
|
|
2838
|
+
function loadFactsCache() {
|
|
2839
|
+
if (typeof localStorage === "undefined") return null;
|
|
2840
|
+
try {
|
|
2841
|
+
const raw = localStorage.getItem(FACTS_STORAGE_KEY);
|
|
2842
|
+
if (raw === null) return null;
|
|
2843
|
+
const parsed = JSON.parse(raw);
|
|
2844
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
2845
|
+
const record = parsed;
|
|
2846
|
+
if (typeof record.signature !== "string") return null;
|
|
2847
|
+
const facts = parseFactsRecord(record.facts);
|
|
2848
|
+
if (facts === null) return null;
|
|
2849
|
+
return {
|
|
2850
|
+
signature: record.signature,
|
|
2851
|
+
facts
|
|
2852
|
+
};
|
|
2853
|
+
} catch {
|
|
2854
|
+
return null;
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Pick the facts batch that belongs to `signature`. Live (in-memory) hits
|
|
2859
|
+
* win; otherwise a matching cache batch. The grouped tree must paint the
|
|
2860
|
+
* moment the workspace path set is known — not only at `useState` init,
|
|
2861
|
+
* when the list is still the pending empty snapshot (signature `""`).
|
|
2862
|
+
*/
|
|
2863
|
+
function factsForSignature(signature, live, cached) {
|
|
2864
|
+
if (live !== null && live.signature === signature) return live;
|
|
2865
|
+
if (cached !== null && cached.signature === signature) return cached;
|
|
2866
|
+
return null;
|
|
2867
|
+
}
|
|
2868
|
+
/** Persist one /group facts batch; write failures (quota, privacy mode) stay silent. */
|
|
2869
|
+
function saveFactsCache(entry) {
|
|
2870
|
+
if (typeof localStorage === "undefined") return;
|
|
2871
|
+
try {
|
|
2872
|
+
localStorage.setItem(FACTS_STORAGE_KEY, JSON.stringify(entry));
|
|
2873
|
+
} catch {}
|
|
2874
|
+
}
|
|
2771
2875
|
/** Recency comparator: newest first, id as the deterministic tiebreak. */
|
|
2772
2876
|
function byRecency(a, b) {
|
|
2773
2877
|
if (b.updatedAt !== a.updatedAt) return b.updatedAt - a.updatedAt;
|
|
@@ -4135,39 +4239,62 @@ window.__ModuleLoader__.load({
|
|
|
4135
4239
|
const items = workspaces.items;
|
|
4136
4240
|
const home = host?.home;
|
|
4137
4241
|
const signature = (0, react.useMemo)(() => [...items].map((item) => item.path).sort().join("\n"), [items]);
|
|
4242
|
+
const cachedBatch = (0, react.useMemo)(() => loadFactsCache(), [signature]);
|
|
4138
4243
|
const [factsState, setFactsState] = (0, react.useState)(null);
|
|
4244
|
+
const factsEntry = factsForSignature(signature, factsState, cachedBatch);
|
|
4245
|
+
const facts = factsEntry?.facts;
|
|
4246
|
+
const hasFactsForSignature = factsEntry !== null;
|
|
4139
4247
|
const readyOnce = (0, react.useRef)(false);
|
|
4140
4248
|
const signalReady = () => {
|
|
4141
4249
|
if (readyOnce.current) return;
|
|
4142
4250
|
readyOnce.current = true;
|
|
4143
4251
|
props.onReady?.();
|
|
4144
4252
|
};
|
|
4253
|
+
/** Signatures this mount already sent a probe for (once per signature). */
|
|
4254
|
+
const probedSignature = (0, react.useRef)(void 0);
|
|
4145
4255
|
(0, react.useEffect)(() => {
|
|
4146
|
-
if (
|
|
4256
|
+
if (probedSignature.current === signature) {
|
|
4147
4257
|
signalReady();
|
|
4148
4258
|
return;
|
|
4149
4259
|
}
|
|
4260
|
+
if (items.length === 0) {
|
|
4261
|
+
if (workspaces.phase === "ready") {
|
|
4262
|
+
probedSignature.current = signature;
|
|
4263
|
+
signalReady();
|
|
4264
|
+
}
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
4267
|
+
if (hasFactsForSignature) signalReady();
|
|
4150
4268
|
let live = true;
|
|
4151
4269
|
props.loadFacts(items.map((item) => item.path)).then((facts) => {
|
|
4152
4270
|
if (!live) return;
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4271
|
+
probedSignature.current = signature;
|
|
4272
|
+
if (facts !== void 0) {
|
|
4273
|
+
setFactsState({
|
|
4274
|
+
signature,
|
|
4275
|
+
facts
|
|
4276
|
+
});
|
|
4277
|
+
saveFactsCache({
|
|
4278
|
+
signature,
|
|
4279
|
+
facts
|
|
4280
|
+
});
|
|
4281
|
+
}
|
|
4157
4282
|
signalReady();
|
|
4158
4283
|
}, () => {
|
|
4159
|
-
if (live)
|
|
4284
|
+
if (!live) return;
|
|
4285
|
+
probedSignature.current = signature;
|
|
4286
|
+
signalReady();
|
|
4160
4287
|
});
|
|
4161
4288
|
return () => {
|
|
4162
4289
|
live = false;
|
|
4163
4290
|
};
|
|
4164
4291
|
}, [
|
|
4165
4292
|
signature,
|
|
4166
|
-
|
|
4293
|
+
items,
|
|
4167
4294
|
props.loadFacts,
|
|
4168
|
-
|
|
4295
|
+
workspaces.phase,
|
|
4296
|
+
hasFactsForSignature
|
|
4169
4297
|
]);
|
|
4170
|
-
const facts = factsState?.signature === signature ? factsState.facts : void 0;
|
|
4171
4298
|
const groups = (0, react.useMemo)(() => deriveSidebarGroups(items, facts), [items, facts]);
|
|
4172
4299
|
const sessionList = sessions;
|
|
4173
4300
|
const archived = workspaces.archivedSessionIds;
|
|
@@ -5368,26 +5495,13 @@ window.__ModuleLoader__.load({
|
|
|
5368
5495
|
}
|
|
5369
5496
|
});
|
|
5370
5497
|
};
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
const enabled = snapshot.value?.groupSidebar ?? true;
|
|
5375
|
-
if (enabled === groupingEnabled) return seatReady;
|
|
5376
|
-
groupingEnabled = enabled;
|
|
5377
|
-
if (groupingDisposer !== void 0) {
|
|
5378
|
-
groupingDisposer();
|
|
5379
|
-
groupingDisposer = void 0;
|
|
5380
|
-
}
|
|
5498
|
+
/** Inject the `sidebar.workspaces` occupant (priority -1 shadows the native
|
|
5499
|
+
* browser at priority 0) and arm its readiness epoch. */
|
|
5500
|
+
const registerGroupingSeat = () => {
|
|
5381
5501
|
const epoch = ++seatEpoch;
|
|
5382
5502
|
seatReady = new Promise((resolve) => {
|
|
5383
5503
|
seatReadyResolve = resolve;
|
|
5384
5504
|
});
|
|
5385
|
-
if (!enabled) {
|
|
5386
|
-
afterPaint().then(() => {
|
|
5387
|
-
if (epoch === seatEpoch) finishSeat();
|
|
5388
|
-
});
|
|
5389
|
-
return seatReady;
|
|
5390
|
-
}
|
|
5391
5505
|
const injectFace = () => ({
|
|
5392
5506
|
workspacesList: ctx.workspaces.list,
|
|
5393
5507
|
sessionsList: ctx.sessions.list,
|
|
@@ -5473,6 +5587,38 @@ window.__ModuleLoader__.load({
|
|
|
5473
5587
|
seatTimer = window.setTimeout(() => {
|
|
5474
5588
|
if (epoch === seatEpoch) finishSeat();
|
|
5475
5589
|
}, SEAT_READY_TIMEOUT_MS);
|
|
5590
|
+
};
|
|
5591
|
+
const syncGroupingSeat = () => {
|
|
5592
|
+
const snapshot = groupingScope.getSnapshot();
|
|
5593
|
+
if (snapshot.status !== "ready") {
|
|
5594
|
+
if (groupingEnabled === void 0) {
|
|
5595
|
+
groupingEnabled = loadGroupSidebarBoot() ?? true;
|
|
5596
|
+
if (groupingEnabled) registerGroupingSeat();
|
|
5597
|
+
}
|
|
5598
|
+
return seatReady;
|
|
5599
|
+
}
|
|
5600
|
+
const enabled = snapshot.value?.groupSidebar ?? true;
|
|
5601
|
+
if (enabled === groupingEnabled) {
|
|
5602
|
+
saveGroupSidebarBoot(enabled);
|
|
5603
|
+
return seatReady;
|
|
5604
|
+
}
|
|
5605
|
+
groupingEnabled = enabled;
|
|
5606
|
+
saveGroupSidebarBoot(enabled);
|
|
5607
|
+
if (groupingDisposer !== void 0) {
|
|
5608
|
+
groupingDisposer();
|
|
5609
|
+
groupingDisposer = void 0;
|
|
5610
|
+
}
|
|
5611
|
+
const epoch = ++seatEpoch;
|
|
5612
|
+
seatReady = new Promise((resolve) => {
|
|
5613
|
+
seatReadyResolve = resolve;
|
|
5614
|
+
});
|
|
5615
|
+
if (!enabled) {
|
|
5616
|
+
afterPaint().then(() => {
|
|
5617
|
+
if (epoch === seatEpoch) finishSeat();
|
|
5618
|
+
});
|
|
5619
|
+
return seatReady;
|
|
5620
|
+
}
|
|
5621
|
+
registerGroupingSeat();
|
|
5476
5622
|
return seatReady;
|
|
5477
5623
|
};
|
|
5478
5624
|
const waitForGroupingSeat = async (enabled) => {
|