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
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ The application is written in TypeScript for Bun. It has no third-party runtime
configuration, feed parsing, CLI handling, web serving, streaming, and tests all use
repository code, Web APIs, or Bun and Node-compatible built-ins.

## See Distil in action

Collect recent items, review every relevance decision, then generate a focused Markdown
digest. Include and Exclude choices remain reversible until generation starts.

[![Distil's three-step workflow with collection activity and source-level review summaries](assets/screenshots/workflow.png)](assets/screenshots/workflow.png)

<p align="center">
<a href="assets/screenshots/generated-digest.png"><img src="assets/screenshots/generated-digest.png" alt="Distil's generation step showing a saved Markdown research digest" width="49%"></a>
<a href="assets/screenshots/key-takeaways.png"><img src="assets/screenshots/key-takeaways.png" alt="The key takeaways section of a Distil research digest" width="49%"></a>
</p>

## Requirements

- [Bun 1.4.3 or newer](https://bun.sh/docs/installation)
Expand Down Expand Up @@ -139,9 +151,14 @@ Then enable its loopback endpoint:
[decision]
enabled = true
base_url = "http://127.0.0.1:8000"
confidence_threshold = 0.9
confidence_threshold = 0.85
timeout_seconds = 10

The default threshold of `0.85` accepts common high-confidence decisions while leaving
less certain items for review. Raise it toward `1` for stricter manual oversight or lower
it cautiously to automate more decisions. Existing explicit configuration values are not
changed automatically.

Distil accepts a Strands include or exclude classification only when it meets the
configured confidence threshold. The preview labels those results **Include** or
**Exclude**, previously processed items **Seen**, and lower-confidence results **Review**.
Expand All @@ -161,8 +178,9 @@ Preview selection without calling the generative LLM:
bun run distil preview --days 7

The web UI offers Include and Exclude controls beside every unresolved item, plus explicit
bulk controls. CLI `run` stops when review is required; after inspecting `preview`, opt in
to a deterministic bulk decision when appropriate:
bulk controls. Every settled item can be changed from Include to Exclude or back again
until generation starts. CLI `run` stops when review is required; after inspecting
`preview`, opt in to a deterministic bulk decision when appropriate:

bun run distil run --review-policy=include
bun run distil run --review-policy=exclude
Expand Down
Binary file added assets/screenshots/generated-digest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/key-takeaways.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/workflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ retries = 2
[decision]
enabled = true
base_url = "http://127.0.0.1:8000"
confidence_threshold = 0.9
confidence_threshold = 0.85
timeout_seconds = 10

[output]
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type TomlValue = string | number | boolean | TomlValue[] | TomlTable;
const DEFAULT_OLLAMA_URL = "http://127.0.0.1:11434/v1";
const DEFAULT_OPENAI_URL = "https://api.mistral.ai/v1";
const DEFAULT_DECISION_URL = "http://127.0.0.1:8000";
const DEFAULT_DECISION_CONFIDENCE = 0.85;

export interface EditableConfig {
llm: {
Expand Down Expand Up @@ -82,7 +83,7 @@ export function setupConfig(): Config {
decision: {
enabled: false,
baseUrl: DEFAULT_DECISION_URL,
confidenceThreshold: 0.9,
confidenceThreshold: DEFAULT_DECISION_CONFIDENCE,
timeoutMs: 10_000,
},
output: { directory: "~/distils", readingTimeMinutes: 5 },
Expand Down Expand Up @@ -355,7 +356,7 @@ export function normalizeConfig(raw: TomlTable): Config {
baseUrl: decisionBaseUrl,
confidenceThreshold: boundedNumber(
decisionRaw.confidence_threshold,
0.9,
DEFAULT_DECISION_CONFIDENCE,
0,
1,
"decision.confidence_threshold",
Expand Down
17 changes: 14 additions & 3 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,18 @@ export function unresolvedSelections(result: SelectionResult): ItemSelection[] {
return result.items.filter(isPendingSelection);
}

export function resolvePendingSelection(
export function resolveSelection(
result: SelectionResult,
fingerprint: string,
policy: ReviewPolicy,
): SelectionResult {
const target = result.items.find((selection) => selection.fingerprint === fingerprint);
if (!target) throw new Error("Unknown selection fingerprint");
if (!isPendingSelection(target)) throw new Error("Selection does not require review");
if (target.kind === "seen") {
throw new Error(
"Seen items must be recollected with Include seen before changing them",
);
}
return resolvedResult(
result,
result.items.map((selection) =>
Expand Down Expand Up @@ -376,11 +380,18 @@ function manualResolution(
source: "user review" | "explicit bulk review",
): ItemSelection {
const included = policy === "include";
const evidence =
selection.kind === "manual"
? selection.reason.replace(
/^(?:Included|Excluded) by (?:user review|explicit bulk review)\. /,
"",
)
: selection.reason;
return {
...selection,
selected: included,
kind: "manual",
reason: `${included ? "Included" : "Excluded"} by ${source}. ${selection.reason}`,
reason: `${included ? "Included" : "Excluded"} by ${source}. ${evidence}`,
};
}

Expand Down
10 changes: 8 additions & 2 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { streamDistil } from "./prompts.ts";
import {
ContentSelector,
resolveAllPending,
resolvePendingSelection,
resolveSelection,
type SelectionKind,
type SelectionPipeline,
type SelectionResult,
Expand Down Expand Up @@ -404,6 +404,12 @@ export class DistilWebApp {
if (job?.status !== "complete" || !job.collection || !this.#cachedSelection) {
return json({ error: "No completed fetch is available for review" }, 409);
}
if (this.#generationInProgress) {
return json(
{ error: "The selection cannot change while generation is running" },
409,
);
}

let resolution: SelectionResolution;
try {
Expand All @@ -416,7 +422,7 @@ export class DistilWebApp {
const policy = resolution.selected ? "include" : "exclude";
const selection = resolution.all
? resolveAllPending(this.#cachedSelection, policy)
: resolvePendingSelection(this.#cachedSelection, resolution.fingerprint, policy);
: resolveSelection(this.#cachedSelection, resolution.fingerprint, policy);
this.#cachedSelection = selection;
this.#cachedItems = selection.selected;
job.result = fetchPayload(job.collection, selection);
Expand Down
33 changes: 24 additions & 9 deletions src/web_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function homePage(
'<ol id="fetch-log" class="progress-log" aria-label="Collection activity"></ol>',
"</section>",
'<section id="review-panel" class="card workflow-panel" aria-labelledby="review-heading">',
'<div class="card-heading"><div><p class="kicker">Step 2</p><h2 id="review-heading">Review the selection</h2><p>Check what will shape the digest and resolve any uncertain items.</p></div></div>',
'<div class="card-heading"><div><p class="kicker">Step 2</p><h2 id="review-heading">Review the selection</h2><p>Check what will shape the digest. You can change any included or excluded item before generating.</p></div></div>',
'<p id="review-status" class="section-status" role="status" aria-live="polite" aria-atomic="true">Collect items to begin reviewing.</p>',
'<div id="review-actions" class="review-actions row" hidden>',
'<strong id="review-summary"></strong>',
Expand Down Expand Up @@ -115,7 +115,7 @@ export function settingsPage(): string {
'<label class="switch-row"><input id="decision-enabled" type="checkbox"><span><strong>Use Strands Decider</strong><small>Only a loopback service is accepted.</small></span></label>',
'<div id="decision-fields" class="field-grid three" hidden>',
'<label>Service URL <span class="hint">loopback only</span><input id="decision-url" type="url" value="http://127.0.0.1:8000" required></label>',
'<label>Confidence <span class="hint">0–1</span><input id="confidence" type="number" min="0" max="1" step="0.01" value="0.9" required></label>',
'<label>Confidence <span class="hint">0–1</span><input id="confidence" type="number" min="0" max="1" step="0.01" value="0.85" required></label>',
'<label>Timeout <span class="hint">seconds</span><input id="decision-timeout" type="number" min="1" value="10" required></label>',
"</div>",
"</section>",
Expand Down Expand Up @@ -563,6 +563,9 @@ const CSS = String.raw`
.field-grid { display:grid; gap:1rem; margin-top:1rem; }
.field-grid.two { grid-template-columns:repeat(2,minmax(0,1fr)); }
.field-grid.three { grid-template-columns:repeat(3,minmax(0,1fr)); }
.field-grid > label { display:flex; flex-direction:column; gap:.35rem; }
.field-grid > label > input,.field-grid > label > select,
.field-grid > label > textarea { margin-top:auto; }
.hint { display:block; color:var(--muted); font-size:.78rem; font-weight:400; }
.field-help { margin:.5rem 0 0; color:var(--muted); font-size:.9rem; }
.advanced { margin-top:1rem; padding:.75rem 0 0; }
Expand Down Expand Up @@ -842,8 +845,7 @@ const HOME_SCRIPT = String.raw`
setWorkflowStep("collect", "current", "Collect again");
setWorkflowStep("review", "complete", "No items included");
setWorkflowStep("generate", "blocked", "No included items");
generateStatus.textContent =
"No items are included. Adjust the collection and fetch again.";
generateStatus.textContent = "No items are included. Include one to continue.";
}
return;
}
Expand Down Expand Up @@ -986,13 +988,24 @@ const HOME_SCRIPT = String.raw`
if (meta.childNodes.length > 0) content.append(meta);
content.append(reason);
row.append(tag, content);
if (item.kind === "review" || item.kind === "fallback") {
if (item.kind !== "seen") {
const actions = document.createElement("div");
actions.className = "decision-actions";
actions.append(
reviewButton("Include", item.title, item.fingerprint, true),
reviewButton("Exclude", item.title, item.fingerprint, false),
);
if (item.kind === "review" || item.kind === "fallback") {
actions.append(
reviewButton("Include", item.title, item.fingerprint, true),
reviewButton("Exclude", item.title, item.fingerprint, false),
);
} else {
actions.append(
reviewButton(
item.selected ? "Exclude instead" : "Include instead",
item.title,
item.fingerprint,
!item.selected,
),
);
}
row.append(actions);
}
list.append(row);
Expand Down Expand Up @@ -1072,6 +1085,7 @@ const HOME_SCRIPT = String.raw`
generateButton.addEventListener("click", async () => {
generateButton.disabled = true;
generateButton.textContent = "Generating…";
setReviewControlsDisabled(true);
generatePanel.setAttribute("aria-busy", "true");
setWorkflowStep("generate", "current", "Generating digest");
let completed = false;
Expand Down Expand Up @@ -1112,6 +1126,7 @@ const HOME_SCRIPT = String.raw`
generatePanel.setAttribute("aria-busy", "false");
generateButton.disabled = completed;
generateButton.textContent = "Generate digest";
if (!completed) setReviewControlsDisabled(false);
}
});

Expand Down
1 change: 1 addition & 0 deletions tests/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test("parses and normalizes the existing TOML shape", () => {
assertEquals(config.llm.retries, 3);
assertEquals(config.decision.enabled, false);
assertEquals(config.decision.baseUrl, "http://127.0.0.1:8000");
assertEquals(config.decision.confidenceThreshold, 0.85);
assertEquals(config.output.readingTimeMinutes, 7);
assertEquals(config.feeds[0].keywords, ["drug", "protein"]);
});
Expand Down
34 changes: 21 additions & 13 deletions tests/selection_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FileSeenStore,
itemFingerprint,
resolveAllPending,
resolvePendingSelection,
resolveSelection,
type SeenStore,
unresolvedSelections,
} from "../src/selection.ts";
Expand Down Expand Up @@ -81,12 +81,12 @@ test("selection skips seen items and trusts only confident Strands choices", asy
assertEquals(progress.at(-1)?.completed, 4);
assertMatch(progress.at(-1)?.message ?? "", /top choice was exclude/);

await assertRejects(() => selector.markReviewed(result), /1 unresolved item/);
const resolved = resolvePendingSelection(
result,
result.items[3].fingerprint,
"include",
await assertRejects(
() => resolveSelection(result, result.items[0].fingerprint, "include"),
/Include seen/,
);
await assertRejects(() => selector.markReviewed(result), /1 unresolved item/);
const resolved = resolveSelection(result, result.items[3].fingerprint, "include");
assertEquals(resolved.items[3].kind, "manual");
assertEquals(resolved.items[3].selected, true);
assertMatch(resolved.items[3].reason, /^Included by user review\./);
Expand Down Expand Up @@ -151,7 +151,7 @@ test("selection requires review when the local decision service is unavailable",
assertMatch(resolved.items[0].reason, /^Excluded by explicit bulk review\./);
});

test("selection resolution rejects unknown and final decisions", async () => {
test("selection decisions can be reversed while preserving their evidence", async () => {
const decisions = new FakeDecisionClient();
decisions.verdicts = [{ choice: "include", confidence: 0.95 }];
const selector = new ContentSelector(config, "research", {
Expand All @@ -160,13 +160,21 @@ test("selection resolution rejects unknown and final decisions", async () => {
});
const result = await selector.select([item(1)]);

await assertRejects(
() => resolvePendingSelection(result, "missing", "include"),
/Unknown selection fingerprint/,
await assertRejects(() => resolveSelection(result, "missing", "include"), /Unknown/);

const excluded = resolveSelection(result, result.items[0].fingerprint, "exclude");
assertEquals(excluded.items[0].kind, "manual");
assertEquals(excluded.items[0].selected, false);
assertEquals(
excluded.items[0].reason,
"Excluded by user review. Strands chose include with 95% confidence in its relevance classification",
);
await assertRejects(
() => resolvePendingSelection(result, result.items[0].fingerprint, "exclude"),
/does not require review/,

const included = resolveSelection(excluded, result.items[0].fingerprint, "include");
assertEquals(included.items[0].selected, true);
assertEquals(
included.items[0].reason,
"Included by user review. Strands chose include with 95% confidence in its relevance classification",
);
});

Expand Down
Loading
Loading