dsh-cross-memory 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +247 -2
- package/cordis.patch.yml +27 -0
- package/docs/DETAIL.md +13 -0
- package/docs/DETAIL.zh.md +17 -0
- package/icon.svg +1 -0
- package/lib/backfill.js +273 -0
- package/lib/citations.js +305 -0
- package/lib/client.js +1550 -0
- package/lib/config.js +736 -0
- package/lib/consolidate.js +1119 -0
- package/lib/extract.js +570 -0
- package/lib/gate.js +137 -0
- package/lib/git-origin.js +224 -0
- package/lib/index.js +4475 -0
- package/lib/log.js +260 -0
- package/lib/loops.js +186 -0
- package/lib/notices.js +195 -0
- package/lib/notify.js +33 -0
- package/lib/persona.js +112 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +455 -0
- package/lib/render.js +678 -0
- package/lib/retention.js +64 -0
- package/lib/schedule.js +245 -0
- package/lib/search.js +1068 -0
- package/lib/skills.js +220 -0
- package/lib/state.js +701 -0
- package/lib/storage.js +1424 -0
- package/lib/sync-runtime.js +268 -0
- package/lib/sync.js +620 -0
- package/lib/test/activity.test.js +74 -0
- package/lib/test/archive.test.js +182 -0
- package/lib/test/backfill.test.js +144 -0
- package/lib/test/citations.test.js +91 -0
- package/lib/test/client-wiring.test.js +134 -0
- package/lib/test/consolidate-job.test.js +95 -0
- package/lib/test/consolidate.test.js +430 -0
- package/lib/test/consolidation-selection.test.js +152 -0
- package/lib/test/dedupe-keys.test.js +230 -0
- package/lib/test/delta.test.js +93 -0
- package/lib/test/derived.test.js +110 -0
- package/lib/test/disputes-panel.test.js +314 -0
- package/lib/test/eval.test.js +171 -0
- package/lib/test/expand.test.js +164 -0
- package/lib/test/extract.test.js +1020 -0
- package/lib/test/git-origin.test.js +189 -0
- package/lib/test/injection.test.js +440 -0
- package/lib/test/kind-filter.test.js +49 -0
- package/lib/test/legacy-state.test.js +69 -0
- package/lib/test/log.test.js +156 -0
- package/lib/test/loops.test.js +86 -0
- package/lib/test/memory.test.js +855 -0
- package/lib/test/notices.test.js +140 -0
- package/lib/test/persona.test.js +73 -0
- package/lib/test/prefilter.test.js +73 -0
- package/lib/test/preset.test.js +77 -0
- package/lib/test/raw-recall.test.js +186 -0
- package/lib/test/recall.test.js +433 -0
- package/lib/test/reflection.test.js +64 -0
- package/lib/test/remote.test.js +227 -0
- package/lib/test/retention.test.js +117 -0
- package/lib/test/retrieval.test.js +142 -0
- package/lib/test/rotation.test.js +228 -0
- package/lib/test/schedule.test.js +112 -0
- package/lib/test/settings-card.test.js +58 -0
- package/lib/test/skills.test.js +129 -0
- package/lib/test/state.test.js +212 -0
- package/lib/test/subagent-contract.test.js +139 -0
- package/lib/test/sweep.test.js +159 -0
- package/lib/test/sync.test.js +314 -0
- package/lib/test/time.test.js +171 -0
- package/lib/time.js +303 -0
- package/lib/tool.js +330 -0
- package/lib/types/backfill.d.ts +96 -0
- package/lib/types/citations.d.ts +105 -0
- package/lib/types/config.d.ts +811 -0
- package/lib/types/consolidate.d.ts +742 -0
- package/lib/types/extract.d.ts +352 -0
- package/lib/types/gate.d.ts +83 -0
- package/lib/types/git-origin.d.ts +23 -0
- package/lib/types/index.d.ts +1316 -0
- package/lib/types/log.d.ts +144 -0
- package/lib/types/loops.d.ts +82 -0
- package/lib/types/notices.d.ts +117 -0
- package/lib/types/notify.d.ts +12 -0
- package/lib/types/persona.d.ts +43 -0
- package/lib/types/query.d.ts +45 -0
- package/lib/types/raw-recall.d.ts +84 -0
- package/lib/types/reflection.d.ts +122 -0
- package/lib/types/remote.d.ts +233 -0
- package/lib/types/render.d.ts +286 -0
- package/lib/types/retention.d.ts +66 -0
- package/lib/types/schedule.d.ts +116 -0
- package/lib/types/search.d.ts +583 -0
- package/lib/types/skills.d.ts +71 -0
- package/lib/types/state.d.ts +294 -0
- package/lib/types/storage.d.ts +458 -0
- package/lib/types/sync-runtime.d.ts +103 -0
- package/lib/types/sync.d.ts +222 -0
- package/lib/types/test/activity.test.d.ts +1 -0
- package/lib/types/test/archive.test.d.ts +1 -0
- package/lib/types/test/backfill.test.d.ts +1 -0
- package/lib/types/test/citations.test.d.ts +1 -0
- package/lib/types/test/client-wiring.test.d.ts +1 -0
- package/lib/types/test/consolidate-job.test.d.ts +1 -0
- package/lib/types/test/consolidate.test.d.ts +1 -0
- package/lib/types/test/consolidation-selection.test.d.ts +1 -0
- package/lib/types/test/dedupe-keys.test.d.ts +1 -0
- package/lib/types/test/delta.test.d.ts +1 -0
- package/lib/types/test/derived.test.d.ts +1 -0
- package/lib/types/test/disputes-panel.test.d.ts +1 -0
- package/lib/types/test/eval.test.d.ts +1 -0
- package/lib/types/test/expand.test.d.ts +1 -0
- package/lib/types/test/extract.test.d.ts +1 -0
- package/lib/types/test/git-origin.test.d.ts +1 -0
- package/lib/types/test/injection.test.d.ts +1 -0
- package/lib/types/test/kind-filter.test.d.ts +1 -0
- package/lib/types/test/legacy-state.test.d.ts +1 -0
- package/lib/types/test/log.test.d.ts +1 -0
- package/lib/types/test/loops.test.d.ts +1 -0
- package/lib/types/test/memory.test.d.ts +1 -0
- package/lib/types/test/notices.test.d.ts +1 -0
- package/lib/types/test/persona.test.d.ts +1 -0
- package/lib/types/test/prefilter.test.d.ts +1 -0
- package/lib/types/test/preset.test.d.ts +1 -0
- package/lib/types/test/raw-recall.test.d.ts +1 -0
- package/lib/types/test/recall.test.d.ts +1 -0
- package/lib/types/test/reflection.test.d.ts +1 -0
- package/lib/types/test/remote.test.d.ts +1 -0
- package/lib/types/test/retention.test.d.ts +1 -0
- package/lib/types/test/retrieval.test.d.ts +1 -0
- package/lib/types/test/rotation.test.d.ts +1 -0
- package/lib/types/test/schedule.test.d.ts +1 -0
- package/lib/types/test/settings-card.test.d.ts +1 -0
- package/lib/types/test/skills.test.d.ts +1 -0
- package/lib/types/test/state.test.d.ts +1 -0
- package/lib/types/test/subagent-contract.test.d.ts +1 -0
- package/lib/types/test/sweep.test.d.ts +1 -0
- package/lib/types/test/sync.test.d.ts +1 -0
- package/lib/types/test/time.test.d.ts +1 -0
- package/lib/types/time.d.ts +67 -0
- package/lib/types/tool.d.ts +9 -0
- package/lib/types/types.d.ts +374 -0
- package/lib/types/workspace.d.ts +20 -0
- package/lib/types.js +47 -0
- package/lib/workspace.js +65 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reflections: the layer that notices what no single memory says.
|
|
3
|
+
*
|
|
4
|
+
* Every other layer in this plugin records or retrieves a fact. This one is the
|
|
5
|
+
* Generative Agents "reflection" step: periodically synthesize a small number of
|
|
6
|
+
* higher-level observations from what has accumulated, so the store can say
|
|
7
|
+
* something it never wrote down — a pattern across projects, a preference that
|
|
8
|
+
* only shows up over weeks, a habit the user has not named.
|
|
9
|
+
*
|
|
10
|
+
* Three constraints keep it from becoming a prose generator:
|
|
11
|
+
*
|
|
12
|
+
* - **Every insight cites the memories it came from.** An insight whose evidence
|
|
13
|
+
* the store cannot show is a guess wearing a conclusion's clothes; it is dropped
|
|
14
|
+
* in parsing, not merely flagged.
|
|
15
|
+
* - **Reflections are their own files**, never injected into every conversation.
|
|
16
|
+
* They are for a person to read and for the profile to be refined FROM, which is
|
|
17
|
+
* a different status from "background truth".
|
|
18
|
+
* - **It refuses to run on thin material.** Below {@link REFLECTION_MIN_ENTRIES}
|
|
19
|
+
* recent memories there is nothing to synthesize, and a weekly pass would
|
|
20
|
+
* produce the same generic sentences forever.
|
|
21
|
+
*
|
|
22
|
+
* @module dsh-cross-memory/reflection
|
|
23
|
+
*/
|
|
24
|
+
import { mkdir, readFile, readdir, rename, writeFile } from 'node:fs/promises';
|
|
25
|
+
import { join } from 'node:path';
|
|
26
|
+
import { BlockAssembler, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
27
|
+
import { resolveLlmRoute } from './extract.js';
|
|
28
|
+
import { MEMORY_SOURCE_KIND } from './types.js';
|
|
29
|
+
/** Directory inside the memory store. */
|
|
30
|
+
export const REFLECTION_DIR = 'reflections';
|
|
31
|
+
/** How often the pass may run. */
|
|
32
|
+
export const REFLECTION_INTERVAL_MS = 7 * 86_400_000;
|
|
33
|
+
/** Recent entries required before a reflection is worth attempting. */
|
|
34
|
+
export const REFLECTION_MIN_ENTRIES = 20;
|
|
35
|
+
/** How many entries one pass reads. */
|
|
36
|
+
export const REFLECTION_MAX_ENTRIES = 80;
|
|
37
|
+
/** The instruction. Its job is to refuse restatement. */
|
|
38
|
+
export const REFLECTION_SYSTEM = [
|
|
39
|
+
'You review a person\'s long-term memory store and write a few observations about them that NO SINGLE memory states.',
|
|
40
|
+
'',
|
|
41
|
+
'A reflection is not a summary. Restating what the memories already say is worthless — the reader can read them. What is valuable is the pattern:',
|
|
42
|
+
'- a preference that shows up across unrelated projects;',
|
|
43
|
+
'- a habit in how they work (what they check first, what they postpone, what they always fix by hand);',
|
|
44
|
+
'- a tension between two things they care about;',
|
|
45
|
+
'- something they repeatedly get burned by.',
|
|
46
|
+
'',
|
|
47
|
+
'Rules:',
|
|
48
|
+
'- 2-5 observations. Fewer, sharper ones beat more, vaguer ones.',
|
|
49
|
+
'- Every observation MUST list the ids of the memories it is based on, in "evidence". If you cannot name them, do not write the observation.',
|
|
50
|
+
'- Never repeat a previous observation verbatim; if it still holds, leave it out unless you are sharpening it.',
|
|
51
|
+
'- Write in Simplified Chinese, in the third person, about the user. No advice, no flattery, no instructions.',
|
|
52
|
+
'',
|
|
53
|
+
'Reply with JSON only: {"insights":[{"text":"...","evidence":["id1","id2"]}]}',
|
|
54
|
+
].join('\n');
|
|
55
|
+
/** Output contract. */
|
|
56
|
+
export const REFLECTION_JSON_SCHEMA = {
|
|
57
|
+
type: 'object',
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
required: ['insights'],
|
|
60
|
+
properties: {
|
|
61
|
+
insights: {
|
|
62
|
+
type: 'array',
|
|
63
|
+
items: {
|
|
64
|
+
type: 'object',
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
required: ['text', 'evidence'],
|
|
67
|
+
properties: {
|
|
68
|
+
text: { type: 'string' },
|
|
69
|
+
evidence: { type: 'array', items: { type: 'string' } },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Whether a pass is due.
|
|
77
|
+
*
|
|
78
|
+
* @param lastAt - when the last reflection was written (0 when never).
|
|
79
|
+
* @param now - clock.
|
|
80
|
+
* @param entries - how many recent memories exist.
|
|
81
|
+
* @returns whether to run.
|
|
82
|
+
*/
|
|
83
|
+
export function reflectionDue(lastAt, now, entries) {
|
|
84
|
+
if (entries < REFLECTION_MIN_ENTRIES)
|
|
85
|
+
return false;
|
|
86
|
+
return lastAt <= 0 || now - lastAt >= REFLECTION_INTERVAL_MS;
|
|
87
|
+
}
|
|
88
|
+
/** Render the input document, listing only what the model may cite. */
|
|
89
|
+
export function renderReflectionInput(entries, persona, previous) {
|
|
90
|
+
const blocks = [];
|
|
91
|
+
if (persona !== undefined && persona.trim().length > 0) {
|
|
92
|
+
blocks.push('## Who the user is (already known — do not restate)', persona.trim(), '');
|
|
93
|
+
}
|
|
94
|
+
if (previous !== undefined && previous.length > 0) {
|
|
95
|
+
blocks.push('## Previous observations (do not repeat)', ...previous.map((text) => `- ${text}`), '');
|
|
96
|
+
}
|
|
97
|
+
blocks.push('## Memories');
|
|
98
|
+
for (const entry of entries.slice(0, REFLECTION_MAX_ENTRIES)) {
|
|
99
|
+
blocks.push(`- id: ${entry.id}`);
|
|
100
|
+
blocks.push(` kind: ${entry.kind}${entry.voice === 'user' ? ' (the user\'s own words)' : ''}`);
|
|
101
|
+
blocks.push(` title: ${entry.title}`);
|
|
102
|
+
blocks.push(` body: ${entry.body.replace(/\n+/gu, ' ')}`);
|
|
103
|
+
}
|
|
104
|
+
return blocks.join('\n');
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parse a reflection reply, dropping any insight whose evidence the store cannot show.
|
|
108
|
+
*
|
|
109
|
+
* @param text - the raw reply.
|
|
110
|
+
* @param knownIds - ids present in the material the model was shown.
|
|
111
|
+
* @returns the validated insights, possibly none.
|
|
112
|
+
*/
|
|
113
|
+
export function parseReflection(text, knownIds) {
|
|
114
|
+
const trimmed = text.trim().replace(/^```(?:json)?\s*/iu, '').replace(/```$/u, '').trim();
|
|
115
|
+
const start = trimmed.indexOf('{');
|
|
116
|
+
const end = trimmed.lastIndexOf('}');
|
|
117
|
+
if (start < 0 || end <= start)
|
|
118
|
+
return [];
|
|
119
|
+
let parsed;
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(trimmed.slice(start, end + 1));
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const row = parsed;
|
|
127
|
+
if (!Array.isArray(row.insights))
|
|
128
|
+
return [];
|
|
129
|
+
const insights = [];
|
|
130
|
+
const seen = new Set();
|
|
131
|
+
for (const item of row.insights) {
|
|
132
|
+
if (insights.length >= 5)
|
|
133
|
+
break;
|
|
134
|
+
if (typeof item !== 'object' || item === null)
|
|
135
|
+
continue;
|
|
136
|
+
const entry = item;
|
|
137
|
+
const body = typeof entry.text === 'string' ? entry.text.replace(/\s+/gu, ' ').trim().slice(0, 400) : '';
|
|
138
|
+
const evidence = Array.isArray(entry.evidence)
|
|
139
|
+
? [...new Set(entry.evidence.filter((id) => typeof id === 'string' && knownIds.has(id)))]
|
|
140
|
+
: [];
|
|
141
|
+
if (body.length < 10 || evidence.length === 0)
|
|
142
|
+
continue;
|
|
143
|
+
const key = body.slice(0, 40);
|
|
144
|
+
if (seen.has(key))
|
|
145
|
+
continue;
|
|
146
|
+
seen.add(key);
|
|
147
|
+
insights.push({ text: body, evidence });
|
|
148
|
+
}
|
|
149
|
+
return insights;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Count what a reply contained, before validation dropped it.
|
|
153
|
+
*
|
|
154
|
+
* @param text - the raw reply.
|
|
155
|
+
* @param knownIds - ids the model was shown.
|
|
156
|
+
* @returns raw and evidence-bearing counts, or `undefined` when the reply is not JSON.
|
|
157
|
+
*/
|
|
158
|
+
export function replyStats(text, knownIds) {
|
|
159
|
+
const trimmed = text.trim().replace(/^```(?:json)?\s*/iu, '').replace(/```$/u, '').trim();
|
|
160
|
+
const start = trimmed.indexOf('{');
|
|
161
|
+
const end = trimmed.lastIndexOf('}');
|
|
162
|
+
if (start < 0 || end <= start)
|
|
163
|
+
return undefined;
|
|
164
|
+
let parsed;
|
|
165
|
+
try {
|
|
166
|
+
parsed = JSON.parse(trimmed.slice(start, end + 1));
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const row = parsed;
|
|
172
|
+
if (!Array.isArray(row.insights))
|
|
173
|
+
return { raw: 0, cited: 0 };
|
|
174
|
+
const cited = row.insights.filter((item) => {
|
|
175
|
+
if (typeof item !== 'object' || item === null)
|
|
176
|
+
return false;
|
|
177
|
+
const evidence = item.evidence;
|
|
178
|
+
return Array.isArray(evidence) && evidence.some((id) => typeof id === 'string' && knownIds.has(id));
|
|
179
|
+
}).length;
|
|
180
|
+
return { raw: row.insights.length, cited };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Run one reflection call.
|
|
184
|
+
*
|
|
185
|
+
* @param request - material, route, budget.
|
|
186
|
+
* @returns the validated insights, or why there are none.
|
|
187
|
+
*/
|
|
188
|
+
export async function runReflection(request) {
|
|
189
|
+
if (request.entries.length < REFLECTION_MIN_ENTRIES)
|
|
190
|
+
return { insights: [], reason: `only ${request.entries.length} recent memories`, skipped: 'empty' };
|
|
191
|
+
if (request.llm === undefined)
|
|
192
|
+
return { insights: [], reason: 'no llm runtime', skipped: 'no-llm' };
|
|
193
|
+
if (request.session === undefined)
|
|
194
|
+
return { insights: [], reason: 'no session to route through', skipped: 'no-route' };
|
|
195
|
+
const route = resolveLlmRoute(request.session, request.provider, request.model, {});
|
|
196
|
+
if (route === undefined)
|
|
197
|
+
return { insights: [], reason: 'no route configured', skipped: 'no-route' };
|
|
198
|
+
const input = renderReflectionInput(request.entries, request.persona, request.previous);
|
|
199
|
+
const options = {
|
|
200
|
+
provider: route.provider,
|
|
201
|
+
model: route.model,
|
|
202
|
+
messages: [createUserMessage({ content: [{ type: 'text', text: input }], source: { kind: MEMORY_SOURCE_KIND } })],
|
|
203
|
+
system: REFLECTION_SYSTEM,
|
|
204
|
+
maxTokens: 1_200,
|
|
205
|
+
purpose: 'compaction',
|
|
206
|
+
sessionId: request.session.id,
|
|
207
|
+
signal: AbortSignal.any([request.signal, AbortSignal.timeout(request.timeoutMs)]),
|
|
208
|
+
};
|
|
209
|
+
let text = '';
|
|
210
|
+
try {
|
|
211
|
+
const assembler = new BlockAssembler();
|
|
212
|
+
for await (const chunk of request.llm.stream(options))
|
|
213
|
+
assembler.push(chunk);
|
|
214
|
+
text = assembler.blocks()
|
|
215
|
+
.filter((block) => block.type === 'text')
|
|
216
|
+
.map((block) => block.text)
|
|
217
|
+
.join('\n');
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return { insights: [], reason: `reflection call failed: ${error instanceof Error ? error.message : String(error)}`, skipped: 'failed' };
|
|
221
|
+
}
|
|
222
|
+
const known = new Set(request.entries.map((entry) => entry.id));
|
|
223
|
+
const insights = parseReflection(text, known);
|
|
224
|
+
// A zero result has two very different causes — the model wrote no observations,
|
|
225
|
+
// or it wrote them without citing what they rest on — and for five days the log
|
|
226
|
+
// said only "produced nothing", which is why it stayed unfixed. Count both.
|
|
227
|
+
const stats = replyStats(text, known);
|
|
228
|
+
const detail = stats === undefined
|
|
229
|
+
? ''
|
|
230
|
+
: ` (reply: ${stats.raw} observation(s), ${stats.cited} citing a known id)`;
|
|
231
|
+
return {
|
|
232
|
+
insights,
|
|
233
|
+
reason: insights.length === 0 ? `the reply had no observation that could cite its evidence${detail}` : `${insights.length} observation(s)`,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** Render one reflection as the markdown written to disk. */
|
|
237
|
+
export function renderReflectionFile(insights, now) {
|
|
238
|
+
const stamp = new Date(now).toISOString().slice(0, 10);
|
|
239
|
+
const lines = [
|
|
240
|
+
'---',
|
|
241
|
+
`created: ${new Date(now).toISOString()}`,
|
|
242
|
+
`insights: ${insights.length}`,
|
|
243
|
+
'---',
|
|
244
|
+
'',
|
|
245
|
+
`# 反思 ${stamp}`,
|
|
246
|
+
'',
|
|
247
|
+
...insights.flatMap((insight) => [
|
|
248
|
+
`- ${insight.text}`,
|
|
249
|
+
` 依据:${insight.evidence.join(', ')}`,
|
|
250
|
+
]),
|
|
251
|
+
'',
|
|
252
|
+
];
|
|
253
|
+
return lines.join('\n');
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Write one reflection file, one per day at most.
|
|
257
|
+
*
|
|
258
|
+
* @param memoriesDir - the store root.
|
|
259
|
+
* @param insights - validated observations.
|
|
260
|
+
* @param now - clock.
|
|
261
|
+
* @returns the absolute path written.
|
|
262
|
+
*/
|
|
263
|
+
export async function writeReflection(memoriesDir, insights, now) {
|
|
264
|
+
const dir = join(memoriesDir, REFLECTION_DIR);
|
|
265
|
+
await mkdir(dir, { recursive: true });
|
|
266
|
+
const stamp = new Date(now).toISOString().slice(0, 10);
|
|
267
|
+
const target = join(dir, `${stamp}.md`);
|
|
268
|
+
const temp = `${target}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
269
|
+
await writeFile(temp, renderReflectionFile(insights, now), 'utf8');
|
|
270
|
+
await rename(temp, target);
|
|
271
|
+
return target;
|
|
272
|
+
}
|
|
273
|
+
/** List the reflection files, newest first. */
|
|
274
|
+
export async function listReflections(memoriesDir) {
|
|
275
|
+
const dir = join(memoriesDir, REFLECTION_DIR);
|
|
276
|
+
const names = await readdir(dir).catch(() => []);
|
|
277
|
+
const files = names.filter((name) => name.endsWith('.md')).sort().reverse();
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const name of files) {
|
|
280
|
+
const body = await readFile(join(dir, name), 'utf8').catch(() => '');
|
|
281
|
+
if (body.length > 0)
|
|
282
|
+
out.push({ name, body });
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
285
|
+
}
|
|
286
|
+
/** The one-line observations already written, for the "do not repeat" list. */
|
|
287
|
+
export function previousInsights(files) {
|
|
288
|
+
return files
|
|
289
|
+
.flatMap((file) => file.body.split('\n').filter((line) => line.startsWith('- ')).map((line) => line.slice(2).trim()))
|
|
290
|
+
.slice(0, 40);
|
|
291
|
+
}
|