pixelcrew 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/server.js +22 -3
package/package.json
CHANGED
package/src/server/server.js
CHANGED
|
@@ -34,7 +34,7 @@ export function createServer(engine, options = {}) {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
// Watch events.jsonl for direct external CLI
|
|
37
|
+
// Watch events.jsonl for direct external CLI / IDE writes
|
|
38
38
|
let lastKnownEventCount = 0;
|
|
39
39
|
if (engine.eventsPath) {
|
|
40
40
|
try {
|
|
@@ -44,7 +44,7 @@ export function createServer(engine, options = {}) {
|
|
|
44
44
|
lastKnownEventCount = 0;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
fsSync.watchFile(engine.eventsPath, { interval:
|
|
47
|
+
fsSync.watchFile(engine.eventsPath, { interval: 150 }, async () => {
|
|
48
48
|
try {
|
|
49
49
|
const content = await fs.readFile(engine.eventsPath, 'utf-8');
|
|
50
50
|
const lines = content.trim().split('\n').filter(Boolean);
|
|
@@ -54,7 +54,11 @@ export function createServer(engine, options = {}) {
|
|
|
54
54
|
for (const line of newLines) {
|
|
55
55
|
try {
|
|
56
56
|
const event = JSON.parse(line);
|
|
57
|
-
//
|
|
57
|
+
// Update in-memory event history
|
|
58
|
+
engine.eventHistory.push(event);
|
|
59
|
+
if (engine.eventHistory.length > 200) engine.eventHistory.shift();
|
|
60
|
+
|
|
61
|
+
// Broadcast over SSE immediately
|
|
58
62
|
const payload = `event: agent_event\ndata: ${JSON.stringify(event)}\n\n`;
|
|
59
63
|
for (const client of sseClients) {
|
|
60
64
|
try { client.write(payload); } catch {}
|
|
@@ -66,6 +70,21 @@ export function createServer(engine, options = {}) {
|
|
|
66
70
|
});
|
|
67
71
|
}
|
|
68
72
|
|
|
73
|
+
// Watch state.json for direct external updates
|
|
74
|
+
if (engine.statePath) {
|
|
75
|
+
fsSync.watchFile(engine.statePath, { interval: 150 }, async () => {
|
|
76
|
+
try {
|
|
77
|
+
const content = await fs.readFile(engine.statePath, 'utf-8');
|
|
78
|
+
const state = JSON.parse(content);
|
|
79
|
+
engine.state = state;
|
|
80
|
+
const payload = `event: state_change\ndata: ${JSON.stringify({ state })}\n\n`;
|
|
81
|
+
for (const client of sseClients) {
|
|
82
|
+
try { client.write(payload); } catch {}
|
|
83
|
+
}
|
|
84
|
+
} catch {}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
const server = http.createServer(async (req, res) => {
|
|
70
89
|
// Enable CORS
|
|
71
90
|
res.setHeader('Access-Control-Allow-Origin', '*');
|