icex-dsh-memory 0.2.3 → 0.2.5
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/client.js +23 -3
- package/index.js +23 -5
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -23,6 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
'settings.scope.project': 'Project',
|
|
24
24
|
'settings.dir.label': 'Working directory',
|
|
25
25
|
'settings.dir.placeholder': '/Users/me/codes/project',
|
|
26
|
+
'settings.dir.hint': 'Absolute path, or start with ~/ . The file is <dir>/.dsh/memory/MEMORY.md.',
|
|
26
27
|
'settings.dir.load': 'Load',
|
|
27
28
|
'settings.loading': 'Loading…',
|
|
28
29
|
'settings.saving': 'Saving…',
|
|
@@ -43,6 +44,7 @@ window.__ModuleLoader__.load({
|
|
|
43
44
|
'settings.scope.global': '全局',
|
|
44
45
|
'settings.scope.project': '项目',
|
|
45
46
|
'settings.dir.label': '工作目录',
|
|
47
|
+
'settings.dir.hint': '绝对路径,可用 ~/ 开头。文件是 <目录>/.dsh/memory/MEMORY.md。',
|
|
46
48
|
'settings.dir.placeholder': '/Users/me/codes/project',
|
|
47
49
|
'settings.dir.load': '读取',
|
|
48
50
|
'settings.loading': '读取中…',
|
|
@@ -98,7 +100,13 @@ window.__ModuleLoader__.load({
|
|
|
98
100
|
function MemoryPanel(props) {
|
|
99
101
|
const t = translator(props.t)
|
|
100
102
|
const [scope, setScope] = useState('global')
|
|
101
|
-
const [dir, setDir] = useState(
|
|
103
|
+
const [dir, setDir] = useState(function () {
|
|
104
|
+
try {
|
|
105
|
+
return window.localStorage.getItem('icex-memory.projectDir') ?? ''
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return ''
|
|
108
|
+
}
|
|
109
|
+
})
|
|
102
110
|
const [text, setText] = useState('')
|
|
103
111
|
const [path, setPath] = useState('')
|
|
104
112
|
const [entries, setEntries] = useState(0)
|
|
@@ -112,9 +120,20 @@ window.__ModuleLoader__.load({
|
|
|
112
120
|
}
|
|
113
121
|
|
|
114
122
|
async function load() {
|
|
123
|
+
if (scope === 'project' && dir.trim() === '') {
|
|
124
|
+
setMessage(null)
|
|
125
|
+
return
|
|
126
|
+
}
|
|
115
127
|
setBusy(true)
|
|
116
128
|
setMessage(null)
|
|
117
129
|
try {
|
|
130
|
+
if (scope === 'project') {
|
|
131
|
+
try {
|
|
132
|
+
window.localStorage.setItem('icex-memory.projectDir', dir.trim())
|
|
133
|
+
} catch (error) {
|
|
134
|
+
// A blocked localStorage only costs the remembered directory.
|
|
135
|
+
}
|
|
136
|
+
}
|
|
118
137
|
const response = await fetch(endpoint(), { credentials: 'same-origin' })
|
|
119
138
|
const body = await response.json()
|
|
120
139
|
if (body.ok !== true) throw new Error(body.error ?? response.status)
|
|
@@ -186,7 +205,7 @@ window.__ModuleLoader__.load({
|
|
|
186
205
|
setDir(event.target.value)
|
|
187
206
|
},
|
|
188
207
|
onKeyDown: function (event) {
|
|
189
|
-
if (event.key === 'Enter') void load()
|
|
208
|
+
if (event.key === 'Enter' && event.currentTarget.value.trim() !== '') void load()
|
|
190
209
|
},
|
|
191
210
|
}),
|
|
192
211
|
h('button', {
|
|
@@ -196,7 +215,8 @@ window.__ModuleLoader__.load({
|
|
|
196
215
|
onClick: function () {
|
|
197
216
|
void load()
|
|
198
217
|
},
|
|
199
|
-
}, t('settings.dir.load'))
|
|
218
|
+
}, t('settings.dir.load')),
|
|
219
|
+
h('div', { className: 'icex-memory-hint' }, t('settings.dir.hint')))
|
|
200
220
|
: null,
|
|
201
221
|
h('textarea', {
|
|
202
222
|
className: 'icex-memory-text',
|
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* `memory` tool; when it does not, the policy falls back to editing the file
|
|
20
20
|
* with the built-in filesystem tools.
|
|
21
21
|
*/
|
|
22
|
+
import { randomUUID } from 'node:crypto'
|
|
22
23
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
23
24
|
import { createHash } from 'node:crypto'
|
|
24
25
|
import { homedir } from 'node:os'
|
|
@@ -357,6 +358,16 @@ function policy(storePaths) {
|
|
|
357
358
|
].join('\n')
|
|
358
359
|
}
|
|
359
360
|
|
|
361
|
+
/** Build a complete user message: the inbox accepts UserMessage, not a partial literal. */
|
|
362
|
+
export function memoryMessage(text) {
|
|
363
|
+
return {
|
|
364
|
+
id: randomUUID(),
|
|
365
|
+
role: 'user',
|
|
366
|
+
content: [{ type: 'text', text }],
|
|
367
|
+
source: { kind: 'user' },
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
360
371
|
/** Resolve the session working directory, falling back to the process cwd. */
|
|
361
372
|
async function workingDirectory(ctx, agent, signal) {
|
|
362
373
|
try {
|
|
@@ -429,12 +440,19 @@ function jsonResponse(body, status = 200) {
|
|
|
429
440
|
}
|
|
430
441
|
|
|
431
442
|
/** Resolve the store file named by the editor's query string. */
|
|
443
|
+
/** Expand a leading ~/ so the settings page can take a home-relative path. */
|
|
444
|
+
function expandHome(dir) {
|
|
445
|
+
if (dir === '~') return homedir()
|
|
446
|
+
if (dir.startsWith('~/')) return join(homedir(), dir.slice(2))
|
|
447
|
+
return dir
|
|
448
|
+
}
|
|
449
|
+
|
|
432
450
|
function editorTarget(params) {
|
|
433
451
|
if (params.get('scope') !== 'project') return { scope: 'global', file: GLOBAL_FILE }
|
|
434
|
-
const dir = params.get('dir') ?? ''
|
|
435
|
-
if (!dir.startsWith('/')) return { scope: 'project', error: 'project scope needs an absolute directory' }
|
|
436
|
-
if (!existsSync(dir)) return { scope: 'project', error: 'directory does not exist' }
|
|
437
|
-
return { scope: 'project', file: projectFile(dir) }
|
|
452
|
+
const dir = expandHome(String(params.get('dir') ?? '').trim())
|
|
453
|
+
if (!dir.startsWith('/')) return { scope: 'project', error: 'project scope needs an absolute directory (a leading ~/ works)' }
|
|
454
|
+
if (!existsSync(dir)) return { scope: 'project', error: 'directory does not exist: ' + dir }
|
|
455
|
+
return { scope: 'project', dir, file: projectFile(dir) }
|
|
438
456
|
}
|
|
439
457
|
|
|
440
458
|
/** GET reads a store, POST replaces it; both are owner-only by the route registry. */
|
|
@@ -503,7 +521,7 @@ export function apply(ctx, config) {
|
|
|
503
521
|
}
|
|
504
522
|
const text = renderDigest(cwd)
|
|
505
523
|
if (text === '') return
|
|
506
|
-
agent.inject(
|
|
524
|
+
agent.inject(memoryMessage(text))
|
|
507
525
|
} catch (error) {
|
|
508
526
|
ctx.logger?.warn?.('icex-dsh-memory: digest injection failed: ' + String(error))
|
|
509
527
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icex-dsh-memory",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Cross-session memory for DeepSeek Harness: a budgeted MEMORY.md digest injected once per session, plus one memory tool with provenance back to the producing session.",
|
|
6
6
|
"exports": {
|