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
2 changes: 1 addition & 1 deletion .claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ against.
- `comment-hygiene-patterns.txt` — the canonical change-narration/ticket-reference pattern list, read at runtime by `hooks/post-edit-comment-check.sh`, `.husky/lib/comment-hygiene.sh`, and `.github/workflows/ci.yml`'s `comment-hygiene` job instead of each hardcoding its own copy; first 10 lines are anchored keyword patterns (feed all three surfaces), last 3 (date/ticket/issue reference) are lower-precision and feed only the two warn-only surfaces, not the CI hard gate
- `harness.json` — harness manifest (its `review_note` points at `docs/meta/templatecentral-adoption-log.md`, and the `AGENTS.md` `origin_hash` tracks the slimmed file; the hook-by-hook reference is `docs/meta/ai-harness-reference.md`): templateCentral version/stack/adaptation metadata, plus `seeded_files` — the enforcement-layer file list (path + sha256 `origin_hash`) that `verify-harness.sh` diffs against
- `hooks/`
- `regen-harness.sh` — human-run-only: rewrites every `origin_hash` in `harness.json` to match current on-disk content, blessing an intentional harness edit; `protect-files.sh` requires human approval before an agent can even edit it (most recently re-run 2026-11-10 after the AGENTS.md skills-table edit)
- `regen-harness.sh` — human-run-only: rewrites every `origin_hash` in `harness.json` to match current on-disk content, blessing an intentional harness edit; `protect-files.sh` requires human approval before an agent can even edit it (most recently re-run 2026-12-02 after the `ci.yml` mutation-filter edit)
- `settings.json` — wires each script in `hooks/` to a Claude Code lifecycle event (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, UserPromptSubmit) and sets tool `permissions` (allow/deny) and skill overrides
- `skills/`
- `verify-harness.sh` — harness integrity sensor: computes sha256 from committed HEAD blobs for every seeded file matched by a path guard (`hooks/`, `settings.json`, harness verifier/regen scripts, `.husky/`, `.gitleaks.toml`, `.github/workflows/`) and compares to `harness.json`'s `origin_hash` baseline; read-only, exits non-zero on drift; run by `.github/workflows/ci.yml` and husky's `pre-push` hook
Expand Down
4 changes: 2 additions & 2 deletions .claude/harness.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"richReadme": true,
"seeded_files": {
"AGENTS.md": {
"origin_hash": "eb921107a858d512b9778f925bbd3a47c71a04bb569d807f10b38417037f955c",
"origin_hash": "0ff7c4173834e166903ea2434408c1660c22a8f9371604d0ba6f91c3eaf61b78",
"path": "AGENTS.md"
},
".claude/settings.json": {
Expand Down Expand Up @@ -100,7 +100,7 @@
"path": ".gitleaks.toml"
},
".github/workflows/ci.yml": {
"origin_hash": "c84a211fb37ec23cbe9d83c37c80971f722de3c1d7151b388838ca15537517ed",
"origin_hash": "bb626e231a4a872300a034bef0ac9524a35b4eedf190756385f74712a560225e",
"path": ".github/workflows/ci.yml"
},
".claude/verify-harness.sh": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ security scanning.

## Contents

- `ci.yml` — main CI pipeline, four jobs plus three PR-only gates: harness integrity (`.claude/verify-harness.sh`), `pnpm check`/`pnpm exec vitest --run --coverage`/coverage with an 80% changed-line gate (`diff-cover`); a separate `next build` job with dummy Supabase env vars; a Playwright e2e smoke job; a CHANGELOG-required-for-`src/`-changes gate (`skip-changelog` label bypasses); a README-freshness gate requiring every changed folder's `README.md` also be in the diff (`skip-readme-check` label bypasses) — the CI-time counterpart to `.husky/lib/readme-coupling.sh`'s commit-time nudge; a comment-hygiene gate scanning only the PR's added lines (`git diff -U0`) for change-narration comments, using the first 10 (hard-precision) lines of `.claude/comment-hygiene-patterns.txt` (`skip-comment-check` label bypasses) — the CI-time hard gate counterpart to `.husky/lib/comment-hygiene.sh`'s commit-time warn-only nudge and `.claude/hooks/post-edit-comment-check.sh`'s live edit-time nudge, both of which scan the full 13-line pattern file. Also a `db` job (migrations + pgTAP RLS) and a PR-only, advisory `mutation` job that Stryker-mutates whichever `src/lib/*.ts` files the PR touched — its changed-file diff uses `--diff-filter=d` so a PR that only _deletes_ a `src/lib` file (nothing left to mutate) doesn't crash the job trying to mutate a file that no longer exists.
- `ci.yml` — main CI pipeline, four jobs plus three PR-only gates: harness integrity (`.claude/verify-harness.sh`), `pnpm check`/`pnpm exec vitest --run --coverage`/coverage with an 80% changed-line gate (`diff-cover`); a separate `next build` job with dummy Supabase env vars; a Playwright e2e smoke job; a CHANGELOG-required-for-`src/`-changes gate (`skip-changelog` label bypasses); a README-freshness gate requiring every changed folder's `README.md` also be in the diff (`skip-readme-check` label bypasses) — the CI-time counterpart to `.husky/lib/readme-coupling.sh`'s commit-time nudge; a comment-hygiene gate scanning only the PR's added lines (`git diff -U0`) for change-narration comments, using the first 10 (hard-precision) lines of `.claude/comment-hygiene-patterns.txt` (`skip-comment-check` label bypasses) — the CI-time hard gate counterpart to `.husky/lib/comment-hygiene.sh`'s commit-time warn-only nudge and `.claude/hooks/post-edit-comment-check.sh`'s live edit-time nudge, both of which scan the full 13-line pattern file. Also a `db` job (migrations + pgTAP RLS) and a PR-only, advisory `mutation` job that Stryker-mutates whichever `src/lib/*.ts` files the PR touched — its changed-file diff uses `--diff-filter=d` so a PR that only _deletes_ a `src/lib` file (nothing left to mutate) doesn't crash the job trying to mutate a file that no longer exists; type-only `src/lib/db-types/` files are filtered out too, since Stryker finds no tests for them, and a PR with nothing left to mutate exits 0.
- `security.yml` — secret scan (gitleaks, full history) + the fail-closed `.claude/deps-gate.sh` dependency audit (`pnpm audit --prod`, high/critical severity); no CodeQL job, since code scanning requires GitHub Advanced Security which isn't available on this private repo's plan The gitleaks job installs the pinned release binary and checks its SHA-256, because gitleaks-action needs a paid license on organization-owned repos. It scans the PR commits, or the pushed range on `main`.

- `staging-sync.yml`: on push to `main` (or a manual run), fast-forwards the
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ jobs:
git fetch origin "$GITHUB_BASE_REF" --depth=1
CHANGED=$(git diff --name-only --diff-filter=d "origin/$GITHUB_BASE_REF...HEAD")
FILES=$(printf '%s\n' "$CHANGED" | awk '
/^src\/lib\/.*\.ts$/ && !/\.test\.ts$|\/types\.ts$|\/action-result\.ts$|^src\/lib\/supabase\// {
/^src\/lib\/.*\.ts$/ && !/\.test\.ts$|\/types\.ts$|\/action-result\.ts$|^src\/lib\/supabase\/|^src\/lib\/db-types\// {
printf "%s%s", separator, $0
separator = ","
}')
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to loopkit are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [0.8.0] - 2026-12-02

### Added

- A customer can spend an earned reward at qkit checkout. "Use at qkit checkout" on a reward marks it redeemed and shows a single-use `LK-` code from qkit, with a copy button, in one transaction (migration `0073`, `customer_use_voucher_at_qkit`; a retry returns the same code, and a spent reward stays on /c as "qkit code issued" with a "Show code" button). Vendors set what the code is worth (percent or dollars off) in Profile under "qkit reward code". Free for every vendor. The code expires when the reward does, and the value takes at most two decimals. The customer card list (`customer_join`) now also lists each card's active rewards, which /c never showed before.

## [0.7.1] - 2026-12-02

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ src/lib/merqo-customer-notify.ts — notifyCustomerByPhone/notifyVendor: kit →
src/lib/merqo-vendor-status.ts — reports status/metrics to merqo over HTTP
src/lib/supabase/ — browser / server / service clients (schema: loopkit)
src/components/ — wheel, scratch-card, flame-layers, cup, points-bar, stamp-dots, etc.
supabase/migrations/ — SQL schema + RLS
supabase/migrations/ — SQL schema + RLS (0074: qkit reward codes)
```

Touch devices (@media (pointer: coarse)) get 44px minimum buttons and fields; desktop density is unchanged. See src/app/globals.css.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loopkit",
"version": "0.7.1",
"version": "0.8.0",
"private": true,
"packageManager": "pnpm@11.10.0",
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions src/app/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ Dates and times on these pages render through `@merqo/ui`'s `formatDate`/`format
The account menu shows the shared "Text size · 100%" submenu (a preset list under the Preferences label): `dashboard-nav.tsx` passes `textSizeKey="loopkit:scale:dashboard"` to `SharedDashboardNav` (`@merqo/ui` v0.68.0), so the scale applies to the dashboard only and persists per browser.

`scan-button.tsx` renders its link and hero variants with the shared `Button` (44px minimum height) instead of native buttons.

- `qkit-reward-code-action.test.ts` — unit tests for `saveQkitRewardCodeAction`: percent and dollar saves, two-decimal limit, range, clearing
- `qkit-reward-code-settings.dom.test.tsx` — jsdom tests for `QkitRewardCodeSettings`: saved value shown, empty when unset, entered value submitted
- `qkit-reward-code-settings.tsx` — client `QkitRewardCodeSettings` form (no Pro gate): code type (off, percent, dollars) and value, saved through `saveQkitRewardCodeAction` into `vendor_notify_settings`
2 changes: 1 addition & 1 deletion src/app/dashboard/profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo

- `actions.test.ts` — unit tests for `updateSocialLinksAction`: saves valid links while preserving the existing `stall_name`, rejects an invalid URL without calling `patchVendorProfile`, errors when not signed in, and errors (without revalidating) when the field-specific patch fails.
- `actions.ts` — server actions `updateStallNameAction()` (thin wrapper around `saveStallName`, `src/lib/vendor.ts`, revalidates the dashboard layout), `updatePasswordAction()` (Zod-validates an 8-72 char password, updates it via the Supabase auth client), and `updateSocialLinksAction()` (Zod-validates each link as an optional URL, uses a field-specific shared-profile patch for `social_links`, preserving concurrent stall-name changes).
- `page.tsx` — `ProfilePage` server component (also hosts the former Settings page: an `#integrations` block with `QkitEarnSettings` and `CustomerNotifySettings`, loaded from `qkit_earn_config` / `vendor_notify_settings`; with no `qkit_earn_config` row the oldest active stamp program is passed as already on, mirroring `qkit_earn_resolve_program`); requires a vendor, loads the vendor profile (`getVendorProfile()`, `src/lib/vendor.ts`) and auth `user_metadata` display name, reads the shared `merqo.vendor_profile` row's `social_links` (degrading to `{}` on failure, same pattern as `/setup`'s page), and renders `@merqo/ui`'s `BackButton` ("Back to dashboard") above `ProfileForm`. Its root element is `<div className="mx-auto max-w-lg space-y-8 md:max-w-4xl">` — deliberately narrower than the `../layout.tsx` `<main>`'s shared `max-w-7xl` (this form genuinely reads better constrained), so it nests its own `mx-auto`/`max-w-*` wrapper inside that container rather than stretching full-width; the page no longer sets its own padding, which the layout's `<main>` now owns.
- `page.tsx` — `ProfilePage` server component (also hosts the former Settings page: an `#integrations` block with `QkitEarnSettings` and `CustomerNotifySettings`, loaded from `qkit_earn_config` / `vendor_notify_settings`, plus a free "qkit reward code" section (`QkitRewardCodeSettings`, reads `qkit_code_kind`/`qkit_code_value`); with no `qkit_earn_config` row the oldest active stamp program is passed as already on, mirroring `qkit_earn_resolve_program`); requires a vendor, loads the vendor profile (`getVendorProfile()`, `src/lib/vendor.ts`) and auth `user_metadata` display name, reads the shared `merqo.vendor_profile` row's `social_links` (degrading to `{}` on failure, same pattern as `/setup`'s page), and renders `@merqo/ui`'s `BackButton` ("Back to dashboard") above `ProfileForm`. Its root element is `<div className="mx-auto max-w-lg space-y-8 md:max-w-4xl">` — deliberately narrower than the `../layout.tsx` `<main>`'s shared `max-w-7xl` (this form genuinely reads better constrained), so it nests its own `mx-auto`/`max-w-*` wrapper inside that container rather than stretching full-width; the page no longer sets its own padding, which the layout's `<main>` now owns.
- `profile-form.dom.test.tsx` — jsdom tests for `ProfileForm`: renders all 5 sections, prefills the social-links fields from `socialLinks` and saves them via `updateSocialLinksAction`, saves the stall name via `updateStallNameAction`.
- `profile-form.tsx` — `ProfileForm` client component; `@merqo/ui`'s `TwoColumnSections` (column 1: stall name, profile icon, change password; column 2: display name, social links — the locked cross-kit order) of five independently-saving `Section` cards (stall name via server action, social/website links via `@merqo/ui`'s `SocialLinksFields` + server action, avatar via `@merqo/ui`'s `ImageUploader` + browser auth client, display name via browser auth client, password change with client-side confirm match).

Expand Down
21 changes: 20 additions & 1 deletion src/app/dashboard/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getOrCreateVendorProfile } from "@/lib/merqo-vendor-profile";
import { ProfileForm } from "@/app/dashboard/profile/profile-form";
import { listPrograms } from "@/lib/program";
import { QkitEarnSettings } from "@/app/dashboard/qkit-earn-settings";
import { QkitRewardCodeSettings } from "@/app/dashboard/qkit-reward-code-settings";
import { CustomerNotifySettings } from "@/app/dashboard/customer-notify-settings";
import type { SocialLinks } from "@/lib/types";

Expand All @@ -28,7 +29,9 @@ export default async function ProfilePage() {
.maybeSingle(),
supabase
.from("vendor_notify_settings")
.select("customer_telegram_notify_enabled")
.select(
"customer_telegram_notify_enabled, qkit_code_kind, qkit_code_value",
)
.eq("vendor_id", user.id)
.maybeSingle(),
]);
Expand Down Expand Up @@ -100,6 +103,22 @@ export default async function ProfilePage() {
current={qkitCurrent}
/>
</div>
<div>
<h2 className="mb-3 text-sm font-semibold uppercase tracking-wider text-muted-foreground">
qkit reward code
</h2>
<QkitRewardCodeSettings
current={
notifySettings?.qkit_code_kind &&
notifySettings.qkit_code_value !== null
? {
kind: notifySettings.qkit_code_kind as "percent" | "fixed",
value: notifySettings.qkit_code_value,
}
: null
}
/>
</div>
<div>
<h2 className="mb-3 text-sm font-semibold uppercase tracking-wider text-muted-foreground">
Customer notifications
Expand Down
64 changes: 64 additions & 0 deletions src/app/dashboard/qkit-reward-code-action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { beforeEach, describe, expect, it, vi } from "vitest";

const upsertMock = vi.fn();

vi.mock("next/cache", () => ({ revalidatePath: vi.fn() }));
vi.mock("@/features/auth", () => ({
requireVendor: vi.fn(async () => ({ user: { id: "vendor-1" } })),
}));
vi.mock("@/lib/program", () => ({ isPro: vi.fn() }));
vi.mock("@/lib/supabase/server", () => ({
createServerClient: vi.fn(async () => ({
from: () => ({ upsert: upsertMock }),
})),
}));

import { saveQkitRewardCodeAction } from "./settings-actions";

function form(kind: string, value?: string) {
const fd = new FormData();
fd.set("kind", kind);
if (value !== undefined) fd.set("value", value);
return fd;
}

describe("saveQkitRewardCodeAction", () => {
beforeEach(() => {
vi.clearAllMocks();
upsertMock.mockResolvedValue({ error: null });
});

it("saves a percent code", async () => {
expect(await saveQkitRewardCodeAction(form("percent", "15"))).toEqual({
success: true,
});
expect(upsertMock).toHaveBeenCalledWith(
{ vendor_id: "vendor-1", qkit_code_kind: "percent", qkit_code_value: 15 },
{ onConflict: "vendor_id" },
);
});

it("accepts a two-decimal dollar value", async () => {
const res = await saveQkitRewardCodeAction(form("fixed", "2.50"));
expect(res.success).toBe(true);
});

it("rejects more than two decimals", async () => {
const res = await saveQkitRewardCodeAction(form("fixed", "2.505"));
expect(res.success).toBe(false);
expect(upsertMock).not.toHaveBeenCalled();
});

it("rejects a percent out of range", async () => {
const res = await saveQkitRewardCodeAction(form("percent", "101"));
expect(res.success).toBe(false);
});

it("clears both columns for none", async () => {
await saveQkitRewardCodeAction(form("none"));
expect(upsertMock).toHaveBeenCalledWith(
{ vendor_id: "vendor-1", qkit_code_kind: null, qkit_code_value: null },
{ onConflict: "vendor_id" },
);
});
});
33 changes: 33 additions & 0 deletions src/app/dashboard/qkit-reward-code-settings.dom.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @vitest-environment jsdom
import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

const { saveMock } = vi.hoisted(() => ({
saveMock: vi.fn().mockResolvedValue({ success: true }),
}));
vi.mock("./settings-actions", () => ({ saveQkitRewardCodeAction: saveMock }));

import { QkitRewardCodeSettings } from "./qkit-reward-code-settings";

describe("QkitRewardCodeSettings", () => {
it("shows the saved value", () => {
render(<QkitRewardCodeSettings current={{ kind: "percent", value: 15 }} />);
expect(screen.getByLabelText("Value")).toHaveValue(15);
});

it("starts empty when nothing is saved", () => {
render(<QkitRewardCodeSettings current={null} />);
expect(screen.getByLabelText("Value")).toHaveValue(null);
});

it("submits the entered value", async () => {
const user = userEvent.setup();
render(<QkitRewardCodeSettings current={{ kind: "fixed", value: 2 }} />);
await user.clear(screen.getByLabelText("Value"));
await user.type(screen.getByLabelText("Value"), "3.5");
await user.click(screen.getByRole("button", { name: "Save" }));
const fd = saveMock.mock.calls[0][0] as FormData;
expect(fd.get("value")).toBe("3.5");
});
});
Loading
Loading