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
4 changes: 2 additions & 2 deletions app/(app)/dashboard/intent/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function WatchForm({
watch?: WatchLike;
}) {
const on = (s: string) =>
watch?.sources.length ? watch.sources.includes(s) : s === "github" || INTENT_SOURCES.find((x) => x.id === s)?.defaultOn;
watch?.sources.length ? watch.sources.includes(s) : INTENT_SOURCES.find((x) => x.id === s)?.defaultOn;
return (
<form id={id} action={action} className="card mt-10 grid gap-4 p-6 sm:grid-cols-2">
<h2 className="text-xl font-bold sm:col-span-2">{title}</h2>
Expand Down Expand Up @@ -336,7 +336,7 @@ function WatchForm({
<fieldset className="text-sm sm:col-span-2">
<legend>Communities</legend>
<div className="mt-2 flex flex-wrap gap-3">
{[...INTENT_SOURCES, { id: "github", label: "GitHub issues", defaultOn: true }].map((s) => (
{[...INTENT_SOURCES, { id: "github", label: "GitHub issues (feature requests)", defaultOn: false }].map((s) => (
<label key={s.id} className="flex items-center gap-1">
<input type="checkbox" name="sources" value={s.id} defaultChecked={on(s.id)} /> {s.label}
</label>
Expand Down
12 changes: 8 additions & 4 deletions lib/intent/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function searchHN(term: string, sinceSec: number): Promise<Raw[]> {
url: `https://news.ycombinator.com/item?id=${id}`,
title: strip(title),
snippet: body.slice(0, 600),
body: body.slice(0, 8000),
body: body.slice(0, 2000),
postedAt: typeof h.created_at_i === "number" ? new Date(h.created_at_i * 1000) : null,
};
});
Expand All @@ -77,7 +77,7 @@ async function searchStackOverflow(term: string, sinceSec: number): Promise<Raw[
: `https://stackoverflow.com/q/${String(i.question_id)}`,
title: strip(i.title as string),
snippet: strip((i.excerpt as string) ?? (i.body as string)).slice(0, 600),
body: strip((i.body as string) ?? (i.excerpt as string)).slice(0, 8000),
body: strip((i.body as string) ?? (i.excerpt as string)).slice(0, 2000),
postedAt: typeof i.creation_date === "number" ? new Date(i.creation_date * 1000) : null,
}));
}
Expand All @@ -92,7 +92,7 @@ async function searchGitHub(term: string, since: Date): Promise<Raw[]> {
url: String(i.html_url),
title: String(i.title ?? ""),
snippet: strip(i.body as string).slice(0, 600),
body: strip(i.body as string).slice(0, 8000),
body: strip(i.body as string).slice(0, 2000),
postedAt: i.created_at ? new Date(String(i.created_at)) : null,
}));
}
Expand All @@ -117,10 +117,14 @@ export async function sweepNative(input: {
const sinceSec = Math.floor(since.getTime() / 1000);
const want = (id: string, group: string) =>
!input.sources?.length || input.sources.includes(id) || input.sources.includes(group);
// GitHub is opt-in: most issues are maintainers' own to-do lists and reports,
// and the first live sweep scored one of those "Hot" (an internal docs review
// that named two competitors). Only search it when the watch picks it.
const wantGitHub = !!input.sources?.includes("github");
const searches: Array<[string, (t: string) => Promise<Raw[]>]> = [];
if (want("hn", "forums")) searches.push(["Hacker News", (t) => searchHN(t, sinceSec)]);
if (want("stackoverflow", "forums")) searches.push(["Stack Overflow", (t) => searchStackOverflow(t, sinceSec)]);
if (want("github", "github")) searches.push(["GitHub", (t) => searchGitHub(t, since)]);
if (wantGitHub) searches.push(["GitHub", (t) => searchGitHub(t, since)]);

const notes: string[] = [];
const seen = new Set<string>();
Expand Down
2 changes: 2 additions & 0 deletions lib/intent/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The person replying sells something that may help the author. Write the reply th

Rules:
- Answer the author's actual question first, with something genuinely useful even if they never buy.
- The first two sentences must be concrete help (a step, a check, a tool category, a pitfall) and must not name the product.
- Never write "this is the right fit" or any sales line; one plain disclosure ("I build X, which does Y") at the end is the most allowed.
- Mention the product at most once, plainly, and say you make it ("I build X"), never pretend to be a neutral user.
- If the product is not a good fit for what they asked, do not mention it at all; just help.
- 40 to 120 words. Plain text. No hashtags, no emoji, no bullet lists, no greeting like "Great question".
Expand Down
9 changes: 8 additions & 1 deletion tests/intent-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ afterEach(() => vi.unstubAllGlobals());
describe("sweepNative", () => {
it("searches HN, Stack Overflow and GitHub and scores the results", async () => {
vi.stubGlobal("fetch", vi.fn(async (url: string) => new Response(JSON.stringify(respond(url)), { status: 200 })));
const r = await sweepNative({ terms: ["AEO audit"], keywords: ["AEO audit"], days: 7, minIntent: 1, now });
const r = await sweepNative({ terms: ["AEO audit"], keywords: ["AEO audit"], sources: ["forums", "github"], days: 7, minIntent: 1, now });
expect(r.calls).toBe(3);
const sources = r.hits.map((h) => h.source);
expect(sources).toContain("hn");
expect(sources).toContain("stackoverflow");
expect(r.hits.find((h) => h.source === "hn")!.url).toBe("https://news.ycombinator.com/item?id=1");
});

it("leaves GitHub out unless the watch opts in", async () => {
const f = vi.fn(async (url: string) => new Response(JSON.stringify(respond(url)), { status: 200 }));
vi.stubGlobal("fetch", f);
await sweepNative({ terms: ["x"], keywords: ["x"], days: 7, minIntent: 0, now });
expect(f.mock.calls.some((c) => String(c[0]).includes("api.github.com"))).toBe(false);
});

it("respects the watch's source selection", async () => {
const f = vi.fn(async (url: string) => new Response(JSON.stringify(respond(url)), { status: 200 }));
vi.stubGlobal("fetch", f);
Expand Down
Loading