@bakers-build/addon-grok 0.10.1-next.1 → 0.10.1-next.10

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.
@@ -1,5 +1,6 @@
1
- import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent, type ResolvedSecurity, type RunEnvPolicy, type SandboxHost, type SandboxPreflight, type SecurityOptions } from '@bakers-build/conductor/contract';
1
+ import { type AgentFootprint, type AgentPlugin, type AgentRunContext, type AgentRunIdentity, type BbAgent, type ResolvedSecurity, type RunEnvPolicy, type SandboxHost, type SandboxPreflight, type SecurityOptions } from '@bakers-build/conductor/contract';
2
2
  export { parseGrokTranscript } from './footprint.js';
3
+ export { encodeGrokSessionCwd } from './run.js';
3
4
  export type GrokReasoningEffort = 'high' | 'medium' | 'low';
4
5
  export interface GrokAgentOptions extends SecurityOptions {
5
6
  model?: string;
@@ -7,7 +8,6 @@ export interface GrokAgentOptions extends SecurityOptions {
7
8
  effort?: string;
8
9
  args?: string[];
9
10
  }
10
- export declare function encodeGrokSessionCwd(cwd: string): string;
11
11
  export declare class GrokAgent implements BbAgent {
12
12
  private readonly home;
13
13
  readonly id = "grok";
@@ -18,7 +18,10 @@ export declare class GrokAgent implements BbAgent {
18
18
  readonly security: ResolvedSecurity;
19
19
  readonly runEnvPolicy: RunEnvPolicy;
20
20
  constructor(options?: GrokAgentOptions, home?: string);
21
- launchCommand(prompt: string, run?: AgentRunIdentity): string;
21
+ prepareRun(context: AgentRunContext): import("@bakers-build/conductor/contract").AgentRunPreparation;
22
+ launchCommand(prompt: string, run?: AgentRunIdentity, _workspacePath?: string, _tools?: {
23
+ url: string;
24
+ }, env?: Readonly<Record<string, string>>): string;
22
25
  /** The launch flags a security mode owns (`docs/addons/grok.md`). */
23
26
  private securityFlags;
24
27
  /** Grok's sandbox is Landlock on Linux and Seatbelt on macOS. */
package/dist/src/index.js CHANGED
@@ -5,7 +5,9 @@ import { fileURLToPath } from 'node:url';
5
5
  import { resolveAgentCliOptions, resolveSecurityOptions, systemSandboxHost, validateOptionalString, } from '@bakers-build/conductor/contract';
6
6
  import { shellQuote } from '@bakers-build/core';
7
7
  import { parseGrokTranscript } from './footprint.js';
8
+ import { encodeGrokSessionCwd, prepareGrokRun } from './run.js';
8
9
  export { parseGrokTranscript } from './footprint.js';
10
+ export { encodeGrokSessionCwd } from './run.js';
9
11
  const GROK_RESERVED = ['--permission-mode', '--session-id', '-s'];
10
12
  /** Flags sandbox mode owns on top of `GROK_RESERVED` (`docs/addons/grok.md`). */
11
13
  const GROK_SANDBOX_RESERVED = [
@@ -110,9 +112,6 @@ const GROK_KNOWN = [
110
112
  { kind: 'model', flags: ['--model', '-m'] },
111
113
  { kind: 'effort', flags: ['--reasoning-effort', '--effort'] },
112
114
  ];
113
- export function encodeGrokSessionCwd(cwd) {
114
- return encodeURIComponent(cwd);
115
- }
116
115
  async function readText(path) {
117
116
  try {
118
117
  return await readFile(path, 'utf8');
@@ -184,7 +183,10 @@ export class GrokAgent {
184
183
  validateOptionalString(options.reasoning_effort, 'reasoning_effort');
185
184
  this.overrides = cli.overrides;
186
185
  }
187
- launchCommand(prompt, run) {
186
+ prepareRun(context) {
187
+ return prepareGrokRun(context, join(this.home, '.grok'));
188
+ }
189
+ launchCommand(prompt, run, _workspacePath, _tools, env = {}) {
188
190
  const parts = ['grok'];
189
191
  if (prompt !== '') {
190
192
  // Positional — the interactive form Grok Build documents
@@ -217,7 +219,8 @@ export class GrokAgent {
217
219
  return [
218
220
  shellQuote(process.execPath),
219
221
  shellQuote(launcher),
220
- shellQuote(join(this.home, '.grok')),
222
+ // An isolated run's own home, prepared by prepareRun.
223
+ shellQuote(env.GROK_HOME ?? join(this.home, '.grok')),
221
224
  shellQuote(JSON.stringify(this.security.sandbox.allow_write)),
222
225
  ...parts,
223
226
  ].join(' ');
@@ -0,0 +1,4 @@
1
+ import type { AgentRunContext, AgentRunPreparation } from '@bakers-build/conductor/contract';
2
+ export declare function encodeGrokSessionCwd(cwd: string): string;
3
+ /** Prepare Grok's files in the home supplied by any execution backend. */
4
+ export declare function prepareGrokRun(context: AgentRunContext, grokHome: string, hostEnv?: Readonly<Record<string, string | undefined>>): AgentRunPreparation;
@@ -0,0 +1,42 @@
1
+ import { copyFileSync, existsSync, mkdirSync, realpathSync, symlinkSync, writeFileSync, } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ export function encodeGrokSessionCwd(cwd) {
4
+ return encodeURIComponent(cwd);
5
+ }
6
+ /** Prepare Grok's files in the home supplied by any execution backend. */
7
+ export function prepareGrokRun(context, grokHome, hostEnv = process.env) {
8
+ const home = join(context.homePath, '.grok');
9
+ mkdirSync(join(home, 'sessions'), { recursive: true });
10
+ // Writable copies: a managed launch writes its profile into sandbox.toml;
11
+ // requirements.toml keeps an enterprise policy in force.
12
+ for (const name of ['config.toml', 'sandbox.toml', 'requirements.toml'])
13
+ if (existsSync(join(grokHome, name)))
14
+ copyFileSync(join(grokHome, name), join(home, name));
15
+ // Transcripts land in the user Grok home, where the conductor reads them.
16
+ const key = encodeGrokSessionCwd(context.workspacePath);
17
+ const transcripts = join(grokHome, 'sessions', key);
18
+ mkdirSync(transcripts, { recursive: true });
19
+ symlinkSync(transcripts, join(home, 'sessions', key));
20
+ const env = { GROK_HOME: home };
21
+ const bindPaths = [];
22
+ if (!context.env.XAI_API_KEY) {
23
+ if (hostEnv.XAI_API_KEY)
24
+ env.XAI_API_KEY = hostEnv.XAI_API_KEY;
25
+ else if (existsSync(join(grokHome, 'auth.json'))) {
26
+ // The run shares the host's login file, never a copy: a refresh in one
27
+ // copy rotates the token and logs every other copy out.
28
+ const login = join(home, 'auth.json');
29
+ writeFileSync(login, '', { mode: 0o600 });
30
+ bindPaths.push({
31
+ source: realpathSync(join(grokHome, 'auth.json')),
32
+ target: login,
33
+ });
34
+ }
35
+ }
36
+ return {
37
+ env,
38
+ readPaths: [],
39
+ writePaths: [transcripts],
40
+ ...(bindPaths.length ? { bindPaths } : {}),
41
+ };
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-grok",
3
- "version": "0.10.1-next.1",
3
+ "version": "0.10.1-next.10",
4
4
  "description": "bakers.build agent plugin for xAI Grok Build, with a real session footprint.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "directory": "bakers-cli/addons/grok"
23
23
  },
24
24
  "peerDependencies": {
25
- "@bakers-build/conductor": "^0.10.1-next.1",
26
- "@bakers-build/core": "^0.10.1-next.1"
25
+ "@bakers-build/conductor": "^0.10.1-next.10",
26
+ "@bakers-build/core": "^0.10.1-next.10"
27
27
  },
28
28
  "bakersBuild": {
29
- "commit": "f9cee7721df536cac94906e7278d60a13e202502",
29
+ "commit": "d0f650fbe4c44eda2a26be62d28d30c22c56c386",
30
30
  "channel": "next"
31
31
  }
32
32
  }