chore: publish clean community baseline
Deploy / deploy (push) Successful in 30s
CI / Rust Checks (push) Successful in 4m59s
CI / UI Checks (push) Successful in 5s
CI / Deployment Manifests (push) Successful in 3s
CI / Frontend E2E (push) Successful in 4m8s

This commit is contained in:
github-ops
2026-06-17 06:15:46 +00:00
commit b546063998
307 changed files with 71048 additions and 0 deletions
+229
View File
@@ -0,0 +1,229 @@
const { transform } = require('esbuild');
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const ROOT_DIR = path.resolve(__dirname, '..');
const DIST_DIR = path.join(ROOT_DIR, 'dist');
const BUNDLE_DIR = path.join(DIST_DIR, 'js', 'bundles');
const BRAND_IMAGE_PATHS = [
path.join(ROOT_DIR, 'Crank.png'),
path.resolve(ROOT_DIR, '..', '..', 'Crank.png'),
];
const BUNDLES = {
'protected-core': {
files: [
'js/config.js',
'js/i18n.js',
'js/slot-registry.js',
'js/overlay-loader.js',
'js/dom.js',
'js/diagnostics.js',
'js/workspace.js',
'js/api.js',
'js/ui-feedback.js',
'js/auth.js',
],
footer: 'window.CrankAuth.guardProtectedPage();\n',
},
login: {
files: [
'js/config.js',
'js/i18n.js',
'js/diagnostics.js',
'js/api.js',
'js/auth.js',
'js/login.js',
],
},
operations: {
files: [
'node_modules/alpinejs/dist/cdn.min.js',
'js/catalog.js',
],
},
agents: {
files: [
'node_modules/alpinejs/dist/cdn.min.js',
'js/agents.js',
],
},
'api-keys': {
files: [
'js/nav.js',
'js/api-keys.js',
],
},
logs: {
files: [
'js/nav.js',
'js/logs.js',
],
},
usage: {
files: [
'js/nav.js',
'js/usage.js',
],
},
secrets: {
files: [
'js/nav.js',
'js/secrets.js',
],
},
settings: {
files: [
'js/nav.js',
'js/settings.js',
],
},
'workspace-setup': {
files: [
'js/diagnostics.js',
'js/workspace-setup.js',
],
},
wizard: {
files: [
'node_modules/js-yaml/dist/js-yaml.min.js',
'js/wizard-state.js',
'js/wizard-shell.js',
'js/wizard-upstreams.js',
'js/wizard-model.js',
'js/wizard-live.js',
'js/wizard.js',
'js/nav.js',
],
},
};
function sha(input) {
return crypto.createHash('sha256').update(input).digest('hex').slice(0, 12);
}
function sourcePath(relativePath) {
return path.join(ROOT_DIR, relativePath);
}
function ensureDirectory(directoryPath) {
fs.mkdirSync(directoryPath, { recursive: true });
}
function removeDirectory(directoryPath) {
fs.rmSync(directoryPath, { recursive: true, force: true });
}
function copyFile(source, destination) {
ensureDirectory(path.dirname(destination));
fs.copyFileSync(source, destination);
}
function copyDirectory(source, destination) {
ensureDirectory(destination);
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
const sourceEntry = path.join(source, entry.name);
const destinationEntry = path.join(destination, entry.name);
if (entry.isDirectory()) {
copyDirectory(sourceEntry, destinationEntry);
continue;
}
copyFile(sourceEntry, destinationEntry);
}
}
function readSource(relativePath) {
return fs.readFileSync(sourcePath(relativePath), 'utf8');
}
function resolveBrandImage() {
const match = BRAND_IMAGE_PATHS.find(function(filePath) {
return fs.existsSync(filePath);
});
if (!match) {
throw new Error('unable to resolve Crank.png for UI build');
}
return match;
}
async function buildBundle(name, config) {
const source = config.files.map(readSource).join('\n\n') + '\n' + (config.footer || '');
const result = await transform(source, {
loader: 'js',
minify: true,
target: 'es2019',
legalComments: 'none',
});
const hash = sha(result.code);
const fileName = `${name}.${hash}.js`;
const relativeOutputPath = path.posix.join('js', 'bundles', fileName);
fs.writeFileSync(path.join(BUNDLE_DIR, fileName), result.code);
return relativeOutputPath;
}
function rewriteHtml(relativePath, replacements, prefix) {
const source = readSource(relativePath);
const output = source.replace(/%CRANK_BUNDLE_([A-Z0-9_]+)%/g, function(_match, token) {
const key = token.toLowerCase().replace(/_/g, '-');
const filePath = replacements[key];
if (!filePath) {
throw new Error(`missing bundle placeholder ${key}`);
}
return prefix ? path.posix.join(prefix, filePath) : filePath;
});
const destination = path.join(DIST_DIR, relativePath);
ensureDirectory(path.dirname(destination));
fs.writeFileSync(destination, output);
}
async function main() {
var overlayDirectory = process.env.CRANK_UI_OVERLAY_DIR || '';
removeDirectory(DIST_DIR);
ensureDirectory(BUNDLE_DIR);
const manifest = {};
for (const [name, config] of Object.entries(BUNDLES)) {
manifest[name] = await buildBundle(name, config);
}
copyDirectory(path.join(ROOT_DIR, 'css'), path.join(DIST_DIR, 'css'));
copyDirectory(path.join(ROOT_DIR, 'data'), path.join(DIST_DIR, 'data'));
ensureDirectory(path.join(DIST_DIR, 'html', 'wizard'));
[
'html/wizard/index.html',
'html/wizard/step1.html',
'html/wizard/step2.html',
'html/wizard/step3-rest.html',
'html/wizard/step4.html',
'html/wizard/step5.html',
].forEach(function(relativePath) {
copyFile(path.join(ROOT_DIR, relativePath), path.join(DIST_DIR, relativePath));
});
copyDirectory(path.join(ROOT_DIR, 'icons'), path.join(DIST_DIR, 'icons'));
copyFile(resolveBrandImage(), path.join(DIST_DIR, 'Crank.png'));
if (overlayDirectory && fs.existsSync(overlayDirectory)) {
copyDirectory(overlayDirectory, path.join(DIST_DIR, 'overlay'));
}
rewriteHtml('index.html', manifest, '');
rewriteHtml('html/login.html', manifest, '..');
rewriteHtml('html/agents.html', manifest, '..');
rewriteHtml('html/api-keys.html', manifest, '..');
rewriteHtml('html/logs.html', manifest, '..');
rewriteHtml('html/secrets.html', manifest, '..');
rewriteHtml('html/settings.html', manifest, '..');
rewriteHtml('html/usage.html', manifest, '..');
rewriteHtml('html/workspace-setup.html', manifest, '..');
rewriteHtml('html/wizard/index.html', manifest, '../..');
fs.writeFileSync(
path.join(DIST_DIR, 'build-manifest.json'),
JSON.stringify(manifest, null, 2) + '\n',
);
}
main().catch(function(error) {
console.error(error);
process.exitCode = 1;
});
+165
View File
@@ -0,0 +1,165 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
TMP_DIR="$ROOT_DIR/.tmp/ui-e2e"
LOG_DIR="$TMP_DIR/logs"
POSTGRES_CONTAINER="crank-e2e-postgres"
POSTGRES_PORT="${CRANK_E2E_POSTGRES_PORT:-55433}"
ADMIN_PORT="${CRANK_E2E_ADMIN_PORT:-3301}"
MCP_PORT="${CRANK_E2E_MCP_PORT:-3302}"
UI_PORT="${CRANK_E2E_UI_PORT:-3300}"
STREAM_FIXTURE_PORT="${CRANK_E2E_STREAM_FIXTURE_PORT:-3310}"
GRPC_FIXTURE_BIND="${CRANK_E2E_GRPC_FIXTURE_BIND:-127.0.0.1:3311}"
POSTGRES_DB="${CRANK_E2E_POSTGRES_DB:-crank}"
POSTGRES_USER="${CRANK_E2E_POSTGRES_USER:-crank}"
POSTGRES_PASSWORD="${CRANK_E2E_POSTGRES_PASSWORD:-crank}"
POSTGRES_HOST="${CRANK_E2E_POSTGRES_HOST:-127.0.0.1}"
USE_EXTERNAL_POSTGRES="${CRANK_E2E_USE_EXTERNAL_POSTGRES:-0}"
ADMIN_EMAIL="${CRANK_E2E_ADMIN_EMAIL:-owner@crank.local}"
ADMIN_PASSWORD="${CRANK_E2E_ADMIN_PASSWORD:-change-me-admin-password}"
if [[ -f "$HOME/.cargo/env" ]]; then
. "$HOME/.cargo/env"
fi
PYTHON_BIN="${PYTHON_BIN:-}"
if [[ -z "$PYTHON_BIN" ]]; then
if command -v python3 >/dev/null 2>&1; then
PYTHON_BIN="python3"
else
PYTHON_BIN="python"
fi
fi
mkdir -p "$LOG_DIR"
(
cd "$ROOT_DIR/apps/ui"
npm run build >"$LOG_DIR/ui-build.log" 2>&1
)
kill_port_processes() {
local port="$1"
if command -v lsof >/dev/null 2>&1; then
lsof -ti "tcp:$port" | xargs -r kill >/dev/null 2>&1 || true
fi
}
cleanup() {
set +e
if [[ -f "$TMP_DIR/admin-api.pid" ]]; then
kill "$(cat "$TMP_DIR/admin-api.pid")" >/dev/null 2>&1 || true
rm -f "$TMP_DIR/admin-api.pid"
fi
if [[ -f "$TMP_DIR/mcp-server.pid" ]]; then
kill "$(cat "$TMP_DIR/mcp-server.pid")" >/dev/null 2>&1 || true
rm -f "$TMP_DIR/mcp-server.pid"
fi
if [[ -f "$TMP_DIR/ui-server.pid" ]]; then
kill "$(cat "$TMP_DIR/ui-server.pid")" >/dev/null 2>&1 || true
rm -f "$TMP_DIR/ui-server.pid"
fi
if [[ "$USE_EXTERNAL_POSTGRES" != "1" ]]; then
docker rm -f "$POSTGRES_CONTAINER" >/dev/null 2>&1 || true
fi
kill_port_processes "$UI_PORT"
kill_port_processes "$ADMIN_PORT"
kill_port_processes "$MCP_PORT"
}
trap cleanup EXIT INT TERM
cleanup
wait_for_port() {
local host="$1"
local port="$2"
until "$PYTHON_BIN" - "$host" "$port" <<'PY'
import socket, sys
sock = socket.socket()
sock.settimeout(0.5)
try:
sock.connect((sys.argv[1], int(sys.argv[2])))
except OSError:
sys.exit(1)
finally:
sock.close()
PY
do
sleep 1
done
}
if [[ "$USE_EXTERNAL_POSTGRES" = "1" ]]; then
wait_for_port "$POSTGRES_HOST" "$POSTGRES_PORT"
else
docker run -d --rm \
--name "$POSTGRES_CONTAINER" \
-e POSTGRES_DB="$POSTGRES_DB" \
-e POSTGRES_USER="$POSTGRES_USER" \
-e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" \
-p "$POSTGRES_PORT:5432" \
postgres:16-alpine >/dev/null
until docker exec "$POSTGRES_CONTAINER" pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" >/dev/null 2>&1; do
sleep 1
done
fi
export POSTGRES_HOST
export POSTGRES_PORT="$POSTGRES_PORT"
export POSTGRES_DB="$POSTGRES_DB"
export POSTGRES_USER="$POSTGRES_USER"
export POSTGRES_PASSWORD="$POSTGRES_PASSWORD"
export CRANK_STORAGE_ROOT="$TMP_DIR/storage"
export CRANK_ADMIN_BIND="0.0.0.0:$ADMIN_PORT"
export CRANK_MCP_BIND="0.0.0.0:$MCP_PORT"
export CRANK_MCP_REFRESH_MS="1000"
export CRANK_LOG_LEVEL="info"
export CRANK_SESSION_SECRET="e2e-session-secret"
export CRANK_PASSWORD_PEPPER="e2e-password-pepper"
export CRANK_MASTER_KEY="0000000000000000000000000000000000000000000000000000000000000000"
export CRANK_SESSION_TTL_HOURS="24"
export CRANK_BOOTSTRAP_ADMIN_EMAIL="$ADMIN_EMAIL"
export CRANK_BOOTSTRAP_ADMIN_PASSWORD="$ADMIN_PASSWORD"
export CRANK_BOOTSTRAP_ADMIN_DISPLAY_NAME="Crank E2E"
export CRANK_DEMO_SEED="true"
export CRANK_BASE_URL="http://127.0.0.1:$UI_PORT"
mkdir -p "$CRANK_STORAGE_ROOT"
(
cd "$ROOT_DIR"
cargo run -p admin-api >"$LOG_DIR/admin-api.log" 2>&1
) &
echo $! > "$TMP_DIR/admin-api.pid"
until curl -fsS "http://127.0.0.1:$ADMIN_PORT/health" >/dev/null 2>&1; do
sleep 1
done
(
cd "$ROOT_DIR"
cargo run -p mcp-server >"$LOG_DIR/mcp-server.log" 2>&1
) &
echo $! > "$TMP_DIR/mcp-server.pid"
until curl -fsS "http://127.0.0.1:$MCP_PORT/health" >/dev/null 2>&1; do
sleep 1
done
(
cd "$ROOT_DIR/apps/ui"
node scripts/playwright-ui-server.js >"$LOG_DIR/ui-server.log" 2>&1
) &
echo $! > "$TMP_DIR/ui-server.pid"
until curl -fsS "http://127.0.0.1:$UI_PORT/login" >/dev/null 2>&1; do
sleep 1
done
echo "Crank UI e2e stack is ready on http://127.0.0.1:$UI_PORT"
while true; do
sleep 1
done
+197
View File
@@ -0,0 +1,197 @@
const fs = require('fs');
const path = require('path');
const http = require('http');
const { pipeline } = require('stream');
const { URL } = require('url');
const ROOT_DIR = path.resolve(__dirname, '..', 'dist');
const UI_PORT = Number(process.env.CRANK_E2E_UI_PORT || 3300);
const ADMIN_PORT = Number(process.env.CRANK_E2E_ADMIN_PORT || 3301);
const ADMIN_BASE = new URL(`http://127.0.0.1:${ADMIN_PORT}`);
const MIME_TYPES = {
'.css': 'text/css; charset=utf-8',
'.html': 'text/html; charset=utf-8',
'.js': 'application/javascript; charset=utf-8',
'.json': 'application/json; charset=utf-8',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'.woff2': 'font/woff2',
'.txt': 'text/plain; charset=utf-8',
};
function sendNotFound(response) {
response.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
response.end('Not Found');
}
function redirect(response, location) {
response.writeHead(302, { Location: location });
response.end();
}
function mapRoute(urlPath) {
if (urlPath === '/' || urlPath === '/index.html') {
return path.join(ROOT_DIR, 'index.html');
}
if (urlPath === '/login' || urlPath === '/login.html') {
return path.join(ROOT_DIR, 'html', 'login.html');
}
if (urlPath === '/agents') {
return path.join(ROOT_DIR, 'html', 'agents.html');
}
if (urlPath === '/api-keys') {
return path.join(ROOT_DIR, 'html', 'api-keys.html');
}
if (urlPath === '/secrets') {
return path.join(ROOT_DIR, 'html', 'secrets.html');
}
if (urlPath === '/logs') {
return path.join(ROOT_DIR, 'html', 'logs.html');
}
if (urlPath === '/usage') {
return path.join(ROOT_DIR, 'html', 'usage.html');
}
if (urlPath === '/settings') {
return path.join(ROOT_DIR, 'html', 'settings.html');
}
if (urlPath === '/workspace-setup') {
return path.join(ROOT_DIR, 'html', 'workspace-setup.html');
}
if (urlPath === '/wizard/') {
return path.join(ROOT_DIR, 'html', 'wizard', 'index.html');
}
if (urlPath.startsWith('/wizard/')) {
return path.join(ROOT_DIR, 'html', 'wizard', urlPath.slice('/wizard/'.length));
}
if (urlPath.startsWith('/css/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath.startsWith('/js/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath.startsWith('/icons/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath.startsWith('/data/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath === '/Crank.png') {
return path.join(ROOT_DIR, 'Crank.png');
}
return null;
}
function serveFile(filePath, response) {
const normalized = path.normalize(filePath);
if (!normalized.startsWith(ROOT_DIR) && !normalized.endsWith(path.sep + 'Crank.png')) {
sendNotFound(response);
return;
}
fs.stat(normalized, (error, stats) => {
if (error || !stats.isFile()) {
sendNotFound(response);
return;
}
const extension = path.extname(normalized).toLowerCase();
response.writeHead(200, {
'Content-Length': stats.size,
'Content-Type': MIME_TYPES[extension] || 'application/octet-stream',
'Cache-Control': 'no-store',
});
pipeline(fs.createReadStream(normalized), response, () => {});
});
}
function proxyRequest(request, response) {
const target = new URL(request.url, ADMIN_BASE);
const proxy = http.request(
target,
{
method: request.method,
headers: {
...request.headers,
host: `127.0.0.1:${ADMIN_PORT}`,
},
},
(proxyResponse) => {
response.writeHead(proxyResponse.statusCode || 502, proxyResponse.headers);
pipeline(proxyResponse, response, () => {});
},
);
proxy.on('error', () => {
response.writeHead(502, { 'Content-Type': 'text/plain; charset=utf-8' });
response.end('Bad Gateway');
});
pipeline(request, proxy, () => {});
}
const server = http.createServer((request, response) => {
const requestUrl = new URL(request.url, `http://127.0.0.1:${UI_PORT}`);
const urlPath = requestUrl.pathname;
if (urlPath === '/wizard') {
redirect(response, '/wizard/');
return;
}
if (urlPath === '/html/login.html') {
redirect(response, '/login');
return;
}
if (urlPath === '/html/agents.html') {
redirect(response, '/agents');
return;
}
if (urlPath === '/html/api-keys.html') {
redirect(response, '/api-keys');
return;
}
if (urlPath === '/html/secrets.html') {
redirect(response, '/secrets');
return;
}
if (urlPath === '/html/logs.html') {
redirect(response, '/logs');
return;
}
if (urlPath === '/html/usage.html') {
redirect(response, '/usage');
return;
}
if (urlPath === '/html/settings.html') {
redirect(response, '/settings');
return;
}
if (urlPath === '/html/workspace-setup.html') {
redirect(response, '/workspace-setup');
return;
}
if (urlPath === '/html/wizard' || urlPath === '/html/wizard/') {
redirect(response, '/wizard/');
return;
}
if (urlPath.startsWith('/api/auth/') || urlPath.startsWith('/api/admin/')) {
proxyRequest(request, response);
return;
}
const filePath = mapRoute(urlPath);
if (!filePath) {
sendNotFound(response);
return;
}
serveFile(filePath, response);
});
server.listen(UI_PORT, '127.0.0.1', () => {
console.log(`Playwright UI server listening on http://127.0.0.1:${UI_PORT}`);
});