@karlorz/codexhost-cli-win32-x64 0.17.0-1 → 0.17.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +15 -0
- package/app/console-web.js +16 -1
- package/app/cpa-live-voice-hook.js +51 -33
- package/app/desktop-controller.mjs +1182 -46
- package/app/host-runtime.mjs +1239 -59
- package/app/plugins/antigravity/plugin.mjs +42 -7
- package/app/plugins/claude-code/plugin.mjs +15 -0
- package/app/plugins/codebuddy/plugin.mjs +15 -0
- package/app/plugins/codex-usage/plugin.mjs +15 -0
- package/app/plugins/copilot/plugin.mjs +15 -0
- package/app/plugins/cursor-cli/plugin.mjs +34 -3
- package/app/plugins/deepseek-harness/plugin.mjs +15 -0
- package/app/plugins/devin/plugin.mjs +15 -0
- package/app/plugins/grok/plugin.mjs +383 -70
- package/app/plugins/hermes/plugin.mjs +15 -0
- package/app/plugins/kimi-code/plugin.mjs +65 -3
- package/app/plugins/kiro-cli/plugin.mjs +15 -0
- package/app/plugins/omp/plugin.mjs +15 -0
- package/app/plugins/opencode/plugin.mjs +15 -0
- package/app/plugins/pi/plugin.mjs +223 -88
- package/app/plugins/qoder/plugin.mjs +15 -0
- package/app/plugins/qoder-cn/plugin.mjs +15 -0
- package/app/plugins/qwen-code/plugin.mjs +15 -0
- package/app/plugins/workbuddy/plugin.mjs +15 -0
- package/app/plugins/zcode/plugin.mjs +157 -9
- package/app/renderer-extension.js +594 -251
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -15946,6 +15946,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
|
|
|
15946
15946
|
/** The text about to be steered; a Harness command always stops and restarts. */
|
|
15947
15947
|
text: external_exports.string().optional()
|
|
15948
15948
|
}).strict();
|
|
15949
|
+
var threadSteeringContextSchema = external_exports.object({
|
|
15950
|
+
kind: external_exports.literal("application"),
|
|
15951
|
+
value: external_exports.string().transform((text, context) => {
|
|
15952
|
+
try {
|
|
15953
|
+
return JSON.parse(text);
|
|
15954
|
+
} catch {
|
|
15955
|
+
context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
|
|
15956
|
+
return external_exports.NEVER;
|
|
15957
|
+
}
|
|
15958
|
+
}).pipe(external_exports.object({
|
|
15959
|
+
expectedTurnId: hostTurnIdSchema,
|
|
15960
|
+
clientUserMessageId: external_exports.string().min(1),
|
|
15961
|
+
delivery: external_exports.enum(["newTurn", "activeTurn"])
|
|
15962
|
+
}).strict())
|
|
15963
|
+
}).strict().transform((context) => context.value);
|
|
15949
15964
|
var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
|
|
15950
15965
|
var threadSteeringInspectResultSchema = external_exports.object({
|
|
15951
15966
|
delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
|
|
@@ -25113,8 +25128,20 @@ function grokElicitationResolvedToolCallId(update) {
|
|
|
25113
25128
|
// dist/permission-modes.js
|
|
25114
25129
|
var nativePermissionModes = /* @__PURE__ */ new Set(["ask", "auto", "always-approve"]);
|
|
25115
25130
|
var GROK_DEFAULT_PERMISSION_MODE_ID = harnessPermissionModeIdSchema.parse("ask");
|
|
25131
|
+
var GROK_PLAN_MODE_ID = harnessPermissionModeIdSchema.parse("plan");
|
|
25116
25132
|
var GROK_PERMISSION_MODE_CATALOG = harnessPermissionModeCatalogSchema.parse({
|
|
25117
25133
|
modes: [
|
|
25134
|
+
{
|
|
25135
|
+
id: "plan",
|
|
25136
|
+
label: "Plan",
|
|
25137
|
+
localizations: {
|
|
25138
|
+
"zh-CN": {
|
|
25139
|
+
label: "规划模式",
|
|
25140
|
+
description: "先探索并写计划;批准后退出规划并开始实现。工具权限仍由询问/自动/始终批准决定。"
|
|
25141
|
+
}
|
|
25142
|
+
},
|
|
25143
|
+
description: "Explore and write a plan; approval exits planning and starts implementation. Tool permission stays Ask, Auto, or Always approve."
|
|
25144
|
+
},
|
|
25118
25145
|
{
|
|
25119
25146
|
id: "ask",
|
|
25120
25147
|
label: "Ask",
|
|
@@ -25141,6 +25168,9 @@ var GROK_PERMISSION_MODE_CATALOG = harnessPermissionModeCatalogSchema.parse({
|
|
|
25141
25168
|
],
|
|
25142
25169
|
defaultModeId: GROK_DEFAULT_PERMISSION_MODE_ID
|
|
25143
25170
|
});
|
|
25171
|
+
function isGrokPlanModeId(permissionModeId) {
|
|
25172
|
+
return String(permissionModeId ?? "") === "plan";
|
|
25173
|
+
}
|
|
25144
25174
|
function decodeGrokPermissionModeId(permissionModeId) {
|
|
25145
25175
|
const parsed = harnessPermissionModeIdSchema.parse(permissionModeId);
|
|
25146
25176
|
if (!nativePermissionModes.has(parsed)) {
|
|
@@ -25148,6 +25178,16 @@ function decodeGrokPermissionModeId(permissionModeId) {
|
|
|
25148
25178
|
}
|
|
25149
25179
|
return parsed;
|
|
25150
25180
|
}
|
|
25181
|
+
function grokCatalogPermissionModeId(permissionModeId) {
|
|
25182
|
+
if (isGrokPlanModeId(permissionModeId))
|
|
25183
|
+
return GROK_PLAN_MODE_ID;
|
|
25184
|
+
return harnessPermissionModeIdSchema.parse(decodeGrokPermissionModeId(permissionModeId));
|
|
25185
|
+
}
|
|
25186
|
+
function grokOpenPermissionPolicy(permissionModeId, kind) {
|
|
25187
|
+
if (isGrokPlanModeId(permissionModeId))
|
|
25188
|
+
return kind === "create" ? "ask" : void 0;
|
|
25189
|
+
return decodeGrokPermissionModeId(permissionModeId);
|
|
25190
|
+
}
|
|
25151
25191
|
function grokPermissionModeSessionMeta(permissionMode) {
|
|
25152
25192
|
return {
|
|
25153
25193
|
yoloMode: permissionMode === "always-approve",
|
|
@@ -25412,6 +25452,163 @@ var GrokQuestions = class {
|
|
|
25412
25452
|
}
|
|
25413
25453
|
};
|
|
25414
25454
|
|
|
25455
|
+
// dist/grok-plan-approval.js
|
|
25456
|
+
var GROK_EXIT_PLAN_MODE_METHODS = ["_x.ai/exit_plan_mode", "x.ai/exit_plan_mode"];
|
|
25457
|
+
var DECISION_ID = "plan-decision";
|
|
25458
|
+
var FEEDBACK_ID = "plan-feedback";
|
|
25459
|
+
function isRecord16(value) {
|
|
25460
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25461
|
+
}
|
|
25462
|
+
function nonEmptyString3(value) {
|
|
25463
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
25464
|
+
}
|
|
25465
|
+
function isGrokExitPlanModeMethod(method) {
|
|
25466
|
+
return GROK_EXIT_PLAN_MODE_METHODS.includes(method);
|
|
25467
|
+
}
|
|
25468
|
+
function parseGrokPlanApprovalRequest(value) {
|
|
25469
|
+
if (!isRecord16(value) || !nonEmptyString3(value.sessionId) || !nonEmptyString3(value.toolCallId)) {
|
|
25470
|
+
throw new Error("Grok plan approval requires sessionId and toolCallId");
|
|
25471
|
+
}
|
|
25472
|
+
const raw = value.planContent ?? value.plan_content;
|
|
25473
|
+
if (raw != null && typeof raw !== "string") {
|
|
25474
|
+
throw new Error("Grok plan approval planContent must be text");
|
|
25475
|
+
}
|
|
25476
|
+
return {
|
|
25477
|
+
sessionId: value.sessionId,
|
|
25478
|
+
toolCallId: value.toolCallId,
|
|
25479
|
+
planContent: typeof raw === "string" && raw.trim().length > 0 ? raw : null
|
|
25480
|
+
};
|
|
25481
|
+
}
|
|
25482
|
+
function createGrokPlanReview(request, interactionId, turnId) {
|
|
25483
|
+
const warning = "Approving this plan will exit Grok plan mode and let Grok begin implementation under the current Ask, Auto, or Always approve setting. This is not a one-time tool approval.";
|
|
25484
|
+
const prompt = request.planContent ? `${warning}
|
|
25485
|
+
|
|
25486
|
+
${request.planContent}` : `${warning}
|
|
25487
|
+
|
|
25488
|
+
# No plan written yet
|
|
25489
|
+
|
|
25490
|
+
Grok exited plan mode without a plan body. You can still approve and start implementing, stay in plan mode, or turn plan mode off.`;
|
|
25491
|
+
return {
|
|
25492
|
+
type: "question",
|
|
25493
|
+
interactionId,
|
|
25494
|
+
turnId,
|
|
25495
|
+
title: "Review plan",
|
|
25496
|
+
questions: [
|
|
25497
|
+
{
|
|
25498
|
+
id: DECISION_ID,
|
|
25499
|
+
type: "choice",
|
|
25500
|
+
prompt,
|
|
25501
|
+
options: [
|
|
25502
|
+
{
|
|
25503
|
+
value: "cancelled",
|
|
25504
|
+
label: "Stay in plan mode",
|
|
25505
|
+
description: "Keep planning. Optional comments below are sent as change requests."
|
|
25506
|
+
},
|
|
25507
|
+
{
|
|
25508
|
+
value: "approved",
|
|
25509
|
+
label: "Approve plan and start implementation",
|
|
25510
|
+
description: "Exit plan mode and begin implementing."
|
|
25511
|
+
},
|
|
25512
|
+
{
|
|
25513
|
+
value: "abandoned",
|
|
25514
|
+
label: "Exit plan mode without implementing",
|
|
25515
|
+
description: "Turn plan mode off and do not start implementation."
|
|
25516
|
+
}
|
|
25517
|
+
],
|
|
25518
|
+
multiple: false,
|
|
25519
|
+
allowOther: false,
|
|
25520
|
+
optional: false
|
|
25521
|
+
},
|
|
25522
|
+
{
|
|
25523
|
+
id: FEEDBACK_ID,
|
|
25524
|
+
type: "text",
|
|
25525
|
+
prompt: "Optional changes to request if you stay in plan mode",
|
|
25526
|
+
multiline: true,
|
|
25527
|
+
secret: false,
|
|
25528
|
+
optional: true
|
|
25529
|
+
}
|
|
25530
|
+
]
|
|
25531
|
+
};
|
|
25532
|
+
}
|
|
25533
|
+
function grokPlanReviewResponse(response) {
|
|
25534
|
+
if (response.cancelled)
|
|
25535
|
+
return { outcome: "cancelled" };
|
|
25536
|
+
const decision = response.answers[DECISION_ID]?.[0];
|
|
25537
|
+
const outcome = decision === "approved" || decision === "abandoned" ? decision : "cancelled";
|
|
25538
|
+
const feedback = response.answers[FEEDBACK_ID]?.[0]?.trim();
|
|
25539
|
+
return {
|
|
25540
|
+
outcome,
|
|
25541
|
+
...outcome === "cancelled" && feedback ? { feedback } : {}
|
|
25542
|
+
};
|
|
25543
|
+
}
|
|
25544
|
+
var GrokPlanApprovals = class {
|
|
25545
|
+
turnId;
|
|
25546
|
+
randomUUID;
|
|
25547
|
+
emit;
|
|
25548
|
+
#pending = /* @__PURE__ */ new Map();
|
|
25549
|
+
#seenToolCalls = /* @__PURE__ */ new Set();
|
|
25550
|
+
#closed = false;
|
|
25551
|
+
constructor(turnId, randomUUID3, emit) {
|
|
25552
|
+
this.turnId = turnId;
|
|
25553
|
+
this.randomUUID = randomUUID3;
|
|
25554
|
+
this.emit = emit;
|
|
25555
|
+
}
|
|
25556
|
+
has(interactionId) {
|
|
25557
|
+
return this.#pending.has(interactionId);
|
|
25558
|
+
}
|
|
25559
|
+
ask(request) {
|
|
25560
|
+
if (this.#closed || this.#seenToolCalls.has(request.toolCallId))
|
|
25561
|
+
return Promise.resolve({ outcome: "cancelled" });
|
|
25562
|
+
this.#seenToolCalls.add(request.toolCallId);
|
|
25563
|
+
const interaction = createGrokPlanReview(request, hostInteractionIdSchema.parse(this.randomUUID()), this.turnId);
|
|
25564
|
+
return new Promise((resolve) => {
|
|
25565
|
+
this.#pending.set(interaction.interactionId, { request, interaction, resolve });
|
|
25566
|
+
this.emit({ kind: "interaction", interaction });
|
|
25567
|
+
});
|
|
25568
|
+
}
|
|
25569
|
+
respond(command) {
|
|
25570
|
+
const pending = this.#pending.get(command.interactionId);
|
|
25571
|
+
if (!pending)
|
|
25572
|
+
return this.#error("invalidState", "Grok plan approval is not pending");
|
|
25573
|
+
if (command.response.type !== "question") {
|
|
25574
|
+
return this.#error("invalidRequest", "Grok plan approval requires a Question Response");
|
|
25575
|
+
}
|
|
25576
|
+
const error53 = validateHostQuestionResponse(pending.interaction, command.response);
|
|
25577
|
+
if (error53)
|
|
25578
|
+
return { ok: false, error: error53 };
|
|
25579
|
+
this.#settle(pending, grokPlanReviewResponse(command.response), command.response.cancelled ? "cancelled" : "responded");
|
|
25580
|
+
return { ok: true, value: { accepted: true } };
|
|
25581
|
+
}
|
|
25582
|
+
withdraw(toolCallId) {
|
|
25583
|
+
for (const pending of this.#pending.values()) {
|
|
25584
|
+
if (pending.request.toolCallId === toolCallId)
|
|
25585
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
25586
|
+
}
|
|
25587
|
+
}
|
|
25588
|
+
cancel() {
|
|
25589
|
+
this.#closed = true;
|
|
25590
|
+
for (const pending of this.#pending.values())
|
|
25591
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
25592
|
+
}
|
|
25593
|
+
#settle(pending, response, reason) {
|
|
25594
|
+
if (!this.#pending.delete(pending.interaction.interactionId))
|
|
25595
|
+
return;
|
|
25596
|
+
pending.resolve(response);
|
|
25597
|
+
this.emit({
|
|
25598
|
+
kind: "event",
|
|
25599
|
+
event: {
|
|
25600
|
+
type: "interaction.closed",
|
|
25601
|
+
interactionId: pending.interaction.interactionId,
|
|
25602
|
+
turnId: this.turnId,
|
|
25603
|
+
reason
|
|
25604
|
+
}
|
|
25605
|
+
});
|
|
25606
|
+
}
|
|
25607
|
+
#error(code, message) {
|
|
25608
|
+
return { ok: false, error: { code, message, retryable: false } };
|
|
25609
|
+
}
|
|
25610
|
+
};
|
|
25611
|
+
|
|
25415
25612
|
// dist/grok-interject.js
|
|
25416
25613
|
var GROK_INTERJECT_METHOD = "x.ai/interject";
|
|
25417
25614
|
var GROK_INTERJECT_FALLBACK_METHOD = "_x.ai/interject";
|
|
@@ -25445,16 +25642,16 @@ var GrokTransportError = class extends Error {
|
|
|
25445
25642
|
this.name = "GrokTransportError";
|
|
25446
25643
|
}
|
|
25447
25644
|
};
|
|
25448
|
-
function
|
|
25645
|
+
function isRecord17(value) {
|
|
25449
25646
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25450
25647
|
}
|
|
25451
25648
|
function acpToolName(update, metadata) {
|
|
25452
|
-
if (!
|
|
25649
|
+
if (!isRecord17(update))
|
|
25453
25650
|
return void 0;
|
|
25454
25651
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
25455
25652
|
return update.name;
|
|
25456
|
-
const meta3 =
|
|
25457
|
-
const tool = meta3 &&
|
|
25653
|
+
const meta3 = isRecord17(update._meta) ? update._meta : metadata;
|
|
25654
|
+
const tool = meta3 && isRecord17(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
25458
25655
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
25459
25656
|
}
|
|
25460
25657
|
function errorText(error53) {
|
|
@@ -25510,20 +25707,20 @@ function signalProcessTree(child, signal) {
|
|
|
25510
25707
|
try {
|
|
25511
25708
|
process.kill(-child.pid, signal);
|
|
25512
25709
|
} catch (error53) {
|
|
25513
|
-
if (!
|
|
25710
|
+
if (!isRecord17(error53) || error53.code === "ESRCH")
|
|
25514
25711
|
return;
|
|
25515
25712
|
try {
|
|
25516
25713
|
child.kill(signal);
|
|
25517
25714
|
} catch (fallback) {
|
|
25518
|
-
if (!
|
|
25715
|
+
if (!isRecord17(fallback) || fallback.code !== "ESRCH")
|
|
25519
25716
|
throw fallback;
|
|
25520
25717
|
}
|
|
25521
25718
|
}
|
|
25522
25719
|
}
|
|
25523
25720
|
function grokNotificationMetadata(envelope, update) {
|
|
25524
|
-
if (!
|
|
25721
|
+
if (!isRecord17(envelope) && !isRecord17(update))
|
|
25525
25722
|
return void 0;
|
|
25526
|
-
return { ...
|
|
25723
|
+
return { ...isRecord17(update) ? update : {}, ...isRecord17(envelope) ? envelope : {} };
|
|
25527
25724
|
}
|
|
25528
25725
|
function transportEvent(update, metadata) {
|
|
25529
25726
|
const extension = update;
|
|
@@ -25555,6 +25752,12 @@ function transportEvent(update, metadata) {
|
|
|
25555
25752
|
...metadata ? { metadata } : {}
|
|
25556
25753
|
};
|
|
25557
25754
|
}
|
|
25755
|
+
if (extension.sessionUpdate === "current_mode_update") {
|
|
25756
|
+
const modeId = typeof extension.currentModeId === "string" ? extension.currentModeId : typeof extension.current_mode_id === "string" ? extension.current_mode_id : "";
|
|
25757
|
+
if (!modeId)
|
|
25758
|
+
return null;
|
|
25759
|
+
return { type: "session.mode", modeId, ...metadata ? { metadata } : {} };
|
|
25760
|
+
}
|
|
25558
25761
|
if (extension.sessionUpdate === "rewind_marker") {
|
|
25559
25762
|
const targetPromptIndex = typeof extension.targetPromptIndex === "number" ? extension.targetPromptIndex : typeof extension.target_prompt_index === "number" ? extension.target_prompt_index : null;
|
|
25560
25763
|
if (targetPromptIndex === null || !Number.isInteger(targetPromptIndex) || targetPromptIndex < 0) {
|
|
@@ -25646,7 +25849,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
25646
25849
|
}
|
|
25647
25850
|
}
|
|
25648
25851
|
function isMissingFile(error53) {
|
|
25649
|
-
return
|
|
25852
|
+
return isRecord17(error53) && error53.code === "ENOENT";
|
|
25650
25853
|
}
|
|
25651
25854
|
async function locateGrokNativeSession(options, sessionId) {
|
|
25652
25855
|
if (sessionId.length === 0)
|
|
@@ -25669,7 +25872,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25669
25872
|
try {
|
|
25670
25873
|
summaryRaw = await readFile5(path17.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
25671
25874
|
} catch (error53) {
|
|
25672
|
-
if (isMissingFile(error53) ||
|
|
25875
|
+
if (isMissingFile(error53) || isRecord17(error53) && error53.code === "ENOTDIR")
|
|
25673
25876
|
continue;
|
|
25674
25877
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
25675
25878
|
cause: error53
|
|
@@ -25681,10 +25884,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25681
25884
|
} catch {
|
|
25682
25885
|
continue;
|
|
25683
25886
|
}
|
|
25684
|
-
if (!
|
|
25887
|
+
if (!isRecord17(parsed))
|
|
25685
25888
|
continue;
|
|
25686
25889
|
const info = parsed.info;
|
|
25687
|
-
const cwd =
|
|
25890
|
+
const cwd = isRecord17(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path17.resolve(info.cwd) : path17.resolve(decodeURIComponent(entry.name));
|
|
25688
25891
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path17.resolve(parsed.source_workspace_dir) : void 0;
|
|
25689
25892
|
matches.push({
|
|
25690
25893
|
cwd,
|
|
@@ -25717,10 +25920,10 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
25717
25920
|
} catch {
|
|
25718
25921
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
25719
25922
|
}
|
|
25720
|
-
if (!
|
|
25923
|
+
if (!isRecord17(record3) || !isRecord17(record3.params))
|
|
25721
25924
|
continue;
|
|
25722
25925
|
const params = record3.params;
|
|
25723
|
-
if (params.sessionId !== sessionId || !
|
|
25926
|
+
if (params.sessionId !== sessionId || !isRecord17(params.update))
|
|
25724
25927
|
continue;
|
|
25725
25928
|
let metadata = grokNotificationMetadata(params._meta, params.update._meta);
|
|
25726
25929
|
if (typeof record3.timestamp === "number" && Number.isFinite(record3.timestamp))
|
|
@@ -25790,7 +25993,7 @@ var GrokAcpTransport = class {
|
|
|
25790
25993
|
if (!this.#connection)
|
|
25791
25994
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
25792
25995
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
25793
|
-
return
|
|
25996
|
+
return isRecord17(result) ? result.usage : void 0;
|
|
25794
25997
|
}
|
|
25795
25998
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
25796
25999
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -25821,7 +26024,7 @@ var GrokAcpTransport = class {
|
|
|
25821
26024
|
let session;
|
|
25822
26025
|
let sessionId;
|
|
25823
26026
|
if (input.kind === "create") {
|
|
25824
|
-
const permissionMode =
|
|
26027
|
+
const permissionMode = grokOpenPermissionPolicy(input.permissionModeId, "create");
|
|
25825
26028
|
const created = await withTimeout(connection.newSession({
|
|
25826
26029
|
cwd: this.#options.cwd,
|
|
25827
26030
|
mcpServers: [],
|
|
@@ -25850,7 +26053,7 @@ var GrokAcpTransport = class {
|
|
|
25850
26053
|
}
|
|
25851
26054
|
sessionId = forked.newSessionId;
|
|
25852
26055
|
} else {
|
|
25853
|
-
const permissionMode = input.kind === "resume" ?
|
|
26056
|
+
const permissionMode = input.kind === "resume" ? grokOpenPermissionPolicy(input.permissionModeId, "resume") : void 0;
|
|
25854
26057
|
session = await withTimeout(connection.loadSession({
|
|
25855
26058
|
cwd: this.#options.cwd,
|
|
25856
26059
|
mcpServers: [],
|
|
@@ -25895,7 +26098,7 @@ var GrokAcpTransport = class {
|
|
|
25895
26098
|
sessionId: this.#sessionId,
|
|
25896
26099
|
toolCallId
|
|
25897
26100
|
}), 3e3, "Grok question activity");
|
|
25898
|
-
if (!
|
|
26101
|
+
if (!isRecord17(raw) || !("timeout" in raw))
|
|
25899
26102
|
throw new GrokTransportError("protocolError", "Invalid Grok activity acknowledgement");
|
|
25900
26103
|
return raw.timeout === null ? null : questionAutoResolutionSchema.parse(raw.timeout);
|
|
25901
26104
|
} catch (error53) {
|
|
@@ -26037,7 +26240,7 @@ var GrokAcpTransport = class {
|
|
|
26037
26240
|
this.#goalPrompts--;
|
|
26038
26241
|
}
|
|
26039
26242
|
}
|
|
26040
|
-
async runTurn(text, onEvent, onPermission, onElicitation, onQuestion = async () => ({ outcome: "cancelled" })) {
|
|
26243
|
+
async runTurn(text, onEvent, onPermission, onElicitation, onQuestion = async () => ({ outcome: "cancelled" }), onPlanApproval = async () => ({ outcome: "cancelled" })) {
|
|
26041
26244
|
const connection = this.#connection;
|
|
26042
26245
|
if (!connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
26043
26246
|
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
@@ -26046,7 +26249,7 @@ var GrokAcpTransport = class {
|
|
|
26046
26249
|
throw new Error("Grok ACP Session already has an active Prompt");
|
|
26047
26250
|
if (this.#permissionConfirmation)
|
|
26048
26251
|
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
26049
|
-
const active = { onEvent, onPermission, onElicitation, onQuestion };
|
|
26252
|
+
const active = { onEvent, onPermission, onElicitation, onQuestion, onPlanApproval };
|
|
26050
26253
|
this.#activePrompt = active;
|
|
26051
26254
|
try {
|
|
26052
26255
|
const historyStart = (await this.getHistory()).length;
|
|
@@ -26167,7 +26370,7 @@ var GrokAcpTransport = class {
|
|
|
26167
26370
|
}
|
|
26168
26371
|
} : {}
|
|
26169
26372
|
});
|
|
26170
|
-
if (!
|
|
26373
|
+
if (!isRecord17(response) || !isRecord17(response._meta) || !isRecord17(response._meta.model)) {
|
|
26171
26374
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
26172
26375
|
}
|
|
26173
26376
|
const selected = response._meta.model.Ok;
|
|
@@ -26207,7 +26410,7 @@ var GrokAcpTransport = class {
|
|
|
26207
26410
|
permission_mode: mode
|
|
26208
26411
|
});
|
|
26209
26412
|
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
26210
|
-
if (!
|
|
26413
|
+
if (!isRecord17(response) || !isRecord17(response.result) || response.result.sessionId !== sessionId) {
|
|
26211
26414
|
throw new Error("Grok did not confirm the target Session");
|
|
26212
26415
|
}
|
|
26213
26416
|
})()
|
|
@@ -26223,6 +26426,17 @@ var GrokAcpTransport = class {
|
|
|
26223
26426
|
this.#permissionConfirmation = null;
|
|
26224
26427
|
}
|
|
26225
26428
|
}
|
|
26429
|
+
async setSessionMode(modeId) {
|
|
26430
|
+
const connection = this.#connection;
|
|
26431
|
+
const sessionId = this.#sessionId;
|
|
26432
|
+
if (!connection || !sessionId || this.#closed || this.#closing) {
|
|
26433
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
26434
|
+
}
|
|
26435
|
+
if (this.#activePrompt || this.#activeCompact || this.#permissionConfirmation) {
|
|
26436
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
26437
|
+
}
|
|
26438
|
+
await withTimeout(connection.request("session/set_mode", { sessionId, modeId }), this.#options.commandTimeoutMs, "Grok Session Mode");
|
|
26439
|
+
}
|
|
26226
26440
|
close() {
|
|
26227
26441
|
return this.#closePromise ??= this.#close();
|
|
26228
26442
|
}
|
|
@@ -26282,7 +26496,7 @@ var GrokAcpTransport = class {
|
|
|
26282
26496
|
if (!isGrokExtensionSessionUpdateMethod(method) && !isGrokBackgroundNotificationMethod(method)) {
|
|
26283
26497
|
return;
|
|
26284
26498
|
}
|
|
26285
|
-
if (typeof params.sessionId !== "string" || !
|
|
26499
|
+
if (typeof params.sessionId !== "string" || !isRecord17(params.update))
|
|
26286
26500
|
return;
|
|
26287
26501
|
this.#handleUpdate(params);
|
|
26288
26502
|
}
|
|
@@ -26292,7 +26506,7 @@ var GrokAcpTransport = class {
|
|
|
26292
26506
|
taskId,
|
|
26293
26507
|
source
|
|
26294
26508
|
});
|
|
26295
|
-
if (!
|
|
26509
|
+
if (!isRecord17(result) || result.taskId !== taskId || !["killed", "already_exited", "not_found"].includes(String(result.outcome)))
|
|
26296
26510
|
throw new GrokTransportError("protocolError", "Malformed Grok task kill response");
|
|
26297
26511
|
return result.outcome;
|
|
26298
26512
|
}
|
|
@@ -26307,7 +26521,7 @@ var GrokAcpTransport = class {
|
|
|
26307
26521
|
sessionId: this.sessionId,
|
|
26308
26522
|
taskId
|
|
26309
26523
|
});
|
|
26310
|
-
if (!
|
|
26524
|
+
if (!isRecord17(result) || result.taskId !== taskId || typeof result.deleted !== "boolean")
|
|
26311
26525
|
throw new GrokTransportError("protocolError", "Malformed Grok scheduler delete response");
|
|
26312
26526
|
return result.deleted;
|
|
26313
26527
|
}
|
|
@@ -26319,21 +26533,21 @@ var GrokAcpTransport = class {
|
|
|
26319
26533
|
try {
|
|
26320
26534
|
raw = await withTimeout(this.#connection.request(method, params), this.#options.commandTimeoutMs, `Grok ${method}`);
|
|
26321
26535
|
} catch (error53) {
|
|
26322
|
-
if (!
|
|
26536
|
+
if (!isRecord17(error53) || error53.code !== -32601)
|
|
26323
26537
|
throw error53;
|
|
26324
26538
|
try {
|
|
26325
26539
|
raw = await withTimeout(this.#connection.request(`_${method}`, params), this.#options.commandTimeoutMs, `Grok _${method}`);
|
|
26326
26540
|
} catch (fallback) {
|
|
26327
|
-
if (
|
|
26541
|
+
if (isRecord17(fallback) && fallback.code === -32601)
|
|
26328
26542
|
throw new GrokTransportError("unsupported", `Grok does not support ${method}`);
|
|
26329
26543
|
throw fallback;
|
|
26330
26544
|
}
|
|
26331
26545
|
}
|
|
26332
|
-
if (
|
|
26333
|
-
const message = typeof raw.error === "string" ? raw.error :
|
|
26546
|
+
if (isRecord17(raw) && raw.error !== void 0 && raw.error !== null) {
|
|
26547
|
+
const message = typeof raw.error === "string" ? raw.error : isRecord17(raw.error) && typeof raw.error.message === "string" ? raw.error.message : `Grok ${method} failed`;
|
|
26334
26548
|
throw new GrokTransportError("unavailable", message);
|
|
26335
26549
|
}
|
|
26336
|
-
return
|
|
26550
|
+
return isRecord17(raw) && "result" in raw ? raw.result : raw;
|
|
26337
26551
|
}
|
|
26338
26552
|
#handlePermission(params) {
|
|
26339
26553
|
const observer = this.#activePrompt ?? this.#background;
|
|
@@ -26358,6 +26572,19 @@ var GrokAcpTransport = class {
|
|
|
26358
26572
|
return { outcome: "cancelled" };
|
|
26359
26573
|
return { ...await activePrompt.onQuestion(request) };
|
|
26360
26574
|
}
|
|
26575
|
+
if (isGrokExitPlanModeMethod(method)) {
|
|
26576
|
+
let request;
|
|
26577
|
+
try {
|
|
26578
|
+
request = parseGrokPlanApprovalRequest(params);
|
|
26579
|
+
} catch (error53) {
|
|
26580
|
+
throw RequestError.invalidParams(void 0, error53 instanceof Error ? error53.message : "Invalid Grok plan approval");
|
|
26581
|
+
}
|
|
26582
|
+
if (!activePrompt || request.sessionId !== this.#sessionId)
|
|
26583
|
+
return { outcome: "cancelled" };
|
|
26584
|
+
return {
|
|
26585
|
+
...await activePrompt.onPlanApproval?.(request) ?? { outcome: "cancelled" }
|
|
26586
|
+
};
|
|
26587
|
+
}
|
|
26361
26588
|
if (method !== GROK_MCP_ELICIT_METHOD) {
|
|
26362
26589
|
throw RequestError.methodNotFound(method);
|
|
26363
26590
|
}
|
|
@@ -26505,7 +26732,7 @@ var SessionImportScope = class {
|
|
|
26505
26732
|
// dist/session-import.js
|
|
26506
26733
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
26507
26734
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
26508
|
-
function
|
|
26735
|
+
function isRecord18(value) {
|
|
26509
26736
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26510
26737
|
}
|
|
26511
26738
|
async function readJson(file2, signal) {
|
|
@@ -26518,7 +26745,7 @@ function processAlive(pid) {
|
|
|
26518
26745
|
process.kill(pid, 0);
|
|
26519
26746
|
return true;
|
|
26520
26747
|
} catch (error53) {
|
|
26521
|
-
return
|
|
26748
|
+
return isRecord18(error53) && error53.code === "EPERM";
|
|
26522
26749
|
}
|
|
26523
26750
|
}
|
|
26524
26751
|
async function firstUserText(file2, signal) {
|
|
@@ -26535,10 +26762,10 @@ async function firstUserText(file2, signal) {
|
|
|
26535
26762
|
} catch {
|
|
26536
26763
|
continue;
|
|
26537
26764
|
}
|
|
26538
|
-
const update =
|
|
26539
|
-
if (!
|
|
26765
|
+
const update = isRecord18(entry) && isRecord18(entry.params) ? entry.params.update : null;
|
|
26766
|
+
if (!isRecord18(update) || update.sessionUpdate !== "user_message_chunk")
|
|
26540
26767
|
continue;
|
|
26541
|
-
const text =
|
|
26768
|
+
const text = isRecord18(update.content) ? update.content.text : null;
|
|
26542
26769
|
return typeof text === "string" ? text : "";
|
|
26543
26770
|
}
|
|
26544
26771
|
return null;
|
|
@@ -26615,7 +26842,7 @@ var GrokSessionImport = class {
|
|
|
26615
26842
|
if (!Array.isArray(entries))
|
|
26616
26843
|
return active;
|
|
26617
26844
|
for (const entry of entries) {
|
|
26618
|
-
if (
|
|
26845
|
+
if (isRecord18(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
26619
26846
|
active.add(entry.session_id);
|
|
26620
26847
|
}
|
|
26621
26848
|
return active;
|
|
@@ -26664,7 +26891,7 @@ var GrokSessionImport = class {
|
|
|
26664
26891
|
return null;
|
|
26665
26892
|
try {
|
|
26666
26893
|
const summary = await readJson(files[0], signal);
|
|
26667
|
-
if (!
|
|
26894
|
+
if (!isRecord18(summary) || !isRecord18(summary.info) || summary.info.id !== nativeSessionId)
|
|
26668
26895
|
return null;
|
|
26669
26896
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
26670
26897
|
return null;
|
|
@@ -27386,17 +27613,17 @@ var GrokBackgroundItems = class {
|
|
|
27386
27613
|
await handle.close();
|
|
27387
27614
|
}
|
|
27388
27615
|
} catch (error53) {
|
|
27389
|
-
if (
|
|
27616
|
+
if (isRecord19(error53) && error53.code === "ENOENT")
|
|
27390
27617
|
return;
|
|
27391
27618
|
}
|
|
27392
27619
|
}
|
|
27393
27620
|
};
|
|
27394
|
-
function
|
|
27621
|
+
function isRecord19(value) {
|
|
27395
27622
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27396
27623
|
}
|
|
27397
27624
|
|
|
27398
27625
|
// dist/grok-models.js
|
|
27399
|
-
function
|
|
27626
|
+
function isRecord20(value) {
|
|
27400
27627
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27401
27628
|
}
|
|
27402
27629
|
function nonBlank(value) {
|
|
@@ -27408,7 +27635,7 @@ function thinkingOptions(value) {
|
|
|
27408
27635
|
const seen = /* @__PURE__ */ new Set();
|
|
27409
27636
|
const options = [];
|
|
27410
27637
|
for (const candidate of value) {
|
|
27411
|
-
if (!
|
|
27638
|
+
if (!isRecord20(candidate) || !nonBlank(candidate.label))
|
|
27412
27639
|
continue;
|
|
27413
27640
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
27414
27641
|
if (!id.success || seen.has(id.data))
|
|
@@ -27419,7 +27646,7 @@ function thinkingOptions(value) {
|
|
|
27419
27646
|
return options;
|
|
27420
27647
|
}
|
|
27421
27648
|
function parseGrokModelState(value) {
|
|
27422
|
-
if (!
|
|
27649
|
+
if (!isRecord20(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
27423
27650
|
return null;
|
|
27424
27651
|
}
|
|
27425
27652
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -27431,12 +27658,12 @@ function parseGrokModelState(value) {
|
|
|
27431
27658
|
const models = [];
|
|
27432
27659
|
let currentThinkingOptionId;
|
|
27433
27660
|
for (const candidate of value.availableModels) {
|
|
27434
|
-
if (!
|
|
27661
|
+
if (!isRecord20(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
27435
27662
|
continue;
|
|
27436
27663
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
27437
27664
|
if (!ref.success)
|
|
27438
27665
|
continue;
|
|
27439
|
-
const metadata =
|
|
27666
|
+
const metadata = isRecord20(candidate._meta) ? candidate._meta : {};
|
|
27440
27667
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
27441
27668
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
27442
27669
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -27475,10 +27702,10 @@ function parseGrokModelState(value) {
|
|
|
27475
27702
|
};
|
|
27476
27703
|
}
|
|
27477
27704
|
function modelStateFromInitialize(response) {
|
|
27478
|
-
return parseGrokModelState(
|
|
27705
|
+
return parseGrokModelState(isRecord20(response._meta) ? response._meta.modelState : void 0);
|
|
27479
27706
|
}
|
|
27480
27707
|
function modelStateFromSessionResponse(response) {
|
|
27481
|
-
return parseGrokModelState(
|
|
27708
|
+
return parseGrokModelState(isRecord20(response) ? response.models : void 0);
|
|
27482
27709
|
}
|
|
27483
27710
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
27484
27711
|
const selectedModel = model2;
|
|
@@ -27505,12 +27732,12 @@ var GROK_SETTINGS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/settings";
|
|
|
27505
27732
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
27506
27733
|
var PLAN_TIMEOUT_MS = 2e3;
|
|
27507
27734
|
function parseGrokPlan(value) {
|
|
27508
|
-
if (!
|
|
27735
|
+
if (!isRecord21(value) || typeof value.subscription_tier_display !== "string")
|
|
27509
27736
|
return void 0;
|
|
27510
27737
|
const plan = value.subscription_tier_display.trim();
|
|
27511
27738
|
return plan && plan.length <= 128 && !/[\u0000-\u001f\u007f]/u.test(plan) ? plan : void 0;
|
|
27512
27739
|
}
|
|
27513
|
-
function
|
|
27740
|
+
function isRecord21(value) {
|
|
27514
27741
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27515
27742
|
}
|
|
27516
27743
|
function finitePercent(value) {
|
|
@@ -27519,7 +27746,7 @@ function finitePercent(value) {
|
|
|
27519
27746
|
return Math.min(100, Math.max(0, value));
|
|
27520
27747
|
}
|
|
27521
27748
|
function nonNegativeCentValue(value) {
|
|
27522
|
-
if (!
|
|
27749
|
+
if (!isRecord21(value))
|
|
27523
27750
|
return void 0;
|
|
27524
27751
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
27525
27752
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -27543,7 +27770,7 @@ function productUsageFrom(value) {
|
|
|
27543
27770
|
if (!Array.isArray(value))
|
|
27544
27771
|
return void 0;
|
|
27545
27772
|
const products = value.flatMap((entry) => {
|
|
27546
|
-
if (!
|
|
27773
|
+
if (!isRecord21(entry) || typeof entry.product !== "string")
|
|
27547
27774
|
return [];
|
|
27548
27775
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
27549
27776
|
const labels = {
|
|
@@ -27564,10 +27791,10 @@ function productUsageFrom(value) {
|
|
|
27564
27791
|
return products.length > 0 ? products : void 0;
|
|
27565
27792
|
}
|
|
27566
27793
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
27567
|
-
if (!
|
|
27794
|
+
if (!isRecord21(value) || !isRecord21(value.config))
|
|
27568
27795
|
return null;
|
|
27569
27796
|
const config2 = value.config;
|
|
27570
|
-
const period =
|
|
27797
|
+
const period = isRecord21(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
27571
27798
|
const periodType = periodTypeFrom(period?.type);
|
|
27572
27799
|
const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
|
|
27573
27800
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -27594,11 +27821,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
27594
27821
|
};
|
|
27595
27822
|
}
|
|
27596
27823
|
function selectAccessToken(auth, now) {
|
|
27597
|
-
if (!
|
|
27824
|
+
if (!isRecord21(auth))
|
|
27598
27825
|
return null;
|
|
27599
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
27826
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord21(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
|
|
27600
27827
|
for (const [, value] of entries) {
|
|
27601
|
-
if (!
|
|
27828
|
+
if (!isRecord21(value) || typeof value.key !== "string")
|
|
27602
27829
|
continue;
|
|
27603
27830
|
if (typeof value.expires_at === "string") {
|
|
27604
27831
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -27674,7 +27901,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
27674
27901
|
|
|
27675
27902
|
// dist/grok-usage.js
|
|
27676
27903
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
27677
|
-
function
|
|
27904
|
+
function isRecord22(value) {
|
|
27678
27905
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27679
27906
|
}
|
|
27680
27907
|
function optionalToken(value) {
|
|
@@ -27691,7 +27918,7 @@ function combineUsage(base, next) {
|
|
|
27691
27918
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
27692
27919
|
}
|
|
27693
27920
|
function usageFromNative(value) {
|
|
27694
|
-
if (!
|
|
27921
|
+
if (!isRecord22(value))
|
|
27695
27922
|
return null;
|
|
27696
27923
|
const inputTokens = optionalToken(value.inputTokens);
|
|
27697
27924
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -27715,7 +27942,7 @@ function usageFromNative(value) {
|
|
|
27715
27942
|
}
|
|
27716
27943
|
}
|
|
27717
27944
|
function usageFromResponse(value) {
|
|
27718
|
-
if (!
|
|
27945
|
+
if (!isRecord22(value))
|
|
27719
27946
|
return null;
|
|
27720
27947
|
const buckets = [
|
|
27721
27948
|
value.input_tokens,
|
|
@@ -27815,7 +28042,7 @@ var GrokTurnUsage = class {
|
|
|
27815
28042
|
}
|
|
27816
28043
|
};
|
|
27817
28044
|
function usageFromSignals(value) {
|
|
27818
|
-
if (!
|
|
28045
|
+
if (!isRecord22(value))
|
|
27819
28046
|
return null;
|
|
27820
28047
|
try {
|
|
27821
28048
|
return parseHostUsage({
|
|
@@ -27835,7 +28062,7 @@ var summedUsageFields = [
|
|
|
27835
28062
|
"totalTokens"
|
|
27836
28063
|
];
|
|
27837
28064
|
function nativeCostTicks(value) {
|
|
27838
|
-
if (!
|
|
28065
|
+
if (!isRecord22(value))
|
|
27839
28066
|
return void 0;
|
|
27840
28067
|
const ticks = value.costUsdTicks;
|
|
27841
28068
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -27843,7 +28070,7 @@ function nativeCostTicks(value) {
|
|
|
27843
28070
|
return ticks;
|
|
27844
28071
|
}
|
|
27845
28072
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
27846
|
-
if (!
|
|
28073
|
+
if (!isRecord22(value))
|
|
27847
28074
|
return void 0;
|
|
27848
28075
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
27849
28076
|
return void 0;
|
|
@@ -27874,7 +28101,7 @@ function sessionUsageFromHistory(events) {
|
|
|
27874
28101
|
continue;
|
|
27875
28102
|
const usage = usageFromNative(event.usage);
|
|
27876
28103
|
const ticks2 = nativeCostTicks(event.usage);
|
|
27877
|
-
const complete =
|
|
28104
|
+
const complete = isRecord22(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
27878
28105
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
27879
28106
|
}
|
|
27880
28107
|
if (latestByKey.size === 0)
|
|
@@ -27928,7 +28155,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
27928
28155
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
27929
28156
|
try {
|
|
27930
28157
|
if (update?.sessionUpdate === "usage_update") {
|
|
27931
|
-
const cost =
|
|
28158
|
+
const cost = isRecord22(update.cost) ? update.cost : null;
|
|
27932
28159
|
return parseHostUsage({
|
|
27933
28160
|
contextUsedTokens: update.used,
|
|
27934
28161
|
contextWindowTokens: update.size,
|
|
@@ -28056,6 +28283,7 @@ var GrokHarnessSession = class {
|
|
|
28056
28283
|
#configuring = false;
|
|
28057
28284
|
#phase = "open";
|
|
28058
28285
|
#state;
|
|
28286
|
+
#permissionPolicyId;
|
|
28059
28287
|
#usage = null;
|
|
28060
28288
|
#initialCostUsd;
|
|
28061
28289
|
#costRequest = 0;
|
|
@@ -28132,7 +28360,9 @@ var GrokHarnessSession = class {
|
|
|
28132
28360
|
...capabilitiesForModels(this.#modelState),
|
|
28133
28361
|
steer: this.#canSteerActiveTurn()
|
|
28134
28362
|
});
|
|
28135
|
-
this.#
|
|
28363
|
+
this.#permissionPolicyId = isGrokPlanModeId(options.initialPermissionModeId) ? GROK_DEFAULT_PERMISSION_MODE_ID : options.initialPermissionModeId;
|
|
28364
|
+
const restoredPlan = options.history.findLast((event) => event.type === "session.mode")?.modeId === "plan";
|
|
28365
|
+
this.#state = stateForGrokModel(modelState, { nativeRef: nativeRef(opened.sessionId) }, modelState.currentModel, modelState.currentThinkingOptionId, isGrokPlanModeId(options.initialPermissionModeId) || restoredPlan ? GROK_PLAN_MODE_ID : options.initialPermissionModeId);
|
|
28136
28366
|
this.initialState = this.#state;
|
|
28137
28367
|
this.#snapshot = {
|
|
28138
28368
|
...mapGrokReplay(options.history, this.harnessId, opened.sessionId, cwd, options.knownTurnRefs, this.#toolOutputLimit, options.sessionDirectory),
|
|
@@ -28207,6 +28437,10 @@ var GrokHarnessSession = class {
|
|
|
28207
28437
|
onQuestion: async (request) => {
|
|
28208
28438
|
await this.#backgroundQueue;
|
|
28209
28439
|
return this.#active ? this.#active.questions.ask(request) : { outcome: "cancelled" };
|
|
28440
|
+
},
|
|
28441
|
+
onPlanApproval: async (request) => {
|
|
28442
|
+
await this.#backgroundQueue;
|
|
28443
|
+
return this.#active ? this.#active.planApprovals.ask(request) : { outcome: "cancelled" };
|
|
28210
28444
|
}
|
|
28211
28445
|
});
|
|
28212
28446
|
void goals?.read();
|
|
@@ -28312,7 +28546,10 @@ var GrokHarnessSession = class {
|
|
|
28312
28546
|
const active = this.#newActive(command, catalogCommand);
|
|
28313
28547
|
this.#active = active;
|
|
28314
28548
|
this.#event({ type: "turn.started", turnId: command.turnId });
|
|
28315
|
-
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#requestElicitation(active, request), (request) => this.#active === active && this.#phase === "open" && !active.cancellationRequested ? active.questions.ask(request) : Promise.resolve({ outcome: "cancelled" })
|
|
28549
|
+
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#requestElicitation(active, request), (request) => this.#active === active && this.#phase === "open" && !active.cancellationRequested ? active.questions.ask(request) : Promise.resolve({ outcome: "cancelled" }), (request) => this.#active === active && this.#phase === "open" && !active.cancellationRequested ? active.planApprovals.ask(request) : Promise.resolve({ outcome: "cancelled" })).finally(() => {
|
|
28550
|
+
active.questions.cancel();
|
|
28551
|
+
active.planApprovals.cancel();
|
|
28552
|
+
}).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
28316
28553
|
status: "failed",
|
|
28317
28554
|
error: normalizeError(error53, "nativeFailure")
|
|
28318
28555
|
}));
|
|
@@ -28379,6 +28616,7 @@ var GrokHarnessSession = class {
|
|
|
28379
28616
|
approvals: /* @__PURE__ */ new Map(),
|
|
28380
28617
|
elicitations: /* @__PURE__ */ new Map(),
|
|
28381
28618
|
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
28619
|
+
planApprovals: new GrokPlanApprovals(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
28382
28620
|
cancellationRequested: false,
|
|
28383
28621
|
beforeNativeTurnKeys: new Set(this.#snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey)),
|
|
28384
28622
|
historyStart: this.#historyLength,
|
|
@@ -28535,6 +28773,10 @@ var GrokHarnessSession = class {
|
|
|
28535
28773
|
await this.#goalCommand;
|
|
28536
28774
|
if (this.#phase !== "open")
|
|
28537
28775
|
return;
|
|
28776
|
+
if (event.type === "session.mode") {
|
|
28777
|
+
this.#applyNativeSessionMode(event.modeId);
|
|
28778
|
+
return;
|
|
28779
|
+
}
|
|
28538
28780
|
if (this.#bufferGoalHelper(event))
|
|
28539
28781
|
return;
|
|
28540
28782
|
if (!this.#active && event.type === "subagent.finished") {
|
|
@@ -28759,6 +29001,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28759
29001
|
approvals: /* @__PURE__ */ new Map(),
|
|
28760
29002
|
elicitations: /* @__PURE__ */ new Map(),
|
|
28761
29003
|
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
29004
|
+
planApprovals: new GrokPlanApprovals(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
28762
29005
|
cancellationRequested: false,
|
|
28763
29006
|
beforeNativeTurnKeys: /* @__PURE__ */ new Set(),
|
|
28764
29007
|
historyStart: this.#historyLength,
|
|
@@ -28885,7 +29128,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28885
29128
|
}
|
|
28886
29129
|
async #selectPermissionMode(command) {
|
|
28887
29130
|
try {
|
|
28888
|
-
|
|
29131
|
+
grokCatalogPermissionModeId(command.permissionModeId);
|
|
28889
29132
|
} catch {
|
|
28890
29133
|
return {
|
|
28891
29134
|
ok: false,
|
|
@@ -28906,12 +29149,50 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28906
29149
|
}
|
|
28907
29150
|
};
|
|
28908
29151
|
}
|
|
29152
|
+
const wantPlan = isGrokPlanModeId(command.permissionModeId);
|
|
29153
|
+
const inPlan = isGrokPlanModeId(this.#state.effectivePermissionModeId);
|
|
29154
|
+
if (wantPlan && !this.#transport.setSessionMode) {
|
|
29155
|
+
return {
|
|
29156
|
+
ok: false,
|
|
29157
|
+
error: {
|
|
29158
|
+
code: "unsupported",
|
|
29159
|
+
message: "Grok Session Mode is unavailable",
|
|
29160
|
+
retryable: false
|
|
29161
|
+
}
|
|
29162
|
+
};
|
|
29163
|
+
}
|
|
28909
29164
|
this.#configuring = true;
|
|
28910
29165
|
try {
|
|
28911
|
-
|
|
29166
|
+
if (wantPlan) {
|
|
29167
|
+
if (!inPlan)
|
|
29168
|
+
await this.#transport.setSessionMode?.("plan");
|
|
29169
|
+
} else {
|
|
29170
|
+
if (inPlan) {
|
|
29171
|
+
try {
|
|
29172
|
+
await this.#transport.setSessionMode?.("default");
|
|
29173
|
+
} catch (error53) {
|
|
29174
|
+
return { ok: false, error: normalizeError(error53, "nativeFailure") };
|
|
29175
|
+
}
|
|
29176
|
+
}
|
|
29177
|
+
try {
|
|
29178
|
+
await this.#transport.setPermissionMode(command.permissionModeId);
|
|
29179
|
+
} catch (error53) {
|
|
29180
|
+
if (inPlan) {
|
|
29181
|
+
try {
|
|
29182
|
+
await this.#transport.setSessionMode?.("plan");
|
|
29183
|
+
} catch {
|
|
29184
|
+
}
|
|
29185
|
+
}
|
|
29186
|
+
throw error53;
|
|
29187
|
+
}
|
|
29188
|
+
this.#permissionPolicyId = command.permissionModeId;
|
|
29189
|
+
}
|
|
28912
29190
|
if (this.#phase !== "open")
|
|
28913
29191
|
return { ok: false, error: invalidState("Grok Session is closed") };
|
|
28914
|
-
this.#state = {
|
|
29192
|
+
this.#state = {
|
|
29193
|
+
...this.#state,
|
|
29194
|
+
effectivePermissionModeId: wantPlan ? GROK_PLAN_MODE_ID : command.permissionModeId
|
|
29195
|
+
};
|
|
28915
29196
|
this.#event({ type: "session.state.changed", state: this.#state });
|
|
28916
29197
|
return { ok: true, value: { completed: true } };
|
|
28917
29198
|
} catch (error53) {
|
|
@@ -28933,6 +29214,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28933
29214
|
}
|
|
28934
29215
|
this.#cancelActiveElicitations(active);
|
|
28935
29216
|
active.questions.cancel();
|
|
29217
|
+
active.planApprovals.cancel();
|
|
28936
29218
|
try {
|
|
28937
29219
|
await this.#transport.cancel();
|
|
28938
29220
|
return { ok: true, value: { cancellationRequested: true } };
|
|
@@ -28946,6 +29228,8 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28946
29228
|
const elicitation = active?.elicitations.get(command.interactionId);
|
|
28947
29229
|
if (active?.questions.has(command.interactionId))
|
|
28948
29230
|
return active.questions.respond(command);
|
|
29231
|
+
if (active?.planApprovals.has(command.interactionId))
|
|
29232
|
+
return active.planApprovals.respond(command);
|
|
28949
29233
|
if (!active || !permission && !elicitation)
|
|
28950
29234
|
return { ok: false, error: invalidState("Grok Interaction is not pending") };
|
|
28951
29235
|
if (command.response.type !== "approval") {
|
|
@@ -29072,9 +29356,20 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
29072
29356
|
this.#settleElicitation(active, pending, grokMcpElicitCancel(), "cancelled");
|
|
29073
29357
|
}
|
|
29074
29358
|
}
|
|
29359
|
+
#applyNativeSessionMode(modeId) {
|
|
29360
|
+
const next = modeId === "plan" ? GROK_PLAN_MODE_ID : this.#permissionPolicyId;
|
|
29361
|
+
if (this.#state.effectivePermissionModeId === next)
|
|
29362
|
+
return;
|
|
29363
|
+
this.#state = { ...this.#state, effectivePermissionModeId: next };
|
|
29364
|
+
this.#event({ type: "session.state.changed", state: this.#state });
|
|
29365
|
+
}
|
|
29075
29366
|
#handleEvent(active, event) {
|
|
29076
29367
|
if (this.#active !== active || this.#phase !== "open")
|
|
29077
29368
|
return;
|
|
29369
|
+
if (event.type === "session.mode") {
|
|
29370
|
+
this.#applyNativeSessionMode(event.modeId);
|
|
29371
|
+
return;
|
|
29372
|
+
}
|
|
29078
29373
|
const requestUsage = active.usage?.observe(event);
|
|
29079
29374
|
if (requestUsage) {
|
|
29080
29375
|
this.#publishUsage(requestUsage, active.command.turnId, true);
|
|
@@ -29104,6 +29399,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
29104
29399
|
this.#completeCompaction(active, event);
|
|
29105
29400
|
} else if (event.type === "interaction.resolved") {
|
|
29106
29401
|
active.questions.withdraw(event.toolCallId);
|
|
29402
|
+
active.planApprovals.withdraw(event.toolCallId);
|
|
29107
29403
|
for (const pending of [...active.elicitations.values()]) {
|
|
29108
29404
|
if (pending.nativeToolCallId === event.toolCallId) {
|
|
29109
29405
|
this.#settleElicitation(active, pending, grokMcpElicitCancel(), "cancelled");
|
|
@@ -29585,6 +29881,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
29585
29881
|
}
|
|
29586
29882
|
this.#cancelActiveElicitations(active);
|
|
29587
29883
|
active.questions.cancel();
|
|
29884
|
+
active.planApprovals.cancel();
|
|
29588
29885
|
this.#active = null;
|
|
29589
29886
|
if (usage || this.#usage)
|
|
29590
29887
|
this.#publishUsage({ ...usage, ...active.usage?.metrics() }, active.command.turnId, true);
|
|
@@ -29629,6 +29926,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
29629
29926
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
29630
29927
|
this.#cancelActiveElicitations(active);
|
|
29631
29928
|
active.questions.cancel();
|
|
29929
|
+
active.planApprovals.cancel();
|
|
29632
29930
|
await this.#transport.cancel().catch(() => void 0);
|
|
29633
29931
|
await Promise.race([
|
|
29634
29932
|
active.completion,
|
|
@@ -29821,7 +30119,7 @@ var GrokAdapter = class {
|
|
|
29821
30119
|
};
|
|
29822
30120
|
const requestedPermissionModeId = input.kind === "create" ? input.permissionModeId ?? (input.executionPolicy === "unattended-full-access" ? harnessPermissionModeIdSchema.parse("always-approve") : GROK_DEFAULT_PERMISSION_MODE_ID) : input.kind === "resume" ? input.permissionModeId ?? GROK_DEFAULT_PERMISSION_MODE_ID : GROK_DEFAULT_PERMISSION_MODE_ID;
|
|
29823
30121
|
try {
|
|
29824
|
-
|
|
30122
|
+
grokCatalogPermissionModeId(requestedPermissionModeId);
|
|
29825
30123
|
} catch {
|
|
29826
30124
|
return {
|
|
29827
30125
|
ok: false,
|
|
@@ -29999,7 +30297,22 @@ var GrokAdapter = class {
|
|
|
29999
30297
|
]);
|
|
30000
30298
|
}
|
|
30001
30299
|
}
|
|
30002
|
-
|
|
30300
|
+
if (isGrokPlanModeId(initialPermissionModeId)) {
|
|
30301
|
+
if (!transport.setSessionMode) {
|
|
30302
|
+
await transport.close().catch(() => void 0);
|
|
30303
|
+
return {
|
|
30304
|
+
ok: false,
|
|
30305
|
+
error: {
|
|
30306
|
+
code: "unsupported",
|
|
30307
|
+
message: "Grok Session Mode is unavailable",
|
|
30308
|
+
retryable: false
|
|
30309
|
+
}
|
|
30310
|
+
};
|
|
30311
|
+
}
|
|
30312
|
+
await transport.setSessionMode("plan");
|
|
30313
|
+
} else {
|
|
30314
|
+
await transport.setPermissionMode(initialPermissionModeId);
|
|
30315
|
+
}
|
|
30003
30316
|
const history = await transport.getHistory();
|
|
30004
30317
|
let initialUsage = input.kind === "resume" || input.kind === "fork" || input.kind === "rollbackLastTurn" || input.kind === "rollbackToCheckpoint" ? combineUsage(sessionUsageFromHistory(history), usageFromSignals(opened.signals)) : null;
|
|
30005
30318
|
if (contextWindow !== void 0 && initialUsage?.contextUsedTokens !== void 0) {
|