scalemax 0.1.57 → 0.1.59

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.
@@ -47,8 +47,14 @@ export declare function claudeGithubToolPath(home: string): string;
47
47
  * EVERY Web Fetch (and the sandbox shell reaches no host); tool search keeps
48
48
  * many connectors from filling the context. `skipWebFetchPreflight` stops Code
49
49
  * sessions sending every fetched hostname to api.anthropic.com first (and
50
- * failing every Web Fetch where that host is unreachable). A value the user
51
- * already set for either of the last two is left alone.
50
+ * failing every Web Fetch where that host is unreachable).
51
+ * `builtinBrowserEnabled` gives Cowork and Code the Browser pane Claude can
52
+ * click, type and take screenshots in. It is off unless a profile turns it on,
53
+ * and Claude Desktop keeps its own Computer use switched off in third-party
54
+ * mode (its feature flag never loads there: `[chicago] ... raw=undefined →
55
+ * enabled=false` in main.log), so this is how Claude operates a screen on a
56
+ * gateway. A value the user already set for any of the last three is left
57
+ * alone.
52
58
  */
53
59
  export declare function scaleMaxManagedConfigPatch(current: Record<string, unknown>): Record<string, unknown>;
54
60
  /** Install and verify the bounded public-GitHub MCP server for Claude Desktop/Cowork. */
@@ -118,8 +118,14 @@ function isScaleMaxManagedGateway(value) {
118
118
  * EVERY Web Fetch (and the sandbox shell reaches no host); tool search keeps
119
119
  * many connectors from filling the context. `skipWebFetchPreflight` stops Code
120
120
  * sessions sending every fetched hostname to api.anthropic.com first (and
121
- * failing every Web Fetch where that host is unreachable). A value the user
122
- * already set for either of the last two is left alone.
121
+ * failing every Web Fetch where that host is unreachable).
122
+ * `builtinBrowserEnabled` gives Cowork and Code the Browser pane Claude can
123
+ * click, type and take screenshots in. It is off unless a profile turns it on,
124
+ * and Claude Desktop keeps its own Computer use switched off in third-party
125
+ * mode (its feature flag never loads there: `[chicago] ... raw=undefined →
126
+ * enabled=false` in main.log), so this is how Claude operates a screen on a
127
+ * gateway. A value the user already set for any of the last three is left
128
+ * alone.
123
129
  */
124
130
  export function scaleMaxManagedConfigPatch(current) {
125
131
  const next = { ...current, isLocalDevMcpEnabled: true, toolSearchEnabled: true };
@@ -127,6 +133,8 @@ export function scaleMaxManagedConfigPatch(current) {
127
133
  next.coworkEgressAllowedHosts = ['*'];
128
134
  if (current.skipWebFetchPreflight === undefined)
129
135
  next.skipWebFetchPreflight = true;
136
+ if (current.builtinBrowserEnabled === undefined)
137
+ next.builtinBrowserEnabled = true;
130
138
  return next;
131
139
  }
132
140
  async function managedThirdPartyConfigs(roots) {
@@ -0,0 +1,36 @@
1
+ import { DetectContext } from '../types/client.js';
2
+ /**
3
+ * Codex inside WSL, seen from Windows.
4
+ *
5
+ * The Codex desktop app runs a WSL project's agent inside the Linux distro,
6
+ * and that agent reads the distro's own ~/.codex -- not C:\Users\<me>\.codex,
7
+ * which is all setup used to write. A customer set up on Windows (2026-11-25)
8
+ * still had his ChatGPT sign-in in the Ubuntu ~/.codex: every message in his
9
+ * WSL project went to ChatGPT and hit that plan's usage limit, and nothing
10
+ * reached ScaleMax.
11
+ *
12
+ * Only distros that already have a ~/.codex are touched: those are the ones
13
+ * Codex runs in. Every failure here (no WSL, a distro that will not start, a
14
+ * file that cannot be written) is a warning: the Windows setup has already
15
+ * succeeded and stays.
16
+ */
17
+ export interface WslCodexHome {
18
+ distro: string;
19
+ /** The distro user's home as Windows sees it, e.g. \\wsl$\Ubuntu\home\me */
20
+ home: string;
21
+ }
22
+ export interface WslDeps {
23
+ /** Runs wsl.exe with these arguments and returns its raw stdout. */
24
+ run(args: string[], timeoutMs: number): Promise<Buffer>;
25
+ /** Windows path of a Linux home inside a distro. */
26
+ windowsPath(distro: string, linuxHome: string): string;
27
+ }
28
+ export declare const defaultWslDeps: WslDeps;
29
+ /** `wsl.exe -l -q` prints UTF-16LE (older builds: the console code page). */
30
+ export declare function parseWslDistroList(raw: Buffer): string[];
31
+ export declare function wslSkipped(ctx: DetectContext): boolean;
32
+ /** WSL distros whose default user already has a ~/.codex. */
33
+ export declare function findWslCodexHomes(ctx: DetectContext, deps?: WslDeps): Promise<{
34
+ homes: WslCodexHome[];
35
+ warnings: string[];
36
+ }>;
@@ -0,0 +1,55 @@
1
+ import path from 'node:path';
2
+ import fs from 'fs-extra';
3
+ import { execa } from 'execa';
4
+ export const defaultWslDeps = {
5
+ async run(args, timeoutMs) {
6
+ const result = await execa('wsl.exe', args, { encoding: 'buffer', timeout: timeoutMs, reject: true, windowsHide: true });
7
+ return Buffer.from(result.stdout);
8
+ },
9
+ windowsPath(distro, linuxHome) {
10
+ return `\\\\wsl$\\${distro}${linuxHome.replace(/\//g, '\\')}`;
11
+ },
12
+ };
13
+ /** `wsl.exe -l -q` prints UTF-16LE (older builds: the console code page). */
14
+ export function parseWslDistroList(raw) {
15
+ const text = raw.includes(0) ? raw.toString('utf16le') : raw.toString('utf8');
16
+ return text
17
+ .replace(/\0/g, '')
18
+ .replace(/^\uFEFF/, '')
19
+ .split(/\r?\n/)
20
+ .map(line => line.trim())
21
+ .filter(Boolean)
22
+ // Docker Desktop's own distros never run Codex.
23
+ .filter(name => !/^docker-desktop(-data)?$/i.test(name));
24
+ }
25
+ export function wslSkipped(ctx) {
26
+ return ctx.platform !== 'win32' || /^(1|true|yes)$/i.test(ctx.env?.SCALEMAX_SKIP_WSL ?? '');
27
+ }
28
+ /** WSL distros whose default user already has a ~/.codex. */
29
+ export async function findWslCodexHomes(ctx, deps = defaultWslDeps) {
30
+ if (wslSkipped(ctx))
31
+ return { homes: [], warnings: [] };
32
+ let distros;
33
+ try {
34
+ distros = parseWslDistroList(await deps.run(['-l', '-q'], 15_000));
35
+ }
36
+ catch {
37
+ return { homes: [], warnings: [] }; // no WSL on this PC
38
+ }
39
+ const homes = [];
40
+ const warnings = [];
41
+ for (const distro of distros) {
42
+ try {
43
+ const linuxHome = (await deps.run(['-d', distro, '-e', 'sh', '-c', 'printf %s "$HOME"'], 30_000)).toString('utf8').trim();
44
+ if (!linuxHome.startsWith('/'))
45
+ continue;
46
+ const home = deps.windowsPath(distro, linuxHome);
47
+ if (await fs.pathExists(path.join(home, '.codex')))
48
+ homes.push({ distro, home });
49
+ }
50
+ catch (err) {
51
+ warnings.push(`WSL ${distro}: could not check for Codex (${err instanceof Error ? err.message.split('\n')[0] : String(err)}).`);
52
+ }
53
+ }
54
+ return { homes, warnings };
55
+ }
@@ -1,4 +1,5 @@
1
1
  import { ConfigureContext, ConfigureResult, InstallContext, RemoveContext } from '../types/client.js';
2
+ import { WslDeps } from './codex-wsl.js';
2
3
  export interface CodexVerificationResult {
3
4
  ok: boolean;
4
5
  warnings: string[];
@@ -34,7 +35,21 @@ export declare function verifyCodexConfiguration(ctx: ConfigureContext): Promise
34
35
  export declare function install(ctx: InstallContext): Promise<ConfigureResult>;
35
36
  export declare function verify(ctx: ConfigureContext): Promise<ConfigureResult>;
36
37
  export declare function configure(ctx: ConfigureContext): Promise<ConfigureResult>;
37
- export declare function remove(ctx: RemoveContext): Promise<ConfigureResult>;
38
+ export declare function remove(ctx: RemoveContext, wslDeps?: WslDeps): Promise<ConfigureResult>;
39
+ /**
40
+ * Point Codex inside WSL at ScaleMax too (see codex-wsl.ts for why).
41
+ *
42
+ * Same config.toml merge and auth.json rewrite as on Windows -- the ChatGPT
43
+ * sign-in comes out, the first pre-ScaleMax pair is backed up in that home --
44
+ * minus two things that cannot work from the Linux side: the Connectors table
45
+ * (its headers helper is a Windows script) and the live `codex` check (that
46
+ * Codex is the Windows one). The Windows setup already probed the key.
47
+ */
48
+ export declare function configureWslCodex(ctx: ConfigureContext, deps?: WslDeps): Promise<{
49
+ changed: boolean;
50
+ done: string[];
51
+ warnings: string[];
52
+ }>;
38
53
  export declare function launch(ctx?: ConfigureContext): Promise<ConfigureResult>;
39
54
  export declare function launchCodex(): Promise<{
40
55
  ok: boolean;
@@ -8,6 +8,7 @@ import { GENERATED_HEADER } from '../constants.js';
8
8
  import { commandExists } from '../utils/exec.js';
9
9
  import { codexModel, codexModelIds, sameModelId } from './models.js';
10
10
  import { CONNECTORS_CODEX_NAME, CONNECTORS_MCP_URL, codexConnectorsTable, connectorsHelperPath, connectorsKeyOrThrow, connectorsKeyPath, ensureConnectorsHelper, isConnectorsHelperReference, } from './connectors.js';
11
+ import { defaultWslDeps, findWslCodexHomes, wslSkipped } from './codex-wsl.js';
11
12
  const id = 'codex';
12
13
  const name = 'Codex';
13
14
  const provider = 'scalemax';
@@ -231,8 +232,21 @@ function originalTopLevelLines(backup) {
231
232
  }
232
233
  return out;
233
234
  }
235
+ /**
236
+ * The ChatGPT sign-in fields setup takes out of auth.json.
237
+ *
238
+ * Left in place next to auth_mode="apikey", the Codex desktop app (and the
239
+ * ChatGPT app's Codex) kept sending requests on the ChatGPT account, not the
240
+ * ScaleMax key: the customer saw that plan's "You've hit your usage limit" and
241
+ * nothing reached ScaleMax (2026-11-25). They are still in the first backup,
242
+ * and remove puts them back when Codex has not written fresher ones since.
243
+ */
244
+ const CHATGPT_SIGN_IN_FIELDS = ['tokens', 'last_refresh'];
234
245
  function codexAuth(apiKey, existing = {}) {
235
- return JSON.stringify({ ...existing, auth_mode: 'apikey', OPENAI_API_KEY: apiKey }, null, 2) + '\n';
246
+ const next = { ...existing, auth_mode: 'apikey', OPENAI_API_KEY: apiKey };
247
+ for (const field of CHATGPT_SIGN_IN_FIELDS)
248
+ delete next[field];
249
+ return JSON.stringify(next, null, 2) + '\n';
236
250
  }
237
251
  function parseSimpleTomlForCodex(text) {
238
252
  const values = {};
@@ -323,10 +337,11 @@ async function removeCodexConfig(file, ctx) {
323
337
  * place after "remove". A DIFFERENT key the user put there after setup is
324
338
  * none of these, and is left alone.
325
339
  *
326
- * Only the two fields setup sets are touched: auth_mode and OPENAI_API_KEY go
340
+ * Only the fields setup changes are touched: auth_mode and OPENAI_API_KEY go
327
341
  * back to their pre-setup values from the backup, or away if there were none.
328
- * Tokens and refresh times stay as Codex last wrote them (they are fresher
329
- * than the backup). A file left with nothing in it is deleted.
342
+ * The ChatGPT tokens and refresh time setup took out come back from the backup
343
+ * -- unless Codex has written its own since, which are fresher and stay. A
344
+ * file left with nothing in it is deleted.
330
345
  */
331
346
  async function removeCodexAuth(file, ctx, ownership) {
332
347
  if (!(await fs.pathExists(file)))
@@ -366,6 +381,12 @@ async function removeCodexAuth(file, ctx, ownership) {
366
381
  else
367
382
  delete next[field];
368
383
  }
384
+ // Setup took the ChatGPT sign-in out; bring it back unless Codex has
385
+ // written a fresher one since.
386
+ for (const field of CHATGPT_SIGN_IN_FIELDS) {
387
+ if (original && original[field] != null && next[field] == null)
388
+ next[field] = original[field];
389
+ }
369
390
  const meaningful = Object.values(next).some(value => value !== null && value !== undefined
370
391
  && !(typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0));
371
392
  if (!original && !meaningful) {
@@ -588,18 +609,46 @@ export async function configure(ctx) {
588
609
  }
589
610
  throw error;
590
611
  }
591
- const warningText = verification.warnings.length ? ` Warnings: ${verification.warnings.join(' ')}` : '';
612
+ const wsl = await configureWslCodex(ctx);
613
+ if (wsl.changed)
614
+ changed = true;
615
+ const warnings = [...verification.warnings, ...wsl.warnings];
616
+ const warningText = warnings.length ? ` Warnings: ${warnings.join(' ')}` : '';
592
617
  const backupText = backups.length ? ` (backups: ${backups.join(', ')})` : '';
618
+ const wslText = wsl.done.length ? ` Also set up Codex in WSL: ${wsl.done.join(', ')}.` : '';
593
619
  return {
594
620
  id,
595
621
  name,
596
622
  changed,
597
623
  path: configPath,
598
- message: `${changed ? 'configured' : 'already current'} and verified${backupText}.${warningText}`,
624
+ message: `${changed ? 'configured' : 'already current'} and verified${backupText}.${wslText}${warningText}`,
599
625
  ...(changed ? { rollback: snapshotRollback(snapshots, ctx.platform) } : {}),
600
626
  };
601
627
  }
602
- export async function remove(ctx) {
628
+ export async function remove(ctx, wslDeps = defaultWslDeps) {
629
+ const result = await removeAt(ctx);
630
+ if (wslSkipped(ctx))
631
+ return result;
632
+ const { homes, warnings } = await findWslCodexHomes(ctx, wslDeps);
633
+ const parts = [];
634
+ for (const { distro, home } of homes) {
635
+ try {
636
+ const wsl = await removeAt({ ...ctx, home });
637
+ if (wsl.changed) {
638
+ result.changed = true;
639
+ parts.push(`WSL ${distro}: ${wsl.message}`);
640
+ }
641
+ }
642
+ catch (err) {
643
+ warnings.push(`WSL ${distro}: ${err instanceof Error ? err.message : String(err)}`);
644
+ }
645
+ }
646
+ const extra = [...parts, ...warnings.map(w => `Warning: ${w}`)];
647
+ if (extra.length)
648
+ result.message = `${result.message}; ${extra.join('; ')}`;
649
+ return result;
650
+ }
651
+ async function removeAt(ctx) {
603
652
  const configPath = codexConfigPath(ctx.home);
604
653
  const authPath = codexAuthPath(ctx.home);
605
654
  // Read the ownership markers BEFORE config.toml is rewritten below.
@@ -632,6 +681,62 @@ export async function remove(ctx) {
632
681
  throw error;
633
682
  }
634
683
  }
684
+ /**
685
+ * Point Codex inside WSL at ScaleMax too (see codex-wsl.ts for why).
686
+ *
687
+ * Same config.toml merge and auth.json rewrite as on Windows -- the ChatGPT
688
+ * sign-in comes out, the first pre-ScaleMax pair is backed up in that home --
689
+ * minus two things that cannot work from the Linux side: the Connectors table
690
+ * (its headers helper is a Windows script) and the live `codex` check (that
691
+ * Codex is the Windows one). The Windows setup already probed the key.
692
+ */
693
+ export async function configureWslCodex(ctx, deps = defaultWslDeps) {
694
+ if (wslSkipped(ctx))
695
+ return { changed: false, done: [], warnings: [] };
696
+ const { homes, warnings } = await findWslCodexHomes(ctx, deps);
697
+ const done = [];
698
+ let changed = false;
699
+ for (const { distro, home } of homes) {
700
+ try {
701
+ if (await writeCodexHome(ctx, home))
702
+ changed = true;
703
+ done.push(distro);
704
+ }
705
+ catch (err) {
706
+ warnings.push(`WSL ${distro}: Codex there was not set up (${err instanceof Error ? err.message : String(err)}).`);
707
+ }
708
+ }
709
+ return { changed, done, warnings };
710
+ }
711
+ async function writeCodexHome(ctx, home) {
712
+ const configPath = codexConfigPath(home);
713
+ const authPath = codexAuthPath(home);
714
+ const originalConfig = await fs.readFile(configPath, 'utf8').catch(() => '');
715
+ const originalAuth = await fs.readFile(authPath, 'utf8').catch(() => '');
716
+ let existingAuth = {};
717
+ try {
718
+ existingAuth = JSON.parse(originalAuth || '{}');
719
+ }
720
+ catch { }
721
+ const nextAuth = codexAuth(ctx.apiKey, existingAuth);
722
+ const nextConfig = mergeCodexConfig(originalConfig, ctx.baseUrl, selectedModel(ctx), contentSha256(nextAuth), contentSha256(ctx.apiKey));
723
+ if (originalConfig === nextConfig && originalAuth === nextAuth)
724
+ return false;
725
+ if (!originalConfig.includes(GENERATED_HEADER)) {
726
+ for (const file of [configPath, authPath])
727
+ await backupFile(file, home);
728
+ }
729
+ const snapshots = await captureFileSnapshots([configPath, authPath]);
730
+ try {
731
+ await atomicWrite(configPath, nextConfig, 0o600, ctx.platform);
732
+ await atomicWrite(authPath, nextAuth, 0o600, ctx.platform);
733
+ }
734
+ catch (err) {
735
+ await restoreFileSnapshots(snapshots, ctx.platform).catch(() => undefined);
736
+ throw err;
737
+ }
738
+ return true;
739
+ }
635
740
  export async function launch(ctx) {
636
741
  const result = await launchCodex();
637
742
  if (!result.ok)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scalemax",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "Universal ScaleMax installer for AI coding clients",
5
5
  "type": "module",
6
6
  "bin": {