dsh-plugins-scope 0.5.2 → 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/CHANGELOG.md +9 -0
- package/client.js +163 -1
- package/index.js +164 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
- 新增通用客户端 UI 作用域过滤:包装 `ctx.slots.register/registerFactory` 与 `contextMenus`,按注册包隐藏整个插件 UI;不再为单个插件写 CSS。
|
|
6
|
+
- 服务端扫描每个包的 `client.js` slot id,写入 `clientIds`;修复无 `key` 的 UI(如 `persona-dock`、`windows-mcp-computer-use`)。
|
|
7
|
+
- 新增命令(commands)作用域:静态扫描 + 运行期 owner,关闭后 `/purge` 等命令从列表、查找、执行三处消失。
|
|
8
|
+
- 修复 `hiddenForSession()` 使用未定义 `sid` 导致所有 turn 报 `sid is not defined`。
|
|
9
|
+
- `dsh-harness-remote`、`@linxin666/dsh-remote-web-ui` 判定为仅全局,不参与会话/工作区开关;它们的 13 个远程工具是 Agent 控制面,不是会话插件。
|
|
10
|
+
- 修复 profile 解析对旧依赖名 `dsh-scope-manager` 的回退。
|
|
11
|
+
|
|
3
12
|
## 0.5.2
|
|
4
13
|
|
|
5
14
|
- 分叉会话与子代理沿父链继承父会话的覆盖值(不复制);父会话归档仍可解析,删除后回落到工作区。
|
package/client.js
CHANGED
|
@@ -18,6 +18,160 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
return body.data;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function ClientUiHider({ sessionId }) {
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!sessionId) return undefined;
|
|
24
|
+
let disposed = false;
|
|
25
|
+
const sync = async () => {
|
|
26
|
+
try {
|
|
27
|
+
const state = await call({ op: 'state', sessionId });
|
|
28
|
+
if (disposed) return;
|
|
29
|
+
const hidden = [];
|
|
30
|
+
const idToPackage = new Map();
|
|
31
|
+
for (const row of (state?.rows ?? [])) {
|
|
32
|
+
for (const id of (row?.clientIds ?? [])) {
|
|
33
|
+
if (typeof id === 'string' && id) idToPackage.set(id, row.key);
|
|
34
|
+
}
|
|
35
|
+
if (row?.effective !== 'off') continue;
|
|
36
|
+
if (!row?.protected) hidden.push(row.key);
|
|
37
|
+
}
|
|
38
|
+
scopeIdToPackage = idToPackage;
|
|
39
|
+
publishScopeHidden(hidden);
|
|
40
|
+
} catch {
|
|
41
|
+
// Fail open: an unavailable scope API must never remove plugin UI.
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
sync();
|
|
45
|
+
const timer = setInterval(sync, 1500);
|
|
46
|
+
window.addEventListener('dsh-plugin-scope-changed', sync);
|
|
47
|
+
return () => {
|
|
48
|
+
disposed = true;
|
|
49
|
+
clearInterval(timer);
|
|
50
|
+
window.removeEventListener('dsh-plugin-scope-changed', sync);
|
|
51
|
+
};
|
|
52
|
+
}, [sessionId]);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// One generic layer for every React slot registration. The scope API works on
|
|
57
|
+
// package names; slot registrations expose either `key` (the package id) or an
|
|
58
|
+
// `id` derived from the package slug. Wrapping the component lets React
|
|
59
|
+
// re-render when the hidden set changes instead of relying on per-plugin CSS.
|
|
60
|
+
const scopeHidden = new Set();
|
|
61
|
+
const scopeHiddenListeners = new Set();
|
|
62
|
+
let scopeIdToPackage = new Map();
|
|
63
|
+
|
|
64
|
+
function publishScopeHidden(packages) {
|
|
65
|
+
const next = new Set((packages ?? []).filter((value) => typeof value === 'string' && value.length > 0));
|
|
66
|
+
if (next.size === scopeHidden.size && [...next].every((value) => scopeHidden.has(value))) return;
|
|
67
|
+
scopeHidden.clear();
|
|
68
|
+
for (const value of next) scopeHidden.add(value);
|
|
69
|
+
for (const listener of [...scopeHiddenListeners]) {
|
|
70
|
+
try { listener(); } catch { /* ignore one bad slot */ }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
function slotOwnedBy(options, pkg) {
|
|
76
|
+
const key = typeof options?.key === 'string' ? options.key : '';
|
|
77
|
+
const id = typeof options?.id === 'string' ? options.id : '';
|
|
78
|
+
if (key === pkg || key.startsWith(`${pkg}/`) || key.startsWith(`${pkg}:`)) return true;
|
|
79
|
+
if (id && scopeIdToPackage.get(id) === pkg) return true;
|
|
80
|
+
const slug = pkg.replace(/^@[^/]+\//, '').replace(/^dsh-/, '');
|
|
81
|
+
return id === slug || id.startsWith(`${slug}-`) || id.startsWith(`${slug}:`) || id.startsWith(`${slug}.`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function slotIsHidden(options) {
|
|
85
|
+
for (const pkg of scopeHidden) {
|
|
86
|
+
if (pkg === 'dsh-plugins-scope') continue;
|
|
87
|
+
if (slotOwnedBy(options, pkg)) return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function ScopeSlotGuard({ options, Component, ...props }) {
|
|
93
|
+
const hidden = React.useSyncExternalStore(
|
|
94
|
+
(listener) => {
|
|
95
|
+
scopeHiddenListeners.add(listener);
|
|
96
|
+
return () => scopeHiddenListeners.delete(listener);
|
|
97
|
+
},
|
|
98
|
+
() => slotIsHidden(options),
|
|
99
|
+
() => false,
|
|
100
|
+
);
|
|
101
|
+
return hidden ? null : h(Component, props);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function installSlotScopeGuard(ctx) {
|
|
105
|
+
const slots = ctx.slots;
|
|
106
|
+
if (slots === undefined || slots.__dshScopeGuard === true) return;
|
|
107
|
+
const register = slots.register;
|
|
108
|
+
if (typeof register !== 'function') return;
|
|
109
|
+
const wrap = (options, component) => {
|
|
110
|
+
return typeof component === 'function'
|
|
111
|
+
? function ScopedSlot(props) {
|
|
112
|
+
return h(ScopeSlotGuard, { ...props, options, Component: component });
|
|
113
|
+
}
|
|
114
|
+
: component;
|
|
115
|
+
};
|
|
116
|
+
slots.register = function registerScoped(options, component) {
|
|
117
|
+
return register.call(slots, options, wrap(options, component));
|
|
118
|
+
};
|
|
119
|
+
const registerFactory = slots.registerFactory;
|
|
120
|
+
if (typeof registerFactory === 'function') {
|
|
121
|
+
slots.registerFactory = function registerFactoryScoped(options, component) {
|
|
122
|
+
return registerFactory.call(slots, options, wrap(options, component));
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// Entries registered before this plugin loaded (persona/composer controls are
|
|
126
|
+
// mounted early) never pass through the wrapper above. Wrap them lazily at the
|
|
127
|
+
// renderer's read boundary instead of keeping a per-plugin selector table.
|
|
128
|
+
const core = slots._core;
|
|
129
|
+
if (core && typeof core.entriesOfSlot === 'function' && core.__dshScopeReadGuard !== true) {
|
|
130
|
+
const entriesOfSlot = core.entriesOfSlot.bind(core);
|
|
131
|
+
core.entriesOfSlot = function scopedEntriesOfSlot(key) {
|
|
132
|
+
const entries = entriesOfSlot(key);
|
|
133
|
+
if (!Array.isArray(entries)) return entries;
|
|
134
|
+
return entries.map((entry) => {
|
|
135
|
+
if (!entry || entry.__dshScopeWrapped === true) return entry;
|
|
136
|
+
const Component = entry.component;
|
|
137
|
+
if (Component === null || Component === undefined) return entry;
|
|
138
|
+
const wrapped = function ScopedExistingSlot(props) {
|
|
139
|
+
return h(ScopeSlotGuard, { ...props, options: entry.options, Component });
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
entry.component = wrapped;
|
|
143
|
+
entry.__dshScopeWrapped = true;
|
|
144
|
+
return entry;
|
|
145
|
+
} catch {
|
|
146
|
+
return { ...entry, component: wrapped, __dshScopeWrapped: true };
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
Object.defineProperty(core, '__dshScopeReadGuard', { value: true, enumerable: false });
|
|
151
|
+
}
|
|
152
|
+
Object.defineProperty(slots, '__dshScopeGuard', { value: true, enumerable: false });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function installContextMenuGuard(ctx) {
|
|
156
|
+
const menus = ctx.contextMenus;
|
|
157
|
+
if (menus === undefined || menus.__dshScopeGuard === true) return;
|
|
158
|
+
const register = menus.register;
|
|
159
|
+
if (typeof register !== 'function') return;
|
|
160
|
+
menus.register = function registerScopedMenu(options) {
|
|
161
|
+
const resolve = options?.resolve;
|
|
162
|
+
if (typeof resolve !== 'function') return register.call(menus, options);
|
|
163
|
+
return register.call(menus, {
|
|
164
|
+
...options,
|
|
165
|
+
resolve: async (...args) => {
|
|
166
|
+
const items = await resolve(...args);
|
|
167
|
+
if (!Array.isArray(items)) return items;
|
|
168
|
+
return items.filter((item) => !slotIsHidden({ key: item?.key, id: item?.id }));
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
Object.defineProperty(menus, '__dshScopeGuard', { value: true, enumerable: false });
|
|
173
|
+
}
|
|
174
|
+
|
|
21
175
|
const LABEL = { on: '开', off: '关' };
|
|
22
176
|
const COLOR = {
|
|
23
177
|
on: 'var(--dsw-alias-state-success-primary)',
|
|
@@ -545,7 +699,7 @@ window.__ModuleLoader__.load({
|
|
|
545
699
|
h('div', null,
|
|
546
700
|
h('div', { style: { fontSize: '15px', fontWeight: 600, color: theme.text } }, '第三方插件作用域'),
|
|
547
701
|
h('div', { style: { marginTop: '4px', color: theme.muted, lineHeight: 1.65 } },
|
|
548
|
-
'
|
|
702
|
+
'类型按插件描述自动判定:工具、模型、提示词等会随会话变化的是“会话级”;壁纸、界面、管理、远程连接类只在全局生效的是“仅全局”。远程/隧道插件固定全局,避免关掉会话时把连接通道一起关掉。开关只改“这一层”,右侧文字说明它当前是跟随上一层还是本层已固定。'),
|
|
549
703
|
message
|
|
550
704
|
? h('div', { style: { marginTop: '6px', fontSize: '12px', color: theme.warn } }, message)
|
|
551
705
|
: null,
|
|
@@ -671,6 +825,8 @@ window.__ModuleLoader__.load({
|
|
|
671
825
|
return {
|
|
672
826
|
inject: ['slots', 'contextMenus'],
|
|
673
827
|
apply(ctx) {
|
|
828
|
+
installSlotScopeGuard(ctx);
|
|
829
|
+
installContextMenuGuard(ctx);
|
|
674
830
|
ctx.slots.inject('plugins.tab', () => ctx.slots.register({
|
|
675
831
|
name: 'plugins.tab',
|
|
676
832
|
id: 'plugin-scopes',
|
|
@@ -683,6 +839,12 @@ window.__ModuleLoader__.load({
|
|
|
683
839
|
order: 30,
|
|
684
840
|
label: '插件作用域',
|
|
685
841
|
}, NewSessionScope));
|
|
842
|
+
ctx.slots.inject('conversation.input.left', () => ctx.slots.register({
|
|
843
|
+
name: 'conversation.input.left',
|
|
844
|
+
id: 'plugin-scopes-client-ui',
|
|
845
|
+
order: 900,
|
|
846
|
+
inject: (sessionId) => ({ sessionId }),
|
|
847
|
+
}, ClientUiHider));
|
|
686
848
|
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
687
849
|
name: 'shell.overlay',
|
|
688
850
|
id: 'plugin-scopes-dialog',
|
package/index.js
CHANGED
|
@@ -27,6 +27,8 @@ const HIDDEN_HOOK = Symbol.for('dsh.plugin-scopes.hidden-hook');
|
|
|
27
27
|
const PROMPT_PATCH_MARK = Symbol.for('dsh.plugin-scopes.prompt-patch-v2');
|
|
28
28
|
const HIDDEN_PLUGINS_HOOK = Symbol.for('dsh.plugin-scopes.hidden-plugins');
|
|
29
29
|
const SECTION_OWNERS = Symbol.for('dsh.plugin-scopes.section-owners');
|
|
30
|
+
const COMMAND_OWNERS = Symbol.for('dsh.plugin-scopes.command-owners');
|
|
31
|
+
const COMMAND_PATCH_MARK = Symbol.for('dsh.plugin-scopes.command-patch');
|
|
30
32
|
const CONTEXT_OWNERS = Symbol.for('dsh.plugin-scopes.context-owners');
|
|
31
33
|
const STREAM_PATCH_MARK = Symbol.for('dsh.plugin-scopes.stream-patch-v1');
|
|
32
34
|
const SKILL_PATCH_MARK = Symbol.for('dsh.plugin-scopes.skill-patch-v1');
|
|
@@ -110,7 +112,7 @@ function resolveProfileDir() {
|
|
|
110
112
|
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
111
113
|
const bundles = pkg.dsh?.profile?.bundles ?? [];
|
|
112
114
|
const deps = pkg.dependencies ?? {};
|
|
113
|
-
if (bundles.includes('dsh-plugins-scope') || deps['dsh-plugins-scope'] || bundles.includes('dsh-plugin-scope') || deps['dsh-plugin-scope']) return dir;
|
|
115
|
+
if (bundles.includes('dsh-plugins-scope') || deps['dsh-plugins-scope'] || bundles.includes('dsh-plugin-scope') || deps['dsh-plugin-scope'] || bundles.includes('dsh-scope-manager') || deps['dsh-scope-manager']) return dir;
|
|
114
116
|
} catch {
|
|
115
117
|
/* not a profile */
|
|
116
118
|
}
|
|
@@ -235,7 +237,23 @@ function packageDescription(dir) {
|
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
|
|
240
|
+
const FORCE_GLOBAL_NAME = /remote|远程|relay|tunnel/i;
|
|
241
|
+
|
|
242
|
+
function packageName(dir) {
|
|
243
|
+
try {
|
|
244
|
+
return String(JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).name || '');
|
|
245
|
+
} catch {
|
|
246
|
+
return '';
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
238
250
|
function describeScope(dir) {
|
|
251
|
+
const name = packageName(dir);
|
|
252
|
+
// Remote-access / tunnel plugins are infrastructure: turning them off for a
|
|
253
|
+
// single session would cut the very channel used to reach that session. They
|
|
254
|
+
// must stay global-only regardless of what their description says.
|
|
255
|
+
if (FORCE_GLOBAL_NAME.test(name))
|
|
256
|
+
return { decision: false, category: 'global', forceGlobal: true, reason: `远程连接/基础设施插件(${name}),固定全局` };
|
|
239
257
|
const text = packageDescription(dir);
|
|
240
258
|
if (!text) return { decision: null, category: 'unknown', reason: '没有描述' };
|
|
241
259
|
const agentHits = AGENT_HINTS.filter((word) => hintHit(text, word));
|
|
@@ -738,6 +756,53 @@ function makeService(ctx) {
|
|
|
738
756
|
return names;
|
|
739
757
|
}
|
|
740
758
|
|
|
759
|
+
function clientSlotIds(dir) {
|
|
760
|
+
const files = ['client.js', 'lib/client.js', 'dist/client.js', 'client/index.js'];
|
|
761
|
+
const ids = new Set();
|
|
762
|
+
let source = '';
|
|
763
|
+
for (const file of files) {
|
|
764
|
+
try { source = fs.readFileSync(path.join(dir, file), 'utf8'); break; } catch { /* try next entry */ }
|
|
765
|
+
}
|
|
766
|
+
if (!source) return [];
|
|
767
|
+
// Client UI is registered through `ctx.slots.register/inject({ id, key, name }, ...)`.
|
|
768
|
+
// The id is stable per entry, so scan it once per package instead of asking the
|
|
769
|
+
// user (or the plugin author) to maintain a per-plugin DOM selector.
|
|
770
|
+
for (const call of source.matchAll(/slots\.(?:register|registerFactory|inject)\s*\(/g)) {
|
|
771
|
+
const tail = source.slice(call.index, call.index + 900);
|
|
772
|
+
const id = tail.match(/\bid\s*:\s*['"]([^'"]+)['"]/);
|
|
773
|
+
if (id?.[1]) ids.add(id[1]);
|
|
774
|
+
const key = tail.match(/\bkey\s*:\s*['"]([^'"]+)['"]/);
|
|
775
|
+
if (key?.[1]) ids.add(key[1]);
|
|
776
|
+
}
|
|
777
|
+
return [...ids];
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function commandNames(dir) {
|
|
781
|
+
const names = new Set();
|
|
782
|
+
for (const file of walkSources(dir)) {
|
|
783
|
+
let text;
|
|
784
|
+
try {
|
|
785
|
+
if (fs.statSync(file).size > 8_000_000) continue;
|
|
786
|
+
text = fs.readFileSync(file, 'utf8');
|
|
787
|
+
} catch { continue; }
|
|
788
|
+
for (const call of text.matchAll(/\.register\s*\(\s*\{/g)) {
|
|
789
|
+
const head = text.slice(Math.max(0, call.index - 120), call.index);
|
|
790
|
+
if (!/commands/.test(head)) continue;
|
|
791
|
+
const tail = text.slice(call.index, call.index + 700);
|
|
792
|
+
const name = tail.match(/\bname\s*:\s*['"]([^'"]+)['"]/);
|
|
793
|
+
if (name?.[1]) names.add(name[1]);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return [...names];
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function staticCommandOwner(name) {
|
|
800
|
+
for (const row of rowsCached()) {
|
|
801
|
+
if ((row.commands ?? []).includes(name)) return row.key;
|
|
802
|
+
}
|
|
803
|
+
return undefined;
|
|
804
|
+
}
|
|
805
|
+
|
|
741
806
|
function buildRows() {
|
|
742
807
|
const { deps, bundles } = profileDeps();
|
|
743
808
|
const base = baseToolNames();
|
|
@@ -764,7 +829,7 @@ function makeService(ctx) {
|
|
|
764
829
|
const runtimeContexts = attrStore().contexts.get(pkg);
|
|
765
830
|
const contexts = runtimeContexts?.size ? [...new Set([...staticContexts, ...runtimeContexts.keys()])] : staticContexts;
|
|
766
831
|
const capability = tools.length > 0 || prompts.length > 0 || contexts.length > 0;
|
|
767
|
-
const scoped = PROTECTED.has(pkg) ? false : (desc.decision ?? capability);
|
|
832
|
+
const scoped = PROTECTED.has(pkg) || desc.forceGlobal ? false : (desc.decision ?? capability);
|
|
768
833
|
const axes = [tools.length, prompts.length, contexts.length].filter((count) => count > 0).length;
|
|
769
834
|
const kind = !capability ? 'global' : axes > 1 ? 'mixed' : tools.length > 0 ? 'tools' : prompts.length > 0 ? 'prompt' : 'context';
|
|
770
835
|
rows.push({
|
|
@@ -780,6 +845,9 @@ function makeService(ctx) {
|
|
|
780
845
|
category: PROTECTED.has(pkg) ? 'global' : desc.category,
|
|
781
846
|
reason: PROTECTED.has(pkg) ? '基础插件,不参与作用域' : desc.reason,
|
|
782
847
|
protected: PROTECTED.has(pkg),
|
|
848
|
+
forceGlobal: desc.forceGlobal === true,
|
|
849
|
+
clientIds: clientSlotIds(dir),
|
|
850
|
+
commands: commandNames(dir),
|
|
783
851
|
});
|
|
784
852
|
}
|
|
785
853
|
// Central attribution pass: observed tool names that no row has claimed yet
|
|
@@ -816,7 +884,7 @@ function makeService(ctx) {
|
|
|
816
884
|
}
|
|
817
885
|
for (const row of rows) {
|
|
818
886
|
row.capability = row.tools.length > 0 || row.promptSections.length > 0 || (row.promptContexts?.length ?? 0) > 0;
|
|
819
|
-
row.scoped = !row.protected && (row.descScope === true || row.capability);
|
|
887
|
+
row.scoped = !row.protected && !row.forceGlobal && (row.descScope === true || row.capability);
|
|
820
888
|
const axes = [row.tools.length, row.promptSections.length, row.promptContexts?.length ?? 0].filter((count) => count > 0).length;
|
|
821
889
|
row.kind = !row.capability ? 'global' : axes > 1 ? 'mixed' : row.tools.length > 0 ? 'tools' : row.promptSections.length > 0 ? 'prompt' : 'context';
|
|
822
890
|
}
|
|
@@ -966,7 +1034,11 @@ function makeService(ctx) {
|
|
|
966
1034
|
|
|
967
1035
|
function hiddenPluginsForSession(sessionId, store) {
|
|
968
1036
|
const rows = rowsCached();
|
|
969
|
-
|
|
1037
|
+
// Agent ids are commonly `session-<uuid>` while storage keys use the bare
|
|
1038
|
+
// uuid. Normalize once so every capability (tools, prompts, skills,
|
|
1039
|
+
// commands, stream hooks) sees the same override.
|
|
1040
|
+
const sid = canonicalSessionId(ctx, sessionId) ?? sessionId;
|
|
1041
|
+
const workspaceId = workspaceIdForSession(sid);
|
|
970
1042
|
const hidden = new Set();
|
|
971
1043
|
for (const row of rows) {
|
|
972
1044
|
if (!row.capability) continue;
|
|
@@ -985,11 +1057,12 @@ function makeService(ctx) {
|
|
|
985
1057
|
// skipped for sessions where the row is off. Only session-scoped rows qualify.
|
|
986
1058
|
function hiddenPackagesForSession(sessionId, store) {
|
|
987
1059
|
const rows = rowsCached();
|
|
988
|
-
const
|
|
1060
|
+
const sid = canonicalSessionId(ctx, sessionId) ?? sessionId;
|
|
1061
|
+
const workspaceId = workspaceIdForSession(sid);
|
|
989
1062
|
const hidden = new Set();
|
|
990
1063
|
for (const row of rows) {
|
|
991
1064
|
if (!row.scoped) continue;
|
|
992
|
-
if (effective(ctx, store, row.key, workspaceId,
|
|
1065
|
+
if (effective(ctx, store, row.key, workspaceId, sid) === 'off') hidden.add(row.key);
|
|
993
1066
|
}
|
|
994
1067
|
return hidden;
|
|
995
1068
|
}
|
|
@@ -1108,6 +1181,65 @@ function makeService(ctx) {
|
|
|
1108
1181
|
}
|
|
1109
1182
|
}
|
|
1110
1183
|
|
|
1184
|
+
function commandOwnerMap() {
|
|
1185
|
+
if (!globalThis[COMMAND_OWNERS]) globalThis[COMMAND_OWNERS] = new Map();
|
|
1186
|
+
return globalThis[COMMAND_OWNERS];
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// Commands are a separate capability from tools/prompts: a plugin can be off
|
|
1190
|
+
// for a session yet still be discoverable in the slash menu unless the
|
|
1191
|
+
// command runtime is filtered too. Attribute registration by stack, then
|
|
1192
|
+
// filter list/find/execute for the exact agent.
|
|
1193
|
+
function installCommandFilter() {
|
|
1194
|
+
const commands = ctx.get?.('commands');
|
|
1195
|
+
if (!commands) return;
|
|
1196
|
+
const proto = Object.getPrototypeOf(commands);
|
|
1197
|
+
if (!proto || proto[COMMAND_PATCH_MARK]) return;
|
|
1198
|
+
const originalRegister = proto.register;
|
|
1199
|
+
if (typeof originalRegister !== 'function') return;
|
|
1200
|
+
Object.defineProperty(proto, COMMAND_PATCH_MARK, { value: true, enumerable: false });
|
|
1201
|
+
proto.register = function patchedCommandRegister(definition) {
|
|
1202
|
+
try {
|
|
1203
|
+
const pkg = packageFromStack(new Error().stack);
|
|
1204
|
+
if (definition?.name && pkg) commandOwnerMap().set(String(definition.name), pkg);
|
|
1205
|
+
} catch { /* attribution is best effort */ }
|
|
1206
|
+
return originalRegister.call(this, definition);
|
|
1207
|
+
};
|
|
1208
|
+
const originalList = proto.list;
|
|
1209
|
+
if (typeof originalList === 'function') {
|
|
1210
|
+
proto.list = function patchedCommandList(agent) {
|
|
1211
|
+
const list = originalList.call(this, agent);
|
|
1212
|
+
try {
|
|
1213
|
+
const hidden = hiddenPluginsForSession(agent?.id, readStore());
|
|
1214
|
+
if (!hidden.size) return list;
|
|
1215
|
+
const owners = commandOwnerMap();
|
|
1216
|
+
return list.filter((item) => !hidden.has(owners.get(String(item.name)) ?? staticCommandOwner(String(item.name))));
|
|
1217
|
+
} catch { return list; }
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
const originalFind = proto.find;
|
|
1221
|
+
if (typeof originalFind === 'function') {
|
|
1222
|
+
proto.find = function patchedCommandFind(agent, name) {
|
|
1223
|
+
try {
|
|
1224
|
+
const hidden = hiddenPluginsForSession(agent?.id, readStore());
|
|
1225
|
+
if (hidden.has(commandOwnerMap().get(String(name)) ?? staticCommandOwner(String(name)))) return undefined;
|
|
1226
|
+
} catch { /* never break lookup */ }
|
|
1227
|
+
return originalFind.call(this, agent, name);
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
const originalExecute = proto.execute;
|
|
1231
|
+
if (typeof originalExecute === 'function') {
|
|
1232
|
+
proto.execute = function patchedCommandExecute(agent, line, ...rest) {
|
|
1233
|
+
try {
|
|
1234
|
+
const name = String(line).replace(/^\//, '').trim().split(/\s+/, 1)[0];
|
|
1235
|
+
const hidden = hiddenPluginsForSession(agent?.id, readStore());
|
|
1236
|
+
if (hidden.has(commandOwnerMap().get(name) ?? staticCommandOwner(name))) return undefined;
|
|
1237
|
+
} catch { /* never break execution */ }
|
|
1238
|
+
return originalExecute.call(this, agent, line, ...rest);
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1111
1243
|
function installSectionFilter() {
|
|
1112
1244
|
const proto = Object.getPrototypeOf(ctx.systemPrompt);
|
|
1113
1245
|
if (!proto) return;
|
|
@@ -1168,6 +1300,15 @@ function makeService(ctx) {
|
|
|
1168
1300
|
const owners = sectionOwnerMap();
|
|
1169
1301
|
const staticOwners = staticSectionOwners(rowsCached());
|
|
1170
1302
|
const sections = (assembly.sections ?? []).filter((section) => {
|
|
1303
|
+
const name = String(section.name ?? '');
|
|
1304
|
+
// A plugin can inject a section directly into the assembled prompt
|
|
1305
|
+
// without registering it through systemPrompt.section (dsh-purge does
|
|
1306
|
+
// exactly that). Its section name is still the package name, so match
|
|
1307
|
+
// it against hidden packages as a last line of defence.
|
|
1308
|
+
if (hidden.has(name)) return false;
|
|
1309
|
+
for (const pkg of hidden) {
|
|
1310
|
+
if (name.startsWith(`${pkg}:`) || name.startsWith(`${pkg}/`)) return false;
|
|
1311
|
+
}
|
|
1171
1312
|
const owner = owners.get(section.name);
|
|
1172
1313
|
if (owner && matchesHidden(owner, hidden)) return false;
|
|
1173
1314
|
const key = staticOwners.get(section.name);
|
|
@@ -1176,6 +1317,11 @@ function makeService(ctx) {
|
|
|
1176
1317
|
const contextOwners = contextOwnerMap();
|
|
1177
1318
|
const staticContexts = staticContextOwners(rowsCached());
|
|
1178
1319
|
const contexts = (assembly.contexts ?? []).filter((entry) => {
|
|
1320
|
+
const name = String(entry.name ?? '');
|
|
1321
|
+
if (hidden.has(name)) return false;
|
|
1322
|
+
for (const pkg of hidden) {
|
|
1323
|
+
if (name.startsWith(`${pkg}:`) || name.startsWith(`${pkg}/`)) return false;
|
|
1324
|
+
}
|
|
1179
1325
|
const owner = contextOwners.get(entry.name);
|
|
1180
1326
|
if (owner && matchesHidden(owner, hidden)) return false;
|
|
1181
1327
|
const key = staticContexts.get(entry.name);
|
|
@@ -1227,6 +1373,7 @@ function makeService(ctx) {
|
|
|
1227
1373
|
const thisArg =
|
|
1228
1374
|
args.length > 0 && (typeof args[0] === 'object' || typeof args[0] === 'function') ? args[0] : null;
|
|
1229
1375
|
const nameIndex = thisArg ? 1 : 0;
|
|
1376
|
+
if (args[nameIndex] === 'system-prompt/assemble') return original.apply(this, args);
|
|
1230
1377
|
if (args[nameIndex] !== 'llm/stream') return original.apply(this, args);
|
|
1231
1378
|
const inner = args[args.length - 1];
|
|
1232
1379
|
const listenerArgs = args.slice(nameIndex + 1, args.length - 1);
|
|
@@ -1299,6 +1446,8 @@ function makeService(ctx) {
|
|
|
1299
1446
|
managed: managedSet.has(row.key),
|
|
1300
1447
|
composable: row.scoped && !composable(row.key),
|
|
1301
1448
|
tools: row.tools,
|
|
1449
|
+
clientIds: row.clientIds ?? [],
|
|
1450
|
+
commands: row.commands ?? [],
|
|
1302
1451
|
promptSections: [],
|
|
1303
1452
|
promptContexts: [],
|
|
1304
1453
|
global: on ? 'on' : 'off',
|
|
@@ -1333,6 +1482,8 @@ function makeService(ctx) {
|
|
|
1333
1482
|
return {
|
|
1334
1483
|
key: row.key,
|
|
1335
1484
|
name: row.name,
|
|
1485
|
+
clientIds: row.clientIds ?? [],
|
|
1486
|
+
commands: row.commands ?? [],
|
|
1336
1487
|
scoped: row.scoped,
|
|
1337
1488
|
capability: row.capability,
|
|
1338
1489
|
kind: row.kind,
|
|
@@ -1432,6 +1583,11 @@ function makeService(ctx) {
|
|
|
1432
1583
|
}
|
|
1433
1584
|
writeStore(store);
|
|
1434
1585
|
cache.delete('rows');
|
|
1586
|
+
// A scope change alters the effective slash-command list without
|
|
1587
|
+
// registering/unregistering anything. Notify observers so an open composer
|
|
1588
|
+
// refetches instead of showing a stale command until reload.
|
|
1589
|
+
try { ctx.emit?.('commands/change'); } catch { /* event surface may differ */ }
|
|
1590
|
+
try { ctx.get?.('commands')?.emit?.('commands/change'); } catch { /* best effort */ }
|
|
1435
1591
|
return stateFor({ workspaceId: level === 'workspace' ? id : undefined, sessionId: level === 'session' ? id : undefined });
|
|
1436
1592
|
}
|
|
1437
1593
|
|
|
@@ -1605,7 +1761,7 @@ function makeService(ctx) {
|
|
|
1605
1761
|
throw new Error(`unknown op ${op}`);
|
|
1606
1762
|
}
|
|
1607
1763
|
|
|
1608
|
-
return { collectObserved, rowsCached, stateFor, setValue, handleRequest, hiddenByName, installResolveFilter, installSectionFilter, installSkillFilter, installStreamFilter, installComposeMount };
|
|
1764
|
+
return { collectObserved, rowsCached, stateFor, setValue, handleRequest, hiddenByName, installResolveFilter, installSectionFilter, installCommandFilter, installSkillFilter, installStreamFilter, installComposeMount };
|
|
1609
1765
|
}
|
|
1610
1766
|
|
|
1611
1767
|
export function apply(ctx) {
|
|
@@ -1617,6 +1773,7 @@ export function apply(ctx) {
|
|
|
1617
1773
|
}
|
|
1618
1774
|
try {
|
|
1619
1775
|
service.installSectionFilter();
|
|
1776
|
+
try { service.installCommandFilter(); } catch { /* keep the plugin usable even if command filtering cannot be installed */ }
|
|
1620
1777
|
} catch {
|
|
1621
1778
|
/* keep the plugin usable even if prompt filtering cannot be installed */
|
|
1622
1779
|
}
|