Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
540d85c316 | ||
|
|
40f0a80208 |
No files matched your search
+1
-1
@@ -8,6 +8,7 @@ Docs: https://docs.clawd.bot
|
|||||||
- Highlight: Lobster optional plugin tool for typed workflows + approval gates. https://docs.clawd.bot/tools/lobster
|
- Highlight: Lobster optional plugin tool for typed workflows + approval gates. https://docs.clawd.bot/tools/lobster
|
||||||
- Lobster: allow workflow file args via `argsJson` in the plugin tool. https://docs.clawd.bot/tools/lobster
|
- Lobster: allow workflow file args via `argsJson` in the plugin tool. https://docs.clawd.bot/tools/lobster
|
||||||
- Agents: add identity avatar config support and Control UI avatar rendering. (#1329, #1424) Thanks @dlauer.
|
- Agents: add identity avatar config support and Control UI avatar rendering. (#1329, #1424) Thanks @dlauer.
|
||||||
|
- Slack: add chat-type reply threading overrides via `replyToModeByChatType`. (#1442) Thanks @stefangalescu.
|
||||||
- Memory: prevent CLI hangs by deferring vector probes, adding sqlite-vec/embedding timeouts, and showing sync progress early.
|
- Memory: prevent CLI hangs by deferring vector probes, adding sqlite-vec/embedding timeouts, and showing sync progress early.
|
||||||
- BlueBubbles: add `asVoice` support for MP3/CAF voice memos in sendAttachment. (#1477, #1482) Thanks @Nicell.
|
- BlueBubbles: add `asVoice` support for MP3/CAF voice memos in sendAttachment. (#1477, #1482) Thanks @Nicell.
|
||||||
- Docs: add troubleshooting entry for gateway.mode blocking gateway start. https://docs.clawd.bot/gateway/troubleshooting
|
- Docs: add troubleshooting entry for gateway.mode blocking gateway start. https://docs.clawd.bot/gateway/troubleshooting
|
||||||
@@ -34,7 +35,6 @@ Docs: https://docs.clawd.bot
|
|||||||
- Doctor: honor CLAWDBOT_GATEWAY_TOKEN for auth checks and security audit token reuse. (#1448) Thanks @azade-c.
|
- Doctor: honor CLAWDBOT_GATEWAY_TOKEN for auth checks and security audit token reuse. (#1448) Thanks @azade-c.
|
||||||
- Agents: make tool summaries more readable and only show optional params when set.
|
- Agents: make tool summaries more readable and only show optional params when set.
|
||||||
- Agents: honor SOUL.md guidance even when the file is nested or path-qualified. (#1434) Thanks @neooriginal.
|
- Agents: honor SOUL.md guidance even when the file is nested or path-qualified. (#1434) Thanks @neooriginal.
|
||||||
- Matrix (plugin): persist m.direct for resolved DMs and harden room fallback. (#1436) Thanks @sibbl.
|
|
||||||
- CLI: prefer `~` for home paths in output.
|
- CLI: prefer `~` for home paths in output.
|
||||||
- Mattermost (plugin): enforce pairing/allowlist gating, keep @username targets, and clarify plugin-only docs. (#1428) Thanks @damoahdominic.
|
- Mattermost (plugin): enforce pairing/allowlist gating, keep @username targets, and clarify plugin-only docs. (#1428) Thanks @damoahdominic.
|
||||||
- Agents: centralize transcript sanitization in the runner; keep <final> tags and error turns intact.
|
- Agents: centralize transcript sanitization in the runner; keep <final> tags and error turns intact.
|
||||||
|
|||||||
@@ -362,23 +362,24 @@ By default, Clawdbot replies in the main channel. Use `channels.slack.replyToMod
|
|||||||
|
|
||||||
The mode applies to both auto-replies and agent tool calls (`slack sendMessage`).
|
The mode applies to both auto-replies and agent tool calls (`slack sendMessage`).
|
||||||
|
|
||||||
### DM-specific threading
|
### Per-chat-type threading
|
||||||
You can configure different threading behavior for DMs vs channels by setting `channels.slack.dm.replyToMode`:
|
You can configure different threading behavior per chat type by setting `channels.slack.replyToModeByChatType`:
|
||||||
|
|
||||||
```json5
|
```json5
|
||||||
{
|
{
|
||||||
channels: {
|
channels: {
|
||||||
slack: {
|
slack: {
|
||||||
replyToMode: "off", // default for channels
|
replyToMode: "off", // default for channels
|
||||||
dm: {
|
replyToModeByChatType: {
|
||||||
replyToMode: "all" // DMs always thread
|
direct: "all", // DMs always thread
|
||||||
}
|
group: "first" // group DMs/MPIM thread first reply
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
When `dm.replyToMode` is set, DMs use that mode; channels use the top-level `replyToMode`. If `dm.replyToMode` is not set, both DMs and channels use the top-level setting.
|
When a chat-type override is set, it takes precedence for that chat type. Otherwise the top-level `replyToMode` is used.
|
||||||
|
|
||||||
### Manual threading tags
|
### Manual threading tags
|
||||||
For fine-grained control, use these tags in agent responses:
|
For fine-grained control, use these tags in agent responses:
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export async function resolveMatrixAuth(params?: {
|
|||||||
saveMatrixCredentials,
|
saveMatrixCredentials,
|
||||||
credentialsMatchConfig,
|
credentialsMatchConfig,
|
||||||
touchMatrixCredentials,
|
touchMatrixCredentials,
|
||||||
} = await import("../credentials.js");
|
} = await import("./credentials.js");
|
||||||
|
|
||||||
const cached = loadMatrixCredentials(env);
|
const cached = loadMatrixCredentials(env);
|
||||||
const cachedCredentials =
|
const cachedCredentials =
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
import type { MatrixClient } from "matrix-bot-sdk";
|
|
||||||
import { EventType } from "./types.js";
|
|
||||||
|
|
||||||
let resolveMatrixRoomId: typeof import("./targets.js").resolveMatrixRoomId;
|
|
||||||
let normalizeThreadId: typeof import("./targets.js").normalizeThreadId;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.resetModules();
|
|
||||||
({ resolveMatrixRoomId, normalizeThreadId } = await import("./targets.js"));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("resolveMatrixRoomId", () => {
|
|
||||||
it("uses m.direct when available", async () => {
|
|
||||||
const userId = "@user:example.org";
|
|
||||||
const client = {
|
|
||||||
getAccountData: vi.fn().mockResolvedValue({
|
|
||||||
[userId]: ["!room:example.org"],
|
|
||||||
}),
|
|
||||||
getJoinedRooms: vi.fn(),
|
|
||||||
getJoinedRoomMembers: vi.fn(),
|
|
||||||
setAccountData: vi.fn(),
|
|
||||||
} as unknown as MatrixClient;
|
|
||||||
|
|
||||||
const roomId = await resolveMatrixRoomId(client, userId);
|
|
||||||
|
|
||||||
expect(roomId).toBe("!room:example.org");
|
|
||||||
expect(client.getJoinedRooms).not.toHaveBeenCalled();
|
|
||||||
expect(client.setAccountData).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("falls back to joined rooms and persists m.direct", async () => {
|
|
||||||
const userId = "@fallback:example.org";
|
|
||||||
const roomId = "!room:example.org";
|
|
||||||
const setAccountData = vi.fn().mockResolvedValue(undefined);
|
|
||||||
const client = {
|
|
||||||
getAccountData: vi.fn().mockRejectedValue(new Error("nope")),
|
|
||||||
getJoinedRooms: vi.fn().mockResolvedValue([roomId]),
|
|
||||||
getJoinedRoomMembers: vi.fn().mockResolvedValue([
|
|
||||||
"@bot:example.org",
|
|
||||||
userId,
|
|
||||||
]),
|
|
||||||
setAccountData,
|
|
||||||
} as unknown as MatrixClient;
|
|
||||||
|
|
||||||
const resolved = await resolveMatrixRoomId(client, userId);
|
|
||||||
|
|
||||||
expect(resolved).toBe(roomId);
|
|
||||||
expect(setAccountData).toHaveBeenCalledWith(
|
|
||||||
EventType.Direct,
|
|
||||||
expect.objectContaining({ [userId]: [roomId] }),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("continues when a room member lookup fails", async () => {
|
|
||||||
const userId = "@continue:example.org";
|
|
||||||
const roomId = "!good:example.org";
|
|
||||||
const setAccountData = vi.fn().mockResolvedValue(undefined);
|
|
||||||
const getJoinedRoomMembers = vi
|
|
||||||
.fn()
|
|
||||||
.mockRejectedValueOnce(new Error("boom"))
|
|
||||||
.mockResolvedValueOnce(["@bot:example.org", userId]);
|
|
||||||
const client = {
|
|
||||||
getAccountData: vi.fn().mockRejectedValue(new Error("nope")),
|
|
||||||
getJoinedRooms: vi.fn().mockResolvedValue(["!bad:example.org", roomId]),
|
|
||||||
getJoinedRoomMembers,
|
|
||||||
setAccountData,
|
|
||||||
} as unknown as MatrixClient;
|
|
||||||
|
|
||||||
const resolved = await resolveMatrixRoomId(client, userId);
|
|
||||||
|
|
||||||
expect(resolved).toBe(roomId);
|
|
||||||
expect(setAccountData).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("allows larger rooms when no 1:1 match exists", async () => {
|
|
||||||
const userId = "@group:example.org";
|
|
||||||
const roomId = "!group:example.org";
|
|
||||||
const client = {
|
|
||||||
getAccountData: vi.fn().mockRejectedValue(new Error("nope")),
|
|
||||||
getJoinedRooms: vi.fn().mockResolvedValue([roomId]),
|
|
||||||
getJoinedRoomMembers: vi.fn().mockResolvedValue([
|
|
||||||
"@bot:example.org",
|
|
||||||
userId,
|
|
||||||
"@extra:example.org",
|
|
||||||
]),
|
|
||||||
setAccountData: vi.fn().mockResolvedValue(undefined),
|
|
||||||
} as unknown as MatrixClient;
|
|
||||||
|
|
||||||
const resolved = await resolveMatrixRoomId(client, userId);
|
|
||||||
|
|
||||||
expect(resolved).toBe(roomId);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("normalizeThreadId", () => {
|
|
||||||
it("returns null for empty thread ids", () => {
|
|
||||||
expect(normalizeThreadId(" ")).toBeNull();
|
|
||||||
expect(normalizeThreadId("$thread")).toBe("$thread");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -16,100 +16,22 @@ export function normalizeThreadId(raw?: string | number | null): string | null {
|
|||||||
return trimmed ? trimmed : null;
|
return trimmed ? trimmed : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const directRoomCache = new Map<string, string>();
|
async function resolveDirectRoomId(client: MatrixClient, userId: string): Promise<string> {
|
||||||
|
|
||||||
async function persistDirectRoom(
|
|
||||||
client: MatrixClient,
|
|
||||||
userId: string,
|
|
||||||
roomId: string,
|
|
||||||
): Promise<void> {
|
|
||||||
let directContent: MatrixDirectAccountData | null = null;
|
|
||||||
try {
|
|
||||||
directContent = (await client.getAccountData(
|
|
||||||
EventType.Direct,
|
|
||||||
)) as MatrixDirectAccountData | null;
|
|
||||||
} catch {
|
|
||||||
// Ignore fetch errors and fall back to an empty map.
|
|
||||||
}
|
|
||||||
const existing =
|
|
||||||
directContent && !Array.isArray(directContent) ? directContent : {};
|
|
||||||
const current = Array.isArray(existing[userId]) ? existing[userId] : [];
|
|
||||||
if (current[0] === roomId) return;
|
|
||||||
const next = [roomId, ...current.filter((id) => id !== roomId)];
|
|
||||||
try {
|
|
||||||
await client.setAccountData(EventType.Direct, {
|
|
||||||
...existing,
|
|
||||||
[userId]: next,
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// Ignore persistence errors.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveDirectRoomId(
|
|
||||||
client: MatrixClient,
|
|
||||||
userId: string,
|
|
||||||
): Promise<string> {
|
|
||||||
const trimmed = userId.trim();
|
const trimmed = userId.trim();
|
||||||
if (!trimmed.startsWith("@")) {
|
if (!trimmed.startsWith("@")) {
|
||||||
throw new Error(
|
throw new Error(`Matrix user IDs must be fully qualified (got "${trimmed}")`);
|
||||||
`Matrix user IDs must be fully qualified (got "${trimmed}")`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// matrix-bot-sdk: use getAccountData to retrieve m.direct
|
||||||
const cached = directRoomCache.get(trimmed);
|
|
||||||
if (cached) return cached;
|
|
||||||
|
|
||||||
// 1) Fast path: use account data (m.direct) for *this* logged-in user (the bot).
|
|
||||||
try {
|
try {
|
||||||
const directContent = (await client.getAccountData(
|
const directContent = await client.getAccountData(EventType.Direct) as MatrixDirectAccountData | null;
|
||||||
EventType.Direct,
|
const list = Array.isArray(directContent?.[trimmed]) ? directContent[trimmed] : [];
|
||||||
)) as MatrixDirectAccountData | null;
|
if (list.length > 0) return list[0];
|
||||||
const list = Array.isArray(directContent?.[trimmed])
|
|
||||||
? directContent[trimmed]
|
|
||||||
: [];
|
|
||||||
if (list.length > 0) {
|
|
||||||
directRoomCache.set(trimmed, list[0]);
|
|
||||||
return list[0];
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore and fall back.
|
// Ignore errors, try fetching from server
|
||||||
}
|
}
|
||||||
|
throw new Error(
|
||||||
// 2) Fallback: look for an existing joined room that looks like a 1:1 with the user.
|
`No m.direct room found for ${trimmed}. Open a DM first so Matrix can set m.direct.`,
|
||||||
// Many clients only maintain m.direct for *their own* account data, so relying on it is brittle.
|
);
|
||||||
let fallbackRoom: string | null = null;
|
|
||||||
try {
|
|
||||||
const rooms = await client.getJoinedRooms();
|
|
||||||
for (const roomId of rooms) {
|
|
||||||
let members: string[];
|
|
||||||
try {
|
|
||||||
members = await client.getJoinedRoomMembers(roomId);
|
|
||||||
} catch {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!members.includes(trimmed)) continue;
|
|
||||||
// Prefer classic 1:1 rooms, but allow larger rooms if requested.
|
|
||||||
if (members.length === 2) {
|
|
||||||
directRoomCache.set(trimmed, roomId);
|
|
||||||
await persistDirectRoom(client, trimmed, roomId);
|
|
||||||
return roomId;
|
|
||||||
}
|
|
||||||
if (!fallbackRoom) {
|
|
||||||
fallbackRoom = roomId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Ignore and fall back.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fallbackRoom) {
|
|
||||||
directRoomCache.set(trimmed, fallbackRoom);
|
|
||||||
await persistDirectRoom(client, trimmed, fallbackRoom);
|
|
||||||
return fallbackRoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`No direct room found for ${trimmed} (m.direct missing)`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolveMatrixRoomId(
|
export async function resolveMatrixRoomId(
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ TRASH
|
|||||||
local needle="$1"
|
local needle="$1"
|
||||||
local timeout_s="${2:-45}"
|
local timeout_s="${2:-45}"
|
||||||
local needle_compact
|
local needle_compact
|
||||||
needle_compact="$(printf "%s" "$needle" | tr -cd "[:alnum:]")"
|
needle_compact="$(printf "%s" "$needle" | sed -E "s/[[:space:]]+//g")"
|
||||||
local start_s
|
local start_s
|
||||||
start_s="$(date +%s)"
|
start_s="$(date +%s)"
|
||||||
while true; do
|
while true; do
|
||||||
@@ -61,12 +61,17 @@ TRASH
|
|||||||
let text = \"\";
|
let text = \"\";
|
||||||
try { text = fs.readFileSync(file, \"utf8\"); } catch { process.exit(1); }
|
try { text = fs.readFileSync(file, \"utf8\"); } catch { process.exit(1); }
|
||||||
if (text.length > 20000) text = text.slice(-20000);
|
if (text.length > 20000) text = text.slice(-20000);
|
||||||
const stripAnsi = (value) => value.replace(/\\x1b\\[[0-9;]*[A-Za-z]/g, \"\");
|
const sanitize = (value) => value.replace(/[\\x00-\\x1f\\x7f]/g, \"\");
|
||||||
const compact = (value) => stripAnsi(value).toLowerCase().replace(/[^a-z0-9]+/g, \"\");
|
const haystack = sanitize(text);
|
||||||
const haystack = compact(text);
|
const safeNeedle = sanitize(needle);
|
||||||
const compactNeedle = compact(needle);
|
const needsEscape = new Set([\"\\\\\", \"^\", \"$\", \".\", \"*\", \"+\", \"?\", \"(\", \")\", \"[\", \"]\", \"{\", \"}\", \"|\"]);
|
||||||
if (!compactNeedle) process.exit(1);
|
let escaped = \"\";
|
||||||
process.exit(haystack.includes(compactNeedle) ? 0 : 1);
|
for (const ch of safeNeedle) {
|
||||||
|
escaped += needsEscape.has(ch) ? \"\\\\\" + ch : ch;
|
||||||
|
}
|
||||||
|
const pattern = escaped.split(\"\").join(\".*\");
|
||||||
|
const re = new RegExp(pattern, \"i\");
|
||||||
|
process.exit(re.test(haystack) ? 0 : 1);
|
||||||
"; then
|
"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -255,11 +260,9 @@ TRASH
|
|||||||
|
|
||||||
send_skills_flow() {
|
send_skills_flow() {
|
||||||
# Select skills section and skip optional installs.
|
# Select skills section and skip optional installs.
|
||||||
wait_for_log "Where will the Gateway run?" 60 || true
|
send $'"'"'\r'"'"' 1.2
|
||||||
send $'"'"'\r'"'"' 0.6
|
|
||||||
# Configure skills now? -> No
|
# Configure skills now? -> No
|
||||||
wait_for_log "Configure skills now?" 60 || true
|
send $'"'"'n\r'"'"' 1.5
|
||||||
send $'"'"'n\r'"'"' 0.8
|
|
||||||
send "" 1.0
|
send "" 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,26 +32,26 @@ describe("resolveReplyToMode", () => {
|
|||||||
expect(resolveReplyToMode(cfg, "slack")).toBe("all");
|
expect(resolveReplyToMode(cfg, "slack")).toBe("all");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses dm-specific replyToMode for Slack DMs when configured", () => {
|
it("uses chat-type replyToMode overrides for Slack when configured", () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: {
|
channels: {
|
||||||
slack: {
|
slack: {
|
||||||
replyToMode: "off",
|
replyToMode: "off",
|
||||||
dm: { replyToMode: "all" },
|
replyToModeByChatType: { direct: "all", group: "first" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ClawdbotConfig;
|
} as ClawdbotConfig;
|
||||||
expect(resolveReplyToMode(cfg, "slack", null, "direct")).toBe("all");
|
expect(resolveReplyToMode(cfg, "slack", null, "direct")).toBe("all");
|
||||||
|
expect(resolveReplyToMode(cfg, "slack", null, "group")).toBe("first");
|
||||||
expect(resolveReplyToMode(cfg, "slack", null, "channel")).toBe("off");
|
expect(resolveReplyToMode(cfg, "slack", null, "channel")).toBe("off");
|
||||||
expect(resolveReplyToMode(cfg, "slack", null, undefined)).toBe("off");
|
expect(resolveReplyToMode(cfg, "slack", null, undefined)).toBe("off");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to top-level replyToMode when dm.replyToMode is not configured", () => {
|
it("falls back to top-level replyToMode when no chat-type override is set", () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: {
|
channels: {
|
||||||
slack: {
|
slack: {
|
||||||
replyToMode: "first",
|
replyToMode: "first",
|
||||||
dm: { enabled: true },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ClawdbotConfig;
|
} as ClawdbotConfig;
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ export type SlackDmConfig = {
|
|||||||
groupEnabled?: boolean;
|
groupEnabled?: boolean;
|
||||||
/** Optional allowlist for group DM channels (ids or slugs). */
|
/** Optional allowlist for group DM channels (ids or slugs). */
|
||||||
groupChannels?: Array<string | number>;
|
groupChannels?: Array<string | number>;
|
||||||
/** Control reply threading for DMs (off|first|all). Overrides top-level replyToMode for DMs. */
|
|
||||||
replyToMode?: ReplyToMode;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SlackChannelConfig = {
|
export type SlackChannelConfig = {
|
||||||
@@ -119,6 +117,11 @@ export type SlackAccountConfig = {
|
|||||||
reactionAllowlist?: Array<string | number>;
|
reactionAllowlist?: Array<string | number>;
|
||||||
/** Control reply threading when reply tags are present (off|first|all). */
|
/** Control reply threading when reply tags are present (off|first|all). */
|
||||||
replyToMode?: ReplyToMode;
|
replyToMode?: ReplyToMode;
|
||||||
|
/**
|
||||||
|
* Optional per-chat-type reply threading overrides.
|
||||||
|
* Example: { direct: "all", group: "first", channel: "off" }.
|
||||||
|
*/
|
||||||
|
replyToModeByChatType?: Partial<Record<"direct" | "group" | "channel", ReplyToMode>>;
|
||||||
/** Thread session behavior. */
|
/** Thread session behavior. */
|
||||||
thread?: SlackThreadConfig;
|
thread?: SlackThreadConfig;
|
||||||
actions?: SlackActionConfig;
|
actions?: SlackActionConfig;
|
||||||
|
|||||||
@@ -280,6 +280,14 @@ export const SlackThreadSchema = z
|
|||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
|
const SlackReplyToModeByChatTypeSchema = z
|
||||||
|
.object({
|
||||||
|
direct: ReplyToModeSchema.optional(),
|
||||||
|
group: ReplyToModeSchema.optional(),
|
||||||
|
channel: ReplyToModeSchema.optional(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
export const SlackAccountSchema = z
|
export const SlackAccountSchema = z
|
||||||
.object({
|
.object({
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
@@ -307,6 +315,7 @@ export const SlackAccountSchema = z
|
|||||||
reactionNotifications: z.enum(["off", "own", "all", "allowlist"]).optional(),
|
reactionNotifications: z.enum(["off", "own", "all", "allowlist"]).optional(),
|
||||||
reactionAllowlist: z.array(z.union([z.string(), z.number()])).optional(),
|
reactionAllowlist: z.array(z.union([z.string(), z.number()])).optional(),
|
||||||
replyToMode: ReplyToModeSchema.optional(),
|
replyToMode: ReplyToModeSchema.optional(),
|
||||||
|
replyToModeByChatType: SlackReplyToModeByChatTypeSchema.optional(),
|
||||||
thread: SlackThreadSchema.optional(),
|
thread: SlackThreadSchema.optional(),
|
||||||
actions: z
|
actions: z
|
||||||
.object({
|
.object({
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
import type { SlackAccountConfig } from "../config/types.js";
|
import type { SlackAccountConfig } from "../config/types.js";
|
||||||
|
import { normalizeChatType } from "../channels/chat-type.js";
|
||||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||||
import { resolveSlackAppToken, resolveSlackBotToken } from "./token.js";
|
import { resolveSlackAppToken, resolveSlackBotToken } from "./token.js";
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ export type ResolvedSlackAccount = {
|
|||||||
reactionNotifications?: SlackAccountConfig["reactionNotifications"];
|
reactionNotifications?: SlackAccountConfig["reactionNotifications"];
|
||||||
reactionAllowlist?: SlackAccountConfig["reactionAllowlist"];
|
reactionAllowlist?: SlackAccountConfig["reactionAllowlist"];
|
||||||
replyToMode?: SlackAccountConfig["replyToMode"];
|
replyToMode?: SlackAccountConfig["replyToMode"];
|
||||||
|
replyToModeByChatType?: SlackAccountConfig["replyToModeByChatType"];
|
||||||
actions?: SlackAccountConfig["actions"];
|
actions?: SlackAccountConfig["actions"];
|
||||||
slashCommand?: SlackAccountConfig["slashCommand"];
|
slashCommand?: SlackAccountConfig["slashCommand"];
|
||||||
dm?: SlackAccountConfig["dm"];
|
dm?: SlackAccountConfig["dm"];
|
||||||
@@ -95,6 +97,7 @@ export function resolveSlackAccount(params: {
|
|||||||
reactionNotifications: merged.reactionNotifications,
|
reactionNotifications: merged.reactionNotifications,
|
||||||
reactionAllowlist: merged.reactionAllowlist,
|
reactionAllowlist: merged.reactionAllowlist,
|
||||||
replyToMode: merged.replyToMode,
|
replyToMode: merged.replyToMode,
|
||||||
|
replyToModeByChatType: merged.replyToModeByChatType,
|
||||||
actions: merged.actions,
|
actions: merged.actions,
|
||||||
slashCommand: merged.slashCommand,
|
slashCommand: merged.slashCommand,
|
||||||
dm: merged.dm,
|
dm: merged.dm,
|
||||||
@@ -112,8 +115,10 @@ export function resolveSlackReplyToMode(
|
|||||||
account: ResolvedSlackAccount,
|
account: ResolvedSlackAccount,
|
||||||
chatType?: string | null,
|
chatType?: string | null,
|
||||||
): "off" | "first" | "all" {
|
): "off" | "first" | "all" {
|
||||||
if (chatType === "direct" && account.dm?.replyToMode !== undefined) {
|
const normalized = normalizeChatType(chatType ?? undefined);
|
||||||
return account.dm.replyToMode;
|
const overrides = account.replyToModeByChatType;
|
||||||
|
if (normalized && overrides && overrides[normalized] !== undefined) {
|
||||||
|
return overrides[normalized] ?? "off";
|
||||||
}
|
}
|
||||||
return account.replyToMode ?? "off";
|
return account.replyToMode ?? "off";
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,6 @@ export type SlackThreadStarter = {
|
|||||||
text: string;
|
text: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
ts?: string;
|
ts?: string;
|
||||||
files?: SlackFile[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const THREAD_STARTER_CACHE = new Map<string, SlackThreadStarter>();
|
const THREAD_STARTER_CACHE = new Map<string, SlackThreadStarter>();
|
||||||
@@ -72,7 +71,7 @@ export async function resolveSlackThreadStarter(params: {
|
|||||||
ts: params.threadTs,
|
ts: params.threadTs,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
inclusive: true,
|
inclusive: true,
|
||||||
})) as { messages?: Array<{ text?: string; user?: string; ts?: string; files?: SlackFile[] }> };
|
})) as { messages?: Array<{ text?: string; user?: string; ts?: string }> };
|
||||||
const message = response?.messages?.[0];
|
const message = response?.messages?.[0];
|
||||||
const text = (message?.text ?? "").trim();
|
const text = (message?.text ?? "").trim();
|
||||||
if (!message || !text) return null;
|
if (!message || !text) return null;
|
||||||
@@ -80,7 +79,6 @@ export async function resolveSlackThreadStarter(params: {
|
|||||||
text,
|
text,
|
||||||
userId: message.user,
|
userId: message.user,
|
||||||
ts: message.ts,
|
ts: message.ts,
|
||||||
files: message.files,
|
|
||||||
};
|
};
|
||||||
THREAD_STARTER_CACHE.set(cacheKey, starter);
|
THREAD_STARTER_CACHE.set(cacheKey, starter);
|
||||||
return starter;
|
return starter;
|
||||||
|
|||||||
@@ -434,7 +434,6 @@ export async function prepareSlackMessage(params: {
|
|||||||
|
|
||||||
let threadStarterBody: string | undefined;
|
let threadStarterBody: string | undefined;
|
||||||
let threadLabel: string | undefined;
|
let threadLabel: string | undefined;
|
||||||
let threadStarterMedia: Awaited<ReturnType<typeof resolveSlackMedia>> = null;
|
|
||||||
if (isThreadReply && threadTs) {
|
if (isThreadReply && threadTs) {
|
||||||
const starter = await resolveSlackThreadStarter({
|
const starter = await resolveSlackThreadStarter({
|
||||||
channelId: message.channel,
|
channelId: message.channel,
|
||||||
@@ -454,27 +453,11 @@ export async function prepareSlackMessage(params: {
|
|||||||
});
|
});
|
||||||
const snippet = starter.text.replace(/\s+/g, " ").slice(0, 80);
|
const snippet = starter.text.replace(/\s+/g, " ").slice(0, 80);
|
||||||
threadLabel = `Slack thread ${roomLabel}${snippet ? `: ${snippet}` : ""}`;
|
threadLabel = `Slack thread ${roomLabel}${snippet ? `: ${snippet}` : ""}`;
|
||||||
// If current message has no files but thread starter does, fetch starter's files
|
|
||||||
if (!media && starter.files && starter.files.length > 0) {
|
|
||||||
threadStarterMedia = await resolveSlackMedia({
|
|
||||||
files: starter.files,
|
|
||||||
token: ctx.botToken,
|
|
||||||
maxBytes: ctx.mediaMaxBytes,
|
|
||||||
});
|
|
||||||
if (threadStarterMedia) {
|
|
||||||
logVerbose(
|
|
||||||
`slack: hydrated thread starter file ${threadStarterMedia.placeholder} from root message`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
threadLabel = `Slack thread ${roomLabel}`;
|
threadLabel = `Slack thread ${roomLabel}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use thread starter media if current message has none
|
|
||||||
const effectiveMedia = media ?? threadStarterMedia;
|
|
||||||
|
|
||||||
const ctxPayload = finalizeInboundContext({
|
const ctxPayload = finalizeInboundContext({
|
||||||
Body: combinedBody,
|
Body: combinedBody,
|
||||||
RawBody: rawBody,
|
RawBody: rawBody,
|
||||||
@@ -500,9 +483,9 @@ export async function prepareSlackMessage(params: {
|
|||||||
ThreadLabel: threadLabel,
|
ThreadLabel: threadLabel,
|
||||||
Timestamp: message.ts ? Math.round(Number(message.ts) * 1000) : undefined,
|
Timestamp: message.ts ? Math.round(Number(message.ts) * 1000) : undefined,
|
||||||
WasMentioned: isRoomish ? effectiveWasMentioned : undefined,
|
WasMentioned: isRoomish ? effectiveWasMentioned : undefined,
|
||||||
MediaPath: effectiveMedia?.path,
|
MediaPath: media?.path,
|
||||||
MediaType: effectiveMedia?.contentType,
|
MediaType: media?.contentType,
|
||||||
MediaUrl: effectiveMedia?.path,
|
MediaUrl: media?.path,
|
||||||
CommandAuthorized: commandAuthorized,
|
CommandAuthorized: commandAuthorized,
|
||||||
OriginatingChannel: "slack" as const,
|
OriginatingChannel: "slack" as const,
|
||||||
OriginatingTo: slackTo,
|
OriginatingTo: slackTo,
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ describe("buildSlackThreadingToolContext", () => {
|
|||||||
expect(result.replyToMode).toBe("first");
|
expect(result.replyToMode).toBe("first");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses dm.replyToMode for direct messages when configured", () => {
|
it("uses chat-type replyToMode overrides for direct messages when configured", () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: {
|
channels: {
|
||||||
slack: {
|
slack: {
|
||||||
replyToMode: "off",
|
replyToMode: "off",
|
||||||
dm: { replyToMode: "all" },
|
replyToModeByChatType: { direct: "all" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ClawdbotConfig;
|
} as ClawdbotConfig;
|
||||||
@@ -37,12 +37,12 @@ describe("buildSlackThreadingToolContext", () => {
|
|||||||
expect(result.replyToMode).toBe("all");
|
expect(result.replyToMode).toBe("all");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses top-level replyToMode for channels even when dm.replyToMode is set", () => {
|
it("uses top-level replyToMode for channels when no channel override is set", () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: {
|
channels: {
|
||||||
slack: {
|
slack: {
|
||||||
replyToMode: "off",
|
replyToMode: "off",
|
||||||
dm: { replyToMode: "all" },
|
replyToModeByChatType: { direct: "all" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ClawdbotConfig;
|
} as ClawdbotConfig;
|
||||||
@@ -54,12 +54,11 @@ describe("buildSlackThreadingToolContext", () => {
|
|||||||
expect(result.replyToMode).toBe("off");
|
expect(result.replyToMode).toBe("off");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to top-level when dm.replyToMode is not set", () => {
|
it("falls back to top-level when no chat-type override is set", () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
channels: {
|
channels: {
|
||||||
slack: {
|
slack: {
|
||||||
replyToMode: "first",
|
replyToMode: "first",
|
||||||
dm: { enabled: true },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as ClawdbotConfig;
|
} as ClawdbotConfig;
|
||||||
|
|||||||
Reference in new issue
Block a user