dsh-engramory 1.0.8 → 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 +8 -1
- package/README.md +1 -1
- package/client.js +265 -34
- package/index.js +3151 -3112
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -153,7 +153,14 @@ owner, so a program forwarding other people's messages must leave it out.
|
|
|
153
153
|
*Open the folder* open on the machine dsh runs on; a machine with no desktop (a
|
|
154
154
|
headless server, a session over SSH) shows none of them. The switches at the top
|
|
155
155
|
(companion mode, and memory access once it is on) save as you flip them. Below them
|
|
156
|
-
is a short *How to use it*, open while there is no memory yet;
|
|
156
|
+
is a short *How to use it*, open while there is no memory yet; then an overview (notes
|
|
157
|
+
by type, archived files, plans, notes past 12 KB, when it was read; it says when the
|
|
158
|
+
listing was cut short or a store could not be read, rather than counting that as
|
|
159
|
+
nothing), the plans by where they stand (date passed and outcome to confirm, today,
|
|
160
|
+
days ahead, undated; a reminder, nothing is archived), and a filter by name. Each
|
|
161
|
+
store's index fill is a bar (to the nearer of its two caps), and *Copy tidy-up
|
|
162
|
+
instructions* copies a request for the AI to paste into a conversation; the plugin
|
|
163
|
+
itself changes no file. Notes past 12 KB are listed as worth splitting. At the foot, where to
|
|
157
164
|
send feedback: a new GitHub issue (its body pre-filled with the plugin's version and the
|
|
158
165
|
OS family, no path and no note), or an email, with a button that copies the address.
|
|
159
166
|
|
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ agent.followup(createUserMessage({
|
|
|
77
77
|

|
|
78
78
|
|
|
79
79
|
- **设置页**:dsh 的「插件」页里点开「Engramory 记忆」,能改大肥鱼模式、记忆权限和索引上限。保存走 dsh 自己的配置服务,写进你 profile 的 `cordis.patch.yml` 并重新加载插件。这个接口只有登录了的你能调,AI 没法调用它关掉社交模式。
|
|
80
|
-
- **记忆页**:左侧栏「记忆」。列出全局库和各工作区的项目库(设了绝对路径的 `indexPath` 时只列那一个,相对路径则列不出),显示索引离上限还有多远、按类型分组的笔记名字和归档。每个库附一段体检:索引里指向不存在的文件、不在索引里的笔记(AI 回忆从索引开始,除非别的笔记链到它们,否则通常找不到)、没写类型的笔记。体检只按文件名和索引里的链接判断,不顺着符号链接走;索引超上限、要核对的太多或有文件读不了时不做,完整检查仍用 `engramory_doctor.py`。只读,不显示正文;点名字、「打开索引」「打开文件夹」都在运行 dsh 的那台机器上打开;没有桌面的机器(无界面服务器、SSH
|
|
80
|
+
- **记忆页**:左侧栏「记忆」。列出全局库和各工作区的项目库(设了绝对路径的 `indexPath` 时只列那一个,相对路径则列不出),显示索引离上限还有多远、按类型分组的笔记名字和归档。每个库附一段体检:索引里指向不存在的文件、不在索引里的笔记(AI 回忆从索引开始,除非别的笔记链到它们,否则通常找不到)、没写类型的笔记。体检只按文件名和索引里的链接判断,不顺着符号链接走;索引超上限、要核对的太多或有文件读不了时不做,完整检查仍用 `engramory_doctor.py`。只读,不显示正文;点名字、「打开索引」「打开文件夹」都在运行 dsh 的那台机器上打开;没有桌面的机器(无界面服务器、SSH 连过去的)不显示这些按钮。顶部的开关(大肥鱼模式,打开后还有记忆权限)拨了就保存。下面有一段「怎么用」,还没有记忆时自动展开;再下面是概览(各类型笔记数、归档文件数、约定、超过 12 KB 的笔记、读取时间;列表被截断或有库读不了时会注明,不把没列到的算成零)、约定看板(日期已过、结果待确认 / 今天 / 还有几天 / 未定日期,只是提醒,不会自动归档)和按名字筛选。每个库的索引用量画成进度条(两项上限里离得近的那一个),旁边的「复制整理指令」复制一段给 AI 的整理要求,粘贴进对话即可,插件本身不改任何文件;超过 12 KB 的笔记会单独列出,建议拆分。页底是反馈入口:到 GitHub 提 issue(正文预先写好插件版本和系统类型,不带路径和笔记),或发邮件,地址可以一键复制。
|
|
81
81
|
|
|
82
82
|
## 配置
|
|
83
83
|
|
package/client.js
CHANGED
|
@@ -27,7 +27,7 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
const SETTINGS_API = 'api/engramory/settings'
|
|
28
28
|
const MEMORY_API = 'api/engramory/memory'
|
|
29
29
|
/** This plugin's version, for the feedback footer; a test keeps it equal to package.json's. */
|
|
30
|
-
const VERSION = '1.0
|
|
30
|
+
const VERSION = '1.1.0'
|
|
31
31
|
/** Where feedback goes: a new issue on the repository, or the project's mailbox. Opening
|
|
32
32
|
* the link is the browser's (the desktop app hands it to the system's); the footer submits
|
|
33
33
|
* nothing by itself. */
|
|
@@ -35,6 +35,11 @@ window.__ModuleLoader__.load({
|
|
|
35
35
|
const EMAIL = 'engramory@agent.qq.com'
|
|
36
36
|
/** The how-to's lines, in order. */
|
|
37
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)/
|
|
38
43
|
const DEFAULT_LINES = 200
|
|
39
44
|
const DEFAULT_BYTES = 25600
|
|
40
45
|
/** The order the memory page shows note types in (SKILL.md §2, §2.2). */
|
|
@@ -114,7 +119,7 @@ window.__ModuleLoader__.load({
|
|
|
114
119
|
healthBrokenUnlisted: '索引里有指向不存在的文件,太多了,这里没列出。',
|
|
115
120
|
healthUnindexed: '不在索引里({count}):AI 回忆从索引开始,这些它通常找不到,除非别的笔记链到它们。',
|
|
116
121
|
healthUntyped: '没写类型或类型不认识({count}),列在「其他」里。',
|
|
117
|
-
healthFix: '
|
|
122
|
+
healthFix: '可以点上面的「复制整理指令」,粘贴进对话让 AI 整理。完整检查用 engramory_doctor.py。',
|
|
118
123
|
healthLarge: '要核对的太多,没做体检。',
|
|
119
124
|
healthUnreadable: '有文件读不了,没做体检。',
|
|
120
125
|
healthPartial: '文件太多没列全,没做体检。',
|
|
@@ -132,6 +137,30 @@ window.__ModuleLoader__.load({
|
|
|
132
137
|
copyFailed: '复制不了,请手动选中上面的地址。',
|
|
133
138
|
feedbackNote: '邮件会由 AI 助手协助整理,issue 是公开的,两处都别把记忆内容原样贴上去。插件版本 {version}。',
|
|
134
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改完再看一遍索引有没有超出上限,然后告诉我改了什么。',
|
|
135
164
|
}
|
|
136
165
|
const en = {
|
|
137
166
|
summary: 'Companion mode and memory access, and the index cap.',
|
|
@@ -207,7 +236,7 @@ window.__ModuleLoader__.load({
|
|
|
207
236
|
healthBrokenUnlisted: 'The index points to files that are not there: too many to list here.',
|
|
208
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.',
|
|
209
238
|
healthUntyped: 'No type, or one it does not know ({count}), listed under Other.',
|
|
210
|
-
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.',
|
|
211
240
|
healthLarge: 'Too much to check here, so no check-up.',
|
|
212
241
|
healthUnreadable: 'Some files could not be read, so no check-up.',
|
|
213
242
|
healthPartial: 'Too many files to list them all, so no check-up here.',
|
|
@@ -225,6 +254,30 @@ window.__ModuleLoader__.load({
|
|
|
225
254
|
copyFailed: 'Could not copy; select the address above by hand.',
|
|
226
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}.',
|
|
227
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.',
|
|
228
281
|
}
|
|
229
282
|
|
|
230
283
|
const CSS = `
|
|
@@ -272,7 +325,7 @@ window.__ModuleLoader__.load({
|
|
|
272
325
|
.eng-store-title{margin:0;font-size:14px;font-weight:500;line-height:22px;}
|
|
273
326
|
.eng-usage{font-size:12px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;}
|
|
274
327
|
.eng-usage[data-over="true"]{color:var(--dsw-alias-state-error-primary);}
|
|
275
|
-
.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;}
|
|
276
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;}
|
|
277
330
|
.eng-group{display:flex;flex-direction:column;gap:2px;}
|
|
278
331
|
.eng-group-title{margin:0;font-size:12px;font-weight:500;line-height:18px;color:var(--dsw-alias-label-secondary);}
|
|
@@ -296,6 +349,22 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
296
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);}
|
|
297
350
|
.eng-btn-small{padding:1px 8px;font-size:11.5px;}
|
|
298
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;}
|
|
299
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;}
|
|
300
369
|
`
|
|
301
370
|
|
|
@@ -568,7 +637,7 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
568
637
|
try {
|
|
569
638
|
const response = await request(MEMORY_API)
|
|
570
639
|
next = response.ok && Array.isArray(response.body?.stores)
|
|
571
|
-
? { phase: 'ready', data: response.body }
|
|
640
|
+
? { phase: 'ready', data: response.body, at: Date.now() }
|
|
572
641
|
: { phase: 'error', reason: response.status === 503 ? 'listTimeout' : 'listFailed' }
|
|
573
642
|
} catch {
|
|
574
643
|
next = { phase: 'error', reason: 'listFailed' }
|
|
@@ -589,6 +658,70 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
589
658
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
|
|
590
659
|
const byName = (a, b) => collator.compare(a, b)
|
|
591
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
|
+
|
|
592
725
|
/**
|
|
593
726
|
* A store's check-up (index.js checkUp): that nothing was found, what was, or why it
|
|
594
727
|
* did not run. An index over the cap is not checked, and the page already says so.
|
|
@@ -622,8 +755,16 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
622
755
|
h('p', { className: 'eng-note' }, t('healthFix')))
|
|
623
756
|
}
|
|
624
757
|
|
|
625
|
-
/**
|
|
626
|
-
|
|
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 }, [])
|
|
627
768
|
const title = store.kind === 'user' ? [t('storeUser'), ...store.titles].join(' · ')
|
|
628
769
|
: store.kind === 'pinned' ? [t('storePinned'), ...store.titles].join(' · ')
|
|
629
770
|
: store.titles.join(' · ')
|
|
@@ -633,41 +774,118 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
633
774
|
const usage = index === null ? t('noIndex')
|
|
634
775
|
: index.lines !== undefined ? t('usage', { lines: index.lines, maxLines: cap.maxLines, ...sizes })
|
|
635
776
|
: t(index.over ? 'usageOver' : 'usageSize', sizes)
|
|
777
|
+
const fill = index === null ? undefined : fillOf(index, cap)
|
|
636
778
|
const names = (list, archive) => h('ul', { className: 'eng-names' },
|
|
637
|
-
[...list].sort(byName).map((file) => h('li', { key: file },
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
|
|
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
|
+
}
|
|
644
790
|
return h('section', { className: 'eng-store' },
|
|
645
791
|
h('div', { className: 'eng-store-head' },
|
|
646
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))}%` } })),
|
|
647
797
|
h('span', { className: 'eng-usage', 'data-over': index?.over === true, title: index?.over ? t('overHint') : undefined }, usage),
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
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'))] : []))),
|
|
654
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,
|
|
655
812
|
index?.over ? h('p', { className: 'eng-note' }, t('overHint')) : null,
|
|
656
|
-
|
|
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,
|
|
657
818
|
...groups.map(([type, list]) => h('div', { className: 'eng-group', key: type },
|
|
658
819
|
h('h3', { className: 'eng-group-title' }, t('group', { type: t(typeKey(type)), count: list.length })),
|
|
659
820
|
names(list, false))),
|
|
660
|
-
|
|
661
|
-
h('summary', null, t('archive', { count:
|
|
662
|
-
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,
|
|
663
826
|
store.more ? h('p', { className: 'eng-note' }, t('more')) : null)
|
|
664
827
|
}
|
|
665
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
|
+
|
|
666
880
|
/** A store with anything in it: an index with text, a note, an archived note. A folder or an
|
|
667
881
|
* empty index alone is not memory yet. */
|
|
668
882
|
const hasMemory = (store) => (store.index !== null && store.index.bytes > 0) ||
|
|
669
883
|
store.notes.length > 0 || store.archive.length > 0
|
|
670
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
|
+
|
|
671
889
|
/** How to use it, in a few lines: open while there is no memory yet, folded once there is. */
|
|
672
890
|
function HowTo({ open, t }) {
|
|
673
891
|
return h('details', { className: 'eng-howto', open },
|
|
@@ -692,13 +910,7 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
692
910
|
const alive = useRef(true)
|
|
693
911
|
useEffect(() => () => { alive.current = false }, [])
|
|
694
912
|
const copyAddress = async () => {
|
|
695
|
-
|
|
696
|
-
try {
|
|
697
|
-
await globalThis.navigator.clipboard.writeText(EMAIL)
|
|
698
|
-
done = true
|
|
699
|
-
} catch {
|
|
700
|
-
// no clipboard here (a page served over plain http) or permission refused
|
|
701
|
-
}
|
|
913
|
+
const done = await copyText(EMAIL)
|
|
702
914
|
if (alive.current) setCopy(done ? 'copied' : 'copyFailed')
|
|
703
915
|
}
|
|
704
916
|
const href = `${ISSUES}?body=${encodeURIComponent(t('issueBody', { version: VERSION, os: osName() }))}`
|
|
@@ -718,6 +930,7 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
718
930
|
function MemoryPage({ t }) {
|
|
719
931
|
const { state, load } = useMemory()
|
|
720
932
|
const [status, setStatus] = useState(undefined)
|
|
933
|
+
const [query, setQuery] = useState('')
|
|
721
934
|
const alive = useRef(true)
|
|
722
935
|
useEffect(() => () => { alive.current = false }, [])
|
|
723
936
|
|
|
@@ -742,14 +955,32 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
742
955
|
|
|
743
956
|
const data = state.phase === 'ready' ? state.data : undefined
|
|
744
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)
|
|
745
962
|
let body
|
|
746
963
|
if (state.phase === 'loading') body = h('p', { className: 'eng-note' }, t('listing'))
|
|
747
964
|
else if (state.phase === 'error') body = h('div', { className: 'eng-banner', 'data-tone': 'error' }, t(state.reason))
|
|
748
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)
|
|
749
970
|
body = [
|
|
750
971
|
data.pinned === 'relative' ? h('p', { className: 'eng-note', key: 'pinned' }, t('pinnedRelative')) : null,
|
|
751
|
-
data.stores.length === 0 && data.pinned === undefined
|
|
752
|
-
|
|
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 })),
|
|
753
984
|
data.more ? h('p', { className: 'eng-note', key: 'more' }, t('more')) : null,
|
|
754
985
|
]
|
|
755
986
|
}
|
|
@@ -763,7 +994,7 @@ button.eng-name:disabled{cursor:default;opacity:.6;}
|
|
|
763
994
|
status ? h('div', { className: 'eng-banner', 'data-tone': status.tone, role: 'status' }, status.text) : null,
|
|
764
995
|
data !== undefined && !canOpen && data.stores.length > 0 ? h('p', { className: 'eng-note' }, t('openUnavailable')) : null,
|
|
765
996
|
h(HowTo, { open: data !== undefined && data.pinned !== 'relative' && data.more !== true &&
|
|
766
|
-
!data.stores.some(hasMemory), t }),
|
|
997
|
+
!(data.unreadable > 0) && !data.stores.some((store) => hasMemory(store) || readInPart(store)), t }),
|
|
767
998
|
body,
|
|
768
999
|
h(Feedback, { t }))
|
|
769
1000
|
}
|