@adhdev/daemon-core 0.9.76-rc.50 → 0.9.76-rc.52
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/dist/index.js +54 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -15
- package/dist/index.mjs.map +1 -1
- package/dist/session-host/runtime-support.d.ts +2 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +15 -0
- package/src/providers/cli-provider-instance.ts +5 -2
- package/src/session-host/runtime-support.ts +55 -7
package/dist/index.js
CHANGED
|
@@ -11914,6 +11914,7 @@ function buildSessionModalDeliverySignature(payload) {
|
|
|
11914
11914
|
// src/commands/chat-commands.ts
|
|
11915
11915
|
var RECENT_SEND_WINDOW_MS = 1200;
|
|
11916
11916
|
var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
|
|
11917
|
+
var HERMES_CLI_STARTING_SEND_SETTLE_MS = 2e3;
|
|
11917
11918
|
var recentSendByTarget = /* @__PURE__ */ new Map();
|
|
11918
11919
|
function getCurrentProviderType(h, fallback = "") {
|
|
11919
11920
|
return h.currentSession?.providerType || h.currentProviderType || fallback;
|
|
@@ -11966,6 +11967,16 @@ function buildSendInputSignature(input) {
|
|
|
11966
11967
|
function getSendChatInputEnvelope(args) {
|
|
11967
11968
|
return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
|
|
11968
11969
|
}
|
|
11970
|
+
function sleep(ms) {
|
|
11971
|
+
return new Promise((resolve16) => setTimeout(resolve16, ms));
|
|
11972
|
+
}
|
|
11973
|
+
async function waitOnceForFreshHermesCliStart(adapter, log) {
|
|
11974
|
+
if (adapter.cliType !== "hermes-cli") return;
|
|
11975
|
+
const status = typeof adapter.getStatus === "function" ? adapter.getStatus()?.status : void 0;
|
|
11976
|
+
if (status !== "starting") return;
|
|
11977
|
+
log(`Hermes CLI is still starting; waiting ${HERMES_CLI_STARTING_SEND_SETTLE_MS}ms before first send`);
|
|
11978
|
+
await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
|
|
11979
|
+
}
|
|
11969
11980
|
function getHistorySessionId(h, args) {
|
|
11970
11981
|
const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
|
|
11971
11982
|
if (explicit) return explicit;
|
|
@@ -12825,6 +12836,7 @@ async function handleSendChat(h, args) {
|
|
|
12825
12836
|
try {
|
|
12826
12837
|
assertTextOnlyInput(provider, input);
|
|
12827
12838
|
if (!text) return { success: false, error: "text required for PTY send" };
|
|
12839
|
+
await waitOnceForFreshHermesCliStart(adapter, _log);
|
|
12828
12840
|
await adapter.sendMessage(text);
|
|
12829
12841
|
return _logSendSuccess(`${transport}-adapter`, adapter.cliType);
|
|
12830
12842
|
} catch (e) {
|
|
@@ -15752,8 +15764,6 @@ ${effect.notification.body || ""}`.trim();
|
|
|
15752
15764
|
const aTime = getTime(a.message);
|
|
15753
15765
|
const bTime = getTime(b.message);
|
|
15754
15766
|
if (aTime && bTime && aTime !== bTime) return aTime - bTime;
|
|
15755
|
-
if (aTime && !bTime && a.source === "runtime" && b.source === "parsed") return -1;
|
|
15756
|
-
if (!aTime && bTime && a.source === "parsed" && b.source === "runtime") return 1;
|
|
15757
15767
|
return a.index - b.index;
|
|
15758
15768
|
}).map((entry) => entry.message));
|
|
15759
15769
|
}
|
|
@@ -26106,7 +26116,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
|
|
|
26106
26116
|
if (!adapter) return null;
|
|
26107
26117
|
return { target, instance, adapter };
|
|
26108
26118
|
}
|
|
26109
|
-
function
|
|
26119
|
+
function sleep2(ms) {
|
|
26110
26120
|
return new Promise((resolve16) => setTimeout(resolve16, ms));
|
|
26111
26121
|
}
|
|
26112
26122
|
async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
|
|
@@ -26123,7 +26133,7 @@ async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
|
|
|
26123
26133
|
return bundle;
|
|
26124
26134
|
}
|
|
26125
26135
|
}
|
|
26126
|
-
await
|
|
26136
|
+
await sleep2(100);
|
|
26127
26137
|
}
|
|
26128
26138
|
return getCliTargetBundle(ctx, type, instanceId);
|
|
26129
26139
|
}
|
|
@@ -26179,7 +26189,7 @@ async function runCliExerciseInternal(ctx, body) {
|
|
|
26179
26189
|
const message = String(lastLaunchError.message || "");
|
|
26180
26190
|
const retryable = /ECONNREFUSED|session-host|Session host/i.test(message);
|
|
26181
26191
|
if (!retryable || attempt === 2) break;
|
|
26182
|
-
await
|
|
26192
|
+
await sleep2(1e3);
|
|
26183
26193
|
}
|
|
26184
26194
|
}
|
|
26185
26195
|
if (!launched) {
|
|
@@ -26242,16 +26252,16 @@ async function runCliExerciseInternal(ctx, body) {
|
|
|
26242
26252
|
const modal = debug?.activeModal || trace?.activeModal || null;
|
|
26243
26253
|
noteStatus(status);
|
|
26244
26254
|
if (resolveActiveModalIfNeeded(status, modal)) {
|
|
26245
|
-
await
|
|
26255
|
+
await sleep2(150);
|
|
26246
26256
|
continue;
|
|
26247
26257
|
}
|
|
26248
26258
|
const startupParseGate = !!debug?.startupParseGate;
|
|
26249
26259
|
if (status === "idle" && !startupParseGate) break;
|
|
26250
|
-
await
|
|
26260
|
+
await sleep2(150);
|
|
26251
26261
|
}
|
|
26252
26262
|
ctx.instanceManager.sendEvent(bundle.target.instanceId, "send_message", { text });
|
|
26253
26263
|
while (Date.now() - startAt < Math.max(1e3, timeoutMs)) {
|
|
26254
|
-
await
|
|
26264
|
+
await sleep2(150);
|
|
26255
26265
|
bundle = getCliTargetBundle(ctx, type, bundle.target.instanceId);
|
|
26256
26266
|
if (!bundle) {
|
|
26257
26267
|
throw new Error("CLI instance disappeared during exercise");
|
|
@@ -30139,29 +30149,58 @@ function resolveSessionHostAppName(options = {}) {
|
|
|
30139
30149
|
var import_session_host_core4 = require("@adhdev/session-host-core");
|
|
30140
30150
|
var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
|
|
30141
30151
|
var STARTUP_POLL_MS = 200;
|
|
30142
|
-
|
|
30152
|
+
var SessionHostCompatibilityError = class extends Error {
|
|
30153
|
+
constructor(message) {
|
|
30154
|
+
super(message);
|
|
30155
|
+
this.name = "SessionHostCompatibilityError";
|
|
30156
|
+
}
|
|
30157
|
+
};
|
|
30158
|
+
function getMissingRequestTypes(diagnostics, requiredRequestTypes) {
|
|
30159
|
+
const supported = new Set(diagnostics?.supportedRequestTypes || []);
|
|
30160
|
+
return requiredRequestTypes.filter((requestType) => !supported.has(requestType));
|
|
30161
|
+
}
|
|
30162
|
+
async function assertRequiredRequestTypes(client, requiredRequestTypes) {
|
|
30163
|
+
if (requiredRequestTypes.length === 0) return;
|
|
30164
|
+
const response = await client.request({
|
|
30165
|
+
type: "get_host_diagnostics",
|
|
30166
|
+
payload: { includeSessions: false }
|
|
30167
|
+
});
|
|
30168
|
+
const missing = getMissingRequestTypes(response.success ? response.result : void 0, requiredRequestTypes);
|
|
30169
|
+
if (missing.length > 0) {
|
|
30170
|
+
const detail = response.success ? "" : ` (${response.error || "capability probe failed"})`;
|
|
30171
|
+
throw new SessionHostCompatibilityError(
|
|
30172
|
+
`Session host does not support required request types: ${missing.join(", ")}${detail}`
|
|
30173
|
+
);
|
|
30174
|
+
}
|
|
30175
|
+
}
|
|
30176
|
+
async function canConnect(endpoint, requiredRequestTypes = []) {
|
|
30143
30177
|
const client = new import_session_host_core4.SessionHostClient({ endpoint });
|
|
30144
30178
|
try {
|
|
30145
30179
|
await client.connect();
|
|
30146
|
-
await client
|
|
30180
|
+
await assertRequiredRequestTypes(client, requiredRequestTypes);
|
|
30147
30181
|
return true;
|
|
30148
|
-
} catch {
|
|
30182
|
+
} catch (error) {
|
|
30183
|
+
if (error instanceof SessionHostCompatibilityError) throw error;
|
|
30149
30184
|
return false;
|
|
30185
|
+
} finally {
|
|
30186
|
+
await client.close().catch(() => {
|
|
30187
|
+
});
|
|
30150
30188
|
}
|
|
30151
30189
|
}
|
|
30152
|
-
async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
|
|
30190
|
+
async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRequestTypes = []) {
|
|
30153
30191
|
const deadline = Date.now() + timeoutMs;
|
|
30154
30192
|
while (Date.now() < deadline) {
|
|
30155
|
-
if (await canConnect(endpoint)) return;
|
|
30193
|
+
if (await canConnect(endpoint, requiredRequestTypes)) return;
|
|
30156
30194
|
await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
|
|
30157
30195
|
}
|
|
30158
30196
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
30159
30197
|
}
|
|
30160
30198
|
async function ensureSessionHostReady(options) {
|
|
30161
30199
|
const endpoint = (0, import_session_host_core4.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
|
|
30162
|
-
|
|
30200
|
+
const requiredRequestTypes = options.requiredRequestTypes || [];
|
|
30201
|
+
if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
|
|
30163
30202
|
options.spawnHost();
|
|
30164
|
-
await waitForReady(endpoint, options.timeoutMs);
|
|
30203
|
+
await waitForReady(endpoint, options.timeoutMs, requiredRequestTypes);
|
|
30165
30204
|
return endpoint;
|
|
30166
30205
|
}
|
|
30167
30206
|
async function listHostedCliRuntimes(endpoint) {
|