@volter/supercode-teams 0.2.99 → 0.2.100
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/bin/workspace.mjs +25 -0
- package/package.json +1 -1
package/bin/workspace.mjs
CHANGED
|
@@ -19,6 +19,9 @@ import { duration, parseArgs, positiveInteger, requireArgs, usage } from './work
|
|
|
19
19
|
import { reserveArtifactDirectory, reserveProtected, writeProtected } from './workspace/files.mjs';
|
|
20
20
|
import { acquireLifecycle, activeSocket, lifecycleHeld, requestStop } from './workspace/lifecycle.mjs';
|
|
21
21
|
import { retireLinklessDaemon, watchCodeChange } from './workspace/upgrade-watch.mjs';
|
|
22
|
+
|
|
23
|
+
/** How long a service-run connector's machine link may stay down before the connector restarts itself. */
|
|
24
|
+
const LINK_LOST_MS = 120_000;
|
|
22
25
|
import { volterDeviceSignIn } from './workspace/volter-device.mjs';
|
|
23
26
|
import { loginSummary, signInToTeams } from './workspace/volter-login.mjs';
|
|
24
27
|
import { readSharedSignIn, signOut } from '@volter/identity';
|
|
@@ -733,6 +736,15 @@ async function connectorCommand(verb, { flags, rest, output, client, context, te
|
|
|
733
736
|
// A connected machine is a person's: each pane it launches opens a window on its screen (SUPERCODE_POPUPS=0: none).
|
|
734
737
|
const machine = new TeamsMachine({ home: daemonHome, supercode: binary, popups: process.env.SUPERCODE_POPUPS !== '0', ...(flags.tmux_socket ? { tmuxSocket: String(flags.tmux_socket) } : {}), link: { server: context.origin, teamId: context.team_id, machineId: saved.machine.id, credential: saved.credential.token, incarnationId: connector.state.incarnation_id, configuration: () => connector.configuration() }, onTurn: (turn) => connector.noteTurn(turn), onTurnWithdrawn: (turn) => connector.withdrawTurn(turn) });
|
|
735
738
|
machine.on('link', (event) => { if (event.event === 'replaced') process.stderr.write(`supercode teams: ${event.error}. Two connectors were running for this machine; stop one of them (\`supercode teams disconnect\` where it should not run).\n`); });
|
|
739
|
+
// The link's state for the watch after start: down until it is up, down again (since when) when it drops. A
|
|
740
|
+
// `replaced` link is left alone: another connector for this machine owns it, by design.
|
|
741
|
+
let linkDownSince = Date.now();
|
|
742
|
+
let linkReplaced = false;
|
|
743
|
+
machine.on('link', (event) => {
|
|
744
|
+
if (event.event === 'up') linkDownSince = null;
|
|
745
|
+
else if (event.event === 'dropped') linkDownSince ??= Date.now();
|
|
746
|
+
else if (event.event === 'replaced') linkReplaced = true;
|
|
747
|
+
});
|
|
736
748
|
// The connector is the service's daemon and keeps serving; a daemon that took its socket path is the one to stop.
|
|
737
749
|
machine.on('superseded', (path) => process.stderr.write(`supercode teams: another machine daemon replaced this connector's socket at ${path}; stop it (supercode teams status)\n`));
|
|
738
750
|
const stopAll = async () => { await machine.stop().catch(() => {}); await connector.stop(); await core.close(); await largeCore.close(); await slowCore.close(); await liveCore.close(); await lifecycle.close(); state.update(current => current ? ({ ...current, process: undefined }) : null); };
|
|
@@ -762,6 +774,19 @@ async function connectorCommand(verb, { flags, rest, output, client, context, te
|
|
|
762
774
|
if (process.platform !== 'win32') setTimeout(async () => { await stopConnector?.(); process.exit(75); }, 60_000);
|
|
763
775
|
});
|
|
764
776
|
}
|
|
777
|
+
// Run by a service, a connector whose machine link stays down restarts itself, so a machine is never left
|
|
778
|
+
// unreachable with no remote way back (the Mac mini sat unlinked for hours while its connector lived on): a
|
|
779
|
+
// daemon that died, a start that half failed or a link its backoff never recovered all end in a fresh start.
|
|
780
|
+
// It exits non-zero, which every service manager here restarts.
|
|
781
|
+
if (saved.service) {
|
|
782
|
+
const linkWatch = setInterval(() => {
|
|
783
|
+
if (linkReplaced || linkDownSince === null || Date.now() - linkDownSince < LINK_LOST_MS) return;
|
|
784
|
+
clearInterval(linkWatch);
|
|
785
|
+
process.stderr.write(`supercode teams: this machine has had no link to its Teams server for ${Math.round((Date.now() - linkDownSince) / 1000)} s; restarting the connector\n`);
|
|
786
|
+
void (async () => { await stopConnector?.(); process.exit(75); })();
|
|
787
|
+
}, 15_000);
|
|
788
|
+
linkWatch.unref?.();
|
|
789
|
+
}
|
|
765
790
|
await new Promise(resolveStop => { let stopped = false; stopConnector = async () => { if (stopped) return; stopped = true; await stopAll(); resolveStop(); }; for (const signal of ['SIGINT', 'SIGTERM', ...(process.platform === 'win32' ? ['SIGHUP', 'SIGBREAK'] : [])]) process.once(signal, stopConnector); });
|
|
766
791
|
return;
|
|
767
792
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.100",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A machine daemon serving this machine's doors, and a local or remote Teams server for shared session discovery, OpenTelemetry ingestion and access to enrolled machines.",
|
|
6
6
|
"license": "MIT",
|