dsh-feiyu-memgate 0.3.2 → 0.5.1

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 (116) hide show
  1. package/CHANGELOG.md +119 -12
  2. package/README.md +130 -15
  3. package/README.zh.md +154 -39
  4. package/client/README.md +279 -0
  5. package/client/art/mascot-asleep.webp +0 -0
  6. package/client/art/mascot-busy.webp +0 -0
  7. package/client/art/mascot-nag.webp +0 -0
  8. package/client/art/mascot-ready.webp +0 -0
  9. package/client/art/mascot-trouble.webp +0 -0
  10. package/client/client.js +5540 -1280
  11. package/client/src/clipboard.cjs +52 -0
  12. package/client/src/constants.cjs +54 -0
  13. package/client/src/fields.cjs +1048 -0
  14. package/client/src/hooks.cjs +495 -0
  15. package/client/src/i18n.cjs +596 -0
  16. package/client/src/index.cjs +76 -0
  17. package/client/src/kit/controls.cjs +206 -0
  18. package/client/src/kit/icons.cjs +41 -0
  19. package/client/src/kit/layout.cjs +124 -0
  20. package/client/src/layout.cjs +154 -0
  21. package/client/src/model/changelog.cjs +29 -0
  22. package/client/src/model/core.cjs +105 -0
  23. package/client/src/model/feedback.cjs +168 -0
  24. package/client/src/model/form.cjs +83 -0
  25. package/client/src/model/memories.cjs +277 -0
  26. package/client/src/model/models.cjs +87 -0
  27. package/client/src/model/overview.cjs +111 -0
  28. package/client/src/model/page.cjs +104 -0
  29. package/client/src/model/status.cjs +57 -0
  30. package/client/src/model/trial.cjs +125 -0
  31. package/client/src/net.cjs +131 -0
  32. package/client/src/react.cjs +11 -0
  33. package/client/src/theme/page.css +1481 -0
  34. package/client/src/theme/styles.cjs +43 -0
  35. package/client/src/view/core.cjs +80 -0
  36. package/client/src/view/feedback.cjs +180 -0
  37. package/client/src/view/field-row.cjs +98 -0
  38. package/client/src/view/hero.cjs +54 -0
  39. package/client/src/view/markdown.cjs +96 -0
  40. package/client/src/view/memories.cjs +181 -0
  41. package/client/src/view/models.cjs +154 -0
  42. package/client/src/view/page.cjs +215 -0
  43. package/client/src/view/settings-tab.cjs +78 -0
  44. package/client/src/view/tabs.cjs +71 -0
  45. package/client/src/view/trial.cjs +106 -0
  46. package/docs/DETAIL.en.md +99 -8
  47. package/docs/DETAIL.md +107 -16
  48. package/locale/zh.json +1 -1
  49. package/package.json +2 -1
  50. package/python/GATEWAY_VERSION.json +47 -33
  51. package/python/feiyu_memgate/__init__.py +1 -1
  52. package/python/feiyu_memgate/backends/_sqlfile.py +430 -0
  53. package/python/feiyu_memgate/backends/base.py +216 -7
  54. package/python/feiyu_memgate/backends/embedding.py +722 -204
  55. package/python/feiyu_memgate/backends/hybrid.py +466 -86
  56. package/python/feiyu_memgate/backends/inmemory.py +245 -34
  57. package/python/feiyu_memgate/backends/openviking.py +7 -10
  58. package/python/feiyu_memgate/backends/sqlite.py +512 -218
  59. package/python/feiyu_memgate/builtins.py +1 -0
  60. package/python/feiyu_memgate/cli.py +869 -24
  61. package/python/feiyu_memgate/client/block.py +8 -2
  62. package/python/feiyu_memgate/client/http.py +339 -27
  63. package/python/feiyu_memgate/client/local.py +16 -5
  64. package/python/feiyu_memgate/config.py +167 -25
  65. package/python/feiyu_memgate/core/dates.py +762 -0
  66. package/python/feiyu_memgate/core/limits.py +2 -1
  67. package/python/feiyu_memgate/core/pool.py +29 -2
  68. package/python/feiyu_memgate/core/recall.py +197 -10
  69. package/python/feiyu_memgate/core/redact.py +4 -2
  70. package/python/feiyu_memgate/core/stages.py +594 -22
  71. package/python/feiyu_memgate/core/tidy.py +247 -28
  72. package/python/feiyu_memgate/core/watch.py +3 -2
  73. package/python/feiyu_memgate/core/write.py +20 -4
  74. package/python/feiyu_memgate/forgetting/archive.py +49 -10
  75. package/python/feiyu_memgate/forgetting/engine.py +78 -9
  76. package/python/feiyu_memgate/forgetting/stage.py +4 -2
  77. package/python/feiyu_memgate/gateway/app.py +841 -276
  78. package/python/feiyu_memgate/gateway/fields.py +126 -0
  79. package/python/feiyu_memgate/gateway/policies.py +266 -0
  80. package/python/feiyu_memgate/gateway/server.py +23 -5
  81. package/python/feiyu_memgate/gateway/tokens.py +137 -0
  82. package/python/feiyu_memgate/gateway/validate.py +173 -0
  83. package/python/feiyu_memgate/identity.py +152 -0
  84. package/python/feiyu_memgate/mcp/__init__.py +64 -0
  85. package/python/feiyu_memgate/mcp/protocol.py +330 -0
  86. package/python/feiyu_memgate/mcp/tools.py +321 -0
  87. package/python/feiyu_memgate/model.py +293 -2
  88. package/python/feiyu_memgate/registry.py +6 -3
  89. package/python/feiyu_memgate/standing/__init__.py +11 -0
  90. package/python/feiyu_memgate/standing/engine.py +98 -0
  91. package/python/feiyu_memgate/standing/select.py +79 -0
  92. package/python/feiyu_memgate/standing/state.py +127 -0
  93. package/python/feiyu_memgate/tools/crypto.py +5 -4
  94. package/python/feiyu_memgate/tools/evaluate.py +2 -1
  95. package/python/feiyu_memgate/tools/tenants.py +2 -0
  96. package/src/block.js +13 -3
  97. package/src/capture.js +98 -0
  98. package/src/catalogue.js +4 -4
  99. package/src/changelog.js +72 -0
  100. package/src/client.js +411 -12
  101. package/src/commands.js +112 -62
  102. package/src/config.js +171 -62
  103. package/src/followup.js +139 -0
  104. package/src/gateway.js +112 -6
  105. package/src/migrate.py +118 -16
  106. package/src/mirror.py +91 -7
  107. package/src/plugin.js +564 -415
  108. package/src/pool.js +369 -0
  109. package/src/recent.js +68 -0
  110. package/src/relevance.js +80 -0
  111. package/src/routes.js +490 -0
  112. package/src/setup.js +36 -36
  113. package/src/shared.js +135 -0
  114. package/src/tiers.js +4 -4
  115. package/src/time.js +27 -0
  116. package/src/tools.js +208 -0
@@ -0,0 +1,279 @@
1
+ # The settings page (browser half)
2
+
3
+ `client/client.js` is the browser half of dsh-feiyu-memgate: the settings page of the plugin's row on the
4
+ Plugins page. It is a **generated file**. The source is the set of small modules under `client/src/`;
5
+ `npm run build-client` joins them into `client/client.js`. Edit the modules, never the generated file.
6
+
7
+ ## What the host loads
8
+
9
+ The host serves a package's `./client` export to the page as one script in the client module system's
10
+ lazy-CJS form: it registers the package name and a `factory(require)` with the page's module loader, and
11
+ `require` answers only the page's shared module table (`docs/cookbook/adding-a-settings-card.md`
12
+ section 5; `packages/client/modules/README.md` "What the browser loads" and "Sharing modules"). So the
13
+ script must be one file, written as plain JavaScript (React elements are built with `createElement`, no
14
+ JSX), and the only module it asks for is `react`. The page does not use the host's UI primitives: its
15
+ controls are its own (`kit/`), and its stylesheet is `theme/page.css`.
16
+
17
+ ## How the file is assembled
18
+
19
+ `scripts/build-client.mjs` reads every `*.cjs` and `*.css` file under `client/src` (sorted by path, line
20
+ endings turned into LF) and writes `client/client.js`: a header comment, the
21
+ `window.__ModuleLoader__.load({ id: 'dsh-feiyu-memgate', factory })` call, a small registry (`define`,
22
+ `load` with a cache, a `require` per module that resolves `./x` and `../x` against the requiring module's
23
+ path and passes every other name to the host's `require`), one `define` per file with its text indented,
24
+ and `return load('index.cjs')`. Nothing is transpiled and nothing is minified; the output does not depend
25
+ on the platform, the date or the path of the checkout.
26
+
27
+ A `.css` file becomes a module that exports its text as a string (`theme/styles.cjs` puts it into the
28
+ document).
29
+
30
+ Because the text of a module is indented, a module must not contain a template literal that spans lines.
31
+
32
+ ## The modules
33
+
34
+ Ids are paths relative to `client/src`.
35
+
36
+ **Wiring**
37
+
38
+ | module | holds |
39
+ |---|---|
40
+ | `index.cjs` | the entry point: `name`, `inject`, `apply(ctx)` (registers the dictionaries, the stylesheet and the page in the row slot) and the `internals` export for tests and the preview |
41
+ | `react.cjs` | the one place that asks the host for React: `{ React, h, useEffect, useRef, useState }` |
42
+
43
+ **Tables**
44
+
45
+ | module | holds |
46
+ |---|---|
47
+ | `constants.cjs` | the settings namespace, the slot key, the routes, the poll intervals, the element id prefix, the public links (among them GitHub's new-issue page) and the address of the project's feedback receiver (`FEEDBACK_ENDPOINT`, empty while there is none) |
48
+ | `fields.cjs` | **generated** by `npm run sync-client` from `src/config.js`: `FIELDS` and `INDEX` |
49
+ | `layout.cjs` | where each setting sits: `TABS` → sections → setting keys, and `placedKeys()` |
50
+ | `i18n.cjs` | the `UI` dictionary (en, zh) and `dictionaries()`, which adds the texts of the field table |
51
+ | `net.cjs` | `fetchStatus`, `fetchChangelog`, `fetchModels`, `postModels`, `tryRecall`, `fetchCore`, `postCore`, `fetchMemories`, `fetchMemory`, `postCues`, over one `getJson` / `postJson` pair; and `sendFeedback`, the one call that leaves the host |
52
+ | `clipboard.cjs` | `copyText`: the one place that touches the clipboard, and says whether the text arrived |
53
+
54
+ **Logic, `model/`** (pure: no React, no DOM)
55
+
56
+ | module | holds |
57
+ |---|---|
58
+ | `model/form.cjs` | the settings form as data: `at`, `checkText`, `fieldView`, `buildOps`, `saveDraft` |
59
+ | `model/page.cjs` | the settings arranged for drawing: `splitOption`, `isMet`, `sectionView`, `pageView`, `savable` |
60
+ | `model/overview.cjs` | the summary at the top of the page: `summarise` (mood, headline, line, facts), `formatCount`, `MOODS` |
61
+ | `model/status.cjs` | the status block as text rows: `stateText`, `statusRows` |
62
+ | `model/models.cjs` | the local model list as data: `pickText`, `formatSize`, `memoryText`, `modelActions`, `chainLine`, `sameProblem` |
63
+ | `model/changelog.cjs` | the changelog answer as a list of releases: `entryDate`, `releases` |
64
+ | `model/feedback.cjs` | a feedback report and the address that hands it to GitHub: `KINDS`, `environment`, `safe`, `titleOf`, `bodyOf`, `compose`, `reportText`, with the limits `MAX_TEXT` and `MAX_URL`; and for the receiver `payload`, `usableEndpoint`. Also loaded by the host half (see below) |
65
+ | `model/trial.cjs` | the answer of the try route as what the panel shows: `rows` (each keeps its `id` and `source`), `summary`, `score`, `usable`, `errorKey` |
66
+ | `model/memories.cjs` | the answers of the memories route as what the Memories tab shows: `rows`, `stores`, `paging`, `listBody`, `detail`, the cue edits (`addCue`, `removeCue`, `canSave`, `sameCues`) and the error keys |
67
+ | `model/core.cjs` | the answer of the core route as what the panel shows: `rows` (the core, what did not fit and what was taken out, each row with the mark its button sends), `summary`, `isEmpty`, `holds`, `canAdd`, `keyOf`, `errorKey`, `rowErrorKey`, `howKey` |
68
+
69
+ **Hooks**
70
+
71
+ | module | holds |
72
+ |---|---|
73
+ | `hooks.cjs` | `useStatus` (polled), `useChangelog` (read once), `useModels` (polled, and the clicks of the model list), `useCopy` (the clipboard, and what became of the last copy), `useTrial` (one trial recall at a time, and what became of the last), `useSend` (a report posted to the receiver, and what became of it), `useMemories` (the Memories tab: one list read when it is first shown, searching, paging, the open memory and its cue edits; the hook may use the pure `model/memories.cjs`), `useCore` (the core memory and the owner's marks: read when the Retrieval tab is shown and after each change, one mark per memory at a time; the page keeps it so that the core panel and the recall trial share it); they own the timers and the "still mounted" flag |
74
+
75
+ **Theme, `theme/`**
76
+
77
+ | module | holds |
78
+ |---|---|
79
+ | `theme/page.css` | the stylesheet of the page, with the one block that maps the host's style variables to the page's own |
80
+ | `theme/styles.cjs` | `installStyles(document)` (adds one `<style>` with the stylesheet, returns the function that removes it), `STYLE_ID`, `cx` (joins class names) |
81
+
82
+ **Controls and parts, `kit/`** (plain functions of props, no state of their own)
83
+
84
+ | module | holds |
85
+ |---|---|
86
+ | `kit/controls.cjs` | `Button`, `Tag`, `Switch`, `TextInput`, `TextArea`, `Stepper`, `Select`, `Choices` and `stepText` |
87
+ | `kit/layout.cjs` | `Tabs`, `TabPanel`, `Reveal`, `Fold`, `Group`, `Facts`, `Notice`, `Progress` |
88
+ | `kit/icons.cjs` | the few line icons: `Icon`, `ICON_NAMES` |
89
+
90
+ **Views, `view/`** (what is drawn and what the page keeps in state)
91
+
92
+ | module | holds |
93
+ |---|---|
94
+ | `view/page.cjs` | `SettingsPage` (the slot entry), `SettingsBody` (summary, tabs, panel, save bar, footer; keeps the tab, the staged edits, the phase of a save, the open groups, the feedback being written and the recall trial), `SaveBar`, `Footer` |
95
+ | `view/hero.cjs` | `Hero`: the headline, the line and the facts of the summary, with the mascot's drawing |
96
+ | `view/settings-tab.cjs` | `SettingsTab`: the sections of one settings tab, sub-rows inside a `Reveal`, folding groups in the Advanced tab |
97
+ | `view/field-row.cjs` | `FieldRow`: one setting as one row, with the control that fits its kind; `fieldId` |
98
+ | `view/tabs.cjs` | `OverviewTab` and `ChangelogTab`, two of the tabs without settings |
99
+ | `view/feedback.cjs` | `FeedbackTab`, the third, and `Nag` (the fifth drawing, `mascot-nag.webp`, with its speech bubble, beside the title; none if it cannot be loaded): what it is about, the text, the environment lines, Send, the link out to GitHub and the copy button; `emptyFeedback` |
100
+ | `view/models.cjs` | `ModelsPanel` and `ModelRow`: the local embedding models and their one button |
101
+ | `view/core.cjs` | `CorePanel` and `CoreRow`: core memory on the Retrieval tab, under its switch: the summary line, the memories given at the start of every conversation, those that did not fit and those the owner took out, each with its one button; or the one line that says why there is nothing to list (off, not ready, not supported, failed) |
102
+ | `view/trial.cjs` | `TrialPanel` and `TrialRow`: the recall trial of the Retrieval tab, one line to type a sentence and the memories the gateway looked at, each with its score and, if left out, the step that removed it, and, while the core memory has an answer, the button that adds it to core memory (or a tag when it is in there) |
103
+ | `view/memories.cjs` | `MemoriesTab`, `MemoryRow`, `MemoryDetail` and `CueEditor`: the Memories tab, a searchable list of what the gateway holds, one row open at a time with its full text and its recall cues |
104
+ | `view/markdown.cjs` | the changelog Markdown subset, text in and React elements out: `inlineMarkdown`, `joinLines`, `renderMarkdown` |
105
+
106
+ ## The page
107
+
108
+ The Plugins page renders entries of its keyed slot `plugins.row.config` under the key
109
+ `<package name>#<row id>` and passes `view` (`'summary'` | `'page'`) and `form` (`{ state, mutate }`) for
110
+ the row's settings namespace (`packages/client/ui-plugin-manager/src/client/slot-contract.ts:160-167`,
111
+ `:190-195`; `PluginManagerPage.tsx:1568-1572`, `:714`). `view/page.cjs` exports `SettingsPage`, which
112
+ `index.cjs` registers in that slot; `apply(ctx)` also registers the dictionaries and the stylesheet.
113
+
114
+ `SettingsBody` draws, in order: the `Hero` (the state in one headline, one line and a few facts, with a
115
+ mood that picks one of four drawings of the mascot), the `Tabs` (overview, features, retrieval, memories, advanced,
116
+ changelog, feedback), the one `TabPanel` of the selected tab, the `SaveBar` (only while edits are staged, or just
117
+ after a save) and the `Footer`. The page keeps its shape whatever the settings form is doing: while the
118
+ form is loading, unavailable or read-only, the summary, the model list, the changelog and the feedback tab
119
+ still work, and a settings tab says what is the matter instead of showing rows nobody can use.
120
+
121
+ The settings form follows the host's conventions: edits are staged, only Save writes, all staged edits go
122
+ in one `form.mutate(ops, revision)` with the revision they were made against, a changed setting shows a
123
+ tag and a reset that stages a return to the inherited value, and a secret is write-only (an empty draft
124
+ keeps the stored value). A setting with `needs` (see `src/config.js`) is drawn as a sub-row inside a
125
+ `Reveal` that is open while the setting it needs has a fitting value, judged by the value on screen, a
126
+ staged edit included. The Advanced tab's sections are folds, closed by default.
127
+
128
+ Status. The summary and the Overview tab read `GET feiyu-memgate/status` (document-relative, like the
129
+ first-party pages' host routes), which the host half serves to the owner only. It shows no secret, address
130
+ or memory: secrets arrive as booleans.
131
+
132
+ Changelog. The Changelog tab reads `GET feiyu-memgate/changelog` (owner only, like the status): the released
133
+ entries of the package's `CHANGELOG.md`. Their Markdown is drawn by a small subset (`view/markdown.cjs`)
134
+ that builds React elements from text (headings, lists, paragraphs, code, bold, https links), so no HTML
135
+ from the file can reach the page.
136
+
137
+ Feedback. The Feedback tab writes a report and either sends it to the project's receiver (Send, below) or hands it to the person's browser.
138
+ `model/feedback.cjs` builds the address of GitHub's new-issue page with the title and the text as query
139
+ parameters, and the button is a plain link to it (`target="_blank"`), so the report exists only once the
140
+ person submits it on GitHub under their own account. What is attached besides their own words is decided in
141
+ one function, `environment(status)`: version numbers and state names, each of which has to look like one
142
+ (letters, digits, dots, dashes, at most 40 characters) or becomes a question mark, so a path, an address or
143
+ a file name cannot get in whatever a later status holds. The same lines are listed on the tab under the
144
+ switch that attaches them. An address is kept under `MAX_URL` characters: a longer report is cut in the
145
+ address only, the cut is marked, and the link copies the whole report to the clipboard on the way out.
146
+ The shipped package names a receiver (`FEEDBACK_ENDPOINT`, checked by `usableEndpoint`: https, or this
147
+ computer for the preview; an empty value switches Send off and leaves the link and the copy button), so the tab is "write, then Send": one Send button, and the link
148
+ to GitHub and the copy button are shown only inside the notice of a Send that failed. Send is the only call of the
149
+ page that leaves the host: `net.cjs` `sendFeedback` posts `payload()` with `credentials: 'omit'` and no
150
+ referrer, waits `FEEDBACK_TIMEOUT_MS`, and turns every failure into a code the tab shows. The receiver is
151
+ `feedback-worker/worker.js` (a Cloudflare Worker the maintainers run, not shipped in the package); its
152
+ `validate()` and this module's `payload()` describe the same shape and are tested against each other.
153
+ The host half loads the same module for `/memgate feedback` (`src/commands.js` imports
154
+ `client/src/model/feedback.cjs`), which is why that module and `constants.cjs` must stay plain CommonJS
155
+ that runs in Node without a browser.
156
+
157
+ The mascot. The drawings are the files of `client/art/`: four moods (`mascot-<mood>.webp`) and a fifth,
158
+ `mascot-nag.webp`, for the Feedback tab. The host half serves them from its art route
159
+ (`GET feiyu-memgate/art/<file>`, `src/plugin.js`); the summary loads the one that fits the mood, the
160
+ Feedback tab shows the fifth beside its title with a speech bubble over it (the bubble is text of the page,
161
+ so it follows the language), and like the others the tab simply has no drawing, and no bubble, if it cannot
162
+ be loaded. Nothing a person needs is only in the picture.
163
+
164
+ The host half never depends on this page: without it every setting still works, through `/memgate` and
165
+ the profile's patch file.
166
+
167
+ ## Rules for the modules
168
+
169
+ - One responsibility per file. Each file starts with `'use strict'` and a header comment that says what it
170
+ is responsible for and what it must not do.
171
+ - A module gets another module with `require('./x.cjs')` or `require('../x.cjs')`: a relative path with the
172
+ `.cjs` extension. Only `react.cjs` requires `react`; no other module asks the host for anything.
173
+ - One `module.exports = { ... }` at the end of a file, with the names in the order they are defined.
174
+ - No `import` or `export` syntax, no JSX, no dependency that is not in the host's shared module table, no
175
+ template literal that spans lines.
176
+ - `fields.cjs` is generated; change the settings in `src/config.js` instead.
177
+ - Keep a comment with the code it explains.
178
+
179
+ ### Layers
180
+
181
+ The require graph has no cycle, and each layer reaches only what is listed (`tests/client-modules.test.js`
182
+ checks every line of this):
183
+
184
+ | layer | may require |
185
+ |---|---|
186
+ | `constants.cjs`, `fields.cjs`, `layout.cjs`, `react.cjs`, `clipboard.cjs` | nothing of the page |
187
+ | `i18n.cjs` | `fields.cjs` |
188
+ | `net.cjs` | `constants.cjs` |
189
+ | `hooks.cjs` | `react.cjs`, `constants.cjs`, `net.cjs`, `clipboard.cjs` (no view, kit or theme) |
190
+ | `model/*` | other `model/*` files, `fields.cjs`, `layout.cjs`, `constants.cjs` (no React, kit, view, theme or hooks) |
191
+ | `theme/*` | `theme/*` |
192
+ | `kit/*` | `kit/*`, `react.cjs`, `theme/styles.cjs` |
193
+ | `view/*` | anything but `index.cjs` |
194
+ | `index.cjs` | anything; it is the only module that requires `view/page.cjs`, and nothing requires it |
195
+
196
+ ### Design conventions
197
+
198
+ - **Tokens.** The host switches its style variables between light and dark by itself. The page reads them
199
+ through one mapping block at the top of `theme/page.css` (`.fmg-root`): `--fmg-*` variables, each with a
200
+ fallback for a host that does not define it. Every other rule uses `--fmg-*` only, and the host's
201
+ variable names (`--dsw-*`, `--dsh-*`, `--ds-*`) appear nowhere else.
202
+ - **No theme branch.** There is no light rule and no dark rule; the page's own colours are mixed from the
203
+ host's.
204
+ - **Class names** all start with `fmg-`; modifiers are `--name`. No rule reaches outside `.fmg-root`.
205
+ Every class a module uses is defined in the stylesheet and every class the stylesheet defines is used
206
+ (both are tested).
207
+ - **State is carried by ARIA and data attributes** the components set anyway (`aria-selected`,
208
+ `aria-checked`, `aria-expanded`, `aria-invalid`, `data-open`), not by extra classes. Controls are native
209
+ elements with ARIA roles: a switch is a `button` with `role="switch"`, a list of choices a radio group,
210
+ the tabs follow the tabs pattern with arrow keys.
211
+ - **No inline styles.** The one exception is the width of a progress bar's inner element.
212
+ - Every element id starts with `feiyu-memgate-` so that none can meet an id of the host's page.
213
+
214
+ ## How to add a setting
215
+
216
+ 1. Add it to `FIELDS` in `src/config.js` (key, kind, default, range, label and help in both languages;
217
+ `needs`, `unit` or `experimental` when they apply).
218
+ 2. Add its key to a section in `layout.cjs`. A setting with `needs` goes in the same section as the setting
219
+ it needs, after it.
220
+ 3. Run `npm run sync-client`. It rewrites `client/src/fields.cjs` and `client/client.js`.
221
+
222
+ `tests/client-modules.test.js` fails when a setting is not placed, is placed twice or sits before the
223
+ setting it needs; the page needs no other change.
224
+
225
+ ## How to preview
226
+
227
+ ```bash
228
+ node scripts/preview-client.mjs --react <a node_modules folder with react and react-dom 18> [--port 47931]
229
+ ```
230
+
231
+ Run it in `plugins/dsh-feiyu-memgate`, then open `http://127.0.0.1:47931/` and pick a scenario, a theme, a
232
+ language, the state of the settings form, a column width and how feedback is received in the bar on top.
233
+ The page script is assembled from `client/src` on every request, so a reload shows an edit.
234
+
235
+ The Feedback choice decides where Send goes. "As shipped" leaves it to `FEEDBACK_ENDPOINT`: with an address
236
+ there, Send really sends a report to the project's receiver. "No receiver" hides Send. The three made-up
237
+ receivers (takes it, fails, is busy) are a route of the preview server that reads nothing of what is posted.
238
+
239
+ The Recall trial choice (`trial=` in the address) decides what the try route answers: it finds memories (every
240
+ kind of row: delivered, linked, left out at each step, a moved score, a cut text, a missing text), finds
241
+ nothing, the gateway is too old, no recall is made for the sentence, or the lookup fails. The sentence typed
242
+ is not read; the memories are invented.
243
+
244
+ The Core memory choice (`core=` in the address) decides what the core route answers: `some` (three picked by the
245
+ type "identity", two the owner added, one taken out with its text and one taken out that no longer exists), `leftout`
246
+ (the same, with two the owner added that do not fit), `empty`, `off`, `unsupported`, or `failed`. In the modes that list
247
+ memories the buttons work while the server runs: the preview server keeps the marks you press, per mode, and the
248
+ list moves accordingly; a memory the preview does not know answers "no longer there". The marks are lost when the
249
+ server stops.
250
+
251
+ What is real: the page script, its stylesheet, the drawings of `client/art`, the changelog (read from
252
+ `CHANGELOG.md` like the host half does). What is made up: the status and the model list
253
+ (`scripts/preview/scenarios.mjs`), the settings form (kept in the page), and the host's style variables
254
+ (`scripts/preview/host-tokens.css`, copied values). So the preview shows layout, texts, states and both
255
+ themes; it does not show the page inside the real Plugins page. The server listens on `127.0.0.1` only and
256
+ serves nothing but the files named in the script. `tests/client-preview.test.js` checks that every made-up
257
+ scenario can be drawn by the page; it does not start the server.
258
+
259
+ ## Commands
260
+
261
+ Run them in `plugins/dsh-feiyu-memgate`.
262
+
263
+ | command | what it does |
264
+ |---|---|
265
+ | `npm run build-client` | assemble `client/client.js` from `client/src`; rewrite it when it differs |
266
+ | `npm run build-client -- --check` | exit 1 when `client/client.js` is stale; change nothing |
267
+ | `npm run sync-client` | write `client/src/fields.cjs` from `src/config.js`, then do `build-client` |
268
+ | `npm run sync-client -- --check` | exit 1 when `fields.cjs` or `client/client.js` is stale (CI runs this) |
269
+
270
+ ## Tests
271
+
272
+ | file | what it checks |
273
+ |---|---|
274
+ | `tests/client-build.test.js` | the registry and the assembly |
275
+ | `tests/client-modules.test.js` | the pure modules on their own, the rules above (headers, imports, layers, the layout table), the stylesheet against the class names the modules use, the dictionary against the keys they ask for |
276
+ | `tests/client-page.test.js` | the assembled file: what it asks of the host, `apply`, and the page drawn with a small stand-in for React (`tests/helpers/client-harness.js`); fails when either generated file is stale |
277
+ | `tests/client-preview.test.js` | the preview's made-up answers against the page |
278
+ | `tests/trial.test.js` | the recall trial: the model, the call, the panel, its place in the page and the preview's answers for it |
279
+ | `tests/core.test.js` | core memory: the model, the two calls, the hook (run with a React that keeps state), the panel, the trial's "add" button, its place in the page and the preview's answers and marks |
Binary file
Binary file
Binary file
Binary file
Binary file