@yaks/memory 0.0.0-stage → 0.2.36

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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +309 -2
  3. package/_dist/comp.d.ts +9 -0
  4. package/_dist/comp.d.ts.map +1 -0
  5. package/_dist/earlier.d.ts +108 -0
  6. package/_dist/earlier.d.ts.map +1 -0
  7. package/_dist/graph.d.ts +13 -0
  8. package/_dist/graph.d.ts.map +1 -0
  9. package/_dist/inspect.d.ts +28 -0
  10. package/_dist/inspect.d.ts.map +1 -0
  11. package/_dist/mod.d.ts +54 -0
  12. package/_dist/mod.d.ts.map +1 -0
  13. package/_dist/passage.d.ts +19 -0
  14. package/_dist/passage.d.ts.map +1 -0
  15. package/_dist/recall.d.ts +67 -0
  16. package/_dist/recall.d.ts.map +1 -0
  17. package/_dist/save.d.ts +45 -0
  18. package/_dist/save.d.ts.map +1 -0
  19. package/_dist/tools.d.ts +12 -0
  20. package/_dist/tools.d.ts.map +1 -0
  21. package/_dist/views.d.ts +17 -0
  22. package/_dist/views.d.ts.map +1 -0
  23. package/_dist/vocab.d.ts +7 -0
  24. package/_dist/vocab.d.ts.map +1 -0
  25. package/around.js +141 -0
  26. package/around.js.map +1 -0
  27. package/around.ts +152 -0
  28. package/comp.js +42 -0
  29. package/comp.js.map +1 -0
  30. package/comp.ts +45 -0
  31. package/deno.json +1 -0
  32. package/earlier.js +386 -0
  33. package/earlier.js.map +1 -0
  34. package/earlier.ts +494 -0
  35. package/graph.js +138 -0
  36. package/graph.js.map +1 -0
  37. package/graph.ts +133 -0
  38. package/inspect.js +168 -0
  39. package/inspect.js.map +1 -0
  40. package/inspect.ts +169 -0
  41. package/mod.js +54 -0
  42. package/mod.js.map +1 -0
  43. package/mod.ts +55 -0
  44. package/package.json +51 -4
  45. package/passage.js +67 -0
  46. package/passage.js.map +1 -0
  47. package/passage.ts +75 -0
  48. package/recall.js +145 -0
  49. package/recall.js.map +1 -0
  50. package/recall.ts +180 -0
  51. package/save.js +93 -0
  52. package/save.js.map +1 -0
  53. package/save.ts +113 -0
  54. package/tools.js +246 -0
  55. package/tools.js.map +1 -0
  56. package/tools.ts +250 -0
  57. package/views.js +18 -0
  58. package/views.js.map +1 -0
  59. package/views.ts +23 -0
  60. package/vocab.js +14 -0
  61. package/vocab.js.map +1 -0
  62. package/vocab.json +456 -0
  63. package/vocab.ts +16 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,310 @@
1
- # Temporary Holding Version
1
+ # @yaks/memory
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Marks what a person said, in their own words, where the graph already holds it,
4
+ reads it back at the start of the next conversation, and reads around it. It
5
+ also declares what is built from those words: `belief`, a conclusion a builder
6
+ drew from memories about a subject, often a topic
7
+ ([@yaks/topic](../topic/README.md)). This package supplies the components, the
8
+ write and read helpers, and seven tools; storage and optional semantic ranking
9
+ come from elsewhere.
10
+
11
+ An entity is a record identified by `entity.eid`. A bundle is a JSON object
12
+ containing that identifier and the entity's named components, such as `doc` and
13
+ `memory`. The graph and its storage adapter persist these objects; this package
14
+ constructs writes, queries and display text.
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ deno add jsr:@yaks/memory
20
+ # or: npx jsr add @yaks/memory
21
+ ```
22
+
23
+ ## Use
24
+
25
+ ```ts
26
+ import { loadVocab } from '@yaks/vocab'
27
+ import { docDoc } from '@yaks/doc'
28
+ import { memoryDoc, saved } from '@yaks/memory'
29
+ import { graph } from '@yaks/graph'
30
+ import { ram } from '@yaks/ram'
31
+
32
+ const vocab = loadVocab([docDoc, memoryDoc])
33
+ const g = graph({ vocab, storage: ram(vocab) })
34
+
35
+ await g.apply(saved({
36
+ eid: crypto.randomUUID(),
37
+ said: 'use grams, never cups',
38
+ about: 'recipes',
39
+ context: 'looking at the recipe app',
40
+ }))
41
+
42
+ console.log(await g.read('.memory ?doc'))
43
+ // For persistent storage, replace ram with a database adapter. For full-text
44
+ // queries, configure @yaks/fts on a compatible SQL adapter.
45
+ ```
46
+
47
+ ## The component
48
+
49
+ A memory is a mark on the entity holding the words: a session entry, a comment,
50
+ a doc. The words are that entity's own text, and nothing here edits them:
51
+
52
+ ```json
53
+ {
54
+ "entity": { "eid": "e1" },
55
+ "entry": { "session": "s1", "seq": 12 },
56
+ "content": { "body": "use grams, never cups" },
57
+ "memory": { "context": "the recipe app", "at": "…", "by": "a1", "via": "s1" }
58
+ }
59
+ ```
60
+
61
+ Words the graph holds nowhere yet (said in a chat, say) get a doc of their own,
62
+ whose `doc.body` is the sentence verbatim; on yaks.app that is most of them.
63
+ `words(bundle)` reads the words from whichever component holds them, a doc's
64
+ body, else a transcript entry's content, else a doc's title (a task filed as one
65
+ line), so a memory renders and is found the same way whatever it marks. `memory`
66
+ holds the rest:
67
+
68
+ - `space` — the space the statement belongs to. Deleting the space deletes its
69
+ memories. Space membership and read access require application access
70
+ controls; this schema alone does not enforce them.
71
+ - `scope` — an optional project reference; the memory survives project deletion.
72
+ - `last_confirmed_at` — a stamped timestamp for the latest confirmation.
73
+ - `at`, `by`, `via` — who marked the words, when, and through what. They make
74
+ `memory` a mark in @yaks/graph's sense: stamped the first time the component
75
+ is written, and left alone after. Nothing needs approving.
76
+ - `feedback{by}` — a separate component marking a correction and, when known,
77
+ the entity identifying the person who supplied it.
78
+ - `miss{entry, needed, across, told, kind}` — worn beside `feedback` on the
79
+ entity recording a correction: the agent's `entry` that erred, the entity that
80
+ held the fact it lacked (`needed`, absent when nothing did), the compaction,
81
+ clear, fork or spawn between them (`across`), and whether the person
82
+ `restated` it or `pointed` at the graph (`told`, absent when an agent found
83
+ it), and which known error it was (`kind`: `reserve`, keeping back budget the
84
+ person said to spend; `offer`, ending on "Want me to…?"; `directive`, posting
85
+ their remark as a directive; absent when it was none of them). A miss is a
86
+ case [@yaks/trial](../trial) scores context on.
87
+ - `about` — the app it was about, by slug, when it was about one.
88
+ - `context` — the line or two needed to understand the words. Never a
89
+ restatement of them.
90
+
91
+ Who said the words, and when, is the entity's own `created{at, by}`. A mark says
92
+ what happened to an entity, never what it is: a comment marked as a memory is
93
+ still a comment, and only a doc that is nothing but a memory is shown as one
94
+ (@yaks/vocab `kindOrder`).
95
+
96
+ ## Beliefs
97
+
98
+ A memory is what happened; a belief is what was built from it. A belief is a
99
+ builder's output ([@yaks/builders](../builders)): `doc{title, body}` says it,
100
+ `built` names the build that made it, `cites` edges name the memories or beliefs
101
+ it was built from, and `belief` says where it stands:
102
+
103
+ - `about` — its subject: a topic, a project, a package, a component (`_comp`) or
104
+ a design.
105
+ - `scope` — the project it holds for; absent for a principle that holds
106
+ everywhere.
107
+
108
+ Nobody edits a belief. A wrong one is fixed in the builder that made it, and the
109
+ builder makes it again.
110
+
111
+ A topic, the subject most beliefs are about, is
112
+ [@yaks/topic](../topic/README.md)'s, with the tools that find and make one.
113
+
114
+ ## Writing
115
+
116
+ `marked()` returns the bundle that marks an entity already holding the words:
117
+ `memory` and, for a correction, `feedback`, nothing about the words. `saved()`
118
+ returns the bundle for words the graph holds nowhere: a doc whose body is `said`
119
+ trimmed, marked the same way; it rejects an empty `said`. Both keep context as
120
+ at most `LINES` (two) trimmed, non-blank lines. The caller passes the list to
121
+ `g.apply()`.
122
+
123
+ ## Reading
124
+
125
+ `line()` builds the query string that finds memories, in the filter grammar
126
+ understood by yaks storage adapters. With `said`, it adds search terms as a
127
+ filter; without `near` or explicit ids, the newest words come first (descending
128
+ `created.at`). Every component comes back, since the words may be a doc's body
129
+ or an entry's content. Search terms do not request BM25 ranking. A `.near` query
130
+ requires a configured embedding index. A memory carrying a `quarantined` stamp
131
+ (@yaks/kernel) is never in the line, so no recall, passage or ranking returns
132
+ one.
133
+
134
+ Ranking by meaning is the host's: `host.meaning` ([@yaks/host](../host)) takes
135
+ words and a filter line and answers the entities nearest them in meaning among
136
+ what the line admits, closest first. `ordered(ids, bundles)` puts what a store
137
+ returned into that order. Nothing here knows how the ranking is done: on the box
138
+ it is [@yaks/embedding](https://jsr.io/@yaks/embedding)'s graph facet, and on
139
+ yaks.app it is the store's own vectors, embedded by Workers AI.
140
+
141
+ ## The passage
142
+
143
+ `passage({ name, space }, memories)` builds the text an agent is given at the
144
+ start of a conversation. Pass `Memory` records in the desired order; use
145
+ `heard(bundle)` to convert graph results. Each statement is quoted in full with
146
+ its context below. The helper includes at most `LAST` (8) records and targets
147
+ `BYTES` (2048) UTF-8 bytes of record text. The first record is always included
148
+ even if oversized, and the heading and omitted-results notice are additional
149
+ bytes. This is not a strict total-output bound. If records are omitted, a notice
150
+ names `memory_recall`, so the application should expose that tool.
151
+
152
+ ## The tools
153
+
154
+ `vocab.json` declares seven tools, and `@yaks/memory/tools` exports the `runs()`
155
+ factory that implements them (`yak memory save`, `yak memory recall`, and the
156
+ rest the same way, and each over `/mcp`):
157
+
158
+ ```sh
159
+ yak memory save 'always commit your changes' --scope P-1 --feedback jeff
160
+ yak memory save --on C-38041 --context 'on the persona gates'
161
+ yak memory recall 'commit'
162
+ yak memory recall --near T-37666
163
+ yak memory source 'always commit your changes' --by jeff
164
+ yak memory around '#c625160bfa' -B 5 -A 2
165
+ yak memory target C-38041
166
+ yak memory thread C-38041
167
+ yak memory session '#c625160bfa'
168
+ ```
169
+
170
+ `memory save` marks the words where the graph holds them: the entity `on` names,
171
+ or, given `said` and a `feedback` naming who said them, the earliest entity that
172
+ person wrote whose text holds those words verbatim. The same words in anybody
173
+ else's text are a quote, so words it cannot place become a new doc. Passing `id`
174
+ patches an existing memory instead, leaving alone whatever the call did not
175
+ mention. Replacing the words requires `was` — the token `memory recall` returns
176
+ beside them, which the graph's own precondition check reads — so a memory
177
+ another writer changed since you read it is rejected as a whole rather than
178
+ overwritten; the words of anything a memory marks (a comment, an entry, a task)
179
+ are what happened there and are never replaced.
180
+
181
+ `memory recall` returns complete memories, not excerpts. `said` says what the
182
+ memory is about. Where the host ranks by meaning (`host.meaning`), the memories
183
+ nearest it come first, among those the recall's space, `scope` and `feedback`
184
+ admit, whether or not they share a word with it. Where it does not, or it names
185
+ none yet (a memory saved a moment ago), `said` becomes search terms the memory
186
+ must all contain, newest first. A ranking that fails is reported to
187
+ `host.report` and the words select instead. `near` names an existing entity to
188
+ rank by its meaning, and `said` then selects by its words. With neither, the
189
+ newest come first.
190
+
191
+ `memory source` answers where a person said words: the earliest entity they
192
+ wrote holding them verbatim, the same entity a save given `said` and `feedback`
193
+ marks, or a refusal where there is none. A model finding the source of a quote
194
+ marks it with `on`, and never makes a doc for words it could not place.
195
+
196
+ The other four read around a memory, the way `grep -C` reads around a line, for
197
+ a model building beliefs from memories. Each takes any entity and answers
198
+ bundles, each whole:
199
+
200
+ | Tool | Answers |
201
+ | ---------------- | -------------------------------------------------------------------------------------------------- |
202
+ | `memory_around` | the transcript entries around an entry: `before` ahead, the entry, `after` behind (default 3 each) |
203
+ | `memory_target` | what it is aimed at: the entity each of its components' `target` names (a comment's, a letter's) |
204
+ | `memory_thread` | what its comments are about, past every reply, then every comment below that, oldest first |
205
+ | `memory_session` | the session it was written in, then what that session worked on (`worked` edges) or claims |
206
+
207
+ They know other packages' components (`entry`, `comment`, `worked`, `claim`)
208
+ only by the names their queries speak and the rows those answer.
209
+
210
+ ## Exports
211
+
212
+ The root exports `memoryDoc`, `marked`, `saved`, `clamped`, `words`, `terms`,
213
+ `line`, `heard`, `ordered`, `passage`, the `Marking`, `Saving`, `Asked`,
214
+ `Memory`, and `Ranker` types, and constants `MEMORY`, `FEEDBACK`, `LINES`,
215
+ `EMPTY`, `LAST` and `BYTES`. `clamped` performs context-line trimming; `terms`
216
+ turns words into search terms the query grammar cannot misread; `EMPTY` is the
217
+ empty-statement error message. `@yaks/memory/vocab` exports `memoryDoc` and its
218
+ `docs` array for schema loaders; `@yaks/memory/tools` supplies the tool
219
+ implementations described above. `@yaks/memory/views` exports the asynchronous
220
+ `inspectViews()` accessor, how the inspector (@yaks/inspect) draws a belief: it
221
+ says what it says, what it is about and where it holds, then each memory it
222
+ cites, the words verbatim with who said them, when and where, the context line,
223
+ and the conversation around them (as @yaks/session draws it). In a topic's lists
224
+ (`Topic.List.Tile`, [@yaks/topic](../topic/README.md)'s page) a belief reads as
225
+ what it states and where it holds. `@yaks/memory/inspect` exports the inspector
226
+ components directly.
227
+
228
+ ## Compatibility
229
+
230
+ Pure TypeScript. It imports no platform API — no `Deno`, no Node built-in, no
231
+ DOM global beyond `TextEncoder` — and type-checks under
232
+ `lib: ["dom", "es2023"]`, so it runs unchanged in a **browser**, on **Deno**,
233
+ and on **Node** (via JSR / npm). The library depends on sibling schema and graph
234
+ libraries. The optional `./tools` implementations additionally require the
235
+ configured graph and, for search queries, the appropriate search extensions.
236
+
237
+ ## License
238
+
239
+ Apache-2.0
240
+
241
+ ## Earlier words beside a prompt
242
+
243
+ `@yaks/memory/earlier` offers `earlier(graph, options)`: a bounded read of
244
+ strictly earlier person-authored transcript inputs, comments the person wrote
245
+ and comments explicitly attributing a verbatim quotation to that person, and of
246
+ the memories and answered decisions nearest the prompt in meaning, at least
247
+ `FLOOR` similar. It returns at most three quotations, a line each with its
248
+ source id and date, cut at 280 characters with a closing `…`, and at most four
249
+ memories and decisions by id and title (a decision with its choice). A
250
+ quarantined memory is not offered, nor one already quoted; a memory kept on an
251
+ untitled entry shows its words. Agent prose outside a quotation is not returned,
252
+ and duplicate quotations are shown once.
253
+
254
+ A person the graph has no name for has no attributed quotations, only their own
255
+ inputs. `among` is a filter line those inputs are kept to, such as the ones the
256
+ agent answering does not already have in front of it. With `wait`, a recall
257
+ slower than that many milliseconds answers nothing.
258
+
259
+ ```ts
260
+ import { ownWords } from '@yaks/memory/earlier'
261
+ import { equal } from '@yaks/testing'
262
+ const words = ownWords(
263
+ {
264
+ entity: { eid: 'source' },
265
+ comment: { target: 'discussion' },
266
+ doc: { body: 'Ada, 2026-01-01, verbatim: "keep files immutable"' },
267
+ created: { at: '2026-01-02T00:00:00Z' },
268
+ },
269
+ 'ada',
270
+ 'Ada',
271
+ )
272
+ equal(words[0].words, 'keep files immutable')
273
+ ```
274
+
275
+ The caller supplies the person's id, the prompt words and its cutoff instant.
276
+ Full-text search supplies lexical candidates when meaning search has no
277
+ candidates; the optional host `meaning` function supplies semantic candidates.
278
+ The selector verifies authorship and cutoff again after reading the candidates.
279
+ No model composes an answer, no recall event is written, and no historical
280
+ quotation becomes an instruction. The similarity floor is calibrated for
281
+ Granite's 30M English embedding space; other embedding spaces need their own
282
+ measurement.
283
+
284
+ ## Earlier words beside a write
285
+
286
+ A prompt recalls by the person's message. What an agent then does about it is
287
+ often nearer to something they said before than the message was, so a write is
288
+ answered with it too. As a plugin, `@yaks/memory/graph` exports `reply(host)`:
289
+ what a direct tool call's answer carries beside the tool's own
290
+ ([@yaks/tools](../tools/README.md) `Reply`), next to the neighbours
291
+ @yaks/embedding answers with. For each entity the call's write made, up to
292
+ three, it answers `bearing(graph, options)`:
293
+
294
+ - the configured person's nearest earlier words, three at most, each at least
295
+ `SAID` similar to the entity's title and words;
296
+ - the nearest answered decisions, two at most, each at least `FLOOR` similar.
297
+
298
+ Each is a `hit` naming under `said` the entity it bears on and under `by` the
299
+ person, so a model reads
300
+ `Ada earlier, on T-12: C-7 · comment on T-3 (meaning) —
301
+ 2026-01-03 "test with the other number"`.
302
+ What the calling session wrote or was told since its latest compaction is left
303
+ out, since it holds that already, and the person's own writes are answered with
304
+ nothing. The recall waits a second and then answers nothing; it never fails or
305
+ holds the write. A host with no configured person or no meaning index answers
306
+ nothing.
307
+
308
+ Both floors belong to the embedder's space and were measured on the box's model
309
+ (the constants say how). `yak trial score --arrive said` replays this door over
310
+ the cases a graph holds (@yaks/trial).
@@ -0,0 +1,9 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** The component marking a thing a person said. */ export declare let MEMORY: string;
3
+ /**
4
+ * The memory vocabulary document, to load beside @yaks/doc's and your own:
5
+ * `loadVocab([docDoc, memoryDoc, ...mine])`. It declares nothing about what a
6
+ * space is — that component is your own document's — only that a memory
7
+ * belongs to one.
8
+ */ export declare let memoryDoc: VocabDoc;
9
+ //# sourceMappingURL=comp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.d.ts","sources":["../comp.ts"],"names":[],"mappings":"AAgCA,cAAc,QAAQ,2BAAgC;AAGtD,iDAAiD,GACjD,OAAO,YAAI,eAAiB;AAE5B;;;;;CAKC,GACD,OAAO,YAAI,WAAW,SAAc"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Earlier words, not summaries: a bounded read of what a person said and
3
+ * decided before, shared by the doors that set it beside what is in front of
4
+ * an agent.
5
+ *
6
+ * - {@link earlier} is keyed on the person's own words: a prompt, a comment or
7
+ * a letter of theirs, answered with their nearest earlier words and the
8
+ * nearest memories and decisions, as lines.
9
+ * - {@link bearing} is keyed on what an agent just wrote (a task, a comment, a
10
+ * memory): the person's earlier words and the decisions already answered
11
+ * that are near it, as rows, for the answer to the write (./graph.ts).
12
+ *
13
+ * @module
14
+ */ import type { Bundle, Graph } from "@yaks/graph";
15
+ import { type Built } from "@yaks/query";
16
+ import type { Meaning } from "@yaks/host";
17
+ export type Earlier = {
18
+ id: string;
19
+ at: string;
20
+ words: string;
21
+ };
22
+ /** A recalled item in a stored prompt, with the addressing prefix removed
23
+ * from its displayed text. */ export type RecalledItem = {
24
+ id: string;
25
+ text: string;
26
+ };
27
+ export declare let recalledItems: (prompt: string) => RecalledItem[];
28
+ /** Only an authored input, a comment the person wrote, or an explicitly
29
+ * attributed verbatim quotation. Text outside the quotation is never evidence
30
+ * of what the person said. */ export declare function ownWords(b: Bundle, person: string, name: string): Earlier[];
31
+ /** The similarities a recall keeps to, in its meaning's model's space. */ export type Floors = {
32
+ floor?: number;
33
+ quoted?: number;
34
+ };
35
+ type Asked = {
36
+ person?: string;
37
+ name?: string;
38
+ words: string;
39
+ before: string;
40
+ meaning?: Meaning;
41
+ wait?: number | null;
42
+ /** a filter line the person's own inputs are kept to, such as those the
43
+ * agent answering does not already have in front of it */ among?: Built;
44
+ /** the similarity a memory or decision must reach to be listed (default
45
+ * {@link FLOOR}) */ floor?: number;
46
+ /** the similarity one of the person's earlier words must reach to be
47
+ * quoted (default {@link QUOTED}) */ quoted?: number;
48
+ };
49
+ /** One thing the person said before, and the row that holds it. */ export type Said = Earlier & {
50
+ from: Bundle;
51
+ };
52
+ /** What a person said, kept and decided before on the subject of `words`:
53
+ * a few lines by id for the agent answering them. A person the graph has no
54
+ * name for has no attributed quotations, only their own inputs. With `wait`,
55
+ * only the reads completed by the deadline are included. A meaning read that
56
+ * fails rejects it, for its caller to report. */ export declare function earlier(g: Graph, options: Asked): Promise<string>;
57
+ /** Words cut to a line's worth, saying where they stop. */ export declare let clip: (words: string) => string;
58
+ /** What a memory or a decision is called in a line: its title, or its words
59
+ * where it has none, and the choice a decision was answered with. */ export declare let titleOf: (b: Bundle) => string;
60
+ /** How near in meaning a memory or decision must be to a person's words to be
61
+ * listed beside them. In granite-embedding-30m-english, over the 19 inputs of
62
+ * Jeff's in the windows of T-155224's cases, the memories on the input's
63
+ * subject began at about .75 and the ones at .70 to .75 were on another: .65
64
+ * listed 69 memories and 13 decisions, .75 lists 28 and none (T-161252). No
65
+ * floor from .55 to .70 put a case's needed fact in front. */ export declare let FLOOR: number;
66
+ /** How near in meaning one of the person's earlier words must be to their
67
+ * words now to be quoted beside them. In granite-embedding-30m-english,
68
+ * unrelated corpus pairs reached .642; the attachment paraphrase reached .669
69
+ * and inspect's two earlier asks .664/.677. Like {@link FLOOR}, it is a number
70
+ * in one model's space: a host whose vectors another model makes passes its
71
+ * own. */ export declare let QUOTED: number;
72
+ /** How near in meaning one of the person's earlier words, or an answered
73
+ * decision, must be to what an agent wrote to be set beside it: nothing is,
74
+ * so the door brings nothing until a variant scored with `yak trial score
75
+ * --arrive said --floor` earns it. At .8, the third-nearest of Jeff's words
76
+ * to the 73 things T-155224's agents wrote was at .74 in the median, and the
77
+ * door reached the needed row in 1 of 17 cases (C-161507), not worth a list
78
+ * beside every write. */ export declare let SAID: number;
79
+ /** The memories and answered decisions nearest the words in meaning: what was
80
+ * already kept or settled on the subject, at least `floor` similar. A
81
+ * quarantined memory is not offered; without a meaning index there is nothing
82
+ * to rank by, so nothing. `memories: false` answers the decisions alone. */ export declare function decided(g: Graph, words: string, before: string, meaning?: Meaning, floor?: any, memories?: boolean): Promise<Bundle[]>;
83
+ /** What the agent that wrote something already holds: what its session wrote
84
+ * or was told `since` (its start, or its latest compaction). */ export type Held = {
85
+ via: string;
86
+ since?: string;
87
+ };
88
+ /** What bears on something an agent wrote: the person's earlier words near
89
+ * it, and the decisions answered before it. */ export type Bearing = {
90
+ said: Said[];
91
+ decided: Bundle[];
92
+ };
93
+ /** How many of the person's words, and how many decisions, one written thing
94
+ * is answered with. */ export declare let FEW: {
95
+ readonly said: number;
96
+ readonly decided: number;
97
+ };
98
+ /**
99
+ * What a person said and decided before that bears on `words`, the text of
100
+ * something an agent just wrote: their nearest earlier words at least `floor`
101
+ * similar (default {@link SAID}), and the nearest answered decisions at least
102
+ * that and {@link FLOOR} similar. What the writing session already `held` is left out.
103
+ * There is no ranking by words here: without a meaning index, or past `wait`
104
+ * milliseconds, nothing bears.
105
+ */ export declare function bearing(g: Graph, options: Asked & {
106
+ held?: Held;
107
+ }): Promise<Bearing>;
108
+ //# sourceMappingURL=earlier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"earlier.d.ts","sources":["../earlier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,cAAc,MAAM,EAAQ,KAAK,2BAAgC;AACjE,SAAS,KAAK,KAAK,2BAAmD;AACtE,cAAc,OAAO,0BAA+B;AAMpD,YAAY;EAAY,IAAI,MAAM;EAAE,IAAI,MAAM;EAAE,OAAO,MAAM;;AAO7D;4BAC4B,GAC5B,YAAY;EAAiB,IAAI,MAAM;EAAE,MAAM,MAAM;;AAErD,OAAO,YAAI,gBAAiB,QAAQ,MAAM,KAAG,eAqBzC;AAmBJ;;4BAE4B,GAC5B,OAAO,iBAAS,SAAS,GAAG,MAAM,EAAE,QAAQ,MAAM,EAAE,MAAM,MAAM,GAAG;AAmCnE,wEAAwE,GACxE,YAAY;EAAW,QAAQ,MAAM;EAAE,SAAS,MAAM;;KAEjD;EACH,SAAS,MAAM;EACf,OAAO,MAAM;EACb,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,UAAU;EACV,OAAO,MAAM,GAAG,IAAI;EACpB;0DACwD,GACxD,QAAQ;EACR;oBACkB,GAClB,QAAQ,MAAM;EACd;qCACmC,GACnC,SAAS,MAAM;;AAiEjB,iEAAiE,GACjE,YAAY,OAAO;EAAY,MAAM;;AAwFrC;;;;+CAI+C,GAC/C,OAAO,iBAAe,QAAQ,GAAG,KAAK,EAAE,SAAS,KAAK,GAAG,QAAQ,MAAM;AAyDvE,yDAAyD,GACzD,OAAO,YAAI,OAAQ,OAAO,MAAM,KAAG,MAAM,CAKxC;AAED;mEACmE,GACnE,OAAO,YAAI,UAAW,GAAG,WAAS,MAAM,CAOvC;AAED;;;;;4DAK4D,GAC5D,OAAO,YAAI,cAAW;AAEtB;;;;;QAKQ,GACR,OAAO,YAAI,eAAY;AAEvB;;;;;;uBAMuB,GACvB,OAAO,YAAI,aAAe;AAE1B;;;0EAG0E,GAC1E,OAAO,iBAAe,QACpB,GAAG,KAAK,EACR,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,UAAU,OAAO,EACjB,WAAa,EACb,kBAAe,GACd,QAAQ;AA+BX;8DAC8D,GAC9D,YAAY;EAAS,KAAK,MAAM;EAAE,QAAQ,MAAM;;AAShD;6CAC6C,GAC7C,YAAY;EAAY,MAAM;EAAQ,SAAS;;AAE/C;qBACqB,GACrB,OAAO,YAAI;WAAQ;WAAS;EAAY;AAExC;;;;;;;CAOC,GACD,OAAO,iBAAS,QACd,GAAG,KAAK,EACR,SAAS;EAAU,OAAO;CAAM,GAC/B,QAAQ"}
@@ -0,0 +1,13 @@
1
+ import { type Bundle } from "@yaks/graph";
2
+ import type { Host } from "@yaks/host";
3
+ import { type Reply } from "@yaks/tools";
4
+ /** How long a write's answer waits for what was said before, in
5
+ * milliseconds: as long as it waits for its neighbours (@yaks/embedding
6
+ * `WAIT`), which are asked at the same time. */ export declare let WAIT: number;
7
+ /** How many of one call's new entities are looked at. */ export declare let MOST: number;
8
+ /** How much of a written entity's text the recall is keyed on. */ export declare let TEXT: number;
9
+ /** The text of something written, as a recall is keyed on it: its title and
10
+ * its words. */ export declare let textOf: (b: Bundle) => string;
11
+ /** The reply: for each entity the call's write made, the person's nearest
12
+ * earlier words and answered decisions, as `hit` bundles. */ export declare let reply: (host: Host) => Reply;
13
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAgBA,SAAS,KAAK,MAAM,2BAA0D;AAE9E,cAAc,IAAI,0BAA+B;AAEjD,SAAiB,KAAK,KAAK,2BAAgC;AAG3D;;8CAE8C,GAC9C,OAAO,YAAI,aAAW;AAEtB,uDAAuD,GACvD,OAAO,YAAI,aAAQ;AAEnB,gEAAgE,GAChE,OAAO,YAAI,aAAW;AAKtB;cACc,GACd,OAAO,YAAI,SAAU,GAAG,WAAS,MAAM,CAEwB;AAe/D;2DAC2D,GAC3D,OAAO,YAAI,QAAS,MAAM,SAAO,MA0EhC"}