Skip to content

An agentic skills framework & software development methodology that works.

Auto-exit server after 30 minutes idle, add liveness check to skill

Jesse Vincent263e3268f45f
diff --git a/skills/brainstorming/scripts/server.js b/skills/brainstorming/scripts/server.js
index 6dec0bf14..82db1a67e 100644
--- a/skills/brainstorming/scripts/server.js
+++ b/skills/brainstorming/scripts/server.js
@@ -124,6 +124,7 @@ function getNewestScreen() {
// ========== HTTP Request Handler ==========
function handleRequest(req, res) {
+ touchActivity();
if (req.method === 'GET' && req.url === '/') {
const screenFile = getNewestScreen();
let html = screenFile
@@ -225,6 +226,7 @@ function handleMessage(text) {
console.error('Failed to parse WebSocket message:', e.message);
return;
}
+ touchActivity();
console.log(JSON.stringify({ source: 'user-event', ...event }));
if (event.choice) {
const eventsFile = path.join(SCREEN_DIR, '.events');
@@ -239,6 +241,15 @@ function broadcast(msg) {
}
}
+// ========== Activity Tracking ==========
+
+const IDLE_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
+let lastActivity = Date.now();
+
+function touchActivity() {
+ lastActivity = Date.now();
+}
+
// ========== File Watching ==========
const debounceTimers = new Map();
@@ -267,6 +278,7 @@ function startServer() {
const filePath = path.join(SCREEN_DIR, filename);
if (!fs.existsSync(filePath)) return; // file was deleted
+ touchActivity();
if (!knownFiles.has(filename)) {
knownFiles.add(filename);
@@ -282,6 +294,23 @@ function startServer() {
});
watcher.on('error', (err) => console.error('fs.watch error:', err.message));
+ // Exit if no activity for 30 minutes (prevents orphaned servers)
+ const idleCheck = setInterval(() => {
+ if (Date.now() - lastActivity > IDLE_TIMEOUT_MS) {
+ console.log(JSON.stringify({ type: 'server-stopped', reason: 'idle timeout' }));
+ const infoFile = path.join(SCREEN_DIR, '.server-info');
+ if (fs.existsSync(infoFile)) fs.unlinkSync(infoFile);
+ fs.writeFileSync(
+ path.join(SCREEN_DIR, '.server-stopped'),
+ JSON.stringify({ reason: 'idle timeout', timestamp: Date.now() }) + '\n'
+ );
+ watcher.close();
+ clearInterval(idleCheck);
+ server.close(() => process.exit(0));
+ }
+ }, 60 * 1000); // check every minute
+ idleCheck.unref(); // don't keep process alive just for the timer
+
server.listen(PORT, HOST, () => {
const info = JSON.stringify({
type: 'server-started', port: Number(PORT), host: HOST,
diff --git a/skills/brainstorming/visual-companion.md b/skills/brainstorming/visual-companion.md
index b5f308dcc..a25e85aa1 100644
--- a/skills/brainstorming/visual-companion.md
+++ b/skills/brainstorming/visual-companion.md
@@ -83,7 +83,8 @@ Use `--url-host` to control what hostname is printed in the returned URL JSON.
## The Loop
-1. **Write HTML** to a new file in `screen_dir`:
+1. **Check server is alive**, then **write HTML** to a new file in `screen_dir`:
+ - Before each write, check that `$SCREEN_DIR/.server-info` exists. If it doesn't (or `.server-stopped` exists), the server has shut down — restart it with `start-server.sh` before continuing. The server auto-exits after 30 minutes of inactivity.
- Use semantic filenames: `platform.html`, `visual-style.html`, `layout.html`
- **Never reuse filenames** — each screen gets a fresh file
- Use Write tool — **never use cat/heredoc** (dumps noise into terminal)