@karlorz/codexhost-cli-win32-x64 0.16.1-3 → 0.17.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.txt +6 -2
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +55 -20
- package/app/console-web.js +45 -17
- package/app/cpa-live-voice-hook.js +31 -8
- package/app/desktop-controller.mjs +76 -31
- package/app/host-runtime.mjs +2387 -1587
- package/app/plugins/antigravity/plugin.mjs +35 -2
- package/app/plugins/claude-code/plugin.mjs +12 -6
- package/app/plugins/codebuddy/plugin.mjs +10 -0
- package/app/plugins/cursor-cli/plugin.mjs +9 -5
- package/app/plugins/deepseek-harness/plugin.mjs +459 -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 +489 -403
- package/app/plugins/hermes/plugin.mjs +453 -196
- package/app/plugins/pi/plugin.mjs +1460 -411
- package/app/plugins/qoder/plugin.mjs +9524 -8654
- package/app/plugins/qoder-cn/plugin.mjs +9524 -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 +10 -0
- package/app/renderer-extension.js +1032 -479
- 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
|
}
|
|
@@ -16793,7 +16793,35 @@ import path4 from "node:path";
|
|
|
16793
16793
|
|
|
16794
16794
|
// dist/hermes-runtime.js
|
|
16795
16795
|
import { execFile as execFile2 } from "node:child_process";
|
|
16796
|
+
import { statSync } from "node:fs";
|
|
16796
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
|
+
}
|
|
16797
16825
|
function legacyHermesPythonCommand(python, script) {
|
|
16798
16826
|
return {
|
|
16799
16827
|
command: python,
|
|
@@ -16809,22 +16837,12 @@ ${script}`
|
|
|
16809
16837
|
};
|
|
16810
16838
|
}
|
|
16811
16839
|
async function nativeHermesPythonCommand(launcher, script, environment, timeoutMs = 2e4, platform = process.platform) {
|
|
16812
|
-
const
|
|
16813
|
-
|
|
16814
|
-
|
|
16815
|
-
|
|
16816
|
-
|
|
16817
|
-
|
|
16818
|
-
"1",
|
|
16819
|
-
"-r",
|
|
16820
|
-
"1",
|
|
16821
|
-
"-s",
|
|
16822
|
-
// timeit is a stdlib entry point supported by the native launcher. After
|
|
16823
|
-
// the operation returns, redirect its timing footer, preserving normal
|
|
16824
|
-
// native cleanup and exit status without contaminating JSON/RPC stdout.
|
|
16825
|
-
`exec(${JSON.stringify(script)}, {}); import sys, io; sys.stdout = io.StringIO()`,
|
|
16826
|
-
"pass"
|
|
16827
|
-
], 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);
|
|
16828
16846
|
let stdout;
|
|
16829
16847
|
try {
|
|
16830
16848
|
({ stdout } = await promisify(execFile2)(invocation.command, invocation.arguments, {
|
|
@@ -16844,6 +16862,9 @@ async function nativeHermesPythonCommand(launcher, script, environment, timeoutM
|
|
|
16844
16862
|
if (!Array.isArray(value) || value.length === 0 || !value.every((arg) => typeof arg === "string") || !value[0]) {
|
|
16845
16863
|
throw new Error("Hermes launcher returned an invalid runtime command");
|
|
16846
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));
|
|
16847
16868
|
return { command: value[0], arguments: value.slice(1) };
|
|
16848
16869
|
}
|
|
16849
16870
|
async function hermesPythonCommand(runtime, script, environment, timeoutMs = 2e4) {
|
|
@@ -17156,9 +17177,6 @@ function catalogModelsFromInventory(inventory) {
|
|
|
17156
17177
|
}
|
|
17157
17178
|
|
|
17158
17179
|
// dist/gateway-delegation.js
|
|
17159
|
-
import { mkdtemp as mkdtemp2, writeFile as writeFile2, rm as rm2 } from "node:fs/promises";
|
|
17160
|
-
import os2 from "node:os";
|
|
17161
|
-
import path5 from "node:path";
|
|
17162
17180
|
var HERMES_DELEGATION_GUIDANCE = `This Session runs inside codexhost.
|
|
17163
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.`;
|
|
17164
17182
|
var required2 = [
|
|
@@ -17169,48 +17187,40 @@ var required2 = [
|
|
|
17169
17187
|
];
|
|
17170
17188
|
async function prepareGatewayDelegation(environment) {
|
|
17171
17189
|
if (!required2.every((key) => environment[key]))
|
|
17172
|
-
return { environment, bootstrap: "", dispose: async () => {
|
|
17190
|
+
return { environment, bootstrap: "", guidance: null, dispose: async () => {
|
|
17173
17191
|
} };
|
|
17174
|
-
|
|
17175
|
-
|
|
17176
|
-
|
|
17177
|
-
|
|
17178
|
-
|
|
17179
|
-
|
|
17180
|
-
|
|
17181
|
-
|
|
17182
|
-
|
|
17183
|
-
|
|
17184
|
-
|
|
17185
|
-
|
|
17186
|
-
|
|
17187
|
-
|
|
17188
|
-
|
|
17189
|
-
|
|
17190
|
-
// process-local; no plugin is installed and no user config is changed.
|
|
17191
|
-
//
|
|
17192
|
-
// ``hermes_bootstrap`` must run before ``tui_gateway.server`` is imported:
|
|
17193
|
-
// the gateway spawn uses ``python -I``, so PYTHONPATH and the launcher's
|
|
17194
|
-
// activation are stripped. Hermes's own entry point (``tui_gateway/entry.py``)
|
|
17195
|
-
// imports this module first to put the selected dependency environment on
|
|
17196
|
-
// ``sys.path``; skipping it makes bare third-party imports (e.g.
|
|
17197
|
-
// ``hermes_yaml`` -> ``ruamel``) fail on interpreters whose site-packages
|
|
17198
|
-
// do not already carry Hermes's dependencies. ``hermes_bootstrap`` is
|
|
17199
|
-
// import-safe here for the same reason entry.py relies on it: stdlib-only
|
|
17200
|
-
// at import time, so nothing can shadow it from the launch directory.
|
|
17201
|
-
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
|
|
17202
17208
|
from tui_gateway import server
|
|
17203
|
-
|
|
17204
|
-
from hermes_cli.plugins import PluginContext, PluginManifest, get_plugin_manager
|
|
17205
|
-
PluginContext(PluginManifest(name="codexhost-runtime"), get_plugin_manager()).register_skill(
|
|
17206
|
-
"delegation", Path(${JSON.stringify(file2)}))
|
|
17209
|
+
sys.stdout = _stdout
|
|
17207
17210
|
`,
|
|
17208
|
-
|
|
17209
|
-
|
|
17210
|
-
|
|
17211
|
-
|
|
17212
|
-
|
|
17213
|
-
|
|
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
|
+
};
|
|
17214
17224
|
}
|
|
17215
17225
|
|
|
17216
17226
|
// dist/hermes-transport.js
|
|
@@ -17244,8 +17254,87 @@ function gatewayRecord(value) {
|
|
|
17244
17254
|
function gatewayString(value) {
|
|
17245
17255
|
return typeof value === "string" ? value : "";
|
|
17246
17256
|
}
|
|
17247
|
-
var GATEWAY_LAUNCH = `import
|
|
17248
|
-
|
|
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
|
+
`;
|
|
17249
17338
|
var HermesGatewayTransport = class _HermesGatewayTransport {
|
|
17250
17339
|
runtime;
|
|
17251
17340
|
cwd;
|
|
@@ -17272,6 +17361,18 @@ var HermesGatewayTransport = class _HermesGatewayTransport {
|
|
|
17272
17361
|
this.environment = environment;
|
|
17273
17362
|
this.timeoutMs = timeoutMs;
|
|
17274
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
|
+
}
|
|
17275
17376
|
static async probe(executable, cwd, environment) {
|
|
17276
17377
|
const override = environment.CODEXHOST_HERMES_GATEWAY_PYTHON;
|
|
17277
17378
|
if (override) {
|
|
@@ -17784,7 +17885,7 @@ async function resolveHermesSessionCandidate(input) {
|
|
|
17784
17885
|
}
|
|
17785
17886
|
|
|
17786
17887
|
// dist/command.js
|
|
17787
|
-
import
|
|
17888
|
+
import path5 from "node:path";
|
|
17788
17889
|
var HermesExecutableError = class extends Error {
|
|
17789
17890
|
code = "HERMES_NOT_FOUND";
|
|
17790
17891
|
};
|
|
@@ -17807,7 +17908,62 @@ function resolveHermesExecutable(input = {}) {
|
|
|
17807
17908
|
});
|
|
17808
17909
|
if (!resolution)
|
|
17809
17910
|
throw new HermesExecutableError("Hermes CLI is not installed");
|
|
17810
|
-
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;
|
|
17811
17967
|
}
|
|
17812
17968
|
|
|
17813
17969
|
// dist/gateway-history.js
|
|
@@ -17897,21 +18053,24 @@ def capture(db):
|
|
|
17897
18053
|
boundaries[str(row['id'])] = {'count': end, 'digest': digest(active[:end])}
|
|
17898
18054
|
return exported, {'rows': rows, 'derivable': derivable, 'boundaries': boundaries, 'physicalSessionId': sid}
|
|
17899
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
|
+
|
|
17900
18069
|
try:
|
|
17901
18070
|
if p['operation'] == 'ensure':
|
|
17902
18071
|
db = SessionDB()
|
|
17903
18072
|
try:
|
|
17904
|
-
|
|
17905
|
-
from hermes_constants import parse_reasoning_effort
|
|
17906
|
-
initial = {}
|
|
17907
|
-
if isinstance(p.get('provider'), str) and p['provider']: initial['provider'] = p['provider']
|
|
17908
|
-
if isinstance(p.get('model'), str) and p['model']: initial['model'] = p['model']
|
|
17909
|
-
if isinstance(p.get('reasoningEffort'), str):
|
|
17910
|
-
reasoning = parse_reasoning_effort(p['reasoningEffort'])
|
|
17911
|
-
if reasoning is not None: initial['reasoning_config'] = reasoning
|
|
17912
|
-
if isinstance(p.get('yolo'), bool): initial['yolo_mode'] = p['yolo']
|
|
17913
|
-
db.create_session(session_id=sid, source='cli', cwd=p['cwd'], model=p.get('model'), model_config=initial)
|
|
17914
|
-
result = {'created': True}
|
|
18073
|
+
result = ensure_session_row(db)
|
|
17915
18074
|
finally: db.close()
|
|
17916
18075
|
elif p['operation'] == 'discard':
|
|
17917
18076
|
child = p['derivedSessionId']
|
|
@@ -18279,28 +18438,6 @@ var HermesUsage = class {
|
|
|
18279
18438
|
}
|
|
18280
18439
|
};
|
|
18281
18440
|
|
|
18282
|
-
// dist/gateway-configuration.js
|
|
18283
|
-
import { execFile as execFile4 } from "node:child_process";
|
|
18284
|
-
import { promisify as promisify3 } from "node:util";
|
|
18285
|
-
async function resolveGatewayModel(transport, modelId) {
|
|
18286
|
-
if (/\s/u.test(modelId) || modelId.startsWith("-"))
|
|
18287
|
-
throw new Error("Invalid Hermes Model identifier");
|
|
18288
|
-
const command = await hermesPythonCommand(transport.runtime, `import json
|
|
18289
|
-
from hermes_cli.models import parse_model_input
|
|
18290
|
-
p,m=parse_model_input(${JSON.stringify(modelId)}, '')
|
|
18291
|
-
print(json.dumps({'provider':p,'model':m}))`, { ...process.env, ...transport.environment });
|
|
18292
|
-
const result = await promisify3(execFile4)(command.command, command.arguments, {
|
|
18293
|
-
cwd: transport.cwd,
|
|
18294
|
-
env: { ...process.env, ...transport.environment },
|
|
18295
|
-
timeout: 2e4,
|
|
18296
|
-
maxBuffer: 1024 * 1024
|
|
18297
|
-
});
|
|
18298
|
-
const value = JSON.parse(result.stdout.trim());
|
|
18299
|
-
if (!value || typeof value !== "object" || !("provider" in value) || !("model" in value) || typeof value.provider !== "string" || typeof value.model !== "string")
|
|
18300
|
-
throw new Error("Hermes returned an invalid Model choice");
|
|
18301
|
-
return { provider: value.provider, model: value.model };
|
|
18302
|
-
}
|
|
18303
|
-
|
|
18304
18441
|
// dist/gateway-session-transport.js
|
|
18305
18442
|
var hermesGatewayThinkingOptions = [
|
|
18306
18443
|
"none",
|
|
@@ -18332,14 +18469,14 @@ function gatewayDiff(text2) {
|
|
|
18332
18469
|
if (!text2 || text2.length > 1024 * 1024)
|
|
18333
18470
|
return [];
|
|
18334
18471
|
const result = [];
|
|
18335
|
-
let
|
|
18472
|
+
let path8 = "";
|
|
18336
18473
|
let inHunk = false;
|
|
18337
18474
|
let oldLines = [], newLines = [];
|
|
18338
18475
|
const flush = () => {
|
|
18339
|
-
if (
|
|
18476
|
+
if (path8)
|
|
18340
18477
|
result.push({
|
|
18341
18478
|
type: "diff",
|
|
18342
|
-
path:
|
|
18479
|
+
path: path8,
|
|
18343
18480
|
oldText: oldLines.join("\n"),
|
|
18344
18481
|
newText: newLines.join("\n")
|
|
18345
18482
|
});
|
|
@@ -18352,24 +18489,24 @@ function gatewayDiff(text2) {
|
|
|
18352
18489
|
if (header) {
|
|
18353
18490
|
flush();
|
|
18354
18491
|
inHunk = false;
|
|
18355
|
-
|
|
18492
|
+
path8 = (header[2] === "/dev/null" ? header[1] ?? "" : header[2] ?? "").replace(/^[ab]\//u, "");
|
|
18356
18493
|
continue;
|
|
18357
18494
|
}
|
|
18358
18495
|
if (line.startsWith("--- ") && !inHunk) {
|
|
18359
18496
|
flush();
|
|
18360
|
-
|
|
18497
|
+
path8 = line.slice(4).replace(/^a\//u, "");
|
|
18361
18498
|
} else if (line.startsWith("+++ ") && !inHunk) {
|
|
18362
18499
|
const next = line.slice(4);
|
|
18363
18500
|
if (next !== "/dev/null")
|
|
18364
|
-
|
|
18501
|
+
path8 = next.replace(/^b\//u, "");
|
|
18365
18502
|
} else if (line.startsWith("@@")) {
|
|
18366
18503
|
inHunk = true;
|
|
18367
18504
|
continue;
|
|
18368
|
-
} else if (
|
|
18505
|
+
} else if (path8 && line.startsWith("-"))
|
|
18369
18506
|
oldLines.push(line.slice(1));
|
|
18370
|
-
else if (
|
|
18507
|
+
else if (path8 && line.startsWith("+"))
|
|
18371
18508
|
newLines.push(line.slice(1));
|
|
18372
|
-
else if (
|
|
18509
|
+
else if (path8 && line.startsWith(" ")) {
|
|
18373
18510
|
oldLines.push(line.slice(1));
|
|
18374
18511
|
newLines.push(line.slice(1));
|
|
18375
18512
|
}
|
|
@@ -18393,7 +18530,7 @@ var HermesGatewaySessionTransport = class {
|
|
|
18393
18530
|
return this.#commands;
|
|
18394
18531
|
}
|
|
18395
18532
|
async getCommands() {
|
|
18396
|
-
const params = { session_id: this.sessionId
|
|
18533
|
+
const params = { session_id: this.sessionId };
|
|
18397
18534
|
const [response, catalog] = await Promise.all([
|
|
18398
18535
|
this.transport.request("complete.slash", { ...params, text: "/" }, this.transport.timeoutMs, false),
|
|
18399
18536
|
this.transport.request("commands.catalog", params, this.transport.timeoutMs, false)
|
|
@@ -18418,13 +18555,29 @@ var HermesGatewaySessionTransport = class {
|
|
|
18418
18555
|
history;
|
|
18419
18556
|
#active = null;
|
|
18420
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 = [];
|
|
18421
18562
|
#closed = false;
|
|
18422
18563
|
#info;
|
|
18423
|
-
|
|
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) {
|
|
18424
18570
|
this.transport = transport;
|
|
18425
18571
|
this.sessionId = sessionId;
|
|
18426
18572
|
this.nativeSessionId = nativeSessionId;
|
|
18427
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;
|
|
18428
18581
|
this.history = new HermesGatewayHistory({
|
|
18429
18582
|
python: transport.runtime,
|
|
18430
18583
|
cwd: transport.cwd,
|
|
@@ -18485,17 +18638,24 @@ var HermesGatewaySessionTransport = class {
|
|
|
18485
18638
|
return optionId;
|
|
18486
18639
|
}
|
|
18487
18640
|
async setModel(modelId) {
|
|
18488
|
-
const
|
|
18489
|
-
const
|
|
18490
|
-
|
|
18491
|
-
|
|
18492
|
-
|
|
18493
|
-
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 }
|
|
18494
18652
|
});
|
|
18495
|
-
if (result.
|
|
18496
|
-
|
|
18497
|
-
|
|
18498
|
-
|
|
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);
|
|
18499
18659
|
if (modelId !== actualModel && modelId !== `${actualProvider}:${actualModel}`)
|
|
18500
18660
|
throw new Error("Hermes did not confirm the requested Model");
|
|
18501
18661
|
}
|
|
@@ -18505,11 +18665,11 @@ var HermesGatewaySessionTransport = class {
|
|
|
18505
18665
|
const result = await this.transport.request("config.set", {
|
|
18506
18666
|
key: "yolo",
|
|
18507
18667
|
value: modeId === "dont_ask" ? "on" : "off",
|
|
18508
|
-
scope: "session",
|
|
18509
18668
|
session_id: this.sessionId
|
|
18510
18669
|
});
|
|
18511
|
-
if (result.value !== (modeId === "dont_ask" ? "1" : "0")
|
|
18670
|
+
if (result.value !== (modeId === "dont_ask" ? "1" : "0"))
|
|
18512
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" };
|
|
18513
18673
|
}
|
|
18514
18674
|
nativeCommandName(text2) {
|
|
18515
18675
|
return hermesGatewayCommandName(text2, this.#commands);
|
|
@@ -18532,9 +18692,11 @@ var HermesGatewaySessionTransport = class {
|
|
|
18532
18692
|
reject: rejectResult,
|
|
18533
18693
|
streamed: "",
|
|
18534
18694
|
reasoning: "",
|
|
18535
|
-
toolIds: /* @__PURE__ */ new Set()
|
|
18695
|
+
toolIds: /* @__PURE__ */ new Set(),
|
|
18696
|
+
admissionId: null
|
|
18536
18697
|
};
|
|
18537
18698
|
this.#active = active;
|
|
18699
|
+
void this.#adoptedPrompts.splice(0).map((prompt) => void this.#respondAdoptedApproval(prompt, active).catch(() => void 0));
|
|
18538
18700
|
const commandText = text2.trim();
|
|
18539
18701
|
const nativeCommand = this.nativeCommandName(text2);
|
|
18540
18702
|
try {
|
|
@@ -18573,12 +18735,21 @@ var HermesGatewaySessionTransport = class {
|
|
|
18573
18735
|
emit({ type: "agent.text", text: response.output });
|
|
18574
18736
|
active.resolve({ stopReason: "end_turn" });
|
|
18575
18737
|
} else {
|
|
18738
|
+
const guidance = this.#delegationGuidance;
|
|
18739
|
+
this.#delegationGuidance = null;
|
|
18576
18740
|
const submitted = await this.transport.request("prompt.submit", {
|
|
18577
18741
|
session_id: this.sessionId,
|
|
18578
|
-
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}` } : {}
|
|
18579
18748
|
});
|
|
18580
|
-
if (submitted.status !== "
|
|
18581
|
-
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;
|
|
18582
18753
|
}
|
|
18583
18754
|
} catch (error51) {
|
|
18584
18755
|
active.reject(error51 instanceof Error ? error51 : new Error(String(error51)));
|
|
@@ -18594,7 +18765,12 @@ var HermesGatewaySessionTransport = class {
|
|
|
18594
18765
|
}
|
|
18595
18766
|
}
|
|
18596
18767
|
async cancel() {
|
|
18597
|
-
|
|
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
|
+
});
|
|
18598
18774
|
}
|
|
18599
18775
|
async close() {
|
|
18600
18776
|
if (this.#closed)
|
|
@@ -18605,10 +18781,13 @@ var HermesGatewaySessionTransport = class {
|
|
|
18605
18781
|
this.#requests.clear();
|
|
18606
18782
|
this.#active?.reject(new Error("Hermes gateway Session closed"));
|
|
18607
18783
|
try {
|
|
18608
|
-
|
|
18784
|
+
if (this.#subscriptionId !== null)
|
|
18785
|
+
await this.transport.request("session.detach", {
|
|
18786
|
+
session_id: this.sessionId,
|
|
18787
|
+
subscription_id: this.#subscriptionId
|
|
18788
|
+
});
|
|
18609
18789
|
} catch {
|
|
18610
18790
|
}
|
|
18611
|
-
await this.transport.close();
|
|
18612
18791
|
}
|
|
18613
18792
|
#fault(error51) {
|
|
18614
18793
|
if (this.#closed)
|
|
@@ -18628,6 +18807,10 @@ var HermesGatewaySessionTransport = class {
|
|
|
18628
18807
|
const payload = gatewayRecord(event.payload);
|
|
18629
18808
|
if (event.type === "session.info") {
|
|
18630
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;
|
|
18631
18814
|
return;
|
|
18632
18815
|
}
|
|
18633
18816
|
if (event.type === "session.usage") {
|
|
@@ -18639,12 +18822,26 @@ var HermesGatewaySessionTransport = class {
|
|
|
18639
18822
|
controller?.abort(payload.reason === "timeout" ? "expired" : "cancelled");
|
|
18640
18823
|
return;
|
|
18641
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
|
+
}
|
|
18642
18833
|
const active = this.#active;
|
|
18643
18834
|
if (!active) {
|
|
18644
18835
|
if (event.type === "error")
|
|
18645
18836
|
this.#fault(new Error(gatewayString(payload.message)));
|
|
18646
18837
|
return;
|
|
18647
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
|
+
}
|
|
18648
18845
|
const text2 = gatewayString(payload.text);
|
|
18649
18846
|
if (event.type === "message.delta") {
|
|
18650
18847
|
active.streamed += text2;
|
|
@@ -18775,27 +18972,80 @@ var HermesGatewaySessionTransport = class {
|
|
|
18775
18972
|
label: choice === "session" ? "Allow for this session" : "Always allow"
|
|
18776
18973
|
}
|
|
18777
18974
|
] : choice === "deny" ? [{ id: "deny", effect: "deny", label: "Deny" }] : []);
|
|
18778
|
-
const
|
|
18779
|
-
|
|
18780
|
-
|
|
18781
|
-
|
|
18782
|
-
|
|
18783
|
-
|
|
18784
|
-
|
|
18785
|
-
|
|
18786
|
-
|
|
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
|
|
18787
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
|
+
}
|
|
18788
18993
|
} else
|
|
18789
18994
|
this.transport.rejectRequest(id);
|
|
18790
18995
|
} finally {
|
|
18791
18996
|
this.#requests.delete(id);
|
|
18792
18997
|
}
|
|
18793
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
|
+
}
|
|
18794
19044
|
};
|
|
18795
19045
|
|
|
18796
19046
|
// dist/usage-statistics.js
|
|
18797
|
-
import
|
|
18798
|
-
import
|
|
19047
|
+
import os2 from "node:os";
|
|
19048
|
+
import path6 from "node:path";
|
|
18799
19049
|
import { lstat } from "node:fs/promises";
|
|
18800
19050
|
|
|
18801
19051
|
// ../../harness-adapter/dist/usage-statistics.js
|
|
@@ -18855,9 +19105,9 @@ function usageEntryFromRequest(request, occurredAtMs) {
|
|
|
18855
19105
|
|
|
18856
19106
|
// dist/usage-statistics.js
|
|
18857
19107
|
function hermesStateDatabasePath(environment) {
|
|
18858
|
-
const home = environment.HOME || environment.USERPROFILE ||
|
|
19108
|
+
const home = environment.HOME || environment.USERPROFILE || os2.homedir();
|
|
18859
19109
|
const configured = environment.HERMES_HOME;
|
|
18860
|
-
return
|
|
19110
|
+
return path6.resolve(configured ? path6.join(configured, "state.db") : path6.join(home, ".hermes", "state.db"));
|
|
18861
19111
|
}
|
|
18862
19112
|
async function fingerprint(file2) {
|
|
18863
19113
|
const info = await lstat(file2).catch(() => null);
|
|
@@ -18939,7 +19189,7 @@ function createHermesUsageStatistics(environment) {
|
|
|
18939
19189
|
}
|
|
18940
19190
|
|
|
18941
19191
|
// dist/gateway-open.js
|
|
18942
|
-
import
|
|
19192
|
+
import path7 from "node:path";
|
|
18943
19193
|
import { realpath } from "node:fs/promises";
|
|
18944
19194
|
|
|
18945
19195
|
// dist/hermes-session.js
|
|
@@ -19149,16 +19399,16 @@ var Diff = class {
|
|
|
19149
19399
|
}
|
|
19150
19400
|
}
|
|
19151
19401
|
}
|
|
19152
|
-
addToPath(
|
|
19153
|
-
const last =
|
|
19402
|
+
addToPath(path8, added, removed, oldPosInc, options) {
|
|
19403
|
+
const last = path8.lastComponent;
|
|
19154
19404
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
19155
19405
|
return {
|
|
19156
|
-
oldPos:
|
|
19406
|
+
oldPos: path8.oldPos + oldPosInc,
|
|
19157
19407
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
19158
19408
|
};
|
|
19159
19409
|
} else {
|
|
19160
19410
|
return {
|
|
19161
|
-
oldPos:
|
|
19411
|
+
oldPos: path8.oldPos + oldPosInc,
|
|
19162
19412
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
19163
19413
|
};
|
|
19164
19414
|
}
|
|
@@ -19473,8 +19723,8 @@ function hermesFileChanges(update) {
|
|
|
19473
19723
|
for (const block of update.content ?? []) {
|
|
19474
19724
|
if (block.type !== "diff")
|
|
19475
19725
|
continue;
|
|
19476
|
-
const { path:
|
|
19477
|
-
if (!
|
|
19726
|
+
const { path: path8, oldText, newText } = block;
|
|
19727
|
+
if (!path8.trim() || /[\0\r\n]/u.test(path8) || typeof newText !== "string")
|
|
19478
19728
|
continue;
|
|
19479
19729
|
if (oldText === newText)
|
|
19480
19730
|
continue;
|
|
@@ -19482,10 +19732,10 @@ function hermesFileChanges(update) {
|
|
|
19482
19732
|
if (bytes > MAX_DIFF_BYTES || changes.length === MAX_DIFFS)
|
|
19483
19733
|
return [];
|
|
19484
19734
|
changes.push({
|
|
19485
|
-
path:
|
|
19735
|
+
path: path8,
|
|
19486
19736
|
kind: "update",
|
|
19487
19737
|
diffScope: "fragment",
|
|
19488
|
-
unifiedDiff: createTwoFilesPatch(
|
|
19738
|
+
unifiedDiff: createTwoFilesPatch(path8, path8, oldText ?? "", newText, "", "", {
|
|
19489
19739
|
context: 3
|
|
19490
19740
|
})
|
|
19491
19741
|
});
|
|
@@ -20290,7 +20540,7 @@ ${reason}` }
|
|
|
20290
20540
|
|
|
20291
20541
|
// dist/gateway-open.js
|
|
20292
20542
|
async function sameDirectory(left, right) {
|
|
20293
|
-
return await realpath(left).catch(() =>
|
|
20543
|
+
return await realpath(left).catch(() => path7.resolve(left)) === await realpath(right).catch(() => path7.resolve(right));
|
|
20294
20544
|
}
|
|
20295
20545
|
var gatewayCapabilities = {
|
|
20296
20546
|
configuration: {
|
|
@@ -20352,8 +20602,10 @@ async function openGatewaySession(input, transport, onSettle, inheritedPermissio
|
|
|
20352
20602
|
let nativeRef = source;
|
|
20353
20603
|
let sourceHistory;
|
|
20354
20604
|
try {
|
|
20355
|
-
|
|
20356
|
-
|
|
20605
|
+
if (!transport.started) {
|
|
20606
|
+
await transport.prepareSession();
|
|
20607
|
+
await transport.start();
|
|
20608
|
+
}
|
|
20357
20609
|
if (source && (input.kind === "fork" || input.kind === "rollbackLastTurn")) {
|
|
20358
20610
|
sourceHistory = new HermesGatewayHistory({
|
|
20359
20611
|
python: transport.runtime,
|
|
@@ -20363,34 +20615,33 @@ async function openGatewaySession(input, transport, onSettle, inheritedPermissio
|
|
|
20363
20615
|
});
|
|
20364
20616
|
nativeRef = await sourceHistory.derive(input.kind === "fork" ? { checkpoint: input.checkpoint } : { rollbackLastTurn: true });
|
|
20365
20617
|
}
|
|
20366
|
-
const
|
|
20367
|
-
|
|
20368
|
-
|
|
20369
|
-
close_on_disconnect
|
|
20370
|
-
|
|
20371
|
-
|
|
20372
|
-
|
|
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
|
+
);
|
|
20373
20628
|
const runtimeId = gatewayString(response.session_id);
|
|
20374
20629
|
const storedId = nativeRef?.nativeSessionId || gatewayString(response.stored_session_id);
|
|
20375
20630
|
if (!runtimeId || !storedId)
|
|
20376
20631
|
throw new Error("Hermes gateway did not return Session identity");
|
|
20377
|
-
|
|
20378
|
-
if (info.lazy === true)
|
|
20379
|
-
info = await transport.waitForSession(runtimeId);
|
|
20632
|
+
const info = gatewayRecord(response.info);
|
|
20380
20633
|
const nativeCwd = gatewayString(info.cwd);
|
|
20381
20634
|
if (nativeCwd && !await sameDirectory(nativeCwd, input.cwd))
|
|
20382
20635
|
throw new HermesGatewayHistoryError("unsupported", "Hermes resumed a different native working directory");
|
|
20383
|
-
const bridge = new HermesGatewaySessionTransport(transport, runtimeId, storedId, info
|
|
20384
|
-
|
|
20385
|
-
|
|
20386
|
-
|
|
20387
|
-
|
|
20388
|
-
|
|
20389
|
-
|
|
20390
|
-
|
|
20391
|
-
|
|
20392
|
-
if (gatewayString(info.stored_session_id) !== physicalId)
|
|
20393
|
-
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
|
+
}
|
|
20394
20645
|
if (model2)
|
|
20395
20646
|
await bridge.setModel(model2);
|
|
20396
20647
|
if (input.kind !== "fork" && input.thinkingOptionId)
|
|
@@ -20442,6 +20693,7 @@ var HermesAdapter = class {
|
|
|
20442
20693
|
#importReads = /* @__PURE__ */ new Map();
|
|
20443
20694
|
#closed = false;
|
|
20444
20695
|
#gatewayTransports = /* @__PURE__ */ new Set();
|
|
20696
|
+
#gatewayPool = new GatewayTransportPool(2);
|
|
20445
20697
|
#gatewayProbes = /* @__PURE__ */ new Map();
|
|
20446
20698
|
#openingNativeIds = /* @__PURE__ */ new Set();
|
|
20447
20699
|
usageStatistics;
|
|
@@ -20567,9 +20819,10 @@ var HermesAdapter = class {
|
|
|
20567
20819
|
return failure("sessionBusy", "This Hermes Session already has an owner", true);
|
|
20568
20820
|
if (ref)
|
|
20569
20821
|
this.#openingNativeIds.add(ref.nativeSessionId);
|
|
20570
|
-
|
|
20571
|
-
this.#gatewayTransports.add(transport);
|
|
20822
|
+
let transport;
|
|
20572
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);
|
|
20573
20826
|
let inheritedMode;
|
|
20574
20827
|
if (input.kind === "fork") {
|
|
20575
20828
|
const source = [...this.#sessions].find((s) => s.initialState.nativeRef?.nativeSessionId === input.sourceRef.nativeSessionId);
|
|
@@ -20580,6 +20833,7 @@ var HermesAdapter = class {
|
|
|
20580
20833
|
const session = await openGatewaySession(input, transport, (settled) => {
|
|
20581
20834
|
this.#sessions.delete(settled);
|
|
20582
20835
|
this.#gatewayTransports.delete(transport);
|
|
20836
|
+
this.#gatewayPool.release(transport);
|
|
20583
20837
|
}, inheritedMode);
|
|
20584
20838
|
if (this.#closed) {
|
|
20585
20839
|
await session.close();
|
|
@@ -20588,8 +20842,10 @@ var HermesAdapter = class {
|
|
|
20588
20842
|
this.#sessions.add(session);
|
|
20589
20843
|
return { ok: true, value: session };
|
|
20590
20844
|
} catch (error51) {
|
|
20591
|
-
|
|
20592
|
-
|
|
20845
|
+
if (transport) {
|
|
20846
|
+
await transport.close().catch(() => void 0);
|
|
20847
|
+
this.#gatewayTransports.delete(transport);
|
|
20848
|
+
}
|
|
20593
20849
|
return failure(error51 instanceof HermesGatewayHistoryError ? error51.code : "nativeFailure", error51 instanceof Error ? error51.message : "Hermes gateway open failed");
|
|
20594
20850
|
} finally {
|
|
20595
20851
|
if (ref)
|
|
@@ -20613,6 +20869,7 @@ var HermesAdapter = class {
|
|
|
20613
20869
|
await Promise.all(sessions.map((session) => session.close().catch(() => void 0)));
|
|
20614
20870
|
await Promise.all([...this.#gatewayTransports].map((transport) => transport.close()));
|
|
20615
20871
|
this.#gatewayTransports.clear();
|
|
20872
|
+
await this.#gatewayPool.close();
|
|
20616
20873
|
}
|
|
20617
20874
|
#effectiveEnvironment(environment) {
|
|
20618
20875
|
return { ...this.#options.environment ?? process.env, ...environment ?? {} };
|