@karlorz/codexhost-cli-win32-x64 0.16.1-2 → 0.17.0-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 +2 -2
- package/THIRD_PARTY_NOTICES.txt +6 -2
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +86 -20
- package/app/console-web.js +76 -17
- package/app/cpa-live-voice-hook.js +62 -8
- package/app/desktop-controller.mjs +107 -31
- package/app/host-runtime.mjs +2560 -1634
- package/app/plugins/antigravity/plugin.mjs +66 -2
- package/app/plugins/claude-code/plugin.mjs +43 -6
- package/app/plugins/codebuddy/plugin.mjs +41 -0
- package/app/plugins/codex-usage/plugin.mjs +31 -0
- package/app/plugins/copilot/plugin.mjs +31 -0
- package/app/plugins/cursor-cli/plugin.mjs +40 -5
- package/app/plugins/deepseek-harness/plugin.mjs +490 -46
- package/app/plugins/devin/assets/icon.svg +1 -0
- package/app/plugins/devin/manifest.json +30 -0
- package/app/plugins/devin/plugin.mjs +23536 -0
- package/app/plugins/enabled.json +2 -0
- package/app/plugins/grok/plugin.mjs +1615 -495
- package/app/plugins/hermes/plugin.mjs +484 -196
- package/app/plugins/kimi-code/plugin.mjs +31 -0
- package/app/plugins/kiro-cli/plugin.mjs +31 -0
- package/app/plugins/omp/plugin.mjs +31 -0
- package/app/plugins/opencode/plugin.mjs +31 -0
- package/app/plugins/pi/plugin.mjs +1491 -411
- package/app/plugins/qoder/plugin.mjs +9555 -8654
- package/app/plugins/qoder-cn/plugin.mjs +9555 -8654
- package/app/plugins/qwen-code/assets/icon.svg +1 -0
- package/app/plugins/qwen-code/manifest.json +29 -0
- package/app/plugins/qwen-code/plugin.mjs +29471 -0
- package/app/plugins/workbuddy/plugin.mjs +41 -0
- package/app/plugins/zcode/plugin.mjs +31 -0
- package/app/renderer-extension.js +966 -233
- 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/licenses/Qwen-Code-SDK-LICENSE.txt +203 -0
- package/package.json +2 -2
|
@@ -1138,10 +1138,10 @@ function mergeDefs(...defs) {
|
|
|
1138
1138
|
function cloneDef(schema) {
|
|
1139
1139
|
return mergeDefs(schema._zod.def);
|
|
1140
1140
|
}
|
|
1141
|
-
function getElementAtPath(obj,
|
|
1142
|
-
if (!
|
|
1141
|
+
function getElementAtPath(obj, path8) {
|
|
1142
|
+
if (!path8)
|
|
1143
1143
|
return obj;
|
|
1144
|
-
return
|
|
1144
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
1145
1145
|
}
|
|
1146
1146
|
function promiseAllObject(promisesObj) {
|
|
1147
1147
|
const keys = Object.keys(promisesObj);
|
|
@@ -1550,11 +1550,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1550
1550
|
}
|
|
1551
1551
|
return false;
|
|
1552
1552
|
}
|
|
1553
|
-
function prefixIssues(
|
|
1553
|
+
function prefixIssues(path8, issues) {
|
|
1554
1554
|
return issues.map((iss) => {
|
|
1555
1555
|
var _a3;
|
|
1556
1556
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1557
|
-
iss.path.unshift(
|
|
1557
|
+
iss.path.unshift(path8);
|
|
1558
1558
|
return iss;
|
|
1559
1559
|
});
|
|
1560
1560
|
}
|
|
@@ -1701,16 +1701,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1701
1701
|
}
|
|
1702
1702
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1703
1703
|
const fieldErrors = { _errors: [] };
|
|
1704
|
-
const processError = (error52,
|
|
1704
|
+
const processError = (error52, path8 = []) => {
|
|
1705
1705
|
for (const issue2 of error52.issues) {
|
|
1706
1706
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1707
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1707
|
+
issue2.errors.map((issues) => processError({ issues }, [...path8, ...issue2.path]));
|
|
1708
1708
|
} else if (issue2.code === "invalid_key") {
|
|
1709
|
-
processError({ issues: issue2.issues }, [...
|
|
1709
|
+
processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
|
|
1710
1710
|
} else if (issue2.code === "invalid_element") {
|
|
1711
|
-
processError({ issues: issue2.issues }, [...
|
|
1711
|
+
processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
|
|
1712
1712
|
} else {
|
|
1713
|
-
const fullpath = [...
|
|
1713
|
+
const fullpath = [...path8, ...issue2.path];
|
|
1714
1714
|
if (fullpath.length === 0) {
|
|
1715
1715
|
fieldErrors._errors.push(mapper(issue2));
|
|
1716
1716
|
} else {
|
|
@@ -1737,17 +1737,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1737
1737
|
}
|
|
1738
1738
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1739
1739
|
const result = { errors: [] };
|
|
1740
|
-
const processError = (error52,
|
|
1740
|
+
const processError = (error52, path8 = []) => {
|
|
1741
1741
|
var _a3, _b;
|
|
1742
1742
|
for (const issue2 of error52.issues) {
|
|
1743
1743
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1744
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1744
|
+
issue2.errors.map((issues) => processError({ issues }, [...path8, ...issue2.path]));
|
|
1745
1745
|
} else if (issue2.code === "invalid_key") {
|
|
1746
|
-
processError({ issues: issue2.issues }, [...
|
|
1746
|
+
processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
|
|
1747
1747
|
} else if (issue2.code === "invalid_element") {
|
|
1748
|
-
processError({ issues: issue2.issues }, [...
|
|
1748
|
+
processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
|
|
1749
1749
|
} else {
|
|
1750
|
-
const fullpath = [...
|
|
1750
|
+
const fullpath = [...path8, ...issue2.path];
|
|
1751
1751
|
if (fullpath.length === 0) {
|
|
1752
1752
|
result.errors.push(mapper(issue2));
|
|
1753
1753
|
continue;
|
|
@@ -1779,8 +1779,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
function toDotPath(_path) {
|
|
1781
1781
|
const segs = [];
|
|
1782
|
-
const
|
|
1783
|
-
for (const seg of
|
|
1782
|
+
const path8 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1783
|
+
for (const seg of path8) {
|
|
1784
1784
|
if (typeof seg === "number")
|
|
1785
1785
|
segs.push(`[${seg}]`);
|
|
1786
1786
|
else if (typeof seg === "symbol")
|
|
@@ -14472,13 +14472,13 @@ function resolveRef(ref, ctx) {
|
|
|
14472
14472
|
if (!ref.startsWith("#")) {
|
|
14473
14473
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14474
14474
|
}
|
|
14475
|
-
const
|
|
14476
|
-
if (
|
|
14475
|
+
const path8 = ref.slice(1).split("/").filter(Boolean);
|
|
14476
|
+
if (path8.length === 0) {
|
|
14477
14477
|
return ctx.rootSchema;
|
|
14478
14478
|
}
|
|
14479
14479
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14480
|
-
if (
|
|
14481
|
-
const key =
|
|
14480
|
+
if (path8[0] === defsKey) {
|
|
14481
|
+
const key = path8[1];
|
|
14482
14482
|
if (!key || !ctx.defs[key]) {
|
|
14483
14483
|
throw new Error(`Reference not found: ${ref}`);
|
|
14484
14484
|
}
|
|
@@ -16505,6 +16505,37 @@ var voiceSettingsStateSchema = external_exports.strictObject({
|
|
|
16505
16505
|
})
|
|
16506
16506
|
});
|
|
16507
16507
|
|
|
16508
|
+
// ../../shared-contracts/dist/background-activity.js
|
|
16509
|
+
var backgroundActivitySchema = external_exports.strictObject({
|
|
16510
|
+
id: external_exports.string().min(1),
|
|
16511
|
+
kind: external_exports.enum(["task", "monitor", "loop", "subagent"]),
|
|
16512
|
+
label: external_exports.string(),
|
|
16513
|
+
status: external_exports.enum(["running", "scheduled", "completed", "failed", "cancelled", "unknown"]),
|
|
16514
|
+
canStop: external_exports.boolean(),
|
|
16515
|
+
/** Existing detached command Item presented by Desktop's native process UI. */
|
|
16516
|
+
commandItemId: hostItemIdSchema.optional(),
|
|
16517
|
+
schedule: external_exports.string().optional(),
|
|
16518
|
+
nextRunAt: external_exports.string().datetime({ offset: true }).optional(),
|
|
16519
|
+
relatedActivityId: external_exports.string().optional(),
|
|
16520
|
+
threadId: hostThreadIdSchema.optional()
|
|
16521
|
+
});
|
|
16522
|
+
var backgroundActivityDetailSchema = external_exports.strictObject({
|
|
16523
|
+
activity: backgroundActivitySchema,
|
|
16524
|
+
output: external_exports.string(),
|
|
16525
|
+
truncated: external_exports.boolean()
|
|
16526
|
+
});
|
|
16527
|
+
var threadActivityParamsSchema = external_exports.strictObject({ threadId: hostThreadIdSchema });
|
|
16528
|
+
var threadActivityItemParamsSchema = threadActivityParamsSchema.extend({
|
|
16529
|
+
activityId: external_exports.string().min(1)
|
|
16530
|
+
});
|
|
16531
|
+
var threadActivityListResultSchema = external_exports.strictObject({
|
|
16532
|
+
supported: external_exports.boolean(),
|
|
16533
|
+
activities: external_exports.array(backgroundActivitySchema)
|
|
16534
|
+
});
|
|
16535
|
+
var threadActivityStopResultSchema = external_exports.strictObject({
|
|
16536
|
+
outcome: external_exports.enum(["stopped", "alreadyStopped", "notFound"])
|
|
16537
|
+
});
|
|
16538
|
+
|
|
16508
16539
|
// ../../shared-contracts/dist/index.js
|
|
16509
16540
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
16510
16541
|
|
|
@@ -16762,7 +16793,35 @@ import path4 from "node:path";
|
|
|
16762
16793
|
|
|
16763
16794
|
// dist/hermes-runtime.js
|
|
16764
16795
|
import { execFile as execFile2 } from "node:child_process";
|
|
16796
|
+
import { statSync } from "node:fs";
|
|
16765
16797
|
import { promisify } from "node:util";
|
|
16798
|
+
var launcherPrefixCache = /* @__PURE__ */ new Map();
|
|
16799
|
+
function launcherCacheKey(launcher, environment) {
|
|
16800
|
+
let stat;
|
|
16801
|
+
try {
|
|
16802
|
+
stat = statSync(launcher);
|
|
16803
|
+
} catch {
|
|
16804
|
+
return null;
|
|
16805
|
+
}
|
|
16806
|
+
return [
|
|
16807
|
+
launcher,
|
|
16808
|
+
stat.mtimeMs,
|
|
16809
|
+
stat.size,
|
|
16810
|
+
environment.HERMES_HOME ?? "",
|
|
16811
|
+
environment.PATH ?? ""
|
|
16812
|
+
].join("\0");
|
|
16813
|
+
}
|
|
16814
|
+
function timeitPassthrough(script) {
|
|
16815
|
+
return [
|
|
16816
|
+
"-n",
|
|
16817
|
+
"1",
|
|
16818
|
+
"-r",
|
|
16819
|
+
"1",
|
|
16820
|
+
"-s",
|
|
16821
|
+
`exec(${JSON.stringify(script)}, {}); import sys, io; sys.stdout = io.StringIO()`,
|
|
16822
|
+
"pass"
|
|
16823
|
+
];
|
|
16824
|
+
}
|
|
16766
16825
|
function legacyHermesPythonCommand(python, script) {
|
|
16767
16826
|
return {
|
|
16768
16827
|
command: python,
|
|
@@ -16778,22 +16837,12 @@ ${script}`
|
|
|
16778
16837
|
};
|
|
16779
16838
|
}
|
|
16780
16839
|
async function nativeHermesPythonCommand(launcher, script, environment, timeoutMs = 2e4, platform = process.platform) {
|
|
16781
|
-
const
|
|
16782
|
-
|
|
16783
|
-
|
|
16784
|
-
|
|
16785
|
-
|
|
16786
|
-
|
|
16787
|
-
"1",
|
|
16788
|
-
"-r",
|
|
16789
|
-
"1",
|
|
16790
|
-
"-s",
|
|
16791
|
-
// timeit is a stdlib entry point supported by the native launcher. After
|
|
16792
|
-
// the operation returns, redirect its timing footer, preserving normal
|
|
16793
|
-
// native cleanup and exit status without contaminating JSON/RPC stdout.
|
|
16794
|
-
`exec(${JSON.stringify(script)}, {}); import sys, io; sys.stdout = io.StringIO()`,
|
|
16795
|
-
"pass"
|
|
16796
|
-
], environment, platform);
|
|
16840
|
+
const passthrough = timeitPassthrough(script);
|
|
16841
|
+
const cacheKey = launcherCacheKey(launcher, environment);
|
|
16842
|
+
const cached2 = cacheKey !== null ? launcherPrefixCache.get(cacheKey) : void 0;
|
|
16843
|
+
if (cached2 !== void 0 && cached2.length > 0 && cached2[0])
|
|
16844
|
+
return { command: cached2[0], arguments: [...cached2.slice(1), ...passthrough] };
|
|
16845
|
+
const invocation = commandInvocation(launcher, ["--print-runtime-command", "--module", "timeit", "--", ...passthrough], environment, platform);
|
|
16797
16846
|
let stdout;
|
|
16798
16847
|
try {
|
|
16799
16848
|
({ stdout } = await promisify(execFile2)(invocation.command, invocation.arguments, {
|
|
@@ -16813,6 +16862,9 @@ async function nativeHermesPythonCommand(launcher, script, environment, timeoutM
|
|
|
16813
16862
|
if (!Array.isArray(value) || value.length === 0 || !value.every((arg) => typeof arg === "string") || !value[0]) {
|
|
16814
16863
|
throw new Error("Hermes launcher returned an invalid runtime command");
|
|
16815
16864
|
}
|
|
16865
|
+
const passthroughStart = value.length - passthrough.length;
|
|
16866
|
+
if (cacheKey !== null && passthroughStart >= 1 && value.slice(passthroughStart).every((arg, index) => arg === passthrough[index]))
|
|
16867
|
+
launcherPrefixCache.set(cacheKey, value.slice(0, passthroughStart));
|
|
16816
16868
|
return { command: value[0], arguments: value.slice(1) };
|
|
16817
16869
|
}
|
|
16818
16870
|
async function hermesPythonCommand(runtime, script, environment, timeoutMs = 2e4) {
|
|
@@ -17125,9 +17177,6 @@ function catalogModelsFromInventory(inventory) {
|
|
|
17125
17177
|
}
|
|
17126
17178
|
|
|
17127
17179
|
// dist/gateway-delegation.js
|
|
17128
|
-
import { mkdtemp as mkdtemp2, writeFile as writeFile2, rm as rm2 } from "node:fs/promises";
|
|
17129
|
-
import os2 from "node:os";
|
|
17130
|
-
import path5 from "node:path";
|
|
17131
17180
|
var HERMES_DELEGATION_GUIDANCE = `This Session runs inside codexhost.
|
|
17132
17181
|
When the user authorizes cross-Harness delegation, discover the executable named by CODEXHOST_CLI_PATH through your native terminal tool. Read its --help and harness list, then use delegate start and thread send/read/wait/cancel as documented. Prefer --format compact. Preserve CODEXHOST_RUNTIME_ENDPOINT, CODEXHOST_RUNTIME_TOKEN and CODEXHOST_THREAD_ID in these calls: they identify the Runtime and parent Thread. Never print their values or substitute another executable. Native Hermes delegate_task remains available for Hermes subagents.`;
|
|
17133
17182
|
var required2 = [
|
|
@@ -17138,48 +17187,40 @@ var required2 = [
|
|
|
17138
17187
|
];
|
|
17139
17188
|
async function prepareGatewayDelegation(environment) {
|
|
17140
17189
|
if (!required2.every((key) => environment[key]))
|
|
17141
|
-
return { environment, bootstrap: "", dispose: async () => {
|
|
17190
|
+
return { environment, bootstrap: "", guidance: null, dispose: async () => {
|
|
17142
17191
|
} };
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17152
|
-
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17158
|
-
|
|
17159
|
-
// process-local; no plugin is installed and no user config is changed.
|
|
17160
|
-
//
|
|
17161
|
-
// ``hermes_bootstrap`` must run before ``tui_gateway.server`` is imported:
|
|
17162
|
-
// the gateway spawn uses ``python -I``, so PYTHONPATH and the launcher's
|
|
17163
|
-
// activation are stripped. Hermes's own entry point (``tui_gateway/entry.py``)
|
|
17164
|
-
// imports this module first to put the selected dependency environment on
|
|
17165
|
-
// ``sys.path``; skipping it makes bare third-party imports (e.g.
|
|
17166
|
-
// ``hermes_yaml`` -> ``ruamel``) fail on interpreters whose site-packages
|
|
17167
|
-
// do not already carry Hermes's dependencies. ``hermes_bootstrap`` is
|
|
17168
|
-
// import-safe here for the same reason entry.py relies on it: stdlib-only
|
|
17169
|
-
// at import time, so nothing can shadow it from the launch directory.
|
|
17170
|
-
bootstrap: `import hermes_bootstrap
|
|
17192
|
+
return {
|
|
17193
|
+
environment,
|
|
17194
|
+
// Reserve RPC stdout before native plugin imports.
|
|
17195
|
+
//
|
|
17196
|
+
// ``hermes_bootstrap`` must run before ``tui_gateway.server`` is imported:
|
|
17197
|
+
// the gateway spawn uses ``python -I``, so PYTHONPATH and the launcher's
|
|
17198
|
+
// activation are stripped. Hermes's own entry point (``tui_gateway/entry.py``)
|
|
17199
|
+
// imports this module first to put the selected dependency environment on
|
|
17200
|
+
// ``sys.path``; skipping it makes bare third-party imports (e.g.
|
|
17201
|
+
// ``hermes_yaml`` -> ``ruamel``) fail on interpreters whose site-packages
|
|
17202
|
+
// do not already carry Hermes's dependencies. ``hermes_bootstrap`` is
|
|
17203
|
+
// import-safe here for the same reason entry.py relies on it: stdlib-only
|
|
17204
|
+
// at import time, so nothing can shadow it from the launch directory.
|
|
17205
|
+
bootstrap: `import sys
|
|
17206
|
+
import hermes_bootstrap
|
|
17207
|
+
_stdout = sys.stdout # tui_gateway.server redirects sys.stdout to sys.stderr at import (stdio-entry protection); this bridge owns stdout as its RPC channel to the host
|
|
17171
17208
|
from tui_gateway import server
|
|
17172
|
-
|
|
17173
|
-
from hermes_cli.plugins import PluginContext, PluginManifest, get_plugin_manager
|
|
17174
|
-
PluginContext(PluginManifest(name="codexhost-runtime"), get_plugin_manager()).register_skill(
|
|
17175
|
-
"delegation", Path(${JSON.stringify(file2)}))
|
|
17209
|
+
sys.stdout = _stdout
|
|
17176
17210
|
`,
|
|
17177
|
-
|
|
17178
|
-
|
|
17179
|
-
|
|
17180
|
-
|
|
17181
|
-
|
|
17182
|
-
|
|
17211
|
+
guidance: `${HERMES_DELEGATION_GUIDANCE}
|
|
17212
|
+
|
|
17213
|
+
Runtime identity for this Thread:
|
|
17214
|
+
|
|
17215
|
+
- CODEXHOST_CLI_PATH: ${environment.CODEXHOST_CLI_PATH}
|
|
17216
|
+
- CODEXHOST_RUNTIME_ENDPOINT: ${environment.CODEXHOST_RUNTIME_ENDPOINT}
|
|
17217
|
+
- CODEXHOST_RUNTIME_TOKEN: ${environment.CODEXHOST_RUNTIME_TOKEN}
|
|
17218
|
+
- CODEXHOST_THREAD_ID: ${environment.CODEXHOST_THREAD_ID}
|
|
17219
|
+
|
|
17220
|
+
(end of codexhost delegation note; the user's message follows)`,
|
|
17221
|
+
dispose: async () => {
|
|
17222
|
+
}
|
|
17223
|
+
};
|
|
17183
17224
|
}
|
|
17184
17225
|
|
|
17185
17226
|
// dist/hermes-transport.js
|
|
@@ -17213,8 +17254,87 @@ function gatewayRecord(value) {
|
|
|
17213
17254
|
function gatewayString(value) {
|
|
17214
17255
|
return typeof value === "string" ? value : "";
|
|
17215
17256
|
}
|
|
17216
|
-
var GATEWAY_LAUNCH = `import
|
|
17217
|
-
|
|
17257
|
+
var GATEWAY_LAUNCH = `import asyncio
|
|
17258
|
+
import sys
|
|
17259
|
+
|
|
17260
|
+
|
|
17261
|
+
async def _bridge():
|
|
17262
|
+
from hermes_constants import get_hermes_home
|
|
17263
|
+
from hermes_cli.gateway_client import _session_ticket, gateway_ws_target
|
|
17264
|
+
from hermes_cli.gateway_runtime import (
|
|
17265
|
+
attachable,
|
|
17266
|
+
ensure_gateway_runtime,
|
|
17267
|
+
gateway_profile_home,
|
|
17268
|
+
)
|
|
17269
|
+
from gateway.session_contract import CANONICAL_GATEWAY_PROTOCOL
|
|
17270
|
+
from websockets.asyncio.client import connect
|
|
17271
|
+
|
|
17272
|
+
home = gateway_profile_home(get_hermes_home())
|
|
17273
|
+
result = await asyncio.to_thread(ensure_gateway_runtime, home, idle_exit=True)
|
|
17274
|
+
if not attachable(result):
|
|
17275
|
+
detail = f" ({result.detail})" if result.detail else ""
|
|
17276
|
+
raise SystemExit(
|
|
17277
|
+
f"[bridge-exit] gateway not attachable: {result.state} "
|
|
17278
|
+
f"{result.reason_code or 'not ready'}{detail}"
|
|
17279
|
+
)
|
|
17280
|
+
endpoint = result.endpoint
|
|
17281
|
+
ticket = await asyncio.to_thread(_session_ticket, home, endpoint)
|
|
17282
|
+
url, protocols = gateway_ws_target(endpoint, ticket)
|
|
17283
|
+
|
|
17284
|
+
async with connect(
|
|
17285
|
+
url, subprotocols=protocols, open_timeout=10, max_size=8 * 1024 * 1024, proxy=None
|
|
17286
|
+
) as ws:
|
|
17287
|
+
if protocols and ws.subprotocol != CANONICAL_GATEWAY_PROTOCOL:
|
|
17288
|
+
raise SystemExit("[bridge-exit] gateway protocol mismatch; update/restart required")
|
|
17289
|
+
|
|
17290
|
+
loop = asyncio.get_running_loop()
|
|
17291
|
+
# A full prompt rides on ONE JSON-RPC line; StreamReader's default 64 KiB
|
|
17292
|
+
# line limit aborts the bridge on large pastes (LimitOverrunError), so the
|
|
17293
|
+
# stdin side matches the WebSocket side's 8 MiB frame ceiling.
|
|
17294
|
+
reader = asyncio.StreamReader(limit=8 * 1024 * 1024)
|
|
17295
|
+
await loop.connect_read_pipe(
|
|
17296
|
+
lambda: asyncio.StreamReaderProtocol(reader), sys.stdin
|
|
17297
|
+
)
|
|
17298
|
+
|
|
17299
|
+
async def pump_in():
|
|
17300
|
+
async for raw in reader:
|
|
17301
|
+
line = raw.decode("utf-8", "replace").strip()
|
|
17302
|
+
if line:
|
|
17303
|
+
await ws.send(line)
|
|
17304
|
+
|
|
17305
|
+
async def pump_out():
|
|
17306
|
+
async for raw in ws:
|
|
17307
|
+
if isinstance(raw, bytes):
|
|
17308
|
+
raw = raw.decode("utf-8", "replace")
|
|
17309
|
+
sys.stdout.write(raw + "\\n")
|
|
17310
|
+
sys.stdout.flush()
|
|
17311
|
+
|
|
17312
|
+
pump_out_task = asyncio.create_task(pump_out())
|
|
17313
|
+
pump_in_task = asyncio.create_task(pump_in())
|
|
17314
|
+
# stdin EOF (host closed us) or socket close (gateway went away): end both.
|
|
17315
|
+
done, _pending = await asyncio.wait(
|
|
17316
|
+
{pump_in_task, pump_out_task}, return_when=asyncio.FIRST_COMPLETED
|
|
17317
|
+
)
|
|
17318
|
+
for task in (pump_in_task, pump_out_task):
|
|
17319
|
+
task.cancel()
|
|
17320
|
+
for task in done:
|
|
17321
|
+
if task.cancelled():
|
|
17322
|
+
continue
|
|
17323
|
+
exc = task.exception()
|
|
17324
|
+
if exc is not None:
|
|
17325
|
+
raise exc
|
|
17326
|
+
|
|
17327
|
+
|
|
17328
|
+
# No __main__ guard: the native launcher spawns this through exec(script, {})
|
|
17329
|
+
# whose fresh globals lack __name__; top-level code runs in both the legacy
|
|
17330
|
+
# (-c) and native (exec) spawn forms.
|
|
17331
|
+
try:
|
|
17332
|
+
asyncio.run(_bridge())
|
|
17333
|
+
except SystemExit:
|
|
17334
|
+
raise
|
|
17335
|
+
except Exception as exc:
|
|
17336
|
+
raise SystemExit(f"[bridge-exit] bridge failed: {type(exc).__name__}: {exc}")
|
|
17337
|
+
`;
|
|
17218
17338
|
var HermesGatewayTransport = class _HermesGatewayTransport {
|
|
17219
17339
|
runtime;
|
|
17220
17340
|
cwd;
|
|
@@ -17241,6 +17361,18 @@ var HermesGatewayTransport = class _HermesGatewayTransport {
|
|
|
17241
17361
|
this.environment = environment;
|
|
17242
17362
|
this.timeoutMs = timeoutMs;
|
|
17243
17363
|
}
|
|
17364
|
+
/** Model-facing delegation guidance for this Thread, or null without delegation. */
|
|
17365
|
+
get delegationGuidance() {
|
|
17366
|
+
return this.#delegation?.guidance ?? null;
|
|
17367
|
+
}
|
|
17368
|
+
/** Whether start() already ran (a warm transport skips prepare/start on reuse). */
|
|
17369
|
+
get started() {
|
|
17370
|
+
return this.#startRequested;
|
|
17371
|
+
}
|
|
17372
|
+
/** Whether the bridge child is gone; a closed transport cannot be reused. */
|
|
17373
|
+
get closed() {
|
|
17374
|
+
return this.#closed;
|
|
17375
|
+
}
|
|
17244
17376
|
static async probe(executable, cwd, environment) {
|
|
17245
17377
|
const override = environment.CODEXHOST_HERMES_GATEWAY_PYTHON;
|
|
17246
17378
|
if (override) {
|
|
@@ -17753,7 +17885,7 @@ async function resolveHermesSessionCandidate(input) {
|
|
|
17753
17885
|
}
|
|
17754
17886
|
|
|
17755
17887
|
// dist/command.js
|
|
17756
|
-
import
|
|
17888
|
+
import path5 from "node:path";
|
|
17757
17889
|
var HermesExecutableError = class extends Error {
|
|
17758
17890
|
code = "HERMES_NOT_FOUND";
|
|
17759
17891
|
};
|
|
@@ -17776,7 +17908,62 @@ function resolveHermesExecutable(input = {}) {
|
|
|
17776
17908
|
});
|
|
17777
17909
|
if (!resolution)
|
|
17778
17910
|
throw new HermesExecutableError("Hermes CLI is not installed");
|
|
17779
|
-
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable :
|
|
17911
|
+
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path5.resolve(resolution.executable);
|
|
17912
|
+
}
|
|
17913
|
+
|
|
17914
|
+
// dist/gateway-transport-pool.js
|
|
17915
|
+
function sameRuntime(a, b) {
|
|
17916
|
+
if (typeof a === "string" || typeof b === "string")
|
|
17917
|
+
return a === b;
|
|
17918
|
+
return a.launcher === b.launcher;
|
|
17919
|
+
}
|
|
17920
|
+
var ENVIRONMENT_IDENTITY_KEYS = ["HERMES_HOME", "HERMES_TUI_SKILLS"];
|
|
17921
|
+
function environmentIdentity(environment) {
|
|
17922
|
+
return ENVIRONMENT_IDENTITY_KEYS.map((key) => `${key}=${environment[key] ?? ""}`).join("\0");
|
|
17923
|
+
}
|
|
17924
|
+
function sameBridge(transport, runtime, cwd, environment) {
|
|
17925
|
+
return sameRuntime(transport.runtime, runtime) && transport.cwd === cwd && environmentIdentity(transport.environment) === environmentIdentity(environment);
|
|
17926
|
+
}
|
|
17927
|
+
var GatewayTransportPool = class {
|
|
17928
|
+
#idle = [];
|
|
17929
|
+
#capacity;
|
|
17930
|
+
#closed = false;
|
|
17931
|
+
constructor(capacity = 2) {
|
|
17932
|
+
this.#capacity = Math.max(1, capacity);
|
|
17933
|
+
}
|
|
17934
|
+
/** A healthy started bridge equivalent to a fresh spawn for these inputs, or null. */
|
|
17935
|
+
acquire(runtime, cwd, environment) {
|
|
17936
|
+
while (this.#idle.length > 0) {
|
|
17937
|
+
const index = this.#idle.findIndex((transport2) => sameBridge(transport2, runtime, cwd, environment));
|
|
17938
|
+
const transport = index >= 0 ? this.#idle.splice(index, 1)[0] : void 0;
|
|
17939
|
+
if (transport === void 0)
|
|
17940
|
+
return null;
|
|
17941
|
+
if (!transport.closed && transport.started)
|
|
17942
|
+
return transport;
|
|
17943
|
+
void transport.close().catch(() => void 0);
|
|
17944
|
+
}
|
|
17945
|
+
return null;
|
|
17946
|
+
}
|
|
17947
|
+
/** Return a bridge after its session settled; unhealthy or late ones are discarded. */
|
|
17948
|
+
release(transport) {
|
|
17949
|
+
if (transport.closed || this.#closed || this.#idle.length >= this.#capacity) {
|
|
17950
|
+
void transport.close().catch(() => void 0);
|
|
17951
|
+
return;
|
|
17952
|
+
}
|
|
17953
|
+
this.#idle.push(transport);
|
|
17954
|
+
}
|
|
17955
|
+
async close() {
|
|
17956
|
+
this.#closed = true;
|
|
17957
|
+
const transports = this.#idle;
|
|
17958
|
+
this.#idle = [];
|
|
17959
|
+
await Promise.all(transports.map((transport) => transport.close().catch(() => void 0)));
|
|
17960
|
+
}
|
|
17961
|
+
};
|
|
17962
|
+
async function startGatewayTransport(runtime, cwd, environment, timeoutMs) {
|
|
17963
|
+
const transport = new HermesGatewayTransport(runtime, cwd, environment, timeoutMs);
|
|
17964
|
+
await transport.prepareSession();
|
|
17965
|
+
await transport.start();
|
|
17966
|
+
return transport;
|
|
17780
17967
|
}
|
|
17781
17968
|
|
|
17782
17969
|
// dist/gateway-history.js
|
|
@@ -17866,21 +18053,24 @@ def capture(db):
|
|
|
17866
18053
|
boundaries[str(row['id'])] = {'count': end, 'digest': digest(active[:end])}
|
|
17867
18054
|
return exported, {'rows': rows, 'derivable': derivable, 'boundaries': boundaries, 'physicalSessionId': sid}
|
|
17868
18055
|
|
|
18056
|
+
def ensure_session_row(db):
|
|
18057
|
+
if db.get_session(sid) is None:
|
|
18058
|
+
from hermes_constants import parse_reasoning_effort
|
|
18059
|
+
initial = {}
|
|
18060
|
+
if isinstance(p.get('provider'), str) and p['provider']: initial['provider'] = p['provider']
|
|
18061
|
+
if isinstance(p.get('model'), str) and p['model']: initial['model'] = p['model']
|
|
18062
|
+
if isinstance(p.get('reasoningEffort'), str):
|
|
18063
|
+
reasoning = parse_reasoning_effort(p['reasoningEffort'])
|
|
18064
|
+
if reasoning is not None: initial['reasoning_config'] = reasoning
|
|
18065
|
+
if isinstance(p.get('yolo'), bool): initial['yolo_mode'] = p['yolo']
|
|
18066
|
+
db.create_session(session_id=sid, source='cli', cwd=p['cwd'], model=p.get('model'), model_config=initial)
|
|
18067
|
+
return {'created': True}
|
|
18068
|
+
|
|
17869
18069
|
try:
|
|
17870
18070
|
if p['operation'] == 'ensure':
|
|
17871
18071
|
db = SessionDB()
|
|
17872
18072
|
try:
|
|
17873
|
-
|
|
17874
|
-
from hermes_constants import parse_reasoning_effort
|
|
17875
|
-
initial = {}
|
|
17876
|
-
if isinstance(p.get('provider'), str) and p['provider']: initial['provider'] = p['provider']
|
|
17877
|
-
if isinstance(p.get('model'), str) and p['model']: initial['model'] = p['model']
|
|
17878
|
-
if isinstance(p.get('reasoningEffort'), str):
|
|
17879
|
-
reasoning = parse_reasoning_effort(p['reasoningEffort'])
|
|
17880
|
-
if reasoning is not None: initial['reasoning_config'] = reasoning
|
|
17881
|
-
if isinstance(p.get('yolo'), bool): initial['yolo_mode'] = p['yolo']
|
|
17882
|
-
db.create_session(session_id=sid, source='cli', cwd=p['cwd'], model=p.get('model'), model_config=initial)
|
|
17883
|
-
result = {'created': True}
|
|
18073
|
+
result = ensure_session_row(db)
|
|
17884
18074
|
finally: db.close()
|
|
17885
18075
|
elif p['operation'] == 'discard':
|
|
17886
18076
|
child = p['derivedSessionId']
|
|
@@ -18248,28 +18438,6 @@ var HermesUsage = class {
|
|
|
18248
18438
|
}
|
|
18249
18439
|
};
|
|
18250
18440
|
|
|
18251
|
-
// dist/gateway-configuration.js
|
|
18252
|
-
import { execFile as execFile4 } from "node:child_process";
|
|
18253
|
-
import { promisify as promisify3 } from "node:util";
|
|
18254
|
-
async function resolveGatewayModel(transport, modelId) {
|
|
18255
|
-
if (/\s/u.test(modelId) || modelId.startsWith("-"))
|
|
18256
|
-
throw new Error("Invalid Hermes Model identifier");
|
|
18257
|
-
const command = await hermesPythonCommand(transport.runtime, `import json
|
|
18258
|
-
from hermes_cli.models import parse_model_input
|
|
18259
|
-
p,m=parse_model_input(${JSON.stringify(modelId)}, '')
|
|
18260
|
-
print(json.dumps({'provider':p,'model':m}))`, { ...process.env, ...transport.environment });
|
|
18261
|
-
const result = await promisify3(execFile4)(command.command, command.arguments, {
|
|
18262
|
-
cwd: transport.cwd,
|
|
18263
|
-
env: { ...process.env, ...transport.environment },
|
|
18264
|
-
timeout: 2e4,
|
|
18265
|
-
maxBuffer: 1024 * 1024
|
|
18266
|
-
});
|
|
18267
|
-
const value = JSON.parse(result.stdout.trim());
|
|
18268
|
-
if (!value || typeof value !== "object" || !("provider" in value) || !("model" in value) || typeof value.provider !== "string" || typeof value.model !== "string")
|
|
18269
|
-
throw new Error("Hermes returned an invalid Model choice");
|
|
18270
|
-
return { provider: value.provider, model: value.model };
|
|
18271
|
-
}
|
|
18272
|
-
|
|
18273
18441
|
// dist/gateway-session-transport.js
|
|
18274
18442
|
var hermesGatewayThinkingOptions = [
|
|
18275
18443
|
"none",
|
|
@@ -18301,14 +18469,14 @@ function gatewayDiff(text2) {
|
|
|
18301
18469
|
if (!text2 || text2.length > 1024 * 1024)
|
|
18302
18470
|
return [];
|
|
18303
18471
|
const result = [];
|
|
18304
|
-
let
|
|
18472
|
+
let path8 = "";
|
|
18305
18473
|
let inHunk = false;
|
|
18306
18474
|
let oldLines = [], newLines = [];
|
|
18307
18475
|
const flush = () => {
|
|
18308
|
-
if (
|
|
18476
|
+
if (path8)
|
|
18309
18477
|
result.push({
|
|
18310
18478
|
type: "diff",
|
|
18311
|
-
path:
|
|
18479
|
+
path: path8,
|
|
18312
18480
|
oldText: oldLines.join("\n"),
|
|
18313
18481
|
newText: newLines.join("\n")
|
|
18314
18482
|
});
|
|
@@ -18321,24 +18489,24 @@ function gatewayDiff(text2) {
|
|
|
18321
18489
|
if (header) {
|
|
18322
18490
|
flush();
|
|
18323
18491
|
inHunk = false;
|
|
18324
|
-
|
|
18492
|
+
path8 = (header[2] === "/dev/null" ? header[1] ?? "" : header[2] ?? "").replace(/^[ab]\//u, "");
|
|
18325
18493
|
continue;
|
|
18326
18494
|
}
|
|
18327
18495
|
if (line.startsWith("--- ") && !inHunk) {
|
|
18328
18496
|
flush();
|
|
18329
|
-
|
|
18497
|
+
path8 = line.slice(4).replace(/^a\//u, "");
|
|
18330
18498
|
} else if (line.startsWith("+++ ") && !inHunk) {
|
|
18331
18499
|
const next = line.slice(4);
|
|
18332
18500
|
if (next !== "/dev/null")
|
|
18333
|
-
|
|
18501
|
+
path8 = next.replace(/^b\//u, "");
|
|
18334
18502
|
} else if (line.startsWith("@@")) {
|
|
18335
18503
|
inHunk = true;
|
|
18336
18504
|
continue;
|
|
18337
|
-
} else if (
|
|
18505
|
+
} else if (path8 && line.startsWith("-"))
|
|
18338
18506
|
oldLines.push(line.slice(1));
|
|
18339
|
-
else if (
|
|
18507
|
+
else if (path8 && line.startsWith("+"))
|
|
18340
18508
|
newLines.push(line.slice(1));
|
|
18341
|
-
else if (
|
|
18509
|
+
else if (path8 && line.startsWith(" ")) {
|
|
18342
18510
|
oldLines.push(line.slice(1));
|
|
18343
18511
|
newLines.push(line.slice(1));
|
|
18344
18512
|
}
|
|
@@ -18362,7 +18530,7 @@ var HermesGatewaySessionTransport = class {
|
|
|
18362
18530
|
return this.#commands;
|
|
18363
18531
|
}
|
|
18364
18532
|
async getCommands() {
|
|
18365
|
-
const params = { session_id: this.sessionId
|
|
18533
|
+
const params = { session_id: this.sessionId };
|
|
18366
18534
|
const [response, catalog] = await Promise.all([
|
|
18367
18535
|
this.transport.request("complete.slash", { ...params, text: "/" }, this.transport.timeoutMs, false),
|
|
18368
18536
|
this.transport.request("commands.catalog", params, this.transport.timeoutMs, false)
|
|
@@ -18387,13 +18555,29 @@ var HermesGatewaySessionTransport = class {
|
|
|
18387
18555
|
history;
|
|
18388
18556
|
#active = null;
|
|
18389
18557
|
#requests = /* @__PURE__ */ new Map();
|
|
18558
|
+
/** Open approval server requests by their payload request_id, for approval.cancelled. */
|
|
18559
|
+
#approvalRequests = /* @__PURE__ */ new Map();
|
|
18560
|
+
/** Pending approval prompts adopted from the create/resume snapshot. */
|
|
18561
|
+
#adoptedPrompts = [];
|
|
18390
18562
|
#closed = false;
|
|
18391
18563
|
#info;
|
|
18392
|
-
|
|
18564
|
+
#revision = null;
|
|
18565
|
+
#generation = null;
|
|
18566
|
+
#subscriptionId = null;
|
|
18567
|
+
/** Thread's delegation guidance, injected as api_text on the first turn only. */
|
|
18568
|
+
#delegationGuidance;
|
|
18569
|
+
constructor(transport, sessionId, nativeSessionId, info, bookkeeping = {}, delegationGuidance = null) {
|
|
18393
18570
|
this.transport = transport;
|
|
18394
18571
|
this.sessionId = sessionId;
|
|
18395
18572
|
this.nativeSessionId = nativeSessionId;
|
|
18396
18573
|
this.#info = info;
|
|
18574
|
+
this.#delegationGuidance = delegationGuidance;
|
|
18575
|
+
if (typeof bookkeeping.revision === "number")
|
|
18576
|
+
this.#revision = bookkeeping.revision;
|
|
18577
|
+
if (typeof bookkeeping.generation === "number")
|
|
18578
|
+
this.#generation = bookkeeping.generation;
|
|
18579
|
+
if (typeof bookkeeping.subscriptionId === "string")
|
|
18580
|
+
this.#subscriptionId = bookkeeping.subscriptionId;
|
|
18397
18581
|
this.history = new HermesGatewayHistory({
|
|
18398
18582
|
python: transport.runtime,
|
|
18399
18583
|
cwd: transport.cwd,
|
|
@@ -18454,17 +18638,24 @@ var HermesGatewaySessionTransport = class {
|
|
|
18454
18638
|
return optionId;
|
|
18455
18639
|
}
|
|
18456
18640
|
async setModel(modelId) {
|
|
18457
|
-
const
|
|
18458
|
-
const
|
|
18459
|
-
|
|
18460
|
-
|
|
18461
|
-
|
|
18462
|
-
session_id: this.sessionId
|
|
18641
|
+
const revision = this.#revision;
|
|
18642
|
+
const generation = this.#generation;
|
|
18643
|
+
if (revision === null || generation === null)
|
|
18644
|
+
throw new Error("Hermes gateway Session revision is not known yet");
|
|
18645
|
+
const result = await this.transport.request("session.mutate", {
|
|
18646
|
+
session_id: this.sessionId,
|
|
18647
|
+
request_id: `codexhost-model-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
18648
|
+
expected_revision: revision,
|
|
18649
|
+
expected_generation: generation,
|
|
18650
|
+
operation: "model",
|
|
18651
|
+
payload: { model: modelId }
|
|
18463
18652
|
});
|
|
18464
|
-
if (result.
|
|
18465
|
-
|
|
18466
|
-
|
|
18467
|
-
|
|
18653
|
+
if (typeof result.revision === "number")
|
|
18654
|
+
this.#revision = result.revision;
|
|
18655
|
+
if (typeof result.execution_generation === "number")
|
|
18656
|
+
this.#generation = result.execution_generation;
|
|
18657
|
+
const actualModel = gatewayString(result.model);
|
|
18658
|
+
const actualProvider = gatewayString(result.provider);
|
|
18468
18659
|
if (modelId !== actualModel && modelId !== `${actualProvider}:${actualModel}`)
|
|
18469
18660
|
throw new Error("Hermes did not confirm the requested Model");
|
|
18470
18661
|
}
|
|
@@ -18474,11 +18665,11 @@ var HermesGatewaySessionTransport = class {
|
|
|
18474
18665
|
const result = await this.transport.request("config.set", {
|
|
18475
18666
|
key: "yolo",
|
|
18476
18667
|
value: modeId === "dont_ask" ? "on" : "off",
|
|
18477
|
-
scope: "session",
|
|
18478
18668
|
session_id: this.sessionId
|
|
18479
18669
|
});
|
|
18480
|
-
if (result.value !== (modeId === "dont_ask" ? "1" : "0")
|
|
18670
|
+
if (result.value !== (modeId === "dont_ask" ? "1" : "0"))
|
|
18481
18671
|
throw new Error("Hermes effective approval policy differs from the requested mode; check native global approvals policy");
|
|
18672
|
+
this.#info = { ...this.#info, yolo: modeId === "dont_ask" };
|
|
18482
18673
|
}
|
|
18483
18674
|
nativeCommandName(text2) {
|
|
18484
18675
|
return hermesGatewayCommandName(text2, this.#commands);
|
|
@@ -18501,9 +18692,11 @@ var HermesGatewaySessionTransport = class {
|
|
|
18501
18692
|
reject: rejectResult,
|
|
18502
18693
|
streamed: "",
|
|
18503
18694
|
reasoning: "",
|
|
18504
|
-
toolIds: /* @__PURE__ */ new Set()
|
|
18695
|
+
toolIds: /* @__PURE__ */ new Set(),
|
|
18696
|
+
admissionId: null
|
|
18505
18697
|
};
|
|
18506
18698
|
this.#active = active;
|
|
18699
|
+
void this.#adoptedPrompts.splice(0).map((prompt) => void this.#respondAdoptedApproval(prompt, active).catch(() => void 0));
|
|
18507
18700
|
const commandText = text2.trim();
|
|
18508
18701
|
const nativeCommand = this.nativeCommandName(text2);
|
|
18509
18702
|
try {
|
|
@@ -18542,12 +18735,21 @@ var HermesGatewaySessionTransport = class {
|
|
|
18542
18735
|
emit({ type: "agent.text", text: response.output });
|
|
18543
18736
|
active.resolve({ stopReason: "end_turn" });
|
|
18544
18737
|
} else {
|
|
18738
|
+
const guidance = this.#delegationGuidance;
|
|
18739
|
+
this.#delegationGuidance = null;
|
|
18545
18740
|
const submitted = await this.transport.request("prompt.submit", {
|
|
18546
18741
|
session_id: this.sessionId,
|
|
18547
|
-
text: text2
|
|
18742
|
+
text: text2,
|
|
18743
|
+
submission_id: `codexhost-turn-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
18744
|
+
clarify_batch: true,
|
|
18745
|
+
...guidance ? { api_text: `${guidance}
|
|
18746
|
+
|
|
18747
|
+
${text2}` } : {}
|
|
18548
18748
|
});
|
|
18549
|
-
if (submitted.status !== "
|
|
18550
|
-
this.#fault(new Error(`Hermes did not
|
|
18749
|
+
if (submitted.status !== "queued" && submitted.status !== "started")
|
|
18750
|
+
this.#fault(new Error(`Hermes did not accept the turn (${String(submitted.status)})`));
|
|
18751
|
+
else if (active.admissionId === null && typeof submitted.admission_id === "string")
|
|
18752
|
+
active.admissionId = submitted.admission_id;
|
|
18551
18753
|
}
|
|
18552
18754
|
} catch (error51) {
|
|
18553
18755
|
active.reject(error51 instanceof Error ? error51 : new Error(String(error51)));
|
|
@@ -18563,7 +18765,12 @@ var HermesGatewaySessionTransport = class {
|
|
|
18563
18765
|
}
|
|
18564
18766
|
}
|
|
18565
18767
|
async cancel() {
|
|
18566
|
-
|
|
18768
|
+
if (this.#generation === null)
|
|
18769
|
+
return;
|
|
18770
|
+
await this.transport.request("session.interrupt", {
|
|
18771
|
+
session_id: this.sessionId,
|
|
18772
|
+
execution_generation: this.#generation
|
|
18773
|
+
});
|
|
18567
18774
|
}
|
|
18568
18775
|
async close() {
|
|
18569
18776
|
if (this.#closed)
|
|
@@ -18574,10 +18781,13 @@ var HermesGatewaySessionTransport = class {
|
|
|
18574
18781
|
this.#requests.clear();
|
|
18575
18782
|
this.#active?.reject(new Error("Hermes gateway Session closed"));
|
|
18576
18783
|
try {
|
|
18577
|
-
|
|
18784
|
+
if (this.#subscriptionId !== null)
|
|
18785
|
+
await this.transport.request("session.detach", {
|
|
18786
|
+
session_id: this.sessionId,
|
|
18787
|
+
subscription_id: this.#subscriptionId
|
|
18788
|
+
});
|
|
18578
18789
|
} catch {
|
|
18579
18790
|
}
|
|
18580
|
-
await this.transport.close();
|
|
18581
18791
|
}
|
|
18582
18792
|
#fault(error51) {
|
|
18583
18793
|
if (this.#closed)
|
|
@@ -18597,6 +18807,10 @@ var HermesGatewaySessionTransport = class {
|
|
|
18597
18807
|
const payload = gatewayRecord(event.payload);
|
|
18598
18808
|
if (event.type === "session.info") {
|
|
18599
18809
|
this.#info = payload;
|
|
18810
|
+
if (typeof payload.revision === "number")
|
|
18811
|
+
this.#revision = payload.revision;
|
|
18812
|
+
if (typeof payload.execution_generation === "number")
|
|
18813
|
+
this.#generation = payload.execution_generation;
|
|
18600
18814
|
return;
|
|
18601
18815
|
}
|
|
18602
18816
|
if (event.type === "session.usage") {
|
|
@@ -18608,12 +18822,26 @@ var HermesGatewaySessionTransport = class {
|
|
|
18608
18822
|
controller?.abort(payload.reason === "timeout" ? "expired" : "cancelled");
|
|
18609
18823
|
return;
|
|
18610
18824
|
}
|
|
18825
|
+
if (event.type === "approval.cancelled") {
|
|
18826
|
+
const ids = Array.isArray(payload.request_ids) ? payload.request_ids.filter((id) => typeof id === "string") : [];
|
|
18827
|
+
for (const id of ids) {
|
|
18828
|
+
this.#approvalRequests.get(id)?.abort("cancelled");
|
|
18829
|
+
this.#approvalRequests.delete(id);
|
|
18830
|
+
}
|
|
18831
|
+
return;
|
|
18832
|
+
}
|
|
18611
18833
|
const active = this.#active;
|
|
18612
18834
|
if (!active) {
|
|
18613
18835
|
if (event.type === "error")
|
|
18614
18836
|
this.#fault(new Error(gatewayString(payload.message)));
|
|
18615
18837
|
return;
|
|
18616
18838
|
}
|
|
18839
|
+
const eventAdmission = gatewayString(event.admission_id);
|
|
18840
|
+
const eventType = gatewayString(event.type);
|
|
18841
|
+
if (eventAdmission && active.admissionId && eventAdmission !== active.admissionId) {
|
|
18842
|
+
if (eventType.startsWith("message.") || eventType.startsWith("reasoning."))
|
|
18843
|
+
return;
|
|
18844
|
+
}
|
|
18617
18845
|
const text2 = gatewayString(payload.text);
|
|
18618
18846
|
if (event.type === "message.delta") {
|
|
18619
18847
|
active.streamed += text2;
|
|
@@ -18744,27 +18972,80 @@ var HermesGatewaySessionTransport = class {
|
|
|
18744
18972
|
label: choice === "session" ? "Allow for this session" : "Always allow"
|
|
18745
18973
|
}
|
|
18746
18974
|
] : choice === "deny" ? [{ id: "deny", effect: "deny", label: "Deny" }] : []);
|
|
18747
|
-
const
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18975
|
+
const payloadRequestId = gatewayString(params.request_id);
|
|
18976
|
+
if (payloadRequestId)
|
|
18977
|
+
this.#approvalRequests.set(payloadRequestId, controller);
|
|
18978
|
+
try {
|
|
18979
|
+
const response = await active.permission({
|
|
18980
|
+
signal: controller.signal,
|
|
18981
|
+
title: gatewayString(params.description) || gatewayString(params.command),
|
|
18982
|
+
description: gatewayString(params.command) || gatewayString(params.description),
|
|
18983
|
+
options
|
|
18756
18984
|
});
|
|
18985
|
+
if (!controller.signal.aborted)
|
|
18986
|
+
this.transport.respond(id, {
|
|
18987
|
+
choice: response ?? "deny"
|
|
18988
|
+
});
|
|
18989
|
+
} finally {
|
|
18990
|
+
if (payloadRequestId)
|
|
18991
|
+
this.#approvalRequests.delete(payloadRequestId);
|
|
18992
|
+
}
|
|
18757
18993
|
} else
|
|
18758
18994
|
this.transport.rejectRequest(id);
|
|
18759
18995
|
} finally {
|
|
18760
18996
|
this.#requests.delete(id);
|
|
18761
18997
|
}
|
|
18762
18998
|
}
|
|
18999
|
+
/** Keep approval prompts from the create/resume snapshot for the next turn. */
|
|
19000
|
+
adoptPendingPrompts(prompts) {
|
|
19001
|
+
if (!Array.isArray(prompts))
|
|
19002
|
+
return;
|
|
19003
|
+
for (const entry of prompts) {
|
|
19004
|
+
const prompt = gatewayRecord(entry);
|
|
19005
|
+
if (gatewayString(prompt.kind) === "approval" && gatewayString(prompt.prompt_id))
|
|
19006
|
+
this.#adoptedPrompts.push(prompt);
|
|
19007
|
+
}
|
|
19008
|
+
}
|
|
19009
|
+
/**
|
|
19010
|
+
* Answer a snapshot-adopted approval through canonical `approval.respond`.
|
|
19011
|
+
* Clarify prompts are deliberately not answered here: a live clarify
|
|
19012
|
+
* question is served by the `clarify` server request (batch mode), and the
|
|
19013
|
+
* gateway re-issues still-open server requests to an attaching client.
|
|
19014
|
+
*/
|
|
19015
|
+
async #respondAdoptedApproval(prompt, active) {
|
|
19016
|
+
if (this.#closed)
|
|
19017
|
+
return;
|
|
19018
|
+
const promptId = gatewayString(prompt.prompt_id);
|
|
19019
|
+
const generation = prompt.execution_generation;
|
|
19020
|
+
const choices = Array.isArray(prompt.choices) ? prompt.choices.filter((choice) => typeof choice === "string") : ["once", "deny"];
|
|
19021
|
+
const options = choices.flatMap((choice) => choice === "once" ? [{ id: "once", effect: "allowOnce", label: "Allow once" }] : choice === "session" || choice === "always" ? [
|
|
19022
|
+
{
|
|
19023
|
+
id: choice,
|
|
19024
|
+
effect: choice === "session" ? "allowForSession" : "allowAlways",
|
|
19025
|
+
label: choice === "session" ? "Allow for this session" : "Always allow"
|
|
19026
|
+
}
|
|
19027
|
+
] : choice === "deny" ? [{ id: "deny", effect: "deny", label: "Deny" }] : []);
|
|
19028
|
+
const response = await active.permission({
|
|
19029
|
+
signal: new AbortController().signal,
|
|
19030
|
+
title: gatewayString(prompt.description) || gatewayString(prompt.command) || "Hermes approval requested before this Session attached",
|
|
19031
|
+
description: gatewayString(prompt.command) || gatewayString(prompt.description),
|
|
19032
|
+
options
|
|
19033
|
+
});
|
|
19034
|
+
if (this.#closed)
|
|
19035
|
+
return;
|
|
19036
|
+
if (typeof generation === "number")
|
|
19037
|
+
await this.transport.request("approval.respond", {
|
|
19038
|
+
session_id: this.sessionId,
|
|
19039
|
+
execution_generation: generation,
|
|
19040
|
+
prompt_id: promptId,
|
|
19041
|
+
choice: response ?? "deny"
|
|
19042
|
+
}, this.transport.timeoutMs, false);
|
|
19043
|
+
}
|
|
18763
19044
|
};
|
|
18764
19045
|
|
|
18765
19046
|
// dist/usage-statistics.js
|
|
18766
|
-
import
|
|
18767
|
-
import
|
|
19047
|
+
import os2 from "node:os";
|
|
19048
|
+
import path6 from "node:path";
|
|
18768
19049
|
import { lstat } from "node:fs/promises";
|
|
18769
19050
|
|
|
18770
19051
|
// ../../harness-adapter/dist/usage-statistics.js
|
|
@@ -18824,9 +19105,9 @@ function usageEntryFromRequest(request, occurredAtMs) {
|
|
|
18824
19105
|
|
|
18825
19106
|
// dist/usage-statistics.js
|
|
18826
19107
|
function hermesStateDatabasePath(environment) {
|
|
18827
|
-
const home = environment.HOME || environment.USERPROFILE ||
|
|
19108
|
+
const home = environment.HOME || environment.USERPROFILE || os2.homedir();
|
|
18828
19109
|
const configured = environment.HERMES_HOME;
|
|
18829
|
-
return
|
|
19110
|
+
return path6.resolve(configured ? path6.join(configured, "state.db") : path6.join(home, ".hermes", "state.db"));
|
|
18830
19111
|
}
|
|
18831
19112
|
async function fingerprint(file2) {
|
|
18832
19113
|
const info = await lstat(file2).catch(() => null);
|
|
@@ -18908,7 +19189,7 @@ function createHermesUsageStatistics(environment) {
|
|
|
18908
19189
|
}
|
|
18909
19190
|
|
|
18910
19191
|
// dist/gateway-open.js
|
|
18911
|
-
import
|
|
19192
|
+
import path7 from "node:path";
|
|
18912
19193
|
import { realpath } from "node:fs/promises";
|
|
18913
19194
|
|
|
18914
19195
|
// dist/hermes-session.js
|
|
@@ -19118,16 +19399,16 @@ var Diff = class {
|
|
|
19118
19399
|
}
|
|
19119
19400
|
}
|
|
19120
19401
|
}
|
|
19121
|
-
addToPath(
|
|
19122
|
-
const last =
|
|
19402
|
+
addToPath(path8, added, removed, oldPosInc, options) {
|
|
19403
|
+
const last = path8.lastComponent;
|
|
19123
19404
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
19124
19405
|
return {
|
|
19125
|
-
oldPos:
|
|
19406
|
+
oldPos: path8.oldPos + oldPosInc,
|
|
19126
19407
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
19127
19408
|
};
|
|
19128
19409
|
} else {
|
|
19129
19410
|
return {
|
|
19130
|
-
oldPos:
|
|
19411
|
+
oldPos: path8.oldPos + oldPosInc,
|
|
19131
19412
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
19132
19413
|
};
|
|
19133
19414
|
}
|
|
@@ -19442,8 +19723,8 @@ function hermesFileChanges(update) {
|
|
|
19442
19723
|
for (const block of update.content ?? []) {
|
|
19443
19724
|
if (block.type !== "diff")
|
|
19444
19725
|
continue;
|
|
19445
|
-
const { path:
|
|
19446
|
-
if (!
|
|
19726
|
+
const { path: path8, oldText, newText } = block;
|
|
19727
|
+
if (!path8.trim() || /[\0\r\n]/u.test(path8) || typeof newText !== "string")
|
|
19447
19728
|
continue;
|
|
19448
19729
|
if (oldText === newText)
|
|
19449
19730
|
continue;
|
|
@@ -19451,10 +19732,10 @@ function hermesFileChanges(update) {
|
|
|
19451
19732
|
if (bytes > MAX_DIFF_BYTES || changes.length === MAX_DIFFS)
|
|
19452
19733
|
return [];
|
|
19453
19734
|
changes.push({
|
|
19454
|
-
path:
|
|
19735
|
+
path: path8,
|
|
19455
19736
|
kind: "update",
|
|
19456
19737
|
diffScope: "fragment",
|
|
19457
|
-
unifiedDiff: createTwoFilesPatch(
|
|
19738
|
+
unifiedDiff: createTwoFilesPatch(path8, path8, oldText ?? "", newText, "", "", {
|
|
19458
19739
|
context: 3
|
|
19459
19740
|
})
|
|
19460
19741
|
});
|
|
@@ -20259,7 +20540,7 @@ ${reason}` }
|
|
|
20259
20540
|
|
|
20260
20541
|
// dist/gateway-open.js
|
|
20261
20542
|
async function sameDirectory(left, right) {
|
|
20262
|
-
return await realpath(left).catch(() =>
|
|
20543
|
+
return await realpath(left).catch(() => path7.resolve(left)) === await realpath(right).catch(() => path7.resolve(right));
|
|
20263
20544
|
}
|
|
20264
20545
|
var gatewayCapabilities = {
|
|
20265
20546
|
configuration: {
|
|
@@ -20321,8 +20602,10 @@ async function openGatewaySession(input, transport, onSettle, inheritedPermissio
|
|
|
20321
20602
|
let nativeRef = source;
|
|
20322
20603
|
let sourceHistory;
|
|
20323
20604
|
try {
|
|
20324
|
-
|
|
20325
|
-
|
|
20605
|
+
if (!transport.started) {
|
|
20606
|
+
await transport.prepareSession();
|
|
20607
|
+
await transport.start();
|
|
20608
|
+
}
|
|
20326
20609
|
if (source && (input.kind === "fork" || input.kind === "rollbackLastTurn")) {
|
|
20327
20610
|
sourceHistory = new HermesGatewayHistory({
|
|
20328
20611
|
python: transport.runtime,
|
|
@@ -20332,34 +20615,33 @@ async function openGatewaySession(input, transport, onSettle, inheritedPermissio
|
|
|
20332
20615
|
});
|
|
20333
20616
|
nativeRef = await sourceHistory.derive(input.kind === "fork" ? { checkpoint: input.checkpoint } : { rollbackLastTurn: true });
|
|
20334
20617
|
}
|
|
20335
|
-
const
|
|
20336
|
-
|
|
20337
|
-
|
|
20338
|
-
close_on_disconnect
|
|
20339
|
-
|
|
20340
|
-
|
|
20341
|
-
|
|
20618
|
+
const response = await transport.request(
|
|
20619
|
+
nativeRef ? "session.resume" : "session.create",
|
|
20620
|
+
// Canonical wire (hermes-gateway-v1, CanonicalCreateParams/CanonicalResumeParams):
|
|
20621
|
+
// no close_on_disconnect / eager_build keys, and the effort key is "reasoning".
|
|
20622
|
+
nativeRef ? { session_id: nativeRef.nativeSessionId, omit_messages: true } : {
|
|
20623
|
+
cwd: input.cwd,
|
|
20624
|
+
...model2 ? { model: model2 } : {},
|
|
20625
|
+
...input.kind === "create" && input.thinkingOptionId ? { reasoning: input.thinkingOptionId } : {}
|
|
20626
|
+
}
|
|
20627
|
+
);
|
|
20342
20628
|
const runtimeId = gatewayString(response.session_id);
|
|
20343
20629
|
const storedId = nativeRef?.nativeSessionId || gatewayString(response.stored_session_id);
|
|
20344
20630
|
if (!runtimeId || !storedId)
|
|
20345
20631
|
throw new Error("Hermes gateway did not return Session identity");
|
|
20346
|
-
|
|
20347
|
-
if (info.lazy === true)
|
|
20348
|
-
info = await transport.waitForSession(runtimeId);
|
|
20632
|
+
const info = gatewayRecord(response.info);
|
|
20349
20633
|
const nativeCwd = gatewayString(info.cwd);
|
|
20350
20634
|
if (nativeCwd && !await sameDirectory(nativeCwd, input.cwd))
|
|
20351
20635
|
throw new HermesGatewayHistoryError("unsupported", "Hermes resumed a different native working directory");
|
|
20352
|
-
const bridge = new HermesGatewaySessionTransport(transport, runtimeId, storedId, info
|
|
20353
|
-
|
|
20354
|
-
|
|
20355
|
-
|
|
20356
|
-
|
|
20357
|
-
|
|
20358
|
-
|
|
20359
|
-
|
|
20360
|
-
|
|
20361
|
-
if (gatewayString(info.stored_session_id) !== physicalId)
|
|
20362
|
-
throw new Error("Hermes live Session and persisted history identities differ");
|
|
20636
|
+
const bridge = new HermesGatewaySessionTransport(transport, runtimeId, storedId, info, {
|
|
20637
|
+
revision: response.revision,
|
|
20638
|
+
generation: response.execution_generation,
|
|
20639
|
+
subscriptionId: response.subscription_id
|
|
20640
|
+
}, transport.delegationGuidance);
|
|
20641
|
+
bridge.adoptPendingPrompts(response.prompts);
|
|
20642
|
+
if (nativeRef) {
|
|
20643
|
+
await bridge.history.resolvePhysicalSessionId();
|
|
20644
|
+
}
|
|
20363
20645
|
if (model2)
|
|
20364
20646
|
await bridge.setModel(model2);
|
|
20365
20647
|
if (input.kind !== "fork" && input.thinkingOptionId)
|
|
@@ -20411,6 +20693,7 @@ var HermesAdapter = class {
|
|
|
20411
20693
|
#importReads = /* @__PURE__ */ new Map();
|
|
20412
20694
|
#closed = false;
|
|
20413
20695
|
#gatewayTransports = /* @__PURE__ */ new Set();
|
|
20696
|
+
#gatewayPool = new GatewayTransportPool(2);
|
|
20414
20697
|
#gatewayProbes = /* @__PURE__ */ new Map();
|
|
20415
20698
|
#openingNativeIds = /* @__PURE__ */ new Set();
|
|
20416
20699
|
usageStatistics;
|
|
@@ -20536,9 +20819,10 @@ var HermesAdapter = class {
|
|
|
20536
20819
|
return failure("sessionBusy", "This Hermes Session already has an owner", true);
|
|
20537
20820
|
if (ref)
|
|
20538
20821
|
this.#openingNativeIds.add(ref.nativeSessionId);
|
|
20539
|
-
|
|
20540
|
-
this.#gatewayTransports.add(transport);
|
|
20822
|
+
let transport;
|
|
20541
20823
|
try {
|
|
20824
|
+
transport = this.#gatewayPool.acquire(runtime, input.cwd, environment) ?? await startGatewayTransport(runtime, input.cwd, environment, this.#options.commandTimeoutMs);
|
|
20825
|
+
this.#gatewayTransports.add(transport);
|
|
20542
20826
|
let inheritedMode;
|
|
20543
20827
|
if (input.kind === "fork") {
|
|
20544
20828
|
const source = [...this.#sessions].find((s) => s.initialState.nativeRef?.nativeSessionId === input.sourceRef.nativeSessionId);
|
|
@@ -20549,6 +20833,7 @@ var HermesAdapter = class {
|
|
|
20549
20833
|
const session = await openGatewaySession(input, transport, (settled) => {
|
|
20550
20834
|
this.#sessions.delete(settled);
|
|
20551
20835
|
this.#gatewayTransports.delete(transport);
|
|
20836
|
+
this.#gatewayPool.release(transport);
|
|
20552
20837
|
}, inheritedMode);
|
|
20553
20838
|
if (this.#closed) {
|
|
20554
20839
|
await session.close();
|
|
@@ -20557,8 +20842,10 @@ var HermesAdapter = class {
|
|
|
20557
20842
|
this.#sessions.add(session);
|
|
20558
20843
|
return { ok: true, value: session };
|
|
20559
20844
|
} catch (error51) {
|
|
20560
|
-
|
|
20561
|
-
|
|
20845
|
+
if (transport) {
|
|
20846
|
+
await transport.close().catch(() => void 0);
|
|
20847
|
+
this.#gatewayTransports.delete(transport);
|
|
20848
|
+
}
|
|
20562
20849
|
return failure(error51 instanceof HermesGatewayHistoryError ? error51.code : "nativeFailure", error51 instanceof Error ? error51.message : "Hermes gateway open failed");
|
|
20563
20850
|
} finally {
|
|
20564
20851
|
if (ref)
|
|
@@ -20582,6 +20869,7 @@ var HermesAdapter = class {
|
|
|
20582
20869
|
await Promise.all(sessions.map((session) => session.close().catch(() => void 0)));
|
|
20583
20870
|
await Promise.all([...this.#gatewayTransports].map((transport) => transport.close()));
|
|
20584
20871
|
this.#gatewayTransports.clear();
|
|
20872
|
+
await this.#gatewayPool.close();
|
|
20585
20873
|
}
|
|
20586
20874
|
#effectiveEnvironment(environment) {
|
|
20587
20875
|
return { ...this.#options.environment ?? process.env, ...environment ?? {} };
|