dual-brain 0.3.31 → 0.3.33
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/dual-brain.mjs +35 -0
- package/package.json +1 -1
package/bin/dual-brain.mjs
CHANGED
|
@@ -1481,6 +1481,9 @@ async function cmdRuntimeSwitch(args = []) {
|
|
|
1481
1481
|
let provider = _sessionTool(sess);
|
|
1482
1482
|
let reason = 'head-runtime-switch';
|
|
1483
1483
|
const confirmed = args.includes('--confirm') || args.includes('--go');
|
|
1484
|
+
const explicitModel = args.includes('--model') || args.includes('--head-model');
|
|
1485
|
+
const explicitEffort = args.includes('--effort');
|
|
1486
|
+
const explicitLevel = args.includes('--level') || args.includes('--intelligence') || args.includes('--intelligence-level');
|
|
1484
1487
|
|
|
1485
1488
|
for (let i = 0; i < args.length; i += 1) {
|
|
1486
1489
|
const a = args[i];
|
|
@@ -1514,6 +1517,12 @@ async function cmdRuntimeSwitch(args = []) {
|
|
|
1514
1517
|
settings.bypassPermissions = true;
|
|
1515
1518
|
}
|
|
1516
1519
|
|
|
1520
|
+
const existingPending = readPendingRuntimeSwitch(cwd);
|
|
1521
|
+
if (!explicitModel && !explicitLevel && existingPending?.sessionId === sess.id && existingPending.provider === provider && _modelMatchesProvider(existingPending.model, provider)) {
|
|
1522
|
+
settings.headModel = existingPending.model;
|
|
1523
|
+
if (!explicitEffort && existingPending.effort) settings.effort = existingPending.effort;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1517
1526
|
const headPolicy = _headPolicyFor(provider, profile, settings);
|
|
1518
1527
|
if (!settings.headModel || !_modelMatchesProvider(settings.headModel, provider)) {
|
|
1519
1528
|
settings.headModel = headPolicy.model;
|
|
@@ -1536,6 +1545,7 @@ async function cmdRuntimeSwitch(args = []) {
|
|
|
1536
1545
|
effort: settings.effort,
|
|
1537
1546
|
confirmed,
|
|
1538
1547
|
reason,
|
|
1548
|
+
changedBy: 'HEAD',
|
|
1539
1549
|
});
|
|
1540
1550
|
|
|
1541
1551
|
const launchArgs = provider === _sessionTool(sess)
|
|
@@ -1546,11 +1556,15 @@ async function cmdRuntimeSwitch(args = []) {
|
|
|
1546
1556
|
console.log(`Runtime switch ${confirmed ? 'confirmed' : 'prepared'} for ${pending?.sessionName || sess.id}`);
|
|
1547
1557
|
console.log(`Provider: ${provider}`);
|
|
1548
1558
|
console.log(`Mode: ${getEffectiveConversationMode(profile, cwd)}`);
|
|
1559
|
+
console.log(`Model: ${settings.headModel || 'default'}${settings.effort ? ` (${settings.effort})` : ''}`);
|
|
1560
|
+
console.log(`Changed by: HEAD`);
|
|
1561
|
+
console.log(`Reason: ${reason}`);
|
|
1549
1562
|
console.log(`Launch: ${provider} ${launchArgs.join(' ')}`);
|
|
1550
1563
|
if (confirmed) {
|
|
1551
1564
|
const activeForSwitch = readActiveConversation(cwd);
|
|
1552
1565
|
if (activeForSwitch?.sessionId === sess.id) {
|
|
1553
1566
|
console.log('Active supervisor detected: HEAD will restart with these settings.');
|
|
1567
|
+
signalActiveConversation(cwd, sess.id);
|
|
1554
1568
|
} else if (!args.includes('--apply')) {
|
|
1555
1569
|
console.log('No active supervisor detected: saved for the next dual-brain resume/switch, not live yet.');
|
|
1556
1570
|
}
|
|
@@ -2714,6 +2728,7 @@ function writePendingRuntimeSwitch(cwd, session, updates = {}) {
|
|
|
2714
2728
|
automode: typeof updates.automode === 'boolean' ? updates.automode : null,
|
|
2715
2729
|
bypassPermissions: typeof updates.bypassPermissions === 'boolean' ? updates.bypassPermissions : null,
|
|
2716
2730
|
reason: updates.reason || 'runtime-settings-change',
|
|
2731
|
+
changedBy: updates.changedBy || 'HEAD',
|
|
2717
2732
|
autoLaunch: updates.autoLaunch !== false,
|
|
2718
2733
|
handoffBrief: updates.handoffBrief || _sessionBrief(session, tool),
|
|
2719
2734
|
};
|
|
@@ -2837,6 +2852,18 @@ function updateActiveConversation(cwd, sessionId, updates = {}) {
|
|
|
2837
2852
|
} catch {}
|
|
2838
2853
|
}
|
|
2839
2854
|
|
|
2855
|
+
function signalActiveConversation(cwd, sessionId) {
|
|
2856
|
+
try {
|
|
2857
|
+
const lease = JSON.parse(readFileSync(activeConversationPath(cwd), 'utf8'));
|
|
2858
|
+
if (sessionId && lease.sessionId !== sessionId) return false;
|
|
2859
|
+
if (!pidAlive(lease.ownerPid)) return false;
|
|
2860
|
+
process.kill(lease.ownerPid, 'SIGUSR1');
|
|
2861
|
+
return true;
|
|
2862
|
+
} catch {
|
|
2863
|
+
return false;
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2840
2867
|
function writeHandoffConversationLease(cwd, session, fromTool, targetTool, taskBrief = '') {
|
|
2841
2868
|
const dir = join(cwd, '.dualbrain');
|
|
2842
2869
|
const terminalId = getTerminalId();
|
|
@@ -2943,6 +2970,12 @@ async function launchSupervisedHead(tool, launchArgs, cwd, session) {
|
|
|
2943
2970
|
}, 2500);
|
|
2944
2971
|
};
|
|
2945
2972
|
|
|
2973
|
+
const onSignalSwitch = () => {
|
|
2974
|
+
const pending = readPendingRuntimeSwitch(cwd);
|
|
2975
|
+
if (pendingSwitchMatchesSession(pending, session)) stopChildForSwitch();
|
|
2976
|
+
};
|
|
2977
|
+
process.on('SIGUSR1', onSignalSwitch);
|
|
2978
|
+
|
|
2946
2979
|
const watcher = setInterval(() => {
|
|
2947
2980
|
const pending = readPendingRuntimeSwitch(cwd);
|
|
2948
2981
|
if (pendingSwitchMatchesSession(pending, session)) stopChildForSwitch();
|
|
@@ -2950,6 +2983,7 @@ async function launchSupervisedHead(tool, launchArgs, cwd, session) {
|
|
|
2950
2983
|
|
|
2951
2984
|
child.on('exit', async (code, signal) => {
|
|
2952
2985
|
clearInterval(watcher);
|
|
2986
|
+
process.off('SIGUSR1', onSignalSwitch);
|
|
2953
2987
|
if (forceTimer) clearTimeout(forceTimer);
|
|
2954
2988
|
saveTerminalState(cwd, getTerminalId(), session?.id, session?.tool || tool);
|
|
2955
2989
|
|
|
@@ -2965,6 +2999,7 @@ async function launchSupervisedHead(tool, launchArgs, cwd, session) {
|
|
|
2965
2999
|
|
|
2966
3000
|
child.on('error', (err) => {
|
|
2967
3001
|
clearInterval(watcher);
|
|
3002
|
+
process.off('SIGUSR1', onSignalSwitch);
|
|
2968
3003
|
if (forceTimer) clearTimeout(forceTimer);
|
|
2969
3004
|
process.stderr.write(`\n Could not launch ${tool}: ${err.message}\n`);
|
|
2970
3005
|
clearActiveConversation(cwd, session?.id);
|
package/package.json
CHANGED