@commonlyai/cli 0.1.398 → 0.1.400
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/commands/agent.js +16 -4
- package/src/commands/daemon.js +39 -4
- package/src/lib/adapters/codex.js +615 -22
- package/src/lib/api.js +13 -0
- package/src/lib/daemon-lock.js +187 -0
- package/src/lib/daemon-service-windows.js +38 -11
- package/src/lib/daemon-supervisor.js +47 -5
- package/src/lib/sandbox/guest-home.js +178 -0
- package/src/lib/sandbox/host-check.js +17 -2
- package/src/lib/sandbox/microsandbox.js +475 -57
- package/src/lib/sandbox/mode.js +24 -2
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -118,8 +118,10 @@ import { claimReleaseFor, ackResultFor, EMPTY_OUTPUT } from '../lib/claim-outcom
|
|
|
118
118
|
import { createClaimedWorkGate } from '../lib/claimed-work-gate.js';
|
|
119
119
|
import { prepareCommitAttribution } from '../lib/commit-attribution.js';
|
|
120
120
|
import { detectBwrap } from '../lib/sandbox/bwrap.js';
|
|
121
|
-
import { resolvePublicSandboxMode } from '../lib/sandbox/mode.js';
|
|
122
|
-
import {
|
|
121
|
+
import { resolveCodexSandboxMode, resolvePublicSandboxMode } from '../lib/sandbox/mode.js';
|
|
122
|
+
import {
|
|
123
|
+
checkMicrovmAttach, probeWhp as defaultProbeWhp, refuseMicrovmMcpDeclarations,
|
|
124
|
+
} from '../lib/sandbox/microsandbox.js';
|
|
123
125
|
import {
|
|
124
126
|
CODEX_OPTED_IN_PUBLIC_POD_MESSAGE, UNSANDBOXED_FLAG, bwrapRefusedMessage, hostSandboxRefusal, windowsSandboxMessage,
|
|
125
127
|
} from '../lib/sandbox/host-check.js';
|
|
@@ -1497,6 +1499,13 @@ export const resolveAttachSandbox = ({
|
|
|
1497
1499
|
// Both confined trusts take their mode from the host the same way; they
|
|
1498
1500
|
// differ in what the policy inside the sandbox allows, not in the sandbox.
|
|
1499
1501
|
const confined = trust === 'public' || trust === 'workspace';
|
|
1502
|
+
// A public Codex seat on native Windows with the microVM opt-in runs in the
|
|
1503
|
+
// VM whatever access it declared (mode.js resolveCodexSandboxMode), so its
|
|
1504
|
+
// attach takes the microvm branch, never the Codex-profile one.
|
|
1505
|
+
if (adapterName === 'codex' && trust === 'public'
|
|
1506
|
+
&& resolveCodexSandboxMode(sandbox, platform) === 'microvm') {
|
|
1507
|
+
return { mode: 'microvm', trust };
|
|
1508
|
+
}
|
|
1500
1509
|
const mode = sandbox?.mode
|
|
1501
1510
|
|| (confined ? resolvePublicSandboxMode(sandbox, platform) : 'none');
|
|
1502
1511
|
if (confined && mode === 'none') {
|
|
@@ -1593,7 +1602,7 @@ export const performAttach = async ({
|
|
|
1593
1602
|
// that don't offer the flag. A seat with no sandbox block still needs the
|
|
1594
1603
|
// person's opt-in at `agent run`.
|
|
1595
1604
|
const codexRefusal = hostSandboxRefusal({
|
|
1596
|
-
environment, adapterName, platform, hostUnconfined: true, optedIn: true, detectBwrap: probeBwrap,
|
|
1605
|
+
environment, adapterName, platform, hostUnconfined: true, optedIn: true, detectBwrap: probeBwrap, detectWhp: probeWhp,
|
|
1597
1606
|
});
|
|
1598
1607
|
if (codexRefusal) throw new Error(codexRefusal);
|
|
1599
1608
|
}
|
|
@@ -1667,8 +1676,11 @@ export const performAttach = async ({
|
|
|
1667
1676
|
}
|
|
1668
1677
|
} else if (sandboxMode === 'microvm') {
|
|
1669
1678
|
// Host-resolved on native Windows with COMMONLY_SANDBOX_MICROVM=1, never
|
|
1670
|
-
// stored: claude only, and only where WHP is on.
|
|
1679
|
+
// stored: claude and codex only, and only where WHP is on.
|
|
1671
1680
|
checkMicrovmAttach({ adapterName, platform, probe: probeWhp });
|
|
1681
|
+
// An MCP server the Codex turn refuses every time is refused here, before
|
|
1682
|
+
// anything is published.
|
|
1683
|
+
if (adapterName === 'codex') refuseMicrovmMcpDeclarations(environment?.mcp);
|
|
1672
1684
|
log('sandbox: microVM via microsandbox (network fenced to the model proxy and the MCP bridge)');
|
|
1673
1685
|
} else if (sandboxMode !== 'none' && sandboxMode !== undefined) {
|
|
1674
1686
|
throw new Error(
|
package/src/commands/daemon.js
CHANGED
|
@@ -45,6 +45,9 @@ import {
|
|
|
45
45
|
|
|
46
46
|
import { daemonLogsDir, daemonSeatLogPath, readLogTail } from '../lib/daemon-logs.js';
|
|
47
47
|
import { watchWindowsLauncher } from '../lib/daemon-service-windows.js';
|
|
48
|
+
import {
|
|
49
|
+
DAEMON_LOCK_EXIT, acquireDaemonLock, daemonLockPath, daemonLockWaitMs,
|
|
50
|
+
} from '../lib/daemon-lock.js';
|
|
48
51
|
import {
|
|
49
52
|
UNSANDBOXED_FLAG, clearUnsandboxedOptIn, hostSandboxReport, loadUnsandboxedOptIn, saveUnsandboxedOptIn, unsandboxedFlagRefusal,
|
|
50
53
|
} from '../lib/sandbox/windows-unsandboxed.js';
|
|
@@ -375,6 +378,7 @@ export const firstSupervisionPass = async ({
|
|
|
375
378
|
onLauncherGone,
|
|
376
379
|
isEnded = () => false,
|
|
377
380
|
armLauncherWatch = watchWindowsLauncher,
|
|
381
|
+
releaseLock = async () => {},
|
|
378
382
|
}) => {
|
|
379
383
|
let launcherGone = false;
|
|
380
384
|
armLauncherWatch({
|
|
@@ -385,9 +389,19 @@ export const firstSupervisionPass = async ({
|
|
|
385
389
|
});
|
|
386
390
|
const stopped = () => launcherGone || isEnded();
|
|
387
391
|
if (stopped()) return false;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
392
|
+
try {
|
|
393
|
+
await supervisor.tick();
|
|
394
|
+
if (stopped()) return false;
|
|
395
|
+
await supervisor.heartbeat();
|
|
396
|
+
} catch (error) {
|
|
397
|
+
// F637 review: a throw here (a later seat's token read, say) comes after
|
|
398
|
+
// earlier seats have started. The caller's catch can't reach them or the
|
|
399
|
+
// lock, so stop them and free the lock before the error goes on, as the
|
|
400
|
+
// runtime-failure and shutdown paths do.
|
|
401
|
+
supervisor.stop();
|
|
402
|
+
await releaseLock();
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
391
405
|
return !stopped();
|
|
392
406
|
};
|
|
393
407
|
|
|
@@ -727,6 +741,20 @@ Examples:
|
|
|
727
741
|
process.exitCode = process.platform === 'darwin' ? 0 : stopped.exitCode;
|
|
728
742
|
return;
|
|
729
743
|
}
|
|
744
|
+
// F637: one daemon per machine credential. Taken before the first
|
|
745
|
+
// request, so a refused copy never touches the server. It waits ~10 s
|
|
746
|
+
// first: a restart's old daemon is still exiting when the new one starts.
|
|
747
|
+
const lock = await acquireDaemonLock({
|
|
748
|
+
lockPath: daemonLockPath({ home: homedir() }),
|
|
749
|
+
waitMs: daemonLockWaitMs(),
|
|
750
|
+
});
|
|
751
|
+
if (!lock.ok) {
|
|
752
|
+
const holder = lock.holderPid ? `pid ${lock.holderPid}` : 'another process';
|
|
753
|
+
console.error(`${new Date().toISOString()} another Commonly daemon (${holder}) is already running for ${record.machineName}; this copy exits (${DAEMON_LOCK_EXIT}).`);
|
|
754
|
+
process.exitCode = DAEMON_LOCK_EXIT;
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
const releaseLock = () => { void lock.release(); };
|
|
730
758
|
const client = createClient({ instance: record.instanceUrl, token: record.daemonToken });
|
|
731
759
|
const logsDir = daemonLogsDir();
|
|
732
760
|
if (!existsSync(logsDir)) mkdirSync(logsDir, { recursive: true });
|
|
@@ -775,6 +803,7 @@ Examples:
|
|
|
775
803
|
clearInterval(pollTimer);
|
|
776
804
|
clearInterval(heartbeatTimer);
|
|
777
805
|
supervisor.stop();
|
|
806
|
+
releaseLock();
|
|
778
807
|
// Without the marker launchd would restart forever. A successful
|
|
779
808
|
// exit parks it on macOS; systemd honors 77 directly.
|
|
780
809
|
process.exitCode = saved || process.platform !== 'darwin' ? 77 : 0;
|
|
@@ -825,6 +854,7 @@ Examples:
|
|
|
825
854
|
clearInterval(pollTimer);
|
|
826
855
|
clearInterval(heartbeatTimer);
|
|
827
856
|
supervisor.stop();
|
|
857
|
+
releaseLock();
|
|
828
858
|
process.exit(0);
|
|
829
859
|
};
|
|
830
860
|
// Under the Windows launcher, the launcher's exit is the stop
|
|
@@ -838,8 +868,12 @@ Examples:
|
|
|
838
868
|
shutdown();
|
|
839
869
|
},
|
|
840
870
|
isEnded: () => terminalEnded,
|
|
871
|
+
releaseLock: () => lock.release(),
|
|
841
872
|
});
|
|
842
|
-
if (!started)
|
|
873
|
+
if (!started) {
|
|
874
|
+
releaseLock();
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
843
877
|
const runtimeFailure = (error) => {
|
|
844
878
|
if (terminalEnded) return;
|
|
845
879
|
terminalEnded = true;
|
|
@@ -847,6 +881,7 @@ Examples:
|
|
|
847
881
|
clearInterval(pollTimer);
|
|
848
882
|
clearInterval(heartbeatTimer);
|
|
849
883
|
supervisor.stop();
|
|
884
|
+
releaseLock();
|
|
850
885
|
process.exitCode = 75;
|
|
851
886
|
};
|
|
852
887
|
pollTimer = setInterval(() => { void supervisor.tick().catch(runtimeFailure); }, Number(opts.poll) || DEFAULT_POLL_MS);
|