@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/LICENSE +21 -0
- package/README.md +189 -2
- package/dist/access.d.ts +5 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +39 -0
- package/dist/access.js.map +1 -0
- package/dist/bin.d.ts +4 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +27 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +321 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +26 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +94 -0
- package/dist/models.js.map +1 -0
- package/dist/parse.d.ts +17 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +221 -0
- package/dist/parse.js.map +1 -0
- package/dist/processing.d.ts +15 -0
- package/dist/processing.d.ts.map +1 -0
- package/dist/processing.js +42 -0
- package/dist/processing.js.map +1 -0
- package/dist/profile.d.ts +11 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +50 -0
- package/dist/profile.js.map +1 -0
- package/dist/prompt.d.ts +4 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +16 -0
- package/dist/prompt.js.map +1 -0
- package/dist/startup.d.ts +26 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +106 -0
- package/dist/startup.js.map +1 -0
- package/package.json +42 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { HarnessUnavailableError, abortSignalFromSpec, effortLadders, effortResolutionEvent, resolveEffortEvidence, runCliHarness, throwIfEffortRejected, } from "@claudexor/core";
|
|
2
|
+
import { HarnessCapabilityProfile, HarnessManifest, ConformanceReport, CredentialProfileStatus, } from "@claudexor/schema";
|
|
3
|
+
import { CLAUDEXOR_VERSION, nowIso, redactSecrets } from "@claudexor/util";
|
|
4
|
+
import { detectGrokVersion, resolveGrokBin } from "./bin.js";
|
|
5
|
+
import { grokAccessArgs } from "./access.js";
|
|
6
|
+
import { GROK_EFFORTS, probeGrokLogin } from "./models.js";
|
|
7
|
+
import { GROK_PROFILE_REQUIRED, grokRouteEnv } from "./profile.js";
|
|
8
|
+
import { createGrokParser, grokFailure } from "./parse.js";
|
|
9
|
+
import { applyGrokRunProcessing, prepareGrokProcessing } from "./processing.js";
|
|
10
|
+
import { withGrokPromptFile } from "./prompt.js";
|
|
11
|
+
import { GROK_STARTUP_REFUSALS, createGrokStartupCheck, grokNoInitNote } from "./startup.js";
|
|
12
|
+
export { resolveGrokBin } from "./bin.js";
|
|
13
|
+
export { canonicalGrokProfileHome, grokProfileEnv } from "./profile.js";
|
|
14
|
+
export const GROK_MANAGED_LOGIN = { stdin: "none" };
|
|
15
|
+
const INTENTS = [
|
|
16
|
+
"explain",
|
|
17
|
+
"audit",
|
|
18
|
+
"plan",
|
|
19
|
+
"spec",
|
|
20
|
+
"implement",
|
|
21
|
+
"repair",
|
|
22
|
+
"create_from_scratch",
|
|
23
|
+
"review",
|
|
24
|
+
"verify",
|
|
25
|
+
"synthesize",
|
|
26
|
+
];
|
|
27
|
+
export const GROK_CAPABILITY_PROFILE = HarnessCapabilityProfile.parse({
|
|
28
|
+
auth: {
|
|
29
|
+
supported_sources: ["native_session"],
|
|
30
|
+
preferred_source: "native_session",
|
|
31
|
+
credential_transports: [
|
|
32
|
+
{ source: "native_session", kind: "config_file", relocatable_by: ["HOME"] },
|
|
33
|
+
],
|
|
34
|
+
managed_login: GROK_MANAGED_LOGIN,
|
|
35
|
+
},
|
|
36
|
+
access_control: {
|
|
37
|
+
readonly_mechanism: "tool_allowlist",
|
|
38
|
+
write_mechanism: "tool_policy",
|
|
39
|
+
auxiliary_writable_roots: false,
|
|
40
|
+
},
|
|
41
|
+
isolation: { supported_containment: ["env_or_file_injection"] },
|
|
42
|
+
attachment_inputs: [],
|
|
43
|
+
});
|
|
44
|
+
const defaults = {
|
|
45
|
+
detectVersion: detectGrokVersion,
|
|
46
|
+
probeLogin: probeGrokLogin,
|
|
47
|
+
runCli: runCliHarness,
|
|
48
|
+
};
|
|
49
|
+
async function doctor(spec, runtime) {
|
|
50
|
+
const version = await runtime.detectVersion();
|
|
51
|
+
const supported = spec.authSource === undefined || spec.authSource === "native_session";
|
|
52
|
+
// Harness-level doctor has no account identity. Only a named profile probe
|
|
53
|
+
// may verify credentials; never probe the operator's ordinary ~/.grok.
|
|
54
|
+
const detail = !supported || spec.authPreference === "api_key"
|
|
55
|
+
? "Grok supports only grok.com subscription login"
|
|
56
|
+
: version
|
|
57
|
+
? GROK_PROFILE_REQUIRED
|
|
58
|
+
: "Grok CLI is unavailable";
|
|
59
|
+
return ConformanceReport.parse({
|
|
60
|
+
harness_id: "grok",
|
|
61
|
+
status: "unavailable",
|
|
62
|
+
checks: [
|
|
63
|
+
{
|
|
64
|
+
id: "installed",
|
|
65
|
+
status: version ? "pass" : "fail",
|
|
66
|
+
detail: version ?? "grok not found; set CLAUDEXOR_GROK_BIN",
|
|
67
|
+
},
|
|
68
|
+
{ id: "default_credential", status: "fail", detail },
|
|
69
|
+
],
|
|
70
|
+
enabled_intents: [],
|
|
71
|
+
disabled_intents: INTENTS,
|
|
72
|
+
reasons: [detail],
|
|
73
|
+
auth_sources: [
|
|
74
|
+
{
|
|
75
|
+
source: spec.authSource ?? "native_session",
|
|
76
|
+
availability: "unavailable",
|
|
77
|
+
verification: "not_run",
|
|
78
|
+
detail,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** A probe that threw decided nothing about the login. */
|
|
84
|
+
async function probeOrUnknown(runtime, env, abortSignal) {
|
|
85
|
+
try {
|
|
86
|
+
return await runtime.probeLogin(env, abortSignal);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const reason = redactSecrets(error instanceof Error ? error.message : String(error));
|
|
90
|
+
return {
|
|
91
|
+
authenticated: false,
|
|
92
|
+
models: [],
|
|
93
|
+
failed: true,
|
|
94
|
+
detail: `Grok login probe failed (${reason.slice(0, 200)}); login state is unknown`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Vendor answer -> account status. Only an explicit vendor refusal fails
|
|
99
|
+
* verification; an inconclusive probe never condemns the credential. */
|
|
100
|
+
async function probeCredentialProfile(profile, runtime, abortSignal) {
|
|
101
|
+
const base = { profile_id: profile.profile_id, harness_id: "grok" };
|
|
102
|
+
let env;
|
|
103
|
+
try {
|
|
104
|
+
env = grokRouteEnv(profile);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return CredentialProfileStatus.parse({
|
|
108
|
+
...base,
|
|
109
|
+
availability: "unavailable",
|
|
110
|
+
verification: "not_run",
|
|
111
|
+
detail: redactSecrets(error instanceof Error ? error.message : String(error)).slice(0, 300),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const probe = await probeOrUnknown(runtime, env, abortSignal);
|
|
115
|
+
if (probe.authenticated)
|
|
116
|
+
return CredentialProfileStatus.parse({
|
|
117
|
+
...base,
|
|
118
|
+
availability: "available",
|
|
119
|
+
verification: "passed",
|
|
120
|
+
verification_source: "vendor",
|
|
121
|
+
last_verified_at: nowIso(),
|
|
122
|
+
detail: probe.detail,
|
|
123
|
+
});
|
|
124
|
+
return CredentialProfileStatus.parse({
|
|
125
|
+
...base,
|
|
126
|
+
availability: probe.failed ? "unknown" : "unavailable",
|
|
127
|
+
verification: probe.failed ? "not_run" : "failed",
|
|
128
|
+
...(probe.failed ? {} : { verification_source: "vendor" }),
|
|
129
|
+
detail: probe.detail,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** The HOME the vendor child receives: the named profile's own HOME. */
|
|
133
|
+
function grokChildHome(spec) {
|
|
134
|
+
try {
|
|
135
|
+
return grokRouteEnv(spec.credential_profile).HOME ?? null;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export function createGrokAdapter(deps = {}) {
|
|
142
|
+
const runtime = { ...defaults, ...deps };
|
|
143
|
+
async function* stamped(input) {
|
|
144
|
+
const spec = applyGrokRunProcessing(input);
|
|
145
|
+
for await (const event of withGrokPromptFile(spec.prompt, (path) => runGrok(spec, runtime, path))) {
|
|
146
|
+
// The route is the one selected before spawn; the source is stamped by
|
|
147
|
+
// runGrok only once Grok's own init confirmed it.
|
|
148
|
+
event.credential_route = "vendor_native";
|
|
149
|
+
if (spec.credential_profile)
|
|
150
|
+
event.credential_profile_id = spec.credential_profile.profile_id;
|
|
151
|
+
event.processing = spec.processing;
|
|
152
|
+
event.processing_cost_basis = spec.processing_cost_basis;
|
|
153
|
+
yield event;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
id: "grok",
|
|
158
|
+
effortParameter: "--reasoning-effort",
|
|
159
|
+
capabilityProfile: GROK_CAPABILITY_PROFILE,
|
|
160
|
+
nativeHomeLifetime: {
|
|
161
|
+
status: "not_pruned",
|
|
162
|
+
reason: "Grok session pruning has no independently verified contract",
|
|
163
|
+
},
|
|
164
|
+
async discover() {
|
|
165
|
+
const version = await runtime.detectVersion();
|
|
166
|
+
if (!version)
|
|
167
|
+
throw new HarnessUnavailableError("grok not found (install Grok Build or set CLAUDEXOR_GROK_BIN)");
|
|
168
|
+
return HarnessManifest.parse({
|
|
169
|
+
id: "grok",
|
|
170
|
+
display_name: "Grok Build",
|
|
171
|
+
kind: "local_cli",
|
|
172
|
+
version,
|
|
173
|
+
adapter_version: CLAUDEXOR_VERSION,
|
|
174
|
+
provider_family: "xai",
|
|
175
|
+
capabilities: {
|
|
176
|
+
plan: true,
|
|
177
|
+
implement: true,
|
|
178
|
+
create_from_scratch: true,
|
|
179
|
+
review: true,
|
|
180
|
+
verify: true,
|
|
181
|
+
synthesize: true,
|
|
182
|
+
read_files: true,
|
|
183
|
+
browser_tool: false,
|
|
184
|
+
max_turns: true,
|
|
185
|
+
web_policy: "native",
|
|
186
|
+
effort_levels: GROK_EFFORTS,
|
|
187
|
+
effort_levels_verified_against: "1.0.46",
|
|
188
|
+
// Account inventories need a named profile; an unscoped query has
|
|
189
|
+
// no account to run `grok models` under and claims no live list.
|
|
190
|
+
model_inventory_routes: ["local_session"],
|
|
191
|
+
model_inventory_absence: "advisory",
|
|
192
|
+
json_schema_output: true,
|
|
193
|
+
work_report_transport: "unsupported",
|
|
194
|
+
},
|
|
195
|
+
capability_profile: GROK_CAPABILITY_PROFILE,
|
|
196
|
+
auth_modes: ["local_session"],
|
|
197
|
+
access_profiles_supported: ["readonly", "workspace_write", "full", "inherit_native"],
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
doctor: (spec) => doctor(spec, runtime),
|
|
201
|
+
probeCredentialProfile: (profile, signal) => probeCredentialProfile(profile, runtime, signal),
|
|
202
|
+
async models(spec) {
|
|
203
|
+
if (spec?.authPreference === "api_key")
|
|
204
|
+
return [];
|
|
205
|
+
try {
|
|
206
|
+
const probe = await runtime.probeLogin(grokRouteEnv(spec?.credentialProfile, spec?.env), spec?.abortSignal);
|
|
207
|
+
return probe.authenticated ? probe.models : [];
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
async prepareProcessing(spec) {
|
|
214
|
+
return prepareGrokProcessing(spec);
|
|
215
|
+
},
|
|
216
|
+
childHome: grokChildHome,
|
|
217
|
+
run: stamped,
|
|
218
|
+
review: stamped,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/** Typed retryable refusal: a probe that could not decide is not a logout. */
|
|
222
|
+
function inconclusiveLogin(spec, detail, timedOut) {
|
|
223
|
+
const ts = nowIso();
|
|
224
|
+
return [
|
|
225
|
+
{
|
|
226
|
+
type: "error",
|
|
227
|
+
session_id: spec.session_id,
|
|
228
|
+
ts,
|
|
229
|
+
error: detail,
|
|
230
|
+
transient: { kind: timedOut ? "timeout" : "unknown", retry_delay_ms: null },
|
|
231
|
+
payload: { code: "grok_login_probe_inconclusive" },
|
|
232
|
+
},
|
|
233
|
+
{ type: "completed", session_id: spec.session_id, ts },
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
async function* runGrok(spec, runtime, promptPath) {
|
|
237
|
+
if (spec.auth_preference === "api_key")
|
|
238
|
+
throw new HarnessUnavailableError("Grok Build requires grok.com subscription authentication");
|
|
239
|
+
let env;
|
|
240
|
+
try {
|
|
241
|
+
env = grokRouteEnv(spec.credential_profile, spec.env);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
throw new HarnessUnavailableError(`Grok credential profile is missing or invalid. ${GROK_PROFILE_REQUIRED}`);
|
|
245
|
+
}
|
|
246
|
+
const abortSignal = abortSignalFromSpec(spec);
|
|
247
|
+
const probe = await probeOrUnknown(runtime, env, abortSignal);
|
|
248
|
+
if (abortSignal?.aborted) {
|
|
249
|
+
yield { type: "completed", session_id: spec.session_id, ts: nowIso(), aborted: true };
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!probe.authenticated && probe.failed) {
|
|
253
|
+
yield* inconclusiveLogin(spec, probe.detail, probe.timedOut === true);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!probe.authenticated)
|
|
257
|
+
throw new HarnessUnavailableError(probe.detail);
|
|
258
|
+
// The shared order places preferences outside the recorded ladder
|
|
259
|
+
// (max/ultra downward, none/minimal at the floor); unknown words still fail.
|
|
260
|
+
const effort = resolveEffortEvidence(spec.effort_hint, GROK_EFFORTS, effortLadders([GROK_EFFORTS]), "versioned_snapshot", "--reasoning-effort");
|
|
261
|
+
yield effortResolutionEvent(spec.session_id, effort);
|
|
262
|
+
throwIfEffortRejected(effort);
|
|
263
|
+
const args = [
|
|
264
|
+
"--no-auto-update",
|
|
265
|
+
"--prompt-file",
|
|
266
|
+
promptPath,
|
|
267
|
+
"--cwd",
|
|
268
|
+
spec.cwd,
|
|
269
|
+
"--output-format",
|
|
270
|
+
"streaming-messages-json",
|
|
271
|
+
...grokAccessArgs(spec),
|
|
272
|
+
];
|
|
273
|
+
if (spec.instructions)
|
|
274
|
+
args.push("--rules", spec.instructions);
|
|
275
|
+
if (spec.model_hint)
|
|
276
|
+
args.push("-m", spec.model_hint);
|
|
277
|
+
if (effort.submitted)
|
|
278
|
+
args.push("--reasoning-effort", effort.submitted);
|
|
279
|
+
if (spec.max_turns !== null)
|
|
280
|
+
args.push("--max-turns", String(spec.max_turns));
|
|
281
|
+
if (spec.output_schema)
|
|
282
|
+
args.push("--json-schema", JSON.stringify(spec.output_schema));
|
|
283
|
+
if (spec.resume_session_id)
|
|
284
|
+
args.push("--resume", spec.resume_session_id);
|
|
285
|
+
if (spec.tool_permission_policy.web === "off" || spec.external_context_policy === "off") {
|
|
286
|
+
args.push("--disable-web-search");
|
|
287
|
+
// web_fetch has its own vendor switch; an inherited GROK_WEB_FETCH=1 must
|
|
288
|
+
// not re-enable it under `full`. Access stays exactly as requested.
|
|
289
|
+
env = { ...env, GROK_WEB_FETCH: "0" };
|
|
290
|
+
}
|
|
291
|
+
const parser = createGrokParser();
|
|
292
|
+
const startup = createGrokStartupCheck(spec);
|
|
293
|
+
for await (const event of runtime.runCli({
|
|
294
|
+
bin: resolveGrokBin(),
|
|
295
|
+
args,
|
|
296
|
+
spec,
|
|
297
|
+
env,
|
|
298
|
+
label: "grok",
|
|
299
|
+
redact: redactSecrets,
|
|
300
|
+
parseEvent: (raw, id) => {
|
|
301
|
+
const verdict = startup.observe(raw, id);
|
|
302
|
+
if (verdict.refusal)
|
|
303
|
+
return [verdict.refusal];
|
|
304
|
+
const events = parser.parseEvent(raw, id);
|
|
305
|
+
return events && verdict.note ? [...events, verdict.note] : events;
|
|
306
|
+
},
|
|
307
|
+
stopAfterEvent: (event) => GROK_STARTUP_REFUSALS.has(String(event.payload?.code)),
|
|
308
|
+
parseStderrFailure: (stderr, id) => grokFailure(stderr, id),
|
|
309
|
+
})) {
|
|
310
|
+
if (event.type === "completed" && event.payload?.exit_code === 0) {
|
|
311
|
+
if (!startup.sawInit)
|
|
312
|
+
yield grokNoInitNote(spec.session_id);
|
|
313
|
+
if (!parser.hasTerminal())
|
|
314
|
+
yield grokFailure("Grok exited without a terminal result", spec.session_id);
|
|
315
|
+
}
|
|
316
|
+
if (startup.sourceConfirmed)
|
|
317
|
+
event.credential_source = "native_session";
|
|
318
|
+
yield event;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,uBAAuB,GAIxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBA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AC;YAC5D,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;gBACvB,MAAM,WAAW,CAAC,uCAAuC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,OAAO,CAAC,eAAe;YAAE,KAAK,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;QACxE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type EnvMap } from "@claudexor/core";
|
|
2
|
+
import type { HarnessModel } from "@claudexor/schema";
|
|
3
|
+
export declare const GROK_EFFORTS: readonly ["low", "medium", "high", "xhigh"];
|
|
4
|
+
/** `failed` means the probe could not decide: login state unknown, never a
|
|
5
|
+
* refusal. `failed: false` without `authenticated` is a definite vendor
|
|
6
|
+
* refusal, which this probe never reports: no logged-out transcript of
|
|
7
|
+
* `grok models` is recorded, and generic auth words may come from a proxy or
|
|
8
|
+
* backend, not from this account. */
|
|
9
|
+
export interface GrokLoginProbe {
|
|
10
|
+
authenticated: boolean;
|
|
11
|
+
models: HarnessModel[];
|
|
12
|
+
detail: string;
|
|
13
|
+
failed?: boolean;
|
|
14
|
+
/** The probe's own budget ended it before the CLI answered. */
|
|
15
|
+
timedOut?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function parseGrokModels(text: string): HarnessModel[];
|
|
18
|
+
/**
|
|
19
|
+
* `grok models` in the exact profile env is the login proof; the profile's
|
|
20
|
+
* private file store is never an oracle. A normal exit that prints the
|
|
21
|
+
* grok.com login line verifies the login. Every other end (spawn error, signal,
|
|
22
|
+
* own timeout, cancellation, forced drain, nonzero exit, any other text) leaves
|
|
23
|
+
* the login unknown. Raw output never leaves here.
|
|
24
|
+
*/
|
|
25
|
+
export declare function probeGrokLogin(env: EnvMap, abortSignal?: AbortSignal, budgetMs?: number): Promise<GrokLoginProbe>;
|
|
26
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,eAAO,MAAM,YAAY,YAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAYxE;;;;qCAIqC;AACrC,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAY5D;AAUD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,WAAW,EACzB,QAAQ,GAAE,MAAoC,GAC7C,OAAO,CAAC,cAAc,CAAC,CAoDzB"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { runCapture } from "@claudexor/core";
|
|
2
|
+
import { redactSecrets } from "@claudexor/util";
|
|
3
|
+
import { resolveGrokBin } from "./bin.js";
|
|
4
|
+
export const GROK_EFFORTS = ["low", "medium", "high", "xhigh"];
|
|
5
|
+
/** Budget of one `grok models` login probe, enforced by a timer the probe owns. */
|
|
6
|
+
const GROK_LOGIN_PROBE_TIMEOUT_MS = 20_000;
|
|
7
|
+
/** The grok.com login line this probe requires. The CLI binaries (1.0.46 to
|
|
8
|
+
* 1.0.70) contain only the prefix `You are logged in with ` and fill in the
|
|
9
|
+
* login at runtime, and no `grok models` transcript is recorded, so the line is
|
|
10
|
+
* an expectation, not an observation. Only the whole line verifies: another
|
|
11
|
+
* login, such as an enterprise identity provider or a value that merely starts
|
|
12
|
+
* with `grok.com`, or another format leaves the login unknown. */
|
|
13
|
+
const GROK_COM_LOGIN = /^[ \t]*You are logged in with grok\.com\.[ \t]*\r?$/im;
|
|
14
|
+
export function parseGrokModels(text) {
|
|
15
|
+
const models = new Set();
|
|
16
|
+
for (const line of text.split(/\r?\n/)) {
|
|
17
|
+
const match = /^\s*[-*]\s+(grok-[A-Za-z0-9._-]+)(?:\s|$)/.exec(line);
|
|
18
|
+
if (match)
|
|
19
|
+
models.add(match[1]);
|
|
20
|
+
}
|
|
21
|
+
return [...models].map((id) => ({
|
|
22
|
+
id,
|
|
23
|
+
label: null,
|
|
24
|
+
context_window: null,
|
|
25
|
+
routes: ["local_session"],
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const unknownLogin = (detail, timedOut = false, hint = "") => ({
|
|
29
|
+
authenticated: false,
|
|
30
|
+
models: [],
|
|
31
|
+
detail: `${detail}; login state is unknown${hint}`,
|
|
32
|
+
failed: true,
|
|
33
|
+
...(timedOut ? { timedOut: true } : {}),
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* `grok models` in the exact profile env is the login proof; the profile's
|
|
37
|
+
* private file store is never an oracle. A normal exit that prints the
|
|
38
|
+
* grok.com login line verifies the login. Every other end (spawn error, signal,
|
|
39
|
+
* own timeout, cancellation, forced drain, nonzero exit, any other text) leaves
|
|
40
|
+
* the login unknown. Raw output never leaves here.
|
|
41
|
+
*/
|
|
42
|
+
export async function probeGrokLogin(env, abortSignal, budgetMs = GROK_LOGIN_PROBE_TIMEOUT_MS) {
|
|
43
|
+
const budget = new AbortController();
|
|
44
|
+
// First observed end cause: a child that exited before the timer is not a timeout.
|
|
45
|
+
const first = {
|
|
46
|
+
cause: abortSignal?.aborted ? "cancel" : null,
|
|
47
|
+
};
|
|
48
|
+
const onCancel = () => {
|
|
49
|
+
first.cause ??= "cancel";
|
|
50
|
+
};
|
|
51
|
+
abortSignal?.addEventListener("abort", onCancel, { once: true });
|
|
52
|
+
const timer = setTimeout(() => {
|
|
53
|
+
first.cause ??= "timeout";
|
|
54
|
+
budget.abort();
|
|
55
|
+
}, budgetMs);
|
|
56
|
+
let result;
|
|
57
|
+
try {
|
|
58
|
+
result = await runCapture(resolveGrokBin(), ["models"], {
|
|
59
|
+
env,
|
|
60
|
+
abortSignal: abortSignal ? AbortSignal.any([abortSignal, budget.signal]) : budget.signal,
|
|
61
|
+
cancelSignal: "SIGTERM",
|
|
62
|
+
onExit: () => {
|
|
63
|
+
first.cause ??= "exit";
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const reason = redactSecrets(error instanceof Error ? error.message : String(error));
|
|
69
|
+
return unknownLogin(`Grok login probe could not run (${reason.slice(0, 200)})`);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
abortSignal?.removeEventListener("abort", onCancel);
|
|
74
|
+
}
|
|
75
|
+
if (first.cause === "timeout")
|
|
76
|
+
return unknownLogin(`grok models did not answer within ${budgetMs / 1000}s`, true);
|
|
77
|
+
if (first.cause === "cancel")
|
|
78
|
+
return unknownLogin("Grok login probe was cancelled");
|
|
79
|
+
if (result.signal !== null || result.code === null)
|
|
80
|
+
return unknownLogin(`grok models ended by ${result.signal ?? "an unknown cause"}`);
|
|
81
|
+
if (result.drain === "truncated")
|
|
82
|
+
return unknownLogin("grok models output was truncated by a process that kept it open");
|
|
83
|
+
const text = `${result.stdout}\n${result.stderr}`;
|
|
84
|
+
if (result.code === 0 && GROK_COM_LOGIN.test(text))
|
|
85
|
+
return {
|
|
86
|
+
authenticated: true,
|
|
87
|
+
models: parseGrokModels(text),
|
|
88
|
+
detail: "Grok CLI reported a grok.com login",
|
|
89
|
+
};
|
|
90
|
+
return unknownLogin(result.code === 0
|
|
91
|
+
? "grok models did not confirm a grok.com login"
|
|
92
|
+
: `grok models failed (exit ${result.code})`, false, " (a profile that was never signed in needs claudexor profiles login grok <id>)");
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmC,MAAM,iBAAiB,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AACxE,mFAAmF;AACnF,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAE3C;;;;;kEAKkE;AAClE,MAAM,cAAc,GAAG,uDAAuD,CAAC;AAgB/E,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,2CAA2C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrE,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9B,EAAE;QACF,KAAK,EAAE,IAAI;QACX,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,CAAC,eAAe,CAAC;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,QAAQ,GAAG,KAAK,EAAE,IAAI,GAAG,EAAE,EAAkB,EAAE,CAAC,CAAC;IACrF,aAAa,EAAE,KAA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YAAY,CACjB,MAAM,CAAC,IAAI,KAAK,CAAC;QACf,CAAC,CAAC,8CAA8C;QAChD,CAAC,CAAC,4BAA4B,MAAM,CAAC,IAAI,GAAG,EAC9C,KAAK,EACL,gFAAgF,CACjF,CAAC;AACJ,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HarnessEvent } from "@claudexor/schema";
|
|
2
|
+
/** Only vendor failure channels call this classifier; assistant prose never does.
|
|
3
|
+
* It types quota and rate limits only. Grok documents no authentication error
|
|
4
|
+
* code and refreshes and retries a 401 itself, and a proxy or backend can
|
|
5
|
+
* print the same words, so no text or code becomes an authentication verdict:
|
|
6
|
+
* such a failure stays untyped and never marks the account unusable. Login
|
|
7
|
+
* readiness belongs to the pre-run `grok models` probe. */
|
|
8
|
+
export declare function grokFailure(value: unknown, sessionId: string): HarnessEvent;
|
|
9
|
+
/** Messages JSON is Claude-shaped, but usage/finality belong to Grok's result,
|
|
10
|
+
* never to intermediate assistant messages or tool-result text. A top-level
|
|
11
|
+
* error frame fails the turn; a result that still follows contributes only its
|
|
12
|
+
* aggregate usage, so spend is counted once and no answer is manufactured. */
|
|
13
|
+
export declare function createGrokParser(): {
|
|
14
|
+
parseEvent: (raw: unknown, sessionId: string) => HarnessEvent[] | null;
|
|
15
|
+
hasTerminal: () => boolean;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAW,MAAM,mBAAmB,CAAC;AAQ/D;;;;;2DAK2D;AAC3D,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,YAAY,CA+B3E;AA2CD;;;8EAG8E;AAC9E,wBAAgB,gBAAgB;sBAIL,OAAO,aAAa,MAAM,KAAG,YAAY,EAAE,GAAG,IAAI;;EA+I5E"}
|