22 Commits
Author SHA1 Message Date
CatoandClaude c106673c24 feat(auth): every way in on AccountKit's own screens (#225)
/login, /register and /forgot-password are AccountKit's forms: password,
passkey, an email sign-in link, recovery, Continue with OrangeCat and the
shared bitbaum sign-in, each when its env is set. The profile settings
carry AccountKit's account panel (password, passkeys, two-factor, linked
sign-ins, deletion). compat passes screens: "accountkit" (AccountKit 0.20).

AccountKit is the only credential writer: Kivvi's registration, invite
sign-up, reset link and settings password change are removed, along with
the Auth.js runtime. A new person gets Kivvi's users row under the same id
and lands on /join; an invitation sends them through sign-up and back.
Deleting an account is refused before anything is deleted when the person
is named on kept business records or is the only owner of a company others
work in.

Migration 0039 (additive, idempotent) makes the panel's rename and deletion
reach users. The browser journey runs every method in CI against the
production build, with AccountKit's real mail caught by a sink.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-02 00:47:01 +01:00
CatoandClaude ab8fad1550 refactor(auth): use AccountKit's compat layer instead of a local copy (#212)
The next-auth/react bridge, its call helper, the session plumbing, the
AUTH_RUNTIME switch, the import rehearsal script and the journey-test cookie
client were copies of code five products each carried. They now come from
AccountKit 0.18.0:

- @bitbaum/accountkit/auth/nextauth-compat answers next-auth/react. The
  product's compat.ts holds only what is its own: the session shape, how each
  password form signs in, its login codes and hooks.
- @bitbaum/accountkit/auth/switch: sharedRuntimeEnabled().
- `pnpm run db:rehearse-import` runs AccountKit's accountkit-rehearse-import
  on this product's import SQL.
- The journeys use @bitbaum/accountkit/auth/compat-testing.

Behaviour is unchanged with the switch off. With it on, a signed-out session
reads as null, and a resolver or hook failure is a readable refusal rather
than a 500. The real-database journeys pass unchanged.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-01 11:53:06 +01:00
CatoandClaude Opus 5.5 405ba372d4 feat(auth): stage AccountKit beside Auth.js, switch off (#209)
* feat(auth): stage AccountKit beside Auth.js, switch off

Kivvi moves from Auth.js to @bitbaum/accountkit one reversible step at a
time, the same way evig did. This step adds everything the switch needs and
changes nothing while AUTH_RUNTIME is unset.

- Migration 0038: AccountKit's tables under an `auth_` prefix, plus the
  users <-> auth_users mirror functions, inert until attached.
- scripts/db/accountkit-import.sql: copies accounts under their own ids and
  bcrypt hashes byte for byte, refuses address collisions, drift or a live
  shared runtime, then attaches the mirror triggers. The rehearsal CLI always
  rolls back and prints only counts.
- apps/web/lib/accountkit/: the runtime (ids: 'uuid', legacy bcrypt, AccountKit
  0.16.0), a session reader in Kivvi's shape re-read from `users` and the
  membership on every request, and a bridge that answers next-auth/react.
  AccountKit's own credential endpoints stay closed: Kivvi's sign-up, reset and
  password change remain the only writers, and the triggers carry them over.
  Changing your own password keeps that session and ends the others.
- apps/web/lib/session-claims.ts: the company/role/onboarding rule, written
  once and used by both runtimes.
- The middleware has one routing function and two session sources, and runs
  on Node so it can read a database session.
- browser-smoke.yml runs the account journey once per runtime; the AccountKit
  leg first runs the rehearsal and the real-database journeys.

docs/ACCOUNTKIT-MIGRATION.md records what is left before switching.

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

* fix(web): load tailwindcss-animate by import; keep the switch-off password path unchanged

Node 24 loads tailwind.config.ts natively as ESM, where require() is not
defined, and next dev exited in the chatkit smoke. The settings password change
now uses a transaction only when it has a shared session to keep.

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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-01 08:32:07 +01:00
CatoandClaude 3e68dcb9aa fix(db): the migration chain replays onto an empty database as committed (#192)
0032_chilly_shatterstar re-added six columns that 0029_team_participation
already added (invitations/memberships.permission_preset,
users.location/languages/skills/availability_type), so a fresh install that
applies the files as written stopped at 0032. Those six statements now read
ADD COLUMN IF NOT EXISTS; the definitions in 0029 and 0032 are identical,
so nothing is lost by skipping them.

Safe on production: the deploy's applier (loki apply-schema.sh) already
rewrites every ADD COLUMN to ADD COLUMN IF NOT EXISTS before running a
file, so the SQL it would run for 0032 is byte-identical before and after
this change (same sha256), and it never re-runs a tag already in
_deploy_schema_history anyway. Drizzle's own migrator compares only the
journal timestamp, which is unchanged.

scripts/ci/apply-migrations.sh drops its ADD COLUMN rewrite and applies
the committed files verbatim, so CI now catches a migration that only
replays with help.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-30 12:16:42 +01:00
CatoandClaude 93ab5ec70c ci(browser-smoke): prove an account can be made and used (#189)
A new `account` job in browser-smoke.yml drives real Chromium against the
production standalone server and a PostgreSQL built from the committed
migrations:

- sign up as a new organisation, finish onboarding (company info, business
  setup, start fresh) and land on the dashboard; the company, its onboarding
  stamp and the owner membership are checked in the database;
- sign out from the user menu; the session is gone and the dashboard asks
  for sign-in;
- a wrong password and an unknown email are refused, with no session;
- sign in and reach the dashboard;
- set a company AI key through the settings form, then check that the key
  field holds only the mask or nothing, that no response of the settings
  page carries the key, that it is stored sealed, and that saving with the
  mask keeps it (guards #185).

scripts/ci/apply-migrations.sh applies the chain to the throwaway database.
The committed chain does not replay onto an empty one (0032 re-adds six
columns 0029 added), so ADD COLUMN is read as ADD COLUMN IF NOT EXISTS; the
migration files are unchanged.

The journey stays on the sign-in page between attempts because /login
allows 10 requests a minute per address.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-30 11:29:28 +01:00
CatoandClaude Opus 5 935a9902cf fix: stop committing one laptop's home directory into the repo (#97)
Two absolute paths from a single machine were checked in, so anyone who
clones kivvi inherits them:

- .husky/pre-push hard-coded /home/g/dev/loki for both the CI gate and the
  deploy script. The hook is committed, so every clone gets a pre-push
  pointing at a stranger's home directory; on any other machine both bash
  calls fail. Resolve the path at run time from DEV_ROOT (the variable
  loki's scripts/hetzner/_box-env.sh uses as the source of truth for the
  checkout root), falling back to $HOME/dev. The generated block and its
  markers are otherwise unchanged.

- scripts/fix-line-items.ts pinned EXPORT_DIR to /home/g/dev/kivvi/...,
  which cannot be right for anyone else. It now reads KIVITENDO_EXPORT_DIR
  or falls back to the repo-root-relative kivitendo-export/ - the same
  __dirname pattern the sibling scripts already use. The existing
  "AR file not found: <path>" guard prints the resolved directory, so a
  wrong or missing export dir still fails loudly.

Verified: sh -n and bash -n on .husky/pre-push, prettier --check on the
changed TypeScript.


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

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 00:54:32 -07:00
GandClaude Opus 5 afbe985e53 chore: add a formatter (#64)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false 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 (759 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): resolve the lockfile with the pnpm major CI runs

The previous commit regenerated pnpm-lock.yaml with local pnpm 11, which
re-resolved the `github:catomean/ai-forms` shorthand from a codeload tarball
to git+ssh. CI runs pnpm 9, which cannot read that entry — and could not fetch
over SSH even if it could, having no key. The lockfile was valid on the machine
that wrote it and broken everywhere else.

Resolved with pnpm 9 instead. The rollout script now derives the major from
packageManager/PNPM_VERSION and refuses any lockfile that gains an ssh-form
resolution.

* fix(ci): resolve ai-forms over https, not ssh

pnpm records whichever transport it could use when the lockfile was written.
This laptop has an SSH key, so pnpm wrote git+ssh; CI has none and the install
died on 'Permission denied (publickey)'. Resolving with GIT_SSH_COMMAND=/bin/false
reproduces CI's capabilities and yields git+https, which needs no credentials
for a public repo.

* fix(ci): keep the lockfile byte-identical apart from the pin

kivvi already depended on prettier, so this PR is script wiring, not a new
dependency — and it should not have rewritten the lockfile at all.

Regenerating it re-resolved the `github:catomean/ai-forms` shorthand three
different ways, none of which CI could use: git+ssh (no key on the runner),
then git+https (fetches, but pnpm's virtual-store path for a git dep failed to
import). Only main's original codeload tarball works. The resolution recorded
in a lockfile depends on what the machine writing it could reach, which makes
'it resolved fine locally' worth nothing.

So: restore main's lockfile and change only the specifier, which is what
--frozen-lockfile actually compares, and format with 3.8.0 — the version this
repo's own lockfile already pinned — rather than dragging it to the fleet's
3.9.6 and reformatting against a version it does not install.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 10:31:23 +00:00
GandClaude Opus 5 181e7ef49b ci: call the central auto-merge sweep instead of carrying a copy (#44)
auto-merge-sweep.sh was copied into 22 repos and drifted into EIGHT distinct
versions, 245 to 404 lines. Three of them independently grew different fixes for
real outages, and each fix reached only the repo that wrote it:

  evig, revampit   infra-failure detection + re-run. An Actions incident left
                   main "failure" with no failed job at all; 11 PRs stranded
                   for roughly 14 hours.
  fleetcrown       DEADLOCK naming — a red base with the repairing PR sitting in
                   the queue was indistinguishable from "nothing to merge".
  the other 19     neither.

Nothing could carry a fix across, so every repo waited to hit each outage
itself. This repo now calls the canonical sweep in maonakamoto/dotfiles, and the
local copy is deleted.

The canonical is the union of the three, built on the variant ten repos were
already running rather than on the longest one — the 404-line variant is missing
the step-summary reporting the 296-line one has, so "take the biggest file"
would have silently deleted working behaviour. The merge was 106 insertions and
zero deletions: nothing can be lost by adopting it.

The triggers stay in this file because they genuinely are per-repo: workflow_run
must name the CI workflow exactly, and that name differs across the fleet.

Two details that are silent when wrong, both found by piloting rather than
reasoning:

  rearm_workflows is SPACE-separated. The sweep word-splits it; a comma makes
  one bogus token, every dispatch fails, and the only symptom is that nothing
  deploys — while the sweep still exits 0 and reports a successful merge.

  permissions are declared on the CALLER as well. A called workflow's token is
  capped by what the caller grants, so relying on the callee's block alone can
  hand it a read-only token; the sweep would then merge nothing while exiting 0,
  which is indistinguishable from having nothing to merge.

Verified before this rollout: the canonical ran end to end in dotfiles' own CI,
and the reusable-workflow path ran end to end in the pilot repo (s-ink).

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 14:57:50 +00:00
G a03cf42e72 fix(ci): declare the failing-job list before the branch that can skip it (#42) 2026-08-07 09:58:08 +00:00
G 73085dfd0b fix(ci): a red base must not trap the PR that repairs it (#41) 2026-08-07 09:39:42 +00:00
G 9baddd5472 fix(ci): stop skipping conflicts, and keep branches current (#39) 2026-08-07 07:18:20 +00:00
GandClaude Opus 5 9250a25d49 fix(ci): drain the merge queue oldest-first, not newest-first (#37)
`gh pr list` returns newest-first, and the sweep merges the first eligible PR
then stops. So the newest green PR wins every sweep, and an older one can wait
indefinitely.

Observed in maonakamoto/fleetcrown on 2026-08-06: two consecutive sweeps merged
the two newest PRs while three older green ones sat untouched and were never
even evaluated. With several agent sessions opening PRs continuously that is
starvation — and it starves the worst candidate, since the longest-waiting PR
is the one whose checks were proven against the most now-stale base.

PR numbers increase monotonically with creation, so sorting ascending is FIFO.
The ordering was never a decision, just whatever gh happened to return.

Fixed upstream first (fleetcrown #182) and verified in production there: the
sweep immediately after it landed correctly took the oldest open PR rather than
the newest. This is that one-line change, applied to the fleet.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 13:44:28 +00:00
G 0c9774cfbf ci: green PRs merge and deploy themselves (#36)
* ci: add the auto-merge sweep policy

* ci: green PRs merge and deploy themselves

* ci: allow CI to be dispatched so auto-merge can re-arm it

* ci: allow deploy to be dispatched so an automated merge still ships
2026-08-05 19:16:59 +02:00
GandClaude Opus 4.8 7ecb257ff8 chore(infra): remove Vercel references — self-hosted now (#33)
Vercel is fully decommissioned; kivvi.orangecat.ch runs self-hosted on the
Hetzner box behind Caddy (build → rsync → systemd restart). This repoints or
removes every LIVE Vercel reference:

- DB driver (packages/database): drop the dead `process.env.VERCEL` branch in
  createDb(); the Neon serverless driver is now selected solely by USE_NEON,
  preserving self-host behavior (VERCEL was always undefined).
- Dead kivvi.vercel.app fallback URLs → kivvi.orangecat.ch (intake label pages).
- Cron routes: "Vercel Cron" → system cron (self-hosted); webhook-retry no longer
  points at the removed vercel.json.
- next.config.js: drop Sentry automaticVercelMonitors (no Vercel crons to monitor).
- docs/DEPLOYMENT.md: replace "Option A: Vercel + Neon" with the self-hosted
  Hetzner (Caddy + systemd) production reality; fix the DB-driver/env-table/Neon
  sections and upgrade/troubleshooting notes. Neon-via-USE_NEON stays documented.
- Remove apps/web/vercel.json, the .vercel gitignore entries, and the VERCEL_URL
  .env.example var.
- set-org-profile impact-hub URL and bug_report deploy-target list de-Vercel'd.

Kept: the .husky/pre-push `env -u VERCEL` guardrail (defensive env strip).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 21:54:22 +02:00
Mao NakamotoandClaude Opus 4.8 fed9edea18 feat(revamp-it): service-sale bridge, payment triage & labor leakage
Complete the revamp-it ERP-companion roadmap (items 4–6, 8) and close the
new-code review findings.

Money-path bridges (roadmap 4–6, acceptance 4–5):
- recordServiceSale + POST /api/v1/services/sales: book any paid revamp-it
  service flow (workshop, appointment, IT-Hilfe, other) as one service invoice
  + one payment routed to service revenue (3200), in a single transaction.
- Idempotent by natural key: durable invoice marker (survives key pruning) plus
  a concurrency claim on the existing unique-constrained apiIdempotencyKeys
  table — DB-enforced single booking, no schema migration.

AI-assisted ERP (roadmap 8):
- classifyMoneyIn + classify_payment tool: deterministic, advisory triage of
  unclear money-in (sale/donation/grant/refund/pass-through/manual_review);
  donation/grant/refund/pass-through always flagged for Treuhänder confirmation.
- findUninvoicedRepairLabor + find_uninvoiced_repair_labor tool: surface logged
  repair hours still in stock and unbilled (revenue leakage) with suggested
  amounts.

Supporting:
- getOrCreateServiceProduct extracted from repair-labor (DRY); repair-labor now
  delegates to it.
- Integration-health dashboard section + workflow hub (ERP projection
  diagnostics), production smoke script, French i18n parity (52 keys).
- Roadmap status doc.

Money math uses decimal.js throughout. 1110 core + 104 ai tests pass;
type-check, lint, and build clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 10:26:27 +02:00
g-butandClaude Opus 4.6 2b55476c83 docs: add Kivitendo migration checklist and CSV validation script
- MIGRATION_CHECKLIST.md: step-by-step guide for Swiss SME migration
  from Kivitendo (German), covering CSV exports, import order, and
  verification
- validate-kivitendo-csvs.ts: standalone script that validates CSV
  exports against mapping profiles, reports data quality issues

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 13:43:29 +01:00
g-butandClaude Opus 4.6 13403eb0a1 feat(import): fix invoice line item import from Kivitendo CSV
Kivitendo CSV exports store line items as extra columns beyond the CSV
header. Previously PapaParse in header mode dropped these columns,
resulting in ~3100 imported documents with no line items.

Changes:
- CsvUploader: switch to array-mode parsing, pass raw rows through
- StepDataImport: extract structured line items via parseKivitendoLineItems
- buildProductLookup: return {id, unitPrice} instead of just id
- bulkInsertDocuments: calculate proper unitPrice from product catalog
- Add repair-import settings page for backfilling existing documents
- Add repairDocumentLineItemsAction server action
- Fix all hardcoded i18n strings (Export CSV, Data Tools, Repair Import)
- Add defaultDocumentFooter to CompanySettings
- Extract PDF data builder to shared utility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 14:02:45 +01:00
g-butandClaude Opus 4.6 4956b434f1 chore: add data cleanup script and browser test findings
Add cleanup-import-data.ts for deduplicating Kivitendo import data
(products, invoices, warehouses, stock). Add BROWSER_TEST_FINDINGS.md
documenting 20 issues found during manual testing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 22:40:21 +01:00
g-butandClaude Opus 4.6 3d892c8213 refactor(import): consolidate kivitendo import into single comprehensive script
Replaces fragmented import-kivitendo-data.ts and import-real-data.ts with a
single import-kivitendo.ts that handles all 14 import steps with proper FK
dependency ordering, dry-run support, and Swiss number/date format handling.

Adds contact address and project bulk insert functions to import-bulk.ts,
plus vendor/project/GL/stock mapping profiles to import-mappings.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 10:19:00 +01:00
g-butandClaude Opus 4.6 5dca958eae fix(security): upgrade Next.js 14.2.0 → 14.2.35 to patch critical CVEs
Fixes GHSA-f82v (auth bypass in middleware), GHSA-gp8f (cache poisoning),
and GHSA-7gfc (authorization bypass). Also adds gitignore rules for
customer data exports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 10:18:34 +01:00
g-butandClaude Opus 4.6 f4799d6ae5 fix(import): parse Kivitendo line items from extra CSV columns
Kivitendo exports put line items as extra columns beyond the CSV header.
PapaParser in header mode dropped them, leaving 822 documents with broken
or missing items. This adds array-mode CSV parsing to extract structured
line items and a one-time fix script that repaired all 660 AR invoices
and 162 AP purchase invoices (1,681 total items, 0 errors).

- Add parseKivitendoLineItems() to import-mappings.ts (pure, client-safe)
- Add missing units to mapUnit(): psch, Jahr, Tag
- Extend bulkInsertDocuments() with optional structuredItems parameter
- Add scripts/fix-line-items.ts one-time data fix (already executed)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 22:34:36 +01:00
g-butandClaude Opus 4.6 d14779669e feat(i18n): add complete internationalization with next-intl v4
Integrate next-intl v4.8.2 for full i18n support across the app with
three locales (de-CH, en, fr). Create message JSON files with 20
namespaces covering all UI strings. Convert hardcoded German/English
strings to translation calls. Add language switcher component. Fix
pre-existing TypeScript errors in banking, documents, auth, reports,
chat, bulk-import, and document-form modules to achieve clean type-check
and successful production build.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 17:32:03 +01:00