Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): mirror grok context window server-side + handle joined prompt-file on Windows

[._.]/ Adam Eivy6563e55accdd
diff --git a/server/lib/grok.js b/server/lib/grok.js
index 4c5e65c7cd..08543cf11f 100644
--- a/server/lib/grok.js
+++ b/server/lib/grok.js
@@ -144,8 +144,15 @@ export function ensureGrokTuiArgs(args = []) {
*/
export function prepareGrokPromptFile(args, prompt) {
if (process.platform !== 'win32') return { args, useStdin: true, cleanup: NOOP_CLEANUP };
- const idx = args.indexOf(GROK_STDIN_PROMPT_PATH);
- if (idx <= 0 || args[idx - 1] !== '--prompt-file') return { args, useStdin: true, cleanup: NOOP_CLEANUP };
+ // Locate the /dev/stdin sentinel in either form: separated
+ // (`--prompt-file /dev/stdin`, what buildCliArgs emits) or joined
+ // (`--prompt-file=/dev/stdin`, which a user could bake into provider.args and
+ // which ensureGrokHeadlessArgs then leaves in place as an existing prompt
+ // source). Both are a POSIX-only path grok can't open on Windows.
+ const joined = `--prompt-file=${GROK_STDIN_PROMPT_PATH}`;
+ const sepIdx = args.findIndex((a, i) => a === GROK_STDIN_PROMPT_PATH && args[i - 1] === '--prompt-file');
+ const joinIdx = sepIdx === -1 ? args.indexOf(joined) : -1;
+ if (sepIdx === -1 && joinIdx === -1) return { args, useStdin: true, cleanup: NOOP_CLEANUP };
// A collision-resistant name — concurrent grok runs in the same process (e.g.
// parallel CoS agents / pipeline stages) can reach here in the same millisecond,
// so a pid+timestamp name would clobber each other's prompt or delete a file a
@@ -153,7 +160,8 @@ export function prepareGrokPromptFile(args, prompt) {
const file = join(os.tmpdir(), `grok-prompt-${process.pid}-${randomUUID()}.txt`);
writeFileSync(file, typeof prompt === 'string' ? prompt : '', 'utf8');
const rewritten = [...args];
- rewritten[idx] = file;
+ if (sepIdx !== -1) rewritten[sepIdx] = file;
+ else rewritten[joinIdx] = `--prompt-file=${file}`;
return {
args: rewritten,
useStdin: false,
diff --git a/server/lib/grok.test.js b/server/lib/grok.test.js
index 2ffbd1471f..c7d214051b 100644
--- a/server/lib/grok.test.js
+++ b/server/lib/grok.test.js
@@ -126,7 +126,7 @@ describe('grok — prepareGrokPromptFile', () => {
expect(res.args).toEqual(['-p', '-']);
});
- it('writes a temp file and rewrites the sentinel on Windows', () => {
+ it('writes a temp file and rewrites the separated sentinel on Windows', () => {
setPlatform('win32');
const args = ['--output-format', 'plain', '--prompt-file', '/dev/stdin'];
const res = prepareGrokPromptFile(args, 'my prompt body');
@@ -139,4 +139,28 @@ describe('grok — prepareGrokPromptFile', () => {
res.cleanup();
expect(existsSync(file)).toBe(false);
});
+
+ it('rewrites the joined --prompt-file=/dev/stdin form on Windows too', () => {
+ setPlatform('win32');
+ const args = ['--output-format', 'plain', '--prompt-file=/dev/stdin'];
+ const res = prepareGrokPromptFile(args, 'joined body');
+ expect(res.useStdin).toBe(false);
+ const rewritten = res.args.find((a) => a.startsWith('--prompt-file='));
+ const file = rewritten.slice('--prompt-file='.length);
+ expect(file).not.toBe('/dev/stdin');
+ expect(res.args).not.toContain('--prompt-file=/dev/stdin');
+ expect(readFileSync(file, 'utf8')).toBe('joined body');
+ res.cleanup();
+ expect(existsSync(file)).toBe(false);
+ });
+
+ it('uses a unique temp filename per call (no collision under concurrency)', () => {
+ setPlatform('win32');
+ const mk = () => prepareGrokPromptFile(['--prompt-file', '/dev/stdin'], 'x');
+ const a = mk(); const b = mk();
+ const fileA = a.args[a.args.indexOf('--prompt-file') + 1];
+ const fileB = b.args[b.args.indexOf('--prompt-file') + 1];
+ expect(fileA).not.toBe(fileB);
+ a.cleanup(); b.cleanup();
+ });
});
diff --git a/server/lib/stageRunner.js b/server/lib/stageRunner.js
index 695e47df68..0ec7a433cd 100644
--- a/server/lib/stageRunner.js
+++ b/server/lib/stageRunner.js
@@ -119,6 +119,7 @@ function resolveModelHint(stage, options = {}) {
export const DEFAULT_LARGE_CONTEXT_WINDOW = 128_000;
export const CODEX_CONTEXT_WINDOW = 1_000_000;
export const GEMINI_CONTEXT_WINDOW = 1_048_576;
+export const GROK_CONTEXT_WINDOW = 256_000;
// Keep in sync with client/src/utils/providers.js.
const KNOWN_MODEL_CONTEXT_WINDOWS = Object.freeze([
@@ -147,6 +148,7 @@ export function knownProviderContextWindow(provider) {
const command = String(provider?.command || '').toLowerCase();
if (id === 'codex' || id === 'codex-tui' || command === 'codex') return CODEX_CONTEXT_WINDOW;
if (id === 'antigravity-cli' || id === 'antigravity-tui' || command === 'agy') return GEMINI_CONTEXT_WINDOW;
+ if (id === 'grok-cli' || id === 'grok-tui' || command === 'grok') return GROK_CONTEXT_WINDOW;
return null;
}
diff --git a/server/lib/stageRunner.test.js b/server/lib/stageRunner.test.js
index ceb17ab14e..345101ad55 100644
--- a/server/lib/stageRunner.test.js
+++ b/server/lib/stageRunner.test.js
@@ -30,6 +30,7 @@ const {
DEFAULT_LARGE_CONTEXT_WINDOW,
CODEX_CONTEXT_WINDOW,
GEMINI_CONTEXT_WINDOW,
+ GROK_CONTEXT_WINDOW,
effectiveContextWindow,
knownModelContextWindow,
knownProviderContextWindow,
@@ -104,6 +105,10 @@ describe('stageRunner — context windows', () => {
it('resolves configured-default provider windows by provider identity', () => {
expect(knownProviderContextWindow({ id: 'codex-tui', type: 'tui', command: 'codex' })).toBe(CODEX_CONTEXT_WINDOW);
expect(knownProviderContextWindow({ id: 'antigravity-cli', type: 'cli', command: 'agy' })).toBe(GEMINI_CONTEXT_WINDOW);
+ // Mirrors client/src/utils/providers.js — a custom grok CLI/TUI without an
+ // explicit contextWindow must resolve the same 256K on both sides.
+ expect(knownProviderContextWindow({ id: 'grok-cli', type: 'cli', command: 'grok' })).toBe(GROK_CONTEXT_WINDOW);
+ expect(knownProviderContextWindow({ id: 'grok-tui', type: 'tui', command: 'grok' })).toBe(GROK_CONTEXT_WINDOW);
});
it('keeps an explicit provider contextWindow above model defaults', () => {