dsh-engramory 1.4.0 → 1.5.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.
Files changed (5) hide show
  1. package/README.en.md +57 -9
  2. package/README.md +20 -6
  3. package/client.js +346 -14
  4. package/index.js +4961 -3495
  5. package/package.json +1 -1
package/client.js CHANGED
@@ -29,8 +29,17 @@ window.__ModuleLoader__.load({
29
29
  /** Relative to the page, as dsh's own pages fetch, so a mounted deployment keeps its prefix. */
30
30
  const SETTINGS_API = 'api/engramory/settings'
31
31
  const MEMORY_API = 'api/engramory/memory'
32
+ const STORE_API = 'api/engramory/store'
33
+ const PICK_API = 'api/engramory/store/pick'
34
+ /** How long the page waits on dsh's folder chooser: the route closes it after ten minutes. */
35
+ const PICK_WAIT_MS = 11 * 60 * 1000
36
+ /** How often the page asks after a move it started, and for how long in all. */
37
+ const MOVE_POLL_MS = 500
38
+ const MOVE_WATCH_MS = 120000
39
+ /** How often the page looks again at a move it did not start, while one is under way. */
40
+ const MOVE_FOLLOW_MS = 2000
32
41
  /** This plugin's version, for the feedback footer; a test keeps it equal to package.json's. */
33
- const VERSION = '1.4.0'
42
+ const VERSION = '1.5.0'
34
43
  /** Where feedback goes: a new issue on the repository, or the project's mailbox. Opening
35
44
  * the link is the browser's (the desktop app hands it to the system's); the footer submits
36
45
  * nothing by itself. */
@@ -85,6 +94,59 @@ window.__ModuleLoader__.load({
85
94
  overridden: '更高一层的配置覆盖了这些值,这里保存不了。',
86
95
  invalid: '有一项填得不对:',
87
96
  failed: '保存失败:',
97
+ place: '记忆库位置',
98
+ placeNow: '现在在',
99
+ placeIsDefault: '(默认位置)',
100
+ placeLoadFailed: '读不到记忆库在哪。',
101
+ placeLoading: '正在读取记忆库位置…',
102
+ placeChange: '更换存储地址',
103
+ globalAbsent: '全局记忆还没有建,AI 第一次往全局库存记忆时会自动建好。',
104
+ placeHide: '收起',
105
+ placeChoose: '选文件夹…',
106
+ placeChoosing: '在弹出的窗口里选…',
107
+ placeChosenInside: '选的文件夹里已经有东西,会在里面新建一个 {name} 文件夹来放记忆。',
108
+ placeChooseFailed: '打不开选文件夹的窗口:{reason}',
109
+ placeInput: '新位置',
110
+ placePlaceholder: '新位置:一个空文件夹或还不存在的文件夹,例如 D:\\同步盘\\AI记忆',
111
+ placeMove: '搬过去',
112
+ placeBack: '搬回默认位置',
113
+ placeHint: '整个记忆库连同归档一起搬过去,搬完旧位置自动清理;这台电脑上的桌面版和命令行都用这个位置。搬的那几秒 AI 存不了记忆,会过一会儿再存。放进网盘的话别让两台电脑同时写;放进 git 仓库会被一起提交;映射的网络盘可能让 dsh 卡顿。',
114
+ placeMoving: '正在搬…',
115
+ placeMoved: '搬好了,旧位置已经清理。',
116
+ placeMovedConflicts: '搬好了。有 {count} 个文件在搬的时候两边都被改过:旧位置那份放在新位置、名字里带 .old-,索引里也加了一行,记得合并。',
117
+ placeSame: '记忆库已经在这里了。',
118
+ placeStillMoving: '还在搬,过一会儿刷新这一页看看。',
119
+ placeEnded: '这次搬家已经结束,记忆库现在在上面写的位置。',
120
+ placeMoveFailed: '没搬成:{reason}',
121
+ placeResuming: '有一次搬家还没做完,dsh 会自动接着做完。',
122
+ placeResumingWhy: '上次停在:{reason}会自动再试。',
123
+ placePinned: '配置里固定了索引(indexPath),记忆库就在它所在的文件夹,这里不能搬。',
124
+ placeRemote: 'dsh 主目录在网络位置上,这里不能搬。',
125
+ placeProblem: '记录记忆库位置的文件读不懂,暂时找不到记忆库:{file}。把它改对后刷新这一页。',
126
+ placeCustomSkill: '你用的是自己写的记忆规则(skill),里面写的位置搬完要自己改。',
127
+ placeLegacy: 'dsh 主目录的 AGENTS.md 里还有不装插件时写进去的记忆规则,写的是默认位置;装了插件就用不着它了,可以用 engramory_init.py 卸掉。',
128
+ whyRelative: '要写完整路径(Windows 上带盘符)。',
129
+ whyNetwork: '不能放在网络路径上。',
130
+ whyRoot: '不能是整个盘。',
131
+ whyDeep: '路径太深了。',
132
+ whyInvalid: '路径里有 Windows 不认的名字或字符。',
133
+ whyReserved: '这个位置不能用:用户主目录、dsh 主目录和它们的上级都不行,名字也不能跟记忆库撞。',
134
+ whyNested: '新位置不能在记忆库里面,也不能把记忆库包在里面。',
135
+ whyNotEmpty: '那个文件夹里已经有东西了,要选空文件夹或还不存在的文件夹。',
136
+ whyNotDir: '那里是个文件,不是文件夹。',
137
+ whyLink: '新位置或记忆库里有目录链接,插件不替你搬,请手动处理。',
138
+ whyUnreadable: '读不了那个位置。',
139
+ whyUnavailable: '现在的记忆库找不到了,比如它所在的盘没接上。',
140
+ whyBusy: '正在搬家,等它做完。',
141
+ whyProblem: '记忆库位置的记录有问题,先修好它。',
142
+ whyTooMany: '文件太多了。',
143
+ whyTooBig: '太大了(超过 256 MB)。',
144
+ whyTooDeep: '文件夹层数太多了。',
145
+ whySpecial: '记忆库里有不是普通文件的东西。',
146
+ whyChanged: '搬的时候记忆库被别处换了位置。',
147
+ whyInterrupted: '上次搬到一半被打断了,已经撤销,记忆库还在原处。',
148
+ whyFailed: '文件操作出错了。',
149
+ locationUnknown: '记录记忆库位置的文件(dsh 主目录下的 .engramory-memory.json)读不懂,全局记忆这次没列出来。把它改对后点刷新。',
88
150
  panel: '记忆',
89
151
  panelTitle: 'Engramory 记忆',
90
152
  refresh: '刷新',
@@ -104,7 +166,6 @@ window.__ModuleLoader__.load({
104
166
  sizeKB: '{n} KB',
105
167
  overHint: '超出上限了,AI 只读得到前面一部分,该压缩了。',
106
168
  noIndex: '还没有索引',
107
- openIndex: '打开索引',
108
169
  openFolder: '打开文件夹',
109
170
  opened: '已打开 {name}。',
110
171
  revealed: '已在文件夹里显示 {name}。',
@@ -136,7 +197,7 @@ window.__ModuleLoader__.load({
136
197
  howToSay: '想让 AI 记住什么,直接跟它说,比如「记住:我习惯用 pnpm」「把这个决定记下来」。平时它也会尽量自己挑值得长期记住的记下来,比如你纠正过它的做法。',
137
198
  howToRecall: '默认每次对话都会带上记忆的目录(索引),AI 用到细节时再打开那条笔记,不用你提醒。',
138
199
  howToEdit: '这里列出读得到的记忆,打开笔记就能直接改;想让 AI 忘掉什么,跟它说「忘掉……」就行。',
139
- howToMove: '记忆是存在运行 dsh 那台电脑上的普通 markdown 文件,位置写在每个库的标题下面。换电脑时把那个文件夹拷到新电脑的同一位置;在配置里指定过位置的,配置也一起带过去。',
200
+ howToMove: '记忆是存在运行 dsh 那台电脑上的普通 markdown 文件,位置写在每个库的标题下面。想放到别处(比如网盘里),点「全局记忆」右上角的「更换存储地址」,插件会整个搬过去。换电脑时,把那个文件夹拷到新电脑 dsh 主目录下的 .engramory-memory,想放别处再在新电脑上搬一次。',
140
201
  howToSocial: '接了 QQ、微信等、别人也能跟你的 AI 聊的话,在上面打开「大肥鱼模式」,再把「记忆权限」改成「社交」:只有认得出是你本人的对话才拿得到记忆。这不是安全隔离,详见插件说明。',
141
202
  feedbackLead: '遇到问题或有建议:',
142
203
  feedbackIssue: '到 GitHub 提 issue',
@@ -227,6 +288,59 @@ window.__ModuleLoader__.load({
227
288
  overridden: 'A higher configuration layer overrides these values, so they cannot be saved here.',
228
289
  invalid: 'One field is not acceptable: ',
229
290
  failed: 'Saving failed: ',
291
+ place: 'Where the memory is',
292
+ placeNow: 'Now in',
293
+ placeIsDefault: ' (the default place)',
294
+ placeLoadFailed: 'Could not read where the memory is.',
295
+ placeLoading: 'Reading where the memory is…',
296
+ placeChange: 'Change location',
297
+ globalAbsent: 'No global memory yet: the global store is made the first time the AI saves to it.',
298
+ placeHide: 'Close',
299
+ placeChoose: 'Choose folder…',
300
+ placeChoosing: 'Choose in the window that opened…',
301
+ placeChosenInside: 'That folder holds something already: a {name} folder is made inside it for the memory.',
302
+ placeChooseFailed: 'The folder chooser did not open: {reason}',
303
+ placeInput: 'New place',
304
+ placePlaceholder: 'New place: an empty folder, or one not there yet, such as D:\\Sync\\AI memory',
305
+ placeMove: 'Move it there',
306
+ placeBack: 'Move it back to the default place',
307
+ placeHint: 'The whole store moves, archive and all, and the old place is cleared once it has; the desktop app and the command line on this computer both use the new place. For the few seconds it takes, the AI cannot save memory and tries again a little later. In a synced folder, do not let two computers write at once; in a git repository it gets committed with the rest; a mapped network drive may make dsh stall.',
308
+ placeMoving: 'Moving…',
309
+ placeMoved: 'Moved, and the old place is cleared.',
310
+ placeMovedConflicts: 'Moved. {count} file(s) changed in both places while it moved: the old place\'s copy is beside it in the new place, with .old- in its name and a line in the index. Merge them.',
311
+ placeSame: 'The memory is there already.',
312
+ placeStillMoving: 'Still moving. Refresh this page in a little while.',
313
+ placeEnded: 'The move is over: the memory is where it says above.',
314
+ placeMoveFailed: 'Not moved: {reason}',
315
+ placeResuming: 'A move is not finished yet; dsh finishes it on its own.',
316
+ placeResumingWhy: 'It last stopped at: {reason} It will try again.',
317
+ placePinned: 'An index is pinned (indexPath): the memory is in its folder, and is not moved here.',
318
+ placeRemote: 'dsh\'s home folder is on a network place: the memory is not moved here.',
319
+ placeProblem: 'The file that says where the memory is cannot be read as written, so the memory cannot be found for now: {file}. Correct it, then refresh this page.',
320
+ placeCustomSkill: 'You use memory rules of your own (skill): change the place they name once it has moved.',
321
+ placeLegacy: 'AGENTS.md in dsh\'s home folder still holds memory rules written there for a setup without the plugin, naming the default place. With the plugin they are not needed: engramory_init.py can take them out.',
322
+ whyRelative: 'Give the whole path (on Windows, with its drive).',
323
+ whyNetwork: 'It cannot be on a network path.',
324
+ whyRoot: 'It cannot be a whole drive.',
325
+ whyDeep: 'The path is too deep.',
326
+ whyInvalid: 'The path holds a name or a character Windows does not take.',
327
+ whyReserved: 'That place cannot be used: not your home folder, not dsh\'s, nor any folder holding them, and not a name the memory store uses.',
328
+ whyNested: 'The new place cannot be inside the store, nor hold it.',
329
+ whyNotEmpty: 'There is something in that folder already: choose an empty folder, or one not there yet.',
330
+ whyNotDir: 'That is a file, not a folder.',
331
+ whyLink: 'The new place or the store holds a folder link: the plugin does not move it for you. Sort it out by hand.',
332
+ whyUnreadable: 'That place cannot be read.',
333
+ whyUnavailable: 'The store cannot be found where it is now: its drive may not be connected.',
334
+ whyBusy: 'A move is under way: wait until it is done.',
335
+ whyProblem: 'The record of where the memory is has a problem: fix it first.',
336
+ whyTooMany: 'There are too many files.',
337
+ whyTooBig: 'It is too big (over 256 MB).',
338
+ whyTooDeep: 'Its folders go too deep.',
339
+ whySpecial: 'The store holds something that is not a plain file.',
340
+ whyChanged: 'The store was moved elsewhere while this move ran.',
341
+ whyInterrupted: 'The last move was cut short and has been undone: the store is where it was.',
342
+ whyFailed: 'A file operation failed.',
343
+ locationUnknown: 'The file that says where the memory is (.engramory-memory.json in dsh\'s home folder) cannot be read as written, so the global memory is not listed this time. Correct it, then refresh.',
230
344
  panel: 'Memory',
231
345
  panelTitle: 'Engramory memory',
232
346
  refresh: 'Refresh',
@@ -246,7 +360,6 @@ window.__ModuleLoader__.load({
246
360
  sizeKB: '{n} KB',
247
361
  overHint: 'Over the cap: the AI reads only the first part. Time to compact it.',
248
362
  noIndex: 'No index yet',
249
- openIndex: 'Open the index',
250
363
  openFolder: 'Open the folder',
251
364
  opened: 'Opened {name}.',
252
365
  revealed: 'Showed {name} in its folder.',
@@ -278,7 +391,7 @@ window.__ModuleLoader__.load({
278
391
  howToSay: 'To have the AI remember something, just tell it: "remember that I use pnpm", "note this decision down". It also tries to keep what is worth keeping on its own, such as a way of working you corrected.',
279
392
  howToRecall: 'By default every conversation carries the memory\'s table of contents (the index), and the AI opens a note when it needs the details; you do not have to remind it.',
280
393
  howToEdit: 'The memory this page can read is listed here; open a note to edit it. To have the AI forget something, tell it "forget …".',
281
- howToMove: 'The memory is plain markdown files on the computer dsh runs on, in the folder shown under each store\'s title. On a new computer, copy that folder to the same place, and if your configuration names where the store is, bring that setting along.',
394
+ howToMove: 'The memory is plain markdown files on the computer dsh runs on, in the folder shown under each store\'s title. To keep it elsewhere (a synced folder, say), click Change location at the top right of the global memory, and the plugin moves it all there. On a new computer, copy that folder to .engramory-memory in dsh\'s home folder there, then move it again if you want it elsewhere.',
282
395
  howToSocial: 'If others can talk to your AI too (through QQ, WeChat and the like), turn on Companion mode above and set Memory access to Social: only conversations it can tell are yours get the memory. This is not a security boundary; see the plugin\'s README.',
283
396
  feedbackLead: 'Found a problem or have an idea? ',
284
397
  feedbackIssue: 'Open an issue on GitHub',
@@ -367,6 +480,12 @@ window.__ModuleLoader__.load({
367
480
  .eng-cap{display:flex;gap:12px;align-items:center;flex-wrap:wrap;}
368
481
  .eng-cap label{display:flex;align-items:center;gap:6px;color:var(--dsw-alias-label-secondary);font-size:12px;}
369
482
  .eng-cap input{width:110px;}
483
+ .eng-empty{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}
484
+ .eng-place{display:flex;flex-direction:column;gap:8px;padding:12px 14px;border:.5px solid var(--dsw-alias-border-l3);border-radius:14px;}
485
+ .eng-place-now{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere;}
486
+ .eng-place-now code{font-family:var(--ds-font-family-code,ui-monospace,monospace);color:var(--dsw-alias-label-primary);}
487
+ .eng-place-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap;}
488
+ .eng-place-row .eng-input{flex:1 1 260px;}
370
489
  .eng-btn{display:inline-flex;align-items:center;gap:6px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);border-radius:8px;padding:5px 14px;font:inherit;font-size:12px;line-height:18px;cursor:pointer;white-space:nowrap;}
371
490
  .eng-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);}
372
491
  .eng-btn:disabled{opacity:.5;cursor:default;}
@@ -510,9 +629,11 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
510
629
  }
511
630
 
512
631
  /** fetch with a deadline: a request the host never answers must not hold the page busy. */
513
- async function request(url, init = {}) {
632
+ async function request(url, { timeout = 15000, signal, ...init } = {}) {
514
633
  const deadline = new AbortController()
515
- const timer = setTimeout(() => deadline.abort(), 15000)
634
+ const timer = setTimeout(() => deadline.abort(), timeout)
635
+ // the caller's own end too (a section closed while dsh's chooser is open)
636
+ signal?.addEventListener('abort', () => deadline.abort(), { once: true })
516
637
  try {
517
638
  const response = await fetch(url, { cache: 'no-store', ...init, signal: deadline.signal,
518
639
  headers: { accept: 'application/json', ...(init.headers ?? {}) } })
@@ -720,6 +841,207 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
720
841
  return h(SettingsForm, props)
721
842
  }
722
843
 
844
+ /** "No memory yet", and where the store is to be made: it can be moved before there is any. */
845
+ function NoMemory({ t, onMoved, note = 'empty' }) {
846
+ const [placing, setPlacing] = useState(false)
847
+ return h('div', { className: 'eng-section' },
848
+ h('div', { className: 'eng-empty' },
849
+ h('p', { className: 'eng-note' }, t(note === 'global' ? 'globalAbsent' : 'empty')),
850
+ h('button', { type: 'button', className: 'eng-btn eng-btn-ghost', 'aria-expanded': placing,
851
+ onClick: () => setPlacing(!placing) }, icon('move', 14), t(placing ? 'placeHide' : 'placeChange'))),
852
+ placing ? h(PlaceSection, { t, onMoved, showNow: true }) : null)
853
+ }
854
+
855
+ /** Why the store route turned a move down, or a move stopped (its codes, index.js). */
856
+ function whyNot(t, code, detail) {
857
+ const why = {
858
+ relative: () => t('whyRelative'), network: () => t('whyNetwork'), root: () => t('whyRoot'),
859
+ deep: () => t('whyDeep'), invalid: () => t('whyInvalid'), reserved: () => t('whyReserved'),
860
+ nested: () => t('whyNested'), notEmpty: () => t('whyNotEmpty'), notDir: () => t('whyNotDir'),
861
+ link: () => t('whyLink'), unreadable: () => t('whyUnreadable'), unavailable: () => t('whyUnavailable'),
862
+ busy: () => t('whyBusy'), problem: () => t('whyProblem'), pinned: () => t('placePinned'),
863
+ remote: () => t('placeRemote'), tooMany: () => t('whyTooMany'), tooBig: () => t('whyTooBig'),
864
+ tooDeep: () => t('whyTooDeep'), special: () => t('whySpecial'), changed: () => t('whyChanged'),
865
+ interrupted: () => t('whyInterrupted'),
866
+ }[code]
867
+ return why === undefined ? `${t('whyFailed')}${typeof detail === 'string' ? ` (${detail})` : ''}` : why()
868
+ }
869
+
870
+ /**
871
+ * Moving the global store: on the memory page, opened from the global store's own actions
872
+ * (or beside "no memory yet"). The folder comes from dsh's own chooser where it opens on this
873
+ * desktop, or is typed; the page starts a move and asks after it until it is done (the plugin
874
+ * carries it on whether or not the page stays), then has the listing read again (`onMoved`).
875
+ * `showNow`: say where the store is, where the page does not show it already.
876
+ */
877
+ function PlaceSection({ t, onMoved, showNow = false }) {
878
+ const [state, setState] = useState({ phase: 'loading' })
879
+ const [text, setText] = useState('')
880
+ const [busy, setBusy] = useState(false)
881
+ const [choosing, setChoosing] = useState(false)
882
+ const [banner, setBanner] = useState(undefined)
883
+ const alive = useRef(true)
884
+ const moving = useRef(false)
885
+ const chooserRequest = useRef(undefined)
886
+ // a move on record the last time it was read: over now, the listing is read again
887
+ const wasMoving = useRef(false)
888
+ useEffect(() => () => {
889
+ alive.current = false
890
+ chooserRequest.current?.abort() // closed: the chooser it asked for closes with it
891
+ }, [])
892
+ const load = useCallback(async () => {
893
+ try {
894
+ const response = await request(STORE_API)
895
+ if (!response.ok || response.body === undefined) throw new Error(`HTTP ${response.status}`)
896
+ if (!alive.current) return
897
+ setState({ phase: 'ready', data: response.body })
898
+ const under = response.body.moving !== undefined
899
+ if (wasMoving.current && !under) onMoved?.()
900
+ wasMoving.current = under
901
+ } catch {
902
+ if (alive.current) setState((s) => (s.phase === 'ready' ? s : { phase: 'error' }))
903
+ }
904
+ }, [onMoved])
905
+ useEffect(() => { load() }, [load])
906
+ // a move under way when the page opened (another window's, or one carried on after a
907
+ // restart): asked after until it is over, as one this page starts
908
+ const underWay = state.phase === 'ready' && state.data.moving !== undefined && !busy
909
+ // each look, answered or not, schedules the next while the move is still on record
910
+ const [looks, setLooks] = useState(0)
911
+ useEffect(() => {
912
+ if (!underWay) return undefined
913
+ const timer = setTimeout(() => {
914
+ if (alive.current) load().finally(() => { if (alive.current) setLooks((n) => n + 1) })
915
+ }, MOVE_FOLLOW_MS)
916
+ return () => clearTimeout(timer)
917
+ }, [underWay, looks])
918
+
919
+ const choose = async () => {
920
+ if (moving.current || choosing) return
921
+ setChoosing(true)
922
+ setBanner(undefined)
923
+ try {
924
+ let response
925
+ const ending = new AbortController()
926
+ chooserRequest.current = ending
927
+ try {
928
+ response = await request(PICK_API, { method: 'POST', headers: { 'content-type': 'application/json' },
929
+ body: '{}', timeout: PICK_WAIT_MS, signal: ending.signal })
930
+ } catch (error) {
931
+ response = { ok: false, body: { message: String(error?.message ?? error) } }
932
+ } finally {
933
+ if (chooserRequest.current === ending) chooserRequest.current = undefined
934
+ }
935
+ if (!alive.current) return
936
+ const body = response.body ?? {}
937
+ if (response.ok && body.cancelled === true) return
938
+ if (response.ok && typeof body.to === 'string') {
939
+ setText(body.to)
940
+ if (typeof body.inside === 'string') setBanner({ tone: 'ok', text: t('placeChosenInside', { name: body.inside }) })
941
+ return
942
+ }
943
+ setBanner({ tone: 'error', text: t('placeChooseFailed', { reason: body.message ?? body.error ?? `HTTP ${response.status}` }) })
944
+ } finally {
945
+ if (alive.current) setChoosing(false)
946
+ }
947
+ }
948
+
949
+ const move = async (to) => {
950
+ if (moving.current) return
951
+ moving.current = true
952
+ setBusy(true)
953
+ setBanner(undefined)
954
+ try {
955
+ let response
956
+ try {
957
+ response = await request(STORE_API, {
958
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ to }),
959
+ })
960
+ } catch (error) {
961
+ response = { ok: false, body: { error: 'failed', detail: String(error?.message ?? error) } }
962
+ }
963
+ if (!alive.current) return
964
+ const body = response.body ?? {}
965
+ if (response.ok && body.same === true) {
966
+ await load() // another dsh may have moved it there: the page shows where it is now
967
+ if (alive.current) setBanner({ tone: 'ok', text: t('placeSame') })
968
+ onMoved?.()
969
+ return
970
+ }
971
+ if (response.status !== 202 || typeof body.id !== 'string') {
972
+ setBanner({ tone: 'error', text: t('placeMoveFailed', { reason: whyNot(t, body.reason ?? body.error, body.detail) }) })
973
+ await load()
974
+ return
975
+ }
976
+ setBanner({ tone: 'ok', text: t('placeMoving') })
977
+ let outcome
978
+ // by the clock, not by count: each ask may itself wait out its own deadline
979
+ const until = Date.now() + MOVE_WATCH_MS
980
+ while (alive.current && outcome?.done !== true && Date.now() < until) {
981
+ await new Promise((resolve) => setTimeout(resolve, MOVE_POLL_MS))
982
+ try {
983
+ const polled = await request(`${STORE_API}?id=${encodeURIComponent(body.id)}`)
984
+ if (polled.ok && polled.body !== undefined && alive.current) {
985
+ setState({ phase: 'ready', data: polled.body })
986
+ outcome = polled.body.outcome
987
+ }
988
+ } catch { /* asked again */ }
989
+ }
990
+ if (!alive.current) return
991
+ if (outcome?.done === true && outcome.elsewhere === true) {
992
+ setText('')
993
+ setBanner({ tone: 'ok', text: t('placeEnded') })
994
+ onMoved?.()
995
+ } else if (outcome?.done === true && outcome.ok === true) {
996
+ setText('')
997
+ setBanner({ tone: 'ok', text: outcome.conflicts > 0
998
+ ? t('placeMovedConflicts', { count: outcome.conflicts }) : t('placeMoved') })
999
+ onMoved?.()
1000
+ } else if (outcome?.done === true) {
1001
+ setBanner({ tone: 'error', text: t('placeMoveFailed', { reason: whyNot(t, outcome.error, outcome.detail) }) })
1002
+ } else {
1003
+ setBanner({ tone: 'error', text: t('placeStillMoving') })
1004
+ }
1005
+ } finally {
1006
+ moving.current = false
1007
+ if (alive.current) setBusy(false)
1008
+ }
1009
+ }
1010
+
1011
+ if (state.phase === 'loading') return h('p', { className: 'eng-note' }, t('placeLoading'))
1012
+ if (state.phase === 'error') {
1013
+ return h('section', { className: 'eng-place', 'aria-label': t('place') },
1014
+ h('p', { className: 'eng-note' }, t('placeLoadFailed')),
1015
+ h('div', { className: 'eng-actions' }, h('button', { type: 'button', className: 'eng-btn', onClick: load }, t('retry'))))
1016
+ }
1017
+ const { data } = state
1018
+ const atDefault = typeof data.store === 'string' && data.store === data.default
1019
+ const blocked = data.pinned === true ? 'placePinned' : data.remote === true ? 'placeRemote' : undefined
1020
+ const stopped = data.moving !== undefined && !busy
1021
+ return h('section', { className: 'eng-place', 'aria-label': t('place') },
1022
+ showNow && typeof data.store === 'string' ? h('p', { className: 'eng-place-now' },
1023
+ `${t('placeNow')} `, h('code', null, legible(data.store)), atDefault ? t('placeIsDefault') : '') : null,
1024
+ data.problem !== undefined ? h('div', { className: 'eng-banner', 'data-tone': 'error' },
1025
+ t('placeProblem', { file: legible(data.file ?? '') })) : null,
1026
+ stopped ? h('p', { className: 'eng-note' }, t('placeResuming'),
1027
+ data.moving.error === undefined ? '' : ` ${t('placeResumingWhy', { reason: whyNot(t, data.moving.error) })}`) : null,
1028
+ blocked !== undefined ? h('p', { className: 'eng-note' }, t(blocked)) : data.problem === undefined ? [
1029
+ h('div', { className: 'eng-place-row', key: 'row' },
1030
+ data.chooser === true ? h('button', { type: 'button', className: 'eng-btn', disabled: busy || choosing,
1031
+ onClick: choose }, icon('folder', 14), t(choosing ? 'placeChoosing' : 'placeChoose')) : null,
1032
+ h('input', { className: 'eng-input', value: text, disabled: busy, placeholder: t('placePlaceholder'),
1033
+ 'aria-label': t('placeInput'), spellCheck: false, onChange: (e) => { setText(e.target.value); setBanner(undefined) } }),
1034
+ h('button', { type: 'button', className: 'eng-btn eng-btn-primary', disabled: busy || choosing || text.trim() === '',
1035
+ onClick: () => move(text.trim()) }, busy ? t('placeMoving') : t('placeMove'))),
1036
+ atDefault ? null : h('div', { className: 'eng-actions', key: 'back' },
1037
+ h('button', { type: 'button', className: 'eng-btn', disabled: busy, onClick: () => move(null) }, t('placeBack'))),
1038
+ h('p', { className: 'eng-hint', key: 'hint' }, t('placeHint')),
1039
+ data.customSkill === true ? h('p', { className: 'eng-note', key: 'skill' }, t('placeCustomSkill')) : null,
1040
+ data.legacyRules === true ? h('p', { className: 'eng-note', key: 'legacy' }, t('placeLegacy')) : null,
1041
+ ] : null,
1042
+ banner ? h('div', { className: 'eng-banner', 'data-tone': banner.tone, role: 'status' }, banner.text) : null)
1043
+ }
1044
+
723
1045
  /**
724
1046
  * The two settings that matter most, atop the memory page, each saved as it is switched;
725
1047
  * what they mean, and the index cap, stay on the package's page.
@@ -863,7 +1185,8 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
863
1185
  search: [['circle', { cx: 11, cy: 11, r: 7 }], ['path', { d: 'm20 20-3.5-3.5' }]],
864
1186
  copy: [['rect', { x: 9, y: 9, width: 11, height: 11, rx: 2 }], ['path', { d: 'M5 15V5a2 2 0 0 1 2-2h8' }]],
865
1187
  folder: [['path', { d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z' }]],
866
- index: [['path', { d: 'M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01' }]],
1188
+ move: [['path', { d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z' }],
1189
+ ['path', { d: 'M9 13h6m-2-2 2 2-2 2' }]],
867
1190
  tidy: [['path', { d: 'm4 20 11-11M14 4l1 2 2 1-2 1-1 2-1-2-2-1 2-1zM19 11l.7 1.3L21 13l-1.3.7L19 15l-.7-1.3L17 13l1.3-.7z' }]],
868
1191
  archive: [['rect', { x: 3, y: 4, width: 18, height: 5, rx: 1 }], ['path', { d: 'M5 9v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9M10 13h4' }]],
869
1192
  alert: [['path', { d: 'M12 4 2.5 20h19z' }], ['path', { d: 'M12 10v4M12 17h.01' }]],
@@ -953,8 +1276,10 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
953
1276
  * mark, the name, the type and size, and what stands out (a plan's day, a note grown past one
954
1277
  * fact, one the index leaves out). While the page filters, the rows that match and no more.
955
1278
  */
956
- function StoreSection({ store, cap, canOpen, open, match, kind, now, t }) {
1279
+ function StoreSection({ store, cap, canOpen, open, match, kind, now, t, onMoved }) {
957
1280
  const [tidy, setTidy] = useState('idle')
1281
+ // the global store's: moving it, opened from its actions
1282
+ const [placing, setPlacing] = useState(false)
958
1283
  const alive = useRef(true)
959
1284
  useEffect(() => () => { alive.current = false }, [])
960
1285
  const title = legible(store.kind === 'user' ? [t('storeUser'), ...store.titles].join(' · ')
@@ -1061,14 +1386,16 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
1061
1386
  h('span', { className: 'eng-meter-fill', style: { width: `${Math.min(100, Math.floor(fill * 100))}%` } })),
1062
1387
  h('span', { className: 'eng-usage', 'data-over': index?.over === true, title: index?.over ? t('overHint') : undefined }, usage),
1063
1388
  h('div', { className: 'eng-store-actions' },
1389
+ store.kind === 'user' ? h('button', { type: 'button', className: 'eng-btn eng-btn-ghost', key: 'place',
1390
+ 'aria-expanded': placing, onClick: () => setPlacing(!placing) },
1391
+ icon('move', 14), t(placing ? 'placeHide' : 'placeChange')) : null,
1064
1392
  attention ? null : tidyButton('eng-btn eng-btn-ghost'),
1065
1393
  // the folder is shown with its index selected: no index, no folder to show
1066
1394
  ...(canOpen && index !== null ? [
1067
- h('button', { type: 'button', className: 'eng-btn eng-btn-ghost', key: 'index',
1068
- onClick: () => open(store, index.name, false) }, icon('index', 14), t('openIndex')),
1069
1395
  h('button', { type: 'button', className: 'eng-btn eng-btn-ghost', key: 'folder',
1070
1396
  onClick: () => open(store, undefined, false) }, icon('folder', 14), t('openFolder'))] : []))),
1071
1397
  h('p', { className: 'eng-path' }, legible(store.dir)),
1398
+ placing ? h(PlaceSection, { t, onMoved }) : null,
1072
1399
  !filtering && checked && findings.length === 0
1073
1400
  ? h('p', { className: 'eng-store-ok' }, icon('check', 13), t('healthOk')) : null,
1074
1401
  attention ? h('div', { className: 'eng-attn', role: 'note' },
@@ -1301,8 +1628,13 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
1301
1628
  (shown === undefined ? store.archive.filter(match).length : 0), 0)
1302
1629
  body = [
1303
1630
  data.pinned === 'relative' ? h('p', { className: 'eng-note', key: 'pinned' }, t('pinnedRelative')) : null,
1304
- data.stores.length === 0 && data.pinned === undefined && !(data.unreadable > 0) && data.more !== true
1305
- ? h('p', { className: 'eng-note', key: 'empty' }, t('empty')) : null,
1631
+ data.location !== undefined ? h('p', { className: 'eng-note', key: 'location' }, t('locationUnknown')) : null,
1632
+ data.stores.length === 0 && data.pinned === undefined && data.location === undefined &&
1633
+ !(data.unreadable > 0) && data.more !== true
1634
+ ? h(NoMemory, { key: 'empty', t, onMoved: load })
1635
+ // projects' stores listed, the global one not made yet: still to be moved from here
1636
+ : data.stores.length > 0 && data.global === 'absent'
1637
+ ? h(NoMemory, { key: 'global', t, onMoved: load, note: 'global' }) : null,
1306
1638
  notes.length + archived > 0 ? h('div', { className: 'eng-toolbar', key: 'toolbar' },
1307
1639
  h('div', { className: 'eng-tabs', role: 'group', 'aria-label': t('typeLabel') },
1308
1640
  tab(undefined, t('typeAll'), notes.length),
@@ -1313,7 +1645,7 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
1313
1645
  'aria-label': t('filterLabel'), onChange: (event) => setQuery(event.target.value) }))) : null,
1314
1646
  match === undefined ? null : h('p', { className: 'eng-filter-count', key: 'count', role: 'status',
1315
1647
  'aria-live': 'polite' }, t('filterCount', { count: matched })),
1316
- ...data.stores.map((store) => h(StoreSection, { key: store.id, store, cap: data.cap, canOpen, open, match,
1648
+ ...data.stores.map((store) => h(StoreSection, { key: store.id, store, cap: data.cap, canOpen, open, match, onMoved: load,
1317
1649
  kind: shown, now: state.at, t })),
1318
1650
  data.more ? h('p', { className: 'eng-note', key: 'more' }, t('more')) : null,
1319
1651
  ]