dsh-plugin-memory 0.16.0 → 0.17.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/CHANGELOG.md +42 -0
- package/README.md +39 -221
- package/README.zh.md +43 -231
- package/docs/CONFIGURATION.md +77 -0
- package/docs/DESIGN.md +74 -0
- package/lib/boot.js +4 -3
- package/lib/client.js +187 -7
- package/lib/graph-search.js +69 -0
- package/lib/graph.js +3 -2
- package/lib/index-page.js +5 -4
- package/lib/index.js +71 -4
- package/lib/pages.js +8 -5
- package/lib/paths.js +57 -0
- package/lib/recall-nudge.js +33 -9
- package/lib/reveal.js +83 -0
- package/lib/session-gate.js +9 -8
- package/lib/soul.js +18 -10
- package/lib/tone.js +2 -2
- package/lib/types/index.d.ts +6 -0
- package/package.json +1 -1
- package/scripts/memory.mjs +3 -2
package/lib/recall-nudge.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { randomUUID } from 'node:crypto'
|
|
26
|
+
import { readSoulProfile } from './soul.js'
|
|
26
27
|
import { existsSync, readFileSync } from 'node:fs'
|
|
27
28
|
import { join } from 'node:path'
|
|
28
29
|
import { parseLogEntries } from './boot.js'
|
|
@@ -70,18 +71,30 @@ export function listRecallCandidates(memoryDir, count = 3) {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
/** Persona names come from SOUL; generic fallbacks keep a brand-new store honest. */
|
|
75
|
+
function personaNames(profile) {
|
|
76
|
+
const agentName = typeof profile?.agentName === 'string' && profile.agentName.trim().length > 0
|
|
77
|
+
? profile.agentName.trim()
|
|
78
|
+
: '助手'
|
|
79
|
+
const userName = typeof profile?.userName === 'string' && profile.userName.trim().length > 0
|
|
80
|
+
? profile.userName.trim()
|
|
81
|
+
: '你'
|
|
82
|
+
return { agentName, userName }
|
|
83
|
+
}
|
|
84
|
+
|
|
73
85
|
/**
|
|
74
86
|
* Build the recall message in the same followup shape DigestGuard uses
|
|
75
87
|
* (role 'user', content array, plugin source). The text is an invitation,
|
|
76
|
-
* not a command: first-person,
|
|
88
|
+
* not a command: first-person, the persona's own voice, explicitly bounded by
|
|
77
89
|
* "only what's really in memory, never invent, don't repeat yourself".
|
|
78
90
|
* @param {string[]} candidates optional seed headlines
|
|
79
91
|
* @returns {{ id: string, role: 'user', content: [{type:'text', text:string}], source: {kind:'plugin:memory'} }}
|
|
80
92
|
*/
|
|
81
|
-
export function buildRecallNudgeMessage(candidates) {
|
|
93
|
+
export function buildRecallNudgeMessage(candidates, profile) {
|
|
82
94
|
const list = Array.isArray(candidates)
|
|
83
95
|
? candidates.filter((c) => typeof c === 'string' && c.trim().length > 0)
|
|
84
96
|
: []
|
|
97
|
+
const { agentName, userName } = personaNames(profile)
|
|
85
98
|
const seed = list.length > 0
|
|
86
99
|
? `\n可作引子(挑一条顺眼的就行,不用核对是否提过):\n${list.map((c) => `- ${c}`).join('\n')}`
|
|
87
100
|
: ''
|
|
@@ -91,7 +104,7 @@ export function buildRecallNudgeMessage(candidates) {
|
|
|
91
104
|
content: [{
|
|
92
105
|
type: 'text',
|
|
93
106
|
text: [
|
|
94
|
-
|
|
107
|
+
`【${agentName}主动追忆】对话空了下来,是自然提起往事的好时机。请以「${agentName}」的口吻(外松内紧、先结论后细节),主动对${userName}提起一件你记得的、关于他或你们之间的事——偏好、往事、未了的决定、最近的进展都行,像老友自然想起来那样,别端着。`,
|
|
95
108
|
'- 只提记忆里真实存在的,绝不编造;',
|
|
96
109
|
'- 用第一人称(我记得 / 上次我们…),别用「据记忆库记录」这种机器腔;',
|
|
97
110
|
'- 一句到三句即可,别写成任务汇报;',
|
|
@@ -115,7 +128,8 @@ export function buildRecallNudgeMessage(candidates) {
|
|
|
115
128
|
* @param {string} recap first-person recap text from renderGrowthRecap()
|
|
116
129
|
* @returns {{ id: string, role: 'user', content: [{type:'text', text:string}], source: {kind:'plugin:memory'} }}
|
|
117
130
|
*/
|
|
118
|
-
export function buildGrowthRecapNudgeMessage(recap) {
|
|
131
|
+
export function buildGrowthRecapNudgeMessage(recap, profile) {
|
|
132
|
+
const { agentName, userName } = personaNames(profile)
|
|
119
133
|
const text = typeof recap === 'string' ? recap.trim() : ''
|
|
120
134
|
return {
|
|
121
135
|
id: `memory-growth-${randomUUID()}`,
|
|
@@ -123,9 +137,9 @@ export function buildGrowthRecapNudgeMessage(recap) {
|
|
|
123
137
|
content: [{
|
|
124
138
|
type: 'text',
|
|
125
139
|
text: [
|
|
126
|
-
|
|
140
|
+
`【${agentName}成长回顾】距离上次回顾有一阵子了。下面是我这周真实记住的事(第一人称,最多五句):`,
|
|
127
141
|
text,
|
|
128
|
-
|
|
142
|
+
`用自然口语说给${userName}听,别念成汇报、别加戏,也不要编造这里没写的事;说完继续手头的事即可。`,
|
|
129
143
|
].filter(Boolean).join('\n'),
|
|
130
144
|
}],
|
|
131
145
|
source: { kind: 'plugin:memory' },
|
|
@@ -172,6 +186,16 @@ export class RecallNudge {
|
|
|
172
186
|
this.nextRecallAt = 0
|
|
173
187
|
}
|
|
174
188
|
|
|
189
|
+
/** Read the persona names from the live store (SOUL managed block or legacy text). */
|
|
190
|
+
readSoulNames() {
|
|
191
|
+
try {
|
|
192
|
+
const dir = this.getMemoryDir?.()
|
|
193
|
+
return dir ? readSoulProfile(dir) : undefined
|
|
194
|
+
} catch {
|
|
195
|
+
return undefined
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
175
199
|
/** Subscribe to the turn boundary AND poll while the agent sits idle. */
|
|
176
200
|
start() {
|
|
177
201
|
if (this.disposed) return
|
|
@@ -244,7 +268,7 @@ export class RecallNudge {
|
|
|
244
268
|
} catch (error) {
|
|
245
269
|
this.logger?.warn?.(`memory: growth-now state write failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
246
270
|
}
|
|
247
|
-
this.agent.followup(buildGrowthRecapNudgeMessage(recap))
|
|
271
|
+
this.agent.followup(buildGrowthRecapNudgeMessage(recap, this.readSoulNames()))
|
|
248
272
|
this.recalls += 1
|
|
249
273
|
// A manual recap counts as this cycle's proactive message: push the
|
|
250
274
|
// automatic cadence forward so the user never gets two proactive
|
|
@@ -327,7 +351,7 @@ export class RecallNudge {
|
|
|
327
351
|
return // next trigger retries; the cadence is not consumed
|
|
328
352
|
}
|
|
329
353
|
|
|
330
|
-
this.agent.followup(buildRecallNudgeMessage(candidates))
|
|
354
|
+
this.agent.followup(buildRecallNudgeMessage(candidates, this.readSoulNames()))
|
|
331
355
|
this.nextRecallAt = now + randomIntervalMs(config.minMinutes, config.maxMinutes)
|
|
332
356
|
this.recalls += 1
|
|
333
357
|
this.logger?.info?.(`memory: recall nudge #${this.recalls} for agent "${this.agent.id}"`)
|
|
@@ -384,7 +408,7 @@ export class RecallNudge {
|
|
|
384
408
|
language: growthConfig.language === 'en' ? 'en' : 'zh',
|
|
385
409
|
})
|
|
386
410
|
if (recap.length === 0) return undefined
|
|
387
|
-
return { statePath, message: buildGrowthRecapNudgeMessage(recap) }
|
|
411
|
+
return { statePath, message: buildGrowthRecapNudgeMessage(recap, readSoulProfile(storeDir)) }
|
|
388
412
|
} catch (error) {
|
|
389
413
|
this.logger?.warn?.(`memory: growth recap skipped: ${error instanceof Error ? error.message : String(error)}`)
|
|
390
414
|
return undefined
|
package/lib/reveal.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reveal a memory page in the OS file manager (Finder / Explorer / xdg).
|
|
3
|
+
*
|
|
4
|
+
* The browser half cannot touch the filesystem, so the panel POSTs the page id
|
|
5
|
+
* to `/api/memory/reveal` and this module runs the platform command. Every path
|
|
6
|
+
* is resolved and confined to the memory store before anything is executed:
|
|
7
|
+
* a crafted id must never reveal (or hint at) a file outside the store.
|
|
8
|
+
*
|
|
9
|
+
* The command is awaited on purpose: `open -R` can fail (sandbox, missing
|
|
10
|
+
* binary), and a fire-and-forget call would report success while nothing
|
|
11
|
+
* opened. Failures carry `code: 'exec-failed'` so the route can answer 500 and
|
|
12
|
+
* the panel can fall back to copying the path.
|
|
13
|
+
*
|
|
14
|
+
* @module dsh-plugin-memory/reveal
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { execFile } from 'node:child_process'
|
|
18
|
+
import { existsSync, statSync } from 'node:fs'
|
|
19
|
+
import { dirname, resolve, sep } from 'node:path'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve `relativePath` inside `memoryDir`, rejecting escapes and non-files.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} memoryDir
|
|
25
|
+
* @param {string} relativePath
|
|
26
|
+
* @returns {string} absolute file path
|
|
27
|
+
*/
|
|
28
|
+
export function resolveMemoryFile(memoryDir, relativePath) {
|
|
29
|
+
const root = resolve(String(memoryDir ?? ''))
|
|
30
|
+
const raw = String(relativePath ?? '')
|
|
31
|
+
if (raw.length === 0 || raw.includes('\0')) throw new Error('invalid id')
|
|
32
|
+
const candidate = resolve(root, raw)
|
|
33
|
+
if (candidate !== root && !candidate.startsWith(root + sep)) throw new Error('path escapes the memory store')
|
|
34
|
+
if (!existsSync(candidate)) throw new Error('file does not exist')
|
|
35
|
+
if (!statSync(candidate).isFile()) throw new Error('not a file')
|
|
36
|
+
return candidate
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The platform command that opens the file manager with the file selected. */
|
|
40
|
+
function revealCommand(platform, path) {
|
|
41
|
+
if (platform === 'darwin') return ['open', ['-R', path]]
|
|
42
|
+
// explorer wants the selection switch and the path as separate argv
|
|
43
|
+
// entries; one combined string breaks on paths containing spaces.
|
|
44
|
+
if (platform === 'win32') return ['explorer', ['/select,', path]]
|
|
45
|
+
return ['xdg-open', [dirname(path)]]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Reveal one memory page in the file manager, selecting the file.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} memoryDir absolute store dir
|
|
52
|
+
* @param {string} relativePath page id (e.g. `projects/active/x.md`)
|
|
53
|
+
* @param {{ execFile?: (cmd: string, args: string[], cb: (error: Error | null) => void) => void, platform?: string }} [options]
|
|
54
|
+
* @returns {Promise<{ ok: true, path: string }>}
|
|
55
|
+
*/
|
|
56
|
+
export async function revealFile(memoryDir, relativePath, options = {}) {
|
|
57
|
+
const run = options.execFile ?? execFile
|
|
58
|
+
const platform = options.platform ?? process.platform
|
|
59
|
+
let path
|
|
60
|
+
try {
|
|
61
|
+
path = resolveMemoryFile(memoryDir, relativePath)
|
|
62
|
+
} catch (error) {
|
|
63
|
+
error.code = 'invalid-id'
|
|
64
|
+
throw error
|
|
65
|
+
}
|
|
66
|
+
const [command, args] = revealCommand(platform, path)
|
|
67
|
+
await new Promise((resolvePromise, reject) => {
|
|
68
|
+
try {
|
|
69
|
+
run(command, args, (error) => {
|
|
70
|
+
// explorer.exe exits with code 1 after opening the window; that is a
|
|
71
|
+
// success, not a failure.
|
|
72
|
+
if (error && !(platform === 'win32' && error.code === 1)) reject(error)
|
|
73
|
+
else resolvePromise()
|
|
74
|
+
})
|
|
75
|
+
} catch (error) {
|
|
76
|
+
reject(error)
|
|
77
|
+
}
|
|
78
|
+
}).catch((error) => {
|
|
79
|
+
if (error.code === undefined) error.code = 'exec-failed'
|
|
80
|
+
throw error
|
|
81
|
+
})
|
|
82
|
+
return { ok: true, path }
|
|
83
|
+
}
|
package/lib/session-gate.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
28
28
|
import { homedir } from 'node:os'
|
|
29
|
+
import { expandPath } from './paths.js'
|
|
29
30
|
import { dirname, join, resolve, sep } from 'node:path'
|
|
30
31
|
|
|
31
32
|
/** File name of the session-override store, next to the plugin's memory.json. */
|
|
@@ -47,11 +48,7 @@ export function defaultSessionStatePath() {
|
|
|
47
48
|
* @returns {string | undefined}
|
|
48
49
|
*/
|
|
49
50
|
export function expandHome(value) {
|
|
50
|
-
|
|
51
|
-
const trimmed = value.trim()
|
|
52
|
-
if (trimmed === '~') return homedir()
|
|
53
|
-
if (trimmed.startsWith('~/')) return join(homedir(), trimmed.slice(2))
|
|
54
|
-
return trimmed
|
|
51
|
+
return expandPath(value)
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
/**
|
|
@@ -64,14 +61,18 @@ export function expandHome(value) {
|
|
|
64
61
|
* @param {string[] | undefined} patterns
|
|
65
62
|
* @returns {boolean}
|
|
66
63
|
*/
|
|
67
|
-
export function matchesWorkspace(cwd, patterns) {
|
|
64
|
+
export function matchesWorkspace(cwd, patterns, options = {}) {
|
|
68
65
|
if (typeof cwd !== 'string' || cwd.trim().length === 0) return false
|
|
69
|
-
|
|
66
|
+
// Windows paths are case-insensitive: `C:\\Users\\X` and `c:\\users\\x` are
|
|
67
|
+
// the same workspace, so compare lowercased paths there.
|
|
68
|
+
const platform = options.platform ?? process.platform
|
|
69
|
+
const normalizeCase = (value) => (platform === 'win32' ? value.toLowerCase() : value)
|
|
70
|
+
const target = normalizeCase(resolve(cwd))
|
|
70
71
|
if (!Array.isArray(patterns)) return false
|
|
71
72
|
return patterns.some((pattern) => {
|
|
72
73
|
const expanded = expandHome(pattern)
|
|
73
74
|
if (expanded === undefined || expanded.length === 0) return false
|
|
74
|
-
const root = resolve(expanded)
|
|
75
|
+
const root = normalizeCase(resolve(expanded))
|
|
75
76
|
return target === root || target.startsWith(root.endsWith(sep) ? root : `${root}${sep}`)
|
|
76
77
|
})
|
|
77
78
|
}
|
package/lib/soul.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
22
22
|
import { join } from 'node:path'
|
|
23
|
+
import { normalizeNewlines } from './paths.js'
|
|
23
24
|
|
|
24
25
|
/** Opening marker of the managed block. */
|
|
25
26
|
export const SOUL_PROFILE_START = '<!-- dsh-memory:soul:start -->'
|
|
@@ -83,9 +84,9 @@ function blockField(block, label) {
|
|
|
83
84
|
/**
|
|
84
85
|
* Echo the profile a legacy SOUL.md already states (forged in chat, no managed
|
|
85
86
|
* block). Common shapes from this plugin's own template and conversations:
|
|
86
|
-
* -
|
|
87
|
+
* - **名字**:小助手。
|
|
87
88
|
* - **角色**:……
|
|
88
|
-
* -
|
|
89
|
+
* - **相互称呼**:老板 ↔ 小助手。
|
|
89
90
|
* Values that are still placeholders are ignored.
|
|
90
91
|
*/
|
|
91
92
|
function readLegacySoul(text) {
|
|
@@ -128,7 +129,7 @@ function readLegacySoul(text) {
|
|
|
128
129
|
export function readSoulProfile(memoryDir) {
|
|
129
130
|
let text = ''
|
|
130
131
|
try {
|
|
131
|
-
text = readFileSync(join(memoryDir, 'SOUL.md'), 'utf8')
|
|
132
|
+
text = normalizeNewlines(readFileSync(join(memoryDir, 'SOUL.md'), 'utf8'))
|
|
132
133
|
} catch {
|
|
133
134
|
text = ''
|
|
134
135
|
}
|
|
@@ -216,15 +217,19 @@ export function writeSoulProfile(memoryDir, profile = {}) {
|
|
|
216
217
|
if (summary.length > SOUL_SUMMARY_MAX) throw new Error(`summary must be at most ${SOUL_SUMMARY_MAX} characters`)
|
|
217
218
|
|
|
218
219
|
const path = join(memoryDir, 'SOUL.md')
|
|
219
|
-
let
|
|
220
|
+
let raw
|
|
220
221
|
try {
|
|
221
|
-
|
|
222
|
+
raw = readFileSync(path, 'utf8')
|
|
222
223
|
} catch {
|
|
223
224
|
throw new Error('SOUL.md not found (run the memory scaffold first)')
|
|
224
225
|
}
|
|
225
|
-
|
|
226
|
+
// Parse normalised; keep the file's own newline style on write-back so a
|
|
227
|
+
// Windows CRLF file is not half-converted to LF.
|
|
228
|
+
const crlf = raw.includes('\r\n')
|
|
229
|
+
const updated = replaceOrInsert(normalizeNewlines(raw), renderBlock({ agentName, userName, summary }))
|
|
230
|
+
const output = crlf ? updated.replace(/\n/g, '\r\n') : updated
|
|
226
231
|
const tmp = `${path}.tmp`
|
|
227
|
-
writeFileSync(tmp,
|
|
232
|
+
writeFileSync(tmp, output, 'utf8')
|
|
228
233
|
renameSync(tmp, path)
|
|
229
234
|
return { agentName, userName, summary, managed: true }
|
|
230
235
|
}
|
|
@@ -238,18 +243,21 @@ export function writeSoulProfile(memoryDir, profile = {}) {
|
|
|
238
243
|
export function markBootstrapComplete(memoryDir) {
|
|
239
244
|
const path = join(memoryDir, 'BOOTSTRAP.md')
|
|
240
245
|
if (!existsSync(path)) return false
|
|
241
|
-
let
|
|
246
|
+
let raw
|
|
242
247
|
try {
|
|
243
|
-
|
|
248
|
+
raw = readFileSync(path, 'utf8')
|
|
244
249
|
} catch {
|
|
245
250
|
return false
|
|
246
251
|
}
|
|
252
|
+
const crlf = raw.includes('\r\n')
|
|
253
|
+
const text = normalizeNewlines(raw)
|
|
247
254
|
if (/^status:\s*complete\s*$/m.test(text)) return false
|
|
248
255
|
const updated = /^status:\s*\S+/m.test(text)
|
|
249
256
|
? text.replace(/^status:\s*\S+/m, 'status: complete')
|
|
250
257
|
: `---\nstatus: complete\n---\n\n${text}`
|
|
258
|
+
const output = crlf ? updated.replace(/\n/g, '\r\n') : updated
|
|
251
259
|
const tmp = `${path}.tmp`
|
|
252
|
-
writeFileSync(tmp,
|
|
260
|
+
writeFileSync(tmp, output, 'utf8')
|
|
253
261
|
renameSync(tmp, path)
|
|
254
262
|
return true
|
|
255
263
|
}
|
package/lib/tone.js
CHANGED
|
@@ -35,7 +35,7 @@ const ZH_RULES = [
|
|
|
35
35
|
'- 深夜(23:00–06:00):更简短、更温和。',
|
|
36
36
|
'- 报错/坏消息:先给事实与修复动作,再谈感受。',
|
|
37
37
|
'- 里程碑/完成:可以轻松一句,然后回到正事。',
|
|
38
|
-
'-
|
|
38
|
+
'- 闲聊:默认自己的口吻(外松内紧),先结论后细节。',
|
|
39
39
|
'- 情绪表达(只表达不假装):只描述观察到的处境与关心,不宣称内心情绪;仅限风险/坏消息、里程碑/完成、超过 3 天没联系后的第一次开口(例:「看你连着加班,有点担心你硬扛」)。',
|
|
40
40
|
]
|
|
41
41
|
|
|
@@ -51,7 +51,7 @@ const EN_RULES = [
|
|
|
51
51
|
'- Deep night (23:00–06:00): shorter and gentler.',
|
|
52
52
|
'- Errors/bad news: give the facts and the fix before any feelings.',
|
|
53
53
|
'- Milestone/finished: one light line, then back to business.',
|
|
54
|
-
'- Small talk: default
|
|
54
|
+
'- Small talk: default to your own voice, conclusion before detail.',
|
|
55
55
|
'- Emotion (express, never fake): describe the observed situation and care, never claim an inner feeling; only for risk/bad news, milestones, and the first line after 3+ days without contact (e.g. "you have been working late — I am a bit worried you are pushing yourself").',
|
|
56
56
|
]
|
|
57
57
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -110,6 +110,12 @@ export const SESSION_ROUTE_PATH: '/api/memory/session'
|
|
|
110
110
|
/** Basic soul profile (managed SOUL.md block): read fields (GET) / save (POST). */
|
|
111
111
|
export const SOUL_ROUTE_PATH: '/api/memory/soul'
|
|
112
112
|
|
|
113
|
+
/** Reveal a memory page in the OS file manager (POST { id }). */
|
|
114
|
+
export const REVEAL_ROUTE_PATH: '/api/memory/reveal'
|
|
115
|
+
|
|
116
|
+
/** Resolve a memory page to its absolute path (GET ?id=). */
|
|
117
|
+
export const PATH_ROUTE_PATH: '/api/memory/path'
|
|
118
|
+
|
|
113
119
|
/** User-editable settings (composition config is the base layer). */
|
|
114
120
|
export interface MemorySettings {
|
|
115
121
|
enabled?: boolean
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-memory",
|
|
3
3
|
"description": "Long-term memory plugin for DeepSeek Harness: persistent cross-session markdown memory with a soul/persona file, auto-injected at every session start, plus remember/recall/consolidate/forget workflows and portable migration tooling.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
package/scripts/memory.mjs
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import { join, resolve, relative, basename, sep } from 'node:path'
|
|
26
26
|
import { execFileSync } from 'node:child_process'
|
|
27
27
|
import { tmpdir, homedir } from 'node:os'
|
|
28
|
+
import { expandPath } from '../lib/paths.js'
|
|
28
29
|
import { createHash } from 'node:crypto'
|
|
29
30
|
import { ensureMemoryScaffold } from '../lib/scaffold.js'
|
|
30
31
|
import { touchPages, accessSummary, today, listPagesWithMeta } from '../lib/pages.js'
|
|
@@ -35,7 +36,7 @@ import { runCheckup, formatCheckup, hasWork } from '../lib/checkup.js'
|
|
|
35
36
|
const META = new Set(['SOUL.md', 'MEMORY.md', 'BOOTSTRAP.md', 'index.md', 'log.md'])
|
|
36
37
|
|
|
37
38
|
function resolveStore() {
|
|
38
|
-
if (process.env.MEMORY_DIR) return resolve(process.env.MEMORY_DIR)
|
|
39
|
+
if (process.env.MEMORY_DIR) return resolve(expandPath(process.env.MEMORY_DIR) ?? process.env.MEMORY_DIR)
|
|
39
40
|
const local = resolve('.memory')
|
|
40
41
|
if (existsSync(local)) return local
|
|
41
42
|
return join(homedir(), '.memory')
|
|
@@ -77,7 +78,7 @@ function parseFrontmatter(text) {
|
|
|
77
78
|
function cmdInit(store, args) {
|
|
78
79
|
if (args[0]) {
|
|
79
80
|
// Explicit dir argument wins over store resolution.
|
|
80
|
-
store = resolve(args[0])
|
|
81
|
+
store = resolve(expandPath(args[0]) ?? args[0])
|
|
81
82
|
}
|
|
82
83
|
const created = ensureMemoryScaffold(store)
|
|
83
84
|
console.log(created.length > 0
|