dsh-prompt-pocket 1.0.5 → 1.0.7

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
@@ -19,7 +19,7 @@ Prompt libraries ask for a title, tags, a folder and a panel before they will ke
19
19
  - **✦ writes a DSH prompt, it does not paraphrase.** Variables, paths, URLs and code blocks are kept byte-for-byte, nothing is invented, and filler is forbidden by the instruction. A failed or empty result never replaces your text; accepting a rewrite keeps the old one in `prior`.
20
20
  - **One click on an assistant reply keeps it verbatim** as source material, read from the session log — text blocks only, tool calls never leak in.
21
21
  - **The agent shares the same pocket** through the `prompt_stash` tool, scoped to the drawers so one project's prompts do not show up in another's answer.
22
- - **Sync through your own private git repository.** The panel pushes each change and merges the remote on launch; prompts are one file each, so a merge keeps both sides instead of corrupting one document. **A public repository is refused** — the plugin asks GitHub whether the repo is visible before it enables sync.
22
+ - **Sync through your own private git repository, automatically.** The host pulls on launch, when the panel opens after a stale gap, and every five minutes; each change is pushed three seconds after you make it. The panel pushes each change and merges the remote on launch; prompts are one file each, so a merge keeps both sides instead of corrupting one document. **A public repository is refused** — the plugin asks GitHub whether the repo is visible before it enables sync.
23
23
  - **Export and import as one JSON file.** For machines without git, or for a backup before you trust a sync.
24
24
  - **500 prompts, least recently used dropped, one JSON file, atomic writes, no runtime dependencies, no account.** Nothing leaves the machine except the one model call you explicitly ask for.
25
25
 
package/README.zh.md CHANGED
@@ -19,7 +19,7 @@
19
19
  - **✦ 写的是 DSH 提示词,不是同义改写。** `{{变量}}`、路径、URL、代码块原样保留,没说过的东西不编,套话在被禁之列。失败或空结果绝不覆盖原文;接受新版本时旧文本留在 `prior` 里,一键退回。
20
20
  - **AI 回复一键存原文。** 从会话日志里只取 text 块,工具调用不会漏进提示词。
21
21
  - **模型共用同一个口袋。** `prompt_stash` 工具读写同一份文件,且守分档,一个项目的提示词不会出现在另一个项目的回答里。
22
- - **用你自己的私有 git 仓库同步。** 每次改动自动提交推送,启动时合并远端;一条提示词一个文件,所以合并会让两边都留下,而不是把一份文档写坏。**公开仓库会被直接拒绝**——开启前插件会问一次 GitHub,这个仓库是不是公开的。
22
+ - **用你自己的私有 git 仓库自动同步。** 启动时拉一次,面板打开时如果上次同步超过 30 秒也会拉,另外每五分钟拉一次;改动后三秒推送。 每次改动自动提交推送,启动时合并远端;一条提示词一个文件,所以合并会让两边都留下,而不是把一份文档写坏。**公开仓库会被直接拒绝**——开启前插件会问一次 GitHub,这个仓库是不是公开的。
23
23
  - **导出与导入就是一个 JSON 文件。** 给没有 git 的机器用,或者在信任同步之前先做一次备份。
24
24
  - **最多 500 条,满了淘汰最久没用的那条;一个 JSON 文件、原子写、没有运行时依赖、不需要账号。** 除了你主动点的那一次模型调用,什么都不出这台机器。
25
25
 
package/client.js CHANGED
@@ -247,6 +247,9 @@ window.__ModuleLoader__.load({
247
247
 
248
248
  useEffect(() => {
249
249
  load();
250
+ // 打开面板后如果有同步,拉到远端条目需要几秒;到点再读一次,避免看到旧清单
251
+ const timer = setTimeout(() => load(), 8000);
252
+ return () => clearTimeout(timer);
250
253
  }, [load]);
251
254
 
252
255
  const remember = useCallback(() => {
package/docs/DETAIL.md CHANGED
@@ -61,7 +61,7 @@ The agent can read and write the same pocket through the `prompt_stash` tool, so
61
61
 
62
62
  Two ways, one file format.
63
63
 
64
- **Through a private git repository.** Set the remote in the panel; the host initialises the repository inside `$DSH_HOME/dsh-prompt-stash`, commits after each change and pushes, then merges the remote branch on launch. Prompts are stored as **one file per entry**, so a merge keeps both sides rather than corrupting a single JSON document. Identity is the repository credential — the plugin never stores a token, and it asks GitHub whether the repository is public before enabling sync, refusing if it is.
64
+ **Through a private git repository.** Set the remote in the panel; the host initialises the repository inside `$DSH_HOME/dsh-prompt-stash`, commits after each change and pushes, then merges the remote branch on launch, whenever the panel opens after a stale gap, and every five minutes. Prompts are stored as **one file per entry**, so a merge keeps both sides rather than corrupting a single JSON document. Identity is the repository credential — the plugin never stores a token, and it asks GitHub whether the repository is public before enabling sync, refusing if it is.
65
65
 
66
66
  **By hand.** Export writes one JSON file with every entry; import reads it and merges by id — a newer `updatedAt` replaces the local copy, an older one is skipped, invalid entries are counted and ignored, and neither path deletes a local prompt.
67
67
 
package/docs/DETAIL.zh.md CHANGED
@@ -61,7 +61,7 @@
61
61
 
62
62
  两条路,同一种文件格式。
63
63
 
64
- **走你自己的私有 git 仓库。** 在面板里填远端地址,宿主会在 `$DSH_HOME/dsh-prompt-stash` 里初始化仓库,每次改动后提交并推送,启动时合并远端分支。提示词是**一条一个文件**,所以合并会让两边都留下,而不是把一份 JSON 写坏。身份就是仓库的凭据,插件不存 token;开启前它会问一次 GitHub 这个仓库是不是公开的,公开就拒绝。
64
+ **走你自己的私有 git 仓库。** 在面板里填远端地址,宿主会在 `$DSH_HOME/dsh-prompt-stash` 里初始化仓库,每次改动后提交并推送,启动时、面板打开且距上次同步超过 30 秒时、以及每五分钟合并一次远端分支。提示词是**一条一个文件**,所以合并会让两边都留下,而不是把一份 JSON 写坏。身份就是仓库的凭据,插件不存 token;开启前它会问一次 GitHub 这个仓库是不是公开的,公开就拒绝。
65
65
 
66
66
  **手动搬。** 导出把全部条目写成一个 JSON 文件;导入按 id 合并——`updatedAt` 更新的覆盖本地、更旧的跳过、无效条目单独计数忽略,两条路都不会删掉本地已有的提示词。
67
67
 
package/index.js CHANGED
@@ -387,7 +387,17 @@ async function publicGitHubRepo(remote) {
387
387
  }
388
388
  }
389
389
 
390
+ let syncInFlight = null;
391
+
390
392
  async function syncNow(cfg) {
393
+ if (syncInFlight) return syncInFlight;
394
+ syncInFlight = runSync(cfg).finally(() => {
395
+ syncInFlight = null;
396
+ });
397
+ return syncInFlight;
398
+ }
399
+
400
+ async function runSync(cfg) {
391
401
  if (!cfg.enabled || !cfg.remote) return { ok: false, code: 'disabled' };
392
402
  const hasGit = await git(['--version']);
393
403
  if (!hasGit.ok) {
@@ -398,7 +408,12 @@ async function syncNow(cfg) {
398
408
  const local = await readStore();
399
409
  const remote = await readRemoteEntries(cfg);
400
410
  const merged = remote ? mergeStores(local, remote) : { entries: local.entries, tombstones: local.tombstones, added: 0, updated: 0, skipped: 0, deleted: 0 };
401
- await writeStore({ version: 1, entries: merged.entries, tombstones: merged.tombstones });
411
+ // A sync can take seconds (fetch, worktree, push). Anything saved or deleted
412
+ // while it runs is newer than the snapshot read above, so merge that in before
413
+ // writing: otherwise the tail of the sync resurrects what was just deleted.
414
+ const fresh = await readStore();
415
+ const settled = mergeStores(merged, fresh);
416
+ await writeStore({ version: 1, entries: settled.entries, tombstones: settled.tombstones });
402
417
  await git(['add', '-A']);
403
418
  const status = await git(['status', '--porcelain']);
404
419
  if (status.ok && status.stdout.trim()) await git(['commit', '-m', `pocket sync ${new Date().toISOString()}`]);
@@ -601,6 +616,22 @@ export const inject = ['webServer', 'tools'];
601
616
  export function apply(ctx) {
602
617
  const sessions = ctx.get('sessions');
603
618
 
619
+ // Pull once the host is up, then keep pulling every five minutes. Without this
620
+ // a machine only ever pushed its own changes and never saw the other one.
621
+ readSyncConfig()
622
+ .then((cfg) => {
623
+ if (cfg.enabled && cfg.remote) return syncNow(cfg);
624
+ })
625
+ .catch(() => {});
626
+ const timer = setInterval(() => {
627
+ readSyncConfig()
628
+ .then((cfg) => {
629
+ if (cfg.enabled && cfg.remote) return syncNow(cfg);
630
+ })
631
+ .catch(() => {});
632
+ }, 5 * 60 * 1000);
633
+ if (timer.unref) timer.unref();
634
+
604
635
  ctx.webServer.register({
605
636
  kind: 'prefix',
606
637
  path: '/dsh-prompt-stash',
@@ -609,6 +640,9 @@ export function apply(ctx) {
609
640
 
610
641
  if (url.pathname === '/dsh-prompt-stash/state') {
611
642
  if (req.method !== 'GET') return sendNode(res, 405, { error: 'method not allowed' });
643
+ // Opening the panel refreshes from the remote when the last sync is old.
644
+ const cfg = await readSyncConfig();
645
+ if (cfg.enabled && cfg.remote && Date.now() - cfg.lastSyncAt > 30000) scheduleSync();
612
646
  return sendNode(res, 200, await snapshot(url.searchParams.get('workspace') || undefined));
613
647
  }
614
648
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-prompt-pocket",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A prompt pocket that floats in the corner: save the draft or the selected text with Ctrl+Shift+S, click a saved prompt to drop it back at the caret.",