This commit is contained in:
@@ -5414,12 +5414,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
rows: dims.rows,
|
||||
tty: true,
|
||||
})
|
||||
.then((res) => {
|
||||
const shell = res?.shell || (Array.isArray(res?.cmd) ? res.cmd.join(' ') : '');
|
||||
if (shell) {
|
||||
xterm.writeln(`\x1b[90m[peardock] shell: ${shell}\x1b[0m\r`);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
xterm.writeln(`\r\n\x1b[31m[ERROR] ${err.message}\x1b[0m`);
|
||||
});
|
||||
|
||||
@@ -182,12 +182,6 @@ function startTerminal(containerId, containerName) {
|
||||
rows: dims.rows,
|
||||
tty: true,
|
||||
})
|
||||
.then((res) => {
|
||||
const shell = res?.shell || (Array.isArray(res?.cmd) ? res.cmd.join(' ') : '')
|
||||
if (shell) {
|
||||
xterm.writeln(`\x1b[90m[peardock] shell: ${shell}\x1b[0m\r`)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
xterm.writeln(`\r\n\x1b[31m[ERROR] ${err.message}\x1b[0m\r\n`)
|
||||
})
|
||||
|
||||
@@ -106,6 +106,31 @@ function resolveSessionId(args) {
|
||||
return args.sessionId || args.terminalId || args.containerId || 'default'
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-readable shell label for logs / client banner.
|
||||
* Never include multi-line probe scripts (those dump into the PTY UI).
|
||||
* @param {string[]} cmd
|
||||
* @returns {string}
|
||||
*/
|
||||
export function describeShellCmd(cmd) {
|
||||
if (!Array.isArray(cmd) || cmd.length === 0) return 'shell'
|
||||
const cIdx = cmd.indexOf('-c')
|
||||
if (cIdx >= 0) {
|
||||
const script = String(cmd[cIdx + 1] || '')
|
||||
const isProbe =
|
||||
script.includes('for s in') ||
|
||||
script.includes('\n') ||
|
||||
script.length > 80
|
||||
if (isProbe) {
|
||||
const launcher = cmd.slice(0, cIdx).join(' ') || cmd[0]
|
||||
return `${launcher} (auto)`
|
||||
}
|
||||
}
|
||||
// busybox sh, etc.
|
||||
if (cmd.length <= 3) return cmd.join(' ')
|
||||
return cmd[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Buffer|Uint8Array} chunk
|
||||
*/
|
||||
@@ -419,11 +444,12 @@ export function registerTerminalHandlers(session) {
|
||||
}
|
||||
}
|
||||
|
||||
const shellLabel = describeShellCmd(cmd)
|
||||
logger.info('Terminal session started', {
|
||||
containerId,
|
||||
sessionId,
|
||||
tty: useTty,
|
||||
shell: cmd.join(' '),
|
||||
shell: shellLabel,
|
||||
peer: session.id.slice(0, 12),
|
||||
})
|
||||
return {
|
||||
@@ -432,8 +458,8 @@ export function registerTerminalHandlers(session) {
|
||||
sessionId,
|
||||
containerId,
|
||||
tty: useTty,
|
||||
shell: cmd.join(' '),
|
||||
cmd,
|
||||
shell: shellLabel,
|
||||
cmd: Array.isArray(cmd) ? cmd.map((p) => (String(p).length > 80 ? `${String(p).slice(0, 40)}…` : p)) : cmd,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -5,8 +5,23 @@ import test from 'brittle'
|
||||
import {
|
||||
DEFAULT_SHELL_CANDIDATES,
|
||||
buildShellCandidates,
|
||||
describeShellCmd,
|
||||
} from '../server/handlers/terminal.js'
|
||||
|
||||
test('describeShellCmd hides multi-line probe scripts', (t) => {
|
||||
const probe = buildShellCandidates({}).find(
|
||||
(c) => c.includes('-c') && c.some((p) => String(p).includes('for s in'))
|
||||
)
|
||||
t.ok(probe)
|
||||
const label = describeShellCmd(probe)
|
||||
t.ok(label.includes('(auto)'))
|
||||
t.absent(label.includes('\n'))
|
||||
t.absent(label.includes('for s in'))
|
||||
t.ok(label.length < 40)
|
||||
t.is(describeShellCmd(['/bin/bash']), '/bin/bash')
|
||||
t.is(describeShellCmd(['/bin/busybox', 'sh']), '/bin/busybox sh')
|
||||
})
|
||||
|
||||
test('probe wrapper -c script keeps newlines (valid sh -c)', (t) => {
|
||||
const list = buildShellCandidates({})
|
||||
const probe = list.find((c) => c.includes('-c') && c.some((p) => String(p).includes('exec')))
|
||||
|
||||
Reference in New Issue
Block a user