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
7 changes: 7 additions & 0 deletions .agents/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@
[0] `pnpm run dev -- web` launches the CLI web stack (API + built static PWA) and does not provide Vite HMR. For frontend hot reload, run Vite (`pnpm run dev:web`) with API separately (now `pnpm run dev:stack` does both).
[0] Current web UI architecture is intentionally mobile-first single-column across all viewport sizes; desktop split-pane branches were removed from `app-shell`, `inbox-filters`, and `inbox-list`.
[0] In Fastify/Ajv query validation, `oneOf` with numeric query params can produce false validation failures (e.g. `querystring/limit must match exactly one schema in oneOf`) due to coercion behavior; use a single string schema pattern for query params and parse downstream.
[1] Drizzle SQLite table-rebuild migrations can generate invalid copy SQL when adding new columns (`INSERT ... SELECT` referencing columns that do not exist on the old table). After `drizzle-kit generate`, always verify the data-copy statement and map new columns to constants/nulls for backward-compatible migration.
[0] In TypeScript tests, shell script snippets inside template literals must escape `${...}` as `\${...}`; otherwise the TS parser treats them as JS interpolation and breaks compilation.
[0] With `exactOptionalPropertyTypes: true`, do not pass explicit `undefined` for optional object fields; build payload objects with conditional spreads so omitted fields stay omitted.
[0] Homebrew Python can enforce PEP 668 (`externally-managed-environment`) and block global `pip install`; document and prefer a small project-local virtualenv flow for optional Python helpers like auto-tags.
[0] In SQLite table-rebuild migrations (`__new_*` + rename), `CHECK` constraints must reference unqualified column names; qualifiers like `__new_table.column` can break after rename.
[0] Drizzle SQLite migrator runs migrations in a transaction; `PRAGMA foreign_keys=OFF` inside migration SQL may not disable FK checks. Table-copy migrations should filter/clean orphan rows explicitly (e.g., `INNER JOIN` parents) instead of relying on that pragma.
[0] CI `validate` workflow currently runs `format:check`, `lint`, `test`, and `apps/web` build. Before pushing, run all four locally to avoid fast-follow CI fix commits.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ STASH_DB_PATH=~/.stash/stash.db
# STASH_WEB_HOST=127.0.0.1
# STASH_API_PORT=4173
# STASH_PWA_PORT=5173
# STASH_AUTO_TAGS_ENABLED=true
# STASH_AUTO_TAGS_MAX=3
# STASH_AUTO_TAGS_MIN_SCORE=0.4
# STASH_AUTO_TAGS_MODEL=sentence-transformers/all-MiniLM-L6-v2
# STASH_AUTO_TAGS_BACKEND=python
# STASH_AUTO_TAGS_PYTHON=python3
# STASH_AUTO_TAGS_HELPER=./scripts/auto-tags-embed.py
15 changes: 14 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Current implementation status:
- Implemented: thumbnail extraction (metadata-first with content-image fallback) persisted on `items.thumbnail_url`.
- Implemented: automatic X/Twitter `status/<id>` extraction via Playwright Chromium rendered DOM (public-only, single-status only, no generic fallback for X URLs).
- Implemented: `extract` command to extract or re-extract content for existing items.
- Implemented: optional local auto-tagging on `save`/`extract` (`--auto-tags`) with deterministic rules + Python sentence-transformers backend fallback behavior.
- Implemented: auto-tag provenance tracking in `item_tags` (`is_manual`, `is_auto`, `auto_score`, `auto_source`, `auto_model`, `auto_updated_at`).
- Implemented: `stash tags doctor` diagnostics for local auto-tags runtime checks.
- Not implemented yet: `archive`, `delete`, `open`, search command.

## Stack
Expand All @@ -33,6 +36,7 @@ Current implementation status:
- Package manager: `pnpm`
- Content extraction: Mozilla Readability + linkedom
- X/Twitter extraction: Playwright Chromium (headless browser) for public `status/<id>` URLs
- Auto-tags embeddings backend: Python `sentence-transformers` helper (`scripts/auto-tags-embed.py`)
- TTS provider (default): Coqui TTS (Python 3.11 + espeak-ng)
- Default Coqui voice: `tts_models/en/vctk/vits|p241`
- CLI discovery standardized across providers: PATH first, optional env overrides (`STASH_GTTS_CLI`, `STASH_COQUI_TTS_CLI`, `STASH_FFMPEG_CLI`, `STASH_SAY_CLI`, `STASH_AFCONVERT_CLI`, `STASH_ESPEAK_CLI`)
Expand Down Expand Up @@ -156,6 +160,7 @@ stash save https://example.com --no-extract
Save URL:
```bash
stash save https://example.com --title "Example" --tag ai --tag typescript --json
stash save https://example.com --auto-tags --json
```

Save without content extraction:
Expand Down Expand Up @@ -204,6 +209,8 @@ Extract or re-extract content:
```bash
stash extract 1 --json
stash extract 1 --force --json
stash extract 1 --auto-tags --json
stash tags doctor --json
```

## UI/UX Workflow for Agents
Expand Down Expand Up @@ -269,7 +276,8 @@ Typical error shape:
- `tags`
- Unique tag names.
- `item_tags`
- Many-to-many link between items and tags.
- Many-to-many link between items and tags with provenance metadata:
- `is_manual`, `is_auto`, `auto_score`, `auto_source`, `auto_model`, `auto_updated_at`.
- `notes`
- Optional per-item note content.
- `item_audio`
Expand Down Expand Up @@ -321,6 +329,9 @@ Updates should include:
- `.db/` is git-ignored local runtime data for repository-local development.
- Local npm scripts load `.env` using `dotenv` via `scripts/with-env.mjs`.
- CLI DB path precedence remains: `--db-path` > `STASH_DB_PATH` > `~/.stash/stash.db`.
- Auto-tags env controls:
- `STASH_AUTO_TAGS_ENABLED`, `STASH_AUTO_TAGS_MAX`, `STASH_AUTO_TAGS_MIN_SCORE`
- `STASH_AUTO_TAGS_MODEL`, `STASH_AUTO_TAGS_BACKEND`, `STASH_AUTO_TAGS_PYTHON`, `STASH_AUTO_TAGS_HELPER`
- `stash web` now accepts `--host`, `--api-port`, `--pwa-port` (`--port` removed).
- `stash web` runs split listeners (API + PWA) and fails fast on port conflicts or identical API/PWA ports.
- Web dev (`apps/web` Vite) reads the same root `.env` port variables and uses strict port binding.
Expand All @@ -335,6 +346,8 @@ Updates should include:
- `has_extracted_content: boolean`
- `tts_audio: null | { file_name, format, provider, voice, bytes, generated_at }`
- `POST /api/items/:id/tts` is enqueue-first and returns job metadata (`job`, `poll_url`, `poll_interval_ms`).
- `POST /api/items` and `POST /api/items/:id/extract` accept optional `autoTags: boolean`.
- Web save UX requests auto-tags when the tags field is left empty.
- `GET /api/tts-jobs/:id` and `GET /api/items/:id/tts-jobs` expose job status/history for polling/recovery.
- `tts` auto-generated filenames use friendly slugs + timestamp + short random suffix and collision fallback (`_2`, `_3`, ...).
- Vitest sets `STASH_TTS_MOCK_BASE64` in `test/vitest.setup.ts` for deterministic TTS tests; default `pnpm test` does not require local Coqui/espeak binaries.
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ stash db doctor --json
- Public X/Twitter `status/<id>` extraction via Playwright Chromium (headless, public-only)
- Extract or re-extract content for existing items
- Organize with tags
- Optional local auto-tagging (`--auto-tags`) with provenance tracking
- Mark items as read/unread
- Generate TTS audio from extracted article content
- Play previously generated TTS audio in the web UI
Expand All @@ -200,22 +201,40 @@ stash db doctor --json
```bash
stash save https://example.com --tag typescript --tag cli
stash save https://example.com --no-extract # skip content extraction
stash save https://example.com --auto-tags --json
stash list --status unread --tag typescript --tag-mode all
stash list --json
stash tags list --json
stash tags doctor --json
stash tag add 1 productivity
stash tag rm 1 productivity
stash mark read 1
stash mark unread 1
stash extract 1 # extract content + thumbnail metadata for an existing item
stash extract 1 --force # re-extract even if content exists
stash extract 1 --auto-tags --json
stash tts 1 --json
stash tts 1 --wait --json
stash tts status 12 --json
stash tts doctor --json
stash jobs worker --once --json
```

## Auto Tags

- Auto-tags are opt-in by default:
- `stash save <url> --auto-tags`
- `stash extract <id> --auto-tags`
- Disable explicitly with `--no-auto-tags`.
- Existing URLs are supported: `stash save <existing-url> --auto-tags` re-runs auto-tagging and refreshes auto-only tags.
- Provenance is tracked in `item_tags` (`is_manual`, `is_auto`, score/source/model metadata).
- Manual tags are never removed by auto-tag refresh.
- Web save form behavior: when tag input is left empty, web save requests auto-tagging automatically.
- Runtime health check:
- `stash tags doctor --json`
- Python setup instructions:
- `docs/AUTO_TAGS_SETUP.md`

## X / Twitter Extraction (Headless Browser)

- `stash` automatically uses a Playwright Chromium-based extractor for public X/Twitter status URLs (`x.com/.../status/<id>` and `twitter.com/.../status/<id>`).
Expand Down
17 changes: 15 additions & 2 deletions apps/api/src/app/create-api-app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Fastify, { type FastifyInstance } from "fastify"

import type { ApiRouteOptions } from "../features/options.js"
import { extractRoutes } from "../features/extract/routes.js"
import { inboxRoutes } from "../features/inbox/routes.js"
import { itemRoutes } from "../features/item/routes.js"
import type { ApiRouteOptions } from "../features/options.js"
import { saveRoutes } from "../features/save/routes.js"
import { statusRoutes } from "../features/status/routes.js"
import { tagsRoutes } from "../features/tags/routes.js"
Expand All @@ -17,6 +16,20 @@ export function createApiApp(options: CreateApiAppOptions): FastifyInstance {
logger: false,
})

// Fastify's default JSON parser rejects empty bodies (e.g. DELETE with Content-Type: application/json).
// Override it to treat empty bodies as undefined instead of an error.
server.addContentTypeParser("application/json", { parseAs: "string" }, (_req, body, done) => {
if (body === "") {
done(null, undefined)
return
}
try {
done(null, JSON.parse(body as string))
} catch (err) {
done(err as Error, undefined)
}
})

registerApiErrorHandlers(server)

server.register(
Expand Down
9 changes: 9 additions & 0 deletions apps/api/src/features/extract/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ export function parseForce(body: unknown): boolean {
const raw = body as Record<string, unknown>
return Boolean(raw.force)
}

export function parseAutoTags(body: unknown): boolean | undefined {
if (!body || typeof body !== "object") {
return undefined
}

const raw = body as Record<string, unknown>
return typeof raw.autoTags === "boolean" ? raw.autoTags : undefined
}
16 changes: 13 additions & 3 deletions apps/api/src/features/extract/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FastifyPluginAsync } from "fastify"

import { extractItem } from "../../../../../packages/core/src/features/extract/service.js"
import type { ApiRouteOptions } from "../options.js"
import { parseForce, parseItemId } from "./dto.js"
import { parseAutoTags, parseForce, parseItemId } from "./dto.js"

const extractParamsSchema = {
type: "object",
Expand All @@ -12,7 +12,13 @@ const extractParamsSchema = {
required: ["id"],
} as const

const extractBodySchema = {} as const
const extractBodySchema = {
type: "object",
properties: {
force: { type: "boolean" },
autoTags: { type: "boolean" },
},
} as const

export const extractRoutes: FastifyPluginAsync<ApiRouteOptions> = async (fastify, options) => {
fastify.post(
Expand All @@ -24,13 +30,17 @@ export const extractRoutes: FastifyPluginAsync<ApiRouteOptions> = async (fastify
},
},
async (request) => {
const autoTags = parseAutoTags(request.body)
const result = await extractItem(
{
dbPath: options.dbPath,
migrationsDir: options.migrationsDir,
},
parseItemId(request.params as Record<string, string>),
parseForce(request.body),
{
force: parseForce(request.body),
...(autoTags !== undefined ? { autoTags } : {}),
},
)

return {
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/features/save/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function parseSaveBody(body: unknown): SaveItemInput {
? raw.tags.filter((value): value is string => typeof value === "string")
: undefined
const extract = typeof raw.extract === "boolean" ? raw.extract : undefined
const autoTags = typeof raw.autoTags === "boolean" ? raw.autoTags : undefined

const input: SaveItemInput = { url }
if (title !== undefined) {
Expand All @@ -28,5 +29,8 @@ export function parseSaveBody(body: unknown): SaveItemInput {
if (extract !== undefined) {
input.extract = extract
}
if (autoTags !== undefined) {
input.autoTags = autoTags
}
return input
}
1 change: 1 addition & 0 deletions apps/api/src/features/save/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const saveBodySchema = {
items: { type: "string" },
},
extract: { type: "boolean" },
autoTags: { type: "boolean" },
},
required: ["url"],
} as const
Expand Down
Loading