Skip to content

Commit 6cf8e88

Browse files
authored
fix(line): apply a group's wildcard defaults to its own entry (#132918)
* fix(line): apply a group's wildcard defaults to its own entry * docs(line): define wildcard group inheritance and its upgrade effect
1 parent 8995aa4 commit 6cf8e88

3 files changed

Lines changed: 47 additions & 10 deletions

File tree

‎docs/channels/line.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ Allowlists and policies:
223223
- `channels.line.groupAllowFrom`: allowlisted LINE user IDs for groups; DM `allowFrom` entries do not admit group senders
224224
- Per-group overrides: `channels.line.groups.<groupId>.allowFrom` (plus `enabled`, `requireMention`, `systemPrompt`, `skills`). With
225225
`groupPolicy: "allowlist"`, set `groupAllowFrom` or the per-group `allowFrom`; an empty group allowlist blocks group messages even when DMs are open.
226+
- `channels.line.groups."*"` is the defaults entry for every group and room, not a fallback that a named entry replaces. A named entry overrides `"*"` field by field, so each field the named entry omits is taken from `"*"`. This matches how `requireMention` already resolves through the shared group scope tree; see [Groups](/channels/groups).
227+
- Upgrade check: if you set `enabled` or `allowFrom` only on `channels.line.groups."*"` while also listing a named group or room, those wildcard values now apply to that named entry as well. Earlier releases returned the named entry alone, so wildcard-only fields never reached it. Before upgrading, review any `"*"` entry that sets `enabled: false` or narrows `allowFrom`, and repeat the value on a named entry that should keep its current access.
226228
- Quoting one of the bot's own messages counts as addressing it, so a group reply made with LINE's quote gesture reaches the agent without an explicit mention. LINE does not read the `implicitMentions` flags, so this always counts; see [Groups](/channels/groups). The bot recognizes a quote of its own message from the most recent ones it remembers sending (a few hundred per account), so quoting an older message, or one sent before the last Gateway restart, still needs a mention.
227229
- Static sender access groups can be referenced from `allowFrom`, `groupAllowFrom`, and per-group `allowFrom` with `accessGroup:<name>`; see [Access groups](/channels/access-groups).
228230
- Runtime note: if `channels.line` is completely missing, runtime falls back to `groupPolicy="allowlist"` for group checks (even if `channels.defaults.groupPolicy` is set).

‎extensions/line/src/group-keys.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveLineGroupsConfig,
99
} from "./group-keys.js";
1010
import { resolveLineGroupRequireMention } from "./group-policy.js";
11+
import type { LineGroupConfig } from "./types.js";
1112

1213
describe("resolveLineGroupLookupIds", () => {
1314
it("expands raw ids to both prefixed candidates", () => {
@@ -32,12 +33,44 @@ describe("resolveLineGroupConfigEntry", () => {
3233
requireMention: false,
3334
});
3435
expect(resolveLineGroupConfigEntry(groups, { roomId: "r1" })).toEqual({
36+
requireMention: true,
3537
systemPrompt: "Room prompt",
3638
});
3739
expect(resolveLineGroupConfigEntry(groups, { groupId: "missing" })).toEqual({
3840
requireMention: true,
3941
});
4042
});
43+
44+
it("keeps the settings an operator only wrote on the wildcard", () => {
45+
// A room entry that says nothing about mentions must not silently turn the
46+
// wildcard's `requireMention: false` back into the mention-gated default.
47+
const groups = {
48+
"*": { requireMention: false, systemPrompt: "House rules" },
49+
C1: { skills: ["deploy"] },
50+
};
51+
52+
expect(resolveLineGroupConfigEntry(groups, { groupId: "C1" })).toEqual({
53+
requireMention: false,
54+
systemPrompt: "House rules",
55+
skills: ["deploy"],
56+
});
57+
});
58+
59+
it("resolves mentions the same way the channel reports them", () => {
60+
// The inbound gate reads this entry while `/status` and the turn's activation
61+
// directive read the scope tree. They answer the same question, so a room the
62+
// wildcard opened must not be gated by one and open to the other.
63+
const groups: Record<string, LineGroupConfig> = {
64+
"*": { requireMention: false },
65+
C1: { systemPrompt: "team bot" },
66+
};
67+
const cfg = { channels: { line: { groups } } } as unknown as OpenClawConfig;
68+
69+
const entry = resolveLineGroupConfigEntry(groups, { groupId: "C1" });
70+
expect(entry?.requireMention !== false).toBe(
71+
resolveLineGroupRequireMention({ cfg, accountId: null, groupId: "C1" }),
72+
);
73+
});
4174
});
4275

4376
describe("account-scoped LINE groups", () => {

‎extensions/line/src/group-keys.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@ export function resolveLineGroupLookupIds(groupId?: string | null): string[] {
1616
return [normalized, `group:${normalized}`, `room:${normalized}`];
1717
}
1818

19-
export function resolveLineGroupConfigEntry<T>(
19+
export function resolveLineGroupConfigEntry<T extends object>(
2020
groups: Record<string, T | undefined> | undefined,
2121
params: { groupId?: string | null; roomId?: string | null },
2222
): T | undefined {
2323
if (!groups) {
2424
return undefined;
2525
}
26-
for (const candidate of resolveLineGroupLookupIds(params.groupId)) {
26+
// `*` is the defaults node, not a rival entry: a room's own entry overrides it
27+
// field by field. Returning the matched entry alone would drop every setting the
28+
// operator only wrote on `*`, and would disagree with the scope-tree resolution
29+
// this channel already reports through `resolveLineGroupRequireMention`.
30+
const defaults = groups["*"];
31+
for (const candidate of [
32+
...resolveLineGroupLookupIds(params.groupId),
33+
...resolveLineGroupLookupIds(params.roomId),
34+
]) {
2735
const hit = groups[candidate];
2836
if (hit) {
29-
return hit;
37+
return defaults && defaults !== hit ? { ...defaults, ...hit } : hit;
3038
}
3139
}
32-
for (const candidate of resolveLineGroupLookupIds(params.roomId)) {
33-
const hit = groups[candidate];
34-
if (hit) {
35-
return hit;
36-
}
37-
}
38-
return groups["*"];
40+
return defaults;
3941
}
4042

4143
export function resolveLineGroupsConfig(

0 commit comments

Comments
 (0)