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
8 changes: 8 additions & 0 deletions .agents/HANDOFF.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# HANDOFF

## 2026-11-21 - Env template and ignore rules (Claude)

- Branch `chore/env-contract-and-ignore-rules-2026-11-21`, cut from the public `main` (`c3541d3`) in a scratch clone. Local only, NOT pushed: Gaffer has not approved a push.
- Added `.env.example` (the four names the site reads, empty values) and `.gitignore` rules for every env file, local databases, dumps, backups and key files; `.env.example` stays trackable.
- New `app/env-contract.test.mjs` (4 tests, RED first) pins both: a variable read by the site but missing from `.env.example` fails, a filled key or token fails, an unignored secret or data path fails.
- Verified: install, typecheck, lint, test 63/63, build, deploy:dry-run all exit 0 (Linux, Node 24.22.3, pnpm 11.21.0). E2E and live Vera NOT RUN.
- Open for Gaffer: the same change must land in the monorepo capsule, or the next publish from the capsule drops it; `.agents/` and `.review-2026-11-12/` are public (keep or untrack); a pre-commit secret scan was not added (needs approval).

## 2026-11-20 - Published to gaffercode/Sentraverse, MIT (Claude)

- Gaffer chose MIT for the public repo `gaffercode/Sentraverse` (its web-made LICENSE); capsule `LICENSE`, `package.json`, README and manifest follow (`bc978726`).
Expand Down
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Sentraverse Neural: environment template.
# Copy this file to `.env.local` (git-ignored) and fill in only what you need.
# Never commit real values. Every variable is server-only and optional: the site builds and
# runs without any of them.

# Vera chat (Dify). Without the key, POST /api/vera/chat answers HTTP 500
# "Vera is not available right now."
DIFY_API_KEY=
# Optional override of the Dify endpoint. Default when empty: https://api.dify.ai/v1
DIFY_API_URL=

# Vera message limit (Upstash Redis REST). Set both or neither: without the pair the limit is
# counted in memory per server instance.
KV_REST_API_URL=
KV_REST_API_TOKEN=
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,35 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Local env
# Local env: every env file stays on the machine; only the example is tracked
.env
.env.*
!.env.example
.env*.local

# Local databases, dumps and backups: real data never goes into Git
*.sqlite
*.sqlite3
*.db
*.dump
*.pgdump
*.bak
*.backup
*.sql.gz
*dump*.sql
*backup*.sql
backups/
dumps/

# Keys and credential files
*.key
*.p12
*.pfx
id_rsa*
id_ed25519*
service-account*.json
credentials*.json

# Vercel
.vercel

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ node scripts/pnpm.mjs run start

### Configuration

Store server-only values in git-ignored `.env.local` or the host's environment configuration. **Never commit credentials.**
Copy `.env.example` to a git-ignored `.env.local` and fill in what you need, or set the values in the host's environment configuration. **Never commit credentials.**

| <small>Variable</small> | <small>Required</small> | <small>Role</small> | <small>Boundary</small> |
|---|---|---|---|
Expand Down Expand Up @@ -695,7 +695,7 @@ The following results distinguish **past recorded tests** from **checks performe
| <small><small>Install</small></small> | <small><small>**PASS — 20 Nov 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs install --frozen-lockfile`</small></small> | <small><small>Historical evidence in `docs/verification.md`.</small></small> |
| <small><small>Typecheck</small></small> | <small><small>**PASS — 20 Nov 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs run typecheck`</small></small> | <small><small>Not rerun for README revision.</small></small> |
| <small><small>Lint</small></small> | <small><small>**PASS — 20 Nov 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs run lint`</small></small> | <small><small>Not rerun for README revision.</small></small> |
| <small><small>Unit tests</small></small> | <small><small>**59/59 — 20 Nov 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs run test`</small></small> | <small><small>Does not cover full Vera widget / route.</small></small> |
| <small><small>Unit tests</small></small> | <small><small>**63/63 — 21 Nov 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs run test`</small></small> | <small><small>Does not cover full Vera widget / route.</small></small> |
| <small><small>Build</small></small> | <small><small>**PASS — 20 Nov 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs run build`</small></small> | <small><small>Not rerun for README revision.</small></small> |
| <small><small>Deployment dry-run</small></small> | <small><small>**PASS WITH LIMITATION — recorded**</small></small> | <small><small>`node scripts/pnpm.mjs run deploy:dry-run`</small></small> | <small><small>Secret-name check currently uses an empty list.</small></small> |
| <small><small>Playwright E2E</small></small> | <small><small>**24/24 — 9 Oct 2026 record**</small></small> | <small><small>`node scripts/pnpm.mjs run test:e2e`</small></small> | <small><small>Predates Vera; not rerun on this revision.</small></small> |
Expand Down
87 changes: 87 additions & 0 deletions app/env-contract.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { readdirSync, readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { test } from 'node:test';
import { fileURLToPath } from 'node:url';

// Repository contract: every environment variable the site reads is listed in `.env.example`
// with a placeholder, and local secrets or data files can never be committed by accident.

const root = dirname(dirname(fileURLToPath(import.meta.url)));
const RUNTIME_DIRS = ['app', 'components', 'src'];
const SOURCE_FILE = /\.(?:ts|tsx|mjs|js|jsx)$/;
const TEST_FILE = /\.(?:test|spec)\./;
// Set by Node, Next.js or the host, never by a developer's env file.
const PLATFORM_VARIABLES = new Set(['NODE_ENV', 'CI', 'PORT', 'VERCEL', 'VERCEL_ENV', 'VERCEL_URL', 'NEXT_RUNTIME']);

function sourceFiles(dir) {
const found = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name);
if (entry.isDirectory()) found.push(...sourceFiles(path));
else if (SOURCE_FILE.test(entry.name) && !TEST_FILE.test(entry.name)) found.push(path);
}
return found;
}

function variablesReadByTheSite() {
const names = new Set();
for (const dir of RUNTIME_DIRS) {
for (const file of sourceFiles(join(root, dir))) {
for (const [, name] of readFileSync(file, 'utf8').matchAll(/process\.env\.([A-Z][A-Z0-9_]*)/g)) names.add(name);
}
}
return [...names].filter((name) => !PLATFORM_VARIABLES.has(name)).sort();
}

function envExample() {
const entries = new Map();
for (const line of readFileSync(join(root, '.env.example'), 'utf8').split(/\r?\n/)) {
const match = /^([A-Z][A-Z0-9_]*)=(.*)$/.exec(line);
if (match) entries.set(match[1], match[2].trim());
}
return entries;
}

function isIgnored(path) {
return spawnSync('git', ['check-ignore', '--quiet', '--no-index', path], { cwd: root }).status === 0;
}

const insideGit = spawnSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: root }).status === 0;

test('.env.example lists every environment variable the site reads', () => {
const documented = envExample();
const missing = variablesReadByTheSite().filter((name) => !documented.has(name));
assert.deepEqual(missing, []);
});

test('.env.example holds no value for keys, tokens, secrets or passwords', () => {
const filled = [...envExample()].filter(([name, value]) => /KEY|TOKEN|SECRET|PASSWORD/.test(name) && value !== '');
assert.deepEqual(filled.map(([name]) => name), []);
});

test('.gitignore keeps local env files, databases, dumps and keys out of Git', { skip: !insideGit && 'not a Git checkout' }, () => {
const mustBeIgnored = [
'.env',
'.env.local',
'.env.production',
'apps/web/.env',
'data.sqlite',
'local.sqlite3',
'dev.db',
'prod.dump',
'db.bak',
'backup.sql.gz',
'backups/2026-11-21.sql',
'server.pem',
'private.key',
'id_rsa',
'service-account.json',
];
assert.deepEqual(mustBeIgnored.filter((path) => !isIgnored(path)), []);
});

test('.gitignore still lets .env.example be committed', { skip: !insideGit && 'not a Git checkout' }, () => {
assert.equal(isIgnored('.env.example'), false);
});
3 changes: 2 additions & 1 deletion docs/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ truncated SHA-256 hash reaches Upstash (`limit.test.mjs` asserts it).

## Environment variables

Names only; values live in Vercel project settings or a local `.env.local` (git-ignored).
Names only; values live in Vercel project settings or a local `.env.local` (git-ignored). The
tracked `.env.example` lists the same names with empty values.

| Name | Used by | Required |
| --- | --- | --- |
Expand Down
3 changes: 2 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ If 4346 is held by an earlier `next start`, stop it or verify on another port
## Configuration

The journey needs no configuration. Vera needs `DIFY_API_KEY` (and optionally `DIFY_API_URL`,
`KV_REST_API_URL`, `KV_REST_API_TOKEN`) in a git-ignored `.env.local`; see [`data.md`](data.md).
`KV_REST_API_URL`, `KV_REST_API_TOKEN`) in a git-ignored `.env.local`, copied from the tracked
[`.env.example`](../.env.example); see [`data.md`](data.md).
Never commit values. Without a key the page works and Vera answers "not available".

## Workflow
Expand Down
1 change: 1 addition & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ with no runtime relative imports.
| `morphology.test.mjs`, `constellation.test.mjs` | Neuron tree shape, vertex budget, constellation seats |
| `signal.test.mjs`, `handoff.test.mjs`, `tactile.test.mjs` | Activity cycle, carrier handoff, pointer placement |
| `app/api/vera/chat/limit.test.mjs` | Daily limit with TTL, hashed IP only, fallback when store is down or absent |
| `app/env-contract.test.mjs` | Every variable the site reads is in `.env.example` with no secret value; `.gitignore` blocks env files, databases, dumps and keys |

## End-to-end (Playwright, Chromium)

Expand Down
21 changes: 21 additions & 0 deletions docs/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ A change is acceptable when, from the capsule root:
3. Vera changes are exercised against a stub or closed upstream (no real Dify calls in tests);
4. the result is recorded here and in `.agents/HANDOFF.md`.

## 2026-11-21 — env template and ignore rules (Claude Fable 5.2)

Branch `chore/env-contract-and-ignore-rules-2026-11-21`, cut from the public `main` (`c3541d3`) in a
scratch clone of `gaffercode/Sentraverse`. Linux, Node 24.22.3, pnpm 11.21.0. Commands run via
`node scripts/pnpm.mjs` on a clean clone.

| Command | Finished (UTC) | Exit | Result |
| --- | --- | --- | --- |
| `install --frozen-lockfile` | 07:33 | 0 | Lockfile unchanged |
| `typecheck` | 07:33 | 0 | No errors |
| `lint` | 07:33 | 0 | No findings |
| `test` | 07:33 | 0 | 63/63 (59 existing, 4 new in `app/env-contract.test.mjs`) |
| `build` | 07:33 | 0 | Production build written |
| `deploy:dry-run` | 07:33 | 0 | Artifact present, no server-only names in the client bundle |

The four new tests were watched failing before the change: no `.env.example`; thirteen probe paths
not ignored (`.env`, `.env.production`, a nested `.env`, SQLite and `.db` files, dumps, backups, key
files); and, with the ignore rule in place but no exception, `.env.example` itself ignored.

NOT RUN: `test:e2e` (no browser on this machine) and live Vera.

## 2026-11-20 — documentation pass (Claude Opus 5.5)

Branch `docs/sentraverse-neural-srds`, capsule `projects/healthcare/sentraverse-neural`,
Expand Down
Loading