repoburg 1.3.303 → 1.3.305
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/agent-pane/backend/dist/index.js +3936 -717
- package/agent-pane/backend/dist/server.js +4031 -717
- package/agent-pane/backend/scripts/session-host.mjs +860 -0
- package/agent-pane/frontend/dist/assets/{TerminalView-C6AkFuDP.js → TerminalView-CWb7lwEQ.js} +1 -1
- package/agent-pane/frontend/dist/assets/index-B5j2jGP4.css +1 -0
- package/agent-pane/frontend/dist/assets/index-BhyGOapD.js +836 -0
- package/agent-pane/frontend/dist/index.html +2 -2
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +30 -2
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +108 -6
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js.map +1 -1
- package/backend/dist/src/agent-runtime/agent-runtime.controller.d.ts +4 -2
- package/backend/dist/src/agent-runtime/agent-runtime.controller.js +49 -9
- package/backend/dist/src/agent-runtime/agent-runtime.controller.js.map +1 -1
- package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +20 -1
- package/backend/dist/src/interactive-chat/chat.service.js +9 -2
- package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
- package/backend/dist/src/session-inputs/session-inputs.module.js +2 -0
- package/backend/dist/src/session-inputs/session-inputs.module.js.map +1 -1
- package/backend/dist/src/session-inputs/session-inputs.service.d.ts +4 -1
- package/backend/dist/src/session-inputs/session-inputs.service.js +15 -2
- package/backend/dist/src/session-inputs/session-inputs.service.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/daemon/dist/agentPane.js +6 -2
- package/daemon/dist/agents.js +74 -0
- package/daemon/dist/agents.spec.js +90 -0
- package/daemon/dist/api/agents.js +38 -0
- package/daemon/dist/api/services.js +25 -0
- package/daemon/dist/index.js +7 -3
- package/daemon/dist/serviceManager.js +28 -2
- package/daemon/dist/serviceRoller.js +133 -0
- package/daemon/dist/serviceRoller.spec.js +132 -0
- package/package.json +2 -1
- package/tabtape/extension/dist/build-info.json +3 -3
- package/tabtape/extension/dist/manifest.json +1 -1
- package/tabtape/ui/dist/build-info.json +3 -3
- package/agent-pane/frontend/dist/assets/index-CuJZVIUh.css +0 -1
- package/agent-pane/frontend/dist/assets/index-DoReiVY-.js +0 -834
package/daemon/dist/agentPane.js
CHANGED
|
@@ -93,10 +93,14 @@ async function loadAgentPane(opts = {}) {
|
|
|
93
93
|
});
|
|
94
94
|
},
|
|
95
95
|
startAutoResume: mod.startAutoResume
|
|
96
|
-
? () => {
|
|
97
|
-
mod.startAutoResume?.()
|
|
96
|
+
? (opts) => {
|
|
97
|
+
void Promise.resolve(mod.startAutoResume?.(opts)).catch((err) => {
|
|
98
|
+
console.error('[agentPane] auto-resume failed:', err);
|
|
99
|
+
});
|
|
98
100
|
}
|
|
99
101
|
: undefined,
|
|
102
|
+
runningAgents: mod.runningAgents,
|
|
103
|
+
stopAllAgents: mod.stopAllAgents,
|
|
100
104
|
shutdown: mod.shutdownAllProviders,
|
|
101
105
|
handleVscodeUpgrade: mod.handleVscodeWebUpgrade,
|
|
102
106
|
handleTerminalUpgrade: mod.handleTerminalUpgrade,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The agents of this machine as a whole, for the app's Quit row:
|
|
4
|
+
*
|
|
5
|
+
* GET /agents running turns: Claude and Codex from the pane, Repoburg
|
|
6
|
+
* from the workspace backends (they also see the turns
|
|
7
|
+
* started outside the pane). A plain Quit leaves them
|
|
8
|
+
* running: Claude and Codex in their session hosts,
|
|
9
|
+
* Repoburg in its pm2 backend.
|
|
10
|
+
* POST /agents/stop "Quit and Stop Agents": the pane stops its turns and
|
|
11
|
+
* shuts down every session host, then each backend's turns
|
|
12
|
+
* in flight are cancelled. Nothing is left for the next
|
|
13
|
+
* start to adopt or resume.
|
|
14
|
+
*
|
|
15
|
+
* A Repoburg turn between two LLM rounds (running an action) takes the
|
|
16
|
+
* cancel at its next round, so cancels are sent a few times; turns still in
|
|
17
|
+
* flight after that are reported as `left`.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Agents = void 0;
|
|
21
|
+
exports.cancelBackendTurn = cancelBackendTurn;
|
|
22
|
+
const CANCEL_ROUNDS = 4;
|
|
23
|
+
class Agents {
|
|
24
|
+
constructor(deps) {
|
|
25
|
+
this.deps = deps;
|
|
26
|
+
}
|
|
27
|
+
async count() {
|
|
28
|
+
const pane = this.deps.pane?.runningAgents?.() ?? { claude: 0, codex: 0, repoburg: 0 };
|
|
29
|
+
const busy = await this.busySessions();
|
|
30
|
+
const inBackends = busy.reduce((sum, b) => sum + b.turns, 0);
|
|
31
|
+
// The backends see the pane's Repoburg turns too; one that does not
|
|
32
|
+
// answer still has the pane's.
|
|
33
|
+
const repoburg = Math.max(pane.repoburg, inBackends);
|
|
34
|
+
return { claude: pane.claude, codex: pane.codex, repoburg, total: pane.claude + pane.codex + repoburg };
|
|
35
|
+
}
|
|
36
|
+
async stopAll() {
|
|
37
|
+
const pane = (await this.deps.pane?.stopAllAgents?.()) ?? { turns: 0, hosts: 0 };
|
|
38
|
+
const cancelled = new Set();
|
|
39
|
+
let left = 0;
|
|
40
|
+
for (let round = 0; round < CANCEL_ROUNDS; round++) {
|
|
41
|
+
const sessions = (await this.busySessions()).flatMap((b) => b.sessions.map((id) => ({ port: b.port, id })));
|
|
42
|
+
left = sessions.length;
|
|
43
|
+
if (left === 0 || round === CANCEL_ROUNDS - 1)
|
|
44
|
+
break;
|
|
45
|
+
for (const { port, id } of sessions) {
|
|
46
|
+
try {
|
|
47
|
+
await this.deps.cancel(port, id);
|
|
48
|
+
cancelled.add(`${port}:${id}`);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.warn(`[agents] cancel of ${id} on :${port} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await new Promise((r) => setTimeout(r, this.deps.roundMs ?? 500));
|
|
55
|
+
}
|
|
56
|
+
const report = { turns: pane.turns, hosts: pane.hosts, repoburg: cancelled.size, left };
|
|
57
|
+
console.log(`[agents] stopped: ${JSON.stringify(report)}`);
|
|
58
|
+
return report;
|
|
59
|
+
}
|
|
60
|
+
async busySessions() {
|
|
61
|
+
const answers = await Promise.all(this.deps.backends().map(async (port) => ({ port, activity: await this.deps.activity(port).catch(() => 'no-answer') })));
|
|
62
|
+
return answers.flatMap(({ port, activity }) => typeof activity === 'object' ? [{ port, turns: activity.turnsInFlight, sessions: activity.sessions ?? [] }] : []);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.Agents = Agents;
|
|
66
|
+
/** POST /streaming/:sessionId/cancel of a backend on 127.0.0.1. */
|
|
67
|
+
async function cancelBackendTurn(port, sessionId, timeoutMs = 5000) {
|
|
68
|
+
const response = await fetch(`http://127.0.0.1:${port}/streaming/${encodeURIComponent(sessionId)}/cancel`, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok)
|
|
73
|
+
throw new Error(`HTTP ${response.status}`);
|
|
74
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = __importDefault(require("http"));
|
|
7
|
+
const agents_1 = require("./agents");
|
|
8
|
+
/** Backends by port: the sessions in flight; a cancel ends a session once
|
|
9
|
+
* its countdown reaches zero (a turn between two LLM rounds). */
|
|
10
|
+
function backends(state) {
|
|
11
|
+
const cancels = [];
|
|
12
|
+
const deps = {
|
|
13
|
+
backends: () => Object.keys(state).map(Number),
|
|
14
|
+
activity: async (port) => {
|
|
15
|
+
const s = state[port];
|
|
16
|
+
if (typeof s === 'string' || 'turnsInFlight' in s)
|
|
17
|
+
return s;
|
|
18
|
+
const sessions = Object.keys(s);
|
|
19
|
+
return { turnsInFlight: sessions.length, sessions };
|
|
20
|
+
},
|
|
21
|
+
cancel: async (port, id) => {
|
|
22
|
+
cancels.push(`${port}:${id}`);
|
|
23
|
+
const s = state[port];
|
|
24
|
+
s[id] -= 1;
|
|
25
|
+
if (s[id] <= 0)
|
|
26
|
+
delete s[id];
|
|
27
|
+
},
|
|
28
|
+
roundMs: 1,
|
|
29
|
+
};
|
|
30
|
+
return { deps, cancels };
|
|
31
|
+
}
|
|
32
|
+
const pane = (counts = { claude: 2, codex: 1, repoburg: 1 }) => {
|
|
33
|
+
const stops = [];
|
|
34
|
+
const handle = {
|
|
35
|
+
runningAgents: () => counts,
|
|
36
|
+
stopAllAgents: async () => {
|
|
37
|
+
stops.push(Date.now());
|
|
38
|
+
return { turns: 4, hosts: 3 };
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
return { handle, stops };
|
|
42
|
+
};
|
|
43
|
+
describe('Agents', () => {
|
|
44
|
+
it('U12: counts Claude and Codex in the pane and Repoburg in the backends', async () => {
|
|
45
|
+
const { deps } = backends({ 3400: { a: 1, b: 1 }, 3401: 'no-route', 3402: 'down' });
|
|
46
|
+
const agents = new agents_1.Agents({ ...deps, pane: pane().handle });
|
|
47
|
+
// The pane's Repoburg turn is one of the backend's two.
|
|
48
|
+
expect(await agents.count()).toEqual({ claude: 2, codex: 1, repoburg: 2, total: 5 });
|
|
49
|
+
});
|
|
50
|
+
it('a backend that does not answer still counts the pane\'s Repoburg turns; no pane, no bundle support', async () => {
|
|
51
|
+
const { deps } = backends({ 3400: 'no-answer' });
|
|
52
|
+
expect(await new agents_1.Agents({ ...deps, pane: pane().handle }).count()).toMatchObject({ repoburg: 1, total: 4 });
|
|
53
|
+
expect(await new agents_1.Agents({ ...deps, pane: null }).count()).toEqual({ claude: 0, codex: 0, repoburg: 0, total: 0 });
|
|
54
|
+
expect(await new agents_1.Agents({ ...deps, pane: {} }).count()).toMatchObject({ total: 0 });
|
|
55
|
+
});
|
|
56
|
+
it('U11: stop-all stops the pane first, then cancels each backend turn until none runs', async () => {
|
|
57
|
+
// b takes the cancel only at its next round.
|
|
58
|
+
const { deps, cancels } = backends({ 3400: { a: 1, b: 2 }, 3401: { c: 1 } });
|
|
59
|
+
const { handle, stops } = pane();
|
|
60
|
+
const report = await new agents_1.Agents({ ...deps, pane: handle }).stopAll();
|
|
61
|
+
expect(stops).toHaveLength(1);
|
|
62
|
+
expect(report).toEqual({ turns: 4, hosts: 3, repoburg: 3, left: 0 });
|
|
63
|
+
expect(cancels).toEqual(['3400:a', '3400:b', '3401:c', '3400:b']);
|
|
64
|
+
});
|
|
65
|
+
it('reports what is still in flight after the last round', async () => {
|
|
66
|
+
const { deps } = backends({ 3400: { stuck: 99 } });
|
|
67
|
+
const report = await new agents_1.Agents({ ...deps, pane: null }).stopAll();
|
|
68
|
+
expect(report).toEqual({ turns: 0, hosts: 0, repoburg: 1, left: 1 });
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('cancelBackendTurn', () => {
|
|
72
|
+
it('posts the cancel of the session', async () => {
|
|
73
|
+
const seen = [];
|
|
74
|
+
const server = http_1.default.createServer((req, res) => {
|
|
75
|
+
seen.push(`${req.method} ${req.url}`);
|
|
76
|
+
res.writeHead(req.url === '/streaming/s%201/cancel' ? 200 : 404).end('{}');
|
|
77
|
+
});
|
|
78
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve()));
|
|
79
|
+
const port = server.address().port;
|
|
80
|
+
try {
|
|
81
|
+
await (0, agents_1.cancelBackendTurn)(port, 's 1');
|
|
82
|
+
await expect((0, agents_1.cancelBackendTurn)(port, 'x/y')).rejects.toThrow('HTTP 404');
|
|
83
|
+
expect(seen).toEqual(['POST /streaming/s%201/cancel', 'POST /streaming/x%2Fy/cancel']);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
server.closeAllConnections();
|
|
87
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAgentsRouter = createAgentsRouter;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const agents_1 = require("../agents");
|
|
6
|
+
const serviceManager_1 = require("../serviceManager");
|
|
7
|
+
const serviceRoller_1 = require("../serviceRoller");
|
|
8
|
+
/** GET /agents and POST /agents/stop (see agents.ts). */
|
|
9
|
+
function createAgentsRouter(pane) {
|
|
10
|
+
const agents = new agents_1.Agents({
|
|
11
|
+
pane,
|
|
12
|
+
backends: () => serviceManager_1.serviceManager
|
|
13
|
+
.list()
|
|
14
|
+
.filter((service) => service.status === 'running' && service.port)
|
|
15
|
+
.map((service) => service.port),
|
|
16
|
+
// The app asks every few seconds: a slow backend must not hold it up.
|
|
17
|
+
activity: (port) => (0, serviceRoller_1.backendActivity)(port, 1500),
|
|
18
|
+
cancel: (port, sessionId) => (0, agents_1.cancelBackendTurn)(port, sessionId),
|
|
19
|
+
});
|
|
20
|
+
const router = (0, express_1.Router)();
|
|
21
|
+
router.get('/', async (_req, res) => {
|
|
22
|
+
try {
|
|
23
|
+
res.json(await agents.count());
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
res.status(500).json({ error: error instanceof Error ? error.message : String(error) });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
router.post('/stop', async (_req, res) => {
|
|
30
|
+
try {
|
|
31
|
+
res.json(await agents.stopAll());
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
res.status(500).json({ error: error instanceof Error ? error.message : String(error) });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return router;
|
|
38
|
+
}
|
|
@@ -3,12 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.serviceRoller = void 0;
|
|
6
7
|
const express_1 = require("express");
|
|
7
8
|
const serviceManager_1 = require("../serviceManager");
|
|
9
|
+
const serviceRoller_1 = require("../serviceRoller");
|
|
8
10
|
const checkAuth_1 = require("../middleware/checkAuth");
|
|
9
11
|
const workspace_validation_1 = require("../workspace-validation");
|
|
10
12
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
13
|
const router = (0, express_1.Router)();
|
|
14
|
+
/** Rolls services onto this daemon's runtime once idle (see serviceRoller.ts). */
|
|
15
|
+
exports.serviceRoller = new serviceRoller_1.ServiceRoller({
|
|
16
|
+
services: () => serviceManager_1.serviceManager.rollCandidates(),
|
|
17
|
+
script: serviceManager_1.serviceManager.backendScript(),
|
|
18
|
+
activity: (port) => (0, serviceRoller_1.backendActivity)(port),
|
|
19
|
+
restart: async (target) => {
|
|
20
|
+
await serviceManager_1.serviceManager.roll(target.name);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
12
23
|
router.get('/', (req, res) => {
|
|
13
24
|
try {
|
|
14
25
|
const services = serviceManager_1.serviceManager.list();
|
|
@@ -66,6 +77,20 @@ router.delete('/:name', async (req, res) => {
|
|
|
66
77
|
res.status(404).json({ error: message });
|
|
67
78
|
}
|
|
68
79
|
});
|
|
80
|
+
// After an update: restart the services of another runtime version with this
|
|
81
|
+
// one, each once it runs no turn. Answers at once; busy ones are `waiting`.
|
|
82
|
+
router.post('/roll', checkAuth_1.checkAuth, async (req, res) => {
|
|
83
|
+
try {
|
|
84
|
+
res.json(await exports.serviceRoller.roll());
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const message = error instanceof Error ? error.message : 'An unknown error occurred';
|
|
88
|
+
res.status(500).json({ error: message });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
router.get('/roll', (req, res) => {
|
|
92
|
+
res.json({ waiting: exports.serviceRoller.waiting() });
|
|
93
|
+
});
|
|
69
94
|
router.post('/remove-all', async (req, res) => {
|
|
70
95
|
try {
|
|
71
96
|
const result = await serviceManager_1.serviceManager.removeAll();
|
package/daemon/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const cors_1 = __importDefault(require("cors"));
|
|
|
11
11
|
const serviceManager_1 = require("./serviceManager");
|
|
12
12
|
const originGuard_1 = require("./middleware/originGuard");
|
|
13
13
|
const services_1 = __importDefault(require("./api/services"));
|
|
14
|
+
const agents_1 = require("./api/agents");
|
|
14
15
|
const auth_1 = __importDefault(require("./api/auth"));
|
|
15
16
|
const registry_1 = __importDefault(require("./api/registry"));
|
|
16
17
|
const mcp_gateway_1 = require("./mcp-gateway");
|
|
@@ -93,6 +94,8 @@ async function main() {
|
|
|
93
94
|
app.use('/remote', (0, routes_1.createRemoteRouter)());
|
|
94
95
|
// API Routers
|
|
95
96
|
app.use('/services', services_1.default);
|
|
97
|
+
// Running agents and "Quit and Stop Agents" (the app's Quit row).
|
|
98
|
+
app.use('/agents', (0, agents_1.createAgentsRouter)(pane));
|
|
96
99
|
app.use('/auth', (0, auth_1.default)(wss));
|
|
97
100
|
app.use('/registry', registry_1.default);
|
|
98
101
|
// Session event recorder: POST /recorder/events (collector) + static bundle
|
|
@@ -156,10 +159,11 @@ async function main() {
|
|
|
156
159
|
console.log(`Repoburg Platform Daemon listening on http://127.0.0.1:${PORT}`);
|
|
157
160
|
console.log(`MCP Gateway available at http://localhost:${PORT}/mcp`);
|
|
158
161
|
tabtape = loadTabtape();
|
|
159
|
-
//
|
|
160
|
-
//
|
|
162
|
+
// Adopt the agents the previous daemon left running in session hosts and
|
|
163
|
+
// resume the turns it left interrupted (restart, crash, power loss) —
|
|
164
|
+
// only now that the port is ours.
|
|
161
165
|
try {
|
|
162
|
-
pane?.startAutoResume?.();
|
|
166
|
+
pane?.startAutoResume?.({ daemonUrl: `http://127.0.0.1:${PORT}` });
|
|
163
167
|
}
|
|
164
168
|
catch (err) {
|
|
165
169
|
console.error('[agentPane] auto-resume failed to start:', err);
|
|
@@ -210,7 +210,32 @@ class ServiceManager {
|
|
|
210
210
|
err: path_1.default.join(pm2Home, 'logs', `${name}-error.log`),
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
|
|
213
|
+
/** The backend script this daemon starts services with. */
|
|
214
|
+
backendScript() {
|
|
215
|
+
return backendScriptPath(__dirname);
|
|
216
|
+
}
|
|
217
|
+
/** Running services with the script pm2 runs each with (rolling, see
|
|
218
|
+
* serviceRoller.ts). */
|
|
219
|
+
async rollCandidates() {
|
|
220
|
+
const processes = await this.listPm2();
|
|
221
|
+
return stateManager_1.stateManager
|
|
222
|
+
.getServices()
|
|
223
|
+
.filter((service) => service.status === 'running')
|
|
224
|
+
.map((service) => {
|
|
225
|
+
const proc = processes.find((p) => p.name === service.name);
|
|
226
|
+
const script = proc?.pm2_env?.pm_exec_path ?? null;
|
|
227
|
+
return { name: service.name, path: service.path, port: service.port, script };
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/** Restart a service with this daemon's backend script, on its port when
|
|
231
|
+
* that is free (the pane keeps its URL). */
|
|
232
|
+
async roll(name) {
|
|
233
|
+
const service = stateManager_1.stateManager.getService(name);
|
|
234
|
+
if (!service)
|
|
235
|
+
throw new Error(`Service '${name}' not found.`);
|
|
236
|
+
return this.start(service.path, name, { port: service.port });
|
|
237
|
+
}
|
|
238
|
+
async start(projectPath, customName, opts = {}) {
|
|
214
239
|
const name = customName || path_1.default.basename(path_1.default.resolve(projectPath));
|
|
215
240
|
// Validate BEFORE the same-name replacement below: the service being
|
|
216
241
|
// replaced must not collide with itself, but every other service counts.
|
|
@@ -221,7 +246,8 @@ class ServiceManager {
|
|
|
221
246
|
console.log(`Service '${name}' already exists. Removing it before starting a new one.`);
|
|
222
247
|
await this.remove(name);
|
|
223
248
|
}
|
|
224
|
-
const
|
|
249
|
+
const range = (0, get_port_1.portNumbers)(3400, 3999);
|
|
250
|
+
const port = await (0, get_port_1.default)({ port: opts.port ? [opts.port, ...range] : range });
|
|
225
251
|
const script = backendScriptPath(__dirname);
|
|
226
252
|
console.log(`[ServiceManager] Starting backend service using script: ${script} (node: ${process.execPath})`);
|
|
227
253
|
const logPaths = this._getLogPathsForName(name);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Moving workspace backends onto this daemon's runtime after an update
|
|
4
|
+
* without cutting a turn (POST /services/roll, called by the app's Updater).
|
|
5
|
+
*
|
|
6
|
+
* A running service whose pm2 script is not this daemon's backend script was
|
|
7
|
+
* started by another runtime version. It is restarted with this daemon's
|
|
8
|
+
* script once its backend runs no turn and takes no prompt
|
|
9
|
+
* (GET /agent-runtime/activity); until then it keeps running the old
|
|
10
|
+
* version, whose folder the app's prune keeps while a process uses it.
|
|
11
|
+
*
|
|
12
|
+
* | Backend answers activity | Action |
|
|
13
|
+
* | ------------------------ | --------------------------------------- |
|
|
14
|
+
* | 0 turns | restart now |
|
|
15
|
+
* | busy | ask again every pollMs until idle |
|
|
16
|
+
* | 404 (older backend) | restart now, as the Updater did before |
|
|
17
|
+
* | connection refused | restart now: nothing runs there |
|
|
18
|
+
* | timeout, other error | ask again later |
|
|
19
|
+
*
|
|
20
|
+
* The restart keeps the service's port when it is free, so the pane's
|
|
21
|
+
* sessions keep their backend URL. Waiting lives in this process: a daemon
|
|
22
|
+
* that restarts forgets it, and the next update rolls those services again.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.ServiceRoller = exports.DEFAULT_ROLL_POLL_MS = void 0;
|
|
26
|
+
exports.backendActivity = backendActivity;
|
|
27
|
+
exports.DEFAULT_ROLL_POLL_MS = 5000;
|
|
28
|
+
class ServiceRoller {
|
|
29
|
+
constructor(deps) {
|
|
30
|
+
this.deps = deps;
|
|
31
|
+
this.timers = new Map();
|
|
32
|
+
this.pollMs = deps.pollMs ?? exports.DEFAULT_ROLL_POLL_MS;
|
|
33
|
+
this.log = deps.log ?? ((message) => console.log(`[roll] ${message}`));
|
|
34
|
+
}
|
|
35
|
+
/** Roll every service on another runtime: now when idle, later when busy. */
|
|
36
|
+
async roll() {
|
|
37
|
+
const report = { restarted: [], waiting: [], current: [], failed: [] };
|
|
38
|
+
for (const service of await this.deps.services()) {
|
|
39
|
+
if (service.script === this.deps.script) {
|
|
40
|
+
report.current.push(service.name);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (this.timers.has(service.name)) {
|
|
44
|
+
report.waiting.push(service.name);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const outcome = await this.attempt(service);
|
|
48
|
+
if (outcome === 'restarted')
|
|
49
|
+
report.restarted.push(service.name);
|
|
50
|
+
else if (outcome === 'waiting')
|
|
51
|
+
report.waiting.push(service.name);
|
|
52
|
+
else
|
|
53
|
+
report.failed.push({ name: service.name, error: outcome.error });
|
|
54
|
+
}
|
|
55
|
+
return report;
|
|
56
|
+
}
|
|
57
|
+
/** Services that wait for their turns to end. */
|
|
58
|
+
waiting() {
|
|
59
|
+
return [...this.timers.keys()];
|
|
60
|
+
}
|
|
61
|
+
/** Forget the waiting services (daemon shutdown, tests). */
|
|
62
|
+
stop() {
|
|
63
|
+
for (const timer of this.timers.values())
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
this.timers.clear();
|
|
66
|
+
}
|
|
67
|
+
async attempt(target) {
|
|
68
|
+
const activity = await this.deps.activity(target.port);
|
|
69
|
+
const busy = typeof activity === 'object' ? activity.turnsInFlight > 0 : activity === 'no-answer';
|
|
70
|
+
if (busy) {
|
|
71
|
+
this.wait(target);
|
|
72
|
+
return 'waiting';
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
await this.deps.restart(target);
|
|
76
|
+
this.log(`${target.name} restarted on this runtime`);
|
|
77
|
+
return 'restarted';
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
81
|
+
this.log(`${target.name} could not be restarted: ${error}`);
|
|
82
|
+
return { error };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
wait(target) {
|
|
86
|
+
const timer = setTimeout(() => {
|
|
87
|
+
this.timers.delete(target.name);
|
|
88
|
+
void this.again(target.name);
|
|
89
|
+
}, this.pollMs);
|
|
90
|
+
timer.unref?.();
|
|
91
|
+
this.timers.set(target.name, timer);
|
|
92
|
+
}
|
|
93
|
+
/** Check a waiting service again; it may be gone or rolled meanwhile. */
|
|
94
|
+
async again(name) {
|
|
95
|
+
try {
|
|
96
|
+
const service = (await this.deps.services()).find((s) => s.name === name);
|
|
97
|
+
if (!service || service.script === this.deps.script)
|
|
98
|
+
return;
|
|
99
|
+
await this.attempt(service);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
this.log(`${name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.ServiceRoller = ServiceRoller;
|
|
107
|
+
/** GET /agent-runtime/activity of a backend on 127.0.0.1. */
|
|
108
|
+
async function backendActivity(port, timeoutMs = 5000) {
|
|
109
|
+
let response;
|
|
110
|
+
try {
|
|
111
|
+
response = await fetch(`http://127.0.0.1:${port}/agent-runtime/activity`, {
|
|
112
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
const code = err.cause?.code;
|
|
117
|
+
return code === 'ECONNREFUSED' ? 'down' : 'no-answer';
|
|
118
|
+
}
|
|
119
|
+
if (response.status === 404)
|
|
120
|
+
return 'no-route';
|
|
121
|
+
if (!response.ok)
|
|
122
|
+
return 'no-answer';
|
|
123
|
+
try {
|
|
124
|
+
const body = (await response.json());
|
|
125
|
+
if (typeof body.turnsInFlight !== 'number')
|
|
126
|
+
return 'no-answer';
|
|
127
|
+
const sessions = Array.isArray(body.sessions) ? body.sessions.filter((s) => typeof s === 'string') : undefined;
|
|
128
|
+
return sessions ? { turnsInFlight: body.turnsInFlight, sessions } : { turnsInFlight: body.turnsInFlight };
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return 'no-answer';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = __importDefault(require("http"));
|
|
7
|
+
const serviceRoller_1 = require("./serviceRoller");
|
|
8
|
+
const NEW = '/runtime/versions/2/app/daemon/instance-entry.js';
|
|
9
|
+
const OLD = '/runtime/versions/1/app/daemon/instance-entry.js';
|
|
10
|
+
/** Services and backends the roller sees; a restart moves a service to NEW. */
|
|
11
|
+
function setup(services, activity) {
|
|
12
|
+
const restarted = [];
|
|
13
|
+
const failing = new Set();
|
|
14
|
+
const roller = new serviceRoller_1.ServiceRoller({
|
|
15
|
+
services: async () => services.map((s) => ({ ...s })),
|
|
16
|
+
script: NEW,
|
|
17
|
+
activity: async (port) => activity[port] ?? 'down',
|
|
18
|
+
restart: async (target) => {
|
|
19
|
+
if (failing.has(target.name))
|
|
20
|
+
throw new Error('pm2 said no');
|
|
21
|
+
restarted.push(target.name);
|
|
22
|
+
const service = services.find((s) => s.name === target.name);
|
|
23
|
+
service.script = NEW;
|
|
24
|
+
},
|
|
25
|
+
pollMs: 10,
|
|
26
|
+
log: () => undefined,
|
|
27
|
+
});
|
|
28
|
+
return { roller, restarted, failing };
|
|
29
|
+
}
|
|
30
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
31
|
+
describe('ServiceRoller', () => {
|
|
32
|
+
it('restarts idle services of another runtime now and leaves current ones alone', async () => {
|
|
33
|
+
const { roller, restarted } = setup([
|
|
34
|
+
{ name: 'idle', path: '/w/idle', port: 3400, script: OLD },
|
|
35
|
+
{ name: 'current', path: '/w/current', port: 3401, script: NEW },
|
|
36
|
+
], { 3400: { turnsInFlight: 0 }, 3401: { turnsInFlight: 2 } });
|
|
37
|
+
expect(await roller.roll()).toEqual({ restarted: ['idle'], waiting: [], current: ['current'], failed: [] });
|
|
38
|
+
expect(restarted).toEqual(['idle']);
|
|
39
|
+
roller.stop();
|
|
40
|
+
});
|
|
41
|
+
it('R7: a busy backend is not restarted until it is idle', async () => {
|
|
42
|
+
const activity = { 3400: { turnsInFlight: 1 } };
|
|
43
|
+
const { roller, restarted } = setup([{ name: 'busy', path: '/w/busy', port: 3400, script: OLD }], activity);
|
|
44
|
+
expect(await roller.roll()).toMatchObject({ restarted: [], waiting: ['busy'] });
|
|
45
|
+
await sleep(60);
|
|
46
|
+
expect(restarted).toEqual([]);
|
|
47
|
+
expect(roller.waiting()).toEqual(['busy']);
|
|
48
|
+
// Asked again: still waiting, one timer.
|
|
49
|
+
expect(await roller.roll()).toMatchObject({ waiting: ['busy'] });
|
|
50
|
+
activity[3400] = { turnsInFlight: 0 };
|
|
51
|
+
await sleep(60);
|
|
52
|
+
expect(restarted).toEqual(['busy']);
|
|
53
|
+
expect(roller.waiting()).toEqual([]);
|
|
54
|
+
roller.stop();
|
|
55
|
+
});
|
|
56
|
+
it('a backend from before the activity route, or one not listening, is restarted now', async () => {
|
|
57
|
+
const { roller, restarted } = setup([
|
|
58
|
+
{ name: 'old', path: '/w/old', port: 3400, script: OLD },
|
|
59
|
+
{ name: 'down', path: '/w/down', port: 3401, script: null },
|
|
60
|
+
], { 3400: 'no-route', 3401: 'down' });
|
|
61
|
+
expect((await roller.roll()).restarted).toEqual(['old', 'down']);
|
|
62
|
+
expect(restarted).toEqual(['old', 'down']);
|
|
63
|
+
});
|
|
64
|
+
it('a backend that does not answer is asked again, not restarted', async () => {
|
|
65
|
+
const activity = { 3400: 'no-answer' };
|
|
66
|
+
const { roller, restarted } = setup([{ name: 'slow', path: '/w/slow', port: 3400, script: OLD }], activity);
|
|
67
|
+
expect((await roller.roll()).waiting).toEqual(['slow']);
|
|
68
|
+
await sleep(40);
|
|
69
|
+
expect(restarted).toEqual([]);
|
|
70
|
+
roller.stop();
|
|
71
|
+
});
|
|
72
|
+
it('a waiting service that was removed or restarted meanwhile is left alone', async () => {
|
|
73
|
+
const services = [
|
|
74
|
+
{ name: 'gone', path: '/w/gone', port: 3400, script: OLD },
|
|
75
|
+
{ name: 'manual', path: '/w/manual', port: 3401, script: OLD },
|
|
76
|
+
];
|
|
77
|
+
const activity = { 3400: { turnsInFlight: 1 }, 3401: { turnsInFlight: 1 } };
|
|
78
|
+
const { roller, restarted } = setup(services, activity);
|
|
79
|
+
await roller.roll();
|
|
80
|
+
services.splice(0, 1);
|
|
81
|
+
services[0].script = NEW; // the user restarted it on this daemon
|
|
82
|
+
activity[3400] = { turnsInFlight: 0 };
|
|
83
|
+
activity[3401] = { turnsInFlight: 0 };
|
|
84
|
+
await sleep(60);
|
|
85
|
+
expect(restarted).toEqual([]);
|
|
86
|
+
expect(roller.waiting()).toEqual([]);
|
|
87
|
+
});
|
|
88
|
+
it('reports a restart that failed', async () => {
|
|
89
|
+
const { roller, failing } = setup([{ name: 'bad', path: '/w/bad', port: 3400, script: OLD }], { 3400: { turnsInFlight: 0 } });
|
|
90
|
+
failing.add('bad');
|
|
91
|
+
expect((await roller.roll()).failed).toEqual([{ name: 'bad', error: 'pm2 said no' }]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('backendActivity', () => {
|
|
95
|
+
let server;
|
|
96
|
+
let port;
|
|
97
|
+
let reply;
|
|
98
|
+
beforeAll(async () => {
|
|
99
|
+
server = http_1.default.createServer((req, res) => {
|
|
100
|
+
if (req.url !== '/agent-runtime/activity') {
|
|
101
|
+
res.writeHead(404).end();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
reply(res);
|
|
105
|
+
});
|
|
106
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve()));
|
|
107
|
+
port = server.address().port;
|
|
108
|
+
});
|
|
109
|
+
afterAll(async () => {
|
|
110
|
+
server.closeAllConnections();
|
|
111
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
112
|
+
});
|
|
113
|
+
it('reads the turns in flight', async () => {
|
|
114
|
+
reply = (res) => res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({ bootId: 'b', turnsInFlight: 3 }));
|
|
115
|
+
expect(await (0, serviceRoller_1.backendActivity)(port)).toEqual({ turnsInFlight: 3 });
|
|
116
|
+
reply = (res) => res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({ bootId: 'b', turnsInFlight: 1, sessions: ['s1', 7] }));
|
|
117
|
+
expect(await (0, serviceRoller_1.backendActivity)(port)).toEqual({ turnsInFlight: 1, sessions: ['s1'] });
|
|
118
|
+
});
|
|
119
|
+
it('tells an older backend (404), a refused connection and a slow one apart', async () => {
|
|
120
|
+
reply = (res) => res.writeHead(404).end();
|
|
121
|
+
expect(await (0, serviceRoller_1.backendActivity)(port)).toBe('no-route');
|
|
122
|
+
reply = () => undefined; // never answers
|
|
123
|
+
expect(await (0, serviceRoller_1.backendActivity)(port, 100)).toBe('no-answer');
|
|
124
|
+
reply = (res) => res.writeHead(500).end('boom');
|
|
125
|
+
expect(await (0, serviceRoller_1.backendActivity)(port)).toBe('no-answer');
|
|
126
|
+
const closed = http_1.default.createServer();
|
|
127
|
+
await new Promise((resolve) => closed.listen(0, '127.0.0.1', () => resolve()));
|
|
128
|
+
const closedPort = closed.address().port;
|
|
129
|
+
await new Promise((resolve) => closed.close(() => resolve()));
|
|
130
|
+
expect(await (0, serviceRoller_1.backendActivity)(closedPort)).toBe('down');
|
|
131
|
+
});
|
|
132
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repoburg",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.305",
|
|
4
4
|
"description": "A local AI-powered software developer assistant that runs on your own machine.",
|
|
5
5
|
"author": "Celal Ertug",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"daemon/package.json",
|
|
41
41
|
"daemon/tsconfig.json",
|
|
42
42
|
"agent-pane/backend/dist",
|
|
43
|
+
"agent-pane/backend/scripts/session-host.mjs",
|
|
43
44
|
"agent-pane/frontend/dist",
|
|
44
45
|
"agent-pane/examples",
|
|
45
46
|
"recorder/dist",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"tree": "3f01773d2dfcfcfee7b73a8c7d7497c15ad692bc",
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "3d361128eadd316f2aa54f38815549a6d3d94ed5",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"repoburgVersion": "1.3.
|
|
6
|
-
"builtAt": "2026-11-
|
|
5
|
+
"repoburgVersion": "1.3.305",
|
|
6
|
+
"builtAt": "2026-11-07T06:46:41.838Z"
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"tree": "3f01773d2dfcfcfee7b73a8c7d7497c15ad692bc",
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "3d361128eadd316f2aa54f38815549a6d3d94ed5",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"repoburgVersion": "1.3.
|
|
6
|
-
"builtAt": "2026-11-
|
|
5
|
+
"repoburgVersion": "1.3.305",
|
|
6
|
+
"builtAt": "2026-11-07T06:46:41.838Z"
|
|
7
7
|
}
|