Skip to content
Open
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
6 changes: 4 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/styles/github-dark.min.css" crossorigin="anonymous">
<script type="module" crossorigin src="/assets/index-B6PrWp6i.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CkBYflNC.css">
<script type="module" crossorigin src="/assets/index-B0MlRbV8.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-C4iCh-FI.css">
</head>
<body>
<!-- Login Overlay (shown before auth) -->
Expand Down Expand Up @@ -52,6 +52,7 @@
<a href="#agents" class="nav-link" data-page="agents">Agents</a>
<a href="#usage" class="nav-link" data-page="usage">Usage</a>
<a href="#skills" class="nav-link" data-page="skills">Skills</a>
<a href="#workflows" class="nav-link" data-page="workflows">Workflows</a>
<a href="#chat" class="nav-link" data-page="chat">Chat</a>
<a href="#logs" class="nav-link" data-page="logs">Logs</a>
<a href="#mon" class="nav-link" data-page="mon">Monitor</a>
Expand Down Expand Up @@ -100,6 +101,7 @@
<div id="page-agent-detail" class="page"></div>
<div id="page-usage" class="page"></div>
<div id="page-skills" class="page"></div>
<div id="page-workflows" class="page"></div>
<div id="page-chat" class="page"></div>
<div id="page-users" class="page"></div>
<div id="page-logs" class="page"></div>
Expand Down
68 changes: 68 additions & 0 deletions lib/workflow-worker-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { spawnSync } = require('node:child_process');
const { upsertWorkerStatus } = require('./workflow-worker-status');

function currentTimestamp(now) {
return typeof now === 'function' ? now() : (now || new Date().toISOString());
}

function statusForExit(result = {}) {
if (result.signal) return 'stopped';
if (result.status === 0) return 'idle';
if (result.status === 130 || result.status === 143) return 'stopped';
return 'error';
}

function noteForExit(result = {}) {
if (result.signal) return `terminated by ${result.signal}`;
return `exited ${Number.isInteger(result.status) ? result.status : 1}`;
}

function writeWorkerStatus(options, status, note) {
const snapshot = upsertWorkerStatus({
repoDir: options.repoDir,
file: options.file,
id: options.id,
label: options.label,
provider: options.provider,
sessionId: options.sessionId,
status,
note,
updatedAt: currentTimestamp(options.now),
});
if (typeof options.onStatus === 'function') options.onStatus(snapshot);
return snapshot;
}

function runWorkerCommand(options) {
if (!options || typeof options !== 'object') throw new Error('options are required');
const command = String(options.command || '').trim();
if (!command) throw new Error('command is required');

writeWorkerStatus(options, 'generating', options.startNote || 'started');

const runner = options.spawnSync || spawnSync;
const result = runner(command, options.args || [], {
cwd: options.cwd || options.repoDir || process.cwd(),
env: options.env || process.env,
stdio: options.stdio || 'inherit',
shell: Boolean(options.shell),
});

if (result.error) {
writeWorkerStatus(options, 'error', result.error.message || 'failed to launch');
return { exitCode: 1, signal: result.signal || null, error: result.error };
}

const finalStatus = statusForExit(result);
writeWorkerStatus(options, finalStatus, noteForExit(result));

return {
exitCode: Number.isInteger(result.status) ? result.status : (result.signal ? 143 : 1),
signal: result.signal || null,
};
}

module.exports = {
runWorkerCommand,
statusForExit,
};
93 changes: 93 additions & 0 deletions lib/workflow-worker-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const fs = require('fs');
const path = require('path');
const { normalizeWorkerStatus } = require('./workflows');

function normalizeString(value) {
return String(value || '').trim();
}

function resolveWorkerStatusPath(repoDir, file) {
const resolvedRepoDir = path.resolve(repoDir || process.cwd());
const rawFile = normalizeString(file);
if (!rawFile || path.isAbsolute(rawFile)) {
throw new Error('worker status file must be a repo-local relative path');
}
const resolvedPath = path.resolve(resolvedRepoDir, rawFile);
const relative = path.relative(resolvedRepoDir, resolvedPath);
if (relative.startsWith('..') || path.isAbsolute(relative)) {
throw new Error('worker status file resolves outside repo');
}
return resolvedPath;
}

function readSnapshot(snapshotPath) {
try {
const raw = fs.readFileSync(snapshotPath, 'utf8');
const parsed = JSON.parse(raw);
if (Array.isArray(parsed)) return { workers: parsed };
if (parsed && typeof parsed === 'object') {
return { ...parsed, workers: Array.isArray(parsed.workers) ? parsed.workers : [] };
}
} catch (error) {
if (error.code !== 'ENOENT') throw error;
}
return { workers: [] };
}

function buildWorkerPatch({ id, label, provider, status, sessionId, updatedAt, now, note }) {
const workerId = normalizeString(id);
if (!workerId) throw new Error('worker id is required');

const patch = {
id: workerId,
status: normalizeWorkerStatus(status),
updated_at: normalizeString(updatedAt || now || new Date().toISOString()),
};
const normalizedLabel = normalizeString(label);
const normalizedProvider = normalizeString(provider);
const normalizedSessionId = normalizeString(sessionId);
const normalizedNote = normalizeString(note);
if (normalizedLabel) patch.label = normalizedLabel;
if (normalizedProvider) patch.provider = normalizedProvider;
if (normalizedSessionId) patch.session_id = normalizedSessionId;
if (normalizedNote) patch.note = normalizedNote;
return patch;
}

function writeSnapshotAtomic(snapshotPath, snapshot) {
fs.mkdirSync(path.dirname(snapshotPath), { recursive: true });
const tmpPath = `${snapshotPath}.${process.pid}.${Date.now()}.tmp`;
fs.writeFileSync(tmpPath, `${JSON.stringify(snapshot, null, 2)}\n`);
fs.renameSync(tmpPath, snapshotPath);
}

function upsertWorkerStatus(options) {
const snapshotPath = resolveWorkerStatusPath(options.repoDir, options.file);
const snapshot = readSnapshot(snapshotPath);
const patch = buildWorkerPatch(options);
const workers = new Map();

for (const worker of snapshot.workers) {
if (worker && typeof worker === 'object' && normalizeString(worker.id)) {
workers.set(normalizeString(worker.id), { ...worker });
}
}

workers.set(patch.id, {
...(workers.get(patch.id) || {}),
...patch,
});

const nextSnapshot = {
...snapshot,
updated_at: patch.updated_at,
workers: Array.from(workers.values()).sort((a, b) => String(a.id).localeCompare(String(b.id))),
};
writeSnapshotAtomic(snapshotPath, nextSnapshot);
return nextSnapshot;
}

module.exports = {
resolveWorkerStatusPath,
upsertWorkerStatus,
};
Loading