@codexhost/cli-linux-arm64 0.18.0 → 0.19.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.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +59 -2
- package/app/console-web.js +76 -4
- package/app/desktop-controller.mjs +274 -11
- package/app/host-runtime.mjs +12322 -2469
- package/app/plugins/antigravity/plugin.mjs +654 -216
- package/app/plugins/claude-code/plugin.mjs +138 -11
- package/app/plugins/codebuddy/plugin.mjs +152 -20
- package/app/plugins/codex-usage/plugin.mjs +59 -2
- package/app/plugins/copilot/plugin.mjs +59 -2
- package/app/plugins/cursor-cli/plugin.mjs +134 -12
- package/app/plugins/deepseek-harness/manifest.json +2 -2
- package/app/plugins/deepseek-harness/plugin.mjs +86 -7
- package/app/plugins/devin/plugin.mjs +59 -2
- package/app/plugins/grok/plugin.mjs +392 -269
- package/app/plugins/hermes/plugin.mjs +138 -14
- package/app/plugins/kimi-code/plugin.mjs +59 -2
- package/app/plugins/kiro-cli/plugin.mjs +287 -18
- package/app/plugins/omp/plugin.mjs +788 -627
- package/app/plugins/opencode/plugin.mjs +59 -2
- package/app/plugins/pi/plugin.mjs +899 -773
- package/app/plugins/qoder/plugin.mjs +61 -6
- package/app/plugins/qoder-cn/plugin.mjs +61 -6
- package/app/plugins/qwen-code/plugin.mjs +168 -94
- package/app/plugins/workbuddy/plugin.mjs +152 -20
- package/app/plugins/zcode/plugin.mjs +132 -5
- package/app/renderer-extension.js +657 -270
- package/app/web/assets/index-BNQIOOHE.css +1 -0
- package/app/web/assets/index-Feo4BkqN.js +199 -0
- package/app/web/codexhost-settings.js +76 -4
- package/app/web/index.html +2 -2
- package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +8 -8
- package/app/web/plugins/deepseek-ai__dsh-client-file-upload/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-locale/client.js +3 -3
- package/app/web/plugins/deepseek-ai__dsh-client-ui-attachment/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +129 -8
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +65 -63
- package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +95 -93
- package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.excel.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-files/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +16 -16
- package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +11 -11
- package/app/web-modules/server.mjs +2339 -1514
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
- package/app/web/assets/index-C0aXz2jD.js +0 -199
- package/app/web/assets/index-C3lniEH1.css +0 -1
|
@@ -372,239 +372,6 @@ function createHarnessInstaller(environment, source) {
|
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
// dist/usage-statistics.js
|
|
376
|
-
import os2 from "node:os";
|
|
377
|
-
import path5 from "node:path";
|
|
378
|
-
import { readFile } from "node:fs/promises";
|
|
379
|
-
|
|
380
|
-
// ../../harness-adapter/dist/usage-statistics.js
|
|
381
|
-
import { createReadStream } from "node:fs";
|
|
382
|
-
import { lstat, opendir } from "node:fs/promises";
|
|
383
|
-
import path4 from "node:path";
|
|
384
|
-
import { createInterface } from "node:readline";
|
|
385
|
-
var MAX_SESSION_ID_LENGTH = 512;
|
|
386
|
-
var MAX_CWD_LENGTH = 4096;
|
|
387
|
-
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
388
|
-
function usageSessionTitle(value) {
|
|
389
|
-
if (typeof value !== "string")
|
|
390
|
-
return void 0;
|
|
391
|
-
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
392
|
-
if (!normalized)
|
|
393
|
-
return void 0;
|
|
394
|
-
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
395
|
-
return normalized;
|
|
396
|
-
let title = "";
|
|
397
|
-
for (const character of normalized) {
|
|
398
|
-
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
399
|
-
break;
|
|
400
|
-
title += character;
|
|
401
|
-
}
|
|
402
|
-
return `${title.trimEnd()}…`;
|
|
403
|
-
}
|
|
404
|
-
function sessionIdOk(value) {
|
|
405
|
-
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
406
|
-
}
|
|
407
|
-
function cwdOk(value) {
|
|
408
|
-
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
409
|
-
}
|
|
410
|
-
function withUsageSession(entry, session) {
|
|
411
|
-
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
412
|
-
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
413
|
-
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
414
|
-
if (sessionId === void 0 && cwd === void 0)
|
|
415
|
-
return entry;
|
|
416
|
-
return {
|
|
417
|
-
...entry,
|
|
418
|
-
...sessionId !== void 0 ? { sessionId } : {},
|
|
419
|
-
...cwd !== void 0 ? { cwd } : {},
|
|
420
|
-
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
async function jsonlUsageSources(root, maxDepth, signal) {
|
|
424
|
-
const sources = [];
|
|
425
|
-
const visit = async (directory, depth) => {
|
|
426
|
-
signal.throwIfAborted();
|
|
427
|
-
const entries = await opendir(directory).catch((error53) => {
|
|
428
|
-
if (error53.code === "ENOENT")
|
|
429
|
-
return null;
|
|
430
|
-
throw error53;
|
|
431
|
-
});
|
|
432
|
-
if (!entries)
|
|
433
|
-
return;
|
|
434
|
-
for await (const entry of entries) {
|
|
435
|
-
signal.throwIfAborted();
|
|
436
|
-
const file2 = path4.join(directory, entry.name);
|
|
437
|
-
if (entry.isDirectory()) {
|
|
438
|
-
if (depth < maxDepth)
|
|
439
|
-
await visit(file2, depth + 1);
|
|
440
|
-
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
441
|
-
const info = await lstat(file2).catch(() => null);
|
|
442
|
-
if (info?.isFile() && info.size > 0) {
|
|
443
|
-
sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
await visit(root, 0);
|
|
449
|
-
return sources;
|
|
450
|
-
}
|
|
451
|
-
async function* jsonlRecords(file2, marker, signal) {
|
|
452
|
-
const lines = createInterface({
|
|
453
|
-
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
454
|
-
crlfDelay: Infinity
|
|
455
|
-
});
|
|
456
|
-
for await (const line of lines) {
|
|
457
|
-
if (!line.includes(marker))
|
|
458
|
-
continue;
|
|
459
|
-
let value;
|
|
460
|
-
try {
|
|
461
|
-
value = JSON.parse(line);
|
|
462
|
-
} catch {
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
466
|
-
yield value;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function nativeTimeMs(value) {
|
|
471
|
-
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
472
|
-
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// dist/usage-statistics.js
|
|
476
|
-
function isRecord(value) {
|
|
477
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
478
|
-
}
|
|
479
|
-
var USD_TICKS = 1e10;
|
|
480
|
-
function count(value) {
|
|
481
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
482
|
-
}
|
|
483
|
-
function grokHome(environment) {
|
|
484
|
-
return environment.GROK_HOME || path5.join(environment.HOME || os2.homedir(), ".grok");
|
|
485
|
-
}
|
|
486
|
-
async function grokSummary(directory) {
|
|
487
|
-
try {
|
|
488
|
-
const summary = JSON.parse(await readFile(path5.join(directory, "summary.json"), "utf8"));
|
|
489
|
-
if (!isRecord(summary))
|
|
490
|
-
return { forkedAt: null };
|
|
491
|
-
const title = usageSessionTitle(summary.generated_title) ?? usageSessionTitle(summary.session_summary);
|
|
492
|
-
return {
|
|
493
|
-
forkedAt: typeof summary.parent_session_id === "string" ? nativeTimeMs(summary.created_at) : null,
|
|
494
|
-
...title ? { title } : {}
|
|
495
|
-
};
|
|
496
|
-
} catch {
|
|
497
|
-
return { forkedAt: null };
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function grokSession(file2) {
|
|
501
|
-
const directory = path5.dirname(file2);
|
|
502
|
-
let cwd;
|
|
503
|
-
try {
|
|
504
|
-
cwd = decodeURIComponent(path5.basename(path5.dirname(directory)));
|
|
505
|
-
} catch {
|
|
506
|
-
cwd = void 0;
|
|
507
|
-
}
|
|
508
|
-
return { sessionId: path5.basename(directory), cwd };
|
|
509
|
-
}
|
|
510
|
-
async function readGrokUsage(file2, signal) {
|
|
511
|
-
const summary = await grokSummary(path5.dirname(file2));
|
|
512
|
-
const forkedAt = summary.forkedAt;
|
|
513
|
-
let title = summary.title;
|
|
514
|
-
const session = grokSession(file2);
|
|
515
|
-
const entries = [];
|
|
516
|
-
for await (const line of jsonlRecords(file2, '"sessionUpdate"', signal)) {
|
|
517
|
-
const params = isRecord(line.params) ? line.params : {};
|
|
518
|
-
const update = isRecord(params.update) ? params.update : {};
|
|
519
|
-
if (!title && update.sessionUpdate === "user_message_chunk") {
|
|
520
|
-
title = usageSessionTitle(isRecord(update.content) ? update.content.text : void 0);
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
const usage = isRecord(update.usage) ? update.usage : {};
|
|
524
|
-
if (update.sessionUpdate !== "turn_completed" || typeof update.prompt_id !== "string")
|
|
525
|
-
continue;
|
|
526
|
-
const meta3 = isRecord(params._meta) ? params._meta : {};
|
|
527
|
-
const at = nativeTimeMs(meta3.agentTimestampMs) ?? (typeof line.timestamp === "number" ? nativeTimeMs(line.timestamp * 1e3) : null);
|
|
528
|
-
if (at === null || forkedAt !== null && at <= forkedAt)
|
|
529
|
-
continue;
|
|
530
|
-
for (const [model2, value] of Object.entries(isRecord(usage.modelUsage) ? usage.modelUsage : {})) {
|
|
531
|
-
if (!isRecord(value))
|
|
532
|
-
continue;
|
|
533
|
-
const input = count(value.inputTokens);
|
|
534
|
-
const output = count(value.outputTokens);
|
|
535
|
-
const cached2 = count(value.cachedReadTokens);
|
|
536
|
-
const written = count(value.cacheCreationTokens ?? 0);
|
|
537
|
-
const reasoning = count(value.reasoningTokens);
|
|
538
|
-
const ticks = count(value.costUsdTicks);
|
|
539
|
-
if (input === null || output === null || value.totalTokens !== input + output)
|
|
540
|
-
continue;
|
|
541
|
-
const cacheKnown = cached2 !== null && cached2 <= input && written === 0;
|
|
542
|
-
entries.push(withUsageSession({
|
|
543
|
-
id: `${update.prompt_id}:${model2}`,
|
|
544
|
-
occurredAtMs: at,
|
|
545
|
-
model: model2,
|
|
546
|
-
inputTokens: input,
|
|
547
|
-
...cacheKnown ? { cachedInputTokens: cached2, cacheWriteInputTokens: 0 } : {},
|
|
548
|
-
outputTokens: output,
|
|
549
|
-
...reasoning !== null && reasoning <= output ? { reasoningOutputTokens: reasoning } : {},
|
|
550
|
-
// A turn Grok marks incomplete has no cost of its own; it counts as free rather
|
|
551
|
-
// than as a model without a price.
|
|
552
|
-
...ticks !== null ? { costUsd: ticks / USD_TICKS } : usage.usageIsIncomplete === true ? { costUsd: 0 } : {}
|
|
553
|
-
}, { ...session, ...title ? { title } : {} }));
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return entries;
|
|
557
|
-
}
|
|
558
|
-
function createGrokUsageStatistics(environment) {
|
|
559
|
-
return Object.freeze({
|
|
560
|
-
// sessions/<url-encoded cwd>/<session>/updates.jsonl; subagents are sessions of their own.
|
|
561
|
-
listSources: async (signal) => (await jsonlUsageSources(path5.join(grokHome(environment), "sessions"), 2, signal)).filter((source) => path5.basename(source.id) === "updates.jsonl"),
|
|
562
|
-
readSource: (id, signal) => readGrokUsage(id, signal)
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// dist/grok-adapter.js
|
|
567
|
-
import { randomUUID } from "node:crypto";
|
|
568
|
-
|
|
569
|
-
// dist/grok-credential-export.js
|
|
570
|
-
import { createHash } from "node:crypto";
|
|
571
|
-
import { readFile as readFile2 } from "node:fs/promises";
|
|
572
|
-
import os3 from "node:os";
|
|
573
|
-
import path6 from "node:path";
|
|
574
|
-
async function readGrokCredentials(environment) {
|
|
575
|
-
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((v) => v?.trim()))
|
|
576
|
-
return [];
|
|
577
|
-
try {
|
|
578
|
-
const home = environment.GROK_HOME ?? path6.join(environment.HOME ?? os3.homedir(), ".grok");
|
|
579
|
-
const auth = JSON.parse(await readFile2(path6.join(home, "auth.json"), "utf8"));
|
|
580
|
-
const client2 = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
581
|
-
const entry = auth[`https://auth.x.ai::${client2}`] ?? auth["https://auth.x.ai"];
|
|
582
|
-
if (!entry || entry.oidc_issuer !== "https://auth.x.ai" || entry.oidc_client_id !== client2)
|
|
583
|
-
return [];
|
|
584
|
-
if (![entry.key, entry.refresh_token, entry.user_id].every((v) => typeof v === "string" && v.length))
|
|
585
|
-
return [];
|
|
586
|
-
const expires = Date.parse(entry.expires_at);
|
|
587
|
-
if (!Number.isFinite(expires))
|
|
588
|
-
return [];
|
|
589
|
-
return [
|
|
590
|
-
{
|
|
591
|
-
source: {
|
|
592
|
-
id: `grok:${createHash("sha256").update(entry.user_id).digest("hex")}`,
|
|
593
|
-
harnessId: "grok",
|
|
594
|
-
provider: "xai",
|
|
595
|
-
label: typeof entry.email === "string" && entry.email ? entry.email : "Grok"
|
|
596
|
-
},
|
|
597
|
-
oauth: { access: entry.key, refresh: entry.refresh_token, expires: expires - 3e5 }
|
|
598
|
-
}
|
|
599
|
-
];
|
|
600
|
-
} catch {
|
|
601
|
-
return [];
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// dist/grok-adapter.js
|
|
606
|
-
import path16 from "node:path";
|
|
607
|
-
|
|
608
375
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
609
376
|
var external_exports = {};
|
|
610
377
|
__export(external_exports, {
|
|
@@ -15698,6 +15465,10 @@ var CLIENT_CHANNEL_VERSION = 1;
|
|
|
15698
15465
|
var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
|
|
15699
15466
|
var clientThreadPinsSchema = external_exports.object({ threadIds: external_exports.array(external_exports.string().min(1)) }).strict();
|
|
15700
15467
|
var clientThreadPinParamsSchema = external_exports.object({ threadId: external_exports.string().min(1).max(1024), pinned: external_exports.boolean() }).strict();
|
|
15468
|
+
var clientThreadTreeReadParamsSchema = external_exports.object({}).strict();
|
|
15469
|
+
var clientThreadTreeSchema = external_exports.object({
|
|
15470
|
+
parents: external_exports.record(external_exports.string().min(1), external_exports.string().min(1))
|
|
15471
|
+
}).strict();
|
|
15701
15472
|
var clientProjectlessWorkspaceSchema = external_exports.object({
|
|
15702
15473
|
prompt: external_exports.string().max(16384).optional()
|
|
15703
15474
|
}).strict();
|
|
@@ -15714,6 +15485,11 @@ var clientChannelCursorSchema = external_exports.object({
|
|
|
15714
15485
|
sequence: external_exports.number().int().nonnegative()
|
|
15715
15486
|
});
|
|
15716
15487
|
var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
|
|
15488
|
+
external_exports.object({
|
|
15489
|
+
type: external_exports.literal("skills-changed"),
|
|
15490
|
+
cursor: clientChannelCursorSchema,
|
|
15491
|
+
cwd: external_exports.string().optional()
|
|
15492
|
+
}),
|
|
15717
15493
|
external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
|
|
15718
15494
|
external_exports.object({
|
|
15719
15495
|
type: external_exports.literal("preferences-changed"),
|
|
@@ -15911,6 +15687,28 @@ var voiceTranscribeResultSchema = external_exports.discriminatedUnion("ok", [
|
|
|
15911
15687
|
external_exports.object({ ok: external_exports.literal(false), error: external_exports.object({ code: voiceErrorCodeSchema }).strict() }).strict()
|
|
15912
15688
|
]);
|
|
15913
15689
|
|
|
15690
|
+
// ../../shared-contracts/dist/skills.js
|
|
15691
|
+
var skillsListParamsSchema = external_exports.object({
|
|
15692
|
+
threadId: hostThreadIdSchema.optional(),
|
|
15693
|
+
cwd: external_exports.string().min(1).optional()
|
|
15694
|
+
}).strict().refine((params) => !(params.threadId && params.cwd), {
|
|
15695
|
+
message: "Specify threadId or cwd, not both"
|
|
15696
|
+
});
|
|
15697
|
+
var librarySkillSchema = external_exports.object({
|
|
15698
|
+
name: external_exports.string().min(1).regex(/^[^\s[\]]+$/u),
|
|
15699
|
+
description: external_exports.string().optional(),
|
|
15700
|
+
path: external_exports.string().min(1),
|
|
15701
|
+
scope: external_exports.enum(["project", "global"]),
|
|
15702
|
+
source: external_exports.string().min(1)
|
|
15703
|
+
}).strict();
|
|
15704
|
+
var skillsListResultSchema = external_exports.object({
|
|
15705
|
+
revision: external_exports.number().int().nonnegative(),
|
|
15706
|
+
complete: external_exports.boolean(),
|
|
15707
|
+
skills: external_exports.array(librarySkillSchema),
|
|
15708
|
+
warnings: external_exports.array(external_exports.string()).optional()
|
|
15709
|
+
}).strict();
|
|
15710
|
+
var skillsChangedParamsSchema = external_exports.object({ cwd: external_exports.string().min(1).optional() }).strict();
|
|
15711
|
+
|
|
15914
15712
|
// ../../shared-contracts/dist/web-access-tokens.js
|
|
15915
15713
|
var webNetworkAccessUrlSchema = external_exports.object({
|
|
15916
15714
|
/**
|
|
@@ -16016,8 +15814,8 @@ var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
|
16016
15814
|
var delegationReadParamsSchema = external_exports.strictObject({
|
|
16017
15815
|
threadId: external_exports.string().min(1).max(1024),
|
|
16018
15816
|
view: external_exports.enum(["result", "messages"]),
|
|
16019
|
-
|
|
16020
|
-
|
|
15817
|
+
from: external_exports.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional(),
|
|
15818
|
+
to: external_exports.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional()
|
|
16021
15819
|
});
|
|
16022
15820
|
|
|
16023
15821
|
// ../../shared-contracts/dist/credential-imports.js
|
|
@@ -16211,7 +16009,7 @@ var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
|
16211
16009
|
|
|
16212
16010
|
// ../../shared-contracts/dist/usage-statistics.js
|
|
16213
16011
|
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
16214
|
-
var
|
|
16012
|
+
var count = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
16215
16013
|
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
16216
16014
|
var harness = external_exports.string().min(1).max(128);
|
|
16217
16015
|
var model = external_exports.string().min(1).max(512);
|
|
@@ -16234,24 +16032,24 @@ var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
|
16234
16032
|
date: localDate.optional()
|
|
16235
16033
|
});
|
|
16236
16034
|
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
16237
|
-
requests:
|
|
16238
|
-
inputTokens:
|
|
16239
|
-
cachedInputTokens:
|
|
16240
|
-
cacheWriteInputTokens:
|
|
16241
|
-
cacheKnownInputTokens:
|
|
16242
|
-
cacheHitCachedInputTokens:
|
|
16243
|
-
cacheHitInputTokens:
|
|
16244
|
-
outputTokens:
|
|
16245
|
-
reasoningOutputTokens:
|
|
16035
|
+
requests: count,
|
|
16036
|
+
inputTokens: count,
|
|
16037
|
+
cachedInputTokens: count,
|
|
16038
|
+
cacheWriteInputTokens: count,
|
|
16039
|
+
cacheKnownInputTokens: count,
|
|
16040
|
+
cacheHitCachedInputTokens: count,
|
|
16041
|
+
cacheHitInputTokens: count,
|
|
16042
|
+
outputTokens: count,
|
|
16043
|
+
reasoningOutputTokens: count,
|
|
16246
16044
|
/** USD at the public price, summed over the priced requests only. */
|
|
16247
16045
|
costUsd: external_exports.number().finite().min(0),
|
|
16248
16046
|
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
16249
|
-
unpricedRequests:
|
|
16047
|
+
unpricedRequests: count,
|
|
16250
16048
|
/**
|
|
16251
16049
|
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
16252
16050
|
* cost, and not as unpriced.
|
|
16253
16051
|
*/
|
|
16254
|
-
unmeteredRequests:
|
|
16052
|
+
unmeteredRequests: count
|
|
16255
16053
|
});
|
|
16256
16054
|
var totals = usageStatisticsTotalsSchema.shape;
|
|
16257
16055
|
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
@@ -16262,8 +16060,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
|
16262
16060
|
title: external_exports.string().min(1).max(200).optional(),
|
|
16263
16061
|
/** Models the session used, most requests first. */
|
|
16264
16062
|
models: external_exports.array(model).max(16),
|
|
16265
|
-
firstAtMs:
|
|
16266
|
-
lastAtMs:
|
|
16063
|
+
firstAtMs: count,
|
|
16064
|
+
lastAtMs: count,
|
|
16267
16065
|
...totals
|
|
16268
16066
|
});
|
|
16269
16067
|
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
@@ -16281,7 +16079,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
16281
16079
|
date: localDate.nullable()
|
|
16282
16080
|
}),
|
|
16283
16081
|
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
16284
|
-
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources:
|
|
16082
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count, read: count }),
|
|
16285
16083
|
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
16286
16084
|
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
16287
16085
|
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
@@ -16301,8 +16099,8 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
16301
16099
|
harness,
|
|
16302
16100
|
model: model.nullable(),
|
|
16303
16101
|
credits: external_exports.number().finite().min(0),
|
|
16304
|
-
reportedRequests:
|
|
16305
|
-
requests:
|
|
16102
|
+
reportedRequests: count,
|
|
16103
|
+
requests: count
|
|
16306
16104
|
})).max(4096).optional(),
|
|
16307
16105
|
/** All filters applied. */
|
|
16308
16106
|
totals: usageStatisticsTotalsSchema,
|
|
@@ -16319,7 +16117,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
16319
16117
|
model: model.nullable(),
|
|
16320
16118
|
...totals,
|
|
16321
16119
|
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
16322
|
-
harnessPricedRequests:
|
|
16120
|
+
harnessPricedRequests: count
|
|
16323
16121
|
})).max(4096),
|
|
16324
16122
|
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
16325
16123
|
/**
|
|
@@ -16970,6 +16768,17 @@ var updateStatusResultSchema = external_exports.strictObject({
|
|
|
16970
16768
|
status: updateStatusSchema.nullable()
|
|
16971
16769
|
});
|
|
16972
16770
|
|
|
16771
|
+
// ../../shared-contracts/dist/thread-watch-notice.js
|
|
16772
|
+
var THREAD_WATCH_NOTICE_OUTCOMES = [
|
|
16773
|
+
"completed",
|
|
16774
|
+
"failed",
|
|
16775
|
+
"interrupted",
|
|
16776
|
+
"timedOut",
|
|
16777
|
+
"unreadable",
|
|
16778
|
+
"notFound"
|
|
16779
|
+
];
|
|
16780
|
+
var ENTRY_PATTERN = new RegExp(String.raw`^- \[([^\]\n]+)\]\(thread://([^\s()<>"?#/]+)\): ` + `(${THREAD_WATCH_NOTICE_OUTCOMES.join("|")})(?:. (.+))?$`, "u");
|
|
16781
|
+
|
|
16973
16782
|
// ../../shared-contracts/dist/remote-runtime.js
|
|
16974
16783
|
var remoteUpdatePhaseSchema = external_exports.enum([
|
|
16975
16784
|
"idle",
|
|
@@ -17017,6 +16826,14 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
|
|
|
17017
16826
|
archived: external_exports.boolean()
|
|
17018
16827
|
}),
|
|
17019
16828
|
external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
|
|
16829
|
+
external_exports.strictObject({
|
|
16830
|
+
kind: external_exports.literal("configure"),
|
|
16831
|
+
...thread,
|
|
16832
|
+
epoch: identity,
|
|
16833
|
+
modelId: identity.optional(),
|
|
16834
|
+
thinkingOptionId: identity.optional(),
|
|
16835
|
+
permissionModeId: identity.optional()
|
|
16836
|
+
}).refine((value) => [value.modelId, value.thinkingOptionId, value.permissionModeId].filter((v) => v !== void 0).length === 1, "Select exactly one remote setting"),
|
|
17020
16837
|
external_exports.strictObject({
|
|
17021
16838
|
kind: external_exports.literal("prompt"),
|
|
17022
16839
|
...thread,
|
|
@@ -17089,6 +16906,13 @@ var remoteConnectionsReplySchema = external_exports.union([
|
|
|
17089
16906
|
external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
|
|
17090
16907
|
]);
|
|
17091
16908
|
|
|
16909
|
+
// ../../shared-contracts/dist/thread-title.js
|
|
16910
|
+
var threadTitleInputSchema = external_exports.strictObject({
|
|
16911
|
+
prompt: external_exports.string().trim().min(1).max(2e3),
|
|
16912
|
+
cwd: external_exports.string().max(4096).nullable()
|
|
16913
|
+
});
|
|
16914
|
+
var threadTitleResultSchema = external_exports.string().trim().min(1).max(60).nullable();
|
|
16915
|
+
|
|
17092
16916
|
// ../../shared-contracts/dist/web-ui-extensions.js
|
|
17093
16917
|
var webUiExtensionIdSchema = external_exports.string().max(214).regex(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u);
|
|
17094
16918
|
var localizedTextSchema2 = external_exports.union([
|
|
@@ -17282,11 +17106,11 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
17282
17106
|
"costSource",
|
|
17283
17107
|
"unpricedModels"
|
|
17284
17108
|
]);
|
|
17285
|
-
function
|
|
17109
|
+
function isRecord(value) {
|
|
17286
17110
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17287
17111
|
}
|
|
17288
17112
|
function parseHostUsage(value) {
|
|
17289
|
-
if (!
|
|
17113
|
+
if (!isRecord(value))
|
|
17290
17114
|
throw new Error("Harness Usage must be an object");
|
|
17291
17115
|
const keys = Object.keys(value);
|
|
17292
17116
|
if (keys.length === 0)
|
|
@@ -17333,7 +17157,7 @@ function parseHostUsage(value) {
|
|
|
17333
17157
|
}
|
|
17334
17158
|
if (value.sessionCacheUsage !== void 0) {
|
|
17335
17159
|
const totals2 = value.sessionCacheUsage;
|
|
17336
|
-
if (!
|
|
17160
|
+
if (!isRecord(totals2) || Object.keys(totals2).some((key) => key !== "inputTokens" && key !== "cachedInputTokens") || typeof totals2.inputTokens !== "number" || !Number.isSafeInteger(totals2.inputTokens) || totals2.inputTokens < 0 || typeof totals2.cachedInputTokens !== "number" || !Number.isSafeInteger(totals2.cachedInputTokens) || totals2.cachedInputTokens < 0 || totals2.cachedInputTokens > totals2.inputTokens) {
|
|
17337
17161
|
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
17338
17162
|
}
|
|
17339
17163
|
}
|
|
@@ -17454,14 +17278,12 @@ var COMMON_EXCLUDED_LIVE_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
17454
17278
|
"reload-plugins"
|
|
17455
17279
|
]);
|
|
17456
17280
|
var COMMON_EXCLUDED_LIVE_COMMAND_PREFIXES = ["__", "hooks-"];
|
|
17457
|
-
function isExcludedLiveCommand(name,
|
|
17281
|
+
function isExcludedLiveCommand(name, extra = {}) {
|
|
17458
17282
|
const normalized = name.trim().replace(/^\//u, "");
|
|
17459
17283
|
if (new Set(extra.names ?? []).has(normalized))
|
|
17460
17284
|
return true;
|
|
17461
17285
|
if (extra.prefixes?.some((prefix) => normalized.startsWith(prefix)))
|
|
17462
17286
|
return true;
|
|
17463
|
-
if (kind === "skill")
|
|
17464
|
-
return false;
|
|
17465
17287
|
return COMMON_EXCLUDED_LIVE_COMMANDS.has(normalized) || COMMON_EXCLUDED_LIVE_COMMAND_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
17466
17288
|
}
|
|
17467
17289
|
function liveHarnessCommandPrompt(catalog, idPrefix, commandId, argumentText) {
|
|
@@ -17483,7 +17305,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
17483
17305
|
const name = command.name.trim().replace(/^\//u, "");
|
|
17484
17306
|
if (!name || /\s/u.test(name))
|
|
17485
17307
|
continue;
|
|
17486
|
-
if (isExcludedLiveCommand(name,
|
|
17308
|
+
if (isExcludedLiveCommand(name, exclusions))
|
|
17487
17309
|
continue;
|
|
17488
17310
|
const invocation = `/${name}`;
|
|
17489
17311
|
const id = `${idPrefix}${name.replace(/[^A-Za-z0-9._:-]/gu, "-")}`.slice(0, 128);
|
|
@@ -17495,8 +17317,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
17495
17317
|
invocation,
|
|
17496
17318
|
label: name.slice(0, 128),
|
|
17497
17319
|
...description ? { description } : {},
|
|
17498
|
-
argumentMode: "text"
|
|
17499
|
-
kind: command.kind
|
|
17320
|
+
argumentMode: "text"
|
|
17500
17321
|
});
|
|
17501
17322
|
if (!parsed.success)
|
|
17502
17323
|
continue;
|
|
@@ -17507,6 +17328,293 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
17507
17328
|
return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
|
|
17508
17329
|
}
|
|
17509
17330
|
|
|
17331
|
+
// ../../harness-adapter/dist/subagent-configuration.js
|
|
17332
|
+
function subagentConfiguration(value) {
|
|
17333
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
17334
|
+
return {};
|
|
17335
|
+
const row = value;
|
|
17336
|
+
const text = (value2) => typeof value2 === "string" && value2.trim() ? value2 : void 0;
|
|
17337
|
+
const model2 = row.model === "inherit" ? void 0 : text(row.model);
|
|
17338
|
+
const reasoningEffort = text(row.reasoningEffort) ?? text(row.reasoning_effort) ?? text(row.thinking);
|
|
17339
|
+
return { ...model2 ? { model: model2 } : {}, ...reasoningEffort ? { reasoningEffort } : {} };
|
|
17340
|
+
}
|
|
17341
|
+
function inheritSubagentConfiguration(child, parent) {
|
|
17342
|
+
const native = subagentConfiguration(child);
|
|
17343
|
+
const model2 = native.model ?? parent.model;
|
|
17344
|
+
const reasoningEffort = native.reasoningEffort ?? parent.reasoningEffort;
|
|
17345
|
+
const next = { ...child };
|
|
17346
|
+
delete next.model;
|
|
17347
|
+
delete next.reasoningEffort;
|
|
17348
|
+
return { ...next, ...model2 ? { model: model2 } : {}, ...reasoningEffort ? { reasoningEffort } : {} };
|
|
17349
|
+
}
|
|
17350
|
+
function configureSubagentEvent(event, parent) {
|
|
17351
|
+
const children = (states) => states.map((child) => inheritSubagentConfiguration(child, parent));
|
|
17352
|
+
if (event.type === "item.started" && event.item.type === "subagentDelegation")
|
|
17353
|
+
return { ...event, item: { ...event.item, subagents: children(event.item.subagents) } };
|
|
17354
|
+
if (event.type === "item.updated" && event.update.type === "subagents.replace")
|
|
17355
|
+
return { ...event, update: { ...event.update, subagents: children(event.update.subagents) } };
|
|
17356
|
+
if (event.type === "item.completed" && event.snapshot.item.type === "subagentDelegation")
|
|
17357
|
+
return {
|
|
17358
|
+
...event,
|
|
17359
|
+
snapshot: {
|
|
17360
|
+
...event.snapshot,
|
|
17361
|
+
item: {
|
|
17362
|
+
...event.snapshot.item,
|
|
17363
|
+
subagents: children(event.snapshot.item.subagents)
|
|
17364
|
+
}
|
|
17365
|
+
}
|
|
17366
|
+
};
|
|
17367
|
+
return event;
|
|
17368
|
+
}
|
|
17369
|
+
function configureSubagentSnapshot(snapshot, parent) {
|
|
17370
|
+
return {
|
|
17371
|
+
...snapshot,
|
|
17372
|
+
turns: snapshot.turns.map((turn) => ({
|
|
17373
|
+
...turn,
|
|
17374
|
+
items: turn.items.map((entry) => entry.item.type === "subagentDelegation" ? {
|
|
17375
|
+
...entry,
|
|
17376
|
+
item: {
|
|
17377
|
+
...entry.item,
|
|
17378
|
+
subagents: entry.item.subagents.map((child) => inheritSubagentConfiguration(child, parent))
|
|
17379
|
+
}
|
|
17380
|
+
} : entry)
|
|
17381
|
+
}))
|
|
17382
|
+
};
|
|
17383
|
+
}
|
|
17384
|
+
|
|
17385
|
+
// dist/usage-statistics.js
|
|
17386
|
+
import os2 from "node:os";
|
|
17387
|
+
import path5 from "node:path";
|
|
17388
|
+
import { readFile } from "node:fs/promises";
|
|
17389
|
+
|
|
17390
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
17391
|
+
import { createReadStream } from "node:fs";
|
|
17392
|
+
import { lstat, opendir } from "node:fs/promises";
|
|
17393
|
+
import path4 from "node:path";
|
|
17394
|
+
import { createInterface } from "node:readline";
|
|
17395
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
17396
|
+
var MAX_CWD_LENGTH = 4096;
|
|
17397
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
17398
|
+
function usageSessionTitle(value) {
|
|
17399
|
+
if (typeof value !== "string")
|
|
17400
|
+
return void 0;
|
|
17401
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
17402
|
+
if (!normalized)
|
|
17403
|
+
return void 0;
|
|
17404
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
17405
|
+
return normalized;
|
|
17406
|
+
let title = "";
|
|
17407
|
+
for (const character of normalized) {
|
|
17408
|
+
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
17409
|
+
break;
|
|
17410
|
+
title += character;
|
|
17411
|
+
}
|
|
17412
|
+
return `${title.trimEnd()}…`;
|
|
17413
|
+
}
|
|
17414
|
+
function sessionIdOk(value) {
|
|
17415
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
17416
|
+
}
|
|
17417
|
+
function cwdOk(value) {
|
|
17418
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
17419
|
+
}
|
|
17420
|
+
function withUsageSession(entry, session) {
|
|
17421
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
17422
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
17423
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
17424
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
17425
|
+
return entry;
|
|
17426
|
+
return {
|
|
17427
|
+
...entry,
|
|
17428
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
17429
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
17430
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
17431
|
+
};
|
|
17432
|
+
}
|
|
17433
|
+
async function jsonlUsageSources(root, maxDepth, signal) {
|
|
17434
|
+
const sources = [];
|
|
17435
|
+
const visit = async (directory, depth) => {
|
|
17436
|
+
signal.throwIfAborted();
|
|
17437
|
+
const entries = await opendir(directory).catch((error53) => {
|
|
17438
|
+
if (error53.code === "ENOENT")
|
|
17439
|
+
return null;
|
|
17440
|
+
throw error53;
|
|
17441
|
+
});
|
|
17442
|
+
if (!entries)
|
|
17443
|
+
return;
|
|
17444
|
+
for await (const entry of entries) {
|
|
17445
|
+
signal.throwIfAborted();
|
|
17446
|
+
const file2 = path4.join(directory, entry.name);
|
|
17447
|
+
if (entry.isDirectory()) {
|
|
17448
|
+
if (depth < maxDepth)
|
|
17449
|
+
await visit(file2, depth + 1);
|
|
17450
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
17451
|
+
const info = await lstat(file2).catch(() => null);
|
|
17452
|
+
if (info?.isFile() && info.size > 0) {
|
|
17453
|
+
sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
|
|
17454
|
+
}
|
|
17455
|
+
}
|
|
17456
|
+
}
|
|
17457
|
+
};
|
|
17458
|
+
await visit(root, 0);
|
|
17459
|
+
return sources;
|
|
17460
|
+
}
|
|
17461
|
+
async function* jsonlRecords(file2, marker, signal) {
|
|
17462
|
+
const lines = createInterface({
|
|
17463
|
+
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
17464
|
+
crlfDelay: Infinity
|
|
17465
|
+
});
|
|
17466
|
+
for await (const line of lines) {
|
|
17467
|
+
if (!line.includes(marker))
|
|
17468
|
+
continue;
|
|
17469
|
+
let value;
|
|
17470
|
+
try {
|
|
17471
|
+
value = JSON.parse(line);
|
|
17472
|
+
} catch {
|
|
17473
|
+
continue;
|
|
17474
|
+
}
|
|
17475
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
17476
|
+
yield value;
|
|
17477
|
+
}
|
|
17478
|
+
}
|
|
17479
|
+
}
|
|
17480
|
+
function nativeTimeMs(value) {
|
|
17481
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
17482
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
17483
|
+
}
|
|
17484
|
+
|
|
17485
|
+
// dist/usage-statistics.js
|
|
17486
|
+
function isRecord2(value) {
|
|
17487
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17488
|
+
}
|
|
17489
|
+
var USD_TICKS = 1e10;
|
|
17490
|
+
function count2(value) {
|
|
17491
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
17492
|
+
}
|
|
17493
|
+
function grokHome(environment) {
|
|
17494
|
+
return environment.GROK_HOME || path5.join(environment.HOME || os2.homedir(), ".grok");
|
|
17495
|
+
}
|
|
17496
|
+
async function grokSummary(directory) {
|
|
17497
|
+
try {
|
|
17498
|
+
const summary = JSON.parse(await readFile(path5.join(directory, "summary.json"), "utf8"));
|
|
17499
|
+
if (!isRecord2(summary))
|
|
17500
|
+
return { forkedAt: null };
|
|
17501
|
+
const title = usageSessionTitle(summary.generated_title) ?? usageSessionTitle(summary.session_summary);
|
|
17502
|
+
return {
|
|
17503
|
+
forkedAt: typeof summary.parent_session_id === "string" ? nativeTimeMs(summary.created_at) : null,
|
|
17504
|
+
...title ? { title } : {}
|
|
17505
|
+
};
|
|
17506
|
+
} catch {
|
|
17507
|
+
return { forkedAt: null };
|
|
17508
|
+
}
|
|
17509
|
+
}
|
|
17510
|
+
function grokSession(file2) {
|
|
17511
|
+
const directory = path5.dirname(file2);
|
|
17512
|
+
let cwd;
|
|
17513
|
+
try {
|
|
17514
|
+
cwd = decodeURIComponent(path5.basename(path5.dirname(directory)));
|
|
17515
|
+
} catch {
|
|
17516
|
+
cwd = void 0;
|
|
17517
|
+
}
|
|
17518
|
+
return { sessionId: path5.basename(directory), cwd };
|
|
17519
|
+
}
|
|
17520
|
+
async function readGrokUsage(file2, signal) {
|
|
17521
|
+
const summary = await grokSummary(path5.dirname(file2));
|
|
17522
|
+
const forkedAt = summary.forkedAt;
|
|
17523
|
+
let title = summary.title;
|
|
17524
|
+
const session = grokSession(file2);
|
|
17525
|
+
const entries = [];
|
|
17526
|
+
for await (const line of jsonlRecords(file2, '"sessionUpdate"', signal)) {
|
|
17527
|
+
const params = isRecord2(line.params) ? line.params : {};
|
|
17528
|
+
const update = isRecord2(params.update) ? params.update : {};
|
|
17529
|
+
if (!title && update.sessionUpdate === "user_message_chunk") {
|
|
17530
|
+
title = usageSessionTitle(isRecord2(update.content) ? update.content.text : void 0);
|
|
17531
|
+
continue;
|
|
17532
|
+
}
|
|
17533
|
+
const usage = isRecord2(update.usage) ? update.usage : {};
|
|
17534
|
+
if (update.sessionUpdate !== "turn_completed" || typeof update.prompt_id !== "string")
|
|
17535
|
+
continue;
|
|
17536
|
+
const meta3 = isRecord2(params._meta) ? params._meta : {};
|
|
17537
|
+
const at = nativeTimeMs(meta3.agentTimestampMs) ?? (typeof line.timestamp === "number" ? nativeTimeMs(line.timestamp * 1e3) : null);
|
|
17538
|
+
if (at === null || forkedAt !== null && at <= forkedAt)
|
|
17539
|
+
continue;
|
|
17540
|
+
for (const [model2, value] of Object.entries(isRecord2(usage.modelUsage) ? usage.modelUsage : {})) {
|
|
17541
|
+
if (!isRecord2(value))
|
|
17542
|
+
continue;
|
|
17543
|
+
const input = count2(value.inputTokens);
|
|
17544
|
+
const output = count2(value.outputTokens);
|
|
17545
|
+
const cached2 = count2(value.cachedReadTokens);
|
|
17546
|
+
const written = count2(value.cacheCreationTokens ?? 0);
|
|
17547
|
+
const reasoning = count2(value.reasoningTokens);
|
|
17548
|
+
const ticks = count2(value.costUsdTicks);
|
|
17549
|
+
if (input === null || output === null || value.totalTokens !== input + output)
|
|
17550
|
+
continue;
|
|
17551
|
+
const cacheKnown = cached2 !== null && cached2 <= input && written === 0;
|
|
17552
|
+
entries.push(withUsageSession({
|
|
17553
|
+
id: `${update.prompt_id}:${model2}`,
|
|
17554
|
+
occurredAtMs: at,
|
|
17555
|
+
model: model2,
|
|
17556
|
+
inputTokens: input,
|
|
17557
|
+
...cacheKnown ? { cachedInputTokens: cached2, cacheWriteInputTokens: 0 } : {},
|
|
17558
|
+
outputTokens: output,
|
|
17559
|
+
...reasoning !== null && reasoning <= output ? { reasoningOutputTokens: reasoning } : {},
|
|
17560
|
+
// A turn Grok marks incomplete has no cost of its own; it counts as free rather
|
|
17561
|
+
// than as a model without a price.
|
|
17562
|
+
...ticks !== null ? { costUsd: ticks / USD_TICKS } : usage.usageIsIncomplete === true ? { costUsd: 0 } : {}
|
|
17563
|
+
}, { ...session, ...title ? { title } : {} }));
|
|
17564
|
+
}
|
|
17565
|
+
}
|
|
17566
|
+
return entries;
|
|
17567
|
+
}
|
|
17568
|
+
function createGrokUsageStatistics(environment) {
|
|
17569
|
+
return Object.freeze({
|
|
17570
|
+
// sessions/<url-encoded cwd>/<session>/updates.jsonl; subagents are sessions of their own.
|
|
17571
|
+
listSources: async (signal) => (await jsonlUsageSources(path5.join(grokHome(environment), "sessions"), 2, signal)).filter((source) => path5.basename(source.id) === "updates.jsonl"),
|
|
17572
|
+
readSource: (id, signal) => readGrokUsage(id, signal)
|
|
17573
|
+
});
|
|
17574
|
+
}
|
|
17575
|
+
|
|
17576
|
+
// dist/grok-adapter.js
|
|
17577
|
+
import { randomUUID } from "node:crypto";
|
|
17578
|
+
|
|
17579
|
+
// dist/grok-credential-export.js
|
|
17580
|
+
import { createHash } from "node:crypto";
|
|
17581
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
17582
|
+
import os3 from "node:os";
|
|
17583
|
+
import path6 from "node:path";
|
|
17584
|
+
async function readGrokCredentials(environment) {
|
|
17585
|
+
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((v) => v?.trim()))
|
|
17586
|
+
return [];
|
|
17587
|
+
try {
|
|
17588
|
+
const home = environment.GROK_HOME ?? path6.join(environment.HOME ?? os3.homedir(), ".grok");
|
|
17589
|
+
const auth = JSON.parse(await readFile2(path6.join(home, "auth.json"), "utf8"));
|
|
17590
|
+
const client2 = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
17591
|
+
const entry = auth[`https://auth.x.ai::${client2}`] ?? auth["https://auth.x.ai"];
|
|
17592
|
+
if (!entry || entry.oidc_issuer !== "https://auth.x.ai" || entry.oidc_client_id !== client2)
|
|
17593
|
+
return [];
|
|
17594
|
+
if (![entry.key, entry.refresh_token, entry.user_id].every((v) => typeof v === "string" && v.length))
|
|
17595
|
+
return [];
|
|
17596
|
+
const expires = Date.parse(entry.expires_at);
|
|
17597
|
+
if (!Number.isFinite(expires))
|
|
17598
|
+
return [];
|
|
17599
|
+
return [
|
|
17600
|
+
{
|
|
17601
|
+
source: {
|
|
17602
|
+
id: `grok:${createHash("sha256").update(entry.user_id).digest("hex")}`,
|
|
17603
|
+
harnessId: "grok",
|
|
17604
|
+
provider: "xai",
|
|
17605
|
+
label: typeof entry.email === "string" && entry.email ? entry.email : "Grok"
|
|
17606
|
+
},
|
|
17607
|
+
oauth: { access: entry.key, refresh: entry.refresh_token, expires: expires - 3e5 }
|
|
17608
|
+
}
|
|
17609
|
+
];
|
|
17610
|
+
} catch {
|
|
17611
|
+
return [];
|
|
17612
|
+
}
|
|
17613
|
+
}
|
|
17614
|
+
|
|
17615
|
+
// dist/grok-adapter.js
|
|
17616
|
+
import path16 from "node:path";
|
|
17617
|
+
|
|
17510
17618
|
// ../../harness-adapter/dist/local-media-markdown.js
|
|
17511
17619
|
import { existsSync, statSync } from "node:fs";
|
|
17512
17620
|
import path7 from "node:path";
|
|
@@ -22058,15 +22166,13 @@ function parseGrokAvailableCommands(value) {
|
|
|
22058
22166
|
];
|
|
22059
22167
|
});
|
|
22060
22168
|
}
|
|
22061
|
-
function isGrokSkill(command) {
|
|
22062
|
-
const path17 = command.meta?.path;
|
|
22063
|
-
return typeof path17 === "string" && /(^|[\\/])SKILL\.md$/u.test(path17) || typeof command.meta?.qualifiedName === "string";
|
|
22064
|
-
}
|
|
22065
22169
|
function grokLiveCommands(native) {
|
|
22066
|
-
return native.
|
|
22170
|
+
return native.filter(({ meta: meta3 }) => {
|
|
22171
|
+
const path17 = meta3?.path;
|
|
22172
|
+
return !(typeof path17 === "string" && /(^|[\\/])SKILL\.md$/u.test(path17) || typeof meta3?.qualifiedName === "string");
|
|
22173
|
+
}).map((command) => ({
|
|
22067
22174
|
name: command.name,
|
|
22068
|
-
description: command.description
|
|
22069
|
-
kind: isGrokSkill(command) ? "skill" : "command"
|
|
22175
|
+
description: command.description
|
|
22070
22176
|
}));
|
|
22071
22177
|
}
|
|
22072
22178
|
|
|
@@ -23482,6 +23588,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
23482
23588
|
description: grokSubagentDescription(event.rawInput, event.title),
|
|
23483
23589
|
...role ? { role } : {},
|
|
23484
23590
|
...model2 ? { model: model2 } : {},
|
|
23591
|
+
...subagentConfiguration(event.rawInput),
|
|
23485
23592
|
background: grokSubagentBackground(event.rawInput),
|
|
23486
23593
|
status: "running"
|
|
23487
23594
|
}
|
|
@@ -26200,7 +26307,19 @@ var GrokHarnessSession = class {
|
|
|
26200
26307
|
...this.#state.effectivePermissionModeId ? { permissionModeId: this.#state.effectivePermissionModeId } : {}
|
|
26201
26308
|
};
|
|
26202
26309
|
}
|
|
26310
|
+
#subagentConfiguration() {
|
|
26311
|
+
const state = this.#state;
|
|
26312
|
+
const model2 = state.effectiveModel ? state.effectiveModel.id : void 0;
|
|
26313
|
+
return {
|
|
26314
|
+
...model2 ? { model: model2 } : {},
|
|
26315
|
+
...state.effectiveThinkingOptionId ? { reasoningEffort: state.effectiveThinkingOptionId } : {}
|
|
26316
|
+
};
|
|
26317
|
+
}
|
|
26203
26318
|
async readSnapshot() {
|
|
26319
|
+
const result = await this.#readSnapshot();
|
|
26320
|
+
return result.ok ? { ok: true, value: configureSubagentSnapshot(result.value, this.#subagentConfiguration()) } : result;
|
|
26321
|
+
}
|
|
26322
|
+
async #readSnapshot() {
|
|
26204
26323
|
if (this.#phase !== "open") {
|
|
26205
26324
|
return { ok: false, error: invalidState("Grok Session is not open") };
|
|
26206
26325
|
}
|
|
@@ -26777,6 +26896,7 @@ var GrokHarnessSession = class {
|
|
|
26777
26896
|
...prompt ? { prompt } : {},
|
|
26778
26897
|
...role ? { role } : {},
|
|
26779
26898
|
...model2 ? { model: model2 } : {},
|
|
26899
|
+
...subagentConfiguration(event.rawInput),
|
|
26780
26900
|
background: grokSubagentBackground(event.rawInput),
|
|
26781
26901
|
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
26782
26902
|
});
|
|
@@ -26825,6 +26945,8 @@ var GrokHarnessSession = class {
|
|
|
26825
26945
|
const role = grokSubagentRole(event.rawInput);
|
|
26826
26946
|
const nativeSubagentId = grokNativeSubagentId(event.rawInput, event.rawOutput, event.content);
|
|
26827
26947
|
active.subagents.update(active.command.turnId, event.callId, {
|
|
26948
|
+
...subagentConfiguration(event.rawInput),
|
|
26949
|
+
...subagentConfiguration(event.rawOutput),
|
|
26828
26950
|
...event.title ? { description: grokSubagentDescription(event.rawInput, event.title) } : {},
|
|
26829
26951
|
...role ? { role } : {},
|
|
26830
26952
|
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
@@ -27092,6 +27214,7 @@ var GrokHarnessSession = class {
|
|
|
27092
27214
|
this.#onClosed();
|
|
27093
27215
|
}
|
|
27094
27216
|
#event(event) {
|
|
27217
|
+
event = configureSubagentEvent(event, this.#subagentConfiguration());
|
|
27095
27218
|
this.#channel.emit({ kind: "event", event });
|
|
27096
27219
|
}
|
|
27097
27220
|
};
|