feat(desktop): attest and manage the owned Windows host lifecycle

This commit is contained in:
Agent Workbench Dev
2026-10-31 09:03:01 +08:00
parent e634a252dd
commit 249f191ebc
32 changed files with 1765 additions and 70 deletions
+6 -1
View File
@@ -10,6 +10,7 @@ import { Runtime } from './runtime.mjs';
import { createRequestHandler, createSessionPublisher } from './app.mjs';
import { APP_VERSION } from './diagnostics.mjs';
import { ConfigImporter } from '../core/models/config-import.mjs';
import { hostAuthority } from '../core/desktop/host-authority.mjs';
const appDirectory = process.env.AGENT_WORKBENCH_APP_DIR || path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const dataDirectory = process.env.AGENT_WORKBENCH_DATA_DIR || path.join(process.env.LOCALAPPDATA || path.join(os.homedir(), '.local', 'share'), 'AgentWorkbench');
@@ -40,13 +41,15 @@ try {
store.on('update', createSessionPublisher(clients));
const server = http.createServer();
server.workbenchReady = false;
server.on('request', createRequestHandler({ appDirectory, server, store, provider, runtime, token, clients, started,
getPort: () => actualPort, exampleProject, shutdown }));
async function shutdown() {
if (closing) return; closing = true;
clearInterval(modelImportSync);
await runtime.stopAll();
try { await Promise.all([provider.abortRequests(), runtime.stopAll()]); }
catch (cause) { closing = false; provider.resumeRequests(); console.error('Workbench shutdown remains unverified: ' + provider.redact(cause.message)); return; }
for (const response of clients) response.end();
clients.clear();
server.close(() => { store.close(); process.exit(0); });
@@ -56,5 +59,7 @@ process.on('SIGINT', shutdown); process.on('SIGTERM', shutdown);
server.on('error', error => { store.close(); console.error('Workbench could not start: ' + error.message); process.exitCode = 1; });
server.listen(requestedPort, '127.0.0.1', () => {
actualPort = server.address().port;
try { hostAuthority({ appDirectory, server, store, provider, runtime }).initialize(); server.workbenchReady = true; }
catch (cause) { console.error('Workbench registration failed: ' + provider.redact(cause.message)); server.close(() => { store.close(); process.exit(1); }); return; }
console.log(JSON.stringify({ app: 'agent-workbench', ready: true, url: 'http://127.0.0.1:' + actualPort, version: APP_VERSION }));
});