@restregular/dsh-memory 0.5.4 → 0.5.6
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 +3 -1
- package/lib/client.js +48 -31
- package/lib/provider/apply.js +10 -3
- package/lib/provider/index.js +31 -8
- package/lib/provider/scope.js +18 -1
- package/lib/tools/index.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -280,7 +280,9 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
|
|
|
280
280
|
|
|
281
281
|
## 版本
|
|
282
282
|
|
|
283
|
-
- **0.5.
|
|
283
|
+
- **0.5.6** —— **`project:` 作用域此前是失效的**。项目键本应跟着工作区走,但代码把 `project:${process.cwd()}` 当"显式配置"抢先传进解析函数,而 `process.cwd()` 在 DSH 里是**服务进程的启动目录 = profile 目录**(`~/.dsh/profiles/<name>`),不是工作区。后果:该 profile 下**所有项目的项目级记忆挤进同一个桶**(`project:C:\Users\…\.dsh\profiles\desktop`),互相被检索到,而真正的 `project:<工作区>` 永远是空的;面板「当前项目」也指向那里。三处同一份逻辑(服务解析、装配层默认、工具层各算一份)全部统一:**会话 `cwd` > 显式配置 `projectScope` > `process.cwd()`**,工具层改为向服务端要解析结果(`projectKeyFor`),不再自己算。显式配置现在会正确脱掉 `project:` 前缀,不再拼出 `project:project:/x`。之前写进错误桶里的数据不会自动搬家(那需要判断哪条属于哪个项目),受影响的话请手动重存。
|
|
284
|
+
- **0.5.5** —— 侧栏图标改成**与那一列同风格**的线稿芯片。0.5.4 虽然修好了"空一格",但画的是"蓝色瓦片 + 深墨蓝芯片"的实心方块,那是**插件管理器卡片/行**(36/30px,`icon.svg`)那套插件美术;而设置侧栏这一列全是 16px 单色细线图标(宿主内置 `Icon*OutlineMedium`:16 网格、`fill:none`、`stroke:currentColor`、线宽 1.3),实心蓝块混在里面格格不入。现在只用宿主渲染的那颗 svg 的**子节点**画线稿芯片(圆角方 + 内方 + 四引脚,1.3 描边、跟随主题),尺寸/对齐/行高仍由宿主保证。三条被验证过走不通的路都写进了代码注释:`::before` 补一个(盒子不成形 → 空一格)、给 svg 上背景(画不出描边线稿)、`content: url(...)` 替换 svg 内容(SVG 不支持 content 替换)。
|
|
285
|
+
- **0.5.4** —— 修 0.5.3 的图标空洞。0.5.3 是"把齿轮 `display:none` 藏掉、再用 `::before` 在同一格补一个记号",真机上出现**齿轮没了、记号也没画出来**,只剩一个空位。改成**就地覆盖**那颗 svg(不再隐藏、不再插节点)。同时删掉 0.1.0 遗留的空壳目录 `packages/dsh-memory-panel`(0.4.0 起已被单包取代),免得它继续干扰"哪个子包才是可安装的"这类判断。
|
|
284
286
|
- **0.5.3** —— 设置页侧栏「记忆」那一行的图标。宿主 `dsh-client-ui-settings-general` 把导航图标写死在 `navIcon(id)` 里:只有 `account` / `models` / `agent-presets` / `plugins` / `archived-sessions` 五个 id 有专属图标,其余(含 `memory`)一律回退成**齿轮**;`settings.section` 的注册契约里没有 icon 字段,宿主也不读包的 `icon`(那个只用于插件管理器)。所以插件侧按宿主的类名约定做了一次**定向覆盖**。标记只打在"文案等于「记忆」"的那个按钮上,其它区块不受影响;宿主类名约定一旦改变,规则匹配不到就自动退回齿轮。
|
|
285
287
|
- **0.5.2** —— 新图标:插件图标换成"芯片"记号(内存条的直白隐喻)。仍是宿主内置插件美术那套规范(36×36 画布、蓝色渐变圆角瓦片 `#69B9FF → #324DE2`、外层统一缩到 26/28),但记号改用**深墨蓝 `#0E1C58` 的圆角方 + 中心点**,而不是白色细描边 —— 这个图标同时出现在**浅色主题**下(插件管理器的卡片/行、设置导航),瓦片顶部是亮蓝,白描边在 36px 就糊成"蓝方块+白点";深墨蓝在整块渐变上都够暗,缩到 16px 仍可辨。同时去掉 SVG 里的固定 `width/height`,显示尺寸交给宿主(行 30 / 卡片 36)。
|
|
286
288
|
- **0.5.1** —— 清理空作用域文件:作用域被删空后(删掉最后一条、或 `POST /data/wipe`),它的 `.jsonl` 与 `.vec` 会在下一次落盘时一起移除,不再留 0 字节文件与只剩身份头的边车;下次写同一个名字会重新创建。`global.jsonl` 是唯一例外(保留作用域只清内容、留文件)。同版本的旧文件行为不变,无数据迁移。
|
package/lib/client.js
CHANGED
|
@@ -833,9 +833,9 @@ window.__ModuleLoader__.load({
|
|
|
833
833
|
function apply(ctx) {
|
|
834
834
|
try {
|
|
835
835
|
const styleEl = document.createElement('style')
|
|
836
|
-
|
|
837
|
-
styleEl.textContent = `${CSS}\n${NAV_ICON_CSS}`
|
|
836
|
+
styleEl.textContent = CSS
|
|
838
837
|
document.head.appendChild(styleEl)
|
|
838
|
+
// 侧栏那一行的图标:宿主写死了齿轮,我们只改它 SVG 的孩子(见 wrapSettingsNav)
|
|
839
839
|
const stopNavWatch = wrapSettingsNav()
|
|
840
840
|
ctx.effect(() => () => { styleEl.remove(); stopNavWatch() }, 'dsh-memory: styles + nav icon')
|
|
841
841
|
|
|
@@ -868,8 +868,7 @@ window.__ModuleLoader__.load({
|
|
|
868
868
|
* "官方指定图标"的入口。
|
|
869
869
|
*
|
|
870
870
|
* 因此只有一条路:用宿主自己的类名做一次**定向覆盖** —— 把那颗齿轮**就地**换成我们的
|
|
871
|
-
* 记号(
|
|
872
|
-
* 三条护栏让它不会把界面弄坏:
|
|
871
|
+
* 记号(内存芯片)。三条护栏让它不会把界面弄坏:
|
|
873
872
|
* 1. 选择器只认 className 的**后缀**:宿主的类名是 CSS Modules 生成的
|
|
874
873
|
* `<hash>_navCell` / `<hash>_navIcon`(hash 随构建变),所以用
|
|
875
874
|
* `[class*="_navIcon"]` 匹配,hash 变了也照样命中;
|
|
@@ -877,47 +876,65 @@ window.__ModuleLoader__.load({
|
|
|
877
876
|
* `dsh-memory-nav` 标记类,规则全部限定在它下面 —— 其它区块(账号/模型/插件市场)
|
|
878
877
|
* 的图标一个都不碰。标记打在**按钮自己**身上而不是它所在的列表上:整列共用一个
|
|
879
878
|
* 列表容器,标在容器上会波及所有区块。
|
|
880
|
-
* 3. **不改布局、不插 DOM
|
|
879
|
+
* 3. **不改布局、不插 DOM**:那颗 svg 还是宿主自己渲染的,我们只把它内部换成芯片,
|
|
880
|
+
* 盒子尺寸/行高/对齐全由宿主保证。
|
|
881
881
|
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
882
|
+
* 风格必须跟着**侧栏这一列**走:这一列全是 16px 单色细线图标(宿主内置的
|
|
883
|
+
* Icon*OutlineMedium:16 网格、fill:none、stroke:currentColor、strokeWidth 1.3),
|
|
884
|
+
* 所以记号画成线稿芯片;**不是**插件管理器卡片/行那套"蓝色瓦片 + 白色记号"的插件美术
|
|
885
|
+
* (那个尺寸是 36/30px,另一套 surface —— icon.svg 仍服务那边)。0.5.3/0.5.4 早期版本
|
|
886
|
+
* 把蓝瓦片塞进这一列,结果就是一个实心蓝块混在细线图标里,格格不入。
|
|
887
|
+
*
|
|
888
|
+
* 实现:把宿主那颗 svg 的**子节点**换成芯片的线稿。三条被否掉的路,留给后来人:
|
|
889
|
+
* - `::before` 补一个(0.5.3):真机上盒子没成形 —— 齿轮没了、记号也没出现,空一格;
|
|
890
|
+
* - 给 svg 上背景图(0.5.4):能画出来,但只能画色块,画不出"1.3 描边的线稿",与这列不搭;
|
|
891
|
+
* - `content: url(...)` 替换 svg 内容:SVG 元素不支持 content 替换,实测无效。
|
|
892
|
+
* 换子节点这条路的失败模式是良性的:svg 由宿主渲染,我们只动它的孩子,尺寸/对齐/行高
|
|
893
|
+
* 一定由宿主保证;万一类名约定变了,选中不到就没有任何改动,图标保持原样。
|
|
894
|
+
* React 若重渲染把图形覆盖回去,observer 会在下一轮按子节点重新补上。
|
|
888
895
|
*/
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
'
|
|
893
|
-
'
|
|
894
|
-
'
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
896
|
+
const NAV_ICON_NS = 'http://www.w3.org/2000/svg'
|
|
897
|
+
/** 芯片线稿:16 网格、1.3 描边、跟随 currentColor(与宿主内置图标同一规范)。 */
|
|
898
|
+
const CHIP_SHAPES = [
|
|
899
|
+
{ tag: 'rect', attrs: { x: '5', y: '5', width: '6', height: '6', rx: '1.4', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.3' } },
|
|
900
|
+
{ tag: 'rect', attrs: { x: '6.9', y: '6.9', width: '2.2', height: '2.2', rx: '0.6', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.3' } },
|
|
901
|
+
{ tag: 'path', attrs: { d: 'M8 5V3.2M8 11v1.8M5 8H3.2M11 8h1.8', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.3', 'stroke-linecap': 'round' } },
|
|
902
|
+
]
|
|
903
|
+
|
|
904
|
+
/** 把一颗 nav 图标的图形换成芯片;已经是芯片就跳过(observer 会反复调到这里)。 */
|
|
905
|
+
function paintChip(svg) {
|
|
906
|
+
const shapes = svg.querySelectorAll('rect,path,circle,line,polyline,polygon')
|
|
907
|
+
const first = shapes[0]
|
|
908
|
+
const isChip = shapes.length === CHIP_SHAPES.length
|
|
909
|
+
&& first?.tagName?.toLowerCase() === 'rect'
|
|
910
|
+
&& first.getAttribute('rx') === '1.4'
|
|
911
|
+
if (isChip) return
|
|
912
|
+
svg.replaceChildren(...CHIP_SHAPES.map(({ tag, attrs }) => {
|
|
913
|
+
const node = document.createElementNS(NAV_ICON_NS, tag)
|
|
914
|
+
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v)
|
|
915
|
+
return node
|
|
916
|
+
}))
|
|
917
|
+
}
|
|
903
918
|
|
|
904
919
|
/**
|
|
905
|
-
* 在"含「记忆」那一行"
|
|
920
|
+
* 在"含「记忆」那一行"上做记号并换图。
|
|
906
921
|
*
|
|
907
|
-
*
|
|
922
|
+
* 关键:记号打在**按钮自己**身上,绝不打在父级 navList 上 —— 整列是同一个容器,
|
|
908
923
|
* 打到父级等于给所有区块都加图标。面板随时可能卸载/重挂(它是 body 上的 portal),
|
|
909
924
|
* 所以用 MutationObserver 跟着 DOM 走;识别依据是**这一行的文案**(trim 后比对),
|
|
910
|
-
* 不依赖任何类名 ——
|
|
925
|
+
* 不依赖任何类名 —— 类名约定变了只是什么都不做,图标保持宿主原样。
|
|
911
926
|
*/
|
|
912
927
|
function wrapSettingsNav() {
|
|
913
928
|
const mark = () => {
|
|
914
929
|
try {
|
|
915
930
|
for (const cell of document.querySelectorAll('[class*="_navCell"]')) {
|
|
916
931
|
const label = (cell.textContent ?? '').trim()
|
|
917
|
-
if (label
|
|
918
|
-
|
|
932
|
+
if (label !== NAV_LABEL) continue
|
|
933
|
+
cell.classList?.add('dsh-memory-nav')
|
|
934
|
+
const icon = cell.querySelector('[class*="_navIcon"]')
|
|
935
|
+
if (icon) paintChip(icon)
|
|
919
936
|
}
|
|
920
|
-
} catch { /*
|
|
937
|
+
} catch { /* 换图失败:图标保持宿主原样 */ }
|
|
921
938
|
}
|
|
922
939
|
mark()
|
|
923
940
|
const observer = new MutationObserver(mark)
|
package/lib/provider/apply.js
CHANGED
|
@@ -133,6 +133,11 @@ export class CordisMemoryService extends Service {
|
|
|
133
133
|
return this.impl.resolveWriteScope(agent, requested)
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/** 当前项目 key(会话 cwd 优先)。工具层解析 `scope:'project'` 时用它,口径与读写一致。 */
|
|
137
|
+
projectKeyFor(agent ) {
|
|
138
|
+
return this.impl.projectKeyFor(agent)
|
|
139
|
+
}
|
|
140
|
+
|
|
136
141
|
/** 作用域清单(名字 + 条数),面板 /status 与 memory_list 共用。 */
|
|
137
142
|
scopeStats() {
|
|
138
143
|
return this.impl.scopeStats()
|
|
@@ -158,10 +163,12 @@ export function apply(ctx , config = {}) {
|
|
|
158
163
|
class ScopedMemoryService extends CordisMemoryService {
|
|
159
164
|
constructor(ctx2 ) {
|
|
160
165
|
super(ctx2, config)
|
|
161
|
-
// 写路径默认口径来自 tools 小节(defaultScope 缺省 = 会话)
|
|
162
|
-
//
|
|
166
|
+
// 写路径默认口径来自 tools 小节(defaultScope 缺省 = 会话)。项目键**只在显式配置**
|
|
167
|
+
// 时才固定下来;缺省由每次调用的 `session.header.cwd` 解析(那才是工作区)。
|
|
168
|
+
// 以前这里写成 `?? project:${process.cwd()}`,而 DSH 服务进程的 cwd 是 profile 目录,
|
|
169
|
+
// 等于把"当前项目"钉成了 profile —— 项目级记忆于是跨项目混在一起。
|
|
163
170
|
const tools = (config ).tools
|
|
164
|
-
this.impl.setProjectScope(
|
|
171
|
+
if (tools?.projectScope !== undefined) this.impl.setProjectScope(tools.projectScope )
|
|
165
172
|
if (tools?.defaultScope !== undefined) this.impl.setDefaultScope(tools.defaultScope)
|
|
166
173
|
}
|
|
167
174
|
}
|
package/lib/provider/index.js
CHANGED
|
@@ -483,8 +483,8 @@ export class LocalMemoryService {
|
|
|
483
483
|
llmInvoke = null
|
|
484
484
|
/** 写路径的默认口径(tools.defaultScope);'session' 拿不到会话时回退 project。 */
|
|
485
485
|
defaultWriteScope = 'session'
|
|
486
|
-
/**
|
|
487
|
-
projectScope
|
|
486
|
+
/** 显式配置的项目 scope 键(未配置 = undefined,由 resolveCurrentScopes 按会话 cwd 决定)。 */
|
|
487
|
+
projectScope
|
|
488
488
|
/** 上次发现磁盘 scope 的时间(限流用;0 = 还没发现过)。 */
|
|
489
489
|
discoveredAt = 0
|
|
490
490
|
|
|
@@ -501,8 +501,10 @@ export class LocalMemoryService {
|
|
|
501
501
|
// 会话 scope 是按会话动态生成的,**不能**在这里 eager 加载(加载谁?);只预载
|
|
502
502
|
// project 与 global 这两个稳定作用域。其余按需 peek/loadDiscovered。
|
|
503
503
|
// eager 只加载"已存在"的 scope(peek),不会为不存在的 scope 建空文件。
|
|
504
|
+
// 项目键此刻还看不到会话(没传 agent),所以这里只能预载"没有显式配置时的兜底键"
|
|
505
|
+
// (= project:<process.cwd()>);真正的项目键在每次调用时按会话 cwd 解析。
|
|
504
506
|
const eager = []
|
|
505
|
-
if (this.cfg.projectEnabled) eager.push(this.
|
|
507
|
+
if (this.cfg.projectEnabled) eager.push(this.defaultProjectScope)
|
|
506
508
|
if (this.cfg.globalEnabled) eager.push('global')
|
|
507
509
|
for (const scope of eager) this.store.peek(scope)
|
|
508
510
|
this.embed = new EmbedClient({
|
|
@@ -992,11 +994,19 @@ export class LocalMemoryService {
|
|
|
992
994
|
this.projectScope = scope
|
|
993
995
|
}
|
|
994
996
|
|
|
995
|
-
/** 固定项目 scope(
|
|
997
|
+
/** 固定项目 scope(只有**显式配置**才调);缺省由会话 cwd 决定。 */
|
|
996
998
|
setProjectScope(scope ) {
|
|
997
999
|
this.projectScope = scope
|
|
998
1000
|
}
|
|
999
1001
|
|
|
1002
|
+
/**
|
|
1003
|
+
* 拿不到会话时的项目键:显式配置优先,否则 `project:<process.cwd()>`
|
|
1004
|
+
* (用于构造期预载、以及任何没有 agent 上下文的兜底读写)。
|
|
1005
|
+
*/
|
|
1006
|
+
get defaultProjectScope() {
|
|
1007
|
+
return (this.projectScope ?? `project:${process.cwd()}`)
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1000
1010
|
/**
|
|
1001
1011
|
* Provide the one-shot LLM caller used by the rerank stage. Passing null
|
|
1002
1012
|
* (or never calling) keeps retrieval on recall-order only. The cordis
|
|
@@ -1012,8 +1022,12 @@ export class LocalMemoryService {
|
|
|
1012
1022
|
return this.defaultWriteScope
|
|
1013
1023
|
}
|
|
1014
1024
|
|
|
1025
|
+
/**
|
|
1026
|
+
* 当前项目键(诊断/测试用)。没有会话时就是兜底键 —— 真实调用请用 `scopeRefs(agent)`,
|
|
1027
|
+
* 那里的优先级是 会话 cwd > 显式配置 > process.cwd()。
|
|
1028
|
+
*/
|
|
1015
1029
|
get activeProjectScope() {
|
|
1016
|
-
return this.
|
|
1030
|
+
return this.defaultProjectScope
|
|
1017
1031
|
}
|
|
1018
1032
|
|
|
1019
1033
|
assertScopeAllowed(scope ) {
|
|
@@ -1081,6 +1095,15 @@ export class LocalMemoryService {
|
|
|
1081
1095
|
return resolveCurrentScopes(agent, { projectScope: this.projectScope })
|
|
1082
1096
|
}
|
|
1083
1097
|
|
|
1098
|
+
/**
|
|
1099
|
+
* 当前项目 key(= `scopeRefs(agent).project`)。工具层用它解析 `scope:'project'`,保证与服务端
|
|
1100
|
+
* 读/写口径**同一处** —— 0.5.5 及以前工具层自己算了一份 `project:<process.cwd()>`,于是同一个
|
|
1101
|
+
* 概念在两个层各有各的答案。
|
|
1102
|
+
*/
|
|
1103
|
+
projectKeyFor(agent ) {
|
|
1104
|
+
return this.scopeRefs(agent).project
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1084
1107
|
/**
|
|
1085
1108
|
* 无显式 scope 时的**读取**合并集合:当前会话 + 当前项目 + global(各自开关生效、按 key 去重)。
|
|
1086
1109
|
* 工具 / 注入都用它,保证"写进会话的东西,默认读得回来"。
|
|
@@ -1213,7 +1236,7 @@ export class LocalMemoryService {
|
|
|
1213
1236
|
? [query.scope]
|
|
1214
1237
|
: (queryScopes ?? []).length > 0
|
|
1215
1238
|
? queryScopes
|
|
1216
|
-
: [this.
|
|
1239
|
+
: [this.defaultProjectScope, 'global']
|
|
1217
1240
|
const stores = []
|
|
1218
1241
|
const seen = new Set ()
|
|
1219
1242
|
for (const scope of wanted) {
|
|
@@ -1350,7 +1373,7 @@ export class LocalMemoryService {
|
|
|
1350
1373
|
? [input.scope]
|
|
1351
1374
|
: (input.scopes ?? []).length > 0
|
|
1352
1375
|
? input.scopes
|
|
1353
|
-
: [this.
|
|
1376
|
+
: [this.defaultProjectScope]
|
|
1354
1377
|
const seen = new Set ()
|
|
1355
1378
|
for (const scope of targets) {
|
|
1356
1379
|
if (seen.has(scope)) continue
|
|
@@ -1377,7 +1400,7 @@ export class LocalMemoryService {
|
|
|
1377
1400
|
? [input.scope]
|
|
1378
1401
|
: (input.scopes ?? []).length > 0
|
|
1379
1402
|
? input.scopes
|
|
1380
|
-
: [this.
|
|
1403
|
+
: [this.defaultProjectScope]
|
|
1381
1404
|
const seen = new Set ()
|
|
1382
1405
|
let records = []
|
|
1383
1406
|
for (const scope of wanted) {
|
package/lib/provider/scope.js
CHANGED
|
@@ -225,10 +225,27 @@ export function resolveCurrentScopes(agent , opts
|
|
|
225
225
|
sessionId = undefined
|
|
226
226
|
}
|
|
227
227
|
const cwd = asString(header?.cwd)
|
|
228
|
-
|
|
228
|
+
// 项目 key 的优先级:**会话 cwd** > 显式配置的 projectScope > process.cwd()。
|
|
229
|
+
// cwd 必须排第一:`session.header.cwd` 是宿主给的"canonical primary workspace",
|
|
230
|
+
// 而 DSH 服务进程的 process.cwd() 是**profile 目录**(~/.dsh/profiles/<name>),
|
|
231
|
+
// 与工作区无关 —— 0.5.5 及以前把 `project:${process.cwd()}` 当成"配置"先传进来,
|
|
232
|
+
// 结果所有项目的项目级记忆都挤进同一个桶,`project:` 这个作用域等于失效。
|
|
233
|
+
const project = `project:${cwd ?? stripProjectPrefix(opts.projectScope) ?? process.cwd()}`
|
|
229
234
|
return sessionId !== undefined ? { session: `session:${sessionId}`, project } : { project }
|
|
230
235
|
}
|
|
231
236
|
|
|
237
|
+
/**
|
|
238
|
+
* `project:/x` → `/x`;不是字符串或空串 → undefined(交给下一级回退)。
|
|
239
|
+
*
|
|
240
|
+
* 显式配置按文档写成 `project:/abs/path`(见 tool-memory/cordis.patch.yml),所以拼接前缀前
|
|
241
|
+
* 必须先脱掉已经带上的那一层,否则会得到 `project:project:/x` —— 与配置、与真实落点都对不上。
|
|
242
|
+
*/
|
|
243
|
+
function stripProjectPrefix(value ) {
|
|
244
|
+
const s = asString(value)
|
|
245
|
+
if (s === undefined) return undefined
|
|
246
|
+
return (s.startsWith('project:') ? s.slice('project:'.length) : s) || undefined
|
|
247
|
+
}
|
|
248
|
+
|
|
232
249
|
// ------------------------------------------------------------------ kind → 具体 key
|
|
233
250
|
|
|
234
251
|
|
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:'))
|