Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Nick: more monitoring fixes

Nicolasa0bff66bf094
diff --git a/apps/api/src/services/integrations/slack/commands.ts b/apps/api/src/services/integrations/slack/commands.ts
index 5d19f03d3..76b9196f7 100644
--- a/apps/api/src/services/integrations/slack/commands.ts
+++ b/apps/api/src/services/integrations/slack/commands.ts
@@ -41,7 +41,7 @@ function ephemeral(text: string, blocks?: unknown[]): SlackCommandResponse {
function helpResponse(): SlackCommandResponse {
const lines = [
"*Firecrawl monitor commands*",
- "`/monitor watch <url>` — start monitoring a page and post changes to this channel",
+ "`/monitor watch <url> [what to watch for]` — monitor a page in this channel; add a prompt to alert only on *meaningful* changes",
"`/monitor list` — list your team's monitors",
"`/monitor cancel <monitor-id>` — pause a monitor",
"`/monitor status` — show this workspace's Firecrawl connection",
@@ -100,18 +100,25 @@ async function listResponse(
async function watchResponse(
input: SlackSlashCommandInput,
- rawUrl: string,
+ arg: string,
): Promise<SlackCommandResponse> {
+ const trimmedArg = arg.trim();
+ // First whitespace-delimited token is the URL; everything after it is the
+ // optional prompt describing what to watch for.
+ const spaceIdx = trimmedArg.search(/\s/);
+ const rawUrl = spaceIdx === -1 ? trimmedArg : trimmedArg.slice(0, spaceIdx);
+ const goal = spaceIdx === -1 ? "" : trimmedArg.slice(spaceIdx + 1).trim();
+
let url: string;
try {
- const parsed = new URL(rawUrl.trim());
+ const parsed = new URL(rawUrl);
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
throw new Error("bad protocol");
}
url = parsed.toString();
} catch {
return ephemeral(
- `\`${escapeSlackText(rawUrl)}\` doesn't look like a valid URL. Try \`/monitor watch https://example.com\`.`,
+ `\`${escapeSlackText(rawUrl)}\` doesn't look like a valid URL. Try \`/monitor watch https://example.com pricing changes\`.`,
);
}
@@ -122,6 +129,8 @@ async function watchResponse(
host = url;
}
+ const hasGoal = goal.length > 0;
+
try {
const parsedInput = createMonitorSchema.parse({
name: `Slack: ${host}`,
@@ -140,6 +149,9 @@ async function watchResponse(
channelName: input.channelName,
},
},
+ // A prompt enables meaningful-change judging, so we only alert on changes
+ // that match what the user asked to watch for.
+ ...(hasGoal ? { goal, judgeEnabled: true } : {}),
origin: "slack",
});
@@ -155,11 +167,13 @@ async function watchResponse(
intervalMs: schedule.intervalMs,
});
+ const lead = hasGoal
+ ? `:fire: Now monitoring ${slackLink(url)} for: _${escapeSlackText(goal)}_\nOnly *meaningful* changes will be posted to *#${escapeSlackText(input.channelName)}*.`
+ : `:fire: Now monitoring ${slackLink(url)} — changes will be posted to *#${escapeSlackText(input.channelName)}*.\n_Add a prompt to alert only on meaningful changes, e.g. \`/monitor watch <url> pricing changes\`._`;
+
return ephemeral(
[
- `:fire: Now monitoring ${slackLink(url)} — changes will be posted to *#${escapeSlackText(
- input.channelName,
- )}*.`,
+ lead,
`Runs daily. Manage it in the ${slackLink(
dashboardUrl(`/app/monitoring/${monitor.id}`),
"dashboard",
@@ -240,7 +254,9 @@ export async function handleSlashCommand(
case "watch":
case "add":
if (!arg) {
- return ephemeral("Usage: `/monitor watch <url>`");
+ return ephemeral(
+ "Usage: `/monitor watch <url> [what to watch for]`\nExample: `/monitor watch https://example.com/pricing pricing or plan changes`",
+ );
}
return watchResponse(input, arg);
case "cancel":
diff --git a/apps/api/src/services/integrations/slack/messages.ts b/apps/api/src/services/integrations/slack/messages.ts
index 573eb654a..790eee325 100644
--- a/apps/api/src/services/integrations/slack/messages.ts
+++ b/apps/api/src/services/integrations/slack/messages.ts
@@ -59,20 +59,13 @@ export function buildMonitorAlertMessage(payload: MonitorSlackPayload): {
} {
const { summary } = payload;
- const judged = payload.pages.filter(p => p.judgment);
- const meaningful = judged.filter(p => p.judgment!.meaningful).length;
- const changedLine =
- judged.length > 0
- ? `*Changed:* ${summary.changed} (${meaningful} meaningful)`
- : `*Changed:* ${summary.changed}`;
-
- const summaryLines = [
- changedLine,
- `*New:* ${summary.new}`,
- `*Removed:* ${summary.removed}`,
- `*Errors:* ${summary.error}`,
- `*Pages checked:* ${summary.totalPages}`,
- ].join("\n");
+ // Meaningful changes first — those carry the description the reader cares about.
+ const sortedPages = [...payload.pages].sort((a, b) => {
+ const aM = a.judgment?.meaningful === true ? 0 : 1;
+ const bM = b.judgment?.meaningful === true ? 0 : 1;
+ return aM - bM;
+ });
+ const shownPages = sortedPages.slice(0, MAX_PAGE_BLOCKS);
const blocks: unknown[] = [
{
@@ -83,51 +76,73 @@ export function buildMonitorAlertMessage(payload: MonitorSlackPayload): {
emoji: true,
},
},
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: `Your Firecrawl monitor detected activity.\n${summaryLines}`,
- },
- },
];
- const sortedPages = [...payload.pages].sort((a, b) => {
- const aM = a.judgment?.meaningful === true ? 0 : 1;
- const bM = b.judgment?.meaningful === true ? 0 : 1;
- return aM - bM;
- });
-
- const shownPages = sortedPages.slice(0, MAX_PAGE_BLOCKS);
- if (shownPages.length > 0) {
- blocks.push({ type: "divider" });
- for (const page of shownPages) {
- let line = `*${escapeSlackText(page.status)}* ${boundedPageLink(page.url)}`;
- if (page.judgment) {
- line += page.judgment.meaningful
- ? " :large_orange_diamond: _meaningful_"
- : " :white_circle: _noise_";
- if (page.judgment.reason) {
- line += `\n_${escapeSlackText(truncate(page.judgment.reason, 240))}_`;
- }
- }
+ // Headline each page with WHAT changed (the judged description). The page's
+ // status + URL becomes a small secondary context line beneath it.
+ for (const page of shownPages) {
+ const reason = page.judgment?.reason?.trim();
+ const tag = page.judgment
+ ? page.judgment.meaningful
+ ? " · _meaningful_"
+ : " · _noise_"
+ : "";
+ const meta = `${statusEmoji(page.status)} *${escapeSlackText(page.status)}* · ${boundedPageLink(page.url)}${tag}`;
+
+ if (reason) {
blocks.push({
type: "section",
- // Final safety net: never emit a section over Slack's hard limit.
- text: { type: "mrkdwn", text: truncate(line, SECTION_TEXT_LIMIT) },
+ text: {
+ type: "mrkdwn",
+ // The change description leads; clamp only at Slack's hard limit.
+ text: truncate(escapeSlackText(reason), SECTION_TEXT_LIMIT),
+ },
});
- }
- const remaining = sortedPages.length - shownPages.length;
- if (remaining > 0) {
blocks.push({
type: "context",
- elements: [
- { type: "mrkdwn", text: `…and ${remaining} more page(s).` },
- ],
+ elements: [{ type: "mrkdwn", text: truncate(meta, SECTION_TEXT_LIMIT) }],
+ });
+ } else {
+ // No judged description (e.g. unjudged monitor) — the page itself leads.
+ blocks.push({
+ type: "section",
+ text: { type: "mrkdwn", text: truncate(meta, SECTION_TEXT_LIMIT) },
});
}
}
+ const remaining = sortedPages.length - shownPages.length;
+ if (remaining > 0) {
+ blocks.push({
+ type: "context",
+ elements: [{ type: "mrkdwn", text: `…and ${remaining} more page(s).` }],
+ });
+ }
+
+ blocks.push({ type: "divider" });
+
+ // Secondary: a compact one-line tally (only non-zero categories + total).
+ const meaningfulCount = payload.pages.filter(
+ p => p.judgment?.meaningful === true,
+ ).length;
+ const counts: string[] = [];
+ if (summary.changed > 0) {
+ counts.push(
+ `${summary.changed} changed${meaningfulCount > 0 ? ` (${meaningfulCount} meaningful)` : ""}`,
+ );
+ }
+ if (summary.new > 0) counts.push(`${summary.new} new`);
+ if (summary.removed > 0) counts.push(`${summary.removed} removed`);
+ if (summary.error > 0) {
+ counts.push(`${summary.error} error${summary.error === 1 ? "" : "s"}`);
+ }
+ counts.push(`${summary.totalPages} checked`);
+
+ blocks.push({
+ type: "context",
+ elements: [{ type: "mrkdwn", text: counts.join(" · ") }],
+ });
+
blocks.push({
type: "actions",
elements: [
@@ -152,11 +167,32 @@ export function buildMonitorAlertMessage(payload: MonitorSlackPayload): {
],
});
- const text = `Monitor "${payload.monitorName}" detected activity: ${summary.changed} changed, ${summary.new} new, ${summary.removed} removed, ${summary.error} errors.`;
+ // Notification preview / fallback text also leads with the change itself.
+ const leadReason =
+ shownPages.find(p => p.judgment?.meaningful && p.judgment.reason)?.judgment
+ ?.reason ?? shownPages.find(p => p.judgment?.reason)?.judgment?.reason;
+ const text = leadReason
+ ? `${payload.monitorName}: ${truncate(leadReason.trim(), 280)}`
+ : `Monitor "${payload.monitorName}" detected activity: ${summary.changed} changed, ${summary.new} new, ${summary.removed} removed, ${summary.error} errors.`;
return { text, blocks };
}
+function statusEmoji(status: string): string {
+ switch (status) {
+ case "changed":
+ return ":large_orange_diamond:";
+ case "new":
+ return ":large_green_circle:";
+ case "removed":
+ return ":red_circle:";
+ case "error":
+ return ":warning:";
+ default:
+ return ":small_blue_diamond:";
+ }
+}
+
function truncate(input: string, max: number): string {
if (input.length <= max) return input;
return input.slice(0, Math.max(0, max - 1)) + "…";