mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-07-15 21:11:08 +02:00
Add OS-aware runtime context for cross-platform shell execution
Detect the runtime platform and default shell at startup, inject platform context into assistant instructions, and replace hardcoded /bin/sh with the detected shell in command executors (cli + electron). Made-with: Cursor
This commit is contained in:
parent
a3e74931bf
commit
b5424d92f9
6 changed files with 162 additions and 8 deletions
69
apps/cli/src/application/assistant/runtime-context.ts
Normal file
69
apps/cli/src/application/assistant/runtime-context.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
export type RuntimeShellDialect = 'windows-cmd' | 'posix-sh';
|
||||
export type RuntimeOsName = 'Windows' | 'macOS' | 'Linux' | 'Unknown';
|
||||
|
||||
export interface RuntimeContext {
|
||||
platform: NodeJS.Platform;
|
||||
osName: RuntimeOsName;
|
||||
shellDialect: RuntimeShellDialect;
|
||||
shellExecutable: string;
|
||||
}
|
||||
|
||||
export function getExecutionShell(platform: NodeJS.Platform = process.platform): string {
|
||||
return platform === 'win32' ? (process.env.ComSpec || 'cmd.exe') : '/bin/sh';
|
||||
}
|
||||
|
||||
export function getRuntimeContext(platform: NodeJS.Platform = process.platform): RuntimeContext {
|
||||
if (platform === 'win32') {
|
||||
return {
|
||||
platform,
|
||||
osName: 'Windows',
|
||||
shellDialect: 'windows-cmd',
|
||||
shellExecutable: getExecutionShell(platform),
|
||||
};
|
||||
}
|
||||
|
||||
if (platform === 'darwin') {
|
||||
return {
|
||||
platform,
|
||||
osName: 'macOS',
|
||||
shellDialect: 'posix-sh',
|
||||
shellExecutable: getExecutionShell(platform),
|
||||
};
|
||||
}
|
||||
|
||||
if (platform === 'linux') {
|
||||
return {
|
||||
platform,
|
||||
osName: 'Linux',
|
||||
shellDialect: 'posix-sh',
|
||||
shellExecutable: getExecutionShell(platform),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
platform,
|
||||
osName: 'Unknown',
|
||||
shellDialect: 'posix-sh',
|
||||
shellExecutable: getExecutionShell(platform),
|
||||
};
|
||||
}
|
||||
|
||||
export function getRuntimeContextPrompt(runtime: RuntimeContext): string {
|
||||
if (runtime.shellDialect === 'windows-cmd') {
|
||||
return `## Runtime Platform (CRITICAL)
|
||||
- Detected platform: **${runtime.platform}**
|
||||
- Detected OS: **${runtime.osName}**
|
||||
- Shell used by executeCommand: **${runtime.shellExecutable}** (Windows Command Prompt / cmd syntax)
|
||||
- Use Windows command syntax for executeCommand (for example: \`dir\`, \`type\`, \`copy\`, \`move\`, \`del\`, \`rmdir\`).
|
||||
- Use Windows-style absolute paths when outside workspace (for example: \`C:\\Users\\...\`).
|
||||
- Do not assume macOS/Linux command syntax when the runtime is Windows.`;
|
||||
}
|
||||
|
||||
return `## Runtime Platform (CRITICAL)
|
||||
- Detected platform: **${runtime.platform}**
|
||||
- Detected OS: **${runtime.osName}**
|
||||
- Shell used by executeCommand: **${runtime.shellExecutable}** (POSIX sh syntax)
|
||||
- Use POSIX command syntax for executeCommand (for example: \`ls\`, \`cat\`, \`cp\`, \`mv\`, \`rm\`).
|
||||
- Use POSIX paths when outside workspace (for example: \`~/Desktop\`, \`/Users/.../\` on macOS, \`/home/.../\` on Linux).
|
||||
- Do not assume Windows command syntax when the runtime is POSIX.`;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue