dsh-engramory 1.0.7 → 1.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.en.md +249 -233
- package/README.md +141 -137
- package/client.js +359 -26
- package/index.js +3151 -3112
- package/package.json +79 -79
package/client.js
CHANGED
|
@@ -26,6 +26,20 @@ window.__ModuleLoader__.load({
|
|
|
26
26
|
/** Relative to the page, as dsh's own pages fetch, so a mounted deployment keeps its prefix. */
|
|
27
27
|
const SETTINGS_API = 'api/engramory/settings'
|
|
28
28
|
const MEMORY_API = 'api/engramory/memory'
|
|
29
|
+
/** This plugin's version, for the feedback footer; a test keeps it equal to package.json's. */
|
|
30
|
+
const VERSION = '1.1.0'
|
|
31
|
+
/** Where feedback goes: a new issue on the repository, or the project's mailbox. Opening
|
|
32
|
+
* the link is the browser's (the desktop app hands it to the system's); the footer submits
|
|
33
|
+
* nothing by itself. */
|
|
34
|
+
const ISSUES = 'https://github.com/tinqiao-oss/engramory/issues/new'
|
|
35
|
+
const EMAIL = 'engramory@agent.qq.com'
|
|
36
|
+
/** The how-to's lines, in order. */
|
|
37
|
+
const HOW_TO = ['howToSay', 'howToRecall', 'howToEdit', 'howToMove', 'howToSocial']
|
|
38
|
+
/** A note past this is almost always a timeline under one slug (SKILL.md: "A note has a size
|
|
39
|
+
* too"); the doctor warns at the same size (ENGRAMORY_NOTE_WARN_BYTES). */
|
|
40
|
+
const LARGE_NOTE = 12 * 1024
|
|
41
|
+
/** An `upcoming` note named with its date: `2026-10-31-interview`, `2026-10-31面试` (SKILL.md §2.2). */
|
|
42
|
+
const DATED = /^(\d{4})-(\d{2})-(\d{2})(?!\d)/
|
|
29
43
|
const DEFAULT_LINES = 200
|
|
30
44
|
const DEFAULT_BYTES = 25600
|
|
31
45
|
/** The order the memory page shows note types in (SKILL.md §2, §2.2). */
|
|
@@ -105,10 +119,48 @@ window.__ModuleLoader__.load({
|
|
|
105
119
|
healthBrokenUnlisted: '索引里有指向不存在的文件,太多了,这里没列出。',
|
|
106
120
|
healthUnindexed: '不在索引里({count}):AI 回忆从索引开始,这些它通常找不到,除非别的笔记链到它们。',
|
|
107
121
|
healthUntyped: '没写类型或类型不认识({count}),列在「其他」里。',
|
|
108
|
-
healthFix: '
|
|
122
|
+
healthFix: '可以点上面的「复制整理指令」,粘贴进对话让 AI 整理。完整检查用 engramory_doctor.py。',
|
|
109
123
|
healthLarge: '要核对的太多,没做体检。',
|
|
110
124
|
healthUnreadable: '有文件读不了,没做体检。',
|
|
111
125
|
healthPartial: '文件太多没列全,没做体检。',
|
|
126
|
+
howTo: '怎么用',
|
|
127
|
+
howToSay: '想让 AI 记住什么,直接跟它说,比如「记住:我习惯用 pnpm」「把这个决定记下来」。平时它也会尽量自己挑值得长期记住的记下来,比如你纠正过它的做法。',
|
|
128
|
+
howToRecall: '默认每次对话都会带上记忆的目录(索引),AI 用到细节时再打开那条笔记,不用你提醒。',
|
|
129
|
+
howToEdit: '这里列出读得到的记忆,打开笔记就能直接改;想让 AI 忘掉什么,跟它说「忘掉……」就行。',
|
|
130
|
+
howToMove: '记忆是存在运行 dsh 那台电脑上的普通 markdown 文件,位置写在每个库的标题下面。换电脑时把那个文件夹拷到新电脑的同一位置;在配置里指定过位置的,配置也一起带过去。',
|
|
131
|
+
howToSocial: '接了 QQ、微信等、别人也能跟你的 AI 聊的话,在上面打开「大肥鱼模式」,再把「记忆权限」改成「社交」:只有认得出是你本人的对话才拿得到记忆。这不是安全隔离,详见插件说明。',
|
|
132
|
+
feedbackLead: '遇到问题或有建议:',
|
|
133
|
+
feedbackIssue: '到 GitHub 提 issue',
|
|
134
|
+
feedbackMail: ',或发邮件到',
|
|
135
|
+
copy: '复制',
|
|
136
|
+
copied: '已复制',
|
|
137
|
+
copyFailed: '复制不了,请手动选中上面的地址。',
|
|
138
|
+
feedbackNote: '邮件会由 AI 助手协助整理,issue 是公开的,两处都别把记忆内容原样贴上去。插件版本 {version}。',
|
|
139
|
+
issueBody: '(写下遇到的问题或建议)\n\n---\ndsh-engramory {version}\n打开这个页面的电脑:{os}\ndsh 版本:',
|
|
140
|
+
overview: '概览',
|
|
141
|
+
statsNotes: '笔记 {notes} 条 · 归档文件 {archive} 个',
|
|
142
|
+
listSep: ',',
|
|
143
|
+
statsUpcoming: '约定:日期已过、结果待确认 {past} · 今天及以后 {ahead} · 未定日期 {undated}',
|
|
144
|
+
statsLarge: '超过 12 KB 的笔记 {count} 篇,建议拆分',
|
|
145
|
+
statsReadAt: '读取于 {time},约定按那时的日期算,点刷新更新。',
|
|
146
|
+
statsPartial: '列表太长,只列出了一部分,这些数字偏少。',
|
|
147
|
+
statsUnreadable: '有 {count} 处可能存放记忆库的位置没读到(读不了或查不了),没算在内。',
|
|
148
|
+
statsIncomplete: '有的库里有文件读不了,这些数字可能偏少。',
|
|
149
|
+
upcomingTitle: '约定',
|
|
150
|
+
upcomingPast: '日期已过,结果待确认',
|
|
151
|
+
upcomingToday: '就是今天',
|
|
152
|
+
upcomingTomorrow: '明天',
|
|
153
|
+
upcomingSoon: '还有 {days} 天',
|
|
154
|
+
upcomingUndated: '未定日期',
|
|
155
|
+
filterLabel: '筛选笔记',
|
|
156
|
+
filterPlaceholder: '按名字筛选',
|
|
157
|
+
filterCount: '匹配 {count} 条(只在已列出的笔记里找)',
|
|
158
|
+
filterNone: '这个库里没有匹配的笔记。',
|
|
159
|
+
largeNotes: '超过 12 KB 的笔记({count}):一条笔记该只记一件事,可以让 AI 拆成几篇。',
|
|
160
|
+
tidyCopy: '复制整理指令',
|
|
161
|
+
tidyCopied: '已复制,粘贴进对话发给 AI',
|
|
162
|
+
tidyFailed: '复制不了,请手动选中下面的指令:',
|
|
163
|
+
tidyPrompt: '请按 Engramory 的记忆规则整理这个记忆库:{dir}\n- 索引里指向不存在文件的链接:找得到对应笔记的就改对,确实没有了的只删这个链接;一行里没有别的有效链接了,才删掉整行。\n- 不在索引里的笔记:以后回忆用得上的补进索引,过时的移进 archive/ 或删掉;不要为了补齐全部加进去。\n- 没写类型的笔记补上 type。\n- 索引超出上限就先压缩:合并重复,细节挪回笔记,索引只留指针。\n- 超过约 12 KB 的笔记,按规则拆成几篇。\n- 日期已过的约定别删,问到结果再改写成经历。\n改完再看一遍索引有没有超出上限,然后告诉我改了什么。',
|
|
112
164
|
}
|
|
113
165
|
const en = {
|
|
114
166
|
summary: 'Companion mode and memory access, and the index cap.',
|
|
@@ -184,10 +236,48 @@ window.__ModuleLoader__.load({
|
|
|
184
236
|
healthBrokenUnlisted: 'The index points to files that are not there: too many to list here.',
|
|
185
237
|
healthUnindexed: 'Not in the index ({count}): recall starts from the index, so the AI will not find these unless another note links to them.',
|
|
186
238
|
healthUntyped: 'No type, or one it does not know ({count}), listed under Other.',
|
|
187
|
-
healthFix: '
|
|
239
|
+
healthFix: 'Copy the tidy-up instructions above and paste them into a conversation for the AI to tidy this up. For a full check, run engramory_doctor.py.',
|
|
188
240
|
healthLarge: 'Too much to check here, so no check-up.',
|
|
189
241
|
healthUnreadable: 'Some files could not be read, so no check-up.',
|
|
190
242
|
healthPartial: 'Too many files to list them all, so no check-up here.',
|
|
243
|
+
howTo: 'How to use it',
|
|
244
|
+
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.',
|
|
245
|
+
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.',
|
|
246
|
+
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 …".',
|
|
247
|
+
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.',
|
|
248
|
+
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.',
|
|
249
|
+
feedbackLead: 'Found a problem or have an idea? ',
|
|
250
|
+
feedbackIssue: 'Open an issue on GitHub',
|
|
251
|
+
feedbackMail: ', or email ',
|
|
252
|
+
copy: 'Copy',
|
|
253
|
+
copied: 'Copied',
|
|
254
|
+
copyFailed: 'Could not copy; select the address above by hand.',
|
|
255
|
+
feedbackNote: 'Emails are sorted with the help of an AI assistant, and issues are public: do not paste your memory notes into either. Plugin version {version}.',
|
|
256
|
+
issueBody: '(What happened, or your idea)\n\n---\ndsh-engramory {version}\nComputer this page was opened on: {os}\ndsh version: ',
|
|
257
|
+
overview: 'Overview',
|
|
258
|
+
statsNotes: '{notes} notes · {archive} archived files',
|
|
259
|
+
listSep: ', ',
|
|
260
|
+
statsUpcoming: 'Coming up: date passed, outcome to confirm {past} · today or ahead {ahead} · no date yet {undated}',
|
|
261
|
+
statsLarge: '{count} notes past 12 KB, worth splitting',
|
|
262
|
+
statsReadAt: 'Read at {time}; plans stand as of that day. Refresh to update.',
|
|
263
|
+
statsPartial: 'The listing was too long to finish, so these numbers fall short.',
|
|
264
|
+
statsUnreadable: '{count} places that may hold a memory store could not be read and are not counted.',
|
|
265
|
+
statsIncomplete: 'Some files in a store could not be read, so these numbers may fall short.',
|
|
266
|
+
upcomingTitle: 'Coming up',
|
|
267
|
+
upcomingPast: 'Date passed, outcome to confirm',
|
|
268
|
+
upcomingToday: 'Today',
|
|
269
|
+
upcomingTomorrow: 'Tomorrow',
|
|
270
|
+
upcomingSoon: 'In {days} days',
|
|
271
|
+
upcomingUndated: 'No date yet',
|
|
272
|
+
filterLabel: 'Filter notes',
|
|
273
|
+
filterPlaceholder: 'Filter by name',
|
|
274
|
+
filterCount: '{count} matching (among the notes listed)',
|
|
275
|
+
filterNone: 'No matching notes in this store.',
|
|
276
|
+
largeNotes: 'Notes past 12 KB ({count}): a note should hold one fact; the AI can split these.',
|
|
277
|
+
tidyCopy: 'Copy tidy-up instructions',
|
|
278
|
+
tidyCopied: 'Copied; paste it into a conversation',
|
|
279
|
+
tidyFailed: 'Could not copy; select the instructions below by hand:',
|
|
280
|
+
tidyPrompt: 'Tidy up this memory store by the Engramory rules: {dir}\n- Links in the index to files that are not there: fix the ones whose note you can find; where there is none, remove that link alone, and the line only when it has no other live link left.\n- Notes the index does not name: add the ones recall will need, move the outdated ones into archive/ or delete them; do not add them all just to be complete.\n- Notes with no type: give them one.\n- An index over its cap: compact it first by merging duplicates and moving detail back into the notes, so the index holds pointers only.\n- Notes past about 12 KB: split them as the rules say.\n- Plans whose date has passed: do not delete them; rewrite them as what happened once you learn the outcome.\nThen check the index is within its cap, and tell me what you changed.',
|
|
191
281
|
}
|
|
192
282
|
|
|
193
283
|
const CSS = `
|
|
@@ -235,7 +325,7 @@ window.__ModuleLoader__.load({
|
|
|
235
325
|
.eng-store-title{margin:0;font-size:14px;font-weight:500;line-height:22px;}
|
|
236
326
|
.eng-usage{font-size:12px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;}
|
|
237
327
|
.eng-usage[data-over="true"]{color:var(--dsw-alias-state-error-primary);}
|
|
238
|
-
.eng-store-actions{margin-left:auto;display:inline-flex;gap:8px;}
|
|
328
|
+
.eng-store-actions{margin-left:auto;display:inline-flex;flex-wrap:wrap;gap:8px;}
|
|
239
329
|
.eng-path{margin:-8px 0 0;font-family:var(--ds-font-family-code,ui-monospace,monospace);font-size:11.5px;line-height:18px;color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere;}
|
|
240
330
|
.eng-group{display:flex;flex-direction:column;gap:2px;}
|
|
241
331
|
.eng-group-title{margin:0;font-size:12px;font-weight:500;line-height:18px;color:var(--dsw-alias-label-secondary);}
|
|
@@ -249,6 +339,33 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
249
339
|
.eng-archive[open]>summary{margin-bottom:2px;}
|
|
250
340
|
.eng-health{display:flex;flex-direction:column;gap:8px;padding:10px 14px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-1);}
|
|
251
341
|
.eng-health-item{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);}
|
|
342
|
+
.eng-howto{box-sizing:border-box;padding:10px 14px;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-lg,10px);}
|
|
343
|
+
.eng-howto>summary{cursor:pointer;font-size:13px;font-weight:500;line-height:20px;}
|
|
344
|
+
.eng-howto ul{display:flex;flex-direction:column;gap:4px;margin:8px 0 2px;padding-left:18px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);}
|
|
345
|
+
.eng-feedback{display:flex;flex-direction:column;gap:2px;padding-top:16px;border-top:.5px solid var(--dsw-alias-border-l2);font-size:12px;line-height:22px;color:var(--dsw-alias-label-secondary);}
|
|
346
|
+
.eng-feedback p{margin:0;}
|
|
347
|
+
.eng-link{color:var(--dsw-alias-brand-primary);text-decoration:underline;text-underline-offset:2px;}
|
|
348
|
+
.eng-link:hover{opacity:.8;}
|
|
349
|
+
.eng-email{margin:0 8px 0 2px;font-family:var(--ds-font-family-code,ui-monospace,monospace);user-select:all;color:var(--dsw-alias-label-primary);}
|
|
350
|
+
.eng-btn-small{padding:1px 8px;font-size:11.5px;}
|
|
351
|
+
.eng-feedback-note{color:var(--dsw-alias-label-tertiary);}
|
|
352
|
+
.eng-overview,.eng-upcoming{box-sizing:border-box;display:flex;flex-direction:column;gap:4px;padding:12px 14px;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-lg,10px);}
|
|
353
|
+
.eng-overview-line{margin:0;font-size:13px;line-height:20px;}
|
|
354
|
+
.eng-overview-note{margin:2px 0 0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);}
|
|
355
|
+
.eng-upcoming-list{display:flex;flex-direction:column;gap:0;margin:4px -8px 0;padding:0;list-style:none;}
|
|
356
|
+
.eng-upcoming-list li{display:flex;align-items:center;gap:12px;}
|
|
357
|
+
.eng-upcoming-list .eng-name{width:auto;max-width:60%;}
|
|
358
|
+
.eng-upcoming-status{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);white-space:nowrap;}
|
|
359
|
+
.eng-upcoming-list li[data-status="past"] .eng-upcoming-status{color:var(--dsw-alias-label-primary);font-weight:600;}
|
|
360
|
+
.eng-filter{display:flex;align-items:center;gap:12px;flex-wrap:wrap;}
|
|
361
|
+
.eng-filter input{width:240px;}
|
|
362
|
+
.eng-filter-count,.eng-filter-none{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);}
|
|
363
|
+
.eng-meter{display:inline-block;width:96px;height:6px;border-radius:999px;background:var(--dsw-alias-border-l2);overflow:hidden;}
|
|
364
|
+
.eng-meter-fill{display:block;height:100%;border-radius:999px;background:var(--dsw-alias-label-secondary);}
|
|
365
|
+
.eng-meter[data-over="true"] .eng-meter-fill{background:var(--dsw-alias-state-error-primary);}
|
|
366
|
+
.eng-tidy{display:flex;flex-direction:column;gap:6px;}
|
|
367
|
+
.eng-tidy textarea{box-sizing:border-box;width:100%;min-height:150px;resize:vertical;font:inherit;font-size:12px;line-height:18px;}
|
|
368
|
+
.eng-link:focus-visible,.eng-howto>summary:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary));outline-offset:1px;}
|
|
252
369
|
`
|
|
253
370
|
|
|
254
371
|
/** The settings the page edits, in the order the host computes its revision from. */
|
|
@@ -520,7 +637,7 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
520
637
|
try {
|
|
521
638
|
const response = await request(MEMORY_API)
|
|
522
639
|
next = response.ok && Array.isArray(response.body?.stores)
|
|
523
|
-
? { phase: 'ready', data: response.body }
|
|
640
|
+
? { phase: 'ready', data: response.body, at: Date.now() }
|
|
524
641
|
: { phase: 'error', reason: response.status === 503 ? 'listTimeout' : 'listFailed' }
|
|
525
642
|
} catch {
|
|
526
643
|
next = { phase: 'error', reason: 'listFailed' }
|
|
@@ -541,6 +658,70 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
541
658
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
|
|
542
659
|
const byName = (a, b) => collator.compare(a, b)
|
|
543
660
|
|
|
661
|
+
/** Put `text` on the clipboard; false where there is none (a page over plain http) or it is refused. */
|
|
662
|
+
async function copyText(text) {
|
|
663
|
+
try {
|
|
664
|
+
await globalThis.navigator.clipboard.writeText(text)
|
|
665
|
+
return true
|
|
666
|
+
} catch {
|
|
667
|
+
return false
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** The date an `upcoming` note is named with, if it is a real day: `YYYY-MM-DD`, else undefined. */
|
|
672
|
+
function dateOf(file) {
|
|
673
|
+
const m = DATED.exec(nameOf(file))
|
|
674
|
+
if (m === null) return undefined
|
|
675
|
+
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])]
|
|
676
|
+
const day = new Date(Date.UTC(y, mo - 1, d))
|
|
677
|
+
return day.getUTCFullYear() === y && day.getUTCMonth() === mo - 1 && day.getUTCDate() === d
|
|
678
|
+
? `${m[1]}-${m[2]}-${m[3]}` : undefined
|
|
679
|
+
}
|
|
680
|
+
/** A `YYYY-MM-DD` day as a number of days, to subtract one from another. */
|
|
681
|
+
const dayNumber = (date) => Date.UTC(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1,
|
|
682
|
+
Number(date.slice(8, 10))) / 86400000
|
|
683
|
+
/** Today on this computer's calendar, as `YYYY-MM-DD`. */
|
|
684
|
+
function todayOf(now) {
|
|
685
|
+
const d = new Date(now)
|
|
686
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Every `upcoming` note listed, against today on this computer: a date passed only says
|
|
691
|
+
* the outcome is yet to be asked about (SKILL.md §2.2 keeps the note until it is known),
|
|
692
|
+
* so nothing here is called late or stale. Passed first, then the nearest, then undated.
|
|
693
|
+
*/
|
|
694
|
+
function upcomingOf(stores, now) {
|
|
695
|
+
const today = dayNumber(todayOf(now))
|
|
696
|
+
const items = []
|
|
697
|
+
for (const store of stores) {
|
|
698
|
+
for (const note of store.notes) {
|
|
699
|
+
if (note.type !== 'upcoming') continue
|
|
700
|
+
const date = dateOf(note.name)
|
|
701
|
+
const days = date === undefined ? undefined : dayNumber(date) - today
|
|
702
|
+
const status = days === undefined ? 'undated' : days < 0 ? 'past' : days === 0 ? 'today' : 'ahead'
|
|
703
|
+
items.push({ store, name: note.name, days, status })
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
const rank = { past: 0, today: 1, ahead: 2, undated: 3 }
|
|
707
|
+
return items.sort((a, b) => rank[a.status] - rank[b.status] || (a.days ?? 0) - (b.days ?? 0) ||
|
|
708
|
+
byName(a.name, b.name))
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** How full an index is, the nearer of its two caps; its lines only when they were counted. */
|
|
712
|
+
function fillOf(index, cap) {
|
|
713
|
+
const lines = index.lines === undefined ? 0 : index.lines / cap.maxLines
|
|
714
|
+
return Math.max(lines, index.bytes / cap.maxBytes)
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** A name, to open where dsh can, as text where it cannot. */
|
|
718
|
+
function noteName(store, file, archived, canOpen, open) {
|
|
719
|
+
return canOpen
|
|
720
|
+
? h('button', { type: 'button', className: 'eng-name', title: file,
|
|
721
|
+
onClick: () => open(store, file, archived) }, nameOf(file))
|
|
722
|
+
: h('span', { className: 'eng-name', title: file }, nameOf(file))
|
|
723
|
+
}
|
|
724
|
+
|
|
544
725
|
/**
|
|
545
726
|
* A store's check-up (index.js checkUp): that nothing was found, what was, or why it
|
|
546
727
|
* did not run. An index over the cap is not checked, and the page already says so.
|
|
@@ -574,8 +755,16 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
574
755
|
h('p', { className: 'eng-note' }, t('healthFix')))
|
|
575
756
|
}
|
|
576
757
|
|
|
577
|
-
/**
|
|
578
|
-
|
|
758
|
+
/**
|
|
759
|
+
* One store: where it is, how full its index is (as a bar, the nearer of its two caps), its
|
|
760
|
+
* check-up, its notes grown past what one fact needs, and its notes' names by type — those
|
|
761
|
+
* `match` keeps while the page is filtering. Its tidy-up instructions are copied for the
|
|
762
|
+
* user to hand the AI in a conversation; where there is no clipboard, shown to select.
|
|
763
|
+
*/
|
|
764
|
+
function StoreSection({ store, cap, canOpen, open, match, t }) {
|
|
765
|
+
const [tidy, setTidy] = useState('idle')
|
|
766
|
+
const alive = useRef(true)
|
|
767
|
+
useEffect(() => () => { alive.current = false }, [])
|
|
579
768
|
const title = store.kind === 'user' ? [t('storeUser'), ...store.titles].join(' · ')
|
|
580
769
|
: store.kind === 'pinned' ? [t('storePinned'), ...store.titles].join(' · ')
|
|
581
770
|
: store.titles.join(' · ')
|
|
@@ -585,40 +774,163 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
585
774
|
const usage = index === null ? t('noIndex')
|
|
586
775
|
: index.lines !== undefined ? t('usage', { lines: index.lines, maxLines: cap.maxLines, ...sizes })
|
|
587
776
|
: t(index.over ? 'usageOver' : 'usageSize', sizes)
|
|
777
|
+
const fill = index === null ? undefined : fillOf(index, cap)
|
|
588
778
|
const names = (list, archive) => h('ul', { className: 'eng-names' },
|
|
589
|
-
[...list].sort(byName).map((file) => h('li', { key: file },
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
779
|
+
[...list].sort(byName).map((file) => h('li', { key: file }, noteName(store, file, archive, canOpen, open))))
|
|
780
|
+
const keep = (file) => match === undefined || match(file)
|
|
781
|
+
const groups = TYPES.map((type) => [type, store.notes.filter((note) => note.type === type && keep(note.name))
|
|
782
|
+
.map((note) => note.name)]).filter(([, list]) => list.length > 0)
|
|
783
|
+
const archived = store.archive.filter(keep)
|
|
784
|
+
const large = store.notes.filter((note) => note.bytes > LARGE_NOTE).map((note) => note.name)
|
|
785
|
+
const prompt = t('tidyPrompt', { dir: store.dir })
|
|
786
|
+
const copyTidy = async () => {
|
|
787
|
+
const done = await copyText(prompt)
|
|
788
|
+
if (alive.current) setTidy(done ? 'copied' : 'failed')
|
|
789
|
+
}
|
|
596
790
|
return h('section', { className: 'eng-store' },
|
|
597
791
|
h('div', { className: 'eng-store-head' },
|
|
598
792
|
h('h2', { className: 'eng-store-title' }, title),
|
|
793
|
+
// the nearer cap, whichever it is; over it, full and marked, not a bar that stops at the edge
|
|
794
|
+
fill === undefined ? null : h('span', { className: 'eng-meter', 'data-over': index.over === true || fill > 1,
|
|
795
|
+
'aria-hidden': true },
|
|
796
|
+
h('span', { className: 'eng-meter-fill', style: { width: `${Math.min(100, Math.floor(fill * 100))}%` } })),
|
|
599
797
|
h('span', { className: 'eng-usage', 'data-over': index?.over === true, title: index?.over ? t('overHint') : undefined }, usage),
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
798
|
+
h('div', { className: 'eng-store-actions' },
|
|
799
|
+
h('button', { type: 'button', className: 'eng-btn', onClick: copyTidy },
|
|
800
|
+
t(tidy === 'copied' ? 'tidyCopied' : 'tidyCopy')),
|
|
801
|
+
// the folder is shown with its index selected: no index, no folder to show
|
|
802
|
+
...(canOpen && index !== null ? [
|
|
803
|
+
h('button', { type: 'button', className: 'eng-btn', key: 'index',
|
|
804
|
+
onClick: () => open(store, index.name, false) }, t('openIndex')),
|
|
805
|
+
h('button', { type: 'button', className: 'eng-btn', key: 'folder',
|
|
806
|
+
onClick: () => open(store, undefined, false) }, t('openFolder'))] : []))),
|
|
606
807
|
h('p', { className: 'eng-path' }, store.dir),
|
|
808
|
+
tidy === 'failed' ? h('div', { className: 'eng-tidy', role: 'status' },
|
|
809
|
+
h('p', { className: 'eng-health-item' }, t('tidyFailed')),
|
|
810
|
+
h('textarea', { readOnly: true, value: prompt, 'aria-label': t('tidyCopy'),
|
|
811
|
+
onFocus: (event) => event.target.select() })) : null,
|
|
607
812
|
index?.over ? h('p', { className: 'eng-note' }, t('overHint')) : null,
|
|
608
|
-
|
|
813
|
+
// while filtering, the names that match and nothing else: the check-up comes back after
|
|
814
|
+
match === undefined ? h(Health, { store, names, t }) : null,
|
|
815
|
+
match === undefined && large.length > 0 ? h('div', { className: 'eng-group' },
|
|
816
|
+
h('p', { className: 'eng-health-item' }, t('largeNotes', { count: large.length })),
|
|
817
|
+
names(large, false)) : null,
|
|
609
818
|
...groups.map(([type, list]) => h('div', { className: 'eng-group', key: type },
|
|
610
819
|
h('h3', { className: 'eng-group-title' }, t('group', { type: t(typeKey(type)), count: list.length })),
|
|
611
820
|
names(list, false))),
|
|
612
|
-
|
|
613
|
-
h('summary', null, t('archive', { count:
|
|
614
|
-
names(
|
|
821
|
+
archived.length > 0 ? h('details', { className: 'eng-archive', open: match === undefined ? undefined : true },
|
|
822
|
+
h('summary', null, t('archive', { count: archived.length })),
|
|
823
|
+
names(archived, true)) : null,
|
|
824
|
+
match !== undefined && groups.length === 0 && archived.length === 0
|
|
825
|
+
? h('p', { className: 'eng-filter-none' }, t('filterNone')) : null,
|
|
615
826
|
store.more ? h('p', { className: 'eng-note' }, t('more')) : null)
|
|
616
827
|
}
|
|
617
828
|
|
|
829
|
+
/** When a listing was read, its day with its time, as this computer shows them. */
|
|
830
|
+
const timeOf = (at) => new Date(at).toLocaleString([], { month: '2-digit', day: '2-digit', hour: '2-digit',
|
|
831
|
+
minute: '2-digit' })
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* The listing in numbers, as read at `at`: notes by type, archived files, plans, notes past
|
|
835
|
+
* the size one fact needs — and whether that is all there is (a listing cut short, stores
|
|
836
|
+
* that could not be read), since what was not listed is not counted as nothing.
|
|
837
|
+
*/
|
|
838
|
+
function Overview({ data, at, upcoming, t }) {
|
|
839
|
+
const notes = data.stores.flatMap((store) => store.notes)
|
|
840
|
+
const archive = data.stores.reduce((sum, store) => sum + store.archive.length, 0)
|
|
841
|
+
// a note it could not read has no type to count: the counts say the store was read in part
|
|
842
|
+
const types = TYPES.map((type) => [type, notes.filter((note) => note.type === type && !note.unread).length])
|
|
843
|
+
.filter(([, count]) => count > 0)
|
|
844
|
+
const large = notes.filter((note) => note.bytes > LARGE_NOTE).length
|
|
845
|
+
const partial = data.more === true || data.stores.some((store) => store.more)
|
|
846
|
+
// a note or a folder it could not read: the check-up says so, and the counts may fall short
|
|
847
|
+
const incomplete = data.stores.some((store) => store.health?.checked === false &&
|
|
848
|
+
store.health.reason === 'unreadable')
|
|
849
|
+
const count = (...statuses) => upcoming.filter((item) => statuses.includes(item.status)).length
|
|
850
|
+
return h('section', { className: 'eng-overview', 'aria-label': t('overview') },
|
|
851
|
+
h('h2', { className: 'eng-store-title' }, t('overview')),
|
|
852
|
+
h('p', { className: 'eng-overview-line' }, t('statsNotes', { notes: notes.length, archive })),
|
|
853
|
+
types.length > 0 ? h('p', { className: 'eng-overview-line' },
|
|
854
|
+
types.map(([type, n]) => t('group', { type: t(typeKey(type)), count: n })).join(t('listSep'))) : null,
|
|
855
|
+
upcoming.length > 0 ? h('p', { className: 'eng-overview-line' },
|
|
856
|
+
t('statsUpcoming', { past: count('past'), ahead: count('today', 'ahead'), undated: count('undated') })) : null,
|
|
857
|
+
large > 0 ? h('p', { className: 'eng-overview-line' }, t('statsLarge', { count: large })) : null,
|
|
858
|
+
h('p', { className: 'eng-overview-note' }, [
|
|
859
|
+
t('statsReadAt', { time: timeOf(at) }),
|
|
860
|
+
partial ? t('statsPartial') : null,
|
|
861
|
+
incomplete ? t('statsIncomplete') : null,
|
|
862
|
+
data.unreadable > 0 ? t('statsUnreadable', { count: data.unreadable }) : null,
|
|
863
|
+
].filter((text) => text !== null).join(' ')))
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** The plans listed, by where they stand against today, names to open as everywhere else. */
|
|
867
|
+
function UpcomingBoard({ items, canOpen, open, t }) {
|
|
868
|
+
const status = (item) => (item.status === 'past' ? t('upcomingPast')
|
|
869
|
+
: item.status === 'today' ? t('upcomingToday')
|
|
870
|
+
: item.status === 'undated' ? t('upcomingUndated')
|
|
871
|
+
: item.days === 1 ? t('upcomingTomorrow') : t('upcomingSoon', { days: item.days }))
|
|
872
|
+
return h('section', { className: 'eng-upcoming', 'aria-label': t('upcomingTitle') },
|
|
873
|
+
h('h2', { className: 'eng-store-title' }, t('upcomingTitle')),
|
|
874
|
+
h('ul', { className: 'eng-upcoming-list' }, items.map((item) => h('li', { key: `${item.store.id}/${item.name}`,
|
|
875
|
+
'data-status': item.status },
|
|
876
|
+
noteName(item.store, item.name, false, canOpen, open),
|
|
877
|
+
h('span', { className: 'eng-upcoming-status' }, status(item))))))
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/** A store with anything in it: an index with text, a note, an archived note. A folder or an
|
|
881
|
+
* empty index alone is not memory yet. */
|
|
882
|
+
const hasMemory = (store) => (store.index !== null && store.index.bytes > 0) ||
|
|
883
|
+
store.notes.length > 0 || store.archive.length > 0
|
|
884
|
+
|
|
885
|
+
/** A store not read to its end: a listing cut short, or a file or folder it could not read. */
|
|
886
|
+
const readInPart = (store) => store.more === true ||
|
|
887
|
+
(store.health?.checked === false && store.health.reason === 'unreadable')
|
|
888
|
+
|
|
889
|
+
/** How to use it, in a few lines: open while there is no memory yet, folded once there is. */
|
|
890
|
+
function HowTo({ open, t }) {
|
|
891
|
+
return h('details', { className: 'eng-howto', open },
|
|
892
|
+
h('summary', null, t('howTo')),
|
|
893
|
+
h('ul', null, HOW_TO.map((key) => h('li', { key }, t(key)))))
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** The OS family for a bug report, and nothing that tells one machine from another. */
|
|
897
|
+
function osName() {
|
|
898
|
+
const platform = String(globalThis.navigator?.userAgentData?.platform ?? globalThis.navigator?.platform ?? '')
|
|
899
|
+
return /^win/i.test(platform) ? 'Windows' : /^mac/i.test(platform) ? 'macOS'
|
|
900
|
+
: /linux/i.test(platform) ? 'Linux' : 'unknown'
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Where to report a problem or send an idea: a new issue, its body started with the
|
|
905
|
+
* plugin's version and the OS (no path, no note), or the mailbox, whose address the
|
|
906
|
+
* button copies — the desktop app opens only web links, not `mailto:`.
|
|
907
|
+
*/
|
|
908
|
+
function Feedback({ t }) {
|
|
909
|
+
const [copy, setCopy] = useState('copy')
|
|
910
|
+
const alive = useRef(true)
|
|
911
|
+
useEffect(() => () => { alive.current = false }, [])
|
|
912
|
+
const copyAddress = async () => {
|
|
913
|
+
const done = await copyText(EMAIL)
|
|
914
|
+
if (alive.current) setCopy(done ? 'copied' : 'copyFailed')
|
|
915
|
+
}
|
|
916
|
+
const href = `${ISSUES}?body=${encodeURIComponent(t('issueBody', { version: VERSION, os: osName() }))}`
|
|
917
|
+
return h('footer', { className: 'eng-feedback' },
|
|
918
|
+
h('p', null,
|
|
919
|
+
t('feedbackLead'),
|
|
920
|
+
h('a', { className: 'eng-link', href, target: '_blank', rel: 'noopener noreferrer' }, t('feedbackIssue')),
|
|
921
|
+
t('feedbackMail'),
|
|
922
|
+
h('span', { className: 'eng-email' }, EMAIL),
|
|
923
|
+
h('button', { type: 'button', className: 'eng-btn eng-btn-small', onClick: copyAddress },
|
|
924
|
+
t(copy === 'copied' ? 'copied' : 'copy'))),
|
|
925
|
+
copy === 'copyFailed' ? h('p', { className: 'eng-feedback-note', role: 'status' }, t('copyFailed')) : null,
|
|
926
|
+
h('p', { className: 'eng-feedback-note' }, t('feedbackNote', { version: VERSION })))
|
|
927
|
+
}
|
|
928
|
+
|
|
618
929
|
/** The sidebar's Memory page: the stores recall can use, by name, and two settings. */
|
|
619
930
|
function MemoryPage({ t }) {
|
|
620
931
|
const { state, load } = useMemory()
|
|
621
932
|
const [status, setStatus] = useState(undefined)
|
|
933
|
+
const [query, setQuery] = useState('')
|
|
622
934
|
const alive = useRef(true)
|
|
623
935
|
useEffect(() => () => { alive.current = false }, [])
|
|
624
936
|
|
|
@@ -643,14 +955,32 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
643
955
|
|
|
644
956
|
const data = state.phase === 'ready' ? state.data : undefined
|
|
645
957
|
const canOpen = data?.canOpen === true
|
|
958
|
+
// a name filter over what was listed: case- and width-insensitive, the .md left out
|
|
959
|
+
const needle = query.trim().normalize('NFKC').toLowerCase()
|
|
960
|
+
const match = needle === '' ? undefined
|
|
961
|
+
: (file) => nameOf(file).normalize('NFKC').toLowerCase().includes(needle)
|
|
646
962
|
let body
|
|
647
963
|
if (state.phase === 'loading') body = h('p', { className: 'eng-note' }, t('listing'))
|
|
648
964
|
else if (state.phase === 'error') body = h('div', { className: 'eng-banner', 'data-tone': 'error' }, t(state.reason))
|
|
649
965
|
else {
|
|
966
|
+
const upcoming = upcomingOf(data.stores, state.at)
|
|
967
|
+
const listed = data.stores.some((store) => store.notes.length + store.archive.length > 0)
|
|
968
|
+
const matched = match === undefined ? 0 : data.stores.reduce((sum, store) =>
|
|
969
|
+
sum + store.notes.filter((note) => match(note.name)).length + store.archive.filter(match).length, 0)
|
|
650
970
|
body = [
|
|
651
971
|
data.pinned === 'relative' ? h('p', { className: 'eng-note', key: 'pinned' }, t('pinnedRelative')) : null,
|
|
652
|
-
data.stores.length === 0 && data.pinned === undefined
|
|
653
|
-
|
|
972
|
+
data.stores.length === 0 && data.pinned === undefined && !(data.unreadable > 0) && data.more !== true
|
|
973
|
+
? h('p', { className: 'eng-note', key: 'empty' }, t('empty')) : null,
|
|
974
|
+
data.stores.length > 0 || data.unreadable > 0
|
|
975
|
+
? h(Overview, { key: 'overview', data, at: state.at, upcoming, t }) : null,
|
|
976
|
+
upcoming.length > 0 ? h(UpcomingBoard, { key: 'upcoming', items: upcoming, canOpen, open, t }) : null,
|
|
977
|
+
listed ? h('div', { className: 'eng-filter', key: 'filter' },
|
|
978
|
+
h('input', { type: 'search', className: 'eng-input', value: query, placeholder: t('filterPlaceholder'),
|
|
979
|
+
'aria-label': t('filterLabel'), onChange: (event) => setQuery(event.target.value) }),
|
|
980
|
+
match === undefined ? null : h('p', { className: 'eng-filter-count', role: 'status', 'aria-live': 'polite' },
|
|
981
|
+
t('filterCount', { count: matched })))
|
|
982
|
+
: null,
|
|
983
|
+
...data.stores.map((store) => h(StoreSection, { key: store.id, store, cap: data.cap, canOpen, open, match, t })),
|
|
654
984
|
data.more ? h('p', { className: 'eng-note', key: 'more' }, t('more')) : null,
|
|
655
985
|
]
|
|
656
986
|
}
|
|
@@ -663,7 +993,10 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
663
993
|
h(SettingsStrip, { t }),
|
|
664
994
|
status ? h('div', { className: 'eng-banner', 'data-tone': status.tone, role: 'status' }, status.text) : null,
|
|
665
995
|
data !== undefined && !canOpen && data.stores.length > 0 ? h('p', { className: 'eng-note' }, t('openUnavailable')) : null,
|
|
666
|
-
|
|
996
|
+
h(HowTo, { open: data !== undefined && data.pinned !== 'relative' && data.more !== true &&
|
|
997
|
+
!(data.unreadable > 0) && !data.stores.some((store) => hasMemory(store) || readInPart(store)), t }),
|
|
998
|
+
body,
|
|
999
|
+
h(Feedback, { t }))
|
|
667
1000
|
}
|
|
668
1001
|
|
|
669
1002
|
/** The sidebar entry's icon: the logo, [[ ]] around a cursor, drawn in the row's own colour
|