Commit Graph
7 Commits
Author SHA1 Message Date
CatoandClaude Fable 5.1 634ea86168 refactor: quality sweep — lint at zero warnings, one logger, shared ingestion kit, no generated client in git (#271)
* chore(repo): drop ralph.sh residue, ignore the generated Prisma client at the root

ralph.sh was byte-identical to reparaturbonus-zh/ralph.sh ("Ralph Loop for
Revamp-Hirn") and PROMPT.md was its blank task template; nothing in CI, docs
or scripts referenced either.

backend/generated/ is produced by `prisma generate` (typecheck, build and
Dockerfile.backend all run it) and was already ignored by backend/.gitignore,
so it was never committed — but tools that only read the root ignore file
(the fleet jscpd sweep) counted its ~1,300 generated lines as duplicated
source and reported the repo at 4.4%. Listing it at the root too makes those
sweeps see what git sees.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8

* refactor(backend): log through one pino instance, lint console.log out

The backend had pino-http for requests and bare console.log everywhere else
(index.js, jobs/, services/websocket.js — 26 lines). lib/logger.js now owns
the pino-http middleware and exposes its logger, so application logs and
request logs share level, destination and redaction. pino stays an indirect
dependency: pnpm does not hoist pino-http's copy, and a second pino would be
a second place to configure.

The backend had no linter at all. eslint.config.mjs enables exactly one rule,
no-console (warn/error allowed), so this cannot drift back; the root `lint`
now runs both halves, which is what `verify` and CI call.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8

* refactor(ingest): one shared kit for the image/video/audio/database ingestion components and the /ingest pages

The four data-ingestion components each carried their own copy of the
upload state machine (idle → uploading → processing → complete/error), the
file picker + drag-drop + object-URL preview, the auth header, the response
reader, the drop zone, progress bar, error banner, result card and submit
button. The five /ingest/<kind> pages likewise repeated the page frame, the
"Recent …" panel with its loading/error/empty states, the status badge and
the detail panel, plus a private copy of formatFileSize/formatDate.

Now there is one of each:
- components/data-ingestion/shared.tsx — useIngestionUpload, useFilePreview,
  authHeaders, readIngestionResponse and the shared markup pieces
- components/data-ingestion/icons.tsx — the inline SVG paths as data, one
  OutlineIcon/SpinnerIcon component
- ingest/shared.tsx — IngestPage, RecentPanel, StatusBadge, DetailPanel and
  the useRecentSources fetch
- lib/format.ts — formatFileSize/formatDuration/formatDate, with a test

Markup and copy are unchanged; the components render exactly what they did.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8

* refactor(forms): type the stored form structure once, drop the dead quick-field builder

`/api/v1/forms` returned `schema as any` and every consumer re-derived its
shape. `StoredFormStructure` / `FormListRow` in types/saved-form.ts are now
the one description of what the builder writes into the Json column, used by
the route, SavedFormsLibrary, ModernFormBuilderLayout and the builder page.

DynamicForm loses its unused `addQuickField` duplicate of FormFieldBuilder's
own field factory and an unused `handleCreateGroup` argument; the autosave
draft effect reads the current form through a ref instead of listing the
form as a dependency (which is what the exhaustive-deps warning was pointing
at — re-running it per keystroke would clobber the user's input).
SavedFormsLibrary wraps fetchForms in useCallback so the token effect is
honest about what it depends on; its `handleLoginSuccess` was never wired to
anything. Rendered output is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8

* refactor(frontend): fix every ESLint warning, gate lint at --max-warnings 0, ban console.log

The frontend lint config had downgraded no-unused-vars, no-explicit-any,
ban-ts-comment, exhaustive-deps, no-unescaped-entities and no-img-element to
"warn" ("temporarily, for build success") and `eslint .` ran with no
warning cap, so 152 warnings sat there unread. Every one is fixed at the
source rather than silenced:

- no-explicit-any: real types — jose's private `email` claim, the next-auth
  Session/User augmentation (`session.user.id` is set by the session
  callback), OpenAI.APIError for the vision route's status checks, typed
  event/data shapes elsewhere. The ambient `declare module '@dnd-kit/*'`
  stub is gone: `@dnd-kit/utilities` is now a declared dependency so its own
  types load.
- no-unused-vars: unused imports/params/state dropped. Seven components and
  one hook turned out to be rendered nowhere (BuilderToolbar,
  FormBuilderQuickStart, FormCreationHub, ModernSidebarStore, MultiStepForm,
  MultiStepFormBuilderStore, QuickActions, useApiRequest) — deleted, and the
  README paragraph that described the *Store wrappers updated.
- exhaustive-deps: callbacks memoised so the dependency arrays are truthful.
- ban-ts-comment / no-unescaped-entities: the comments were covering typed
  code; the entities are escaped.
- The 5 console.log calls in frontend/src (debug leftovers in components
  and services) are removed; console.warn/error stay. `no-console` (allow
  warn/error) is now an error so they cannot come back, with scripts/**
  exempt because printing is their job. (Of the 82 console.log in the repo,
  26 were the backend — routed through pino in the previous commit — and
  the rest are operator scripts, which print by design.)

The downgrade block is gone, so upstream next/core-web-vitals defaults
apply, and `lint` runs with `--max-warnings 0`: a warning fails the gate.
152 → 0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 22:22:22 -07:00
CatoandClaude Opus 5 bf1d9c32d3 refactor(ai): complete() owns the request, the per-vendor dedupe goes, and the tests can finally run (#252)
* refactor(ai): complete() owns the request, the per-vendor dedupe goes, and the tests can finally run

Three things, and the third is why the first two were invisible.

1. THE 429 BODY WAS READ AND DISCARDED. The hand-rolled `attempt`
   ended a failed request at
   `chat failed (${res.status}): ${detail.slice(0, 200)}` — fetched,
   truncated, and read by nothing. The three kinds of 429 share that
   status code and want opposite responses:
     capacity — a burst; demoting is right.
     daily    — the vendor's whole org-wide budget is spent; every other
                model there is already dead.
     size     — one request exceeded the per-minute allowance alone; the
                next model down has a SMALLER ceiling, so demoting is
                strictly worse.
   The old `fetch` also had NO deadline, so a vendor that accepted the
   connection and never answered held an ingestion job open forever and
   the fallback beneath it was never reached.

2. THE PER-VENDOR DEDUPE IS GONE, and that is the point rather than a
   tidy-up. It kept one link per vendor because "a second model at the
   same vendor draws on the same daily budget". True of the DAILY case
   and only that case — and it discarded the retry that rescues the two
   failures that actually keep happening: a retired model id, and a model
   that is momentarily busy while the vendor is fine. complete() makes
   the distinction per failure KIND instead of up front, so a daily 429
   still condemns the vendor (the dedupe's real benefit, kept) while a
   404 demotes within it. Strictly more chain, not less.

3. NOTHING IN backend/ COULD RUN A TEST. `backend/package.json`'s script
   was `echo "Error: no test specified" && exit 1`, and the root `test`
   only ever ran the frontend. backend/utils/responseHandlers.test.js has
   been sitting there, committed, executed by nothing — its own docstring
   says so. So a chain change here would have shipped with no coverage,
   and any test I added would have joined it in the dark.

   Wired: backend `test` → `vitest run`, root `test` → frontend AND
   backend. 71 frontend + 20 backend, ten of those twenty running for the
   first time.

The 10 new tests drive every failure through a real response BODY,
because the body is the only thing that separates the three 429s. The
SIZE one asserts exactly one request was made — asserting that it threw
would not show the walk STOPPED, since everything failing throws too.
Mocks are real Response objects built per call: one body reads once, so
a shared instance makes link two fail with "Body has already been read",
a fake failure in front of the real one.

verify green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NHDLTKGirKU7He8q2YR2y4

* ci: install backend deps, or the test script I just wired makes the gate red

The previous commit pointed root `test` at both halves. CI installs only
`frontend`, so `pnpm run verify` would have reached `test:backend` and
died with "Command vitest not found" — a wired script and a red gate,
which is worse than the gate that was simply absent.

Adds an `Install (backend)` step and caches on both lockfiles. Verified
`pnpm install --frozen-lockfile` succeeds in backend/ against the
committed lockfile, which is what CI runs.

Also corrects the comment above `Verify`. It described the gate as
"lint + typecheck + build"; it is format + lint + typecheck + test +
build, and `test` now covers both halves. That comment is what a reader
trusts about what "verified" means in this repo, so leaving it describing
the old bundle would be its own quiet lie.

The job id stays `verify-frontend` even though it is now a misnomer:
renaming a job renames the status check, and a required check that
disappears blocks merges rather than failing loudly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NHDLTKGirKU7He8q2YR2y4

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 11:24:33 +00:00
416b80f09a refactor(deps): ai-kit from npm — the 10th consumer nobody counted (#248)
backend still installed github:bitbaum/ai-kit#v0.6.2; now
@bitbaum/ai-kit ^0.6.2 with the dynamic import codemodded.


Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-04 17:35:09 +00:00
9628b5f868 fix(ai): give text analysis a real multi-vendor fallback chain (#238)
llm-analysis.js and aiAnalysisService.js each constructed their own
OpenAI client, hardcoded model: 'gpt-4', and threw/skipped outright
whenever OPENAI_API_KEY was unset — a single vendor, single model, with
no recovery path. The moment OpenAI has a billing hiccup, an outage, or
retires gpt-4, every text-analysis feature in this app goes dead until
someone notices and redeploys.

backend/lib/aiChain.js gives both services a real chain via ai-kit
(Groq -> OpenRouter free tier, same package already adopted fleet-wide
for this exact failure mode), plus a health tracker exposed
informationally on /health (never gates the endpoint's status — a dead
vendor key can't be fixed by a restart).

Vision/image analysis (imageIngestionService.js, video frame analysis,
openaiVisionService.ts) and Whisper audio transcription stay on OpenAI
directly: ai-kit's free chain carries no vision- or audio-capable free
models, so forcing those onto it would silently degrade output quality
rather than provide a real fallback. Documented as a known limitation
in .claude/CLAUDE.md's env var list.


Claude-Session: https://claude.ai/code/session_01HVwg8DKHQktxJuHeLM3xpG

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-02 09:16:38 +00:00
GandClaude Opus 5 53d2e70723 chore: add a formatter (#233)
* chore: add a formatter, matching the style this repo already writes

singleQuote=true was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (199 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(ci): put prettier where CI actually installs

The formatter was added to the root package.json, but CI installs with
working-directory: frontend and then runs npm run verify at the root, so root
devDependencies are never installed at all. format:check died with
'prettier: not found' before checking a single file.

Root now delegates into frontend the way every other root script already does,
and prettier is a devDependency of frontend, whose lockfile CI installs.

frontend also needs its own .prettierignore: prettier resolves that file
relative to the working directory, so the root one stopped applying the moment
the command ran from frontend/ — which is how README.md and Playwright output
ended up being checked.

* fix(ci): do not format contentlayer's generated output

format:check ran green locally and failed in CI on files that do not exist
locally: CI builds contentlayer before verify, so .contentlayer/generated is
present by the time prettier looks. One generated module imports with
assert { type: 'json' }, which prettier's parser rejects outright.

A local --check cannot see build output, so generated directories have to be
ignored by name rather than discovered.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 11:06:25 +00:00
g-butandClaude Opus 4.5 cb6c2b5ac0 chore: fix security vulnerabilities
Updated vulnerable packages where possible.
Some vulnerabilities remain due to next-contentlayer peer dependency conflicts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 19:58:41 +01:00
Your NameandClaude b2a4656d16 feat: prepare for deployment - update documentation and backend structure
- Updated CLAUDE.md with unified Erfassung platform concept
- Enhanced backend controllers and routes structure
- Updated dependencies and configurations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-07 19:49:19 +02:00