Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plugins/openclaw/extra-message-policy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ transcripts or backups, or prove complete deletion from those systems.

`discordChannelScopes` contains `{accountId, guildId, channelIds, agentIds?}` entries.
It is an admission boundary before mutable policy rules, commands, raw sinks and
model dispatch. Exact roots and native parent metadata for their threads are
model dispatch. The final `before_agent_run` defense targets only explicit
`agentIds`; unrelated agents do not need a guild/cache at that late hook. Positively
identified native DM contexts stay outside guild scopes; missing guild alone does
not identify a DM. Exact roots and native parent metadata for their threads are
admitted. Missing provenance fails closed for protected agents/accounts. Keep
`includeThreadStarter:false`, `historyLimit:0` and thread parent-session inheritance
disabled in native configuration. Automatic quote/starter/forward contexts without
Expand Down
5 changes: 4 additions & 1 deletion plugins/openclaw/extra-message-policy/channel-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export function scopeRoute(event = {}, ctx = {}) {
}
export function activeChannelScope(scopes = [], event = {}, ctx = {}) {
const route = scopeRoute(event, ctx);
const session = value(ctx.sessionKey, ctx.SessionKey, event.sessionKey, event.SessionKey);
const knownDirect = ctx.ChatType === 'direct' || event.ChatType === 'direct' ||
/^agent:[^:]+:discord:direct:[^:]+$/.test(session);
return scopes.find(scope => scope.agentIds.includes(route.agentId) ||
(route.accountId === scope.accountId && (!route.guildId || route.guildId === scope.guildId)));
(!knownDirect && route.accountId === scope.accountId && (!route.guildId || route.guildId === scope.guildId)));
}
const externalKeys = new Set([
'ReplyToId', 'ReplyToIdFull', 'ReplyToBody', 'ReplyToSender', 'ReplyToIsQuote', 'replyToId', 'replyToIdFull', 'replyToBody', 'replyToSender', 'replyToIsQuote',
Expand Down
2 changes: 1 addition & 1 deletion plugins/openclaw/extra-message-policy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestdevlab/openclaw-plugin-extra-message-policy",
"version": "0.1.9",
"version": "0.1.10",
"private": false,
"type": "module",
"description": "OpenClaw plugin for cross-platform message ingest, response policy, and zero-embedding raw recall.",
Expand Down
3 changes: 3 additions & 0 deletions plugins/openclaw/extra-message-policy/plugin-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,9 @@ export function registerExtraMessagePolicy(api, options = {}) {
}, { priority: 1000 });

api.on("before_agent_run", async (event, ctx) => {
// Final-model hooks do not guarantee guild metadata or an earlier route cache.
// Only explicitly isolated agents carry this final fail-closed defense.
if (!cfg.discordChannelScopes.some(scope => scope.agentIds.includes(scopeRoute(event, ctx).agentId))) return;
const admission = await checkScope(event, ctx);
if (admission.protected && !admission.allowed) return {
outcome: "block", reason: "Discord channel scope could not be verified",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ test('invalid mandatory config fails startup rather than silently dropping the s
test('later opt-out excludes even previously admitted raw records',()=>{
assert.equal(admittedRecallRecord({...base,channelScopeAdmission:1,senderId:'400'},scopes,{agentId:'isolated'},{public:['400']}),false);
});
test('only positively identified direct contexts bypass guild admission',()=>{
assert.equal(admitChannelScope(scopes,{accountId:'public',content:'DM'}, {ChatType:'direct'}).protected,false);
assert.equal(admitChannelScope(scopes,{accountId:'public',content:'DM'}, {sessionKey:'agent:legacy:discord:direct:400'}).protected,false);
assert.equal(admitChannelScope(scopes,{accountId:'public',content:'ambiguous',isGroup:false},{}).allowed,false);
assert.equal(admitChannelScope(scopes,{accountId:'public',content:'ambiguous'},{agentId:'isolated',ChatType:'direct'}).allowed,false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2464,3 +2464,12 @@ test('native provider contexts retain numeric sink provenance and support later
assert.equal(await harness.emit('before_agent_run',{accountId,channelId:lab.channelId},{...lab,guildId:undefined}),undefined);
assert.equal((await harness.emit('before_agent_run',{accountId:'other',channelId},{agentId:'isolated',sessionKey:`agent:isolated:discord:channel:${channelId}`})).outcome,'block');
});
test('uncached unrelated agent final hooks pass with SecretRef while isolated agents fail closed',async()=>{
const accountId='public',channelId='222222222222222222';
const harness=await createHarness({discordChannelScopes:[{accountId,guildId:'111111111111111111',channelIds:[channelId],agentIds:['isolated']}]},{channels:{discord:{accounts:{public:{token:{source:'env',provider:'default',id:'TEST_TOKEN_REFERENCE'}}}}}});
const event={accountId,channelId,prompt:'current request'};
assert.equal(await harness.emit('before_agent_run',event,{accountId,channelId,agentId:'lab',sessionKey:`agent:lab:discord:channel:${channelId}`}),undefined);
assert.equal((await harness.emit('before_agent_run',event,{accountId,channelId,agentId:'isolated',sessionKey:`agent:isolated:discord:channel:${channelId}`})).outcome,'block');
const outside={accountId,guildId:'111111111111111111',channelId:'333333333333333333',content:'/help'};
assert.deepEqual(await harness.emit('inbound_claim',outside,{accountId,channelId:outside.channelId}),{handled:true});
});
Loading