@claudexor/harness-grok 0.0.0-stage → 4.8.1

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.
package/dist/parse.js ADDED
@@ -0,0 +1,221 @@
1
+ import { nowIso, redactSecrets } from "@claudexor/util";
2
+ const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
3
+ const string = (value) => (typeof value === "string" ? value : "");
4
+ /** Only vendor failure channels call this classifier; assistant prose never does.
5
+ * It types quota and rate limits only. Grok documents no authentication error
6
+ * code and refreshes and retries a 401 itself, and a proxy or backend can
7
+ * print the same words, so no text or code becomes an authentication verdict:
8
+ * such a failure stays untyped and never marks the account unusable. Login
9
+ * readiness belongs to the pre-run `grok models` probe. */
10
+ export function grokFailure(value, sessionId) {
11
+ const data = object(value);
12
+ const message = string(value) || string(data.message) || string(data.error) || "Grok CLI failed";
13
+ const event = {
14
+ type: "error",
15
+ session_id: sessionId,
16
+ ts: nowIso(),
17
+ error: redactSecrets(message).slice(0, 2000),
18
+ };
19
+ const code = string(data.code) || string(data.type);
20
+ if (data.status === 429 ||
21
+ data.status_code === 429 ||
22
+ /^(?:rate_limit_exceeded|quota_exceeded|usage_limit_exceeded|resource_exhausted)$/.test(code) ||
23
+ /\brate[ _-]?limit(?:ed| exceeded)?\b|\btoo many requests\b|\bquota[ _-]?(?:exceeded|exhausted)\b|\busage limit\b|\b(?:HTTP|status|code)\s*429\b/i.test(message)) {
24
+ const seconds = data.retry_after ?? data.retry_after_seconds;
25
+ const delay = typeof seconds === "number" && Number.isFinite(seconds) && seconds >= 0
26
+ ? Math.ceil(seconds * 1000)
27
+ : null;
28
+ const resets = typeof data.resets_at === "string" && Number.isFinite(Date.parse(data.resets_at))
29
+ ? new Date(data.resets_at).toISOString()
30
+ : null;
31
+ event.rate_limit = { resets_at: resets, retry_delay_ms: delay, applies_to_models: null };
32
+ event.status = { kind: "api_retry", error_category: "rate_limit" };
33
+ }
34
+ return event;
35
+ }
36
+ const tokens = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : null;
37
+ /** One aggregate usage record from a result frame. The bundled 1.0.70 guide
38
+ * (`14-headless-mode.md`) defines three disjoint input buckets, `input_tokens`
39
+ * (uncached), cache reads and cache creation, so their sum is the complete
40
+ * input total; recorded 1.0.67 results agree (9856 cached beside 6086 input).
41
+ * Grok emits a bucket it cannot account for as 0, so an all-zero record is
42
+ * unknown, not free, and is not reported as usage. */
43
+ function resultUsage(raw) {
44
+ const source = object(raw);
45
+ const buckets = [
46
+ source.input_tokens,
47
+ source.output_tokens,
48
+ source.cache_read_input_tokens,
49
+ source.cache_creation_input_tokens,
50
+ ].filter((value) => typeof value === "number");
51
+ if (buckets.length > 0 && buckets.every((value) => value === 0))
52
+ return null;
53
+ const usage = {};
54
+ for (const [native, normalized] of [
55
+ ["input_tokens", "input_tokens"],
56
+ ["output_tokens", "output_tokens"],
57
+ ["cache_read_input_tokens", "cached_input_tokens"],
58
+ ]) {
59
+ const n = source[native];
60
+ if (typeof n === "number" && Number.isFinite(n) && n >= 0)
61
+ usage[normalized] = n;
62
+ }
63
+ const input = tokens(source.input_tokens);
64
+ const read = tokens(source.cache_read_input_tokens);
65
+ const write = tokens(source.cache_creation_input_tokens);
66
+ if (read !== null || write !== null)
67
+ usage.input_token_usage = {
68
+ total_tokens: input !== null && read !== null && write !== null ? input + read + write : null,
69
+ cache_read_tokens: read,
70
+ cache_write_tokens: write,
71
+ };
72
+ // OAuth cost is vendor accounting, not a charge to the user's API key.
73
+ // Tokens remain useful without manufacturing a subscription price.
74
+ return Object.keys(usage).length ? usage : null;
75
+ }
76
+ /** Messages JSON is Claude-shaped, but usage/finality belong to Grok's result,
77
+ * never to intermediate assistant messages or tool-result text. A top-level
78
+ * error frame fails the turn; a result that still follows contributes only its
79
+ * aggregate usage, so spend is counted once and no answer is manufactured. */
80
+ export function createGrokParser() {
81
+ const tools = new Map();
82
+ let failed = false;
83
+ let resulted = false;
84
+ const parseEvent = (raw, sessionId) => {
85
+ const obj = object(raw);
86
+ const base = { session_id: sessionId, ts: nowIso() };
87
+ if (obj.type === "system") {
88
+ if (obj.subtype !== "init")
89
+ return [];
90
+ return [
91
+ {
92
+ ...base,
93
+ type: "started",
94
+ observed_model: string(obj.model) || undefined,
95
+ payload: { native_session_id: string(obj.session_id) },
96
+ },
97
+ ];
98
+ }
99
+ if (obj.type === "assistant") {
100
+ const events = [];
101
+ for (const block of Array.isArray(obj.message?.content) ? obj.message.content : []) {
102
+ if (block.type === "text" && typeof block.text === "string")
103
+ events.push({ ...base, type: "message", text: block.text });
104
+ if (block.type === "tool_use" || block.type === "server_tool_use") {
105
+ const name = string(block.name) || "tool";
106
+ const input = object(block.input);
107
+ const target = string(input.file_path) ||
108
+ string(input.path) ||
109
+ string(input.relative_workspace_path) ||
110
+ string(input.command);
111
+ const tool = {
112
+ name,
113
+ kind: name === "grep"
114
+ ? "search"
115
+ : /terminal|command/.test(name)
116
+ ? "command"
117
+ : /web_/.test(name)
118
+ ? "web"
119
+ : ["read_file", "list_dir", "search_replace", "write"].includes(name)
120
+ ? "file"
121
+ : "other",
122
+ use_id: string(block.id) || undefined,
123
+ target: target ? redactSecrets(target).slice(0, 500) : undefined,
124
+ };
125
+ if (tool.use_id)
126
+ tools.set(tool.use_id, tool);
127
+ events.push({ ...base, type: "tool_call", text: name, tool });
128
+ }
129
+ }
130
+ return events;
131
+ }
132
+ if (obj.type === "user") {
133
+ const events = [];
134
+ for (const block of Array.isArray(obj.message?.content) ? obj.message.content : []) {
135
+ if (block.type !== "tool_result")
136
+ continue;
137
+ const id = string(block.tool_use_id);
138
+ const tool = tools.get(id) ?? { name: "tool", kind: "other", use_id: id };
139
+ if (typeof block.is_error !== "boolean") {
140
+ events.push({
141
+ ...base,
142
+ type: "status",
143
+ text: `${tool.name}: result carried no success or failure status`,
144
+ tool,
145
+ });
146
+ continue;
147
+ }
148
+ const detail = redactSecrets(string(block.content)).slice(0, 1000);
149
+ events.push({
150
+ ...base,
151
+ type: "tool_result",
152
+ text: "tool_result",
153
+ tool: {
154
+ ...tool,
155
+ status: block.is_error === true ? "error" : "ok",
156
+ ...(block.is_error === true
157
+ ? { error_summary: detail || "tool failed" }
158
+ : { content_summary: detail || undefined }),
159
+ },
160
+ });
161
+ if (block.is_error !== true && ["search_replace", "write"].includes(tool.name))
162
+ events.push({
163
+ ...base,
164
+ type: "file_change",
165
+ tool,
166
+ payload: { path: tool.target, tool: tool.name },
167
+ });
168
+ tools.delete(id);
169
+ }
170
+ return events;
171
+ }
172
+ if (obj.type === "error") {
173
+ failed = true;
174
+ return [
175
+ grokFailure({
176
+ ...obj,
177
+ ...object(obj.error),
178
+ message: string(obj.error) || string(object(obj.error).message) || string(obj.message),
179
+ }, sessionId),
180
+ ];
181
+ }
182
+ if (obj.type === "result" || (obj.type === undefined && typeof obj.response === "string")) {
183
+ if (resulted)
184
+ return [];
185
+ resulted = true;
186
+ const events = [];
187
+ // After a vendor error frame the turn has already failed: keep the
188
+ // spend, never a late answer or a second failure.
189
+ if (!failed && (obj.is_error === true || (obj.subtype && obj.subtype !== "success"))) {
190
+ const detail = Array.isArray(obj.errors)
191
+ ? obj.errors.filter((v) => typeof v === "string").join("; ")
192
+ : "";
193
+ events.push(grokFailure({
194
+ ...obj,
195
+ ...object(obj.error),
196
+ message: detail ||
197
+ string(obj.error) ||
198
+ string(obj.result) ||
199
+ `Grok terminal status ${obj.subtype}`,
200
+ }, sessionId));
201
+ }
202
+ else if (!failed) {
203
+ const text = obj.structured_output != null
204
+ ? JSON.stringify(obj.structured_output)
205
+ : string(obj.result) || string(obj.response);
206
+ events.push(text.trim()
207
+ ? { ...base, type: "message", text, final: true, payload: { final_source: "result" } }
208
+ : grokFailure("Grok returned an empty final response", sessionId));
209
+ }
210
+ const usage = resultUsage(obj.usage);
211
+ if (usage)
212
+ events.push({ ...base, type: "usage", usage });
213
+ return events;
214
+ }
215
+ if (obj.type === "stream_event")
216
+ return [];
217
+ return null;
218
+ };
219
+ return { parseEvent, hasTerminal: () => failed || resulted };
220
+ }
221
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGxD,MAAM,MAAM,GAAG,CAAC,KAAc,EAAe,EAAE,CAC7C,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACpF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAEpF;;;;;2DAK2D;AAC3D,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,SAAiB;IAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC;IACjG,MAAM,KAAK,GAAiB;QAC1B,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,SAAS;QACrB,EAAE,EAAE,MAAM,EAAE;QACZ,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;KAC7C,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpD,IACE,IAAI,CAAC,MAAM,KAAK,GAAG;QACnB,IAAI,CAAC,WAAW,KAAK,GAAG;QACxB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AC,GAAG,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBACjD,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,IAAI,EAAE;oBACT,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE;oBACtF,CAAC,CAAC,WAAW,CAAC,uCAAuC,EAAE,SAAS,CAAC,CACpE,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,KAAK;gBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1D,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc;YAAE,OAAO,EAAE,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { HarnessProcessingSpec, PreparedHarnessProcessing } from "@claudexor/core";
2
+ import type { CredentialProfile, HarnessRunSpec } from "@claudexor/schema";
3
+ /**
4
+ * Grok Build exposes no processing tiers, so a preference is reported
5
+ * unavailable. A named grok.com login draws on the subscription's shared
6
+ * weekly allowance (included), but the same pool can continue on purchased
7
+ * Extra Usage Credits or Auto Top Up and no Grok transport reports that debit:
8
+ * cash stays unknown, never an exact zero. `total_cost_usd` is not a receipt.
9
+ */
10
+ export declare function prepareGrokProcessing(spec: Pick<HarnessProcessingSpec, "preference" | "model"> & {
11
+ credentialProfile?: CredentialProfile | null;
12
+ }): PreparedHarnessProcessing;
13
+ /** A direct run prepares itself the same way the engine's gate would. */
14
+ export declare function applyGrokRunProcessing(spec: HarnessRunSpec): HarnessRunSpec;
15
+ //# sourceMappingURL=processing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processing.d.ts","sourceRoot":"","sources":["../src/processing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,IAAI,CAAC,qBAAqB,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG;IAC1D,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC9C,GACA,yBAAyB,CAsB3B;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAQ3E"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Grok Build exposes no processing tiers, so a preference is reported
3
+ * unavailable. A named grok.com login draws on the subscription's shared
4
+ * weekly allowance (included), but the same pool can continue on purchased
5
+ * Extra Usage Credits or Auto Top Up and no Grok transport reports that debit:
6
+ * cash stays unknown, never an exact zero. `total_cost_usd` is not a receipt.
7
+ */
8
+ export function prepareGrokProcessing(spec) {
9
+ const subscription = spec.credentialProfile?.credential_kind === "config_dir_login";
10
+ return {
11
+ model: spec.model,
12
+ receipt: {
13
+ requested: spec.preference ?? null,
14
+ submitted: null,
15
+ submittedNative: null,
16
+ observed: "unknown",
17
+ observedNative: [],
18
+ reason: spec.preference ? "processing_control_unavailable" : null,
19
+ source: "grok_cli_has_no_processing_tiers",
20
+ },
21
+ costBasis: subscription
22
+ ? {
23
+ nativeMode: null,
24
+ kind: "included",
25
+ source: "grok_subscription_allowance",
26
+ debit: "unobserved",
27
+ }
28
+ : { nativeMode: null, kind: "unknown", source: "grok_route_not_subscription" },
29
+ };
30
+ }
31
+ /** A direct run prepares itself the same way the engine's gate would. */
32
+ export function applyGrokRunProcessing(spec) {
33
+ if (spec.processing && spec.processing_cost_basis)
34
+ return spec;
35
+ const prepared = prepareGrokProcessing({
36
+ preference: spec.processing_preference,
37
+ model: spec.model_hint,
38
+ credentialProfile: spec.credential_profile,
39
+ });
40
+ return { ...spec, processing: prepared.receipt, processing_cost_basis: prepared.costBasis };
41
+ }
42
+ //# sourceMappingURL=processing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processing.js","sourceRoot":"","sources":["../src/processing.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAEC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,eAAe,KAAK,kBAAkB,CAAC;IACpF,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE;YACP,SAAS,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI;YAClC,SAAS,EAAE,IAAI;YACf,eAAe,EAAE,IAAI;YACrB,QAAQ,EAAE,SAAS;YACnB,cAAc,EAAE,EAAE;YAClB,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,IAAI;YACjE,MAAM,EAAE,kCAAkC;SAC3C;QACD,SAAS,EAAE,YAAY;YACrB,CAAC,CAAC;gBACE,UAAU,EAAE,IAAI;gBAChB,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,6BAA6B;gBACrC,KAAK,EAAE,YAAY;aACpB;YACH,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,6BAA6B,EAAE;KACjF,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,sBAAsB,CAAC,IAAoB;IACzD,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,qBAAqB;QAAE,OAAO,IAAI,CAAC;IAC/D,MAAM,QAAQ,GAAG,qBAAqB,CAAC;QACrC,UAAU,EAAE,IAAI,CAAC,qBAAqB;QACtC,KAAK,EAAE,IAAI,CAAC,UAAU;QACtB,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;KAC3C,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,OAAO,EAAE,qBAAqB,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CredentialProfile } from "@claudexor/schema";
2
+ type Env = Record<string, string | null | undefined>;
3
+ export declare const GROK_PROFILE_REQUIRED: string;
4
+ export declare function canonicalGrokProfileHome(locator: string): string;
5
+ /** HOME and GROK_HOME must agree for login, models, and execution. The
6
+ * profile HOME is also where Grok keeps its sessions, so one account's native
7
+ * state is shared by every thread that runs on it. */
8
+ export declare function grokProfileEnv(locator: string, env?: Env): Env;
9
+ export declare function grokRouteEnv(profile?: CredentialProfile | null, env?: Env): Env;
10
+ export {};
11
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAmBrD,eAAO,MAAM,qBAAqB,QAEyC,CAAC;AAE5E,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;sDAEsD;AACtD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,GAAQ,GAAG,GAAG,CAYlE;AAED,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,EAAE,GAAG,GAAE,GAAQ,GAAG,GAAG,CAOnF"}
@@ -0,0 +1,50 @@
1
+ import { join } from "node:path";
2
+ import { canonicalIsolationLocator, providerScrubEnv } from "@claudexor/core";
3
+ const MANAGED_ENV = {
4
+ GROK_DISABLE_AUTOUPDATER: "1",
5
+ GROK_CONFIG: null,
6
+ GROK_CONFIG_PATH: null,
7
+ };
8
+ /** The guide documents OIDC and OAuth2 login settings by family; members not
9
+ * named in the shared provider scrub are removed by prefix, from the engine
10
+ * environment and from the run's own env. */
11
+ const LOGIN_SELECTOR_FAMILIES = ["GROK_OIDC_", "GROK_OAUTH2_"];
12
+ function loginSelectorScrub(...sources) {
13
+ const out = {};
14
+ for (const source of sources)
15
+ for (const name of Object.keys(source))
16
+ if (LOGIN_SELECTOR_FAMILIES.some((family) => name.startsWith(family)))
17
+ out[name] = null;
18
+ return out;
19
+ }
20
+ export const GROK_PROFILE_REQUIRED = "Grok has no default credential store; select a named profile (--profile <id>): " +
21
+ "claudexor profiles add grok <id> and claudexor profiles login grok <id>";
22
+ export function canonicalGrokProfileHome(locator) {
23
+ return canonicalIsolationLocator(locator, "credential profile Grok HOME");
24
+ }
25
+ /** HOME and GROK_HOME must agree for login, models, and execution. The
26
+ * profile HOME is also where Grok keeps its sessions, so one account's native
27
+ * state is shared by every thread that runs on it. */
28
+ export function grokProfileEnv(locator, env = {}) {
29
+ if (!locator)
30
+ throw new Error(GROK_PROFILE_REQUIRED);
31
+ const home = canonicalGrokProfileHome(locator);
32
+ return {
33
+ ...env,
34
+ ...providerScrubEnv(),
35
+ ...loginSelectorScrub(process.env, env),
36
+ ...MANAGED_ENV,
37
+ HOME: home,
38
+ USERPROFILE: home,
39
+ GROK_HOME: join(home, ".grok"),
40
+ };
41
+ }
42
+ export function grokRouteEnv(profile, env = {}) {
43
+ if (profile) {
44
+ if (profile.harness_id !== "grok" || profile.credential_kind !== "config_dir_login")
45
+ throw new Error(`credential profile "${profile.profile_id}": Grok requires config_dir_login`);
46
+ return grokProfileEnv(profile.isolation_locator ?? "", env);
47
+ }
48
+ throw new Error(GROK_PROFILE_REQUIRED);
49
+ }
50
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,WAAW,GAAQ;IACvB,wBAAwB,EAAE,GAAG;IAC7B,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF;;6CAE6C;AAC7C,MAAM,uBAAuB,GAAG,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAC/D,SAAS,kBAAkB,CAAC,GAAG,OAAc;IAC3C,MAAM,GAAG,GAAQ,EAAE,CAAC;IACpB,KAAK,MAAM,MAAM,IAAI,OAAO;QAC1B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YACpC,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5F,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,CAAC,MAAM,qBAAqB,GAChC,iFAAiF;IACjF,yEAAyE,CAAC;AAE5E,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,OAAO,yBAAyB,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;AAC5E,CAAC;AAED;;sDAEsD;AACtD,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,GAAG,GAAQ,EAAE;IAC3D,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO;QACL,GAAG,GAAG;QACN,GAAG,gBAAgB,EAAE;QACrB,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;QACvC,GAAG,WAAW;QACd,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAkC,EAAE,GAAG,GAAQ,EAAE;IAC5E,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,UAAU,KAAK,MAAM,IAAI,OAAO,CAAC,eAAe,KAAK,kBAAkB;YACjF,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,CAAC,UAAU,mCAAmC,CAAC,CAAC;QAChG,OAAO,cAAc,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { HarnessEvent } from "@claudexor/schema";
2
+ /** Avoid Windows argv limits and preserve prompt bytes, including newlines. */
3
+ export declare function withGrokPromptFile(prompt: string, run: (path: string) => AsyncIterable<HarnessEvent>): AsyncGenerator<HarnessEvent>;
4
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,+EAA+E;AAC/E,wBAAuB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,aAAa,CAAC,YAAY,CAAC,GACjD,cAAc,CAAC,YAAY,CAAC,CAS9B"}
package/dist/prompt.js ADDED
@@ -0,0 +1,16 @@
1
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ /** Avoid Windows argv limits and preserve prompt bytes, including newlines. */
5
+ export async function* withGrokPromptFile(prompt, run) {
6
+ const directory = mkdtempSync(join(tmpdir(), "claudexor-grok-prompt-"));
7
+ try {
8
+ const path = join(directory, "prompt.txt");
9
+ writeFileSync(path, prompt, { encoding: "utf8", mode: 0o600 });
10
+ yield* run(path);
11
+ }
12
+ finally {
13
+ rmSync(directory, { recursive: true, force: true });
14
+ }
15
+ }
16
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,+EAA+E;AAC/E,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,kBAAkB,CACvC,MAAc,EACd,GAAkD;IAElD,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC;IACxE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC3C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/D,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { HarnessEvent, HarnessRunSpec } from "@claudexor/schema";
2
+ export declare const GROK_STARTUP_REFUSALS: Set<string>;
3
+ /**
4
+ * Reads Grok's own init frame. A scoped run must see exactly its allowed tools
5
+ * under `dontAsk`; any run must not report a credential source other than the
6
+ * recorded session value (configured per-model keys outrank the session token
7
+ * in Grok's resolution order). A refusal stops the process before more output
8
+ * is read; a reported source other than session login is also a typed request
9
+ * refusal, so the engine neither retries nor rotates accounts after it. The
10
+ * source is read first, so a frame that also contradicts the tool policy keeps
11
+ * that stop. A tool-policy contradiction alone is an ordinary failure: another
12
+ * account's own profile configuration can differ. An absent source field
13
+ * leaves the source unknown and says so.
14
+ */
15
+ export declare function createGrokStartupCheck(spec: Pick<HarnessRunSpec, "access">): {
16
+ observe: (raw: unknown, sessionId: string) => {
17
+ refusal?: HarnessEvent;
18
+ note?: HarnessEvent;
19
+ };
20
+ readonly sawInit: boolean;
21
+ readonly sourceConfirmed: boolean;
22
+ };
23
+ /** No init frame at all: neither the scoped tool policy nor the credential
24
+ * source was confirmed by the vendor. Disclosed once, never inferred. */
25
+ export declare function grokNoInitNote(sessionId: string): HarnessEvent;
26
+ //# sourceMappingURL=startup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startup.d.ts","sourceRoot":"","sources":["../src/startup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAWtE,eAAO,MAAM,qBAAqB,aAGhC,CAAC;AAUH;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC;mBAkBlE,OAAO,aACD,MAAM,KAChB;QAAE,OAAO,CAAC,EAAE,YAAY,CAAC;QAAC,IAAI,CAAC,EAAE,YAAY,CAAA;KAAE;;;EA4DnD;AAED;yEACyE;AACzE,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,CAQ9D"}
@@ -0,0 +1,106 @@
1
+ import { nowIso, redactSecrets } from "@claudexor/util";
2
+ /** Init `apiKeySource` for session auth. The bundled guide (1.0.46–1.0.70,
3
+ * `14-headless-mode.md`) defines `user` for API-key auth and `oauth`
4
+ * otherwise; the recorded 1.0.67 streams carry `oauth`. Only `oauth` confirms
5
+ * session login; it rules out an API key but does not name the session's
6
+ * issuer, so it is not proof of grok.com. The guide defers the init line to
7
+ * the first output, so this check detects a paid route after dispatch rather
8
+ * than preventing it. */
9
+ const GROK_SESSION_KEY_SOURCE = "oauth";
10
+ export const GROK_STARTUP_REFUSALS = new Set([
11
+ "grok_access_policy_unconfirmed",
12
+ "grok_credential_source_unconfirmed",
13
+ ]);
14
+ /**
15
+ * Reads Grok's own init frame. A scoped run must see exactly its allowed tools
16
+ * under `dontAsk`; any run must not report a credential source other than the
17
+ * recorded session value (configured per-model keys outrank the session token
18
+ * in Grok's resolution order). A refusal stops the process before more output
19
+ * is read; a reported source other than session login is also a typed request
20
+ * refusal, so the engine neither retries nor rotates accounts after it. The
21
+ * source is read first, so a frame that also contradicts the tool policy keeps
22
+ * that stop. A tool-policy contradiction alone is an ordinary failure: another
23
+ * account's own profile configuration can differ. An absent source field
24
+ * leaves the source unknown and says so.
25
+ */
26
+ export function createGrokStartupCheck(spec) {
27
+ const scoped = spec.access === "readonly" || spec.access === "workspace_write";
28
+ const allowedTools = new Set([
29
+ "read_file",
30
+ "list_dir",
31
+ "grep",
32
+ ...(spec.access === "workspace_write" ? ["search_replace", "write"] : []),
33
+ ]);
34
+ const state = { sawInit: false, sourceConfirmed: false };
35
+ // Neither refusal is a rate limit or a vendor auth verdict.
36
+ const refusal = (code, error, sessionId, extra = {}) => ({
37
+ type: "error",
38
+ session_id: sessionId,
39
+ ts: nowIso(),
40
+ error,
41
+ payload: { code, ...extra },
42
+ });
43
+ function observe(raw, sessionId) {
44
+ const init = raw;
45
+ if (init?.type !== "system" || init.subtype !== "init")
46
+ return {};
47
+ state.sawInit = true;
48
+ const source = init.apiKeySource;
49
+ if (typeof source === "string" && source !== GROK_SESSION_KEY_SOURCE) {
50
+ const reported = redactSecrets(source).slice(0, 80);
51
+ return {
52
+ refusal: {
53
+ ...refusal("grok_credential_source_unconfirmed", `Grok reported credential source "${reported}", not session login ("${GROK_SESSION_KEY_SOURCE}"); a subscription run does not continue on an unverified credential`, sessionId, { reported_source: reported }),
54
+ // Typed, so the engine stops here: every retried or rotated launch
55
+ // could send a paid request before its own init frame is read.
56
+ request_refusal: {
57
+ kind: "credential_source_unconfirmed",
58
+ native_code: "grok_credential_source_unconfirmed",
59
+ source: "grok_init",
60
+ reported_source: reported,
61
+ },
62
+ },
63
+ };
64
+ }
65
+ if (scoped &&
66
+ (!Array.isArray(init.tools) ||
67
+ init.tools.some((tool) => typeof tool !== "string" || !allowedTools.has(tool)) ||
68
+ init.permissionMode !== "dontAsk"))
69
+ return {
70
+ refusal: refusal("grok_access_policy_unconfirmed", "Grok did not confirm the requested scoped tool policy", sessionId),
71
+ };
72
+ state.sourceConfirmed = source === GROK_SESSION_KEY_SOURCE;
73
+ if (state.sourceConfirmed)
74
+ return {};
75
+ return {
76
+ note: {
77
+ type: "status",
78
+ session_id: sessionId,
79
+ ts: nowIso(),
80
+ text: "Grok did not report its credential source; session login is unconfirmed for this run",
81
+ payload: { code: "grok_credential_source_unreported" },
82
+ },
83
+ };
84
+ }
85
+ return {
86
+ observe,
87
+ get sawInit() {
88
+ return state.sawInit;
89
+ },
90
+ get sourceConfirmed() {
91
+ return state.sourceConfirmed;
92
+ },
93
+ };
94
+ }
95
+ /** No init frame at all: neither the scoped tool policy nor the credential
96
+ * source was confirmed by the vendor. Disclosed once, never inferred. */
97
+ export function grokNoInitNote(sessionId) {
98
+ return {
99
+ type: "status",
100
+ session_id: sessionId,
101
+ ts: nowIso(),
102
+ text: "Grok emitted no init frame; its tool policy and credential source were not confirmed",
103
+ payload: { code: "grok_init_missing" },
104
+ };
105
+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rB,EAAE,EAAE,MAAM,EAAE;gBACZ,IAAI,EAAE,sFAAsF;gBAC5F,OAAO,EAAE,EAAE,IAAI,EAAE,mCAAmC,EAAE;aACvD;SACF,CAAC;IACJ,CAAC;IACD,OAAO;QACL,OAAO;QACP,IAAI,OAAO;YACT,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;QACD,IAAI,eAAe;YACjB,OAAO,KAAK,CAAC,eAAe,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC;AAED;yEACyE;AACzE,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,SAAS;QACrB,EAAE,EAAE,MAAM,EAAE;QACZ,IAAI,EAAE,sFAAsF;QAC5F,OAAO,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE;KACvC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@claudexor/harness-grok",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "4.8.1",
4
+ "license": "MIT",
5
+ "description": "Grok Build CLI adapter using grok.com subscription authentication.",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@claudexor/core": "4.8.1",
20
+ "@claudexor/util": "4.8.1",
21
+ "@claudexor/schema": "4.8.1"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/razzant/claudexor.git",
26
+ "directory": "packages/harness-grok"
27
+ },
28
+ "homepage": "https://github.com/razzant/claudexor#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/razzant/claudexor/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=24.15.0"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "devDependencies": {
39
+ "yaml": "^2.9.1"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc",
43
+ "typecheck": "tsc --noEmit"
44
+ }
6
45
  }