Sync vault notes: April-November 2026 sessions, projects, and architecture

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
garfieldandClaude Sonnet 5.5 committed 2026-11-13 11:00:53 -05:00
1 parent fe4fe656be
commit 994c7ae577
379 files changed
+55216 -107

No files matched your search

@@ -0,0 +1,116 @@
# Deployment: MySQL-Backed Tracking Links
**Date:** 2026-06-09
**Branch:** main
**Service:** hermes-mcp (K8s deployment `hermes-mcp` in namespace `fetcherpay`)
**Status:** ✅ DEPLOYED
**Commit:** `5effb41`
**Image:** `localhost:32000/hermes-mcp@sha256:fbe8a90ca5f49800c6e1b3b70c4f2ab1031cb59880fa381631b855e91e7fc5df`
**Related:** [[2026-06-09-mysql-backed-tracking-links-eng-review]]
---
## What Was Built
Tracking links (`/t/:token`) backed by MySQL. Visitors clicking Alex's Facebook posts are redirected to his Calendly/website URL. Click counts persist across Redis restarts. MySQL is the source of truth for where the link goes — Redis is not involved.
---
## Files Changed
| File | Change |
|---|---|
| `src/tracking-links.ts` | **New.** Core module: `createTrackingLink`, `getTrackingLink`, `recordClick`, `validateDestinationUrl`, `isBot` |
| `src/tracking-links.test.ts` | **New.** 20 tests, all passing |
| `src/db.ts` | Added `tracking_links` table, `post_drafts` table, 6 pilot columns on `customers` |
| `src/index.ts` | Added `GET /t/:token` route (public, no auth) + import |
---
## Schema Changes
Applied automatically at startup via `initDatabase()`. No manual SQL required.
**New tables:**
```sql
tracking_links (
token VARCHAR(32) PRIMARY KEY, -- crypto.randomBytes(24).toString('base64url')
customer_id VARCHAR(255) NOT NULL,
draft_id INT NULL,
destination_url VARCHAR(2048) NOT NULL,
click_count BIGINT UNSIGNED NOT NULL DEFAULT 0,
expires_at TIMESTAMP NULL, -- NULL = no expiry (use for all pilot links)
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_customer_created (customer_id, created_at),
INDEX idx_draft (draft_id)
)
post_drafts (
id INT AUTO_INCREMENT PRIMARY KEY,
tenant_id VARCHAR(255) NOT NULL,
draft_text_social TEXT NOT NULL,
draft_text_wa TEXT NOT NULL,
destination_url VARCHAR(512) NULL,
utm_token VARCHAR(32) NULL,
status ENUM('pending','approved','rejected','expired','publish_error') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
approved_at TIMESTAMP NULL
)
```
**New columns on `customers`:**
```sql
pilot_active TINYINT(1) DEFAULT 0
pilot_paused TINYINT(1) DEFAULT 0
pilot_end_date DATE NULL
pilot_owner_phone VARCHAR(32) NULL
industry VARCHAR(128) NULL
location VARCHAR(128) NULL
```
---
## Verification
| Check | Result |
|-------|--------|
| `npm run build` | ✅ Pass |
| `vitest run src/tracking-links.test.ts` | ✅ 20/20 passed |
| Unknown token → `404` | ✅ `curl -I https://hermes.squaremcp.com/t/unknowntoken00000000000000000000` |
| Malformed token → `404` | ✅ `curl /t/bad-token-with-dots...` and `/t/!!!` both 404 |
| Health endpoint | ✅ `{"status":"ok","service":"hermes-mcp","toolCount":55}` |
| K8s rollout | ✅ `deployment "hermes-mcp" successfully rolled out` |
Note: `kubectl exec` / `kubectl logs` currently fail due to a MicroK8s API server TLS certificate mismatch (node IP changed). This is an infrastructure issue, not a code issue. The app is healthy and serving traffic, which confirms `initDatabase()` succeeded.
---
## How to Create a Tracking Link (for next feature: pilot approval flow)
```typescript
import { createTrackingLink } from './tracking-links.js';
const token = await createTrackingLink({
customerId: customer.id,
draftId: draft.id,
destinationUrl: 'https://calendly.com/alex/30min',
expiresAt: null, // pilot links never expire
});
const trackedUrl = `${SERVER_URL}/t/${token}`;
// embed trackedUrl in the Facebook post message
```
---
## What This Does NOT Include
The following are built but not yet wired together (next step):
- Pilot draft cron (`src/pilot/cron.ts`) — weekly Claude API draft generation
- WhatsApp approval flow — inbound "1/2/3" reply → publish
- Lead dashboard (`GET /dashboard`)
Tracking links are a dependency of all three. That's why this shipped first.