@project-ava-supernova/core 0.2.184 → 0.2.186

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 (196) hide show
  1. package/dist/agent/agent.d.ts +0 -6
  2. package/dist/agent/agent.d.ts.map +1 -1
  3. package/dist/agent/agent.js +2 -53
  4. package/dist/agent/agent.js.map +1 -1
  5. package/dist/agent/system-prompt.d.ts +6 -0
  6. package/dist/agent/system-prompt.d.ts.map +1 -1
  7. package/dist/agent/system-prompt.js +3 -1
  8. package/dist/agent/system-prompt.js.map +1 -1
  9. package/dist/auto/auto-coordinator.d.ts.map +1 -1
  10. package/dist/auto/auto-coordinator.js +4 -17
  11. package/dist/auto/auto-coordinator.js.map +1 -1
  12. package/dist/brand/brand-kits.d.ts.map +1 -1
  13. package/dist/brand/brand-kits.js +18 -6
  14. package/dist/brand/brand-kits.js.map +1 -1
  15. package/dist/briefing/briefing-engine.d.ts +4 -3
  16. package/dist/briefing/briefing-engine.d.ts.map +1 -1
  17. package/dist/briefing/briefing-engine.js +16 -18
  18. package/dist/briefing/briefing-engine.js.map +1 -1
  19. package/dist/briefing/types.d.ts +4 -2
  20. package/dist/briefing/types.d.ts.map +1 -1
  21. package/dist/desktop/index.d.ts +2 -0
  22. package/dist/desktop/index.d.ts.map +1 -1
  23. package/dist/desktop/index.js +2 -0
  24. package/dist/desktop/index.js.map +1 -1
  25. package/dist/desktop/learned-steps.d.ts +39 -0
  26. package/dist/desktop/learned-steps.d.ts.map +1 -0
  27. package/dist/desktop/learned-steps.js +108 -0
  28. package/dist/desktop/learned-steps.js.map +1 -0
  29. package/dist/docs/content/concepts.d.ts.map +1 -1
  30. package/dist/docs/content/concepts.js +15 -13
  31. package/dist/docs/content/concepts.js.map +1 -1
  32. package/dist/docs/content/reference.d.ts.map +1 -1
  33. package/dist/docs/content/reference.js +3 -5
  34. package/dist/docs/content/reference.js.map +1 -1
  35. package/dist/docs/content/troubleshooting.js +1 -1
  36. package/dist/docs/content/troubleshooting.js.map +1 -1
  37. package/dist/docs/data/tools.js +4 -4
  38. package/dist/docs/data/tools.js.map +1 -1
  39. package/dist/docs/i18n/translations.d.ts.map +1 -1
  40. package/dist/docs/i18n/translations.js +1 -1
  41. package/dist/docs/i18n/translations.js.map +1 -1
  42. package/dist/events/event-detector.d.ts +0 -3
  43. package/dist/events/event-detector.d.ts.map +1 -1
  44. package/dist/events/event-detector.js +0 -27
  45. package/dist/events/event-detector.js.map +1 -1
  46. package/dist/i18n/locales/ar.d.ts.map +1 -1
  47. package/dist/i18n/locales/ar.js +72 -0
  48. package/dist/i18n/locales/ar.js.map +1 -1
  49. package/dist/i18n/locales/de.d.ts.map +1 -1
  50. package/dist/i18n/locales/de.js +72 -0
  51. package/dist/i18n/locales/de.js.map +1 -1
  52. package/dist/i18n/locales/en.d.ts +72 -0
  53. package/dist/i18n/locales/en.d.ts.map +1 -1
  54. package/dist/i18n/locales/en.js +73 -0
  55. package/dist/i18n/locales/en.js.map +1 -1
  56. package/dist/i18n/locales/es.d.ts.map +1 -1
  57. package/dist/i18n/locales/es.js +72 -0
  58. package/dist/i18n/locales/es.js.map +1 -1
  59. package/dist/i18n/locales/fr.d.ts.map +1 -1
  60. package/dist/i18n/locales/fr.js +72 -0
  61. package/dist/i18n/locales/fr.js.map +1 -1
  62. package/dist/i18n/locales/hi.d.ts.map +1 -1
  63. package/dist/i18n/locales/hi.js +72 -0
  64. package/dist/i18n/locales/hi.js.map +1 -1
  65. package/dist/i18n/locales/id.d.ts.map +1 -1
  66. package/dist/i18n/locales/id.js +72 -0
  67. package/dist/i18n/locales/id.js.map +1 -1
  68. package/dist/i18n/locales/it.d.ts.map +1 -1
  69. package/dist/i18n/locales/it.js +72 -0
  70. package/dist/i18n/locales/it.js.map +1 -1
  71. package/dist/i18n/locales/ja.d.ts.map +1 -1
  72. package/dist/i18n/locales/ja.js +72 -0
  73. package/dist/i18n/locales/ja.js.map +1 -1
  74. package/dist/i18n/locales/ko.d.ts.map +1 -1
  75. package/dist/i18n/locales/ko.js +72 -0
  76. package/dist/i18n/locales/ko.js.map +1 -1
  77. package/dist/i18n/locales/nl.d.ts.map +1 -1
  78. package/dist/i18n/locales/nl.js +72 -0
  79. package/dist/i18n/locales/nl.js.map +1 -1
  80. package/dist/i18n/locales/pl.d.ts.map +1 -1
  81. package/dist/i18n/locales/pl.js +72 -0
  82. package/dist/i18n/locales/pl.js.map +1 -1
  83. package/dist/i18n/locales/pt.d.ts.map +1 -1
  84. package/dist/i18n/locales/pt.js +72 -0
  85. package/dist/i18n/locales/pt.js.map +1 -1
  86. package/dist/i18n/locales/ru.d.ts.map +1 -1
  87. package/dist/i18n/locales/ru.js +72 -0
  88. package/dist/i18n/locales/ru.js.map +1 -1
  89. package/dist/i18n/locales/th.d.ts.map +1 -1
  90. package/dist/i18n/locales/th.js +72 -0
  91. package/dist/i18n/locales/th.js.map +1 -1
  92. package/dist/i18n/locales/tr.d.ts.map +1 -1
  93. package/dist/i18n/locales/tr.js +72 -0
  94. package/dist/i18n/locales/tr.js.map +1 -1
  95. package/dist/i18n/locales/uk.d.ts.map +1 -1
  96. package/dist/i18n/locales/uk.js +72 -0
  97. package/dist/i18n/locales/uk.js.map +1 -1
  98. package/dist/i18n/locales/vi.d.ts.map +1 -1
  99. package/dist/i18n/locales/vi.js +72 -0
  100. package/dist/i18n/locales/vi.js.map +1 -1
  101. package/dist/i18n/locales/zh-CN.d.ts.map +1 -1
  102. package/dist/i18n/locales/zh-CN.js +72 -0
  103. package/dist/i18n/locales/zh-CN.js.map +1 -1
  104. package/dist/i18n/locales/zh-TW.d.ts.map +1 -1
  105. package/dist/i18n/locales/zh-TW.js +72 -0
  106. package/dist/i18n/locales/zh-TW.js.map +1 -1
  107. package/dist/index.d.ts +8 -1
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +6 -1
  110. package/dist/index.js.map +1 -1
  111. package/dist/memory-v4/consolidate.d.ts +44 -0
  112. package/dist/memory-v4/consolidate.d.ts.map +1 -0
  113. package/dist/memory-v4/consolidate.js +241 -0
  114. package/dist/memory-v4/consolidate.js.map +1 -0
  115. package/dist/memory-v4/fact-cache.d.ts +38 -0
  116. package/dist/memory-v4/fact-cache.d.ts.map +1 -0
  117. package/dist/memory-v4/fact-cache.js +133 -0
  118. package/dist/memory-v4/fact-cache.js.map +1 -0
  119. package/dist/memory-v4/fact-file.d.ts +30 -0
  120. package/dist/memory-v4/fact-file.d.ts.map +1 -0
  121. package/dist/memory-v4/fact-file.js +133 -0
  122. package/dist/memory-v4/fact-file.js.map +1 -0
  123. package/dist/memory-v4/files.d.ts +30 -0
  124. package/dist/memory-v4/files.d.ts.map +1 -0
  125. package/dist/memory-v4/files.js +115 -0
  126. package/dist/memory-v4/files.js.map +1 -0
  127. package/dist/memory-v4/import-v3.d.ts +44 -0
  128. package/dist/memory-v4/import-v3.d.ts.map +1 -0
  129. package/dist/memory-v4/import-v3.js +176 -0
  130. package/dist/memory-v4/import-v3.js.map +1 -0
  131. package/dist/memory-v4/index.d.ts +20 -0
  132. package/dist/memory-v4/index.d.ts.map +1 -0
  133. package/dist/memory-v4/index.js +14 -0
  134. package/dist/memory-v4/index.js.map +1 -0
  135. package/dist/memory-v4/model.d.ts +38 -0
  136. package/dist/memory-v4/model.d.ts.map +1 -0
  137. package/dist/memory-v4/model.js +59 -0
  138. package/dist/memory-v4/model.js.map +1 -0
  139. package/dist/memory-v4/page.d.ts +58 -0
  140. package/dist/memory-v4/page.d.ts.map +1 -0
  141. package/dist/memory-v4/page.js +161 -0
  142. package/dist/memory-v4/page.js.map +1 -0
  143. package/dist/memory-v4/projects.d.ts +40 -0
  144. package/dist/memory-v4/projects.d.ts.map +1 -0
  145. package/dist/memory-v4/projects.js +142 -0
  146. package/dist/memory-v4/projects.js.map +1 -0
  147. package/dist/memory-v4/promotion.d.ts +17 -0
  148. package/dist/memory-v4/promotion.d.ts.map +1 -0
  149. package/dist/memory-v4/promotion.js +50 -0
  150. package/dist/memory-v4/promotion.js.map +1 -0
  151. package/dist/memory-v4/reader.d.ts +83 -0
  152. package/dist/memory-v4/reader.d.ts.map +1 -0
  153. package/dist/memory-v4/reader.js +268 -0
  154. package/dist/memory-v4/reader.js.map +1 -0
  155. package/dist/memory-v4/search-index.d.ts +43 -0
  156. package/dist/memory-v4/search-index.d.ts.map +1 -0
  157. package/dist/memory-v4/search-index.js +147 -0
  158. package/dist/memory-v4/search-index.js.map +1 -0
  159. package/dist/memory-v4/store.d.ts +192 -0
  160. package/dist/memory-v4/store.d.ts.map +1 -0
  161. package/dist/memory-v4/store.js +622 -0
  162. package/dist/memory-v4/store.js.map +1 -0
  163. package/dist/memory-v4/threads-episodes.d.ts +36 -0
  164. package/dist/memory-v4/threads-episodes.d.ts.map +1 -0
  165. package/dist/memory-v4/threads-episodes.js +119 -0
  166. package/dist/memory-v4/threads-episodes.js.map +1 -0
  167. package/dist/memory-v4/types.d.ts +84 -0
  168. package/dist/memory-v4/types.d.ts.map +1 -0
  169. package/dist/memory-v4/types.js +14 -0
  170. package/dist/memory-v4/types.js.map +1 -0
  171. package/dist/tools/benchmark.d.ts.map +1 -1
  172. package/dist/tools/benchmark.js +21 -25
  173. package/dist/tools/benchmark.js.map +1 -1
  174. package/dist/tools/design-fonts.d.ts +3 -2
  175. package/dist/tools/design-fonts.d.ts.map +1 -1
  176. package/dist/tools/design-fonts.js +16 -2
  177. package/dist/tools/design-fonts.js.map +1 -1
  178. package/dist/tools/learning.d.ts.map +1 -1
  179. package/dist/tools/learning.js +7 -13
  180. package/dist/tools/learning.js.map +1 -1
  181. package/dist/tools/memory-recall-v4.d.ts +20 -0
  182. package/dist/tools/memory-recall-v4.d.ts.map +1 -0
  183. package/dist/tools/memory-recall-v4.js +49 -0
  184. package/dist/tools/memory-recall-v4.js.map +1 -0
  185. package/dist/tools/memory-write-v4.d.ts +40 -0
  186. package/dist/tools/memory-write-v4.d.ts.map +1 -0
  187. package/dist/tools/memory-write-v4.js +176 -0
  188. package/dist/tools/memory-write-v4.js.map +1 -0
  189. package/dist/tools/report-generate.d.ts +1 -0
  190. package/dist/tools/report-generate.d.ts.map +1 -1
  191. package/dist/tools/report-generate.js +10 -9
  192. package/dist/tools/report-generate.js.map +1 -1
  193. package/dist/tools/tool-registry.d.ts.map +1 -1
  194. package/dist/tools/tool-registry.js +6 -8
  195. package/dist/tools/tool-registry.js.map +1 -1
  196. package/package.json +1 -1
@@ -0,0 +1,133 @@
1
+ /**
2
+ * A per-folder cache of parsed fact files.
3
+ *
4
+ * Without it, every save re-read every fact to check for a repeat (200 ms per
5
+ * save at 600 facts). With it, a folder is only re-read when it changed, and
6
+ * then only the files that changed.
7
+ *
8
+ * Seeing changes from the other apps: every write in this store is a rename
9
+ * into the folder, which updates the folder's own modified time, so an
10
+ * unchanged folder time means nothing was added, removed or rewritten by any
11
+ * app. A file edited by hand in an editor changes only the file, so a full
12
+ * check of every file's time also runs whenever the last one is a few seconds
13
+ * old. Hand edits therefore show up within seconds; app writes at once.
14
+ */
15
+ import { readdir, stat } from 'node:fs/promises';
16
+ import { join } from 'node:path';
17
+ import { parseFact } from './fact-file.js';
18
+ import { readIfExists } from './files.js';
19
+ const FULL_CHECK_MS = 3000;
20
+ export class FactFolderCache {
21
+ dir;
22
+ state;
23
+ entries = new Map();
24
+ folderMtime = -1;
25
+ lastFullCheck = 0;
26
+ /** Goes up whenever the cached facts change; the search index watches it. */
27
+ version = 0;
28
+ constructor(dir, state) {
29
+ this.dir = dir;
30
+ this.state = state;
31
+ }
32
+ /** Force a check on the next read. */
33
+ invalidate() {
34
+ this.folderMtime = -1;
35
+ }
36
+ /**
37
+ * Record this process's own write without rescanning. Called while holding
38
+ * the store lock, so no other app can have written in between, and the
39
+ * folder's new time can be taken as "everything we know about".
40
+ */
41
+ async noteWrite(fact) {
42
+ await this.note(`${fact.id}.md`, fact);
43
+ }
44
+ async noteRemove(id) {
45
+ await this.note(`${id}.md`, null);
46
+ }
47
+ async note(name, fact) {
48
+ const wasCurrent = this.folderMtime !== -1;
49
+ if (fact) {
50
+ try {
51
+ this.entries.set(name, { mtimeMs: (await stat(join(this.dir, name))).mtimeMs, fact });
52
+ }
53
+ catch {
54
+ this.entries.delete(name);
55
+ }
56
+ }
57
+ else {
58
+ this.entries.delete(name);
59
+ }
60
+ this.version++;
61
+ // Only trust the new folder time if the cache was current before this write.
62
+ if (wasCurrent) {
63
+ try {
64
+ this.folderMtime = (await stat(this.dir)).mtimeMs;
65
+ }
66
+ catch {
67
+ this.folderMtime = -1;
68
+ }
69
+ }
70
+ }
71
+ async facts() {
72
+ let folderMtime;
73
+ try {
74
+ folderMtime = (await stat(this.dir)).mtimeMs;
75
+ }
76
+ catch {
77
+ if (this.entries.size > 0) {
78
+ this.entries.clear();
79
+ this.version++;
80
+ }
81
+ this.folderMtime = -1;
82
+ return [];
83
+ }
84
+ const fresh = Date.now() - this.lastFullCheck < FULL_CHECK_MS;
85
+ if (folderMtime !== this.folderMtime || !fresh)
86
+ await this.rescan(folderMtime);
87
+ const out = [];
88
+ for (const e of this.entries.values())
89
+ if (e.fact)
90
+ out.push(e.fact);
91
+ return out.sort((a, b) => a.id.localeCompare(b.id));
92
+ }
93
+ async rescan(folderMtime) {
94
+ let names;
95
+ try {
96
+ names = (await readdir(this.dir)).filter((n) => n.endsWith('.md'));
97
+ }
98
+ catch {
99
+ names = [];
100
+ }
101
+ let changed = false;
102
+ const seen = new Set(names);
103
+ for (const name of [...this.entries.keys()]) {
104
+ if (!seen.has(name)) {
105
+ this.entries.delete(name);
106
+ changed = true;
107
+ }
108
+ }
109
+ await Promise.all(names.map(async (name) => {
110
+ const path = join(this.dir, name);
111
+ let mtimeMs;
112
+ try {
113
+ mtimeMs = (await stat(path)).mtimeMs;
114
+ }
115
+ catch {
116
+ if (this.entries.delete(name))
117
+ changed = true;
118
+ return;
119
+ }
120
+ const cached = this.entries.get(name);
121
+ if (cached && cached.mtimeMs === mtimeMs)
122
+ return;
123
+ const raw = await readIfExists(path);
124
+ this.entries.set(name, { mtimeMs, fact: raw ? parseFact(name.slice(0, -3), raw, this.state) : null });
125
+ changed = true;
126
+ }));
127
+ this.folderMtime = folderMtime;
128
+ this.lastFullCheck = Date.now();
129
+ if (changed)
130
+ this.version++;
131
+ }
132
+ }
133
+ //# sourceMappingURL=fact-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fact-cache.js","sourceRoot":"","sources":["../../src/memory-v4/fact-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,aAAa,GAAG,IAAI,CAAC;AAO3B,MAAM,OAAO,eAAe;IAOG;IAA8B;IANnD,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACnC,WAAW,GAAG,CAAC,CAAC,CAAC;IACjB,aAAa,GAAG,CAAC,CAAC;IAC1B,6EAA6E;IAC7E,OAAO,GAAG,CAAC,CAAC;IAEZ,YAA6B,GAAW,EAAmB,KAAgB;QAA9C,QAAG,GAAH,GAAG,CAAQ;QAAmB,UAAK,GAAL,KAAK,CAAW;IAAG,CAAC;IAE/E,sCAAsC;IACtC,UAAU;QACR,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS,CAAC,IAAU;QACxB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAEO,KAAK,C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30 @@
1
+ /**
2
+ * One fact, one Markdown file: a short frontmatter block, then the fact in
3
+ * plain words. Written so the person can open it in any editor and read it,
4
+ * and edit it by hand without breaking anything.
5
+ *
6
+ * ---
7
+ * kind: preference
8
+ * scope: everywhere
9
+ * source: said
10
+ * quote: "im not a great fan of bold"
11
+ * from: 2026-11-06
12
+ * ---
13
+ * Doesn't like bold type; prefers thin or regular weights.
14
+ */
15
+ import type { Fact, FactState } from './types.js';
16
+ export declare function serializeFact(fact: Fact): string;
17
+ /**
18
+ * Read a fact file. Lenient on purpose: a file the person has edited by hand
19
+ * still loads, with sensible defaults for anything missing or unrecognised.
20
+ * Returns null only when there is no fact text at all.
21
+ */
22
+ export declare function parseFact(id: string, content: string, state: FactState): Fact | null;
23
+ /**
24
+ * A readable file name from the fact's words: "doesnt-like-bold-type".
25
+ * Uniqueness is the store's job (it adds -2, -3 on a clash).
26
+ */
27
+ export declare function slugFor(text: string): string;
28
+ /** Lowercased, punctuation-free text, for spotting exact repeats. */
29
+ export declare function normalizeForMatch(text: string): string;
30
+ //# sourceMappingURL=fact-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fact-file.d.ts","sourceRoot":"","sources":["../../src/memory-v4/fact-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAmC,SAAS,EAAE,MAAM,YAAY,CAAC;AAwBnF,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAqBhD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAuCpF;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiB5C;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * One fact, one Markdown file: a short frontmatter block, then the fact in
3
+ * plain words. Written so the person can open it in any editor and read it,
4
+ * and edit it by hand without breaking anything.
5
+ *
6
+ * ---
7
+ * kind: preference
8
+ * scope: everywhere
9
+ * source: said
10
+ * quote: "im not a great fan of bold"
11
+ * from: 2026-11-06
12
+ * ---
13
+ * Doesn't like bold type; prefers thin or regular weights.
14
+ */
15
+ import { FACT_KINDS, FACT_SOURCES } from './types.js';
16
+ const FIELD_ORDER = ['kind', 'scope', 'source', 'quote', 'from', 'confirmed', 'replaces', 'until', 'superseded_by', 'tags'];
17
+ /** Strings that YAML would misread are written as JSON strings (valid YAML). */
18
+ function formatValue(value) {
19
+ if (Array.isArray(value))
20
+ return JSON.stringify(value);
21
+ return /^[\w./:@+-]+$/.test(value) ? value : JSON.stringify(value);
22
+ }
23
+ function parseValue(raw) {
24
+ const v = raw.trim();
25
+ if (v.startsWith('"') || v.startsWith('[')) {
26
+ try {
27
+ return JSON.parse(v);
28
+ }
29
+ catch {
30
+ // Hand-edited and no longer valid JSON: keep what's there rather than lose it.
31
+ }
32
+ }
33
+ if (v.startsWith("'") && v.endsWith("'") && v.length >= 2)
34
+ return v.slice(1, -1);
35
+ return v;
36
+ }
37
+ export function serializeFact(fact) {
38
+ const fields = {
39
+ kind: fact.kind,
40
+ scope: fact.scope,
41
+ source: fact.source,
42
+ quote: fact.quote,
43
+ from: fact.from,
44
+ confirmed: fact.confirmed,
45
+ replaces: fact.replaces,
46
+ until: fact.until,
47
+ superseded_by: fact.supersededBy,
48
+ tags: fact.tags && fact.tags.length > 0 ? fact.tags : undefined,
49
+ };
50
+ const lines = ['---'];
51
+ for (const key of FIELD_ORDER) {
52
+ const value = fields[key];
53
+ if (value === undefined || value === '')
54
+ continue;
55
+ lines.push(`${key}: ${formatValue(value)}`);
56
+ }
57
+ lines.push('---', fact.text.trim(), '');
58
+ return lines.join('\n');
59
+ }
60
+ /**
61
+ * Read a fact file. Lenient on purpose: a file the person has edited by hand
62
+ * still loads, with sensible defaults for anything missing or unrecognised.
63
+ * Returns null only when there is no fact text at all.
64
+ */
65
+ export function parseFact(id, content, state) {
66
+ const text = content.replace(/^/, '').replace(/\r\n/g, '\n');
67
+ const fields = {};
68
+ let body = text;
69
+ const m = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
70
+ if (m) {
71
+ for (const line of m[1].split('\n')) {
72
+ const kv = line.match(/^([a-z_]+):\s*(.*)$/);
73
+ if (kv)
74
+ fields[kv[1]] = parseValue(kv[2]);
75
+ }
76
+ body = m[2];
77
+ }
78
+ const factText = body.trim();
79
+ if (!factText)
80
+ return null;
81
+ const str = (k) => (typeof fields[k] === 'string' && fields[k] ? fields[k] : undefined);
82
+ const kind = FACT_KINDS.includes(str('kind')) ? str('kind') : 'project';
83
+ const source = FACT_SOURCES.includes(str('source')) ? str('source') : 'said';
84
+ const scopeRaw = str('scope');
85
+ const scope = scopeRaw && (scopeRaw === 'everywhere' || scopeRaw.startsWith('project:'))
86
+ ? scopeRaw
87
+ : 'everywhere';
88
+ const tags = Array.isArray(fields.tags) ? fields.tags.map(String) : undefined;
89
+ return {
90
+ id,
91
+ kind,
92
+ scope,
93
+ source,
94
+ quote: str('quote'),
95
+ from: str('from') ?? '',
96
+ confirmed: str('confirmed'),
97
+ replaces: str('replaces'),
98
+ until: str('until'),
99
+ supersededBy: str('superseded_by'),
100
+ tags,
101
+ text: factText,
102
+ state,
103
+ };
104
+ }
105
+ /**
106
+ * A readable file name from the fact's words: "doesnt-like-bold-type".
107
+ * Uniqueness is the store's job (it adds -2, -3 on a clash).
108
+ */
109
+ export function slugFor(text) {
110
+ const words = text
111
+ .normalize('NFKD')
112
+ .replace(/[̀-ͯ]/g, '')
113
+ .toLowerCase()
114
+ .replace(/['’]/g, '')
115
+ .replace(/[^a-z0-9]+/g, ' ')
116
+ .trim()
117
+ .split(/\s+/)
118
+ .filter(Boolean);
119
+ let slug = '';
120
+ for (const w of words) {
121
+ if ((slug + '-' + w).length > 60)
122
+ break;
123
+ slug = slug ? `${slug}-${w}` : w;
124
+ if (slug.split('-').length >= 8)
125
+ break;
126
+ }
127
+ return slug || 'fact';
128
+ }
129
+ /** Lowercased, punctuation-free text, for spotting exact repeats. */
130
+ export function normalizeForMatch(text) {
131
+ return text.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
132
+ }
133
+ //# sourceMappingURL=fact-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fact-file.js","sourceRoot":"","sources":["../../src/memory-v4/fact-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,CAAU,CAAC;AAErI,gFAAgF;AAChF,SAAS,WAAW,CAAC,KAAwB;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACrB,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACP,+EAA+E;QACjF,CAA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AAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE;YAAE,MAAM;QACxC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC;YAAE,MAAM;IACzC,CAAC;IACD,OAAO,IAAI,IAAI,MAAM,CAAC;AACxB,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACpE,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Safe file handling for memory v4.
3
+ *
4
+ * The extension, the IDE, the CLI and the hub can all be open at once, and all
5
+ * of them write to the same folder. Two rules keep that safe:
6
+ *
7
+ * 1. Every write is atomic: written to a temp file beside the target, then
8
+ * renamed over it. A reader never sees half a file.
9
+ * 2. Every change to the store happens under one lock (a directory, because
10
+ * mkdir is atomic on every platform). The lock is held for the length of
11
+ * one change, never across a model call.
12
+ */
13
+ /**
14
+ * Write a file atomically. On Windows a rename can fail for a moment while
15
+ * another process has the target open for reading, so it is retried briefly.
16
+ */
17
+ export declare function writeAtomic(path: string, content: string): Promise<void>;
18
+ /** Read a file, or null if it doesn't exist. */
19
+ export declare function readIfExists(path: string): Promise<string | null>;
20
+ /** Remove a file if it exists; true if something was removed. */
21
+ export declare function removeIfExists(path: string): Promise<boolean>;
22
+ /**
23
+ * Run `fn` holding the store's lock. Waits for another holder; takes over a
24
+ * lock that has gone stale (its owner crashed). Throws if the lock can't be
25
+ * had in LOCK_WAIT_MS, rather than writing without it.
26
+ */
27
+ export declare function withLock<T>(root: string, fn: () => Promise<T>): Promise<T>;
28
+ /** Today as YYYY-MM-DD in local time (dates in memory are the person's days). */
29
+ export declare function today(now?: Date): string;
30
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/memory-v4/files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB9E;AAED,gDAAgD;AAChD,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOvE;AAED,iEAAiE;AACjE,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQnE;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA+BhF;AAED,iFAAiF;AACjF,wBAAgB,KAAK,CAAC,GAAG,OAAa,GAAG,MAAM,CAK9C"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Safe file handling for memory v4.
3
+ *
4
+ * The extension, the IDE, the CLI and the hub can all be open at once, and all
5
+ * of them write to the same folder. Two rules keep that safe:
6
+ *
7
+ * 1. Every write is atomic: written to a temp file beside the target, then
8
+ * renamed over it. A reader never sees half a file.
9
+ * 2. Every change to the store happens under one lock (a directory, because
10
+ * mkdir is atomic on every platform). The lock is held for the length of
11
+ * one change, never across a model call.
12
+ */
13
+ import { mkdir, rename, rm, stat, writeFile, readFile } from 'node:fs/promises';
14
+ import { dirname, join } from 'node:path';
15
+ import { randomBytes } from 'node:crypto';
16
+ /** A lock older than this was left by a process that died mid-change. */
17
+ const STALE_LOCK_MS = 15_000;
18
+ const LOCK_WAIT_MS = 10_000;
19
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
20
+ /**
21
+ * Write a file atomically. On Windows a rename can fail for a moment while
22
+ * another process has the target open for reading, so it is retried briefly.
23
+ */
24
+ export async function writeAtomic(path, content) {
25
+ await mkdir(dirname(path), { recursive: true });
26
+ const tmp = `${path}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
27
+ await writeFile(tmp, content, 'utf-8');
28
+ for (let attempt = 0;; attempt++) {
29
+ try {
30
+ await rename(tmp, path);
31
+ return;
32
+ }
33
+ catch (err) {
34
+ const code = err.code;
35
+ if ((code === 'EPERM' || code === 'EBUSY' || code === 'EACCES') && attempt < 8) {
36
+ await sleep(25 * (attempt + 1));
37
+ continue;
38
+ }
39
+ await rm(tmp, { force: true });
40
+ throw err;
41
+ }
42
+ }
43
+ }
44
+ /** Read a file, or null if it doesn't exist. */
45
+ export async function readIfExists(path) {
46
+ try {
47
+ return await readFile(path, 'utf-8');
48
+ }
49
+ catch (err) {
50
+ if (err.code === 'ENOENT')
51
+ return null;
52
+ throw err;
53
+ }
54
+ }
55
+ /** Remove a file if it exists; true if something was removed. */
56
+ export async function removeIfExists(path) {
57
+ try {
58
+ await rm(path);
59
+ return true;
60
+ }
61
+ catch (err) {
62
+ if (err.code === 'ENOENT')
63
+ return false;
64
+ throw err;
65
+ }
66
+ }
67
+ /**
68
+ * Run `fn` holding the store's lock. Waits for another holder; takes over a
69
+ * lock that has gone stale (its owner crashed). Throws if the lock can't be
70
+ * had in LOCK_WAIT_MS, rather than writing without it.
71
+ */
72
+ export async function withLock(root, fn) {
73
+ const lockDir = join(root, '.lock');
74
+ await mkdir(root, { recursive: true });
75
+ const started = Date.now();
76
+ for (let attempt = 0;; attempt++) {
77
+ try {
78
+ await mkdir(lockDir);
79
+ break;
80
+ }
81
+ catch (err) {
82
+ if (err.code !== 'EEXIST')
83
+ throw err;
84
+ try {
85
+ const age = Date.now() - (await stat(lockDir)).mtimeMs;
86
+ if (age > STALE_LOCK_MS) {
87
+ await rm(lockDir, { recursive: true, force: true });
88
+ continue;
89
+ }
90
+ }
91
+ catch {
92
+ // Released between our mkdir and stat: just try again.
93
+ continue;
94
+ }
95
+ if (Date.now() - started > LOCK_WAIT_MS) {
96
+ throw new Error('Memory is busy in another window — try again in a moment.');
97
+ }
98
+ await sleep(Math.min(5 + 5 * attempt, 50));
99
+ }
100
+ }
101
+ try {
102
+ return await fn();
103
+ }
104
+ finally {
105
+ await rm(lockDir, { recursive: true, force: true });
106
+ }
107
+ }
108
+ /** Today as YYYY-MM-DD in local time (dates in memory are the person's days). */
109
+ export function today(now = new Date()) {
110
+ const y = now.getFullYear();
111
+ const m = String(now.getMonth() + 1).padStart(2, '0');
112
+ const d = String(now.getDate()).padStart(2, '0');
113
+ return `${y}-${m}-${d}`;
114
+ }
115
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/memory-v4/files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,yEAAyE;AACzE,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEpE;;;GA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AAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,GAAG,YAAY,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;YAC/E,CAAC;YACD,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,KAAK,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE;IACpC,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtD,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACjD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The free import (DECIDED 15 Nov): on the first start after the update, an
3
+ * existing user's old memory comes across automatically, with no model and no
4
+ * cost. Their memory works from the first minute; the tidy-up that sorts and
5
+ * merges it properly is OFFERED on the Memory page, never run unasked.
6
+ *
7
+ * - Old stores read: ~/.ava/memory/graph.json, ~/.ava/memory.json, and each
8
+ * registered project's .ava/memory.json and .ava/memory/graph.json.
9
+ * - Exact repeats are folded (the old graph held each memory ~3 times).
10
+ * - A memory keeps the project it was stored in; the main store's go under
11
+ * "everywhere". (Better sorting is the tidy-up's job, not a guess here.)
12
+ * - Obvious noise ("The assistant…", "Discovery: …") is set aside in
13
+ * .import/set-aside.json, not deleted, and the old files are never touched.
14
+ * - Runs once: .import/done.json records it. `since` imports only what was
15
+ * saved after a date (for someone whose approved memory is already in).
16
+ */
17
+ import type { AvaMemory } from './store.js';
18
+ export interface ImportResult {
19
+ imported: number;
20
+ setAside: number;
21
+ repeatsFolded: number;
22
+ projects: number;
23
+ skippedAsDone?: boolean;
24
+ }
25
+ /**
26
+ * "Delete all memories" also deletes the old memory's files — the same ones
27
+ * the import reads (global, and each project the old registry knew) — so
28
+ * nothing of what they asked to forget is left on disk. Never throws.
29
+ */
30
+ export declare function removeOldMemoryFiles(oldHome: string): Promise<number>;
31
+ export declare function importDone(root: string): boolean;
32
+ /**
33
+ * The first start after the update: bring the old memory across once, free.
34
+ * A no-op once done (or for a new user, who has no old memory: the marker is
35
+ * still written, so it never looks again). Never throws.
36
+ */
37
+ export declare function ensureOldMemoryImported(mem: AvaMemory, oldHome: string, log?: (m: string) => void): Promise<void>;
38
+ export declare function importOldMemory(opts: {
39
+ mem: AvaMemory;
40
+ oldHome: string;
41
+ since?: string;
42
+ now?: Date;
43
+ }): Promise<ImportResult>;
44
+ //# sourceMappingURL=import-v3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-v3.d.ts","sourceRoot":"","sources":["../../src/memory-v4/import-v3.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAkB5C,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAkBD;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa3E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvH;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CA6ElI"}