@restregular/dsh-memory 0.5.5 → 0.6.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/README.md +46 -7
- package/lib/client.js +284 -1
- package/lib/inject/apply.js +221 -98
- package/lib/inject/digest.js +65 -0
- package/lib/inject/inject.js +106 -8
- package/lib/inject/policy.js +21 -0
- package/lib/inject/rules.js +31 -0
- package/lib/panel.js +51 -5
- package/lib/provider/apply.js +49 -3
- package/lib/provider/index.js +214 -10
- package/lib/provider/inject-settings.js +133 -0
- package/lib/provider/scope.js +18 -1
- package/lib/provider/store.js +11 -0
- package/lib/tools/index.js +19 -6
- package/package.json +1 -1
package/lib/tools/index.js
CHANGED
|
@@ -35,6 +35,11 @@ import { normalizeScopeInput, resolveScopeRef } from '../provider/scope.js'
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
38
43
|
|
|
39
44
|
|
|
40
45
|
|
|
@@ -77,8 +82,16 @@ function agentOf(exec ) {
|
|
|
77
82
|
return (exec )?.agent
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
/**
|
|
81
|
-
|
|
85
|
+
/**
|
|
86
|
+
* 当前项目 key。优先级:**服务端解析的会话 cwd** → 显式配置 → process.cwd()。
|
|
87
|
+
*
|
|
88
|
+
* 服务端那一步不能省:DSH 服务进程的 process.cwd() 是 profile 目录,只有
|
|
89
|
+
* `session.header.cwd` 才是工作区;而 mock / 旧 provider 没有 `projectKeyFor` 时,
|
|
90
|
+
* 只能退回配置与 process.cwd()(与旧行为一致,不把测试和旧宿主打断)。
|
|
91
|
+
*/
|
|
92
|
+
function projectKey(opts , service , agent ) {
|
|
93
|
+
const resolved = service?.projectKeyFor?.(agent)
|
|
94
|
+
if (typeof resolved === 'string' && resolved.length > 0) return resolved
|
|
82
95
|
return (opts.projectScope ?? `project:${process.cwd()}`)
|
|
83
96
|
}
|
|
84
97
|
|
|
@@ -87,7 +100,7 @@ function readScopes(opts , service , agent
|
|
|
87
100
|
const provided = service.resolveReadScopes?.(agent)
|
|
88
101
|
if (Array.isArray(provided) && provided.length > 0) return [...new Set(provided)]
|
|
89
102
|
// 服务没提供(测试 mock / 旧 provider):退回 defaultScope 口径
|
|
90
|
-
const fallback = opts.defaultScope === 'global' ? 'global' : projectKey(opts)
|
|
103
|
+
const fallback = opts.defaultScope === 'global' ? 'global' : projectKey(opts, service, agent)
|
|
91
104
|
return [...new Set([fallback, 'global'])]
|
|
92
105
|
}
|
|
93
106
|
|
|
@@ -108,7 +121,7 @@ function resolveScope(
|
|
|
108
121
|
if (!normalized.ok) throw new MemoryToolError('SCOPE_INVALID', normalized.message)
|
|
109
122
|
if (normalized.kind === 'global') return { scope: 'global' }
|
|
110
123
|
const agent = agentOf(exec)
|
|
111
|
-
const project = projectKey(opts)
|
|
124
|
+
const project = projectKey(opts, service, agent)
|
|
112
125
|
// 当前会话 key 由 provider 解析(只有它知道 scopes.session 开关与子代理共享父会话的规则);
|
|
113
126
|
// provider 不在(测试 mock / 旧版本)时不给 session —— 写路径会回退 project,读路径回到合并集合。
|
|
114
127
|
const session = service.resolveReadScopes?.(agent)?.find((s) => s.startsWith('session:'))
|
|
@@ -144,11 +157,11 @@ function resolveScope(
|
|
|
144
157
|
export function memorySaveTool(opts ) {
|
|
145
158
|
return {
|
|
146
159
|
name: 'memory_save',
|
|
147
|
-
description: 'Save a durable memory (fact, decision, preference, procedure) for future sessions.',
|
|
160
|
+
description: 'Save a durable memory (fact, decision, preference, procedure, rule) for future sessions.',
|
|
148
161
|
parameters: {
|
|
149
162
|
content: { type: 'string', description: 'Self-contained declarative sentence, readable without context', required: true },
|
|
150
163
|
scope: { type: 'string', description: SCOPE_DESCRIPTION },
|
|
151
|
-
kind: { type: 'string', enum: ['fact', 'decision', 'preference', 'procedure', 'note'] },
|
|
164
|
+
kind: { type: 'string', enum: ['fact', 'decision', 'preference', 'procedure', 'note', 'rule'] },
|
|
152
165
|
tags: { type: 'array', items: { type: 'string' } },
|
|
153
166
|
importance: { type: 'number', description: '0~1, higher = more important' },
|
|
154
167
|
supersedes: { type: 'string', description: 'Record id this corrects/replaces' },
|