offrouter-adapter-grok 0.2.1 → 0.3.0

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * offrouter-adapter-grok public surface.
3
+ * Install / rollback for Grok personal profiles (MCP config entry).
4
+ */
5
+ export declare const ADAPTER_GROK_PACKAGE: "offrouter-adapter-grok";
6
+ export { isGrokHarnessProfile, isSafeProfileId, isWorkLikeProfile, listAllowlistedPersonalGrokProfiles, resolveGrokProfileDir, SAFE_PROFILE_ID_RE, } from "./profile.js";
7
+ export type { ResolveGrokProfileDirOptions } from "./profile.js";
8
+ export { GROK_CONFIG_REL, GROK_INSTALL_STATE_REL, GrokInstallStateSchema, evaluateInstallProfilePolicy, formatInstallDiffText, installGrokProfile, patchConfigForMcp, } from "./install.js";
9
+ export type { GrokInstallOptions, GrokInstallResult, GrokInstallState, InstallChangeKind, InstallFileChange, } from "./install.js";
10
+ export { rollbackGrokProfile } from "./rollback.js";
11
+ export type { GrokRollbackOptions, GrokRollbackResult } from "./rollback.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,oBAAoB,EAAG,wBAAiC,CAAC;AAEtE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,mCAAmC,EACnC,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * offrouter-adapter-grok public surface.
3
+ * Install / rollback for Grok personal profiles (MCP config entry).
4
+ */
5
+ export const ADAPTER_GROK_PACKAGE = "offrouter-adapter-grok";
6
+ export { isGrokHarnessProfile, isSafeProfileId, isWorkLikeProfile, listAllowlistedPersonalGrokProfiles, resolveGrokProfileDir, SAFE_PROFILE_ID_RE, } from "./profile.js";
7
+ export { GROK_CONFIG_REL, GROK_INSTALL_STATE_REL, GrokInstallStateSchema, evaluateInstallProfilePolicy, formatInstallDiffText, installGrokProfile, patchConfigForMcp, } from "./install.js";
8
+ export { rollbackGrokProfile } from "./rollback.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAiC,CAAC;AAEtE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,mCAAmC,EACnC,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { type OffRouterConfig, type PolicyDenialCode } from "offrouter-core";
2
+ import { z } from "zod";
3
+ export declare const GROK_INSTALL_STATE_REL: ".offrouter/grok-install-state.json";
4
+ export declare const GROK_CONFIG_REL: "config.toml";
5
+ export declare const GrokInstallStateSchema: z.ZodObject<{
6
+ version: z.ZodLiteral<1>;
7
+ profile: z.ZodString;
8
+ harness: z.ZodLiteral<"grok">;
9
+ installedAt: z.ZodString;
10
+ configRelative: z.ZodLiteral<"config.toml">;
11
+ files: z.ZodRecord<z.ZodString, z.ZodObject<{
12
+ previous: z.ZodNullable<z.ZodString>;
13
+ hash: z.ZodOptional<z.ZodString>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ previous: string | null;
16
+ hash?: string | undefined;
17
+ }, {
18
+ previous: string | null;
19
+ hash?: string | undefined;
20
+ }>>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ version: 1;
23
+ profile: string;
24
+ harness: "grok";
25
+ installedAt: string;
26
+ configRelative: "config.toml";
27
+ files: Record<string, {
28
+ previous: string | null;
29
+ hash?: string | undefined;
30
+ }>;
31
+ }, {
32
+ version: 1;
33
+ profile: string;
34
+ harness: "grok";
35
+ installedAt: string;
36
+ configRelative: "config.toml";
37
+ files: Record<string, {
38
+ previous: string | null;
39
+ hash?: string | undefined;
40
+ }>;
41
+ }>;
42
+ export type GrokInstallState = z.infer<typeof GrokInstallStateSchema>;
43
+ export type InstallChangeKind = "create" | "update" | "unchanged" | "remove";
44
+ export interface InstallFileChange {
45
+ path: string;
46
+ relativePath: string;
47
+ kind: InstallChangeKind;
48
+ /** Diff-like summary line for human output. */
49
+ summary: string;
50
+ }
51
+ export interface GrokInstallOptions {
52
+ profile: string;
53
+ config: OffRouterConfig;
54
+ env?: NodeJS.ProcessEnv;
55
+ homedir?: () => string;
56
+ dryRun?: boolean;
57
+ }
58
+ export interface GrokInstallResult {
59
+ ok: boolean;
60
+ dryRun: boolean;
61
+ profile: string;
62
+ profileDir: string;
63
+ changes: InstallFileChange[];
64
+ message: string;
65
+ errorCode?: PolicyDenialCode | "install_error";
66
+ statePath?: string;
67
+ }
68
+ /**
69
+ * Produce the desired config.toml content for the OffRouter MCP entry using a
70
+ * TOML parser (smol-toml) instead of ad hoc string surgery.
71
+ *
72
+ * - Missing/empty file => fresh config containing only the MCP entry.
73
+ * - Existing file already has [mcp_servers.offrouter] with matching
74
+ * command/args => return the original bytes unchanged (idempotent).
75
+ * - Existing file has a conflicting offrouter entry (or none) => set/replace
76
+ * the entry and stringify, preserving all other unrelated keys.
77
+ *
78
+ * smol-toml does not preserve comments on round-trip; that is accepted as
79
+ * best-effort per the project rule against ad hoc config parsing.
80
+ */
81
+ export declare function patchConfigForMcp(existing: string | null): string;
82
+ /**
83
+ * Use routeRequest with empty candidates so work/unallowlisted profile denials
84
+ * reuse the same core policy codes users see from route explain / hooks.
85
+ */
86
+ export declare function evaluateInstallProfilePolicy(profile: string, config: OffRouterConfig): {
87
+ allowed: boolean;
88
+ errorCode?: PolicyDenialCode;
89
+ message?: string;
90
+ };
91
+ /**
92
+ * Install the OffRouter Grok MCP entry into a single profile directory.
93
+ */
94
+ export declare function installGrokProfile(options: GrokInstallOptions): Promise<GrokInstallResult>;
95
+ /**
96
+ * Human-readable diff-like text for an install/uninstall result matrix.
97
+ */
98
+ export declare function formatInstallDiffText(results: GrokInstallResult[], headline?: string): string;
99
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAEtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,sBAAsB,EACjC,oCAA6C,CAAC;AAEhD,eAAO,MAAM,eAAe,EAAG,aAAsB,CAAC;AAOtD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAajC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ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AAC,EAAE,MAAM,GAChB,MAAM,CA4BR"}
@@ -0,0 +1,365 @@
1
+ /**
2
+ * Profile-scoped installer for Grok personal profiles.
3
+ *
4
+ * Mirrors the Codex adapter's TOML model but writes ONE MCP server entry into
5
+ * the Grok profile's TOML config file (profile-scoped) at
6
+ * <profileDir>/config.toml and records rollback metadata inside the target
7
+ * profile (.offrouter/grok-install-state.json).
8
+ *
9
+ * Grok Build config.toml is parsed/stringified with smol-toml (same version as
10
+ * core/codex), never ad hoc string surgery. MCP servers live under the
11
+ * top-level `mcp_servers` table.
12
+ */
13
+ import { access, mkdir, readFile, writeFile } from "node:fs/promises";
14
+ import { constants } from "node:fs";
15
+ import { createHash } from "node:crypto";
16
+ import { dirname, join } from "node:path";
17
+ import { homedir as osHomedir } from "node:os";
18
+ import { ROUTE_PROTOCOL_VERSION, routeRequest, } from "offrouter-core";
19
+ import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
20
+ import { z } from "zod";
21
+ import { isGrokHarnessProfile, isSafeProfileId, isWorkLikeProfile, resolveGrokProfileDir, } from "./profile.js";
22
+ export const GROK_INSTALL_STATE_REL = ".offrouter/grok-install-state.json";
23
+ export const GROK_CONFIG_REL = "config.toml";
24
+ /** Table name and command/args for the OffRouter MCP server entry. */
25
+ const OFFROUTER_MCP_SERVER_NAME = "offrouter";
26
+ const OFFROUTER_MCP_COMMAND = "offrouter";
27
+ const OFFROUTER_MCP_ARGS = ["mcp", "serve"];
28
+ export const GrokInstallStateSchema = z.object({
29
+ version: z.literal(1),
30
+ profile: z.string().min(1),
31
+ harness: z.literal("grok"),
32
+ installedAt: z.string().min(1),
33
+ configRelative: z.literal(GROK_CONFIG_REL),
34
+ files: z.record(z.string().min(1), z.object({
35
+ previous: z.string().nullable(),
36
+ hash: z.string().optional(),
37
+ })),
38
+ });
39
+ async function pathExists(path) {
40
+ try {
41
+ await access(path, constants.F_OK);
42
+ return true;
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ function sha256(content) {
49
+ return createHash("sha256").update(content).digest("hex");
50
+ }
51
+ function changeSummary(kind, relativePath) {
52
+ switch (kind) {
53
+ case "create":
54
+ return `+ ${relativePath}`;
55
+ case "update":
56
+ return `~ ${relativePath}`;
57
+ case "unchanged":
58
+ return `= ${relativePath}`;
59
+ case "remove":
60
+ return `- ${relativePath}`;
61
+ default:
62
+ return `? ${relativePath}`;
63
+ }
64
+ }
65
+ /**
66
+ * Produce the desired config.toml content for the OffRouter MCP entry using a
67
+ * TOML parser (smol-toml) instead of ad hoc string surgery.
68
+ *
69
+ * - Missing/empty file => fresh config containing only the MCP entry.
70
+ * - Existing file already has [mcp_servers.offrouter] with matching
71
+ * command/args => return the original bytes unchanged (idempotent).
72
+ * - Existing file has a conflicting offrouter entry (or none) => set/replace
73
+ * the entry and stringify, preserving all other unrelated keys.
74
+ *
75
+ * smol-toml does not preserve comments on round-trip; that is accepted as
76
+ * best-effort per the project rule against ad hoc config parsing.
77
+ */
78
+ export function patchConfigForMcp(existing) {
79
+ if (existing === null || existing.trim() === "") {
80
+ return stringifyToml(freshOffrouterConfig());
81
+ }
82
+ const root = parseToml(existing);
83
+ const servers = isTomlTable(root.mcp_servers) ? root.mcp_servers : undefined;
84
+ if (servers !== undefined &&
85
+ isOffrouterMcpEntry(servers[OFFROUTER_MCP_SERVER_NAME])) {
86
+ return existing;
87
+ }
88
+ const nextRoot = {
89
+ ...root,
90
+ mcp_servers: {
91
+ ...(servers ?? {}),
92
+ [OFFROUTER_MCP_SERVER_NAME]: offrouterMcpEntry(),
93
+ },
94
+ };
95
+ return stringifyToml(nextRoot);
96
+ }
97
+ function isTomlTable(value) {
98
+ return typeof value === "object" && value !== null && !Array.isArray(value);
99
+ }
100
+ /**
101
+ * True when an existing [mcp_servers.offrouter] entry already matches the
102
+ * OffRouter command/args. Detects a correct prior install by value (not by
103
+ * string equality) so a conflicting entry is overwritten.
104
+ */
105
+ function isOffrouterMcpEntry(value) {
106
+ if (!isTomlTable(value)) {
107
+ return false;
108
+ }
109
+ if (value.command !== OFFROUTER_MCP_COMMAND) {
110
+ return false;
111
+ }
112
+ const args = value.args;
113
+ if (!Array.isArray(args) || args.length !== OFFROUTER_MCP_ARGS.length) {
114
+ return false;
115
+ }
116
+ return args.every((item, index) => item === OFFROUTER_MCP_ARGS[index]);
117
+ }
118
+ function offrouterMcpEntry() {
119
+ return {
120
+ command: OFFROUTER_MCP_COMMAND,
121
+ args: [...OFFROUTER_MCP_ARGS],
122
+ };
123
+ }
124
+ function freshOffrouterConfig() {
125
+ return {
126
+ mcp_servers: {
127
+ [OFFROUTER_MCP_SERVER_NAME]: offrouterMcpEntry(),
128
+ },
129
+ };
130
+ }
131
+ function tinyPolicyProbeRequest(profile) {
132
+ return {
133
+ requestId: "install-policy-probe",
134
+ protocolVersion: ROUTE_PROTOCOL_VERSION,
135
+ harness: { kind: "grok", profile },
136
+ task: {
137
+ promptPreview: "install policy probe",
138
+ promptDigest: "sha256:install-policy-probe",
139
+ kind: "other",
140
+ risk: "low",
141
+ },
142
+ workspace: { cwd: "/tmp/offrouter-install-probe", trusted: true },
143
+ constraints: {
144
+ subscriptionFirst: true,
145
+ allowApiKeyFallback: false,
146
+ },
147
+ };
148
+ }
149
+ /**
150
+ * Use routeRequest with empty candidates so work/unallowlisted profile denials
151
+ * reuse the same core policy codes users see from route explain / hooks.
152
+ */
153
+ export function evaluateInstallProfilePolicy(profile, config) {
154
+ const decision = routeRequest(tinyPolicyProbeRequest(profile), [], config.policy);
155
+ const denials = decision.policyDenials ?? [];
156
+ const hard = denials.find((d) => d.code === "work_profile_denied" ||
157
+ d.code === "profile_not_allowlisted" ||
158
+ d.code === "privacy_label_denied");
159
+ if (hard) {
160
+ return {
161
+ allowed: false,
162
+ errorCode: hard.code,
163
+ message: hard.message,
164
+ };
165
+ }
166
+ // Empty candidates also sets needsConfiguration + may include
167
+ // profile_not_allowlisted even for personal unallowlisted. When allowlisted,
168
+ // only needsConfiguration remains; that is fine for install.
169
+ const profileDenial = denials.find((d) => d.target === "profile");
170
+ if (profileDenial) {
171
+ return {
172
+ allowed: false,
173
+ errorCode: profileDenial.code,
174
+ message: profileDenial.message,
175
+ };
176
+ }
177
+ if (!config.policy.allowlistedProfiles.includes(profile)) {
178
+ return {
179
+ allowed: false,
180
+ errorCode: "profile_not_allowlisted",
181
+ message: `Profile ${profile} is not allowlisted. Add it explicitly before installing or routing.`,
182
+ };
183
+ }
184
+ return { allowed: true };
185
+ }
186
+ /**
187
+ * Install the OffRouter Grok MCP entry into a single profile directory.
188
+ */
189
+ export async function installGrokProfile(options) {
190
+ const { profile, config, dryRun = false, env = process.env, homedir = osHomedir, } = options;
191
+ if (!isSafeProfileId(profile)) {
192
+ return {
193
+ ok: false,
194
+ dryRun,
195
+ profile,
196
+ profileDir: "",
197
+ changes: [],
198
+ message: "Unsafe profile id. Use letters, numbers, dots, underscores, and dashes only.",
199
+ errorCode: "install_error",
200
+ };
201
+ }
202
+ const profileDir = resolveGrokProfileDir(profile, { env, homedir });
203
+ const statePath = join(profileDir, GROK_INSTALL_STATE_REL);
204
+ const configPath = join(profileDir, GROK_CONFIG_REL);
205
+ if (!isGrokHarnessProfile(profile)) {
206
+ return {
207
+ ok: false,
208
+ dryRun,
209
+ profile,
210
+ profileDir,
211
+ changes: [],
212
+ message: "Grok install supports only profile ids named grok or starting with grok-.",
213
+ errorCode: "install_error",
214
+ };
215
+ }
216
+ // Work-like profile ids (e.g. grok-work, grok-work-staging) are never
217
+ // installable, even when allowlisted. This mirrors the filter used by
218
+ // listAllowlistedPersonalGrokProfiles so explicit and --all-personal
219
+ // installs apply the same personal-only boundary.
220
+ if (isWorkLikeProfile(profile)) {
221
+ return {
222
+ ok: false,
223
+ dryRun,
224
+ profile,
225
+ profileDir,
226
+ changes: [],
227
+ message: `Profile ${profile} looks like a work profile and is never installable, even if allowlisted. Use a personal profile such as grok-personal.`,
228
+ errorCode: "work_profile_denied",
229
+ };
230
+ }
231
+ const policy = evaluateInstallProfilePolicy(profile, config);
232
+ if (!policy.allowed) {
233
+ return {
234
+ ok: false,
235
+ dryRun,
236
+ profile,
237
+ profileDir,
238
+ changes: [],
239
+ message: policy.message ?? `Profile ${profile} is not installable.`,
240
+ errorCode: policy.errorCode ?? "install_error",
241
+ };
242
+ }
243
+ // Preserve original previous contents across re-installs (idempotent rollback).
244
+ let priorState = null;
245
+ if (await pathExists(statePath)) {
246
+ try {
247
+ const raw = await readFile(statePath, "utf8");
248
+ priorState = GrokInstallStateSchema.parse(JSON.parse(raw));
249
+ }
250
+ catch (err) {
251
+ const detail = err instanceof Error ? err.message : String(err);
252
+ return {
253
+ ok: false,
254
+ dryRun,
255
+ profile,
256
+ profileDir,
257
+ changes: [],
258
+ message: `Invalid install state at ${statePath}: ${detail}`,
259
+ errorCode: "install_error",
260
+ };
261
+ }
262
+ }
263
+ const changes = [];
264
+ // --- config.toml MCP entry ---
265
+ let current = null;
266
+ if (await pathExists(configPath)) {
267
+ current = await readFile(configPath, "utf8");
268
+ }
269
+ const priorFile = priorState?.files[GROK_CONFIG_REL];
270
+ const previous = priorFile !== undefined ? priorFile.previous : current;
271
+ const desired = patchConfigForMcp(current);
272
+ let kind;
273
+ if (current === null) {
274
+ kind = "create";
275
+ }
276
+ else if (current === desired) {
277
+ kind = "unchanged";
278
+ }
279
+ else {
280
+ kind = "update";
281
+ }
282
+ changes.push({
283
+ path: configPath,
284
+ relativePath: GROK_CONFIG_REL,
285
+ kind,
286
+ summary: changeSummary(kind, GROK_CONFIG_REL),
287
+ });
288
+ if (!dryRun && kind !== "unchanged") {
289
+ await mkdir(dirname(configPath), { recursive: true });
290
+ await writeFile(configPath, desired, "utf8");
291
+ }
292
+ // --- install state metadata ---
293
+ const state = {
294
+ version: 1,
295
+ profile,
296
+ harness: "grok",
297
+ installedAt: priorState?.installedAt ?? new Date().toISOString(),
298
+ configRelative: GROK_CONFIG_REL,
299
+ files: {
300
+ [GROK_CONFIG_REL]: {
301
+ previous,
302
+ hash: sha256(desired),
303
+ },
304
+ },
305
+ };
306
+ const stateJson = `${JSON.stringify(state, null, 2)}\n`;
307
+ let stateKind = "create";
308
+ if (await pathExists(statePath)) {
309
+ const existing = await readFile(statePath, "utf8");
310
+ stateKind = existing === stateJson ? "unchanged" : "update";
311
+ }
312
+ changes.push({
313
+ path: statePath,
314
+ relativePath: GROK_INSTALL_STATE_REL,
315
+ kind: stateKind,
316
+ summary: changeSummary(stateKind, GROK_INSTALL_STATE_REL),
317
+ });
318
+ if (!dryRun && stateKind !== "unchanged") {
319
+ await mkdir(dirname(statePath), { recursive: true });
320
+ await writeFile(statePath, stateJson, "utf8");
321
+ }
322
+ const wrote = changes.filter((c) => c.kind === "create" || c.kind === "update");
323
+ const message = dryRun
324
+ ? `Dry run: would apply ${wrote.length} file change(s) for profile ${profile}.`
325
+ : `Installed OffRouter Grok MCP entry for profile ${profile} (${wrote.length} file change(s)).`;
326
+ return {
327
+ ok: true,
328
+ dryRun,
329
+ profile,
330
+ profileDir,
331
+ changes,
332
+ message,
333
+ statePath,
334
+ };
335
+ }
336
+ /**
337
+ * Human-readable diff-like text for an install/uninstall result matrix.
338
+ */
339
+ export function formatInstallDiffText(results, headline) {
340
+ const lines = [];
341
+ if (headline) {
342
+ lines.push(headline);
343
+ }
344
+ for (const result of results) {
345
+ lines.push(``);
346
+ lines.push(`## ${result.profile} (${result.ok ? (result.dryRun ? "dry-run" : "applied") : "error"})`);
347
+ lines.push(`profileDir: ${result.profileDir}`);
348
+ if (!result.ok) {
349
+ lines.push(`error: ${result.message}`);
350
+ continue;
351
+ }
352
+ for (const change of result.changes) {
353
+ if (change.kind === "unchanged")
354
+ continue;
355
+ lines.push(change.summary);
356
+ }
357
+ const unchanged = result.changes.filter((c) => c.kind === "unchanged").length;
358
+ if (unchanged > 0) {
359
+ lines.push(`= ${unchanged} unchanged`);
360
+ }
361
+ lines.push(result.message);
362
+ }
363
+ return lines.join("\n").trimEnd() + "\n";
364
+ }
365
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@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MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,UAAU,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YACvC,SAAS;QACX,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;gBAAE,SAAS;YAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CACrC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAC9B,CAAC,MAAM,CAAC;QACT,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,YAAY,CAAC,CAAC;QACzC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { OffRouterConfig } from "offrouter-core";
2
+ export declare const SAFE_PROFILE_ID_RE: RegExp;
3
+ export declare function isSafeProfileId(profile: string): boolean;
4
+ export interface ResolveGrokProfileDirOptions {
5
+ env?: NodeJS.ProcessEnv;
6
+ homedir?: () => string;
7
+ }
8
+ /**
9
+ * Resolve the on-disk Grok profile directory for a OffRouter profile id.
10
+ *
11
+ * - When OFFROUTER_GROK_PROFILES_DIR is set: $DIR/<profile>
12
+ * - profile id `grok` -> GROK_HOME (if set) else ~/.grok
13
+ * - otherwise -> ~/.<profile> (e.g. grok-personal -> ~/.grok-personal)
14
+ */
15
+ export declare function resolveGrokProfileDir(profile: string, options?: ResolveGrokProfileDirOptions): string;
16
+ /**
17
+ * Personal Grok profiles only: id starts with "grok" or is exactly "grok".
18
+ */
19
+ export declare function isGrokHarnessProfile(profile: string): boolean;
20
+ export declare function isWorkLikeProfile(profile: string): boolean;
21
+ /**
22
+ * Allowlisted personal Grok profiles eligible for install --all-personal.
23
+ * Excludes the bare global `grok` profile (only mutable when explicit) and
24
+ * work-like ids, and applies deniedProfilePatterns glob filters.
25
+ */
26
+ export declare function listAllowlistedPersonalGrokProfiles(config: OffRouterConfig): string[];
27
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,QAAiC,CAAC;AAEjE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,MAAM,WAAW,4BAA4B;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;CACxB;AAUD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,4BAAiC,GACzC,MAAM,CAiBR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAQD;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,eAAe,GACtB,MAAM,EAAE,CAaV"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Grok profile directory resolution and allowlist helpers.
3
+ *
4
+ * Mirrors the Codex adapter's profile isolation model:
5
+ * - env OFFROUTER_GROK_PROFILES_DIR set => <root>/<profile>
6
+ * - profile === "grok" => env GROK_HOME || ~/.grok (bare global; only
7
+ * mutable when explicitly allowlisted)
8
+ * - otherwise => ~/.<profile> (e.g. grok-personal => ~/.grok-personal)
9
+ */
10
+ import { homedir as osHomedir } from "node:os";
11
+ import { join, resolve } from "node:path";
12
+ export const SAFE_PROFILE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
13
+ export function isSafeProfileId(profile) {
14
+ return SAFE_PROFILE_ID_RE.test(profile);
15
+ }
16
+ function envValue(env, key) {
17
+ const v = env?.[key]?.trim();
18
+ return v || undefined;
19
+ }
20
+ /**
21
+ * Resolve the on-disk Grok profile directory for a OffRouter profile id.
22
+ *
23
+ * - When OFFROUTER_GROK_PROFILES_DIR is set: $DIR/<profile>
24
+ * - profile id `grok` -> GROK_HOME (if set) else ~/.grok
25
+ * - otherwise -> ~/.<profile> (e.g. grok-personal -> ~/.grok-personal)
26
+ */
27
+ export function resolveGrokProfileDir(profile, options = {}) {
28
+ if (!isSafeProfileId(profile)) {
29
+ throw new Error(`Unsafe profile id "${profile}". Use letters, numbers, dots, underscores, and dashes only.`);
30
+ }
31
+ const env = options.env ?? process.env;
32
+ const home = (options.homedir ?? osHomedir)();
33
+ const profilesRoot = envValue(env, "OFFROUTER_GROK_PROFILES_DIR");
34
+ if (profilesRoot) {
35
+ return resolve(join(profilesRoot, profile));
36
+ }
37
+ if (profile === "grok") {
38
+ const grokHome = envValue(env, "GROK_HOME");
39
+ return resolve(grokHome ?? join(home, ".grok"));
40
+ }
41
+ return resolve(join(home, `.${profile}`));
42
+ }
43
+ /**
44
+ * Personal Grok profiles only: id starts with "grok" or is exactly "grok".
45
+ */
46
+ export function isGrokHarnessProfile(profile) {
47
+ return profile === "grok" || profile.startsWith("grok-");
48
+ }
49
+ export function isWorkLikeProfile(profile) {
50
+ return profile.endsWith("-work") || profile.includes("-work-");
51
+ }
52
+ function matchGlob(pattern, value) {
53
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
54
+ const re = new RegExp(`^${escaped.replace(/\*/g, ".*")}$`);
55
+ return re.test(value);
56
+ }
57
+ /**
58
+ * Allowlisted personal Grok profiles eligible for install --all-personal.
59
+ * Excludes the bare global `grok` profile (only mutable when explicit) and
60
+ * work-like ids, and applies deniedProfilePatterns glob filters.
61
+ */
62
+ export function listAllowlistedPersonalGrokProfiles(config) {
63
+ return [...config.policy.allowlistedProfiles]
64
+ .filter((id) => isSafeProfileId(id) &&
65
+ isGrokHarnessProfile(id) &&
66
+ id !== "grok" &&
67
+ !isWorkLikeProfile(id) &&
68
+ !(config.policy.deniedProfilePatterns ?? []).some((p) => matchGlob(p, id)))
69
+ .sort((a, b) => a.localeCompare(b));
70
+ }
71
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;AAEjE,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAOD,SAAS,QAAQ,CACf,GAAkC,EAClC,GAAW;IAEX,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC7B,OAAO,CAAC,IAAI,SAAS,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,UAAwC,EAAE;IAE1C,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,sBAAsB,OAAO,8DAA8D,CAC5F,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG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H,MAAM,UAAU,mCAAmC,CACjD,MAAuB;IAEvB,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;SAC1C,MAAM,CACL,CAAC,EAAE,EAAE,EAAE,CACL,eAAe,CAAC,EAAE,CAAC;QACnB,oBAAoB,CAAC,EAAE,CAAC;QACxB,EAAE,KAAK,MAAM;QACb,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACtB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACtD,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CACjB,CACJ;SACA,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type InstallFileChange } from "./install.js";
2
+ export interface GrokRollbackOptions {
3
+ profile: string;
4
+ env?: NodeJS.ProcessEnv;
5
+ homedir?: () => string;
6
+ dryRun?: boolean;
7
+ /** Optional absolute override of the profile directory (tests). */
8
+ profileDir?: string;
9
+ }
10
+ export interface GrokRollbackResult {
11
+ ok: boolean;
12
+ dryRun: boolean;
13
+ profile: string;
14
+ profileDir: string;
15
+ changes: InstallFileChange[];
16
+ message: string;
17
+ errorCode?: "no_install_state" | "invalid_install_state" | "rollback_error";
18
+ }
19
+ /**
20
+ * Restore files tracked by grok-install-state.json for a profile.
21
+ */
22
+ export declare function rollbackGrokProfile(options: GrokRollbackOptions): Promise<GrokRollbackResult>;
23
+ //# sourceMappingURL=rollback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollback.d.ts","sourceRoot":"","sources":["../src/rollback.ts"],"names":[],"mappings":"AAgBA,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,kBAAkB,GAAG,uBAAuB,GAAG,gBAAgB,CAAC;CAC7E;AAmID;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B"}