Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions bin/multiagent-safety.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,12 @@ function isInteractiveTerminal() {
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
}

const stdinWaitArray = new Int32Array(new SharedArrayBuffer(4));

function sleepSyncMs(milliseconds) {
Atomics.wait(stdinWaitArray, 0, 0, milliseconds);
}

function readSingleLineFromStdin() {
let input = '';
const buffer = Buffer.alloc(1);
Expand All @@ -1777,11 +1783,19 @@ function readSingleLineFromStdin() {
let bytesRead = 0;
try {
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, 1);
} catch {
} catch (error) {
if (error && ['EAGAIN', 'EWOULDBLOCK', 'EINTR'].includes(error.code)) {
sleepSyncMs(15);
continue;
}
return input;
}

if (bytesRead === 0) {
if (process.stdin.isTTY) {
sleepSyncMs(15);
continue;
}
return input;
}

Expand Down Expand Up @@ -1921,9 +1935,8 @@ function maybeSelfUpdateBeforeStatus() {
}

const shouldUpdate = interactive
? promptYesNo(
? promptYesNoStrict(
`Update now? (${NPM_BIN} i -g ${packageJson.name}@latest)`,
false,
)
: autoApproval;

Expand Down
4 changes: 2 additions & 2 deletions test/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,11 @@ exit 1
assert.equal(fs.existsSync(markerPath), true, 'expected self-update command to run');
});

test('self-update prompt defaults to no when approval is not preconfigured', () => {
test('self-update prompt requires explicit y/n when approval is not preconfigured', () => {
const source = fs.readFileSync(cliPath, 'utf8');
assert.match(
source,
/const shouldUpdate = interactive\s*\?\s*promptYesNo\(\s*`Update now\?\s*\(\$\{NPM_BIN\} i -g \$\{packageJson\.name\}@latest\)`\s*,\s*false,\s*\)\s*:\s*autoApproval;/s,
/const shouldUpdate = interactive\s*\?\s*promptYesNoStrict\(\s*`Update now\?\s*\(\$\{NPM_BIN\} i -g \$\{packageJson\.name\}@latest\)`\s*,?\s*\)\s*:\s*autoApproval;/s,
);
});

Expand Down
Loading