Skip to content
Draft
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
13 changes: 13 additions & 0 deletions ecosystem.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ module.exports = {
COMPUTE_MODE: 'local',
ALWAYS_ON: 'true'
}
},
{
name: 'project-genie',
script: './scripts/genesis.cjs',
autorestart: true,
watch: false,
max_memory_restart: '300M',
restart_delay: 5000,
env: {
GENESIS_LOOP: 'true',
FORCE_MUTATION: 'true',
ALWAYS_ON: 'true'
}
}
]
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"test": "hardhat test",
"build": "cd frontend && npm run build",
"build": "echo 'No build step required'",
"worker:dev": "wrangler dev",
"worker:deploy": "wrangler deploy --env production",
"worker:deploy:staging": "wrangler deploy --env staging"
Expand Down
4 changes: 2 additions & 2 deletions scripts/genesis.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
soul: '/dev/shm/yennefer_soul_state.json',
mind: path.join(__dirname, '../yennefer-observatory/public/evolution.json'),
body: path.join(__dirname, '../yennefer-observatory/src/components/generated'),
journal: '/home/yenn/.yennefer/genesis_journal.jsonl'
journal: path.join(__dirname, 'genesis_journal.jsonl')
};

// --- CONFIGURATION ---
Expand Down Expand Up @@ -287,17 +287,17 @@
if (process.env.GENESIS_LOOP === 'true') {
console.log("🔄 Running in continuous Genesis Loop mode...");
while (true) {
await genesis();

Check warning on line 290 in scripts/genesis.cjs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected `await` inside a loop.

See more on https://sonarcloud.io/project/issues?id=Genesis-Conductor-Engine_Yennefer&issues=AaEF0fsNDsOV8zej_KQc&open=AaEF0fsNDsOV8zej_KQc&pullRequest=237
// Wait for reflectionInterval or 5 minutes
const waitTime = CONFIG.reflectionInterval || 5 * 60 * 1000;
console.log(`\n⏳ Genesis cycle sleeping for ${waitTime / 1000} seconds...`);
await new Promise(resolve => setTimeout(resolve, waitTime));

Check warning on line 294 in scripts/genesis.cjs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected `await` inside a loop.

See more on https://sonarcloud.io/project/issues?id=Genesis-Conductor-Engine_Yennefer&issues=AaEF0fsNDsOV8zej_KQd&open=AaEF0fsNDsOV8zej_KQd&pullRequest=237
}
} else {
await genesis();
}
}

main();
main().catch(console.error);

module.exports = { genesis, consultTheVisionary, invokeTheScribe, dispatchTheBuilder };
12 changes: 4 additions & 8 deletions workers/index.js → workers/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ async function getJWKS() {

// ─── JWT Validation (native Web Crypto) ──────────────────────────────────────

function base64UrlDecode(str) {
str = str.replace(/-/g, '+').replace(/_/g, '/');
while (str.length % 4) str += '=';
return Uint8Array.from(atob(str), c => c.charCodeAt(0));
}
const parseB64 = (s) => Uint8Array.from(atob(s.replaceAll('-', '+').replaceAll('_', '/').padEnd(s.length + (4 - s.length % 4) % 4, '=')), c => c.codePointAt(0));

async function validateJWT(request) {
const jwt = request.headers.get('Cf-Access-Jwt-Assertion');
Expand All @@ -129,8 +125,8 @@ async function validateJWT(request) {
const [headerB64, payloadB64, sigB64] = parts;

const dec = new TextDecoder();
const header = JSON.parse(dec.decode(base64UrlDecode(headerB64)));
const payload = JSON.parse(dec.decode(base64UrlDecode(payloadB64)));
const header = JSON.parse(dec.decode(parseB64(headerB64)));
const payload = JSON.parse(dec.decode(parseB64(payloadB64)));

// Reject unexpected algorithm/type before touching the crypto path to
// prevent algorithm-confusion attacks and fail fast for auditing.
Expand All @@ -157,7 +153,7 @@ async function validateJWT(request) {

const message = new TextEncoder().encode(`${headerB64}.${payloadB64}`);
const valid = await crypto.subtle.verify(
'RSASSA-PKCS1-v1_5', cryptoKey, base64UrlDecode(sigB64), message,
'RSASSA-PKCS1-v1_5', cryptoKey, parseB64(sigB64), message,
);
if (!valid) throw new Error('Signature verification failed');

Expand Down
12 changes: 4 additions & 8 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "yennefer"
main = "workers/index.js"
compatibility_date = "2024-09-23"
main = "workers/index.mjs"
compatibility_date = "2024-04-01"
compatibility_flags = ["nodejs_compat"]

# ─── Build step ──────────────────────────────────────────────────────────────
Expand All @@ -9,21 +9,17 @@ compatibility_flags = ["nodejs_compat"]
# Installs frontend deps and builds the SPA so frontend/build exists before
# `wrangler deploy` uploads assets. NODE_OPTIONS is required for
# react-scripts 5.x + Node 18+ (webpack 4 OpenSSL 3.0 compatibility).
command = "cd frontend && npm install --include=dev && GENERATE_SOURCEMAP=false CI=false NODE_OPTIONS=--openssl-legacy-provider npm run build"
command = "cd yennefer-observatory && npm install --legacy-peer-deps && npm run build"

# ─── Static Assets (React SPA build output) ──────────────────────────────────
# Built by `npm run build` (root package.json) before every `wrangler deploy`.
# Cloudflare Workers Builds CI runs that script automatically if present.
# The ASSETS binding serves the React bundle with proper cache headers and
# falls back to index.html for client-side routing.
[assets]
directory = "frontend/build"
directory = "yennefer-observatory/dist"
binding = "ASSETS"

# ─── Placement ───────────────────────────────────────────────────────────────
[placement]
mode = "smart"

# ─── Production environment (yennefer.quest) ─────────────────────────────────
# BACKEND_URL is set as a Cloudflare Worker secret (not a plain var) so it
# stays encrypted and is never committed to source:
Expand Down
Loading