T
Sign in

STATUS.md — project state & how to resume

STATUS.md — project state & how to resume

One-page handoff. Everything referenced below lives in this repo — if this conversation is compacted or you start a new one, read THIS file first, then the pointers.

What this is

The greige-fabric manufacturing platform (yarn kgs → sizing/beams → weaving → checking/grading → dispatch), both profit centres (trading + job-work) in one event-journal system. Built on the org stack: Bun · SvelteKit 3 (@sveltejs/adapter-bun) · Drizzle · libSQL (Turso) · daisyUI · Better Auth. Live on Cloudflare Pages at https://trading-tyno.pages.dev (app login only; /signin is the door) with docs viewer (/docs), screenshot drop (/upload, also downloads), and the exhaustive flow map (/full-flow.html + PDF). The old tunnel hosts (trading.tynolabs.com, dsh.tynolabs.com, terminal.tynolabs.com) were retired on 2026-11-03; only ssh.tynolabs.com is left on the tunnel.

Governance rules (the repo rules)

  1. Rule 0 — commit + push after every change (deploy or docs). Deploy is push: master is wired to Cloudflare Pages (trading-tyno), so a push builds and publishes https://trading-tyno.pages.dev. There is no deploy host any more (retired 2026-11-03); deploy.sh is the legacy path for a self-hosted Bun checkout and exits 3 elsewhere. Locally run bun scripts/dev.ts (loads .env, then Vite) and commit + push.
  2. Rule 1 — light mode only: src/app.css pins themes: light --default (daisyUI v5 auto-ships dark mode otherwise); no second theme, no prefersdark flag, no dark toggle; remove dark-mode config anywhere.
  3. Rule 2 — every solved edge case gets a regression test (same commit, named after the case; suite in tests/, see docs/TESTS.md).
  4. Rule 3 — passing tests is as important as commit+push: bun test must be green before commit/push. Decisions are logged in docs/PLANNING.md (agreed-revisions log; latest entry: §97). Deploy = git push origin master (Pages builds master).

Standing caveat (owner): the EXISTING inventory system is buggy and haphazardly built — its numbers/formats are taken with a grain of salt. Everything derived from it is indicative: verify before trusting, ask the owner when unsure.

Flow review status — A→F SIGNED

Stage Signed How
A Commercial ✓ two order paths, prefill rules, market dhara, amendments, hishob-per-contract
B Yarn ✓ gatepass/direct-delivery intake, booking(trading only), park-lot, warp/weft soft tag, party loan, reservations
C Warp prep ✓ beam-out intimation→guard taps, warping+tippan (krill/parts), sizing receipt (photos+OCR), out-house ledger, flange-vs-beam no
D Weaving ✓ planning board (Excel-derived), weft issue, loomgate telemetry adapter, beam-end reasons/cut processes, knot/gat
E Checking ✓ mending=grade source (A/B/C/R), WIP-bucket→FG, rolling/folding, lumps→bales, checking report (L2L, RS, approvals)
F Dispatch ✓ delivery plan/slip/tracking; F4 Tally + hishob-for-reports deferred to reports freeze

The complete map (forms inline, every field mode-annotated): static/full-flow.html (in-app) + screenshots/FULL-FLOW-A3.pdf (stored; regenerate via the generator when flow changes).

Source-of-truth docs (read these, in order)

  1. PLANNING.md — the flow (A–F) + all agreed-revision logs; §13 pending-inputs shelf; §6-11 stage designs.
  2. BUSINESS.md — domain model, stock/apportionment, order rules, alleys (beam/warp/weft legs), bales, loans, L2L.
  3. COSTING.md — conversion/costing engine (verified cell-by-cell; K = Lasa/L2L resolved).
  4. FIELDMAP.md — every screen's fields + terminology glossary + open questions.
  5. YARN-FLOW.md — per-mode yarn flow charts.
  6. ARCHITECTURE.md (one journal/two books) · PLATFORM.md (staged scale) · BRIDGE.md (file interchange) · DASHBOARDS.md (boards + catalogue index) · ROADMAP.md (phases: planning gate → foundation → MVP…) · MIGRATION.md (old-system data model → new map; backup intake via /upload-backup).
  7. REPORTS.md — report placement, exceptions & approvals catalogue (no silo; report = finished product) + valuation brief (FIFO vs weighted-avg).
  8. DUMPS.md — universal form-dump station (MUST): every form exports raw records to Excel/CSV with its own filters; the dump loop (recurring export → build in-system → retire).
  9. DESIGN.md — the design system (Textile ERP NextJS reference): tokens, typography, layout, component inventory, auth pattern and the conformance checklist (UIPATTERN.md implements it screen by screen).
  10. COMPLETION.md — the master completion checklist of the complete-to-spec build program (PLANNING §97): every phase/slice with honest status, the Definition of Done, the verification-sheet contract, and the findings ledger. Nothing is "done" until owner-signed.
  11. FOCUS-ENTRY.md — the mobile-first entry-form pattern the owner signed (§211–226): summary page + one-field wizard + number wheel/stepper + animated-tick save popup + haptics/sound. Reference: src/routes/leads/new. Read this before restyling any entry form.

Pending inputs from the owner (shelf — PLANNING §13)

Migration backup RECEIVED 2026-09-03 (backups/, SQL Server .bak — scrape first pass done, MIGRATION.md §10; table-level exports pending for exact rows/columns — MIGRATION §10.5) · manual checking-report sample · job-work hishob statement + received slips (statement received+decoded 2026-09-02 — REPORTS.md §2.1; OCR slips still pending) · remaining gatepass photo samples · beam card copy · all slips/formats · reconciliation formats (sizer/winder/weaver) · valuation method (FIFO vs weighted-avg) · GST config per supplier · numbering- sequences decision · LTOL/UTL + cal-wt + "Booking Entries" + promise-vs-target-date · E leftovers (defect-master values, reject path, WIP-remainder rule, grade pricing).

CURRENT PROGRAM — complete-to-spec build (PLANNING §97 · docs/COMPLETION.md)

Owner-agreed operating course: dependency-ordered phases 0–8 (foundations → database → engine → shared platform → transactional spine → read models → capture/OCR → integrations → hardening/cutover); deepseek-v4-flash only; rebuild-to-spec (KEEP/REBUILD per piece, recorded); Definition of Done (six checks); per-phase plain-language Verification Sheets the owner signs. Live status: Phase 0 DONE-VERIFIED (owner-signed 2026-09-06) — event-logging invariant deployed (BUILD-LOG rev 47), 10-min spot-check passed and Verification Sheet signed (PHASES-GUIDE check steps, BUILD-LOG rev 50); F0-7 role-gating deferred to project end by owner decision (PLANNING §98). PHASE 1 ACTIVE (the intended next phase — PLANNING §109): audit PASSED (tenancy 27/27 · migrations 0000–0008 zero-drift · imported data intact · masters 5/5 KEEP with Design gaps fixed · migration 0009 applied incl. evt dedupe index). Verification Sheet: docs/VERIFICATION-PHASE1.md; value sets: docs/VALUE-SETS.md. AWAITING OWNER: 10-min check + sign + two decisions (GSTIN · bale/lump). Phase 2 ENGINE ROUNDS 1–4 DONE + deployed (yarnMath to-sheet ≤0.003%, warping line, per-row GST toggles/spec 6b, tippan guards+slack, capture G0/G0b fields, ops role/transaction guarantees; suite 126 green, journey 53/53) — Verification Sheet drafted at docs/VERIFICATION-PHASE2.md, AWAITING OWNER 10-MIN CHECK + SIGN (quote == costing sheet). Four owner decisions flagged there (numbering · cone-measure · amendment semantics · per-row GST UI). Next: owner sign-off, then Phase 3. The sections below are the historical state this program builds from.

NEXT AREA — dashboards FROZEN · PRODUCTION begins (history)

WORK-SURFACE PASS STARTED (2026-09-04, PLANNING §51): owner: "current UI is useless for an actual ERP" — agreed full work-surface pass (finding records, work verbs, desk density, entry ergonomics; docs/UIPATTERN.md "The work surface"). Sequence: 1 List standard (ListToolbar + SmartTable rollout) → 2 record pages + amend/approve/print → 3 global search (/search?q=) → 4 entry comboboxes + duplicate confirm → 5 density + batch + CSV. Each item ships docs-first, build green, deployed, live-verified. UI PASS 01 done (2026-09-03, PLANNING §45): app shell + theme followed the GrayFabric ERP reference UI (github.com/skpawar1305/gray_fabric_erp) — grouped light sidebar (lucide icons, blue active states, mobile drawer, user chip + sign-out), blue primary, slate neutrals, crisp radii, larger text, table hover bar. UI PASS 01b (2026-09-04, PLANNING §52): the owner changed the UI reference to Textile ERP NextJS (github.com/skpawar1305/textile- erp-nextjs) — shell re-skinned (white rounded-xl sidebar, indigo-100 active pills + indicator line, glassy sticky header with user chip + gradient avatar, collapsible to an icon rail, Logout back in the footer) and theme re-tuned (zinc-100 workspace, indigo-600 primary, 20px card radius, Inter, zinc-50 table headers); daisyUI light pin + tests intact. All screens converted (2026-09-03, §47→§48, BUILD-LOG rev 7/8): every route now uses the reference visual language, each designed for its job (docs/UIPATTERN.md) — lists = bordered table cards + empty states + counts; entry screens = form-first labeled cards; queues = tap-friendly action cards; all page-level navbars gone (shell owns navigation). Pre-existing /tippans/new 500 fixed en route (data.tips?.[0]). Dashboard design is settled "mota-mota" (rounds 27–43, 2026-09-02). The spec is docs/BOARDS-A.md (drill pattern, full page inventory, global rules, approval/control flows, per-user compositions) with the interactive reference at /board.html (all sections, component pages, per-user dashboards; every component carries a hover one-liner + ⓘ What·Data·Who, period bars, dumps, WhatsApp links, AI bot). Cross-cutting standards live in DASHBOARDS.md §5.

BOARDS-A dashboard slice LANDED (2026-09-03, PLANNING §50, BUILD-LOG rev 9): the home is now the master dashboard — period bar · attention strip · all nine section card grids · per-role composition (owner full; planner/godown/checker/production/guard/sales land on their own minimal board) — with 24 component pages at /board/[slug] (ⓘ What·Data·Who, KPI stats, sortable/searchable/filterable SmartTables, per-component CSV dumps at /api/dump?slug=). Every number is a real query; components that need later-phase data are flagged, never faked. Next slices: realtime hub (SSE/WS) + SmartTable standard rollout to the older list screens.

Production starts NEXT per ROADMAP Phase 1 (foundation): masters + conversion engine + tenancy seams + event backbone + realtime board shell (bun:sqlite), then slices. Open decisions that don't block (BOARDS-A §8): valuation FIFO/avg (REPORTS §6) · numbering sequences · grade pricing · promise-vs-target calendar · Tally dues · AI bot phase · planning-board detail (production-time).

OVERNIGHT FULL BUILD (2026-09-05, PLANNING §57–§67)

"Build the WHOLE system, no phase-wise nothing" — done in one continuous run, deployed live in 11 slices (BUILD-LOG revs 16–26). New since the last daily build: realtime hub (SSE live dashboard strip) · global search (shell box + /search) · record pages with amend/print verbs (orders, gatepasses) · OCR everywhere (/api/ocr tesseract + vehicle- plate camera buttons; /api/capture auth-gated with image drafts; drafts thumbnails) · yarn rate board (manual + booking prefill) · procurement suggestion (/procure) · reports slice (open POs, SO vs delivery, stock & allocation + CSV dumps + print CSS) · loomgate telemetry adapter + simulator + live weaving card · WhatsApp share + external confirmation links (/c/gp, /c/hi; no Business API per owner) · leads pipeline (convert→SO) · entry combobox + duplicate hint + voice entry on orders/new · tenancy seams (migration 0006). Plus the Trading Capture Android APK (android-capture/, §56: notification listener + overlay + share, better-auth login — builds via ./gradlew assembleRelease on any machine with Android Studio). Deferred only where the owner/hardware must decide: valuation method, F4 Tally wiring, signing keys, party phone numbers, real device IDs. OVERNIGHT QA (2026-09-05, PLANNING §57–§76, BUILD-LOG rev 28): the full QA program closed — 53-step live journey suite (scripts/journey-test.ts, runs every documented flow with a real session + DB asserts + print markers), 11-role operation simulation drove out and fixed the anonymous- write + role-gate + silent-transition + meters-0 + confirm-link bugs, and every printable document was rebuilt to the provided formats (gatepass per-kind, hishob In/Out/Consumption §2.1, dispatch/packing, beam card, checking report, tippan, contract/SO, reconciliation — all on the COMPANY head w/ GSTIN slot). Remaining ledger + owner gates live in docs/QA-GAPS.md.

How to resume (anywhere)

  1. git pull --rebase --autostash (and re-pull every now and then — parallel sessions land constantly — and always pull again right before committing; deploy.sh pulls itself as step 0/6). If the pull conflicts, resolve all conflicts automatically (never hand them back to the user). 2. Read this file. 3. Read PLANNING.md logs + the referenced docs for the area you're continuing. 4. Owner provides shelf items as they go. 5. Continue the per-point review protocol (sign-off per point).

Correction builder — REMOVED (2026-11-04)

The corrections board, the row line, the /queue screen and everything that ran them were removed on the owner's instruction (PLANNING 747): row-watch.sh and its health/lane checks, queue-next.ts, row-run.sh, the queue-watch service, contract-gate-check.ts, status.sh / line-status.sh, queueBoard.ts, watcher.ts, /api/watcher, agent row.md, and the /queue route.

Work is applied directly: the owner asks for a change in chat, one session writes it, gates it (bun run check + bunx tsc --noEmit), commits and pushes. docs/QUEUE.md, docs/QUESTIONS.md and the sections below are kept as history; nothing reads or rewrites them any more.

State 2026-09-27 (evening) — survival pass done, board nearly empty

Owner asked why "a single small task is killing the cpu" and whether the process should be started over. Measured the agent session store: 80 swarm sessions, 420M tokens, 18 rows closed (~23M tokens/row); the median agent turn re-sent 57,069 tokens to produce 119 tokens of output. The gates were never the cost (full suite = 54 s wall / 10 s CPU) — context re-read was (PLANNING §310).

  • Host freed: 2 orphaned vite dev servers were holding 1.07 GB of 6 GB with swap at 507/512 MB. Available memory 3616 → 5272 MB, swap 507 → 110 MB. swarm.sh now reaps them each round. swapoff is impossible here — the swap device is none/virtual (no backing file), so there is nothing to empty.
  • Cost fixes shipped (14a244f): scripts/quiet.sh (check/build output 2047/5120 lines → 31, exit code + error lines preserved); grep-don't-read rule for PLANNING.md/BUILD-LOG.md; many-rows-per-session rule.
  • Budget now billed on shipped work, not attempts (six no-op rounds burned 6 slots between 05:32 and 05:37).
  • Fixed .gitignore typo /.swarm-lock → /.swarm.lock (untracked + unignored ⇒ dirty tree ⇒ swarm.sh refused to run, blocking every round).
  • C99 payment-terms UI work is SHELVED on stash@{0} (7 files, incl. the untracked test). The schema half was deliberately KEPT and committed as 23d5ab3 because data.db already carries payment_term_id + payment_dhara — stashing it would have made the next drizzle-kit push drop both columns. Restore with git stash pop when C99 is picked up again.
  • Incident: pkill -9 -x bun during cleanup killed the production server (the live app is bun run build/index.js, also ppid 1). Restarted in <1 min, no data impact. The reaper now excludes it by name, with a test that fails if that exclusion is removed.
  • Board: 18 done, 8 pending, 3 verify, 1 reopen. Watcher is disarmed (.queue-auto removed) and stays that way until the owner arms it.
  • Decision reached, not yet executed: do NOT rewrite yet. The board has only 8 rows left, and an idle machine costs nothing. Drain the board first, then rewrite the queue (markdown ledgers → a DB table; one long agent session per feature area instead of one per row; verification as one script over all 69 routes instead of an agent per row) when the board is empty and nothing is at risk.

State 2026-09-27 (late afternoon) — C99 + 4 more rows live, two gate defects fixed (PLANNING §313)

  • Shipped: C99 (payment terms as one input, b666548), then C100, C102, C112, C71 (ce417ec) — one-focus-field popups, three type-fixed order forms, order dictation, carried-quote precedence. Live-check 29/29.
  • Board: 22 done, 4 verify, 4 pending (C113, C114 pending; C71, C80, C103, C104 verifying). Nothing stranded — every doing claim released.
  • Builder stays OFF (.queue-auto absent). Both batches were run by invoking swarm.sh run directly, once, never armed — the daemon can no longer fire rounds by itself.
  • Cost, measured for real: ~4.2M tokens/row, was ~23M (5.5× better); one session did 3 rows instead of 3 sessions doing 1. 98.5% of tokens are context re-read — the agent re-sends its whole conversation every turn. quiet.sh cannot touch that, and reusing one session across rows makes it worse (row N carries rows 1..N-1).
  • Two defects, each of which silently ate a whole round (both fixed, both mutation-checked):
    • swarm.sh gate tested ROOT's quiet.sh but ran it in the worktree → every worker gate-failed on a missing file after green tests.
    • deploy.sh pulled with git pull --rebase, which drops merge commits and discards conflict resolution — it reverted a repaired test file and reported success. Now --rebase-merges.
  • bun run check and the 2,709-test suite both pass a .svelte file with unbalanced blocks or a redeclared let; only vite build rejects them, and it runs once per round. New scripts/svelte-syntax.ts runs the same compiler over the changed .svelte files in the worker gate — 1.4 s vs 61 s CPU — so a stray {/if} no longer costs a round.
  • GATE RULE earned here: a .svelte change is not verified until bun run build is green. A fix ships on check + a targeted test alone only at your own risk — that mistake cost a 20-minute round on 2026-09-27.
  • Stale worktrees archived to archive/swarm-ws{1,2,3}-2026-09-27 (nothing lost) and rebuilt from master. swarm.sh only creates a worktree, never refreshes it — that is why they were 8 h stale and why they conflicted.
  • Still not started, on purpose: the queue rewrite (markdown → DB table, session-per-feature-area, one script over all 69 routes). 4 rows do not justify it. Finish C113/C114 in-session, then do the rewrite against the measurements above — context reset between rows, cheap template gate, and a ship gate that keeps the build because the cheap gates provably cannot see what it sees.