@liberseek/boft-cli-linux-x64 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +58 -5
- package/app/console-web.js +436 -67
- package/app/desktop-controller.mjs +72 -9
- package/app/host-runtime.mjs +772 -218
- package/app/plugins/antigravity/plugin.mjs +91 -13
- package/app/plugins/claude-code/plugin.mjs +404 -26
- package/app/plugins/codebuddy/plugin.mjs +117 -22
- package/app/plugins/codex-usage/plugin.mjs +176 -74
- package/app/plugins/copilot/assets/icon.png +0 -0
- package/app/plugins/copilot/manifest.json +26 -0
- package/app/plugins/copilot/plugin.mjs +34601 -0
- package/app/plugins/cursor-cli/plugin.mjs +20794 -44912
- package/app/plugins/deepseek-harness/plugin.mjs +83 -11
- package/app/plugins/enabled.json +1 -0
- package/app/plugins/grok/plugin.mjs +250 -40
- package/app/plugins/hermes/plugin.mjs +80 -9
- package/app/plugins/kimi-code/plugin.mjs +76 -7
- package/app/plugins/kiro-cli/plugin.mjs +76 -7
- package/app/plugins/muse/plugin.mjs +73 -5
- package/app/plugins/omp/plugin.mjs +2155 -2000
- package/app/plugins/opencode/plugin.mjs +85 -11
- package/app/plugins/pi/plugin.mjs +2515 -2298
- package/app/plugins/qoder/plugin.mjs +83 -11
- package/app/plugins/qoder-cn/plugin.mjs +83 -11
- package/app/plugins/workbuddy/plugin.mjs +378 -46
- package/app/plugins/zcode/plugin.mjs +84 -11
- package/app/renderer-extension.js +833 -162
- package/bin/boft +0 -0
- package/libexec/boft-shim +0 -0
- package/libexec/boft-updater +0 -0
- package/package.json +1 -1
|
@@ -424,10 +424,13 @@ function usageSessionTitle(value) {
|
|
|
424
424
|
return void 0;
|
|
425
425
|
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
426
426
|
return normalized;
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
427
|
+
let title = "";
|
|
428
|
+
for (const character of normalized) {
|
|
429
|
+
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
430
|
+
break;
|
|
431
|
+
title += character;
|
|
432
|
+
}
|
|
433
|
+
return `${title.trimEnd()}…`;
|
|
431
434
|
}
|
|
432
435
|
function sessionIdOk(value) {
|
|
433
436
|
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
@@ -15202,10 +15205,19 @@ var model = external_exports.string().min(1).max(512);
|
|
|
15202
15205
|
var project = external_exports.string().min(1).max(4096);
|
|
15203
15206
|
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
15204
15207
|
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15208
|
+
/** Display timezone for ranges, dates and hourly buckets; omitted means the Host's local zone. */
|
|
15209
|
+
timeZone: external_exports.string().min(1).max(128).refine((value) => {
|
|
15210
|
+
try {
|
|
15211
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
15212
|
+
return true;
|
|
15213
|
+
} catch {
|
|
15214
|
+
return false;
|
|
15215
|
+
}
|
|
15216
|
+
}, "Unsupported usage statistics timezone").optional(),
|
|
15205
15217
|
harness: harness.optional(),
|
|
15206
15218
|
model: model.nullable().optional(),
|
|
15207
15219
|
project: project.nullable().optional(),
|
|
15208
|
-
/** One
|
|
15220
|
+
/** One date in the query timezone inside the range. */
|
|
15209
15221
|
date: localDate.optional()
|
|
15210
15222
|
});
|
|
15211
15223
|
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
@@ -15241,7 +15253,7 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
|
15241
15253
|
});
|
|
15242
15254
|
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
15243
15255
|
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15244
|
-
/** First
|
|
15256
|
+
/** First date in the query timezone (Host local when omitted); null for all time. */
|
|
15245
15257
|
from: localDate.nullable(),
|
|
15246
15258
|
to: localDate,
|
|
15247
15259
|
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
@@ -15281,7 +15293,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
15281
15293
|
totals: usageStatisticsTotalsSchema,
|
|
15282
15294
|
/** Each date and Harness of the range: every filter except the day. */
|
|
15283
15295
|
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
15284
|
-
/**
|
|
15296
|
+
/** Weekday (0 = Sunday) and hour in the query timezone, all filters applied. */
|
|
15285
15297
|
hourly: external_exports.array(external_exports.strictObject({
|
|
15286
15298
|
weekday: external_exports.number().int().min(0).max(6),
|
|
15287
15299
|
hour: external_exports.number().int().min(0).max(23),
|
|
@@ -15423,6 +15435,8 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
15423
15435
|
"codexhost/harness/display-settings/set",
|
|
15424
15436
|
"codexhost/harness/inspect",
|
|
15425
15437
|
"codexhost/harness/installation",
|
|
15438
|
+
"codexhost/harness/installation/start",
|
|
15439
|
+
"codexhost/harness/installation/status",
|
|
15426
15440
|
"codexhost/harness/launch-settings/get",
|
|
15427
15441
|
"codexhost/harness/launch-settings/set",
|
|
15428
15442
|
HARNESS_LONG_CONTEXT_GET_METHOD,
|
|
@@ -15500,7 +15514,18 @@ var threadManualCompactionStartedSchema = external_exports.strictObject({
|
|
|
15500
15514
|
var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
|
|
15501
15515
|
var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
|
|
15502
15516
|
var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
|
|
15517
|
+
var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
|
|
15518
|
+
var composerIndicatorsSchema = external_exports.array(external_exports.object({
|
|
15519
|
+
kind: external_exports.literal("countdown"),
|
|
15520
|
+
id: external_exports.string().min(1).max(64),
|
|
15521
|
+
expiresAtUnix: nonNegativeSafeIntegerSchema,
|
|
15522
|
+
label: indicatorTextSchema(256).optional(),
|
|
15523
|
+
tooltip: indicatorTextSchema(1024).optional()
|
|
15524
|
+
}).strict()).max(2).refine((entries) => new Set(entries.map(({ id }) => id)).size === entries.length, {
|
|
15525
|
+
message: "Composer indicator IDs must be unique"
|
|
15526
|
+
});
|
|
15503
15527
|
var threadUsageSnapshotSchema = external_exports.object({
|
|
15528
|
+
composerIndicators: composerIndicatorsSchema.optional(),
|
|
15504
15529
|
inputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15505
15530
|
cachedInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15506
15531
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
@@ -15926,7 +15951,9 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
|
|
|
15926
15951
|
}).strict().optional(),
|
|
15927
15952
|
input: external_exports.object({
|
|
15928
15953
|
image: external_exports.boolean()
|
|
15929
|
-
}).strict().optional()
|
|
15954
|
+
}).strict().optional(),
|
|
15955
|
+
/** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
|
|
15956
|
+
steer: external_exports.boolean().optional()
|
|
15930
15957
|
}).strict();
|
|
15931
15958
|
var harnessConfigurationStateSchema = external_exports.object({
|
|
15932
15959
|
effectiveModel: harnessModelRefSchema.optional(),
|
|
@@ -15973,7 +16000,9 @@ var harnessInspectionSchema = external_exports.union([
|
|
|
15973
16000
|
var harnessInspectParamsSchema = external_exports.object({
|
|
15974
16001
|
harnessId: harnessIdSchema,
|
|
15975
16002
|
cwd: nonBlankTextSchema2.max(16384).optional(),
|
|
15976
|
-
refresh: external_exports.boolean().optional()
|
|
16003
|
+
refresh: external_exports.boolean().optional(),
|
|
16004
|
+
/** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
|
|
16005
|
+
purpose: external_exports.literal("availability").optional()
|
|
15977
16006
|
}).strict();
|
|
15978
16007
|
var harnessWebUiOpenParamsSchema = external_exports.object({
|
|
15979
16008
|
harnessId: harnessIdSchema
|
|
@@ -16058,6 +16087,15 @@ var threadOwnershipListResultSchema = external_exports.object({
|
|
|
16058
16087
|
seen.add(thread.threadId);
|
|
16059
16088
|
}
|
|
16060
16089
|
});
|
|
16090
|
+
var threadSteeringInspectParamsSchema = external_exports.object({
|
|
16091
|
+
threadId: hostThreadIdSchema,
|
|
16092
|
+
/** The text about to be steered; a Harness command always stops and restarts. */
|
|
16093
|
+
text: external_exports.string().optional()
|
|
16094
|
+
}).strict();
|
|
16095
|
+
var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
|
|
16096
|
+
var threadSteeringInspectResultSchema = external_exports.object({
|
|
16097
|
+
delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
|
|
16098
|
+
}).strict();
|
|
16061
16099
|
|
|
16062
16100
|
// ../../shared-contracts/dist/harness-route.js
|
|
16063
16101
|
var harnessPluginRouteSchema = external_exports.object({
|
|
@@ -16090,6 +16128,10 @@ var harnessInstallationStateSchema = external_exports.object({
|
|
|
16090
16128
|
latestVersion: external_exports.string().min(1).max(128),
|
|
16091
16129
|
updateAvailable: external_exports.boolean(),
|
|
16092
16130
|
canUpdate: external_exports.boolean(),
|
|
16131
|
+
/** Defaults to CLI; some Harnesses ship only inside a desktop application. */
|
|
16132
|
+
versionKind: external_exports.enum(["cli", "application"]).optional(),
|
|
16133
|
+
/** Official download opened by the user; does not imply an automatic installation. */
|
|
16134
|
+
manualUpdateUrl: external_exports.url().max(2048).refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Manual updates require a credential-free HTTPS URL").optional(),
|
|
16093
16135
|
// Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
|
|
16094
16136
|
message: external_exports.string().max(2048).optional(),
|
|
16095
16137
|
messageCode: external_exports.string().min(1).max(128).optional(),
|
|
@@ -16097,6 +16139,20 @@ var harnessInstallationStateSchema = external_exports.object({
|
|
|
16097
16139
|
notice: harnessLocalizedTextSchema.optional(),
|
|
16098
16140
|
latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
|
|
16099
16141
|
}).strict();
|
|
16142
|
+
var harnessInstallationTaskParamsSchema = external_exports.object({ taskId: external_exports.string().uuid() }).strict();
|
|
16143
|
+
var harnessInstallationTaskSchema = external_exports.discriminatedUnion("status", [
|
|
16144
|
+
external_exports.object({ taskId: external_exports.string().uuid(), status: external_exports.literal("running") }).strict(),
|
|
16145
|
+
external_exports.object({
|
|
16146
|
+
taskId: external_exports.string().uuid(),
|
|
16147
|
+
status: external_exports.literal("succeeded"),
|
|
16148
|
+
result: harnessInstallationStateSchema
|
|
16149
|
+
}).strict(),
|
|
16150
|
+
external_exports.object({
|
|
16151
|
+
taskId: external_exports.string().uuid(),
|
|
16152
|
+
status: external_exports.literal("failed"),
|
|
16153
|
+
error: external_exports.object({ code: external_exports.number().int(), message: external_exports.string().min(1).max(2048) }).strict()
|
|
16154
|
+
}).strict()
|
|
16155
|
+
]);
|
|
16100
16156
|
|
|
16101
16157
|
// ../../shared-contracts/dist/codex-accounts.js
|
|
16102
16158
|
var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
|
|
@@ -16910,6 +16966,18 @@ function sanitizeDiagnosticTail(value) {
|
|
|
16910
16966
|
return redacted.length <= DIAGNOSTIC_TAIL_MAX_LENGTH ? redacted : redacted.slice(-DIAGNOSTIC_TAIL_MAX_LENGTH);
|
|
16911
16967
|
}
|
|
16912
16968
|
|
|
16969
|
+
// ../../harness-adapter/dist/steer.js
|
|
16970
|
+
function unsupportedSteer(harnessLabel) {
|
|
16971
|
+
return {
|
|
16972
|
+
ok: false,
|
|
16973
|
+
error: {
|
|
16974
|
+
code: "unsupported",
|
|
16975
|
+
message: `${harnessLabel} cannot steer an active Turn natively`,
|
|
16976
|
+
retryable: false
|
|
16977
|
+
}
|
|
16978
|
+
};
|
|
16979
|
+
}
|
|
16980
|
+
|
|
16913
16981
|
// ../../harness-adapter/dist/usage.js
|
|
16914
16982
|
var tokenFields = [
|
|
16915
16983
|
"inputTokens",
|
|
@@ -16937,6 +17005,7 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
16937
17005
|
...safeIntegerFields,
|
|
16938
17006
|
...percentFields,
|
|
16939
17007
|
"sessionCacheUsage",
|
|
17008
|
+
"composerIndicators",
|
|
16940
17009
|
"totalCostUsd",
|
|
16941
17010
|
"totalCredits",
|
|
16942
17011
|
"contextUsagePercent",
|
|
@@ -16959,6 +17028,7 @@ function parseHostUsage(value) {
|
|
|
16959
17028
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16960
17029
|
}
|
|
16961
17030
|
}
|
|
17031
|
+
const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
|
|
16962
17032
|
for (const field of [
|
|
16963
17033
|
"totalCredits",
|
|
16964
17034
|
"contextUsagePercent",
|
|
@@ -17035,9 +17105,9 @@ function parseHostUsage(value) {
|
|
|
17035
17105
|
if (value.costSource !== "publicPrice") {
|
|
17036
17106
|
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
17037
17107
|
}
|
|
17038
|
-
return { ...value, unpricedModels: [...models] };
|
|
17108
|
+
return { ...value, ...indicators, unpricedModels: [...models] };
|
|
17039
17109
|
}
|
|
17040
|
-
return { ...value };
|
|
17110
|
+
return { ...value, ...indicators };
|
|
17041
17111
|
}
|
|
17042
17112
|
var requestTokenFields = [
|
|
17043
17113
|
"inputTokens",
|
|
@@ -17764,857 +17834,283 @@ function createOmpUsageStatistics(environment) {
|
|
|
17764
17834
|
});
|
|
17765
17835
|
}
|
|
17766
17836
|
|
|
17767
|
-
//
|
|
17768
|
-
|
|
17769
|
-
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
|
|
17775
|
-
|
|
17776
|
-
|
|
17777
|
-
|
|
17778
|
-
|
|
17779
|
-
|
|
17780
|
-
|
|
17781
|
-
|
|
17837
|
+
// dist/omp-model-list.js
|
|
17838
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
17839
|
+
|
|
17840
|
+
// dist/command.js
|
|
17841
|
+
var ompDiscoverySpec = {
|
|
17842
|
+
id: "omp",
|
|
17843
|
+
command: "omp",
|
|
17844
|
+
commandEnvironmentVariable: "OMP_COMMAND",
|
|
17845
|
+
installRoots: {
|
|
17846
|
+
posix: [
|
|
17847
|
+
"~/.npm-global/bin",
|
|
17848
|
+
"~/.local/bin",
|
|
17849
|
+
VERSION_MANAGER_ROOTS,
|
|
17850
|
+
"/opt/homebrew/bin",
|
|
17851
|
+
"/usr/local/bin"
|
|
17852
|
+
],
|
|
17853
|
+
windows: ["${APPDATA}/npm", "~/.local/bin", VERSION_MANAGER_ROOTS]
|
|
17782
17854
|
}
|
|
17783
|
-
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17791
|
-
|
|
17792
|
-
|
|
17793
|
-
|
|
17855
|
+
};
|
|
17856
|
+
function resolveOmpExecutable(input, dependencies = {}) {
|
|
17857
|
+
const resolution = resolveHarnessExecutable(ompDiscoverySpec, {
|
|
17858
|
+
...input.command ? { command: input.command } : {},
|
|
17859
|
+
environment: input.environment,
|
|
17860
|
+
...dependencies.platform ? { platform: dependencies.platform } : {},
|
|
17861
|
+
...dependencies.homeDirectory ? { homeDirectory: dependencies.homeDirectory } : {}
|
|
17862
|
+
}, { ...dependencies.isExecutable ? { isExecutable: dependencies.isExecutable } : {} });
|
|
17863
|
+
return resolution?.executable ?? input.command ?? input.environment.OMP_COMMAND ?? "omp";
|
|
17864
|
+
}
|
|
17865
|
+
|
|
17866
|
+
// dist/omp-rpc-session.js
|
|
17867
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
17868
|
+
import { randomUUID } from "node:crypto";
|
|
17869
|
+
import path6 from "node:path";
|
|
17870
|
+
|
|
17871
|
+
// dist/omp-slash-commands.js
|
|
17872
|
+
var OMP_LIVE_COMMAND_ID_PREFIX = "omp.slash.";
|
|
17873
|
+
function isRecord6(value) {
|
|
17874
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17875
|
+
}
|
|
17876
|
+
function parseOmpAvailableCommands(value) {
|
|
17877
|
+
if (!Array.isArray(value))
|
|
17878
|
+
return [];
|
|
17879
|
+
return value.flatMap((entry) => {
|
|
17880
|
+
if (!isRecord6(entry))
|
|
17881
|
+
return [];
|
|
17882
|
+
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
17883
|
+
if (!name)
|
|
17884
|
+
return [];
|
|
17885
|
+
return [
|
|
17886
|
+
{
|
|
17887
|
+
name,
|
|
17888
|
+
description: typeof entry.description === "string" ? entry.description : "",
|
|
17889
|
+
source: typeof entry.source === "string" ? entry.source : null
|
|
17794
17890
|
}
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
|
|
17815
|
-
|
|
17816
|
-
|
|
17817
|
-
|
|
17818
|
-
|
|
17819
|
-
|
|
17820
|
-
|
|
17821
|
-
|
|
17822
|
-
|
|
17823
|
-
|
|
17824
|
-
|
|
17825
|
-
|
|
17826
|
-
|
|
17827
|
-
|
|
17828
|
-
|
|
17829
|
-
|
|
17830
|
-
|
|
17831
|
-
|
|
17832
|
-
|
|
17833
|
-
|
|
17834
|
-
|
|
17835
|
-
|
|
17836
|
-
|
|
17837
|
-
|
|
17838
|
-
|
|
17839
|
-
|
|
17840
|
-
|
|
17841
|
-
|
|
17842
|
-
}
|
|
17843
|
-
}
|
|
17891
|
+
];
|
|
17892
|
+
});
|
|
17893
|
+
}
|
|
17894
|
+
function ompLiveCommands(native) {
|
|
17895
|
+
return native.filter(({ source, name }) => source !== "builtin" || name === "context").map((command) => ({
|
|
17896
|
+
name: command.name,
|
|
17897
|
+
description: command.description,
|
|
17898
|
+
kind: command.source === "skill" ? "skill" : "command"
|
|
17899
|
+
}));
|
|
17900
|
+
}
|
|
17901
|
+
|
|
17902
|
+
// dist/omp-session-file.js
|
|
17903
|
+
import { createReadStream as createReadStream3 } from "node:fs";
|
|
17904
|
+
import { open, realpath as realpath2 } from "node:fs/promises";
|
|
17905
|
+
import readline from "node:readline";
|
|
17906
|
+
var MAX_SESSION_HEADER_BYTES = 64 * 1024;
|
|
17907
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
17908
|
+
function isRecord7(value) {
|
|
17909
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17910
|
+
}
|
|
17911
|
+
function historyEntry(value) {
|
|
17912
|
+
if (!isRecord7(value) || value.type === "title" || value.type === "session" || typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
|
|
17913
|
+
return null;
|
|
17914
|
+
}
|
|
17915
|
+
return value;
|
|
17916
|
+
}
|
|
17917
|
+
async function readOmpSessionHistory(sessionFile, maxBytes) {
|
|
17918
|
+
const entries = [];
|
|
17919
|
+
let leafId = null;
|
|
17920
|
+
let incomplete = false;
|
|
17921
|
+
const lines = readline.createInterface({
|
|
17922
|
+
input: createReadStream3(sessionFile, {
|
|
17923
|
+
encoding: "utf8",
|
|
17924
|
+
...maxBytes === void 0 ? {} : { end: maxBytes - 1 }
|
|
17925
|
+
}),
|
|
17926
|
+
crlfDelay: Number.POSITIVE_INFINITY
|
|
17927
|
+
});
|
|
17928
|
+
try {
|
|
17929
|
+
for await (const line of lines) {
|
|
17930
|
+
if (line.length === 0)
|
|
17931
|
+
continue;
|
|
17932
|
+
let parsed;
|
|
17933
|
+
try {
|
|
17934
|
+
parsed = JSON.parse(line);
|
|
17935
|
+
} catch {
|
|
17936
|
+
incomplete = true;
|
|
17937
|
+
continue;
|
|
17844
17938
|
}
|
|
17845
|
-
|
|
17846
|
-
|
|
17847
|
-
|
|
17848
|
-
|
|
17849
|
-
setTimeout(function() {
|
|
17850
|
-
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
17851
|
-
return callback(void 0);
|
|
17852
|
-
}
|
|
17853
|
-
if (!execEditLength()) {
|
|
17854
|
-
exec();
|
|
17855
|
-
}
|
|
17856
|
-
}, 0);
|
|
17857
|
-
})();
|
|
17858
|
-
} else {
|
|
17859
|
-
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
17860
|
-
const ret = execEditLength();
|
|
17861
|
-
if (ret) {
|
|
17862
|
-
return ret;
|
|
17939
|
+
const entry = historyEntry(parsed);
|
|
17940
|
+
if (!entry) {
|
|
17941
|
+
if (!isRecord7(parsed) || parsed.type !== "title" && parsed.type !== "session") {
|
|
17942
|
+
incomplete = true;
|
|
17863
17943
|
}
|
|
17944
|
+
continue;
|
|
17864
17945
|
}
|
|
17946
|
+
entries.push(entry);
|
|
17947
|
+
leafId = entry.id;
|
|
17865
17948
|
}
|
|
17949
|
+
} finally {
|
|
17950
|
+
lines.close();
|
|
17866
17951
|
}
|
|
17867
|
-
|
|
17868
|
-
|
|
17869
|
-
|
|
17870
|
-
|
|
17871
|
-
|
|
17872
|
-
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
|
|
17876
|
-
|
|
17877
|
-
|
|
17878
|
-
};
|
|
17952
|
+
return { entries, leafId, ...incomplete ? { incomplete: true } : {} };
|
|
17953
|
+
}
|
|
17954
|
+
async function readOmpSessionHeader(sessionFile) {
|
|
17955
|
+
const handle = await open(sessionFile, "r");
|
|
17956
|
+
try {
|
|
17957
|
+
const buffer = Buffer.allocUnsafe(MAX_SESSION_HEADER_BYTES);
|
|
17958
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
17959
|
+
const contents = buffer.subarray(0, bytesRead);
|
|
17960
|
+
const newline = contents.indexOf(10);
|
|
17961
|
+
if (newline < 0 && bytesRead === buffer.length) {
|
|
17962
|
+
throw new Error("Omp Session header exceeds the supported size");
|
|
17879
17963
|
}
|
|
17880
|
-
|
|
17881
|
-
|
|
17882
|
-
|
|
17883
|
-
|
|
17884
|
-
|
|
17885
|
-
|
|
17886
|
-
|
|
17887
|
-
|
|
17888
|
-
|
|
17889
|
-
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
17964
|
+
const contentsText = utf8Decoder.decode(contents);
|
|
17965
|
+
for (const line of contentsText.split("\n")) {
|
|
17966
|
+
if (line.length === 0)
|
|
17967
|
+
continue;
|
|
17968
|
+
let parsed;
|
|
17969
|
+
try {
|
|
17970
|
+
parsed = JSON.parse(line);
|
|
17971
|
+
} catch {
|
|
17972
|
+
continue;
|
|
17890
17973
|
}
|
|
17891
|
-
|
|
17892
|
-
|
|
17893
|
-
|
|
17894
|
-
|
|
17895
|
-
basePath.oldPos = oldPos;
|
|
17896
|
-
return newPos;
|
|
17897
|
-
}
|
|
17898
|
-
equals(left, right, options) {
|
|
17899
|
-
if (options.comparator) {
|
|
17900
|
-
return options.comparator(left, right);
|
|
17901
|
-
} else {
|
|
17902
|
-
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
17903
|
-
}
|
|
17904
|
-
}
|
|
17905
|
-
removeEmpty(array2) {
|
|
17906
|
-
const ret = [];
|
|
17907
|
-
for (let i = 0; i < array2.length; i++) {
|
|
17908
|
-
if (array2[i]) {
|
|
17909
|
-
ret.push(array2[i]);
|
|
17974
|
+
if (!isRecord7(parsed) || parsed.type !== "session")
|
|
17975
|
+
continue;
|
|
17976
|
+
if (typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
|
|
17977
|
+
throw new Error("Omp Session header is invalid");
|
|
17910
17978
|
}
|
|
17979
|
+
return { type: "session", id: parsed.id, cwd: parsed.cwd };
|
|
17911
17980
|
}
|
|
17912
|
-
|
|
17913
|
-
}
|
|
17914
|
-
|
|
17915
|
-
castInput(value, options) {
|
|
17916
|
-
return value;
|
|
17917
|
-
}
|
|
17918
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17919
|
-
tokenize(value, options) {
|
|
17920
|
-
return Array.from(value);
|
|
17921
|
-
}
|
|
17922
|
-
join(chars) {
|
|
17923
|
-
return chars.join("");
|
|
17981
|
+
throw new Error("Omp Session header is invalid");
|
|
17982
|
+
} finally {
|
|
17983
|
+
await handle.close();
|
|
17924
17984
|
}
|
|
17925
|
-
|
|
17926
|
-
|
|
17985
|
+
}
|
|
17986
|
+
async function verifyOmpSessionCwd(input) {
|
|
17987
|
+
if (!input.sessionFile)
|
|
17988
|
+
throw new Error("Omp Fork Session has no persisted Session file");
|
|
17989
|
+
const header = await readOmpSessionHeader(input.sessionFile);
|
|
17990
|
+
if (header.id !== input.sessionId) {
|
|
17991
|
+
throw new Error("Omp Fork Session header identity does not match RPC state");
|
|
17927
17992
|
}
|
|
17928
|
-
|
|
17929
|
-
|
|
17993
|
+
const [actualCwd, expectedCwd] = await Promise.all([
|
|
17994
|
+
realpath2(header.cwd),
|
|
17995
|
+
realpath2(input.expectedCwd)
|
|
17996
|
+
]);
|
|
17997
|
+
if (actualCwd !== expectedCwd) {
|
|
17998
|
+
throw new Error("Omp Fork Session did not bind the requested cwd");
|
|
17930
17999
|
}
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
18000
|
+
}
|
|
18001
|
+
|
|
18002
|
+
// dist/omp-protocol.js
|
|
18003
|
+
var MAX_FRAME_BYTES = 1024 * 1024;
|
|
18004
|
+
var MAX_REASSEMBLED_BYTES = 64 * 1024 * 1024;
|
|
18005
|
+
var MAX_CHUNK_BYTES = 256 * 1024;
|
|
18006
|
+
function isObject2(value) {
|
|
18007
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18008
|
+
}
|
|
18009
|
+
var OmpFrameDecoder = class {
|
|
18010
|
+
#pending = null;
|
|
18011
|
+
push(value) {
|
|
18012
|
+
if (!isObject2(value))
|
|
18013
|
+
throw new Error("OMP RPC frame must be a JSON object");
|
|
18014
|
+
if (value.type !== "rpc_chunk") {
|
|
18015
|
+
if (this.#pending)
|
|
18016
|
+
throw new Error("OMP RPC chunk sequence was interrupted");
|
|
18017
|
+
return value;
|
|
17939
18018
|
}
|
|
17940
|
-
|
|
17941
|
-
const
|
|
17942
|
-
|
|
17943
|
-
|
|
17944
|
-
|
|
17945
|
-
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
component.value = this.join(value);
|
|
17953
|
-
} else {
|
|
17954
|
-
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
17955
|
-
}
|
|
17956
|
-
newPos += component.count;
|
|
17957
|
-
if (!component.added) {
|
|
17958
|
-
oldPos += component.count;
|
|
17959
|
-
}
|
|
17960
|
-
} else {
|
|
17961
|
-
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
17962
|
-
oldPos += component.count;
|
|
17963
|
-
}
|
|
18019
|
+
const chunkId = value.chunkId;
|
|
18020
|
+
const index = value.index;
|
|
18021
|
+
const count2 = value.count;
|
|
18022
|
+
const byteLength = value.byteLength;
|
|
18023
|
+
const data = value.data;
|
|
18024
|
+
if (typeof chunkId !== "string" || chunkId.length === 0 || chunkId.length > 128 || !Number.isInteger(index) || !Number.isInteger(count2) || !Number.isInteger(byteLength) || index < 0 || count2 < 2 || index >= count2 || byteLength < MAX_FRAME_BYTES || byteLength > MAX_REASSEMBLED_BYTES || typeof data !== "string" || data.length === 0)
|
|
18025
|
+
throw new Error("Invalid OMP RPC chunk metadata");
|
|
18026
|
+
let bytes;
|
|
18027
|
+
try {
|
|
18028
|
+
bytes = Buffer.from(data, "base64");
|
|
18029
|
+
} catch {
|
|
18030
|
+
throw new Error("Invalid OMP RPC chunk data");
|
|
17964
18031
|
}
|
|
17965
|
-
|
|
18032
|
+
if (bytes.length === 0 || bytes.length > MAX_CHUNK_BYTES || bytes.toString("base64") !== data) {
|
|
18033
|
+
throw new Error("Invalid OMP RPC chunk data");
|
|
18034
|
+
}
|
|
18035
|
+
const chunkIndex = index;
|
|
18036
|
+
const chunkCount = count2;
|
|
18037
|
+
const declaredByteLength = byteLength;
|
|
18038
|
+
if (!this.#pending) {
|
|
18039
|
+
if (chunkIndex !== 0)
|
|
18040
|
+
throw new Error("OMP RPC chunk sequence must start at index 0");
|
|
18041
|
+
this.#pending = {
|
|
18042
|
+
chunkId,
|
|
18043
|
+
count: chunkCount,
|
|
18044
|
+
byteLength: declaredByteLength,
|
|
18045
|
+
nextIndex: 0,
|
|
18046
|
+
chunks: [],
|
|
18047
|
+
received: 0
|
|
18048
|
+
};
|
|
18049
|
+
}
|
|
18050
|
+
const pending = this.#pending;
|
|
18051
|
+
if (!pending)
|
|
18052
|
+
throw new Error("OMP RPC chunk state was lost");
|
|
18053
|
+
if (pending.chunkId !== chunkId || pending.count !== chunkCount || pending.byteLength !== declaredByteLength || pending.nextIndex !== chunkIndex) {
|
|
18054
|
+
throw new Error("OMP RPC chunk sequence mismatch");
|
|
18055
|
+
}
|
|
18056
|
+
pending.chunks.push(bytes);
|
|
18057
|
+
pending.received += bytes.length;
|
|
18058
|
+
pending.nextIndex += 1;
|
|
18059
|
+
if (pending.received > pending.byteLength)
|
|
18060
|
+
throw new Error("OMP RPC chunk sequence exceeds its declared length");
|
|
18061
|
+
if (pending.nextIndex < pending.count)
|
|
18062
|
+
return null;
|
|
18063
|
+
if (pending.received !== pending.byteLength)
|
|
18064
|
+
throw new Error("OMP RPC chunk sequence length mismatch");
|
|
18065
|
+
this.#pending = null;
|
|
18066
|
+
let decoded;
|
|
18067
|
+
try {
|
|
18068
|
+
decoded = JSON.parse(Buffer.concat(pending.chunks).toString("utf8"));
|
|
18069
|
+
} catch {
|
|
18070
|
+
throw new Error("Failed to decode reassembled OMP RPC frame");
|
|
18071
|
+
}
|
|
18072
|
+
if (!isObject2(decoded))
|
|
18073
|
+
throw new Error("Reassembled OMP RPC frame must be an object");
|
|
18074
|
+
return decoded;
|
|
17966
18075
|
}
|
|
17967
18076
|
};
|
|
17968
18077
|
|
|
17969
|
-
//
|
|
17970
|
-
var
|
|
17971
|
-
|
|
17972
|
-
|
|
17973
|
-
|
|
18078
|
+
// dist/omp-rpc-session.js
|
|
18079
|
+
var OmpRpcFaultError = class extends Error {
|
|
18080
|
+
kind;
|
|
18081
|
+
diagnostic;
|
|
18082
|
+
constructor(kind, message3, diagnostic) {
|
|
18083
|
+
super(message3);
|
|
18084
|
+
this.kind = kind;
|
|
18085
|
+
this.diagnostic = diagnostic;
|
|
18086
|
+
this.name = "OmpRpcFaultError";
|
|
17974
18087
|
}
|
|
17975
|
-
|
|
17976
|
-
|
|
17977
|
-
|
|
17978
|
-
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
}
|
|
17983
|
-
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
17984
|
-
if (left.endsWith("\n")) {
|
|
17985
|
-
left = left.slice(0, -1);
|
|
17986
|
-
}
|
|
17987
|
-
if (right.endsWith("\n")) {
|
|
17988
|
-
right = right.slice(0, -1);
|
|
17989
|
-
}
|
|
17990
|
-
}
|
|
17991
|
-
return super.equals(left, right, options);
|
|
18088
|
+
};
|
|
18089
|
+
var OmpRpcUnsupportedCommandError = class extends Error {
|
|
18090
|
+
command;
|
|
18091
|
+
constructor(command) {
|
|
18092
|
+
super(`Omp RPC does not support '${command}'`);
|
|
18093
|
+
this.command = command;
|
|
18094
|
+
this.name = "OmpRpcUnsupportedCommandError";
|
|
17992
18095
|
}
|
|
17993
18096
|
};
|
|
17994
|
-
var
|
|
17995
|
-
function
|
|
17996
|
-
return
|
|
18097
|
+
var textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
18098
|
+
function isRecord8(value) {
|
|
18099
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17997
18100
|
}
|
|
17998
|
-
function
|
|
17999
|
-
|
|
18000
|
-
|
|
18001
|
-
|
|
18002
|
-
|
|
18003
|
-
|
|
18004
|
-
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
retLines[retLines.length - 1] += line;
|
|
18010
|
-
} else {
|
|
18011
|
-
retLines.push(line);
|
|
18012
|
-
}
|
|
18101
|
+
function message2(value) {
|
|
18102
|
+
return value instanceof Error ? value.message : String(value);
|
|
18103
|
+
}
|
|
18104
|
+
function nonBlankString(value) {
|
|
18105
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
18106
|
+
}
|
|
18107
|
+
function parseNativeModel(value, context) {
|
|
18108
|
+
if (value === null || value === void 0)
|
|
18109
|
+
return null;
|
|
18110
|
+
if (!isRecord8(value) || !nonBlankString(value.provider) || !nonBlankString(value.id)) {
|
|
18111
|
+
throw new OmpRpcFaultError("protocolError", `Omp RPC returned an invalid ${context} Model`);
|
|
18013
18112
|
}
|
|
18014
|
-
return
|
|
18015
|
-
}
|
|
18016
|
-
|
|
18017
|
-
// ../../../node_modules/diff/libesm/patch/parse.js
|
|
18018
|
-
function parsePatch(uniDiff) {
|
|
18019
|
-
const diffstr = uniDiff.split(/\n/), list = [];
|
|
18020
|
-
let i = 0;
|
|
18021
|
-
function parseIndex() {
|
|
18022
|
-
const index = {};
|
|
18023
|
-
list.push(index);
|
|
18024
|
-
while (i < diffstr.length) {
|
|
18025
|
-
const line = diffstr[i];
|
|
18026
|
-
if (/^(---|\+\+\+|@@)\s/.test(line)) {
|
|
18027
|
-
break;
|
|
18028
|
-
}
|
|
18029
|
-
const header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
|
18030
|
-
if (header) {
|
|
18031
|
-
index.index = header[1];
|
|
18032
|
-
}
|
|
18033
|
-
i++;
|
|
18034
|
-
}
|
|
18035
|
-
parseFileHeader(index);
|
|
18036
|
-
parseFileHeader(index);
|
|
18037
|
-
index.hunks = [];
|
|
18038
|
-
while (i < diffstr.length) {
|
|
18039
|
-
const line = diffstr[i];
|
|
18040
|
-
if (/^(Index:\s|diff\s|---\s|\+\+\+\s|===================================================================)/.test(line)) {
|
|
18041
|
-
break;
|
|
18042
|
-
} else if (/^@@/.test(line)) {
|
|
18043
|
-
index.hunks.push(parseHunk());
|
|
18044
|
-
} else if (line) {
|
|
18045
|
-
throw new Error("Unknown line " + (i + 1) + " " + JSON.stringify(line));
|
|
18046
|
-
} else {
|
|
18047
|
-
i++;
|
|
18048
|
-
}
|
|
18049
|
-
}
|
|
18050
|
-
}
|
|
18051
|
-
function parseFileHeader(index) {
|
|
18052
|
-
const fileHeader = /^(---|\+\+\+)\s+(.*)\r?$/.exec(diffstr[i]);
|
|
18053
|
-
if (fileHeader) {
|
|
18054
|
-
const data = fileHeader[2].split(" ", 2), header = (data[1] || "").trim();
|
|
18055
|
-
let fileName = data[0].replace(/\\\\/g, "\\");
|
|
18056
|
-
if (/^".*"$/.test(fileName)) {
|
|
18057
|
-
fileName = fileName.substr(1, fileName.length - 2);
|
|
18058
|
-
}
|
|
18059
|
-
if (fileHeader[1] === "---") {
|
|
18060
|
-
index.oldFileName = fileName;
|
|
18061
|
-
index.oldHeader = header;
|
|
18062
|
-
} else {
|
|
18063
|
-
index.newFileName = fileName;
|
|
18064
|
-
index.newHeader = header;
|
|
18065
|
-
}
|
|
18066
|
-
i++;
|
|
18067
|
-
}
|
|
18068
|
-
}
|
|
18069
|
-
function parseHunk() {
|
|
18070
|
-
var _a3;
|
|
18071
|
-
const chunkHeaderIndex = i, chunkHeaderLine = diffstr[i++], chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
18072
|
-
const hunk = {
|
|
18073
|
-
oldStart: +chunkHeader[1],
|
|
18074
|
-
oldLines: typeof chunkHeader[2] === "undefined" ? 1 : +chunkHeader[2],
|
|
18075
|
-
newStart: +chunkHeader[3],
|
|
18076
|
-
newLines: typeof chunkHeader[4] === "undefined" ? 1 : +chunkHeader[4],
|
|
18077
|
-
lines: []
|
|
18078
|
-
};
|
|
18079
|
-
if (hunk.oldLines === 0) {
|
|
18080
|
-
hunk.oldStart += 1;
|
|
18081
|
-
}
|
|
18082
|
-
if (hunk.newLines === 0) {
|
|
18083
|
-
hunk.newStart += 1;
|
|
18084
|
-
}
|
|
18085
|
-
let addCount = 0, removeCount = 0;
|
|
18086
|
-
for (; i < diffstr.length && (removeCount < hunk.oldLines || addCount < hunk.newLines || ((_a3 = diffstr[i]) === null || _a3 === void 0 ? void 0 : _a3.startsWith("\\"))); i++) {
|
|
18087
|
-
const operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? " " : diffstr[i][0];
|
|
18088
|
-
if (operation === "+" || operation === "-" || operation === " " || operation === "\\") {
|
|
18089
|
-
hunk.lines.push(diffstr[i]);
|
|
18090
|
-
if (operation === "+") {
|
|
18091
|
-
addCount++;
|
|
18092
|
-
} else if (operation === "-") {
|
|
18093
|
-
removeCount++;
|
|
18094
|
-
} else if (operation === " ") {
|
|
18095
|
-
addCount++;
|
|
18096
|
-
removeCount++;
|
|
18097
|
-
}
|
|
18098
|
-
} else {
|
|
18099
|
-
throw new Error(`Hunk at line ${chunkHeaderIndex + 1} contained invalid line ${diffstr[i]}`);
|
|
18100
|
-
}
|
|
18101
|
-
}
|
|
18102
|
-
if (!addCount && hunk.newLines === 1) {
|
|
18103
|
-
hunk.newLines = 0;
|
|
18104
|
-
}
|
|
18105
|
-
if (!removeCount && hunk.oldLines === 1) {
|
|
18106
|
-
hunk.oldLines = 0;
|
|
18107
|
-
}
|
|
18108
|
-
if (addCount !== hunk.newLines) {
|
|
18109
|
-
throw new Error("Added line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
18110
|
-
}
|
|
18111
|
-
if (removeCount !== hunk.oldLines) {
|
|
18112
|
-
throw new Error("Removed line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
18113
|
-
}
|
|
18114
|
-
return hunk;
|
|
18115
|
-
}
|
|
18116
|
-
while (i < diffstr.length) {
|
|
18117
|
-
parseIndex();
|
|
18118
|
-
}
|
|
18119
|
-
return list;
|
|
18120
|
-
}
|
|
18121
|
-
|
|
18122
|
-
// ../../../node_modules/diff/libesm/patch/create.js
|
|
18123
|
-
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
18124
|
-
let optionsObj;
|
|
18125
|
-
if (!options) {
|
|
18126
|
-
optionsObj = {};
|
|
18127
|
-
} else if (typeof options === "function") {
|
|
18128
|
-
optionsObj = { callback: options };
|
|
18129
|
-
} else {
|
|
18130
|
-
optionsObj = options;
|
|
18131
|
-
}
|
|
18132
|
-
if (typeof optionsObj.context === "undefined") {
|
|
18133
|
-
optionsObj.context = 4;
|
|
18134
|
-
}
|
|
18135
|
-
const context = optionsObj.context;
|
|
18136
|
-
if (optionsObj.newlineIsToken) {
|
|
18137
|
-
throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
|
|
18138
|
-
}
|
|
18139
|
-
if (!optionsObj.callback) {
|
|
18140
|
-
return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
|
|
18141
|
-
} else {
|
|
18142
|
-
const { callback } = optionsObj;
|
|
18143
|
-
diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
|
|
18144
|
-
const patch = diffLinesResultToPatch(diff);
|
|
18145
|
-
callback(patch);
|
|
18146
|
-
} }));
|
|
18147
|
-
}
|
|
18148
|
-
function diffLinesResultToPatch(diff) {
|
|
18149
|
-
if (!diff) {
|
|
18150
|
-
return;
|
|
18151
|
-
}
|
|
18152
|
-
diff.push({ value: "", lines: [] });
|
|
18153
|
-
function contextLines(lines) {
|
|
18154
|
-
return lines.map(function(entry) {
|
|
18155
|
-
return " " + entry;
|
|
18156
|
-
});
|
|
18157
|
-
}
|
|
18158
|
-
const hunks = [];
|
|
18159
|
-
let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
18160
|
-
for (let i = 0; i < diff.length; i++) {
|
|
18161
|
-
const current = diff[i], lines = current.lines || splitLines(current.value);
|
|
18162
|
-
current.lines = lines;
|
|
18163
|
-
if (current.added || current.removed) {
|
|
18164
|
-
if (!oldRangeStart) {
|
|
18165
|
-
const prev = diff[i - 1];
|
|
18166
|
-
oldRangeStart = oldLine;
|
|
18167
|
-
newRangeStart = newLine;
|
|
18168
|
-
if (prev) {
|
|
18169
|
-
curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
|
|
18170
|
-
oldRangeStart -= curRange.length;
|
|
18171
|
-
newRangeStart -= curRange.length;
|
|
18172
|
-
}
|
|
18173
|
-
}
|
|
18174
|
-
for (const line of lines) {
|
|
18175
|
-
curRange.push((current.added ? "+" : "-") + line);
|
|
18176
|
-
}
|
|
18177
|
-
if (current.added) {
|
|
18178
|
-
newLine += lines.length;
|
|
18179
|
-
} else {
|
|
18180
|
-
oldLine += lines.length;
|
|
18181
|
-
}
|
|
18182
|
-
} else {
|
|
18183
|
-
if (oldRangeStart) {
|
|
18184
|
-
if (lines.length <= context * 2 && i < diff.length - 2) {
|
|
18185
|
-
for (const line of contextLines(lines)) {
|
|
18186
|
-
curRange.push(line);
|
|
18187
|
-
}
|
|
18188
|
-
} else {
|
|
18189
|
-
const contextSize = Math.min(lines.length, context);
|
|
18190
|
-
for (const line of contextLines(lines.slice(0, contextSize))) {
|
|
18191
|
-
curRange.push(line);
|
|
18192
|
-
}
|
|
18193
|
-
const hunk = {
|
|
18194
|
-
oldStart: oldRangeStart,
|
|
18195
|
-
oldLines: oldLine - oldRangeStart + contextSize,
|
|
18196
|
-
newStart: newRangeStart,
|
|
18197
|
-
newLines: newLine - newRangeStart + contextSize,
|
|
18198
|
-
lines: curRange
|
|
18199
|
-
};
|
|
18200
|
-
hunks.push(hunk);
|
|
18201
|
-
oldRangeStart = 0;
|
|
18202
|
-
newRangeStart = 0;
|
|
18203
|
-
curRange = [];
|
|
18204
|
-
}
|
|
18205
|
-
}
|
|
18206
|
-
oldLine += lines.length;
|
|
18207
|
-
newLine += lines.length;
|
|
18208
|
-
}
|
|
18209
|
-
}
|
|
18210
|
-
for (const hunk of hunks) {
|
|
18211
|
-
for (let i = 0; i < hunk.lines.length; i++) {
|
|
18212
|
-
if (hunk.lines[i].endsWith("\n")) {
|
|
18213
|
-
hunk.lines[i] = hunk.lines[i].slice(0, -1);
|
|
18214
|
-
} else {
|
|
18215
|
-
hunk.lines.splice(i + 1, 0, "\");
|
|
18216
|
-
i++;
|
|
18217
|
-
}
|
|
18218
|
-
}
|
|
18219
|
-
}
|
|
18220
|
-
return {
|
|
18221
|
-
oldFileName,
|
|
18222
|
-
newFileName,
|
|
18223
|
-
oldHeader,
|
|
18224
|
-
newHeader,
|
|
18225
|
-
hunks
|
|
18226
|
-
};
|
|
18227
|
-
}
|
|
18228
|
-
}
|
|
18229
|
-
function formatPatch(patch) {
|
|
18230
|
-
if (Array.isArray(patch)) {
|
|
18231
|
-
return patch.map(formatPatch).join("\n");
|
|
18232
|
-
}
|
|
18233
|
-
const ret = [];
|
|
18234
|
-
if (patch.oldFileName == patch.newFileName) {
|
|
18235
|
-
ret.push("Index: " + patch.oldFileName);
|
|
18236
|
-
}
|
|
18237
|
-
ret.push("===================================================================");
|
|
18238
|
-
ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
|
|
18239
|
-
ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
|
|
18240
|
-
for (let i = 0; i < patch.hunks.length; i++) {
|
|
18241
|
-
const hunk = patch.hunks[i];
|
|
18242
|
-
if (hunk.oldLines === 0) {
|
|
18243
|
-
hunk.oldStart -= 1;
|
|
18244
|
-
}
|
|
18245
|
-
if (hunk.newLines === 0) {
|
|
18246
|
-
hunk.newStart -= 1;
|
|
18247
|
-
}
|
|
18248
|
-
ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
|
|
18249
|
-
for (const line of hunk.lines) {
|
|
18250
|
-
ret.push(line);
|
|
18251
|
-
}
|
|
18252
|
-
}
|
|
18253
|
-
return ret.join("\n") + "\n";
|
|
18254
|
-
}
|
|
18255
|
-
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
18256
|
-
if (typeof options === "function") {
|
|
18257
|
-
options = { callback: options };
|
|
18258
|
-
}
|
|
18259
|
-
if (!(options === null || options === void 0 ? void 0 : options.callback)) {
|
|
18260
|
-
const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
18261
|
-
if (!patchObj) {
|
|
18262
|
-
return;
|
|
18263
|
-
}
|
|
18264
|
-
return formatPatch(patchObj);
|
|
18265
|
-
} else {
|
|
18266
|
-
const { callback } = options;
|
|
18267
|
-
structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
|
|
18268
|
-
if (!patchObj) {
|
|
18269
|
-
callback(void 0);
|
|
18270
|
-
} else {
|
|
18271
|
-
callback(formatPatch(patchObj));
|
|
18272
|
-
}
|
|
18273
|
-
} }));
|
|
18274
|
-
}
|
|
18275
|
-
}
|
|
18276
|
-
function splitLines(text) {
|
|
18277
|
-
const hasTrailingNl = text.endsWith("\n");
|
|
18278
|
-
const result = text.split("\n").map((line) => line + "\n");
|
|
18279
|
-
if (hasTrailingNl) {
|
|
18280
|
-
result.pop();
|
|
18281
|
-
} else {
|
|
18282
|
-
result.push(result.pop().slice(0, -1));
|
|
18283
|
-
}
|
|
18284
|
-
return result;
|
|
18285
|
-
}
|
|
18286
|
-
|
|
18287
|
-
// dist/omp-adapter.js
|
|
18288
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
18289
|
-
import { realpath as realpath3, stat as stat2 } from "node:fs/promises";
|
|
18290
|
-
import path7 from "node:path";
|
|
18291
|
-
|
|
18292
|
-
// dist/omp-slash-commands.js
|
|
18293
|
-
var OMP_LIVE_COMMAND_ID_PREFIX = "omp.slash.";
|
|
18294
|
-
function isRecord6(value) {
|
|
18295
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18296
|
-
}
|
|
18297
|
-
function parseOmpAvailableCommands(value) {
|
|
18298
|
-
if (!Array.isArray(value))
|
|
18299
|
-
return [];
|
|
18300
|
-
return value.flatMap((entry) => {
|
|
18301
|
-
if (!isRecord6(entry))
|
|
18302
|
-
return [];
|
|
18303
|
-
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
18304
|
-
if (!name)
|
|
18305
|
-
return [];
|
|
18306
|
-
return [
|
|
18307
|
-
{
|
|
18308
|
-
name,
|
|
18309
|
-
description: typeof entry.description === "string" ? entry.description : "",
|
|
18310
|
-
source: typeof entry.source === "string" ? entry.source : null
|
|
18311
|
-
}
|
|
18312
|
-
];
|
|
18313
|
-
});
|
|
18314
|
-
}
|
|
18315
|
-
function ompLiveCommands(native) {
|
|
18316
|
-
return native.filter(({ source, name }) => source !== "builtin" || name === "context").map((command) => ({
|
|
18317
|
-
name: command.name,
|
|
18318
|
-
description: command.description,
|
|
18319
|
-
kind: command.source === "skill" ? "skill" : "command"
|
|
18320
|
-
}));
|
|
18321
|
-
}
|
|
18322
|
-
|
|
18323
|
-
// dist/omp-session-file.js
|
|
18324
|
-
import { createReadStream as createReadStream3 } from "node:fs";
|
|
18325
|
-
import { open, realpath as realpath2 } from "node:fs/promises";
|
|
18326
|
-
import readline from "node:readline";
|
|
18327
|
-
var MAX_SESSION_HEADER_BYTES = 64 * 1024;
|
|
18328
|
-
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
18329
|
-
function isRecord7(value) {
|
|
18330
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18331
|
-
}
|
|
18332
|
-
function historyEntry(value) {
|
|
18333
|
-
if (!isRecord7(value) || value.type === "title" || value.type === "session" || typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
|
|
18334
|
-
return null;
|
|
18335
|
-
}
|
|
18336
|
-
return value;
|
|
18337
|
-
}
|
|
18338
|
-
async function readOmpSessionHistory(sessionFile, maxBytes) {
|
|
18339
|
-
const entries = [];
|
|
18340
|
-
let leafId = null;
|
|
18341
|
-
let incomplete = false;
|
|
18342
|
-
const lines = readline.createInterface({
|
|
18343
|
-
input: createReadStream3(sessionFile, {
|
|
18344
|
-
encoding: "utf8",
|
|
18345
|
-
...maxBytes === void 0 ? {} : { end: maxBytes - 1 }
|
|
18346
|
-
}),
|
|
18347
|
-
crlfDelay: Number.POSITIVE_INFINITY
|
|
18348
|
-
});
|
|
18349
|
-
try {
|
|
18350
|
-
for await (const line of lines) {
|
|
18351
|
-
if (line.length === 0)
|
|
18352
|
-
continue;
|
|
18353
|
-
let parsed;
|
|
18354
|
-
try {
|
|
18355
|
-
parsed = JSON.parse(line);
|
|
18356
|
-
} catch {
|
|
18357
|
-
incomplete = true;
|
|
18358
|
-
continue;
|
|
18359
|
-
}
|
|
18360
|
-
const entry = historyEntry(parsed);
|
|
18361
|
-
if (!entry) {
|
|
18362
|
-
if (!isRecord7(parsed) || parsed.type !== "title" && parsed.type !== "session") {
|
|
18363
|
-
incomplete = true;
|
|
18364
|
-
}
|
|
18365
|
-
continue;
|
|
18366
|
-
}
|
|
18367
|
-
entries.push(entry);
|
|
18368
|
-
leafId = entry.id;
|
|
18369
|
-
}
|
|
18370
|
-
} finally {
|
|
18371
|
-
lines.close();
|
|
18372
|
-
}
|
|
18373
|
-
return { entries, leafId, ...incomplete ? { incomplete: true } : {} };
|
|
18374
|
-
}
|
|
18375
|
-
async function readOmpSessionHeader(sessionFile) {
|
|
18376
|
-
const handle = await open(sessionFile, "r");
|
|
18377
|
-
try {
|
|
18378
|
-
const buffer = Buffer.allocUnsafe(MAX_SESSION_HEADER_BYTES);
|
|
18379
|
-
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
18380
|
-
const contents = buffer.subarray(0, bytesRead);
|
|
18381
|
-
const newline = contents.indexOf(10);
|
|
18382
|
-
if (newline < 0 && bytesRead === buffer.length) {
|
|
18383
|
-
throw new Error("Omp Session header exceeds the supported size");
|
|
18384
|
-
}
|
|
18385
|
-
const contentsText = utf8Decoder.decode(contents);
|
|
18386
|
-
for (const line of contentsText.split("\n")) {
|
|
18387
|
-
if (line.length === 0)
|
|
18388
|
-
continue;
|
|
18389
|
-
let parsed;
|
|
18390
|
-
try {
|
|
18391
|
-
parsed = JSON.parse(line);
|
|
18392
|
-
} catch {
|
|
18393
|
-
continue;
|
|
18394
|
-
}
|
|
18395
|
-
if (!isRecord7(parsed) || parsed.type !== "session")
|
|
18396
|
-
continue;
|
|
18397
|
-
if (typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
|
|
18398
|
-
throw new Error("Omp Session header is invalid");
|
|
18399
|
-
}
|
|
18400
|
-
return { type: "session", id: parsed.id, cwd: parsed.cwd };
|
|
18401
|
-
}
|
|
18402
|
-
throw new Error("Omp Session header is invalid");
|
|
18403
|
-
} finally {
|
|
18404
|
-
await handle.close();
|
|
18405
|
-
}
|
|
18406
|
-
}
|
|
18407
|
-
async function verifyOmpSessionCwd(input) {
|
|
18408
|
-
if (!input.sessionFile)
|
|
18409
|
-
throw new Error("Omp Fork Session has no persisted Session file");
|
|
18410
|
-
const header = await readOmpSessionHeader(input.sessionFile);
|
|
18411
|
-
if (header.id !== input.sessionId) {
|
|
18412
|
-
throw new Error("Omp Fork Session header identity does not match RPC state");
|
|
18413
|
-
}
|
|
18414
|
-
const [actualCwd, expectedCwd] = await Promise.all([
|
|
18415
|
-
realpath2(header.cwd),
|
|
18416
|
-
realpath2(input.expectedCwd)
|
|
18417
|
-
]);
|
|
18418
|
-
if (actualCwd !== expectedCwd) {
|
|
18419
|
-
throw new Error("Omp Fork Session did not bind the requested cwd");
|
|
18420
|
-
}
|
|
18421
|
-
}
|
|
18422
|
-
|
|
18423
|
-
// dist/omp-last-turn-rollback.js
|
|
18424
|
-
function modelFromState(state) {
|
|
18425
|
-
if (state.provider === null && state.modelId === null)
|
|
18426
|
-
return null;
|
|
18427
|
-
if (state.provider === null || state.modelId === null) {
|
|
18428
|
-
throw new Error("Omp state contains a partial Model identity");
|
|
18429
|
-
}
|
|
18430
|
-
return { provider: state.provider, id: state.modelId };
|
|
18431
|
-
}
|
|
18432
|
-
async function rollbackOmpLastTurn(transport, sourceSessionId, cwd) {
|
|
18433
|
-
const startupState = transport.state;
|
|
18434
|
-
const startupSessionId = startupState.sessionId;
|
|
18435
|
-
const currentModel = modelFromState(startupState);
|
|
18436
|
-
const currentThinking = startupState.thinkingLevel;
|
|
18437
|
-
const copiedHistory = await transport.getEntries();
|
|
18438
|
-
const boundary = resolveOmpLastTurnBoundary(copiedHistory);
|
|
18439
|
-
if (!boundary)
|
|
18440
|
-
return { ok: false, reason: "empty" };
|
|
18441
|
-
const sourceSnapshot = mapOmpSnapshot(copiedHistory, {
|
|
18442
|
-
sessionId: startupSessionId,
|
|
18443
|
-
model: currentModel
|
|
18444
|
-
});
|
|
18445
|
-
let state = await transport.fork(boundary.lastUserEntryId);
|
|
18446
|
-
if (state.sessionId === sourceSessionId || state.sessionId === startupSessionId) {
|
|
18447
|
-
throw new Error("Omp last-Turn rollback did not create a distinct Native Session");
|
|
18448
|
-
}
|
|
18449
|
-
if (!sameOmpModel(modelFromState(state), currentModel)) {
|
|
18450
|
-
if (!currentModel)
|
|
18451
|
-
throw new Error("Omp last-Turn rollback changed the current Model");
|
|
18452
|
-
state = await transport.selectModel(currentModel);
|
|
18453
|
-
}
|
|
18454
|
-
if (state.thinkingLevel !== currentThinking) {
|
|
18455
|
-
if (!currentThinking)
|
|
18456
|
-
throw new Error("Omp last-Turn rollback changed current Thinking");
|
|
18457
|
-
state = await transport.selectThinkingOption(currentThinking);
|
|
18458
|
-
}
|
|
18459
|
-
if (!sameOmpModel(modelFromState(state), currentModel) || state.thinkingLevel !== currentThinking) {
|
|
18460
|
-
throw new Error("Omp last-Turn rollback could not restore current Model and Thinking");
|
|
18461
|
-
}
|
|
18462
|
-
const snapshot = mapOmpSnapshot(await transport.getEntries(), {
|
|
18463
|
-
sessionId: state.sessionId,
|
|
18464
|
-
model: modelFromState(state)
|
|
18465
|
-
});
|
|
18466
|
-
const expectedTurnKeys = sourceSnapshot.turns.slice(0, -1).map((turn) => turn.nativeTurnRef.nativeTurnKey);
|
|
18467
|
-
const actualTurnKeys = snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey);
|
|
18468
|
-
if (snapshot.turns.length !== boundary.sourceTurnCount - 1 || actualTurnKeys.some((key, index) => key !== expectedTurnKeys[index])) {
|
|
18469
|
-
throw new Error("Omp last-Turn rollback did not produce the exact retained history prefix");
|
|
18470
|
-
}
|
|
18471
|
-
await transport.verifySessionCwd(cwd);
|
|
18472
|
-
return { ok: true };
|
|
18473
|
-
}
|
|
18474
|
-
|
|
18475
|
-
// dist/omp-rpc-session.js
|
|
18476
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
18477
|
-
import { randomUUID } from "node:crypto";
|
|
18478
|
-
import path6 from "node:path";
|
|
18479
|
-
|
|
18480
|
-
// dist/command.js
|
|
18481
|
-
var ompDiscoverySpec = {
|
|
18482
|
-
id: "omp",
|
|
18483
|
-
command: "omp",
|
|
18484
|
-
commandEnvironmentVariable: "OMP_COMMAND",
|
|
18485
|
-
installRoots: {
|
|
18486
|
-
posix: [
|
|
18487
|
-
"~/.npm-global/bin",
|
|
18488
|
-
"~/.local/bin",
|
|
18489
|
-
VERSION_MANAGER_ROOTS,
|
|
18490
|
-
"/opt/homebrew/bin",
|
|
18491
|
-
"/usr/local/bin"
|
|
18492
|
-
],
|
|
18493
|
-
windows: ["${APPDATA}/npm", "~/.local/bin", VERSION_MANAGER_ROOTS]
|
|
18494
|
-
}
|
|
18495
|
-
};
|
|
18496
|
-
function resolveOmpExecutable(input, dependencies = {}) {
|
|
18497
|
-
const resolution = resolveHarnessExecutable(ompDiscoverySpec, {
|
|
18498
|
-
...input.command ? { command: input.command } : {},
|
|
18499
|
-
environment: input.environment,
|
|
18500
|
-
...dependencies.platform ? { platform: dependencies.platform } : {},
|
|
18501
|
-
...dependencies.homeDirectory ? { homeDirectory: dependencies.homeDirectory } : {}
|
|
18502
|
-
}, { ...dependencies.isExecutable ? { isExecutable: dependencies.isExecutable } : {} });
|
|
18503
|
-
return resolution?.executable ?? input.command ?? input.environment.OMP_COMMAND ?? "omp";
|
|
18504
|
-
}
|
|
18505
|
-
|
|
18506
|
-
// dist/omp-protocol.js
|
|
18507
|
-
var MAX_FRAME_BYTES = 1024 * 1024;
|
|
18508
|
-
var MAX_REASSEMBLED_BYTES = 64 * 1024 * 1024;
|
|
18509
|
-
var MAX_CHUNK_BYTES = 256 * 1024;
|
|
18510
|
-
function isObject2(value) {
|
|
18511
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18512
|
-
}
|
|
18513
|
-
var OmpFrameDecoder = class {
|
|
18514
|
-
#pending = null;
|
|
18515
|
-
push(value) {
|
|
18516
|
-
if (!isObject2(value))
|
|
18517
|
-
throw new Error("OMP RPC frame must be a JSON object");
|
|
18518
|
-
if (value.type !== "rpc_chunk") {
|
|
18519
|
-
if (this.#pending)
|
|
18520
|
-
throw new Error("OMP RPC chunk sequence was interrupted");
|
|
18521
|
-
return value;
|
|
18522
|
-
}
|
|
18523
|
-
const chunkId = value.chunkId;
|
|
18524
|
-
const index = value.index;
|
|
18525
|
-
const count2 = value.count;
|
|
18526
|
-
const byteLength = value.byteLength;
|
|
18527
|
-
const data = value.data;
|
|
18528
|
-
if (typeof chunkId !== "string" || chunkId.length === 0 || chunkId.length > 128 || !Number.isInteger(index) || !Number.isInteger(count2) || !Number.isInteger(byteLength) || index < 0 || count2 < 2 || index >= count2 || byteLength < MAX_FRAME_BYTES || byteLength > MAX_REASSEMBLED_BYTES || typeof data !== "string" || data.length === 0)
|
|
18529
|
-
throw new Error("Invalid OMP RPC chunk metadata");
|
|
18530
|
-
let bytes;
|
|
18531
|
-
try {
|
|
18532
|
-
bytes = Buffer.from(data, "base64");
|
|
18533
|
-
} catch {
|
|
18534
|
-
throw new Error("Invalid OMP RPC chunk data");
|
|
18535
|
-
}
|
|
18536
|
-
if (bytes.length === 0 || bytes.length > MAX_CHUNK_BYTES || bytes.toString("base64") !== data) {
|
|
18537
|
-
throw new Error("Invalid OMP RPC chunk data");
|
|
18538
|
-
}
|
|
18539
|
-
const chunkIndex = index;
|
|
18540
|
-
const chunkCount = count2;
|
|
18541
|
-
const declaredByteLength = byteLength;
|
|
18542
|
-
if (!this.#pending) {
|
|
18543
|
-
if (chunkIndex !== 0)
|
|
18544
|
-
throw new Error("OMP RPC chunk sequence must start at index 0");
|
|
18545
|
-
this.#pending = {
|
|
18546
|
-
chunkId,
|
|
18547
|
-
count: chunkCount,
|
|
18548
|
-
byteLength: declaredByteLength,
|
|
18549
|
-
nextIndex: 0,
|
|
18550
|
-
chunks: [],
|
|
18551
|
-
received: 0
|
|
18552
|
-
};
|
|
18553
|
-
}
|
|
18554
|
-
const pending = this.#pending;
|
|
18555
|
-
if (!pending)
|
|
18556
|
-
throw new Error("OMP RPC chunk state was lost");
|
|
18557
|
-
if (pending.chunkId !== chunkId || pending.count !== chunkCount || pending.byteLength !== declaredByteLength || pending.nextIndex !== chunkIndex) {
|
|
18558
|
-
throw new Error("OMP RPC chunk sequence mismatch");
|
|
18559
|
-
}
|
|
18560
|
-
pending.chunks.push(bytes);
|
|
18561
|
-
pending.received += bytes.length;
|
|
18562
|
-
pending.nextIndex += 1;
|
|
18563
|
-
if (pending.received > pending.byteLength)
|
|
18564
|
-
throw new Error("OMP RPC chunk sequence exceeds its declared length");
|
|
18565
|
-
if (pending.nextIndex < pending.count)
|
|
18566
|
-
return null;
|
|
18567
|
-
if (pending.received !== pending.byteLength)
|
|
18568
|
-
throw new Error("OMP RPC chunk sequence length mismatch");
|
|
18569
|
-
this.#pending = null;
|
|
18570
|
-
let decoded;
|
|
18571
|
-
try {
|
|
18572
|
-
decoded = JSON.parse(Buffer.concat(pending.chunks).toString("utf8"));
|
|
18573
|
-
} catch {
|
|
18574
|
-
throw new Error("Failed to decode reassembled OMP RPC frame");
|
|
18575
|
-
}
|
|
18576
|
-
if (!isObject2(decoded))
|
|
18577
|
-
throw new Error("Reassembled OMP RPC frame must be an object");
|
|
18578
|
-
return decoded;
|
|
18579
|
-
}
|
|
18580
|
-
};
|
|
18581
|
-
|
|
18582
|
-
// dist/omp-rpc-session.js
|
|
18583
|
-
var OmpRpcFaultError = class extends Error {
|
|
18584
|
-
kind;
|
|
18585
|
-
diagnostic;
|
|
18586
|
-
constructor(kind, message3, diagnostic) {
|
|
18587
|
-
super(message3);
|
|
18588
|
-
this.kind = kind;
|
|
18589
|
-
this.diagnostic = diagnostic;
|
|
18590
|
-
this.name = "OmpRpcFaultError";
|
|
18591
|
-
}
|
|
18592
|
-
};
|
|
18593
|
-
var OmpRpcUnsupportedCommandError = class extends Error {
|
|
18594
|
-
command;
|
|
18595
|
-
constructor(command) {
|
|
18596
|
-
super(`Omp RPC does not support '${command}'`);
|
|
18597
|
-
this.command = command;
|
|
18598
|
-
this.name = "OmpRpcUnsupportedCommandError";
|
|
18599
|
-
}
|
|
18600
|
-
};
|
|
18601
|
-
var textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
18602
|
-
function isRecord8(value) {
|
|
18603
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18604
|
-
}
|
|
18605
|
-
function message2(value) {
|
|
18606
|
-
return value instanceof Error ? value.message : String(value);
|
|
18607
|
-
}
|
|
18608
|
-
function nonBlankString(value) {
|
|
18609
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
18610
|
-
}
|
|
18611
|
-
function parseNativeModel(value, context) {
|
|
18612
|
-
if (value === null || value === void 0)
|
|
18613
|
-
return null;
|
|
18614
|
-
if (!isRecord8(value) || !nonBlankString(value.provider) || !nonBlankString(value.id)) {
|
|
18615
|
-
throw new OmpRpcFaultError("protocolError", `Omp RPC returned an invalid ${context} Model`);
|
|
18616
|
-
}
|
|
18617
|
-
return { provider: value.provider, id: value.id };
|
|
18113
|
+
return { provider: value.provider, id: value.id };
|
|
18618
18114
|
}
|
|
18619
18115
|
function sessionStateData(response) {
|
|
18620
18116
|
const data = isRecord8(response.data) ? response.data : null;
|
|
@@ -18842,1178 +18338,1844 @@ var OmpRpcSession = class {
|
|
|
18842
18338
|
if (options.model && (options.sessionFile || options.forkSessionFile)) {
|
|
18843
18339
|
throw new Error("Omp RPC cannot combine a startup Model with Session restore or Fork");
|
|
18844
18340
|
}
|
|
18845
|
-
this.#options = {
|
|
18846
|
-
commandTimeoutMs: 3e4,
|
|
18847
|
-
compactionTimeoutMs: 3e5,
|
|
18848
|
-
// Native Abort waits for tools, persistence and deferred work to unwind.
|
|
18849
|
-
// Stable cancellation must outlast the Host's 20s steering wait.
|
|
18850
|
-
cancelTimeoutMs: 3e4,
|
|
18851
|
-
closeTimeoutMs: 2e3,
|
|
18852
|
-
...options
|
|
18853
|
-
};
|
|
18854
|
-
this.#processAdapter = processAdapter;
|
|
18341
|
+
this.#options = {
|
|
18342
|
+
commandTimeoutMs: 3e4,
|
|
18343
|
+
compactionTimeoutMs: 3e5,
|
|
18344
|
+
// Native Abort waits for tools, persistence and deferred work to unwind.
|
|
18345
|
+
// Stable cancellation must outlast the Host's 20s steering wait.
|
|
18346
|
+
cancelTimeoutMs: 3e4,
|
|
18347
|
+
closeTimeoutMs: 2e3,
|
|
18348
|
+
...options
|
|
18349
|
+
};
|
|
18350
|
+
this.#processAdapter = processAdapter;
|
|
18351
|
+
}
|
|
18352
|
+
get state() {
|
|
18353
|
+
if (!this.#state)
|
|
18354
|
+
throw new Error("Omp RPC Session has not started");
|
|
18355
|
+
return this.#state;
|
|
18356
|
+
}
|
|
18357
|
+
get stderrTail() {
|
|
18358
|
+
return this.#stderrTail;
|
|
18359
|
+
}
|
|
18360
|
+
async start() {
|
|
18361
|
+
if (this.#child || this.#closed)
|
|
18362
|
+
throw new Error("Omp RPC Session cannot be started twice");
|
|
18363
|
+
const child = this.#processAdapter.spawn({
|
|
18364
|
+
cwd: this.#options.cwd,
|
|
18365
|
+
...this.#options.command ? { command: this.#options.command } : {},
|
|
18366
|
+
environment: withNodeRuntimeOnPath({
|
|
18367
|
+
...process.env,
|
|
18368
|
+
...this.#options.environment,
|
|
18369
|
+
OMP_SKIP_VERSION_CHECK: "1",
|
|
18370
|
+
OMP_TELEMETRY: "0"
|
|
18371
|
+
}),
|
|
18372
|
+
...this.#options.sessionFile ? { sessionFile: this.#options.sessionFile } : {},
|
|
18373
|
+
...this.#options.forkSessionFile ? { forkSessionFile: this.#options.forkSessionFile } : {},
|
|
18374
|
+
...this.#options.model ? { model: this.#options.model } : {},
|
|
18375
|
+
...this.#options.permissionMode ? { permissionMode: this.#options.permissionMode } : {}
|
|
18376
|
+
});
|
|
18377
|
+
this.#child = child;
|
|
18378
|
+
child.stdout.on("data", (chunk) => this.#push(chunk));
|
|
18379
|
+
child.stdout.on("end", () => {
|
|
18380
|
+
if (this.#buffer.length !== 0) {
|
|
18381
|
+
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC stdout ended mid-frame"));
|
|
18382
|
+
}
|
|
18383
|
+
});
|
|
18384
|
+
child.stderr.on("data", (chunk) => {
|
|
18385
|
+
this.#stderrTail = sanitizeDiagnosticTail(`${this.#stderrTail}${chunk.toString()}`);
|
|
18386
|
+
});
|
|
18387
|
+
child.once("error", (error51) => {
|
|
18388
|
+
const kind = isRecord8(error51) && error51.code === "ENOENT" ? "notInstalled" : "unavailable";
|
|
18389
|
+
this.#fail(new OmpRpcFaultError(kind, `Omp RPC failed to start: ${error51.message}`, this.stderrTail));
|
|
18390
|
+
});
|
|
18391
|
+
child.once("exit", (code, signal) => {
|
|
18392
|
+
if (!this.#closed) {
|
|
18393
|
+
this.#fail(new OmpRpcFaultError("processExited", `Omp RPC exited (code=${code}, signal=${signal})`, this.stderrTail));
|
|
18394
|
+
}
|
|
18395
|
+
});
|
|
18396
|
+
await Promise.race([
|
|
18397
|
+
new Promise((resolve, reject) => {
|
|
18398
|
+
child.once("spawn", resolve);
|
|
18399
|
+
child.once("error", reject);
|
|
18400
|
+
}),
|
|
18401
|
+
new Promise((_resolve, reject) => setTimeout(() => reject(new Error("Omp RPC start timed out")), this.#options.commandTimeoutMs))
|
|
18402
|
+
]);
|
|
18403
|
+
let readyTimeout;
|
|
18404
|
+
try {
|
|
18405
|
+
await Promise.race([
|
|
18406
|
+
this.#ready,
|
|
18407
|
+
this.#startupFault.then((error51) => {
|
|
18408
|
+
throw error51;
|
|
18409
|
+
}),
|
|
18410
|
+
new Promise((_resolve, reject) => {
|
|
18411
|
+
readyTimeout = setTimeout(() => reject(new Error("Omp RPC ready signal timed out")), this.#options.commandTimeoutMs);
|
|
18412
|
+
})
|
|
18413
|
+
]);
|
|
18414
|
+
} finally {
|
|
18415
|
+
clearTimeout(readyTimeout);
|
|
18416
|
+
}
|
|
18417
|
+
await this.#send("negotiate_protocol", { protocolVersion: 2 }).catch(() => void 0);
|
|
18418
|
+
if (this.#options.subscribeSubagentEvents !== false) {
|
|
18419
|
+
await this.#send("set_subagent_subscription", { level: "events" }).catch(() => void 0);
|
|
18420
|
+
}
|
|
18421
|
+
try {
|
|
18422
|
+
this.#state = parseSessionState(await this.#send("get_state", {}));
|
|
18423
|
+
} catch (error51) {
|
|
18424
|
+
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("unavailable", `Omp RPC state unavailable: ${message2(error51)}`);
|
|
18425
|
+
this.#fail(fault);
|
|
18426
|
+
throw fault;
|
|
18427
|
+
}
|
|
18428
|
+
return this;
|
|
18429
|
+
}
|
|
18430
|
+
async getEntries() {
|
|
18431
|
+
try {
|
|
18432
|
+
if (this.state.sessionFile) {
|
|
18433
|
+
try {
|
|
18434
|
+
return await readOmpSessionHistory(this.state.sessionFile);
|
|
18435
|
+
} catch (error51) {
|
|
18436
|
+
if (!isRecord8(error51) || error51.code !== "ENOENT" || this.#options.sessionFile || this.#options.forkSessionFile)
|
|
18437
|
+
throw error51;
|
|
18438
|
+
const response2 = await this.#send("get_messages", {});
|
|
18439
|
+
const data2 = isRecord8(response2.data) ? response2.data : null;
|
|
18440
|
+
if (data2 && Array.isArray(data2.messages) && data2.messages.length === 0) {
|
|
18441
|
+
return { entries: [], leafId: null };
|
|
18442
|
+
}
|
|
18443
|
+
throw error51;
|
|
18444
|
+
}
|
|
18445
|
+
}
|
|
18446
|
+
const response = await this.#send("get_messages", {});
|
|
18447
|
+
const data = isRecord8(response.data) ? response.data : null;
|
|
18448
|
+
if (!data || !Array.isArray(data.messages)) {
|
|
18449
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC messages response has no messages");
|
|
18450
|
+
}
|
|
18451
|
+
let branchEntryIds = null;
|
|
18452
|
+
try {
|
|
18453
|
+
const branchResponse = await this.#send("get_branch_messages", {});
|
|
18454
|
+
const branchData = isRecord8(branchResponse.data) ? branchResponse.data : null;
|
|
18455
|
+
if (branchData && Array.isArray(branchData.messages)) {
|
|
18456
|
+
const parsed = branchData.messages.flatMap((entry) => {
|
|
18457
|
+
if (!isRecord8(entry) || !nonBlankString(entry.entryId))
|
|
18458
|
+
return [];
|
|
18459
|
+
return [entry.entryId];
|
|
18460
|
+
});
|
|
18461
|
+
if (parsed.length === branchData.messages.length)
|
|
18462
|
+
branchEntryIds = parsed;
|
|
18463
|
+
}
|
|
18464
|
+
} catch (error51) {
|
|
18465
|
+
if (!(error51 instanceof OmpRpcUnsupportedCommandError))
|
|
18466
|
+
throw error51;
|
|
18467
|
+
}
|
|
18468
|
+
let userIndex = 0;
|
|
18469
|
+
let parentId = null;
|
|
18470
|
+
const entries = data.messages.map((nativeMessage, index) => {
|
|
18471
|
+
const role = isRecord8(nativeMessage) ? nativeMessage.role : void 0;
|
|
18472
|
+
const branchId = role === "user" ? branchEntryIds?.[userIndex] : void 0;
|
|
18473
|
+
if (branchId)
|
|
18474
|
+
userIndex += 1;
|
|
18475
|
+
const id = branchId ?? (isRecord8(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
|
|
18476
|
+
const entry = { id, parentId, type: "message", message: nativeMessage };
|
|
18477
|
+
parentId = id;
|
|
18478
|
+
return entry;
|
|
18479
|
+
});
|
|
18480
|
+
return { entries, leafId: parentId };
|
|
18481
|
+
} catch (error51) {
|
|
18482
|
+
if (error51 instanceof OmpRpcFaultError)
|
|
18483
|
+
this.#fail(error51);
|
|
18484
|
+
throw error51;
|
|
18485
|
+
}
|
|
18486
|
+
}
|
|
18487
|
+
async getSubagentMessages(input) {
|
|
18488
|
+
if ((input.subagentId === void 0 || !nonBlankString(input.subagentId)) && (input.sessionFile === void 0 || !nonBlankString(input.sessionFile))) {
|
|
18489
|
+
throw new Error("Omp Subagent transcript requires a Subagent ID or Session file");
|
|
18490
|
+
}
|
|
18491
|
+
if (input.fromByte !== void 0 && (!Number.isSafeInteger(input.fromByte) || input.fromByte < 0)) {
|
|
18492
|
+
throw new Error("Omp Subagent transcript offset is invalid");
|
|
18493
|
+
}
|
|
18494
|
+
const response = await this.#send("get_subagent_messages", {
|
|
18495
|
+
...input.subagentId ? { subagentId: input.subagentId } : {},
|
|
18496
|
+
...input.sessionFile ? { sessionFile: input.sessionFile } : {},
|
|
18497
|
+
...input.fromByte !== void 0 ? { fromByte: input.fromByte } : {}
|
|
18498
|
+
});
|
|
18499
|
+
return parseSubagentMessages(response);
|
|
18500
|
+
}
|
|
18501
|
+
async compact(customInstructions, onEvent) {
|
|
18502
|
+
if (!this.#child || !this.#state || this.#closed || this.#failed) {
|
|
18503
|
+
throw new Error("Omp RPC Session is unavailable");
|
|
18504
|
+
}
|
|
18505
|
+
if (this.#activeTurn || this.#manualCompaction || this.#compactionActive) {
|
|
18506
|
+
throw new Error("Omp RPC Session already has an active operation");
|
|
18507
|
+
}
|
|
18508
|
+
const result = new Promise((resolve, reject) => {
|
|
18509
|
+
this.#manualCompaction = { onEvent, resolve, reject };
|
|
18510
|
+
});
|
|
18511
|
+
try {
|
|
18512
|
+
await this.#send("compact", customInstructions ? { customInstructions } : {});
|
|
18513
|
+
} catch (error51) {
|
|
18514
|
+
const pending = this.#manualCompaction;
|
|
18515
|
+
this.#manualCompaction = null;
|
|
18516
|
+
pending?.reject(error51 instanceof Error ? error51 : new Error(message2(error51)));
|
|
18517
|
+
}
|
|
18518
|
+
return result;
|
|
18519
|
+
}
|
|
18520
|
+
async getSessionUsage() {
|
|
18521
|
+
try {
|
|
18522
|
+
const usage = parseOmpSessionUsage(await this.#send("get_session_stats", {}));
|
|
18523
|
+
await this.#ensureLatestCacheHitRate();
|
|
18524
|
+
return this.#withLatestCacheHitRate(usage);
|
|
18525
|
+
} catch (error51) {
|
|
18526
|
+
if (!(error51 instanceof OmpRpcUnsupportedCommandError))
|
|
18527
|
+
throw error51;
|
|
18528
|
+
const response = await this.#send("get_state", {});
|
|
18529
|
+
const observedState = parseSessionState(response);
|
|
18530
|
+
if (!this.#state || observedState.sessionId !== this.#state.sessionId || observedState.provider !== this.#state.provider || observedState.modelId !== this.#state.modelId) {
|
|
18531
|
+
throw new Error("Omp RPC Usage fallback does not match the confirmed Session state");
|
|
18532
|
+
}
|
|
18533
|
+
await this.#ensureLatestCacheHitRate();
|
|
18534
|
+
const usage = parseOmpStateContextUsage(response);
|
|
18535
|
+
return usage ? this.#withLatestCacheHitRate(usage) : null;
|
|
18536
|
+
}
|
|
18855
18537
|
}
|
|
18856
|
-
|
|
18857
|
-
if (
|
|
18858
|
-
|
|
18859
|
-
|
|
18538
|
+
async #ensureLatestCacheHitRate() {
|
|
18539
|
+
if (this.#latestCacheHitRatePercent !== void 0)
|
|
18540
|
+
return;
|
|
18541
|
+
try {
|
|
18542
|
+
this.#latestCacheHitRatePercent = latestOmpCacheHitRatePercent(await this.getEntries());
|
|
18543
|
+
} catch {
|
|
18544
|
+
this.#latestCacheHitRatePercent = null;
|
|
18545
|
+
}
|
|
18860
18546
|
}
|
|
18861
|
-
|
|
18862
|
-
return this.#
|
|
18547
|
+
#withLatestCacheHitRate(usage) {
|
|
18548
|
+
return this.#latestCacheHitRatePercent === null || this.#latestCacheHitRatePercent === void 0 ? usage : parseHostUsage({ ...usage, cacheHitRatePercent: this.#latestCacheHitRatePercent });
|
|
18863
18549
|
}
|
|
18864
|
-
async
|
|
18865
|
-
if (
|
|
18866
|
-
throw new Error("Omp RPC
|
|
18867
|
-
|
|
18868
|
-
|
|
18869
|
-
|
|
18870
|
-
|
|
18871
|
-
|
|
18872
|
-
...this.#options.environment,
|
|
18873
|
-
OMP_SKIP_VERSION_CHECK: "1",
|
|
18874
|
-
OMP_TELEMETRY: "0"
|
|
18875
|
-
}),
|
|
18876
|
-
...this.#options.sessionFile ? { sessionFile: this.#options.sessionFile } : {},
|
|
18877
|
-
...this.#options.forkSessionFile ? { forkSessionFile: this.#options.forkSessionFile } : {},
|
|
18878
|
-
...this.#options.model ? { model: this.#options.model } : {},
|
|
18879
|
-
...this.#options.permissionMode ? { permissionMode: this.#options.permissionMode } : {}
|
|
18880
|
-
});
|
|
18881
|
-
this.#child = child;
|
|
18882
|
-
child.stdout.on("data", (chunk) => this.#push(chunk));
|
|
18883
|
-
child.stdout.on("end", () => {
|
|
18884
|
-
if (this.#buffer.length !== 0) {
|
|
18885
|
-
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC stdout ended mid-frame"));
|
|
18550
|
+
async fork(entryId) {
|
|
18551
|
+
if (!nonBlankString(entryId))
|
|
18552
|
+
throw new Error("Omp RPC Fork requires an Entry identity");
|
|
18553
|
+
try {
|
|
18554
|
+
const response = await this.#send("branch", { entryId });
|
|
18555
|
+
const data = isRecord8(response.data) ? response.data : null;
|
|
18556
|
+
if (!data || data.cancelled === true) {
|
|
18557
|
+
throw new OmpRpcFaultError("unavailable", "Omp RPC Fork was cancelled");
|
|
18886
18558
|
}
|
|
18559
|
+
this.#state = parseSessionState(await this.#send("get_state", {}));
|
|
18560
|
+
return this.#state;
|
|
18561
|
+
} catch (error51) {
|
|
18562
|
+
if (error51 instanceof OmpRpcFaultError)
|
|
18563
|
+
this.#fail(error51);
|
|
18564
|
+
throw error51;
|
|
18565
|
+
}
|
|
18566
|
+
}
|
|
18567
|
+
verifySessionCwd(expectedCwd) {
|
|
18568
|
+
return verifyOmpSessionCwd({
|
|
18569
|
+
sessionFile: this.state.sessionFile,
|
|
18570
|
+
sessionId: this.state.sessionId,
|
|
18571
|
+
expectedCwd
|
|
18887
18572
|
});
|
|
18888
|
-
|
|
18889
|
-
|
|
18890
|
-
|
|
18891
|
-
|
|
18892
|
-
|
|
18893
|
-
|
|
18894
|
-
|
|
18895
|
-
|
|
18896
|
-
|
|
18897
|
-
|
|
18898
|
-
|
|
18573
|
+
}
|
|
18574
|
+
async getAvailableModels() {
|
|
18575
|
+
try {
|
|
18576
|
+
return parseAvailableModels(await this.#send("get_available_models", {}));
|
|
18577
|
+
} catch (error51) {
|
|
18578
|
+
if (error51 instanceof OmpRpcFaultError)
|
|
18579
|
+
this.#fail(error51);
|
|
18580
|
+
throw error51;
|
|
18581
|
+
}
|
|
18582
|
+
}
|
|
18583
|
+
async getAvailableThinkingLevels() {
|
|
18584
|
+
return this.state.availableThinkingLevels;
|
|
18585
|
+
}
|
|
18586
|
+
async selectModel(model2) {
|
|
18587
|
+
await this.#send("set_model", { provider: model2.provider, modelId: model2.id });
|
|
18588
|
+
return this.#refreshState("Model");
|
|
18589
|
+
}
|
|
18590
|
+
async selectThinkingOption(thinkingOptionId) {
|
|
18591
|
+
const level = harnessThinkingOptionIdSchema.parse(thinkingOptionId);
|
|
18592
|
+
await this.#send("set_thinking_level", { level });
|
|
18593
|
+
return this.#refreshState("Thinking");
|
|
18594
|
+
}
|
|
18595
|
+
async #refreshState(operation) {
|
|
18596
|
+
try {
|
|
18597
|
+
this.#state = parseSessionState(await this.#send("get_state", {}));
|
|
18598
|
+
return this.#state;
|
|
18599
|
+
} catch (error51) {
|
|
18600
|
+
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC ${operation} state could not be confirmed: ${message2(error51)}`);
|
|
18601
|
+
this.#fail(fault);
|
|
18602
|
+
throw fault;
|
|
18603
|
+
}
|
|
18604
|
+
}
|
|
18605
|
+
async runTurn(text, onEvent) {
|
|
18606
|
+
if (!this.#child || !this.#state || this.#closed || this.#failed) {
|
|
18607
|
+
throw new Error("Omp RPC Session is unavailable");
|
|
18608
|
+
}
|
|
18609
|
+
if (this.#activeTurn)
|
|
18610
|
+
throw new Error("Omp RPC Session already has an active Turn");
|
|
18611
|
+
if (text.length === 0)
|
|
18612
|
+
throw new Error("Omp text Turn must not be empty");
|
|
18613
|
+
const promptId = `codexhost-${randomUUID()}`;
|
|
18614
|
+
const settled = new Promise((resolve, reject) => {
|
|
18615
|
+
this.#activeTurn = {
|
|
18616
|
+
promptId,
|
|
18617
|
+
localResult: null,
|
|
18618
|
+
text: "",
|
|
18619
|
+
assistantMessageId: null,
|
|
18620
|
+
sawStreamedMessageText: false,
|
|
18621
|
+
sawStreamedMessageReasoning: false,
|
|
18622
|
+
lastFinalizedMessageText: null,
|
|
18623
|
+
lastFinalizedMessageReasoning: null,
|
|
18624
|
+
reasoningMessageOpen: false,
|
|
18625
|
+
onEvent,
|
|
18626
|
+
resolve,
|
|
18627
|
+
reject,
|
|
18628
|
+
failure: null,
|
|
18629
|
+
sawTool: false,
|
|
18630
|
+
tools: /* @__PURE__ */ new Map(),
|
|
18631
|
+
interactions: /* @__PURE__ */ new Map(),
|
|
18632
|
+
settlement: "pending",
|
|
18633
|
+
terminalEnd: false,
|
|
18634
|
+
cancellation: "none",
|
|
18635
|
+
cancellationTimeout: null,
|
|
18636
|
+
cancellationRecheck: null,
|
|
18637
|
+
cancellationChecking: false,
|
|
18638
|
+
cancellationReloaded: false,
|
|
18639
|
+
abortPromise: null
|
|
18640
|
+
};
|
|
18899
18641
|
});
|
|
18900
|
-
await Promise.race([
|
|
18901
|
-
new Promise((resolve, reject) => {
|
|
18902
|
-
child.once("spawn", resolve);
|
|
18903
|
-
child.once("error", reject);
|
|
18904
|
-
}),
|
|
18905
|
-
new Promise((_resolve, reject) => setTimeout(() => reject(new Error("Omp RPC start timed out")), this.#options.commandTimeoutMs))
|
|
18906
|
-
]);
|
|
18907
|
-
let readyTimeout;
|
|
18908
18642
|
try {
|
|
18909
|
-
await
|
|
18910
|
-
|
|
18911
|
-
|
|
18912
|
-
throw error51;
|
|
18913
|
-
}),
|
|
18914
|
-
new Promise((_resolve, reject) => {
|
|
18915
|
-
readyTimeout = setTimeout(() => reject(new Error("Omp RPC ready signal timed out")), this.#options.commandTimeoutMs);
|
|
18916
|
-
})
|
|
18917
|
-
]);
|
|
18918
|
-
} finally {
|
|
18919
|
-
clearTimeout(readyTimeout);
|
|
18643
|
+
await this.#send("prompt", { message: text }, promptId);
|
|
18644
|
+
} catch (error51) {
|
|
18645
|
+
this.#rejectActiveTurn(error51 instanceof Error ? error51 : new Error(message2(error51)));
|
|
18920
18646
|
}
|
|
18921
|
-
|
|
18922
|
-
|
|
18923
|
-
|
|
18647
|
+
return settled;
|
|
18648
|
+
}
|
|
18649
|
+
respondToInteraction(response) {
|
|
18650
|
+
return this.#resolveInteraction(response, "cancelled" in response ? "cancelled" : "responded");
|
|
18651
|
+
}
|
|
18652
|
+
async #resolveInteraction(response, reason) {
|
|
18653
|
+
const active = this.#activeTurn;
|
|
18654
|
+
const pending = active?.interactions.get(response.requestId);
|
|
18655
|
+
if (!active || !pending || this.#closed || this.#failed) {
|
|
18656
|
+
throw new Error("Omp RPC interaction is not pending");
|
|
18657
|
+
}
|
|
18658
|
+
if ("value" in response && !["select", "input", "editor"].includes(pending.request.method)) {
|
|
18659
|
+
throw new Error("Omp RPC interaction response type does not match the request");
|
|
18660
|
+
}
|
|
18661
|
+
if ("confirmed" in response && pending.request.method !== "confirm") {
|
|
18662
|
+
throw new Error("Omp RPC confirmation does not match the request");
|
|
18663
|
+
}
|
|
18664
|
+
const frame = "cancelled" in response ? {
|
|
18665
|
+
type: "extension_ui_response",
|
|
18666
|
+
id: response.requestId,
|
|
18667
|
+
cancelled: true,
|
|
18668
|
+
...reason === "expired" ? { timedOut: true } : {}
|
|
18669
|
+
} : "confirmed" in response ? { type: "extension_ui_response", id: response.requestId, confirmed: response.confirmed } : { type: "extension_ui_response", id: response.requestId, value: response.value };
|
|
18670
|
+
if (!active.interactions.delete(response.requestId)) {
|
|
18671
|
+
throw new Error("Omp RPC interaction is not pending");
|
|
18924
18672
|
}
|
|
18673
|
+
if (pending.timeout)
|
|
18674
|
+
clearTimeout(pending.timeout);
|
|
18675
|
+
active.onEvent({ type: "interaction.closed", requestId: response.requestId, reason });
|
|
18925
18676
|
try {
|
|
18926
|
-
|
|
18677
|
+
await this.#write(frame);
|
|
18927
18678
|
} catch (error51) {
|
|
18928
|
-
const fault =
|
|
18679
|
+
const fault = new OmpRpcFaultError("protocolError", `Omp RPC interaction response failed: ${message2(error51)}`);
|
|
18929
18680
|
this.#fail(fault);
|
|
18930
18681
|
throw fault;
|
|
18931
18682
|
}
|
|
18932
|
-
return this;
|
|
18933
18683
|
}
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
|
|
18942
|
-
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
|
|
18684
|
+
abort() {
|
|
18685
|
+
const active = this.#activeTurn;
|
|
18686
|
+
if (!active || this.#closed || this.#failed) {
|
|
18687
|
+
return Promise.reject(new Error("Omp RPC Session has no cancellable Turn"));
|
|
18688
|
+
}
|
|
18689
|
+
if (active.abortPromise)
|
|
18690
|
+
return active.abortPromise;
|
|
18691
|
+
active.cancellation = "requesting";
|
|
18692
|
+
active.cancellationTimeout = setTimeout(() => {
|
|
18693
|
+
this.#terminateFailedCancellation(active, new OmpRpcFaultError("protocolError", "Omp Turn cancellation did not settle within its bound"));
|
|
18694
|
+
}, this.#options.cancelTimeoutMs);
|
|
18695
|
+
const aborting = this.#send("abort", {}).then(async () => {
|
|
18696
|
+
if (this.#activeTurn !== active)
|
|
18697
|
+
return;
|
|
18698
|
+
active.cancellation = "accepted";
|
|
18699
|
+
await this.#confirmCancelledTurn(active);
|
|
18700
|
+
}).catch((error51) => {
|
|
18701
|
+
if (this.#activeTurn !== active)
|
|
18702
|
+
throw error51;
|
|
18703
|
+
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC Abort failed: ${message2(error51)}`);
|
|
18704
|
+
this.#terminateFailedCancellation(active, fault);
|
|
18705
|
+
throw fault;
|
|
18706
|
+
});
|
|
18707
|
+
active.abortPromise = aborting;
|
|
18708
|
+
return aborting;
|
|
18709
|
+
}
|
|
18710
|
+
#terminateFailedCancellation(active, fault) {
|
|
18711
|
+
if (this.#activeTurn !== active)
|
|
18712
|
+
return;
|
|
18713
|
+
if (active.cancellationTimeout)
|
|
18714
|
+
clearTimeout(active.cancellationTimeout);
|
|
18715
|
+
active.cancellationTimeout = null;
|
|
18716
|
+
this.#fail(fault);
|
|
18717
|
+
void this.close().catch(() => void 0);
|
|
18718
|
+
}
|
|
18719
|
+
close() {
|
|
18720
|
+
if (!this.#closed) {
|
|
18721
|
+
this.#closed = true;
|
|
18722
|
+
this.#rejectAll(new Error("Omp RPC Session closed"));
|
|
18723
|
+
}
|
|
18724
|
+
this.#closePromise ??= this.#stopProcess();
|
|
18725
|
+
return this.#closePromise;
|
|
18726
|
+
}
|
|
18727
|
+
async #stopProcess() {
|
|
18728
|
+
const child = this.#child;
|
|
18729
|
+
if (!child)
|
|
18730
|
+
return;
|
|
18731
|
+
if (child.stdin.writable)
|
|
18732
|
+
child.stdin.end();
|
|
18733
|
+
if (await waitForExit(child, this.#options.closeTimeoutMs))
|
|
18734
|
+
return;
|
|
18735
|
+
signalProcessTree(child, "SIGTERM");
|
|
18736
|
+
if (await waitForExit(child, this.#options.closeTimeoutMs))
|
|
18737
|
+
return;
|
|
18738
|
+
signalProcessTree(child, "SIGKILL");
|
|
18739
|
+
if (!await waitForExit(child, this.#options.closeTimeoutMs)) {
|
|
18740
|
+
throw new Error("Omp RPC process tree did not exit within cleanup bounds");
|
|
18741
|
+
}
|
|
18742
|
+
}
|
|
18743
|
+
#push(chunk) {
|
|
18744
|
+
this.#buffer = this.#buffer.length === 0 ? chunk : Buffer.concat([this.#buffer, chunk]);
|
|
18745
|
+
let newline = this.#buffer.indexOf(10);
|
|
18746
|
+
while (newline >= 0) {
|
|
18747
|
+
const frame = this.#buffer.subarray(0, newline);
|
|
18748
|
+
this.#buffer = this.#buffer.subarray(newline + 1);
|
|
18749
|
+
let parsed;
|
|
18750
|
+
try {
|
|
18751
|
+
parsed = JSON.parse(textDecoder.decode(frame));
|
|
18752
|
+
} catch (error51) {
|
|
18753
|
+
this.#fail(new OmpRpcFaultError("protocolError", `Omp RPC returned invalid JSONL: ${message2(error51)}`));
|
|
18754
|
+
newline = this.#buffer.indexOf(10);
|
|
18755
|
+
continue;
|
|
18954
18756
|
}
|
|
18955
|
-
let branchEntryIds = null;
|
|
18956
18757
|
try {
|
|
18957
|
-
const
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
if (parsed.length === branchData.messages.length)
|
|
18966
|
-
branchEntryIds = parsed;
|
|
18758
|
+
const decoded = this.#frameDecoder.push(parsed);
|
|
18759
|
+
if (decoded === null) {
|
|
18760
|
+
newline = this.#buffer.indexOf(10);
|
|
18761
|
+
continue;
|
|
18762
|
+
}
|
|
18763
|
+
const value = decoded;
|
|
18764
|
+
if (!isRecord8(value) || typeof value.type !== "string") {
|
|
18765
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid envelope");
|
|
18967
18766
|
}
|
|
18767
|
+
this.#handle(value);
|
|
18968
18768
|
} catch (error51) {
|
|
18969
|
-
|
|
18970
|
-
throw error51;
|
|
18769
|
+
this.#fail(error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC frame handling failed: ${message2(error51)}`));
|
|
18971
18770
|
}
|
|
18972
|
-
|
|
18973
|
-
let parentId = null;
|
|
18974
|
-
const entries = data.messages.map((nativeMessage, index) => {
|
|
18975
|
-
const role = isRecord8(nativeMessage) ? nativeMessage.role : void 0;
|
|
18976
|
-
const branchId = role === "user" ? branchEntryIds?.[userIndex] : void 0;
|
|
18977
|
-
if (branchId)
|
|
18978
|
-
userIndex += 1;
|
|
18979
|
-
const id = branchId ?? (isRecord8(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
|
|
18980
|
-
const entry = { id, parentId, type: "message", message: nativeMessage };
|
|
18981
|
-
parentId = id;
|
|
18982
|
-
return entry;
|
|
18983
|
-
});
|
|
18984
|
-
return { entries, leafId: parentId };
|
|
18985
|
-
} catch (error51) {
|
|
18986
|
-
if (error51 instanceof OmpRpcFaultError)
|
|
18987
|
-
this.#fail(error51);
|
|
18988
|
-
throw error51;
|
|
18771
|
+
newline = this.#buffer.indexOf(10);
|
|
18989
18772
|
}
|
|
18990
18773
|
}
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
|
|
18774
|
+
/** Latest `available_commands_update` of the running process, if any. */
|
|
18775
|
+
get availableCommands() {
|
|
18776
|
+
return this.#availableCommands;
|
|
18777
|
+
}
|
|
18778
|
+
#handle(value) {
|
|
18779
|
+
if (this.#closed || this.#failed)
|
|
18780
|
+
return;
|
|
18781
|
+
if (value.type === "available_commands_update") {
|
|
18782
|
+
this.#availableCommands = parseOmpAvailableCommands(value.commands);
|
|
18783
|
+
return;
|
|
18994
18784
|
}
|
|
18995
|
-
if (
|
|
18996
|
-
|
|
18785
|
+
if (value.type === "ready") {
|
|
18786
|
+
this.#readyResolve?.();
|
|
18787
|
+
this.#readyResolve = null;
|
|
18788
|
+
return;
|
|
18789
|
+
}
|
|
18790
|
+
if (value.type === "response") {
|
|
18791
|
+
this.#handleResponse(value);
|
|
18792
|
+
return;
|
|
18793
|
+
}
|
|
18794
|
+
if (value.type === "auto_compaction_start" || value.type === "compaction_start") {
|
|
18795
|
+
this.#compactionActive = true;
|
|
18796
|
+
this.#compactionTurn = this.#activeTurn;
|
|
18797
|
+
this.#compactionTimeout ??= setTimeout(() => {
|
|
18798
|
+
this.#compactionTimeout = null;
|
|
18799
|
+
this.#fail(new OmpRpcFaultError("protocolError", `Omp RPC compaction timed out after ${this.#options.compactionTimeoutMs}ms`));
|
|
18800
|
+
}, this.#options.compactionTimeoutMs);
|
|
18801
|
+
const onEvent = this.#activeTurn?.onEvent ?? this.#manualCompaction?.onEvent;
|
|
18802
|
+
onEvent?.({ type: "compaction.started" });
|
|
18803
|
+
for (const pending of this.#pending.values()) {
|
|
18804
|
+
if (pending.command !== "prompt" && pending.command !== "compact" || !pending.timeout)
|
|
18805
|
+
continue;
|
|
18806
|
+
clearTimeout(pending.timeout);
|
|
18807
|
+
pending.timeout = null;
|
|
18808
|
+
}
|
|
18809
|
+
return;
|
|
18810
|
+
}
|
|
18811
|
+
if (value.type === "auto_compaction_end" || value.type === "compaction_end") {
|
|
18812
|
+
this.#compactionActive = false;
|
|
18813
|
+
if (this.#compactionTimeout)
|
|
18814
|
+
clearTimeout(this.#compactionTimeout);
|
|
18815
|
+
this.#compactionTimeout = null;
|
|
18816
|
+
const compactionTurn = this.#compactionTurn;
|
|
18817
|
+
this.#compactionTurn = null;
|
|
18818
|
+
for (const [id, pending] of this.#pending) {
|
|
18819
|
+
if (pending.command === "prompt" || pending.command === "compact") {
|
|
18820
|
+
this.#armCommandTimeout(id, pending);
|
|
18821
|
+
}
|
|
18822
|
+
}
|
|
18823
|
+
const outcome = value.aborted === true ? "cancelled" : isRecord8(value.result) ? "succeeded" : "failed";
|
|
18824
|
+
const event = {
|
|
18825
|
+
type: "compaction.completed",
|
|
18826
|
+
outcome,
|
|
18827
|
+
...nonBlankString(value.errorMessage) ? { errorMessage: value.errorMessage } : {}
|
|
18828
|
+
};
|
|
18829
|
+
compactionTurn?.onEvent(event);
|
|
18830
|
+
const manual = this.#manualCompaction;
|
|
18831
|
+
this.#manualCompaction = null;
|
|
18832
|
+
manual?.onEvent(event);
|
|
18833
|
+
manual?.resolve({
|
|
18834
|
+
outcome,
|
|
18835
|
+
...event.errorMessage ? { errorMessage: event.errorMessage } : {}
|
|
18836
|
+
});
|
|
18837
|
+
return;
|
|
18838
|
+
}
|
|
18839
|
+
const active = this.#activeTurn;
|
|
18840
|
+
if (this.#handleSubagentFrame(active, value))
|
|
18841
|
+
return;
|
|
18842
|
+
this.#observeUsage(value);
|
|
18843
|
+
if (value.type === "agent_start" && active)
|
|
18844
|
+
active.terminalEnd = false;
|
|
18845
|
+
if ((value.type === "session_settled" || value.type === "agent_start") && active?.cancellation === "accepted") {
|
|
18846
|
+
void this.#confirmCancelledTurn(active);
|
|
18847
|
+
return;
|
|
18848
|
+
}
|
|
18849
|
+
if (!active) {
|
|
18850
|
+
if (value.type === "extension_ui_request" && this.#isBlockingInteraction(value)) {
|
|
18851
|
+
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC requested blocking Extension UI outside an active Turn"));
|
|
18852
|
+
}
|
|
18853
|
+
return;
|
|
18854
|
+
}
|
|
18855
|
+
if (value.type === "command_output") {
|
|
18856
|
+
if (active.settlement !== "pending")
|
|
18857
|
+
return;
|
|
18858
|
+
if (typeof value.text !== "string") {
|
|
18859
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned invalid command output");
|
|
18860
|
+
}
|
|
18861
|
+
active.text += value.text;
|
|
18862
|
+
active.onEvent({ type: "text.delta", messageId: active.promptId, delta: value.text });
|
|
18863
|
+
return;
|
|
18864
|
+
}
|
|
18865
|
+
if (value.type === "prompt_result") {
|
|
18866
|
+
if (value.id !== active.promptId || value.agentInvoked !== false)
|
|
18867
|
+
return;
|
|
18868
|
+
if (value.status === "completed" || value.status === "aborted") {
|
|
18869
|
+
this.#settleLocalTurn(active, { cancelled: value.status === "aborted" });
|
|
18870
|
+
} else if (value.status === "error" && isRecord8(value.error) && typeof value.error.message === "string") {
|
|
18871
|
+
this.#settleLocalTurn(active, { cancelled: false, error: value.error.message });
|
|
18872
|
+
} else {
|
|
18873
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid local prompt result");
|
|
18874
|
+
}
|
|
18875
|
+
return;
|
|
18876
|
+
}
|
|
18877
|
+
if (value.type === "extension_ui_request") {
|
|
18878
|
+
this.#startInteraction(active, value);
|
|
18879
|
+
return;
|
|
18880
|
+
}
|
|
18881
|
+
if (value.type === "message_start" && assistantText(value.message) !== null) {
|
|
18882
|
+
this.#startAssistantMessage(active, value.message);
|
|
18883
|
+
return;
|
|
18884
|
+
}
|
|
18885
|
+
if (value.type === "message_update" && isRecord8(value.assistantMessageEvent)) {
|
|
18886
|
+
const event = value.assistantMessageEvent;
|
|
18887
|
+
const eventType = String(event.type ?? "");
|
|
18888
|
+
const isThinking = eventType === "thinking_delta" || eventType === "reasoning_delta" || eventType === "thought_delta" || eventType === "thinking" || eventType === "reasoning";
|
|
18889
|
+
const isText = eventType === "text_delta" || eventType === "text" || eventType === "content_block_delta";
|
|
18890
|
+
const delta = typeof event.delta === "string" ? event.delta : typeof event.thinking === "string" ? event.thinking : typeof event.reasoning === "string" ? event.reasoning : typeof event.text === "string" ? event.text : isRecord8(event.delta) && typeof event.delta.thinking === "string" ? event.delta.thinking : isRecord8(event.delta) && typeof event.delta.text === "string" ? event.delta.text : null;
|
|
18891
|
+
if (isThinking && delta !== null && delta.length > 0) {
|
|
18892
|
+
const messageId = this.#ensureAssistantMessage(active, value.message);
|
|
18893
|
+
active.reasoningMessageOpen = true;
|
|
18894
|
+
active.sawStreamedMessageReasoning = true;
|
|
18895
|
+
active.onEvent({ type: "reasoning.delta", messageId, delta });
|
|
18896
|
+
} else if (isText && delta !== null && delta.length > 0) {
|
|
18897
|
+
const messageId = this.#ensureAssistantMessage(active, value.message);
|
|
18898
|
+
active.text += delta;
|
|
18899
|
+
active.sawStreamedMessageText = true;
|
|
18900
|
+
active.onEvent({ type: "text.delta", messageId, delta });
|
|
18901
|
+
} else if (event.type === "error") {
|
|
18902
|
+
this.#ensureAssistantMessage(active, value.message);
|
|
18903
|
+
active.failure = assistantFailure(event.error) ?? assistantFailure(value.message) ?? new Error("Omp assistant message failed");
|
|
18904
|
+
}
|
|
18905
|
+
return;
|
|
18906
|
+
}
|
|
18907
|
+
if (value.type === "message_end") {
|
|
18908
|
+
this.#finalizeAssistantMessage(active, value.message);
|
|
18909
|
+
return;
|
|
18910
|
+
}
|
|
18911
|
+
if (value.type === "turn_end") {
|
|
18912
|
+
this.#finalizeAssistantMessage(active, value.message);
|
|
18913
|
+
return;
|
|
18914
|
+
}
|
|
18915
|
+
if (value.type === "tool_execution_start") {
|
|
18916
|
+
this.#startTool(active, value);
|
|
18917
|
+
return;
|
|
18918
|
+
}
|
|
18919
|
+
if (value.type === "tool_execution_update") {
|
|
18920
|
+
this.#updateTool(active, value);
|
|
18921
|
+
return;
|
|
18922
|
+
}
|
|
18923
|
+
if (value.type === "tool_execution_end") {
|
|
18924
|
+
this.#completeTool(active, value);
|
|
18925
|
+
return;
|
|
18926
|
+
}
|
|
18927
|
+
if (value.type === "agent_end" && Array.isArray(value.messages)) {
|
|
18928
|
+
for (let index = value.messages.length - 1; index >= 0; index -= 1) {
|
|
18929
|
+
const message3 = value.messages[index];
|
|
18930
|
+
if (!isRecord8(message3) || message3.role !== "assistant")
|
|
18931
|
+
continue;
|
|
18932
|
+
this.#finalizeAssistantMessage(active, message3);
|
|
18933
|
+
break;
|
|
18934
|
+
}
|
|
18935
|
+
}
|
|
18936
|
+
if (value.type === "agent_end" && value.isTerminal !== false) {
|
|
18937
|
+
active.terminalEnd = true;
|
|
18938
|
+
if (active.cancellation !== "none") {
|
|
18939
|
+
if (active.cancellation === "accepted")
|
|
18940
|
+
void this.#confirmCancelledTurn(active);
|
|
18941
|
+
return;
|
|
18942
|
+
}
|
|
18943
|
+
if (active.settlement !== "pending")
|
|
18944
|
+
return;
|
|
18945
|
+
active.settlement = "confirming";
|
|
18946
|
+
void this.#confirmSettledTurn(active);
|
|
18997
18947
|
}
|
|
18998
|
-
const response = await this.#send("get_subagent_messages", {
|
|
18999
|
-
...input.subagentId ? { subagentId: input.subagentId } : {},
|
|
19000
|
-
...input.sessionFile ? { sessionFile: input.sessionFile } : {},
|
|
19001
|
-
...input.fromByte !== void 0 ? { fromByte: input.fromByte } : {}
|
|
19002
|
-
});
|
|
19003
|
-
return parseSubagentMessages(response);
|
|
19004
18948
|
}
|
|
19005
|
-
|
|
19006
|
-
|
|
19007
|
-
|
|
18949
|
+
/** Every finished assistant message is one model request, with or without an active Turn. */
|
|
18950
|
+
#observeUsage(value) {
|
|
18951
|
+
if (value.type === "message_start") {
|
|
18952
|
+
this.#usageRequestStartedAtMs = null;
|
|
18953
|
+
return;
|
|
19008
18954
|
}
|
|
19009
|
-
if (
|
|
19010
|
-
|
|
18955
|
+
if (value.type === "message_update") {
|
|
18956
|
+
const event = value.assistantMessageEvent;
|
|
18957
|
+
if (this.#usageRequestStartedAtMs === null && isRecord8(event) && typeof event.type === "string" && /^(text|thinking|reasoning|thought|toolcall)_(start|delta)$/u.test(event.type)) {
|
|
18958
|
+
this.#usageRequestStartedAtMs = Date.now();
|
|
18959
|
+
}
|
|
18960
|
+
return;
|
|
19011
18961
|
}
|
|
19012
|
-
|
|
19013
|
-
|
|
19014
|
-
|
|
19015
|
-
|
|
19016
|
-
|
|
19017
|
-
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
|
|
18962
|
+
if (value.type === "message_end" && isRecord8(value.message)) {
|
|
18963
|
+
if (value.message.role !== "assistant")
|
|
18964
|
+
return;
|
|
18965
|
+
const startedAtMs = this.#usageRequestStartedAtMs;
|
|
18966
|
+
this.#usageRequestStartedAtMs = null;
|
|
18967
|
+
this.#options.onUsage?.({
|
|
18968
|
+
message: value.message,
|
|
18969
|
+
startedAtMs,
|
|
18970
|
+
completedAtMs: Date.now()
|
|
18971
|
+
});
|
|
19021
18972
|
}
|
|
19022
|
-
return result;
|
|
19023
18973
|
}
|
|
19024
|
-
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
await this.#ensureLatestCacheHitRate();
|
|
19028
|
-
return this.#withLatestCacheHitRate(usage);
|
|
19029
|
-
} catch (error51) {
|
|
19030
|
-
if (!(error51 instanceof OmpRpcUnsupportedCommandError))
|
|
19031
|
-
throw error51;
|
|
19032
|
-
const response = await this.#send("get_state", {});
|
|
19033
|
-
const observedState = parseSessionState(response);
|
|
19034
|
-
if (!this.#state || observedState.sessionId !== this.#state.sessionId || observedState.provider !== this.#state.provider || observedState.modelId !== this.#state.modelId) {
|
|
19035
|
-
throw new Error("Omp RPC Usage fallback does not match the confirmed Session state");
|
|
19036
|
-
}
|
|
19037
|
-
await this.#ensureLatestCacheHitRate();
|
|
19038
|
-
const usage = parseOmpStateContextUsage(response);
|
|
19039
|
-
return usage ? this.#withLatestCacheHitRate(usage) : null;
|
|
18974
|
+
#handleSubagentFrame(active, value) {
|
|
18975
|
+
if (value.type !== "subagent_lifecycle" && value.type !== "subagent_progress" && value.type !== "subagent_event") {
|
|
18976
|
+
return false;
|
|
19040
18977
|
}
|
|
19041
|
-
|
|
19042
|
-
|
|
19043
|
-
|
|
19044
|
-
|
|
19045
|
-
|
|
19046
|
-
this.#latestCacheHitRatePercent = latestOmpCacheHitRatePercent(await this.getEntries());
|
|
19047
|
-
} catch {
|
|
19048
|
-
this.#latestCacheHitRatePercent = null;
|
|
18978
|
+
const payload = isRecord8(value.payload) ? value.payload : null;
|
|
18979
|
+
const progressPayload = value.type === "subagent_progress" && payload && isRecord8(payload.progress) ? payload.progress : null;
|
|
18980
|
+
const nativeIdValue = progressPayload?.id ?? payload?.id;
|
|
18981
|
+
if (!payload || !nonBlankString(nativeIdValue)) {
|
|
18982
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent frame has no stable ID");
|
|
19049
18983
|
}
|
|
19050
|
-
|
|
19051
|
-
|
|
19052
|
-
|
|
19053
|
-
|
|
19054
|
-
|
|
19055
|
-
|
|
19056
|
-
|
|
19057
|
-
|
|
19058
|
-
const
|
|
19059
|
-
|
|
19060
|
-
|
|
19061
|
-
|
|
18984
|
+
const nativeSubagentId = nativeIdValue;
|
|
18985
|
+
const callId = nativeSubagentId;
|
|
18986
|
+
const emit = active?.onEvent ?? this.#options.onSubagentEvent;
|
|
18987
|
+
if (value.type === "subagent_event") {
|
|
18988
|
+
emit?.({ type: "subagent.transcript.changed", callId, nativeSubagentId });
|
|
18989
|
+
return true;
|
|
18990
|
+
}
|
|
18991
|
+
if (value.type === "subagent_lifecycle") {
|
|
18992
|
+
const status2 = payload.status;
|
|
18993
|
+
if (status2 === "started") {
|
|
18994
|
+
const description = nonBlankString(payload.description) ? payload.description : nonBlankString(payload.agent) ? `${payload.agent} delegation` : "Subagent delegation";
|
|
18995
|
+
emit?.({
|
|
18996
|
+
type: "subagent.started",
|
|
18997
|
+
callId,
|
|
18998
|
+
nativeSubagentId,
|
|
18999
|
+
description,
|
|
19000
|
+
...nonBlankString(payload.agent) ? { role: payload.agent } : {},
|
|
19001
|
+
...nonBlankString(payload.task) ? { prompt: payload.task } : {},
|
|
19002
|
+
background: payload.detached === true,
|
|
19003
|
+
...typeof payload.sessionFile === "string" ? { sessionFile: payload.sessionFile } : {}
|
|
19004
|
+
});
|
|
19005
|
+
return true;
|
|
19062
19006
|
}
|
|
19063
|
-
|
|
19064
|
-
|
|
19065
|
-
|
|
19066
|
-
|
|
19067
|
-
|
|
19068
|
-
|
|
19007
|
+
if (status2 !== "completed" && status2 !== "failed" && status2 !== "aborted") {
|
|
19008
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent lifecycle status is invalid");
|
|
19009
|
+
}
|
|
19010
|
+
emit?.({
|
|
19011
|
+
type: "subagent.completed",
|
|
19012
|
+
callId,
|
|
19013
|
+
nativeSubagentId,
|
|
19014
|
+
isError: status2 !== "completed",
|
|
19015
|
+
...nonBlankString(payload.resultSummary) ? { resultSummary: payload.resultSummary } : {},
|
|
19016
|
+
...typeof payload.sessionFile === "string" ? { sessionFile: payload.sessionFile } : {}
|
|
19017
|
+
});
|
|
19018
|
+
return true;
|
|
19069
19019
|
}
|
|
19070
|
-
|
|
19071
|
-
|
|
19072
|
-
|
|
19073
|
-
sessionFile: this.state.sessionFile,
|
|
19074
|
-
sessionId: this.state.sessionId,
|
|
19075
|
-
expectedCwd
|
|
19076
|
-
});
|
|
19077
|
-
}
|
|
19078
|
-
async getAvailableModels() {
|
|
19079
|
-
try {
|
|
19080
|
-
return parseAvailableModels(await this.#send("get_available_models", {}));
|
|
19081
|
-
} catch (error51) {
|
|
19082
|
-
if (error51 instanceof OmpRpcFaultError)
|
|
19083
|
-
this.#fail(error51);
|
|
19084
|
-
throw error51;
|
|
19020
|
+
const progress = progressPayload;
|
|
19021
|
+
if (!progress || !nonBlankString(progress.id) || progress.id !== nativeSubagentId) {
|
|
19022
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent progress is invalid");
|
|
19085
19023
|
}
|
|
19024
|
+
const status = subagentStatus(progress.status);
|
|
19025
|
+
const recentOutput = Array.isArray(progress.recentOutput) ? progress.recentOutput.filter((item) => typeof item === "string") : [];
|
|
19026
|
+
const resultSummary = recentOutput.at(-1);
|
|
19027
|
+
emit?.({
|
|
19028
|
+
type: "subagent.updated",
|
|
19029
|
+
callId,
|
|
19030
|
+
nativeSubagentId,
|
|
19031
|
+
status,
|
|
19032
|
+
...nonBlankString(progress.description) ? { description: progress.description } : nonBlankString(payload.task) ? { description: payload.task } : {},
|
|
19033
|
+
...resultSummary !== void 0 ? { resultSummary } : {},
|
|
19034
|
+
...typeof payload.sessionFile === "string" ? { sessionFile: payload.sessionFile } : {}
|
|
19035
|
+
});
|
|
19036
|
+
return true;
|
|
19086
19037
|
}
|
|
19087
|
-
|
|
19088
|
-
return
|
|
19089
|
-
}
|
|
19090
|
-
async selectModel(model2) {
|
|
19091
|
-
await this.#send("set_model", { provider: model2.provider, modelId: model2.id });
|
|
19092
|
-
return this.#refreshState("Model");
|
|
19093
|
-
}
|
|
19094
|
-
async selectThinkingOption(thinkingOptionId) {
|
|
19095
|
-
const level = harnessThinkingOptionIdSchema.parse(thinkingOptionId);
|
|
19096
|
-
await this.#send("set_thinking_level", { level });
|
|
19097
|
-
return this.#refreshState("Thinking");
|
|
19098
|
-
}
|
|
19099
|
-
async #refreshState(operation) {
|
|
19100
|
-
try {
|
|
19101
|
-
this.#state = parseSessionState(await this.#send("get_state", {}));
|
|
19102
|
-
return this.#state;
|
|
19103
|
-
} catch (error51) {
|
|
19104
|
-
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC ${operation} state could not be confirmed: ${message2(error51)}`);
|
|
19105
|
-
this.#fail(fault);
|
|
19106
|
-
throw fault;
|
|
19107
|
-
}
|
|
19038
|
+
#isBlockingInteraction(value) {
|
|
19039
|
+
return ["select", "confirm", "input", "editor"].includes(String(value.method));
|
|
19108
19040
|
}
|
|
19109
|
-
|
|
19110
|
-
if (!this.#
|
|
19111
|
-
|
|
19041
|
+
#startInteraction(active, value) {
|
|
19042
|
+
if (!this.#isBlockingInteraction(value))
|
|
19043
|
+
return;
|
|
19044
|
+
const requestId = value.id;
|
|
19045
|
+
const method = value.method;
|
|
19046
|
+
const title = value.title;
|
|
19047
|
+
const timeoutMs = value.timeout;
|
|
19048
|
+
if (typeof requestId !== "string" || requestId.length === 0 || typeof method !== "string" || typeof title !== "string" || title.length === 0 || timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs < 0) || active.interactions.has(requestId)) {
|
|
19049
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Interaction request");
|
|
19112
19050
|
}
|
|
19113
|
-
|
|
19114
|
-
|
|
19115
|
-
|
|
19116
|
-
|
|
19117
|
-
|
|
19118
|
-
|
|
19119
|
-
|
|
19120
|
-
|
|
19121
|
-
|
|
19122
|
-
|
|
19123
|
-
|
|
19124
|
-
|
|
19125
|
-
|
|
19126
|
-
|
|
19127
|
-
|
|
19128
|
-
|
|
19129
|
-
|
|
19130
|
-
|
|
19131
|
-
|
|
19132
|
-
|
|
19133
|
-
|
|
19134
|
-
|
|
19135
|
-
|
|
19136
|
-
|
|
19137
|
-
|
|
19138
|
-
|
|
19139
|
-
|
|
19140
|
-
|
|
19141
|
-
|
|
19142
|
-
|
|
19143
|
-
|
|
19051
|
+
let request;
|
|
19052
|
+
if (method === "select") {
|
|
19053
|
+
if (!Array.isArray(value.options) || value.options.length === 0 || !value.options.every((option) => typeof option === "string" && option.length > 0)) {
|
|
19054
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC select request has invalid options");
|
|
19055
|
+
}
|
|
19056
|
+
let optionDetails;
|
|
19057
|
+
if (value.optionDetails !== void 0) {
|
|
19058
|
+
if (!Array.isArray(value.optionDetails) || value.optionDetails.length !== value.options.length || !value.optionDetails.every((detail) => typeof detail === "object" && detail !== null && !Array.isArray(detail) && (detail.description === void 0 || typeof detail.description === "string"))) {
|
|
19059
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC select option details are invalid");
|
|
19060
|
+
}
|
|
19061
|
+
optionDetails = value.optionDetails.map(({ description }) => description === void 0 ? {} : { description });
|
|
19062
|
+
}
|
|
19063
|
+
request = {
|
|
19064
|
+
requestId,
|
|
19065
|
+
method,
|
|
19066
|
+
title,
|
|
19067
|
+
options: [...value.options],
|
|
19068
|
+
...optionDetails ? { optionDetails } : {},
|
|
19069
|
+
...typeof timeoutMs === "number" ? { timeoutMs } : {}
|
|
19070
|
+
};
|
|
19071
|
+
} else if (method === "confirm") {
|
|
19072
|
+
if (typeof value.message !== "string") {
|
|
19073
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC confirm request has no message");
|
|
19074
|
+
}
|
|
19075
|
+
request = {
|
|
19076
|
+
requestId,
|
|
19077
|
+
method,
|
|
19078
|
+
title,
|
|
19079
|
+
message: value.message,
|
|
19080
|
+
...typeof timeoutMs === "number" ? { timeoutMs } : {}
|
|
19081
|
+
};
|
|
19082
|
+
} else if (method === "input") {
|
|
19083
|
+
if (value.placeholder !== void 0 && typeof value.placeholder !== "string") {
|
|
19084
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC input placeholder is invalid");
|
|
19085
|
+
}
|
|
19086
|
+
request = {
|
|
19087
|
+
requestId,
|
|
19088
|
+
method,
|
|
19089
|
+
title,
|
|
19090
|
+
...typeof value.placeholder === "string" ? { placeholder: value.placeholder } : {},
|
|
19091
|
+
...typeof timeoutMs === "number" ? { timeoutMs } : {}
|
|
19092
|
+
};
|
|
19093
|
+
} else {
|
|
19094
|
+
if (value.prefill !== void 0 && typeof value.prefill !== "string") {
|
|
19095
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC editor prefill is invalid");
|
|
19096
|
+
}
|
|
19097
|
+
request = {
|
|
19098
|
+
requestId,
|
|
19099
|
+
method: "editor",
|
|
19100
|
+
title,
|
|
19101
|
+
...typeof value.prefill === "string" ? { prefill: value.prefill } : {},
|
|
19102
|
+
...typeof timeoutMs === "number" ? { timeoutMs } : {}
|
|
19144
19103
|
};
|
|
19145
|
-
});
|
|
19146
|
-
try {
|
|
19147
|
-
await this.#send("prompt", { message: text }, promptId);
|
|
19148
|
-
} catch (error51) {
|
|
19149
|
-
this.#rejectActiveTurn(error51 instanceof Error ? error51 : new Error(message2(error51)));
|
|
19150
|
-
}
|
|
19151
|
-
return settled;
|
|
19152
|
-
}
|
|
19153
|
-
respondToInteraction(response) {
|
|
19154
|
-
return this.#resolveInteraction(response, "cancelled" in response ? "cancelled" : "responded");
|
|
19155
|
-
}
|
|
19156
|
-
async #resolveInteraction(response, reason) {
|
|
19157
|
-
const active = this.#activeTurn;
|
|
19158
|
-
const pending = active?.interactions.get(response.requestId);
|
|
19159
|
-
if (!active || !pending || this.#closed || this.#failed) {
|
|
19160
|
-
throw new Error("Omp RPC interaction is not pending");
|
|
19161
19104
|
}
|
|
19162
|
-
|
|
19163
|
-
|
|
19105
|
+
const pending = { request, timeout: null };
|
|
19106
|
+
if (request.timeoutMs !== void 0) {
|
|
19107
|
+
pending.timeout = setTimeout(() => {
|
|
19108
|
+
if (this.#activeTurn !== active || !active.interactions.has(requestId))
|
|
19109
|
+
return;
|
|
19110
|
+
void this.#resolveInteraction({ requestId, cancelled: true }, "expired").catch((error51) => {
|
|
19111
|
+
if (this.#closed || this.#failed)
|
|
19112
|
+
return;
|
|
19113
|
+
this.#fail(new OmpRpcFaultError("protocolError", `Omp RPC Interaction timeout handling failed: ${message2(error51)}`));
|
|
19114
|
+
});
|
|
19115
|
+
}, request.timeoutMs);
|
|
19164
19116
|
}
|
|
19165
|
-
|
|
19166
|
-
|
|
19117
|
+
active.interactions.set(requestId, pending);
|
|
19118
|
+
active.onEvent({ type: "interaction.requested", request });
|
|
19119
|
+
}
|
|
19120
|
+
#handleResponse(value) {
|
|
19121
|
+
const id = value.id;
|
|
19122
|
+
if (typeof id !== "string") {
|
|
19123
|
+
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response has no id"));
|
|
19124
|
+
return;
|
|
19167
19125
|
}
|
|
19168
|
-
const
|
|
19169
|
-
|
|
19170
|
-
|
|
19171
|
-
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
|
-
|
|
19175
|
-
|
|
19126
|
+
const pending = this.#pending.get(id);
|
|
19127
|
+
const active = this.#activeTurn;
|
|
19128
|
+
if (!pending) {
|
|
19129
|
+
if (active?.promptId === id && value.command === "prompt" && value.success === false) {
|
|
19130
|
+
active.failure = new Error(typeof value.error === "string" ? value.error : "Omp RPC command failed");
|
|
19131
|
+
return;
|
|
19132
|
+
}
|
|
19133
|
+
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response id is not pending"));
|
|
19134
|
+
return;
|
|
19176
19135
|
}
|
|
19177
19136
|
if (pending.timeout)
|
|
19178
19137
|
clearTimeout(pending.timeout);
|
|
19179
|
-
|
|
19180
|
-
|
|
19181
|
-
|
|
19182
|
-
|
|
19183
|
-
|
|
19184
|
-
|
|
19185
|
-
|
|
19138
|
+
this.#pending.delete(id);
|
|
19139
|
+
if (value.success === true) {
|
|
19140
|
+
if (pending.command === "prompt" && active?.promptId === id && isRecord8(value.data) && value.data.agentInvoked === false) {
|
|
19141
|
+
this.#settleLocalTurn(active, { cancelled: false });
|
|
19142
|
+
}
|
|
19143
|
+
pending.resolve(value);
|
|
19144
|
+
} else {
|
|
19145
|
+
const error51 = typeof value.error === "string" ? value.error : "Omp RPC command failed";
|
|
19146
|
+
if (value.command === pending.command && error51 === `Unknown command: ${pending.command}`) {
|
|
19147
|
+
pending.reject(new OmpRpcUnsupportedCommandError(pending.command));
|
|
19148
|
+
} else {
|
|
19149
|
+
pending.reject(new Error(error51));
|
|
19150
|
+
}
|
|
19186
19151
|
}
|
|
19187
19152
|
}
|
|
19188
|
-
|
|
19189
|
-
const
|
|
19190
|
-
|
|
19191
|
-
|
|
19153
|
+
#startTool(active, value) {
|
|
19154
|
+
const callId = value.toolCallId;
|
|
19155
|
+
const toolName = value.toolName;
|
|
19156
|
+
const argumentsResult = jsonValueSchema.safeParse(value.args);
|
|
19157
|
+
if (typeof callId !== "string" || callId.length === 0 || typeof toolName !== "string" || toolName.length === 0 || !argumentsResult.success || active.tools.has(callId)) {
|
|
19158
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool start");
|
|
19192
19159
|
}
|
|
19193
|
-
|
|
19194
|
-
|
|
19195
|
-
active.
|
|
19196
|
-
|
|
19197
|
-
|
|
19198
|
-
|
|
19199
|
-
|
|
19200
|
-
if (this.#activeTurn !== active)
|
|
19201
|
-
return;
|
|
19202
|
-
active.cancellation = "accepted";
|
|
19203
|
-
await this.#confirmCancelledTurn(active);
|
|
19204
|
-
}).catch((error51) => {
|
|
19205
|
-
if (this.#activeTurn !== active)
|
|
19206
|
-
throw error51;
|
|
19207
|
-
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC Abort failed: ${message2(error51)}`);
|
|
19208
|
-
this.#terminateFailedCancellation(active, fault);
|
|
19209
|
-
throw fault;
|
|
19160
|
+
active.sawTool = true;
|
|
19161
|
+
active.tools.set(callId, toolName);
|
|
19162
|
+
active.onEvent({
|
|
19163
|
+
type: "tool.started",
|
|
19164
|
+
callId,
|
|
19165
|
+
toolName,
|
|
19166
|
+
arguments: argumentsResult.data
|
|
19210
19167
|
});
|
|
19211
|
-
active.abortPromise = aborting;
|
|
19212
|
-
return aborting;
|
|
19213
19168
|
}
|
|
19214
|
-
#
|
|
19215
|
-
|
|
19169
|
+
#updateTool(active, value) {
|
|
19170
|
+
const callId = value.toolCallId;
|
|
19171
|
+
if (typeof callId !== "string" || callId.length === 0) {
|
|
19172
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
|
|
19173
|
+
}
|
|
19174
|
+
if (!active.tools.has(callId))
|
|
19216
19175
|
return;
|
|
19217
|
-
|
|
19218
|
-
|
|
19219
|
-
|
|
19220
|
-
this.#fail(fault);
|
|
19221
|
-
void this.close().catch(() => void 0);
|
|
19222
|
-
}
|
|
19223
|
-
close() {
|
|
19224
|
-
if (!this.#closed) {
|
|
19225
|
-
this.#closed = true;
|
|
19226
|
-
this.#rejectAll(new Error("Omp RPC Session closed"));
|
|
19176
|
+
const outputResult = jsonValueSchema.safeParse(value.partialResult ?? null);
|
|
19177
|
+
if (!outputResult.success) {
|
|
19178
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
|
|
19227
19179
|
}
|
|
19228
|
-
|
|
19229
|
-
return this.#closePromise;
|
|
19180
|
+
active.onEvent({ type: "tool.updated", callId, output: outputResult.data });
|
|
19230
19181
|
}
|
|
19231
|
-
|
|
19232
|
-
const
|
|
19233
|
-
|
|
19234
|
-
|
|
19235
|
-
|
|
19236
|
-
|
|
19237
|
-
|
|
19238
|
-
|
|
19239
|
-
signalProcessTree(child, "SIGTERM");
|
|
19240
|
-
if (await waitForExit(child, this.#options.closeTimeoutMs))
|
|
19182
|
+
#completeTool(active, value) {
|
|
19183
|
+
const callId = value.toolCallId;
|
|
19184
|
+
const toolName = value.toolName;
|
|
19185
|
+
if (typeof callId !== "string" || callId.length === 0) {
|
|
19186
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool end");
|
|
19187
|
+
}
|
|
19188
|
+
const expectedName = active.tools.get(callId);
|
|
19189
|
+
if (expectedName === void 0)
|
|
19241
19190
|
return;
|
|
19242
|
-
|
|
19243
|
-
if (
|
|
19244
|
-
throw new
|
|
19191
|
+
const result = jsonValueSchema.safeParse(value.result);
|
|
19192
|
+
if (typeof toolName !== "string" || expectedName !== toolName || value.isError !== void 0 && typeof value.isError !== "boolean" || !result.success) {
|
|
19193
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool end");
|
|
19245
19194
|
}
|
|
19195
|
+
active.tools.delete(callId);
|
|
19196
|
+
active.onEvent({
|
|
19197
|
+
type: "tool.completed",
|
|
19198
|
+
callId,
|
|
19199
|
+
toolName,
|
|
19200
|
+
result: result.data,
|
|
19201
|
+
isError: value.isError === true
|
|
19202
|
+
});
|
|
19246
19203
|
}
|
|
19247
|
-
#
|
|
19248
|
-
this.#
|
|
19249
|
-
|
|
19250
|
-
|
|
19251
|
-
|
|
19252
|
-
|
|
19253
|
-
|
|
19254
|
-
|
|
19255
|
-
|
|
19256
|
-
|
|
19257
|
-
|
|
19258
|
-
|
|
19259
|
-
|
|
19204
|
+
async #confirmCancelledTurn(active) {
|
|
19205
|
+
if (this.#activeTurn !== active || active.cancellation !== "accepted" || active.settlement === "confirming" || active.cancellationChecking)
|
|
19206
|
+
return;
|
|
19207
|
+
active.cancellationChecking = true;
|
|
19208
|
+
if (active.cancellationRecheck)
|
|
19209
|
+
clearTimeout(active.cancellationRecheck);
|
|
19210
|
+
active.cancellationRecheck = null;
|
|
19211
|
+
try {
|
|
19212
|
+
let response = await this.#send("get_state", {});
|
|
19213
|
+
if (this.#activeTurn !== active)
|
|
19214
|
+
return;
|
|
19215
|
+
if (parseSessionStreaming(response)) {
|
|
19216
|
+
await this.#send("abort", {});
|
|
19217
|
+
if (this.#activeTurn !== active)
|
|
19218
|
+
return;
|
|
19219
|
+
response = await this.#send("get_state", {});
|
|
19260
19220
|
}
|
|
19261
|
-
|
|
19262
|
-
|
|
19263
|
-
|
|
19264
|
-
|
|
19265
|
-
|
|
19221
|
+
let state = parseSessionState(response);
|
|
19222
|
+
if (this.#activeTurn !== active || active.cancellation !== "accepted")
|
|
19223
|
+
return;
|
|
19224
|
+
const data = sessionStateData(response);
|
|
19225
|
+
if (!active.cancellationReloaded && state.sessionFile && state.sessionId === this.state.sessionId && state.sessionFile === this.state.sessionFile && data.isStreaming === false && data.isCompacting === false && data.queuedMessageCount === 0 && data.hasPendingAsyncWork === true && active.tools.size === 0) {
|
|
19226
|
+
await this.verifySessionCwd(this.#options.cwd);
|
|
19227
|
+
if (this.#activeTurn !== active)
|
|
19228
|
+
return;
|
|
19229
|
+
active.cancellationReloaded = true;
|
|
19230
|
+
const reset = await this.#send("new_session", {});
|
|
19231
|
+
if (this.#activeTurn !== active)
|
|
19232
|
+
return;
|
|
19233
|
+
if (!isRecord8(reset.data) || reset.data.cancelled !== false) {
|
|
19234
|
+
throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reset was refused");
|
|
19235
|
+
}
|
|
19236
|
+
const reloaded = await this.#send("switch_session", { sessionPath: state.sessionFile });
|
|
19237
|
+
if (this.#activeTurn !== active)
|
|
19238
|
+
return;
|
|
19239
|
+
if (!isRecord8(reloaded.data) || reloaded.data.cancelled !== false) {
|
|
19240
|
+
throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reload was refused");
|
|
19241
|
+
}
|
|
19242
|
+
const previous = state;
|
|
19243
|
+
response = await this.#send("get_state", {});
|
|
19244
|
+
state = parseSessionState(response);
|
|
19245
|
+
if (state.sessionId !== previous.sessionId || state.sessionFile !== previous.sessionFile) {
|
|
19246
|
+
throw new OmpRpcFaultError("protocolError", "Omp cancelled Session reload changed its identity");
|
|
19247
|
+
}
|
|
19248
|
+
if (state.provider !== previous.provider || state.modelId !== previous.modelId) {
|
|
19249
|
+
if (!previous.provider || !previous.modelId) {
|
|
19250
|
+
throw new OmpRpcFaultError("protocolError", "Omp cancelled Session has no restorable Model");
|
|
19251
|
+
}
|
|
19252
|
+
await this.#send("set_model", { provider: previous.provider, modelId: previous.modelId });
|
|
19266
19253
|
}
|
|
19267
|
-
|
|
19268
|
-
|
|
19269
|
-
|
|
19254
|
+
if (previous.thinkingLevel && state.thinkingLevel !== previous.thinkingLevel) {
|
|
19255
|
+
await this.#send("set_thinking_level", { level: previous.thinkingLevel });
|
|
19256
|
+
}
|
|
19257
|
+
response = await this.#send("get_state", {});
|
|
19258
|
+
state = parseSessionState(response);
|
|
19259
|
+
if (state.sessionId !== previous.sessionId || state.sessionFile !== previous.sessionFile || state.provider !== previous.provider || state.modelId !== previous.modelId || previous.thinkingLevel !== null && state.thinkingLevel !== previous.thinkingLevel) {
|
|
19260
|
+
throw new OmpRpcFaultError("protocolError", "Omp cancelled Session reload changed its identity or configuration");
|
|
19270
19261
|
}
|
|
19271
|
-
this.#handle(value);
|
|
19272
|
-
} catch (error51) {
|
|
19273
|
-
this.#fail(error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC frame handling failed: ${message2(error51)}`));
|
|
19274
19262
|
}
|
|
19275
|
-
|
|
19263
|
+
if (!cancellationSettled(response, active.terminalEnd)) {
|
|
19264
|
+
active.settlement = "pending";
|
|
19265
|
+
active.cancellationRecheck = setTimeout(() => {
|
|
19266
|
+
active.cancellationRecheck = null;
|
|
19267
|
+
void this.#confirmCancelledTurn(active);
|
|
19268
|
+
}, 250);
|
|
19269
|
+
return;
|
|
19270
|
+
}
|
|
19271
|
+
this.#state = state;
|
|
19272
|
+
active.settlement = "confirmed";
|
|
19273
|
+
this.#finishSettledTurn(active);
|
|
19274
|
+
} catch (error51) {
|
|
19275
|
+
if (this.#activeTurn !== active)
|
|
19276
|
+
return;
|
|
19277
|
+
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC cancelled Turn state could not be confirmed: ${message2(error51)}`);
|
|
19278
|
+
this.#terminateFailedCancellation(active, fault);
|
|
19279
|
+
} finally {
|
|
19280
|
+
active.cancellationChecking = false;
|
|
19276
19281
|
}
|
|
19277
19282
|
}
|
|
19278
|
-
|
|
19279
|
-
|
|
19280
|
-
return this.#availableCommands;
|
|
19281
|
-
}
|
|
19282
|
-
#handle(value) {
|
|
19283
|
-
if (this.#closed || this.#failed)
|
|
19284
|
-
return;
|
|
19285
|
-
if (value.type === "available_commands_update") {
|
|
19286
|
-
this.#availableCommands = parseOmpAvailableCommands(value.commands);
|
|
19287
|
-
return;
|
|
19288
|
-
}
|
|
19289
|
-
if (value.type === "ready") {
|
|
19290
|
-
this.#readyResolve?.();
|
|
19291
|
-
this.#readyResolve = null;
|
|
19292
|
-
return;
|
|
19293
|
-
}
|
|
19294
|
-
if (value.type === "response") {
|
|
19295
|
-
this.#handleResponse(value);
|
|
19296
|
-
return;
|
|
19297
|
-
}
|
|
19298
|
-
if (value.type === "auto_compaction_start" || value.type === "compaction_start") {
|
|
19299
|
-
this.#compactionActive = true;
|
|
19300
|
-
this.#compactionTurn = this.#activeTurn;
|
|
19301
|
-
this.#compactionTimeout ??= setTimeout(() => {
|
|
19302
|
-
this.#compactionTimeout = null;
|
|
19303
|
-
this.#fail(new OmpRpcFaultError("protocolError", `Omp RPC compaction timed out after ${this.#options.compactionTimeoutMs}ms`));
|
|
19304
|
-
}, this.#options.compactionTimeoutMs);
|
|
19305
|
-
const onEvent = this.#activeTurn?.onEvent ?? this.#manualCompaction?.onEvent;
|
|
19306
|
-
onEvent?.({ type: "compaction.started" });
|
|
19307
|
-
for (const pending of this.#pending.values()) {
|
|
19308
|
-
if (pending.command !== "prompt" && pending.command !== "compact" || !pending.timeout)
|
|
19309
|
-
continue;
|
|
19310
|
-
clearTimeout(pending.timeout);
|
|
19311
|
-
pending.timeout = null;
|
|
19312
|
-
}
|
|
19283
|
+
#settleLocalTurn(active, result) {
|
|
19284
|
+
if (this.#activeTurn !== active || active.settlement !== "pending")
|
|
19313
19285
|
return;
|
|
19314
|
-
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
|
|
19318
|
-
|
|
19319
|
-
|
|
19320
|
-
const
|
|
19321
|
-
|
|
19322
|
-
|
|
19323
|
-
|
|
19324
|
-
|
|
19325
|
-
|
|
19286
|
+
active.localResult = result;
|
|
19287
|
+
active.settlement = "confirming";
|
|
19288
|
+
void this.#confirmSettledTurn(active);
|
|
19289
|
+
}
|
|
19290
|
+
async #confirmSettledTurn(active) {
|
|
19291
|
+
try {
|
|
19292
|
+
const response = await this.#send("get_state", {});
|
|
19293
|
+
const state = parseSessionState(response);
|
|
19294
|
+
if (this.#activeTurn !== active)
|
|
19295
|
+
return;
|
|
19296
|
+
if (active.cancellation !== "none") {
|
|
19297
|
+
active.settlement = "pending";
|
|
19298
|
+
if (active.cancellation === "accepted")
|
|
19299
|
+
void this.#confirmCancelledTurn(active);
|
|
19300
|
+
return;
|
|
19326
19301
|
}
|
|
19327
|
-
|
|
19328
|
-
|
|
19329
|
-
type: "compaction.completed",
|
|
19330
|
-
outcome,
|
|
19331
|
-
...nonBlankString(value.errorMessage) ? { errorMessage: value.errorMessage } : {}
|
|
19332
|
-
};
|
|
19333
|
-
compactionTurn?.onEvent(event);
|
|
19334
|
-
const manual = this.#manualCompaction;
|
|
19335
|
-
this.#manualCompaction = null;
|
|
19336
|
-
manual?.onEvent(event);
|
|
19337
|
-
manual?.resolve({
|
|
19338
|
-
outcome,
|
|
19339
|
-
...event.errorMessage ? { errorMessage: event.errorMessage } : {}
|
|
19340
|
-
});
|
|
19341
|
-
return;
|
|
19342
|
-
}
|
|
19343
|
-
const active = this.#activeTurn;
|
|
19344
|
-
if (this.#handleSubagentFrame(active, value))
|
|
19345
|
-
return;
|
|
19346
|
-
this.#observeUsage(value);
|
|
19347
|
-
if (value.type === "agent_start" && active)
|
|
19348
|
-
active.terminalEnd = false;
|
|
19349
|
-
if ((value.type === "session_settled" || value.type === "agent_start") && active?.cancellation === "accepted") {
|
|
19350
|
-
void this.#confirmCancelledTurn(active);
|
|
19351
|
-
return;
|
|
19352
|
-
}
|
|
19353
|
-
if (!active) {
|
|
19354
|
-
if (value.type === "extension_ui_request" && this.#isBlockingInteraction(value)) {
|
|
19355
|
-
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC requested blocking Extension UI outside an active Turn"));
|
|
19302
|
+
if (parseSessionStreaming(response)) {
|
|
19303
|
+
throw new OmpRpcFaultError("protocolError", "Omp RPC completed Turn state is still Streaming");
|
|
19356
19304
|
}
|
|
19357
|
-
|
|
19358
|
-
|
|
19359
|
-
|
|
19360
|
-
|
|
19305
|
+
this.#state = state;
|
|
19306
|
+
active.settlement = "confirmed";
|
|
19307
|
+
this.#finishSettledTurn(active);
|
|
19308
|
+
} catch (error51) {
|
|
19309
|
+
if (this.#activeTurn !== active)
|
|
19361
19310
|
return;
|
|
19362
|
-
|
|
19363
|
-
|
|
19364
|
-
}
|
|
19365
|
-
active.text += value.text;
|
|
19366
|
-
active.onEvent({ type: "text.delta", messageId: active.promptId, delta: value.text });
|
|
19367
|
-
return;
|
|
19311
|
+
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC stable Turn state could not be confirmed: ${message2(error51)}`);
|
|
19312
|
+
this.#fail(fault);
|
|
19368
19313
|
}
|
|
19369
|
-
|
|
19370
|
-
|
|
19371
|
-
|
|
19372
|
-
if (value.status === "completed" || value.status === "aborted") {
|
|
19373
|
-
this.#settleLocalTurn(active, { cancelled: value.status === "aborted" });
|
|
19374
|
-
} else if (value.status === "error" && isRecord8(value.error) && typeof value.error.message === "string") {
|
|
19375
|
-
this.#settleLocalTurn(active, { cancelled: false, error: value.error.message });
|
|
19376
|
-
} else {
|
|
19377
|
-
throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid local prompt result");
|
|
19378
|
-
}
|
|
19314
|
+
}
|
|
19315
|
+
#finishSettledTurn(active) {
|
|
19316
|
+
if (this.#activeTurn !== active || active.settlement !== "confirmed" || active.cancellation === "requesting") {
|
|
19379
19317
|
return;
|
|
19380
19318
|
}
|
|
19381
|
-
if (
|
|
19382
|
-
|
|
19319
|
+
if (active.cancellationTimeout)
|
|
19320
|
+
clearTimeout(active.cancellationTimeout);
|
|
19321
|
+
active.cancellationTimeout = null;
|
|
19322
|
+
if (active.cancellationRecheck)
|
|
19323
|
+
clearTimeout(active.cancellationRecheck);
|
|
19324
|
+
active.cancellationRecheck = null;
|
|
19325
|
+
this.#closeInteractions(active, active.cancellation === "accepted" ? "cancelled" : "superseded");
|
|
19326
|
+
if (active.tools.size > 0) {
|
|
19327
|
+
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC settled with active Tool executions"));
|
|
19383
19328
|
return;
|
|
19384
19329
|
}
|
|
19385
|
-
|
|
19386
|
-
|
|
19387
|
-
|
|
19330
|
+
this.#activeTurn = null;
|
|
19331
|
+
if (active.localResult) {
|
|
19332
|
+
active.resolve({
|
|
19333
|
+
text: active.text,
|
|
19334
|
+
agentInvoked: false,
|
|
19335
|
+
...active.localResult,
|
|
19336
|
+
cancelled: active.localResult.cancelled || active.cancellation === "accepted"
|
|
19337
|
+
});
|
|
19338
|
+
} else if (active.cancellation === "accepted") {
|
|
19339
|
+
active.resolve({ text: active.text, cancelled: true, agentInvoked: true });
|
|
19340
|
+
} else if (active.failure) {
|
|
19341
|
+
active.reject(active.failure);
|
|
19342
|
+
} else if (active.text.trim().length === 0 && !active.sawTool) {
|
|
19343
|
+
active.reject(new Error("Omp RPC settled without displayable output"));
|
|
19344
|
+
} else {
|
|
19345
|
+
active.resolve({ text: active.text, cancelled: false, agentInvoked: true });
|
|
19388
19346
|
}
|
|
19389
|
-
|
|
19390
|
-
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
const isText = eventType === "text_delta" || eventType === "text" || eventType === "content_block_delta";
|
|
19394
|
-
const delta = typeof event.delta === "string" ? event.delta : typeof event.thinking === "string" ? event.thinking : typeof event.reasoning === "string" ? event.reasoning : typeof event.text === "string" ? event.text : isRecord8(event.delta) && typeof event.delta.thinking === "string" ? event.delta.thinking : isRecord8(event.delta) && typeof event.delta.text === "string" ? event.delta.text : null;
|
|
19395
|
-
if (isThinking && delta !== null && delta.length > 0) {
|
|
19396
|
-
const messageId = this.#ensureAssistantMessage(active, value.message);
|
|
19397
|
-
active.reasoningMessageOpen = true;
|
|
19398
|
-
active.sawStreamedMessageReasoning = true;
|
|
19399
|
-
active.onEvent({ type: "reasoning.delta", messageId, delta });
|
|
19400
|
-
} else if (isText && delta !== null && delta.length > 0) {
|
|
19401
|
-
const messageId = this.#ensureAssistantMessage(active, value.message);
|
|
19402
|
-
active.text += delta;
|
|
19403
|
-
active.sawStreamedMessageText = true;
|
|
19404
|
-
active.onEvent({ type: "text.delta", messageId, delta });
|
|
19405
|
-
} else if (event.type === "error") {
|
|
19406
|
-
this.#ensureAssistantMessage(active, value.message);
|
|
19407
|
-
active.failure = assistantFailure(event.error) ?? assistantFailure(value.message) ?? new Error("Omp assistant message failed");
|
|
19408
|
-
}
|
|
19409
|
-
return;
|
|
19347
|
+
}
|
|
19348
|
+
#startAssistantMessage(active, value) {
|
|
19349
|
+
if (active.assistantMessageId !== null && active.reasoningMessageOpen) {
|
|
19350
|
+
active.onEvent({ type: "reasoning.completed", messageId: active.assistantMessageId });
|
|
19410
19351
|
}
|
|
19411
|
-
|
|
19412
|
-
|
|
19352
|
+
const messageId = assistantMessageId(value) ?? randomUUID();
|
|
19353
|
+
active.assistantMessageId = messageId;
|
|
19354
|
+
active.sawStreamedMessageText = false;
|
|
19355
|
+
active.sawStreamedMessageReasoning = false;
|
|
19356
|
+
active.reasoningMessageOpen = false;
|
|
19357
|
+
return messageId;
|
|
19358
|
+
}
|
|
19359
|
+
#ensureAssistantMessage(active, value) {
|
|
19360
|
+
return active.assistantMessageId ?? this.#startAssistantMessage(active, value);
|
|
19361
|
+
}
|
|
19362
|
+
#finalizeAssistantMessage(active, value) {
|
|
19363
|
+
const finalText = assistantText(value);
|
|
19364
|
+
const finalReasoning = assistantReasoning(value);
|
|
19365
|
+
const failure = assistantFailure(value);
|
|
19366
|
+
const cacheHitRatePercent = optionalOmpCacheHitRatePercent(value);
|
|
19367
|
+
if (finalText === null || finalReasoning === null || failure === void 0)
|
|
19413
19368
|
return;
|
|
19414
|
-
|
|
19415
|
-
if (value.type === "turn_end") {
|
|
19416
|
-
this.#finalizeAssistantMessage(active, value.message);
|
|
19369
|
+
if (active.assistantMessageId === null && finalText === active.lastFinalizedMessageText && finalReasoning === active.lastFinalizedMessageReasoning && !active.sawStreamedMessageText && !active.sawStreamedMessageReasoning) {
|
|
19417
19370
|
return;
|
|
19418
19371
|
}
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
|
|
19372
|
+
active.failure = failure;
|
|
19373
|
+
this.#latestCacheHitRatePercent = cacheHitRatePercent;
|
|
19374
|
+
const messageId = this.#ensureAssistantMessage(active, value);
|
|
19375
|
+
if (!active.sawStreamedMessageReasoning && finalReasoning.length > 0) {
|
|
19376
|
+
active.reasoningMessageOpen = true;
|
|
19377
|
+
active.onEvent({ type: "reasoning.delta", messageId, delta: finalReasoning });
|
|
19422
19378
|
}
|
|
19423
|
-
if (
|
|
19424
|
-
|
|
19425
|
-
return;
|
|
19379
|
+
if (active.reasoningMessageOpen && active.failure === null) {
|
|
19380
|
+
active.onEvent({ type: "reasoning.completed", messageId });
|
|
19426
19381
|
}
|
|
19427
|
-
if (
|
|
19428
|
-
|
|
19429
|
-
|
|
19382
|
+
if (!active.sawStreamedMessageText && finalText.length > 0) {
|
|
19383
|
+
active.text += finalText;
|
|
19384
|
+
active.onEvent({ type: "text.delta", messageId, delta: finalText });
|
|
19430
19385
|
}
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
|
|
19386
|
+
active.assistantMessageId = null;
|
|
19387
|
+
active.sawStreamedMessageText = false;
|
|
19388
|
+
active.sawStreamedMessageReasoning = false;
|
|
19389
|
+
active.reasoningMessageOpen = false;
|
|
19390
|
+
active.lastFinalizedMessageText = finalText;
|
|
19391
|
+
active.lastFinalizedMessageReasoning = finalReasoning;
|
|
19392
|
+
active.onEvent({ type: "message.completed", messageId });
|
|
19393
|
+
}
|
|
19394
|
+
#write(value) {
|
|
19395
|
+
const child = this.#child;
|
|
19396
|
+
if (!child?.stdin.writable || this.#closed || this.#failed) {
|
|
19397
|
+
return Promise.reject(new Error("Omp RPC stdin is unavailable"));
|
|
19439
19398
|
}
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19443
|
-
|
|
19444
|
-
|
|
19445
|
-
|
|
19446
|
-
|
|
19447
|
-
|
|
19448
|
-
|
|
19449
|
-
|
|
19450
|
-
void this.#confirmSettledTurn(active);
|
|
19399
|
+
return new Promise((resolve, reject) => {
|
|
19400
|
+
const frame = Buffer.from(`${JSON.stringify(value)}
|
|
19401
|
+
`, "utf8");
|
|
19402
|
+
child.stdin.write(frame, (error51) => error51 ? reject(error51) : resolve());
|
|
19403
|
+
});
|
|
19404
|
+
}
|
|
19405
|
+
#send(type, payload, id = `codexhost-${randomUUID()}`) {
|
|
19406
|
+
const child = this.#child;
|
|
19407
|
+
if (!child?.stdin.writable || this.#closed || this.#failed) {
|
|
19408
|
+
return Promise.reject(new Error("Omp RPC stdin is unavailable"));
|
|
19451
19409
|
}
|
|
19410
|
+
return new Promise((resolve, reject) => {
|
|
19411
|
+
const pending = {
|
|
19412
|
+
command: type,
|
|
19413
|
+
resolve,
|
|
19414
|
+
reject,
|
|
19415
|
+
timeout: null
|
|
19416
|
+
};
|
|
19417
|
+
this.#pending.set(id, pending);
|
|
19418
|
+
this.#armCommandTimeout(id, pending);
|
|
19419
|
+
const frame = Buffer.from(`${JSON.stringify({ id, type, ...payload })}
|
|
19420
|
+
`, "utf8");
|
|
19421
|
+
child.stdin.write(frame, (error51) => {
|
|
19422
|
+
if (error51) {
|
|
19423
|
+
if (pending.timeout)
|
|
19424
|
+
clearTimeout(pending.timeout);
|
|
19425
|
+
this.#pending.delete(id);
|
|
19426
|
+
reject(error51);
|
|
19427
|
+
}
|
|
19428
|
+
});
|
|
19429
|
+
});
|
|
19452
19430
|
}
|
|
19453
|
-
|
|
19454
|
-
|
|
19455
|
-
if (value.type === "message_start") {
|
|
19456
|
-
this.#usageRequestStartedAtMs = null;
|
|
19431
|
+
#armCommandTimeout(id, pending) {
|
|
19432
|
+
if (pending.timeout || this.#pending.get(id) !== pending || (pending.command === "prompt" || pending.command === "compact") && this.#compactionActive) {
|
|
19457
19433
|
return;
|
|
19458
19434
|
}
|
|
19459
|
-
|
|
19460
|
-
|
|
19461
|
-
|
|
19462
|
-
|
|
19435
|
+
pending.timeout = setTimeout(() => {
|
|
19436
|
+
if (this.#pending.get(id) !== pending)
|
|
19437
|
+
return;
|
|
19438
|
+
pending.timeout = null;
|
|
19439
|
+
const error51 = new Error(`Omp RPC '${pending.command}' command timed out`);
|
|
19440
|
+
if (pending.command !== "prompt") {
|
|
19441
|
+
this.#pending.delete(id);
|
|
19442
|
+
pending.reject(error51);
|
|
19443
|
+
return;
|
|
19463
19444
|
}
|
|
19445
|
+
const fault = new OmpRpcFaultError("protocolError", error51.message);
|
|
19446
|
+
void this.#terminateTimedOutPrompt(fault);
|
|
19447
|
+
}, this.#options.commandTimeoutMs);
|
|
19448
|
+
}
|
|
19449
|
+
async #terminateTimedOutPrompt(fault) {
|
|
19450
|
+
if (this.#closed || this.#failed)
|
|
19464
19451
|
return;
|
|
19452
|
+
this.#failed = true;
|
|
19453
|
+
this.#closed = true;
|
|
19454
|
+
for (const pending of this.#pending.values()) {
|
|
19455
|
+
if (pending.timeout)
|
|
19456
|
+
clearTimeout(pending.timeout);
|
|
19457
|
+
pending.timeout = null;
|
|
19465
19458
|
}
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19471
|
-
this.#options.onUsage?.({
|
|
19472
|
-
message: value.message,
|
|
19473
|
-
startedAtMs,
|
|
19474
|
-
completedAtMs: Date.now()
|
|
19475
|
-
});
|
|
19459
|
+
let finalFault = fault;
|
|
19460
|
+
try {
|
|
19461
|
+
await this.close();
|
|
19462
|
+
} catch (error51) {
|
|
19463
|
+
finalFault = new OmpRpcFaultError("processExited", `Omp RPC timed-out Prompt cleanup failed: ${message2(error51)}`);
|
|
19476
19464
|
}
|
|
19465
|
+
this.#rejectAll(finalFault);
|
|
19466
|
+
this.#options.onFault?.(finalFault);
|
|
19477
19467
|
}
|
|
19478
|
-
#
|
|
19479
|
-
|
|
19480
|
-
|
|
19481
|
-
|
|
19482
|
-
|
|
19483
|
-
|
|
19484
|
-
const nativeIdValue = progressPayload?.id ?? payload?.id;
|
|
19485
|
-
if (!payload || !nonBlankString(nativeIdValue)) {
|
|
19486
|
-
throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent frame has no stable ID");
|
|
19468
|
+
#closeInteractions(active, reason) {
|
|
19469
|
+
for (const [requestId, pending] of active.interactions) {
|
|
19470
|
+
active.interactions.delete(requestId);
|
|
19471
|
+
if (pending.timeout)
|
|
19472
|
+
clearTimeout(pending.timeout);
|
|
19473
|
+
active.onEvent({ type: "interaction.closed", requestId, reason });
|
|
19487
19474
|
}
|
|
19488
|
-
|
|
19489
|
-
|
|
19490
|
-
const
|
|
19491
|
-
if (
|
|
19492
|
-
|
|
19493
|
-
|
|
19475
|
+
}
|
|
19476
|
+
#rejectActiveTurn(error51) {
|
|
19477
|
+
const active = this.#activeTurn;
|
|
19478
|
+
if (!active)
|
|
19479
|
+
return;
|
|
19480
|
+
if (active.cancellationTimeout)
|
|
19481
|
+
clearTimeout(active.cancellationTimeout);
|
|
19482
|
+
if (active.cancellationRecheck)
|
|
19483
|
+
clearTimeout(active.cancellationRecheck);
|
|
19484
|
+
this.#closeInteractions(active, "cancelled");
|
|
19485
|
+
this.#activeTurn = null;
|
|
19486
|
+
active.reject(error51);
|
|
19487
|
+
}
|
|
19488
|
+
#rejectAll(error51) {
|
|
19489
|
+
if (this.#compactionTimeout)
|
|
19490
|
+
clearTimeout(this.#compactionTimeout);
|
|
19491
|
+
this.#compactionTimeout = null;
|
|
19492
|
+
for (const pending of this.#pending.values()) {
|
|
19493
|
+
if (pending.timeout)
|
|
19494
|
+
clearTimeout(pending.timeout);
|
|
19495
|
+
pending.reject(error51);
|
|
19494
19496
|
}
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
|
|
19500
|
-
|
|
19501
|
-
|
|
19502
|
-
|
|
19503
|
-
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19512
|
-
|
|
19497
|
+
this.#pending.clear();
|
|
19498
|
+
const manual = this.#manualCompaction;
|
|
19499
|
+
this.#manualCompaction = null;
|
|
19500
|
+
manual?.reject(error51);
|
|
19501
|
+
this.#rejectActiveTurn(error51);
|
|
19502
|
+
}
|
|
19503
|
+
#fail(error51) {
|
|
19504
|
+
if (this.#closed || this.#failed)
|
|
19505
|
+
return;
|
|
19506
|
+
this.#failed = true;
|
|
19507
|
+
this.#startupFaultResolve?.(error51);
|
|
19508
|
+
this.#startupFaultResolve = null;
|
|
19509
|
+
this.#rejectAll(error51);
|
|
19510
|
+
this.#options.onFault?.(error51);
|
|
19511
|
+
}
|
|
19512
|
+
};
|
|
19513
|
+
|
|
19514
|
+
// dist/omp-model-list.js
|
|
19515
|
+
var OMP_MODEL_LIST_TIMEOUT_MS = 15e3;
|
|
19516
|
+
var OMP_MODEL_LIST_OUTPUT_LIMIT = 4 * 1024 * 1024;
|
|
19517
|
+
function listOmpModels(input) {
|
|
19518
|
+
const environment = withNodeRuntimeOnPath({
|
|
19519
|
+
...process.env,
|
|
19520
|
+
...input.environment,
|
|
19521
|
+
OMP_SKIP_VERSION_CHECK: "1",
|
|
19522
|
+
OMP_TELEMETRY: "0"
|
|
19523
|
+
});
|
|
19524
|
+
const executable = resolveOmpExecutable({
|
|
19525
|
+
...input.command ? { command: input.command } : {},
|
|
19526
|
+
environment
|
|
19527
|
+
});
|
|
19528
|
+
const invocation = commandInvocation(executable, ["models", "--json"], environment);
|
|
19529
|
+
return new Promise((resolve) => {
|
|
19530
|
+
if (input.signal?.aborted)
|
|
19531
|
+
return resolve({ kind: "unanswered" });
|
|
19532
|
+
const child = spawn2(invocation.command, invocation.arguments, {
|
|
19533
|
+
cwd: input.cwd,
|
|
19534
|
+
env: environment,
|
|
19535
|
+
// A process group lets a stop reach OMP and its descendants, not only a launcher shim.
|
|
19536
|
+
detached: process.platform !== "win32",
|
|
19537
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
19538
|
+
windowsHide: true,
|
|
19539
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
19540
|
+
});
|
|
19541
|
+
let settled = false;
|
|
19542
|
+
let stdout = "";
|
|
19543
|
+
const finish = (result, stop = false) => {
|
|
19544
|
+
if (settled)
|
|
19545
|
+
return;
|
|
19546
|
+
settled = true;
|
|
19547
|
+
clearTimeout(timer);
|
|
19548
|
+
input.signal?.removeEventListener("abort", onAbort);
|
|
19549
|
+
child.stdout.removeAllListeners("data");
|
|
19550
|
+
if (stop) {
|
|
19551
|
+
child.stdout.destroy();
|
|
19552
|
+
try {
|
|
19553
|
+
signalProcessTree(child, "SIGKILL");
|
|
19554
|
+
} catch {
|
|
19555
|
+
}
|
|
19513
19556
|
}
|
|
19514
|
-
|
|
19515
|
-
|
|
19516
|
-
|
|
19517
|
-
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
19521
|
-
|
|
19522
|
-
|
|
19523
|
-
}
|
|
19524
|
-
const progress = progressPayload;
|
|
19525
|
-
if (!progress || !nonBlankString(progress.id) || progress.id !== nativeSubagentId) {
|
|
19526
|
-
throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent progress is invalid");
|
|
19527
|
-
}
|
|
19528
|
-
const status = subagentStatus(progress.status);
|
|
19529
|
-
const recentOutput = Array.isArray(progress.recentOutput) ? progress.recentOutput.filter((item) => typeof item === "string") : [];
|
|
19530
|
-
const resultSummary = recentOutput.at(-1);
|
|
19531
|
-
emit?.({
|
|
19532
|
-
type: "subagent.updated",
|
|
19533
|
-
callId,
|
|
19534
|
-
nativeSubagentId,
|
|
19535
|
-
status,
|
|
19536
|
-
...nonBlankString(progress.description) ? { description: progress.description } : nonBlankString(payload.task) ? { description: payload.task } : {},
|
|
19537
|
-
...resultSummary !== void 0 ? { resultSummary } : {},
|
|
19538
|
-
...typeof payload.sessionFile === "string" ? { sessionFile: payload.sessionFile } : {}
|
|
19557
|
+
resolve(result);
|
|
19558
|
+
};
|
|
19559
|
+
const onAbort = () => finish({ kind: "unanswered" }, true);
|
|
19560
|
+
input.signal?.addEventListener("abort", onAbort, { once: true });
|
|
19561
|
+
const timer = setTimeout(() => finish({ kind: "timedOut" }, true), input.timeoutMs ?? OMP_MODEL_LIST_TIMEOUT_MS);
|
|
19562
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
19563
|
+
stdout += chunk;
|
|
19564
|
+
if (stdout.length > OMP_MODEL_LIST_OUTPUT_LIMIT)
|
|
19565
|
+
finish({ kind: "unanswered" }, true);
|
|
19539
19566
|
});
|
|
19540
|
-
|
|
19567
|
+
child.once("error", (error51) => {
|
|
19568
|
+
finish(error51.code === "ENOENT" ? { kind: "notInstalled", message: "Oh My Pi (omp) is not installed" } : { kind: "unanswered" });
|
|
19569
|
+
});
|
|
19570
|
+
child.once("close", (code) => {
|
|
19571
|
+
if (code !== 0)
|
|
19572
|
+
return finish({ kind: "unanswered" });
|
|
19573
|
+
const models = parseOmpModelList(stdout);
|
|
19574
|
+
finish(models ? { kind: "models", models } : { kind: "unanswered" });
|
|
19575
|
+
});
|
|
19576
|
+
});
|
|
19577
|
+
}
|
|
19578
|
+
function parseOmpModelList(output) {
|
|
19579
|
+
let parsed;
|
|
19580
|
+
try {
|
|
19581
|
+
parsed = JSON.parse(output);
|
|
19582
|
+
} catch {
|
|
19583
|
+
return null;
|
|
19541
19584
|
}
|
|
19542
|
-
|
|
19543
|
-
return
|
|
19585
|
+
if (!isRecord9(parsed) || !Array.isArray(parsed.models))
|
|
19586
|
+
return null;
|
|
19587
|
+
const models = [];
|
|
19588
|
+
for (const model2 of parsed.models) {
|
|
19589
|
+
if (!isRecord9(model2) || !nonBlankString2(model2.provider) || !nonBlankString2(model2.id) || typeof model2.reasoning !== "boolean") {
|
|
19590
|
+
return null;
|
|
19591
|
+
}
|
|
19592
|
+
models.push({ provider: model2.provider, id: model2.id, reasoning: model2.reasoning });
|
|
19544
19593
|
}
|
|
19545
|
-
|
|
19546
|
-
|
|
19547
|
-
|
|
19548
|
-
|
|
19549
|
-
|
|
19550
|
-
|
|
19551
|
-
|
|
19552
|
-
|
|
19553
|
-
|
|
19594
|
+
return models;
|
|
19595
|
+
}
|
|
19596
|
+
function isRecord9(value) {
|
|
19597
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19598
|
+
}
|
|
19599
|
+
function nonBlankString2(value) {
|
|
19600
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
19601
|
+
}
|
|
19602
|
+
|
|
19603
|
+
// ../../../node_modules/diff/libesm/diff/base.js
|
|
19604
|
+
var Diff = class {
|
|
19605
|
+
diff(oldStr, newStr, options = {}) {
|
|
19606
|
+
let callback;
|
|
19607
|
+
if (typeof options === "function") {
|
|
19608
|
+
callback = options;
|
|
19609
|
+
options = {};
|
|
19610
|
+
} else if ("callback" in options) {
|
|
19611
|
+
callback = options.callback;
|
|
19554
19612
|
}
|
|
19555
|
-
|
|
19556
|
-
|
|
19557
|
-
|
|
19558
|
-
|
|
19613
|
+
const oldString = this.castInput(oldStr, options);
|
|
19614
|
+
const newString = this.castInput(newStr, options);
|
|
19615
|
+
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
19616
|
+
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
19617
|
+
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
19618
|
+
}
|
|
19619
|
+
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
19620
|
+
var _a3;
|
|
19621
|
+
const done = (value) => {
|
|
19622
|
+
value = this.postProcess(value, options);
|
|
19623
|
+
if (callback) {
|
|
19624
|
+
setTimeout(function() {
|
|
19625
|
+
callback(value);
|
|
19626
|
+
}, 0);
|
|
19627
|
+
return void 0;
|
|
19628
|
+
} else {
|
|
19629
|
+
return value;
|
|
19559
19630
|
}
|
|
19560
|
-
|
|
19561
|
-
|
|
19562
|
-
|
|
19563
|
-
|
|
19631
|
+
};
|
|
19632
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
19633
|
+
let editLength = 1;
|
|
19634
|
+
let maxEditLength = newLen + oldLen;
|
|
19635
|
+
if (options.maxEditLength != null) {
|
|
19636
|
+
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
19637
|
+
}
|
|
19638
|
+
const maxExecutionTime = (_a3 = options.timeout) !== null && _a3 !== void 0 ? _a3 : Infinity;
|
|
19639
|
+
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
19640
|
+
const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
|
|
19641
|
+
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
19642
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
19643
|
+
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
19644
|
+
}
|
|
19645
|
+
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
19646
|
+
const execEditLength = () => {
|
|
19647
|
+
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
19648
|
+
let basePath;
|
|
19649
|
+
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
19650
|
+
if (removePath) {
|
|
19651
|
+
bestPath[diagonalPath - 1] = void 0;
|
|
19652
|
+
}
|
|
19653
|
+
let canAdd = false;
|
|
19654
|
+
if (addPath) {
|
|
19655
|
+
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
19656
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
19657
|
+
}
|
|
19658
|
+
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
19659
|
+
if (!canAdd && !canRemove) {
|
|
19660
|
+
bestPath[diagonalPath] = void 0;
|
|
19661
|
+
continue;
|
|
19662
|
+
}
|
|
19663
|
+
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
19664
|
+
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
19665
|
+
} else {
|
|
19666
|
+
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
19667
|
+
}
|
|
19668
|
+
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
19669
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
19670
|
+
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
19671
|
+
} else {
|
|
19672
|
+
bestPath[diagonalPath] = basePath;
|
|
19673
|
+
if (basePath.oldPos + 1 >= oldLen) {
|
|
19674
|
+
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
19675
|
+
}
|
|
19676
|
+
if (newPos + 1 >= newLen) {
|
|
19677
|
+
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
19678
|
+
}
|
|
19564
19679
|
}
|
|
19565
|
-
optionDetails = value.optionDetails.map(({ description }) => description === void 0 ? {} : { description });
|
|
19566
|
-
}
|
|
19567
|
-
request = {
|
|
19568
|
-
requestId,
|
|
19569
|
-
method,
|
|
19570
|
-
title,
|
|
19571
|
-
options: [...value.options],
|
|
19572
|
-
...optionDetails ? { optionDetails } : {},
|
|
19573
|
-
...typeof timeoutMs === "number" ? { timeoutMs } : {}
|
|
19574
|
-
};
|
|
19575
|
-
} else if (method === "confirm") {
|
|
19576
|
-
if (typeof value.message !== "string") {
|
|
19577
|
-
throw new OmpRpcFaultError("protocolError", "Omp RPC confirm request has no message");
|
|
19578
19680
|
}
|
|
19579
|
-
|
|
19580
|
-
|
|
19581
|
-
|
|
19582
|
-
|
|
19583
|
-
|
|
19584
|
-
|
|
19585
|
-
|
|
19586
|
-
|
|
19587
|
-
|
|
19588
|
-
|
|
19681
|
+
editLength++;
|
|
19682
|
+
};
|
|
19683
|
+
if (callback) {
|
|
19684
|
+
(function exec() {
|
|
19685
|
+
setTimeout(function() {
|
|
19686
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
19687
|
+
return callback(void 0);
|
|
19688
|
+
}
|
|
19689
|
+
if (!execEditLength()) {
|
|
19690
|
+
exec();
|
|
19691
|
+
}
|
|
19692
|
+
}, 0);
|
|
19693
|
+
})();
|
|
19694
|
+
} else {
|
|
19695
|
+
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
19696
|
+
const ret = execEditLength();
|
|
19697
|
+
if (ret) {
|
|
19698
|
+
return ret;
|
|
19699
|
+
}
|
|
19589
19700
|
}
|
|
19590
|
-
|
|
19591
|
-
|
|
19592
|
-
|
|
19593
|
-
|
|
19594
|
-
|
|
19595
|
-
|
|
19701
|
+
}
|
|
19702
|
+
}
|
|
19703
|
+
addToPath(path9, added, removed, oldPosInc, options) {
|
|
19704
|
+
const last = path9.lastComponent;
|
|
19705
|
+
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
19706
|
+
return {
|
|
19707
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
19708
|
+
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
19596
19709
|
};
|
|
19597
19710
|
} else {
|
|
19598
|
-
|
|
19599
|
-
|
|
19600
|
-
|
|
19601
|
-
request = {
|
|
19602
|
-
requestId,
|
|
19603
|
-
method: "editor",
|
|
19604
|
-
title,
|
|
19605
|
-
...typeof value.prefill === "string" ? { prefill: value.prefill } : {},
|
|
19606
|
-
...typeof timeoutMs === "number" ? { timeoutMs } : {}
|
|
19711
|
+
return {
|
|
19712
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
19713
|
+
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
19607
19714
|
};
|
|
19608
19715
|
}
|
|
19609
|
-
|
|
19610
|
-
|
|
19611
|
-
|
|
19612
|
-
|
|
19613
|
-
|
|
19614
|
-
|
|
19615
|
-
|
|
19616
|
-
|
|
19617
|
-
|
|
19618
|
-
}
|
|
19619
|
-
}
|
|
19716
|
+
}
|
|
19717
|
+
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
19718
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
19719
|
+
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
19720
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
19721
|
+
newPos++;
|
|
19722
|
+
oldPos++;
|
|
19723
|
+
commonCount++;
|
|
19724
|
+
if (options.oneChangePerToken) {
|
|
19725
|
+
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
19726
|
+
}
|
|
19620
19727
|
}
|
|
19621
|
-
|
|
19622
|
-
|
|
19728
|
+
if (commonCount && !options.oneChangePerToken) {
|
|
19729
|
+
basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
19730
|
+
}
|
|
19731
|
+
basePath.oldPos = oldPos;
|
|
19732
|
+
return newPos;
|
|
19623
19733
|
}
|
|
19624
|
-
|
|
19625
|
-
|
|
19626
|
-
|
|
19627
|
-
|
|
19628
|
-
return;
|
|
19734
|
+
equals(left, right, options) {
|
|
19735
|
+
if (options.comparator) {
|
|
19736
|
+
return options.comparator(left, right);
|
|
19737
|
+
} else {
|
|
19738
|
+
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
19629
19739
|
}
|
|
19630
|
-
|
|
19631
|
-
|
|
19632
|
-
|
|
19633
|
-
|
|
19634
|
-
|
|
19635
|
-
|
|
19740
|
+
}
|
|
19741
|
+
removeEmpty(array2) {
|
|
19742
|
+
const ret = [];
|
|
19743
|
+
for (let i = 0; i < array2.length; i++) {
|
|
19744
|
+
if (array2[i]) {
|
|
19745
|
+
ret.push(array2[i]);
|
|
19636
19746
|
}
|
|
19637
|
-
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response id is not pending"));
|
|
19638
|
-
return;
|
|
19639
19747
|
}
|
|
19640
|
-
|
|
19641
|
-
|
|
19642
|
-
|
|
19643
|
-
|
|
19644
|
-
|
|
19645
|
-
|
|
19646
|
-
|
|
19647
|
-
|
|
19648
|
-
|
|
19649
|
-
|
|
19650
|
-
|
|
19651
|
-
|
|
19748
|
+
return ret;
|
|
19749
|
+
}
|
|
19750
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19751
|
+
castInput(value, options) {
|
|
19752
|
+
return value;
|
|
19753
|
+
}
|
|
19754
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19755
|
+
tokenize(value, options) {
|
|
19756
|
+
return Array.from(value);
|
|
19757
|
+
}
|
|
19758
|
+
join(chars) {
|
|
19759
|
+
return chars.join("");
|
|
19760
|
+
}
|
|
19761
|
+
postProcess(changeObjects, options) {
|
|
19762
|
+
return changeObjects;
|
|
19763
|
+
}
|
|
19764
|
+
get useLongestToken() {
|
|
19765
|
+
return false;
|
|
19766
|
+
}
|
|
19767
|
+
buildValues(lastComponent, newTokens, oldTokens) {
|
|
19768
|
+
const components = [];
|
|
19769
|
+
let nextComponent;
|
|
19770
|
+
while (lastComponent) {
|
|
19771
|
+
components.push(lastComponent);
|
|
19772
|
+
nextComponent = lastComponent.previousComponent;
|
|
19773
|
+
delete lastComponent.previousComponent;
|
|
19774
|
+
lastComponent = nextComponent;
|
|
19775
|
+
}
|
|
19776
|
+
components.reverse();
|
|
19777
|
+
const componentLen = components.length;
|
|
19778
|
+
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
19779
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
19780
|
+
const component = components[componentPos];
|
|
19781
|
+
if (!component.removed) {
|
|
19782
|
+
if (!component.added && this.useLongestToken) {
|
|
19783
|
+
let value = newTokens.slice(newPos, newPos + component.count);
|
|
19784
|
+
value = value.map(function(value2, i) {
|
|
19785
|
+
const oldValue = oldTokens[oldPos + i];
|
|
19786
|
+
return oldValue.length > value2.length ? oldValue : value2;
|
|
19787
|
+
});
|
|
19788
|
+
component.value = this.join(value);
|
|
19789
|
+
} else {
|
|
19790
|
+
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
19791
|
+
}
|
|
19792
|
+
newPos += component.count;
|
|
19793
|
+
if (!component.added) {
|
|
19794
|
+
oldPos += component.count;
|
|
19795
|
+
}
|
|
19652
19796
|
} else {
|
|
19653
|
-
|
|
19797
|
+
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
19798
|
+
oldPos += component.count;
|
|
19654
19799
|
}
|
|
19655
19800
|
}
|
|
19801
|
+
return components;
|
|
19656
19802
|
}
|
|
19657
|
-
|
|
19658
|
-
|
|
19659
|
-
|
|
19660
|
-
|
|
19661
|
-
|
|
19662
|
-
|
|
19663
|
-
|
|
19664
|
-
active.sawTool = true;
|
|
19665
|
-
active.tools.set(callId, toolName);
|
|
19666
|
-
active.onEvent({
|
|
19667
|
-
type: "tool.started",
|
|
19668
|
-
callId,
|
|
19669
|
-
toolName,
|
|
19670
|
-
arguments: argumentsResult.data
|
|
19671
|
-
});
|
|
19803
|
+
};
|
|
19804
|
+
|
|
19805
|
+
// ../../../node_modules/diff/libesm/diff/line.js
|
|
19806
|
+
var LineDiff = class extends Diff {
|
|
19807
|
+
constructor() {
|
|
19808
|
+
super(...arguments);
|
|
19809
|
+
this.tokenize = tokenize;
|
|
19672
19810
|
}
|
|
19673
|
-
|
|
19674
|
-
|
|
19675
|
-
|
|
19676
|
-
|
|
19677
|
-
|
|
19678
|
-
|
|
19679
|
-
|
|
19680
|
-
|
|
19681
|
-
if (!
|
|
19682
|
-
|
|
19811
|
+
equals(left, right, options) {
|
|
19812
|
+
if (options.ignoreWhitespace) {
|
|
19813
|
+
if (!options.newlineIsToken || !left.includes("\n")) {
|
|
19814
|
+
left = left.trim();
|
|
19815
|
+
}
|
|
19816
|
+
if (!options.newlineIsToken || !right.includes("\n")) {
|
|
19817
|
+
right = right.trim();
|
|
19818
|
+
}
|
|
19819
|
+
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
19820
|
+
if (left.endsWith("\n")) {
|
|
19821
|
+
left = left.slice(0, -1);
|
|
19822
|
+
}
|
|
19823
|
+
if (right.endsWith("\n")) {
|
|
19824
|
+
right = right.slice(0, -1);
|
|
19825
|
+
}
|
|
19683
19826
|
}
|
|
19684
|
-
|
|
19827
|
+
return super.equals(left, right, options);
|
|
19685
19828
|
}
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
|
|
19695
|
-
|
|
19696
|
-
|
|
19697
|
-
|
|
19829
|
+
};
|
|
19830
|
+
var lineDiff = new LineDiff();
|
|
19831
|
+
function diffLines(oldStr, newStr, options) {
|
|
19832
|
+
return lineDiff.diff(oldStr, newStr, options);
|
|
19833
|
+
}
|
|
19834
|
+
function tokenize(value, options) {
|
|
19835
|
+
if (options.stripTrailingCr) {
|
|
19836
|
+
value = value.replace(/\r\n/g, "\n");
|
|
19837
|
+
}
|
|
19838
|
+
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
19839
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
19840
|
+
linesAndNewlines.pop();
|
|
19841
|
+
}
|
|
19842
|
+
for (let i = 0; i < linesAndNewlines.length; i++) {
|
|
19843
|
+
const line = linesAndNewlines[i];
|
|
19844
|
+
if (i % 2 && !options.newlineIsToken) {
|
|
19845
|
+
retLines[retLines.length - 1] += line;
|
|
19846
|
+
} else {
|
|
19847
|
+
retLines.push(line);
|
|
19698
19848
|
}
|
|
19699
|
-
active.tools.delete(callId);
|
|
19700
|
-
active.onEvent({
|
|
19701
|
-
type: "tool.completed",
|
|
19702
|
-
callId,
|
|
19703
|
-
toolName,
|
|
19704
|
-
result: result.data,
|
|
19705
|
-
isError: value.isError === true
|
|
19706
|
-
});
|
|
19707
19849
|
}
|
|
19708
|
-
|
|
19709
|
-
|
|
19710
|
-
|
|
19711
|
-
|
|
19712
|
-
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
|
|
19721
|
-
|
|
19722
|
-
return;
|
|
19723
|
-
response = await this.#send("get_state", {});
|
|
19850
|
+
return retLines;
|
|
19851
|
+
}
|
|
19852
|
+
|
|
19853
|
+
// ../../../node_modules/diff/libesm/patch/parse.js
|
|
19854
|
+
function parsePatch(uniDiff) {
|
|
19855
|
+
const diffstr = uniDiff.split(/\n/), list = [];
|
|
19856
|
+
let i = 0;
|
|
19857
|
+
function parseIndex() {
|
|
19858
|
+
const index = {};
|
|
19859
|
+
list.push(index);
|
|
19860
|
+
while (i < diffstr.length) {
|
|
19861
|
+
const line = diffstr[i];
|
|
19862
|
+
if (/^(---|\+\+\+|@@)\s/.test(line)) {
|
|
19863
|
+
break;
|
|
19724
19864
|
}
|
|
19725
|
-
|
|
19726
|
-
if (
|
|
19727
|
-
|
|
19728
|
-
const data = sessionStateData(response);
|
|
19729
|
-
if (!active.cancellationReloaded && state.sessionFile && state.sessionId === this.state.sessionId && state.sessionFile === this.state.sessionFile && data.isStreaming === false && data.isCompacting === false && data.queuedMessageCount === 0 && data.hasPendingAsyncWork === true && active.tools.size === 0) {
|
|
19730
|
-
await this.verifySessionCwd(this.#options.cwd);
|
|
19731
|
-
if (this.#activeTurn !== active)
|
|
19732
|
-
return;
|
|
19733
|
-
active.cancellationReloaded = true;
|
|
19734
|
-
const reset = await this.#send("new_session", {});
|
|
19735
|
-
if (this.#activeTurn !== active)
|
|
19736
|
-
return;
|
|
19737
|
-
if (!isRecord8(reset.data) || reset.data.cancelled !== false) {
|
|
19738
|
-
throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reset was refused");
|
|
19739
|
-
}
|
|
19740
|
-
const reloaded = await this.#send("switch_session", { sessionPath: state.sessionFile });
|
|
19741
|
-
if (this.#activeTurn !== active)
|
|
19742
|
-
return;
|
|
19743
|
-
if (!isRecord8(reloaded.data) || reloaded.data.cancelled !== false) {
|
|
19744
|
-
throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reload was refused");
|
|
19745
|
-
}
|
|
19746
|
-
const previous = state;
|
|
19747
|
-
response = await this.#send("get_state", {});
|
|
19748
|
-
state = parseSessionState(response);
|
|
19749
|
-
if (state.sessionId !== previous.sessionId || state.sessionFile !== previous.sessionFile) {
|
|
19750
|
-
throw new OmpRpcFaultError("protocolError", "Omp cancelled Session reload changed its identity");
|
|
19751
|
-
}
|
|
19752
|
-
if (state.provider !== previous.provider || state.modelId !== previous.modelId) {
|
|
19753
|
-
if (!previous.provider || !previous.modelId) {
|
|
19754
|
-
throw new OmpRpcFaultError("protocolError", "Omp cancelled Session has no restorable Model");
|
|
19755
|
-
}
|
|
19756
|
-
await this.#send("set_model", { provider: previous.provider, modelId: previous.modelId });
|
|
19757
|
-
}
|
|
19758
|
-
if (previous.thinkingLevel && state.thinkingLevel !== previous.thinkingLevel) {
|
|
19759
|
-
await this.#send("set_thinking_level", { level: previous.thinkingLevel });
|
|
19760
|
-
}
|
|
19761
|
-
response = await this.#send("get_state", {});
|
|
19762
|
-
state = parseSessionState(response);
|
|
19763
|
-
if (state.sessionId !== previous.sessionId || state.sessionFile !== previous.sessionFile || state.provider !== previous.provider || state.modelId !== previous.modelId || previous.thinkingLevel !== null && state.thinkingLevel !== previous.thinkingLevel) {
|
|
19764
|
-
throw new OmpRpcFaultError("protocolError", "Omp cancelled Session reload changed its identity or configuration");
|
|
19765
|
-
}
|
|
19865
|
+
const header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
|
19866
|
+
if (header) {
|
|
19867
|
+
index.index = header[1];
|
|
19766
19868
|
}
|
|
19767
|
-
|
|
19768
|
-
|
|
19769
|
-
|
|
19770
|
-
|
|
19771
|
-
|
|
19772
|
-
|
|
19773
|
-
|
|
19869
|
+
i++;
|
|
19870
|
+
}
|
|
19871
|
+
parseFileHeader(index);
|
|
19872
|
+
parseFileHeader(index);
|
|
19873
|
+
index.hunks = [];
|
|
19874
|
+
while (i < diffstr.length) {
|
|
19875
|
+
const line = diffstr[i];
|
|
19876
|
+
if (/^(Index:\s|diff\s|---\s|\+\+\+\s|===================================================================)/.test(line)) {
|
|
19877
|
+
break;
|
|
19878
|
+
} else if (/^@@/.test(line)) {
|
|
19879
|
+
index.hunks.push(parseHunk());
|
|
19880
|
+
} else if (line) {
|
|
19881
|
+
throw new Error("Unknown line " + (i + 1) + " " + JSON.stringify(line));
|
|
19882
|
+
} else {
|
|
19883
|
+
i++;
|
|
19774
19884
|
}
|
|
19775
|
-
this.#state = state;
|
|
19776
|
-
active.settlement = "confirmed";
|
|
19777
|
-
this.#finishSettledTurn(active);
|
|
19778
|
-
} catch (error51) {
|
|
19779
|
-
if (this.#activeTurn !== active)
|
|
19780
|
-
return;
|
|
19781
|
-
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC cancelled Turn state could not be confirmed: ${message2(error51)}`);
|
|
19782
|
-
this.#terminateFailedCancellation(active, fault);
|
|
19783
|
-
} finally {
|
|
19784
|
-
active.cancellationChecking = false;
|
|
19785
19885
|
}
|
|
19786
19886
|
}
|
|
19787
|
-
|
|
19788
|
-
|
|
19789
|
-
|
|
19790
|
-
|
|
19791
|
-
|
|
19792
|
-
|
|
19793
|
-
|
|
19794
|
-
async #confirmSettledTurn(active) {
|
|
19795
|
-
try {
|
|
19796
|
-
const response = await this.#send("get_state", {});
|
|
19797
|
-
const state = parseSessionState(response);
|
|
19798
|
-
if (this.#activeTurn !== active)
|
|
19799
|
-
return;
|
|
19800
|
-
if (active.cancellation !== "none") {
|
|
19801
|
-
active.settlement = "pending";
|
|
19802
|
-
if (active.cancellation === "accepted")
|
|
19803
|
-
void this.#confirmCancelledTurn(active);
|
|
19804
|
-
return;
|
|
19887
|
+
function parseFileHeader(index) {
|
|
19888
|
+
const fileHeader = /^(---|\+\+\+)\s+(.*)\r?$/.exec(diffstr[i]);
|
|
19889
|
+
if (fileHeader) {
|
|
19890
|
+
const data = fileHeader[2].split(" ", 2), header = (data[1] || "").trim();
|
|
19891
|
+
let fileName = data[0].replace(/\\\\/g, "\\");
|
|
19892
|
+
if (/^".*"$/.test(fileName)) {
|
|
19893
|
+
fileName = fileName.substr(1, fileName.length - 2);
|
|
19805
19894
|
}
|
|
19806
|
-
if (
|
|
19807
|
-
|
|
19895
|
+
if (fileHeader[1] === "---") {
|
|
19896
|
+
index.oldFileName = fileName;
|
|
19897
|
+
index.oldHeader = header;
|
|
19898
|
+
} else {
|
|
19899
|
+
index.newFileName = fileName;
|
|
19900
|
+
index.newHeader = header;
|
|
19901
|
+
}
|
|
19902
|
+
i++;
|
|
19903
|
+
}
|
|
19904
|
+
}
|
|
19905
|
+
function parseHunk() {
|
|
19906
|
+
var _a3;
|
|
19907
|
+
const chunkHeaderIndex = i, chunkHeaderLine = diffstr[i++], chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
19908
|
+
const hunk = {
|
|
19909
|
+
oldStart: +chunkHeader[1],
|
|
19910
|
+
oldLines: typeof chunkHeader[2] === "undefined" ? 1 : +chunkHeader[2],
|
|
19911
|
+
newStart: +chunkHeader[3],
|
|
19912
|
+
newLines: typeof chunkHeader[4] === "undefined" ? 1 : +chunkHeader[4],
|
|
19913
|
+
lines: []
|
|
19914
|
+
};
|
|
19915
|
+
if (hunk.oldLines === 0) {
|
|
19916
|
+
hunk.oldStart += 1;
|
|
19917
|
+
}
|
|
19918
|
+
if (hunk.newLines === 0) {
|
|
19919
|
+
hunk.newStart += 1;
|
|
19920
|
+
}
|
|
19921
|
+
let addCount = 0, removeCount = 0;
|
|
19922
|
+
for (; i < diffstr.length && (removeCount < hunk.oldLines || addCount < hunk.newLines || ((_a3 = diffstr[i]) === null || _a3 === void 0 ? void 0 : _a3.startsWith("\\"))); i++) {
|
|
19923
|
+
const operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? " " : diffstr[i][0];
|
|
19924
|
+
if (operation === "+" || operation === "-" || operation === " " || operation === "\\") {
|
|
19925
|
+
hunk.lines.push(diffstr[i]);
|
|
19926
|
+
if (operation === "+") {
|
|
19927
|
+
addCount++;
|
|
19928
|
+
} else if (operation === "-") {
|
|
19929
|
+
removeCount++;
|
|
19930
|
+
} else if (operation === " ") {
|
|
19931
|
+
addCount++;
|
|
19932
|
+
removeCount++;
|
|
19933
|
+
}
|
|
19934
|
+
} else {
|
|
19935
|
+
throw new Error(`Hunk at line ${chunkHeaderIndex + 1} contained invalid line ${diffstr[i]}`);
|
|
19808
19936
|
}
|
|
19809
|
-
this.#state = state;
|
|
19810
|
-
active.settlement = "confirmed";
|
|
19811
|
-
this.#finishSettledTurn(active);
|
|
19812
|
-
} catch (error51) {
|
|
19813
|
-
if (this.#activeTurn !== active)
|
|
19814
|
-
return;
|
|
19815
|
-
const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC stable Turn state could not be confirmed: ${message2(error51)}`);
|
|
19816
|
-
this.#fail(fault);
|
|
19817
19937
|
}
|
|
19818
|
-
|
|
19819
|
-
|
|
19820
|
-
if (this.#activeTurn !== active || active.settlement !== "confirmed" || active.cancellation === "requesting") {
|
|
19821
|
-
return;
|
|
19938
|
+
if (!addCount && hunk.newLines === 1) {
|
|
19939
|
+
hunk.newLines = 0;
|
|
19822
19940
|
}
|
|
19823
|
-
if (
|
|
19824
|
-
|
|
19825
|
-
active.cancellationTimeout = null;
|
|
19826
|
-
if (active.cancellationRecheck)
|
|
19827
|
-
clearTimeout(active.cancellationRecheck);
|
|
19828
|
-
active.cancellationRecheck = null;
|
|
19829
|
-
this.#closeInteractions(active, active.cancellation === "accepted" ? "cancelled" : "superseded");
|
|
19830
|
-
if (active.tools.size > 0) {
|
|
19831
|
-
this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC settled with active Tool executions"));
|
|
19832
|
-
return;
|
|
19941
|
+
if (!removeCount && hunk.oldLines === 1) {
|
|
19942
|
+
hunk.oldLines = 0;
|
|
19833
19943
|
}
|
|
19834
|
-
|
|
19835
|
-
|
|
19836
|
-
active.resolve({
|
|
19837
|
-
text: active.text,
|
|
19838
|
-
agentInvoked: false,
|
|
19839
|
-
...active.localResult,
|
|
19840
|
-
cancelled: active.localResult.cancelled || active.cancellation === "accepted"
|
|
19841
|
-
});
|
|
19842
|
-
} else if (active.cancellation === "accepted") {
|
|
19843
|
-
active.resolve({ text: active.text, cancelled: true, agentInvoked: true });
|
|
19844
|
-
} else if (active.failure) {
|
|
19845
|
-
active.reject(active.failure);
|
|
19846
|
-
} else if (active.text.trim().length === 0 && !active.sawTool) {
|
|
19847
|
-
active.reject(new Error("Omp RPC settled without displayable output"));
|
|
19848
|
-
} else {
|
|
19849
|
-
active.resolve({ text: active.text, cancelled: false, agentInvoked: true });
|
|
19944
|
+
if (addCount !== hunk.newLines) {
|
|
19945
|
+
throw new Error("Added line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
19850
19946
|
}
|
|
19851
|
-
|
|
19852
|
-
|
|
19853
|
-
if (active.assistantMessageId !== null && active.reasoningMessageOpen) {
|
|
19854
|
-
active.onEvent({ type: "reasoning.completed", messageId: active.assistantMessageId });
|
|
19947
|
+
if (removeCount !== hunk.oldLines) {
|
|
19948
|
+
throw new Error("Removed line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
19855
19949
|
}
|
|
19856
|
-
|
|
19857
|
-
active.assistantMessageId = messageId;
|
|
19858
|
-
active.sawStreamedMessageText = false;
|
|
19859
|
-
active.sawStreamedMessageReasoning = false;
|
|
19860
|
-
active.reasoningMessageOpen = false;
|
|
19861
|
-
return messageId;
|
|
19950
|
+
return hunk;
|
|
19862
19951
|
}
|
|
19863
|
-
|
|
19864
|
-
|
|
19952
|
+
while (i < diffstr.length) {
|
|
19953
|
+
parseIndex();
|
|
19865
19954
|
}
|
|
19866
|
-
|
|
19867
|
-
|
|
19868
|
-
|
|
19869
|
-
|
|
19870
|
-
|
|
19871
|
-
|
|
19872
|
-
|
|
19873
|
-
|
|
19955
|
+
return list;
|
|
19956
|
+
}
|
|
19957
|
+
|
|
19958
|
+
// ../../../node_modules/diff/libesm/patch/create.js
|
|
19959
|
+
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
19960
|
+
let optionsObj;
|
|
19961
|
+
if (!options) {
|
|
19962
|
+
optionsObj = {};
|
|
19963
|
+
} else if (typeof options === "function") {
|
|
19964
|
+
optionsObj = { callback: options };
|
|
19965
|
+
} else {
|
|
19966
|
+
optionsObj = options;
|
|
19967
|
+
}
|
|
19968
|
+
if (typeof optionsObj.context === "undefined") {
|
|
19969
|
+
optionsObj.context = 4;
|
|
19970
|
+
}
|
|
19971
|
+
const context = optionsObj.context;
|
|
19972
|
+
if (optionsObj.newlineIsToken) {
|
|
19973
|
+
throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
|
|
19974
|
+
}
|
|
19975
|
+
if (!optionsObj.callback) {
|
|
19976
|
+
return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
|
|
19977
|
+
} else {
|
|
19978
|
+
const { callback } = optionsObj;
|
|
19979
|
+
diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
|
|
19980
|
+
const patch = diffLinesResultToPatch(diff);
|
|
19981
|
+
callback(patch);
|
|
19982
|
+
} }));
|
|
19983
|
+
}
|
|
19984
|
+
function diffLinesResultToPatch(diff) {
|
|
19985
|
+
if (!diff) {
|
|
19874
19986
|
return;
|
|
19875
19987
|
}
|
|
19876
|
-
|
|
19877
|
-
|
|
19878
|
-
|
|
19879
|
-
|
|
19880
|
-
|
|
19881
|
-
active.onEvent({ type: "reasoning.delta", messageId, delta: finalReasoning });
|
|
19988
|
+
diff.push({ value: "", lines: [] });
|
|
19989
|
+
function contextLines(lines) {
|
|
19990
|
+
return lines.map(function(entry) {
|
|
19991
|
+
return " " + entry;
|
|
19992
|
+
});
|
|
19882
19993
|
}
|
|
19883
|
-
|
|
19884
|
-
|
|
19994
|
+
const hunks = [];
|
|
19995
|
+
let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
19996
|
+
for (let i = 0; i < diff.length; i++) {
|
|
19997
|
+
const current = diff[i], lines = current.lines || splitLines(current.value);
|
|
19998
|
+
current.lines = lines;
|
|
19999
|
+
if (current.added || current.removed) {
|
|
20000
|
+
if (!oldRangeStart) {
|
|
20001
|
+
const prev = diff[i - 1];
|
|
20002
|
+
oldRangeStart = oldLine;
|
|
20003
|
+
newRangeStart = newLine;
|
|
20004
|
+
if (prev) {
|
|
20005
|
+
curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
|
|
20006
|
+
oldRangeStart -= curRange.length;
|
|
20007
|
+
newRangeStart -= curRange.length;
|
|
20008
|
+
}
|
|
20009
|
+
}
|
|
20010
|
+
for (const line of lines) {
|
|
20011
|
+
curRange.push((current.added ? "+" : "-") + line);
|
|
20012
|
+
}
|
|
20013
|
+
if (current.added) {
|
|
20014
|
+
newLine += lines.length;
|
|
20015
|
+
} else {
|
|
20016
|
+
oldLine += lines.length;
|
|
20017
|
+
}
|
|
20018
|
+
} else {
|
|
20019
|
+
if (oldRangeStart) {
|
|
20020
|
+
if (lines.length <= context * 2 && i < diff.length - 2) {
|
|
20021
|
+
for (const line of contextLines(lines)) {
|
|
20022
|
+
curRange.push(line);
|
|
20023
|
+
}
|
|
20024
|
+
} else {
|
|
20025
|
+
const contextSize = Math.min(lines.length, context);
|
|
20026
|
+
for (const line of contextLines(lines.slice(0, contextSize))) {
|
|
20027
|
+
curRange.push(line);
|
|
20028
|
+
}
|
|
20029
|
+
const hunk = {
|
|
20030
|
+
oldStart: oldRangeStart,
|
|
20031
|
+
oldLines: oldLine - oldRangeStart + contextSize,
|
|
20032
|
+
newStart: newRangeStart,
|
|
20033
|
+
newLines: newLine - newRangeStart + contextSize,
|
|
20034
|
+
lines: curRange
|
|
20035
|
+
};
|
|
20036
|
+
hunks.push(hunk);
|
|
20037
|
+
oldRangeStart = 0;
|
|
20038
|
+
newRangeStart = 0;
|
|
20039
|
+
curRange = [];
|
|
20040
|
+
}
|
|
20041
|
+
}
|
|
20042
|
+
oldLine += lines.length;
|
|
20043
|
+
newLine += lines.length;
|
|
20044
|
+
}
|
|
19885
20045
|
}
|
|
19886
|
-
|
|
19887
|
-
|
|
19888
|
-
|
|
20046
|
+
for (const hunk of hunks) {
|
|
20047
|
+
for (let i = 0; i < hunk.lines.length; i++) {
|
|
20048
|
+
if (hunk.lines[i].endsWith("\n")) {
|
|
20049
|
+
hunk.lines[i] = hunk.lines[i].slice(0, -1);
|
|
20050
|
+
} else {
|
|
20051
|
+
hunk.lines.splice(i + 1, 0, "\");
|
|
20052
|
+
i++;
|
|
20053
|
+
}
|
|
20054
|
+
}
|
|
19889
20055
|
}
|
|
19890
|
-
|
|
19891
|
-
|
|
19892
|
-
|
|
19893
|
-
|
|
19894
|
-
|
|
19895
|
-
|
|
19896
|
-
|
|
20056
|
+
return {
|
|
20057
|
+
oldFileName,
|
|
20058
|
+
newFileName,
|
|
20059
|
+
oldHeader,
|
|
20060
|
+
newHeader,
|
|
20061
|
+
hunks
|
|
20062
|
+
};
|
|
19897
20063
|
}
|
|
19898
|
-
|
|
19899
|
-
|
|
19900
|
-
|
|
19901
|
-
|
|
19902
|
-
}
|
|
19903
|
-
return new Promise((resolve, reject) => {
|
|
19904
|
-
const frame = Buffer.from(`${JSON.stringify(value)}
|
|
19905
|
-
`, "utf8");
|
|
19906
|
-
child.stdin.write(frame, (error51) => error51 ? reject(error51) : resolve());
|
|
19907
|
-
});
|
|
20064
|
+
}
|
|
20065
|
+
function formatPatch(patch) {
|
|
20066
|
+
if (Array.isArray(patch)) {
|
|
20067
|
+
return patch.map(formatPatch).join("\n");
|
|
19908
20068
|
}
|
|
19909
|
-
|
|
19910
|
-
|
|
19911
|
-
|
|
19912
|
-
|
|
19913
|
-
|
|
19914
|
-
|
|
19915
|
-
|
|
19916
|
-
|
|
19917
|
-
|
|
19918
|
-
|
|
19919
|
-
|
|
19920
|
-
|
|
19921
|
-
|
|
19922
|
-
|
|
19923
|
-
|
|
19924
|
-
|
|
19925
|
-
|
|
19926
|
-
|
|
19927
|
-
|
|
19928
|
-
clearTimeout(pending.timeout);
|
|
19929
|
-
this.#pending.delete(id);
|
|
19930
|
-
reject(error51);
|
|
19931
|
-
}
|
|
19932
|
-
});
|
|
19933
|
-
});
|
|
20069
|
+
const ret = [];
|
|
20070
|
+
if (patch.oldFileName == patch.newFileName) {
|
|
20071
|
+
ret.push("Index: " + patch.oldFileName);
|
|
20072
|
+
}
|
|
20073
|
+
ret.push("===================================================================");
|
|
20074
|
+
ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
|
|
20075
|
+
ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
|
|
20076
|
+
for (let i = 0; i < patch.hunks.length; i++) {
|
|
20077
|
+
const hunk = patch.hunks[i];
|
|
20078
|
+
if (hunk.oldLines === 0) {
|
|
20079
|
+
hunk.oldStart -= 1;
|
|
20080
|
+
}
|
|
20081
|
+
if (hunk.newLines === 0) {
|
|
20082
|
+
hunk.newStart -= 1;
|
|
20083
|
+
}
|
|
20084
|
+
ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
|
|
20085
|
+
for (const line of hunk.lines) {
|
|
20086
|
+
ret.push(line);
|
|
20087
|
+
}
|
|
19934
20088
|
}
|
|
19935
|
-
|
|
19936
|
-
|
|
20089
|
+
return ret.join("\n") + "\n";
|
|
20090
|
+
}
|
|
20091
|
+
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
20092
|
+
if (typeof options === "function") {
|
|
20093
|
+
options = { callback: options };
|
|
20094
|
+
}
|
|
20095
|
+
if (!(options === null || options === void 0 ? void 0 : options.callback)) {
|
|
20096
|
+
const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
20097
|
+
if (!patchObj) {
|
|
19937
20098
|
return;
|
|
19938
20099
|
}
|
|
19939
|
-
|
|
19940
|
-
|
|
19941
|
-
|
|
19942
|
-
|
|
19943
|
-
|
|
19944
|
-
|
|
19945
|
-
|
|
19946
|
-
|
|
19947
|
-
return;
|
|
20100
|
+
return formatPatch(patchObj);
|
|
20101
|
+
} else {
|
|
20102
|
+
const { callback } = options;
|
|
20103
|
+
structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
|
|
20104
|
+
if (!patchObj) {
|
|
20105
|
+
callback(void 0);
|
|
20106
|
+
} else {
|
|
20107
|
+
callback(formatPatch(patchObj));
|
|
19948
20108
|
}
|
|
19949
|
-
|
|
19950
|
-
void this.#terminateTimedOutPrompt(fault);
|
|
19951
|
-
}, this.#options.commandTimeoutMs);
|
|
20109
|
+
} }));
|
|
19952
20110
|
}
|
|
19953
|
-
|
|
19954
|
-
|
|
19955
|
-
|
|
19956
|
-
|
|
19957
|
-
|
|
19958
|
-
|
|
19959
|
-
|
|
19960
|
-
|
|
19961
|
-
pending.timeout = null;
|
|
19962
|
-
}
|
|
19963
|
-
let finalFault = fault;
|
|
19964
|
-
try {
|
|
19965
|
-
await this.close();
|
|
19966
|
-
} catch (error51) {
|
|
19967
|
-
finalFault = new OmpRpcFaultError("processExited", `Omp RPC timed-out Prompt cleanup failed: ${message2(error51)}`);
|
|
19968
|
-
}
|
|
19969
|
-
this.#rejectAll(finalFault);
|
|
19970
|
-
this.#options.onFault?.(finalFault);
|
|
20111
|
+
}
|
|
20112
|
+
function splitLines(text) {
|
|
20113
|
+
const hasTrailingNl = text.endsWith("\n");
|
|
20114
|
+
const result = text.split("\n").map((line) => line + "\n");
|
|
20115
|
+
if (hasTrailingNl) {
|
|
20116
|
+
result.pop();
|
|
20117
|
+
} else {
|
|
20118
|
+
result.push(result.pop().slice(0, -1));
|
|
19971
20119
|
}
|
|
19972
|
-
|
|
19973
|
-
|
|
19974
|
-
|
|
19975
|
-
|
|
19976
|
-
|
|
19977
|
-
|
|
19978
|
-
|
|
20120
|
+
return result;
|
|
20121
|
+
}
|
|
20122
|
+
|
|
20123
|
+
// dist/omp-adapter.js
|
|
20124
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
20125
|
+
import { realpath as realpath3, stat as stat2 } from "node:fs/promises";
|
|
20126
|
+
import path7 from "node:path";
|
|
20127
|
+
|
|
20128
|
+
// dist/omp-last-turn-rollback.js
|
|
20129
|
+
function modelFromState(state) {
|
|
20130
|
+
if (state.provider === null && state.modelId === null)
|
|
20131
|
+
return null;
|
|
20132
|
+
if (state.provider === null || state.modelId === null) {
|
|
20133
|
+
throw new Error("Omp state contains a partial Model identity");
|
|
19979
20134
|
}
|
|
19980
|
-
|
|
19981
|
-
|
|
19982
|
-
|
|
19983
|
-
|
|
19984
|
-
|
|
19985
|
-
|
|
19986
|
-
|
|
19987
|
-
|
|
19988
|
-
|
|
19989
|
-
|
|
19990
|
-
|
|
20135
|
+
return { provider: state.provider, id: state.modelId };
|
|
20136
|
+
}
|
|
20137
|
+
async function rollbackOmpLastTurn(transport, sourceSessionId, cwd) {
|
|
20138
|
+
const startupState = transport.state;
|
|
20139
|
+
const startupSessionId = startupState.sessionId;
|
|
20140
|
+
const currentModel = modelFromState(startupState);
|
|
20141
|
+
const currentThinking = startupState.thinkingLevel;
|
|
20142
|
+
const copiedHistory = await transport.getEntries();
|
|
20143
|
+
const boundary = resolveOmpLastTurnBoundary(copiedHistory);
|
|
20144
|
+
if (!boundary)
|
|
20145
|
+
return { ok: false, reason: "empty" };
|
|
20146
|
+
const sourceSnapshot = mapOmpSnapshot(copiedHistory, {
|
|
20147
|
+
sessionId: startupSessionId,
|
|
20148
|
+
model: currentModel
|
|
20149
|
+
});
|
|
20150
|
+
let state = await transport.fork(boundary.lastUserEntryId);
|
|
20151
|
+
if (state.sessionId === sourceSessionId || state.sessionId === startupSessionId) {
|
|
20152
|
+
throw new Error("Omp last-Turn rollback did not create a distinct Native Session");
|
|
19991
20153
|
}
|
|
19992
|
-
|
|
19993
|
-
if (
|
|
19994
|
-
|
|
19995
|
-
|
|
19996
|
-
for (const pending of this.#pending.values()) {
|
|
19997
|
-
if (pending.timeout)
|
|
19998
|
-
clearTimeout(pending.timeout);
|
|
19999
|
-
pending.reject(error51);
|
|
20000
|
-
}
|
|
20001
|
-
this.#pending.clear();
|
|
20002
|
-
const manual = this.#manualCompaction;
|
|
20003
|
-
this.#manualCompaction = null;
|
|
20004
|
-
manual?.reject(error51);
|
|
20005
|
-
this.#rejectActiveTurn(error51);
|
|
20154
|
+
if (!sameOmpModel(modelFromState(state), currentModel)) {
|
|
20155
|
+
if (!currentModel)
|
|
20156
|
+
throw new Error("Omp last-Turn rollback changed the current Model");
|
|
20157
|
+
state = await transport.selectModel(currentModel);
|
|
20006
20158
|
}
|
|
20007
|
-
|
|
20008
|
-
if (
|
|
20009
|
-
|
|
20010
|
-
|
|
20011
|
-
this.#startupFaultResolve?.(error51);
|
|
20012
|
-
this.#startupFaultResolve = null;
|
|
20013
|
-
this.#rejectAll(error51);
|
|
20014
|
-
this.#options.onFault?.(error51);
|
|
20159
|
+
if (state.thinkingLevel !== currentThinking) {
|
|
20160
|
+
if (!currentThinking)
|
|
20161
|
+
throw new Error("Omp last-Turn rollback changed current Thinking");
|
|
20162
|
+
state = await transport.selectThinkingOption(currentThinking);
|
|
20015
20163
|
}
|
|
20016
|
-
|
|
20164
|
+
if (!sameOmpModel(modelFromState(state), currentModel) || state.thinkingLevel !== currentThinking) {
|
|
20165
|
+
throw new Error("Omp last-Turn rollback could not restore current Model and Thinking");
|
|
20166
|
+
}
|
|
20167
|
+
const snapshot = mapOmpSnapshot(await transport.getEntries(), {
|
|
20168
|
+
sessionId: state.sessionId,
|
|
20169
|
+
model: modelFromState(state)
|
|
20170
|
+
});
|
|
20171
|
+
const expectedTurnKeys = sourceSnapshot.turns.slice(0, -1).map((turn) => turn.nativeTurnRef.nativeTurnKey);
|
|
20172
|
+
const actualTurnKeys = snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey);
|
|
20173
|
+
if (snapshot.turns.length !== boundary.sourceTurnCount - 1 || actualTurnKeys.some((key, index) => key !== expectedTurnKeys[index])) {
|
|
20174
|
+
throw new Error("Omp last-Turn rollback did not produce the exact retained history prefix");
|
|
20175
|
+
}
|
|
20176
|
+
await transport.verifySessionCwd(cwd);
|
|
20177
|
+
return { ok: true };
|
|
20178
|
+
}
|
|
20017
20179
|
|
|
20018
20180
|
// dist/omp-permission-modes.js
|
|
20019
20181
|
var nativePermissionModes = /* @__PURE__ */ new Set(["always-ask", "write", "yolo"]);
|
|
@@ -20166,6 +20328,24 @@ var OmpSubagentLifecycle = class {
|
|
|
20166
20328
|
};
|
|
20167
20329
|
|
|
20168
20330
|
// dist/omp-adapter.js
|
|
20331
|
+
function closedInspection() {
|
|
20332
|
+
return {
|
|
20333
|
+
status: "unavailable",
|
|
20334
|
+
error: { code: "invalidState", message: "Omp Adapter is closed", retryable: false }
|
|
20335
|
+
};
|
|
20336
|
+
}
|
|
20337
|
+
function ompInspectionCapabilities(selectThinkingOption) {
|
|
20338
|
+
return {
|
|
20339
|
+
configuration: {
|
|
20340
|
+
selectModel: true,
|
|
20341
|
+
selectThinkingOption,
|
|
20342
|
+
selectPermissionMode: true,
|
|
20343
|
+
permissionModeScope: "live"
|
|
20344
|
+
},
|
|
20345
|
+
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
|
|
20346
|
+
subagents: { observe: true, readTranscript: true }
|
|
20347
|
+
};
|
|
20348
|
+
}
|
|
20169
20349
|
var ompHarnessId2 = harnessIdSchema.parse("omp");
|
|
20170
20350
|
var ompCommandCatalog = harnessCommandCatalogSchema.parse({
|
|
20171
20351
|
commands: [
|
|
@@ -20180,7 +20360,7 @@ var ompCommandCatalog = harnessCommandCatalogSchema.parse({
|
|
|
20180
20360
|
]
|
|
20181
20361
|
});
|
|
20182
20362
|
var DEFAULT_TOOL_OUTPUT_LIMIT = 64e3;
|
|
20183
|
-
function
|
|
20363
|
+
function isRecord10(value) {
|
|
20184
20364
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20185
20365
|
}
|
|
20186
20366
|
function errorMessage(error51) {
|
|
@@ -20195,7 +20375,7 @@ var OmpAdapterFaultError = class extends Error {
|
|
|
20195
20375
|
}
|
|
20196
20376
|
};
|
|
20197
20377
|
function normalizedError(error51, fallbackCode) {
|
|
20198
|
-
if (
|
|
20378
|
+
if (isRecord10(error51) && error51.code === "ENOENT") {
|
|
20199
20379
|
return { code: "notInstalled", message: errorMessage(error51), retryable: false };
|
|
20200
20380
|
}
|
|
20201
20381
|
if (error51 instanceof OmpAdapterFaultError)
|
|
@@ -20272,7 +20452,7 @@ function nativeModelForHistory(state) {
|
|
|
20272
20452
|
return nativeModelFromState(state);
|
|
20273
20453
|
}
|
|
20274
20454
|
function sessionFileFromRef(ref) {
|
|
20275
|
-
if (ref.harnessId !== ompHarnessId2 || !
|
|
20455
|
+
if (ref.harnessId !== ompHarnessId2 || !isRecord10(ref.locator) || typeof ref.locator.sessionFile !== "string" || ref.locator.sessionFile.length === 0) {
|
|
20276
20456
|
throw new Error("Omp Native Session Ref has no resumable Session file");
|
|
20277
20457
|
}
|
|
20278
20458
|
return ref.locator.sessionFile;
|
|
@@ -20327,9 +20507,9 @@ function toolFailure(toolName) {
|
|
|
20327
20507
|
function nativeText(value) {
|
|
20328
20508
|
if (typeof value === "string")
|
|
20329
20509
|
return value;
|
|
20330
|
-
if (!
|
|
20510
|
+
if (!isRecord10(value) || !Array.isArray(value.content))
|
|
20331
20511
|
return "";
|
|
20332
|
-
return value.content.filter((content) =>
|
|
20512
|
+
return value.content.filter((content) => isRecord10(content) && content.type === "text" && typeof content.text === "string").map(({ text }) => text).join("");
|
|
20333
20513
|
}
|
|
20334
20514
|
function boundedOutput(value, limit) {
|
|
20335
20515
|
const text = nativeText(value);
|
|
@@ -20345,17 +20525,17 @@ function outputText(output) {
|
|
|
20345
20525
|
return output?.content.filter((content) => content.type === "text").map(({ text }) => text).join("") ?? "";
|
|
20346
20526
|
}
|
|
20347
20527
|
function stringField2(value, key) {
|
|
20348
|
-
if (!
|
|
20528
|
+
if (!isRecord10(value))
|
|
20349
20529
|
return void 0;
|
|
20350
20530
|
const field = value[key];
|
|
20351
20531
|
if (typeof field === "string" && field.length > 0)
|
|
20352
20532
|
return field;
|
|
20353
|
-
if (
|
|
20533
|
+
if (isRecord10(value.input)) {
|
|
20354
20534
|
const nested = value.input[key];
|
|
20355
20535
|
if (typeof nested === "string" && nested.length > 0)
|
|
20356
20536
|
return nested;
|
|
20357
20537
|
}
|
|
20358
|
-
if (
|
|
20538
|
+
if (isRecord10(value.arguments)) {
|
|
20359
20539
|
const nested = value.arguments[key];
|
|
20360
20540
|
if (typeof nested === "string" && nested.length > 0)
|
|
20361
20541
|
return nested;
|
|
@@ -20363,7 +20543,7 @@ function stringField2(value, key) {
|
|
|
20363
20543
|
return void 0;
|
|
20364
20544
|
}
|
|
20365
20545
|
function numberField(value, key) {
|
|
20366
|
-
if (!
|
|
20546
|
+
if (!isRecord10(value))
|
|
20367
20547
|
return void 0;
|
|
20368
20548
|
const field = value[key];
|
|
20369
20549
|
return typeof field === "number" || field === null ? field : void 0;
|
|
@@ -20402,7 +20582,7 @@ function fileMutatingKind(toolName) {
|
|
|
20402
20582
|
return null;
|
|
20403
20583
|
}
|
|
20404
20584
|
function nestedToolString(value, keys) {
|
|
20405
|
-
if (!
|
|
20585
|
+
if (!isRecord10(value))
|
|
20406
20586
|
return void 0;
|
|
20407
20587
|
for (const key of keys) {
|
|
20408
20588
|
const field = value[key];
|
|
@@ -20417,14 +20597,14 @@ function nestedToolString(value, keys) {
|
|
|
20417
20597
|
return void 0;
|
|
20418
20598
|
}
|
|
20419
20599
|
function patchFromResult(result) {
|
|
20420
|
-
if (!
|
|
20600
|
+
if (!isRecord10(result))
|
|
20421
20601
|
return void 0;
|
|
20422
20602
|
for (const key of ["patch", "diff", "unifiedDiff"]) {
|
|
20423
20603
|
const field = result[key];
|
|
20424
20604
|
if (typeof field === "string" && field.length > 0)
|
|
20425
20605
|
return field;
|
|
20426
20606
|
}
|
|
20427
|
-
if (
|
|
20607
|
+
if (isRecord10(result.details)) {
|
|
20428
20608
|
for (const key of ["patch", "diff", "unifiedDiff"]) {
|
|
20429
20609
|
const field = result.details[key];
|
|
20430
20610
|
if (typeof field === "string" && field.length > 0)
|
|
@@ -20551,9 +20731,6 @@ var OmpHarnessSession = class {
|
|
|
20551
20731
|
#usage;
|
|
20552
20732
|
#usageGeneration = 0;
|
|
20553
20733
|
#usageRefreshSequence = 0;
|
|
20554
|
-
#backgroundTurnId = null;
|
|
20555
|
-
#backgroundSubagents = /* @__PURE__ */ new Map();
|
|
20556
|
-
#backgroundTurnFailed = false;
|
|
20557
20734
|
constructor(cwd, createTransport, onClosed, options) {
|
|
20558
20735
|
this.#cwd = cwd;
|
|
20559
20736
|
this.#createTransport = createTransport;
|
|
@@ -20611,44 +20788,6 @@ var OmpHarnessSession = class {
|
|
|
20611
20788
|
#backgroundStatus(status) {
|
|
20612
20789
|
return status === "pending" || status === "running" ? "running" : status === "interrupted" ? "interrupted" : status;
|
|
20613
20790
|
}
|
|
20614
|
-
#ensureBackgroundTurn() {
|
|
20615
|
-
if (this.#backgroundTurnId)
|
|
20616
|
-
return this.#backgroundTurnId;
|
|
20617
|
-
const turnId = hostTurnIdSchema.parse(randomUUID2());
|
|
20618
|
-
this.#backgroundTurnId = turnId;
|
|
20619
|
-
this.#backgroundTurnFailed = false;
|
|
20620
|
-
this.#event({
|
|
20621
|
-
type: "turn.autonomous.started",
|
|
20622
|
-
turnId,
|
|
20623
|
-
input: []
|
|
20624
|
-
});
|
|
20625
|
-
return turnId;
|
|
20626
|
-
}
|
|
20627
|
-
#backgroundDelegationStart(event) {
|
|
20628
|
-
const turnId = this.#ensureBackgroundTurn();
|
|
20629
|
-
const description = event.type === "subagent.started" ? event.description : event.type === "subagent.updated" ? event.description ?? "Background subagent" : "Background subagent";
|
|
20630
|
-
const role = event.type === "subagent.started" ? event.role : void 0;
|
|
20631
|
-
const background = event.type === "subagent.started" ? event.background : true;
|
|
20632
|
-
const state = {
|
|
20633
|
-
subagentId: event.nativeSubagentId,
|
|
20634
|
-
nativeSubagentId: event.nativeSubagentId,
|
|
20635
|
-
description,
|
|
20636
|
-
...role ? { role } : {},
|
|
20637
|
-
background,
|
|
20638
|
-
status: "running"
|
|
20639
|
-
};
|
|
20640
|
-
const item = {
|
|
20641
|
-
type: "subagentDelegation",
|
|
20642
|
-
itemId: this.#newItemId(),
|
|
20643
|
-
operation: "spawn",
|
|
20644
|
-
...event.type === "subagent.started" && event.prompt ? { prompt: event.prompt } : {},
|
|
20645
|
-
subagents: [state]
|
|
20646
|
-
};
|
|
20647
|
-
const delegation = { item, turnId };
|
|
20648
|
-
this.#backgroundSubagents.set(event.callId, delegation);
|
|
20649
|
-
this.#event({ type: "item.started", turnId, item });
|
|
20650
|
-
return delegation;
|
|
20651
|
-
}
|
|
20652
20791
|
#handleBackgroundSubagentEvent(event) {
|
|
20653
20792
|
if (event.type === "subagent.transcript.changed") {
|
|
20654
20793
|
this.#event({
|
|
@@ -20660,12 +20799,6 @@ var OmpHarnessSession = class {
|
|
|
20660
20799
|
if (event.type !== "subagent.started" && event.type !== "subagent.updated" && event.type !== "subagent.completed") {
|
|
20661
20800
|
return;
|
|
20662
20801
|
}
|
|
20663
|
-
let delegation = this.#backgroundSubagents.get(event.callId);
|
|
20664
|
-
if (!delegation)
|
|
20665
|
-
delegation = this.#backgroundDelegationStart(event);
|
|
20666
|
-
const current = delegation.item.subagents[0];
|
|
20667
|
-
if (!current)
|
|
20668
|
-
throw new Error("Omp background delegation has no Agent state");
|
|
20669
20802
|
if (event.type === "subagent.started") {
|
|
20670
20803
|
this.#event({
|
|
20671
20804
|
type: "subagent.state.changed",
|
|
@@ -20676,19 +20809,6 @@ var OmpHarnessSession = class {
|
|
|
20676
20809
|
}
|
|
20677
20810
|
if (event.type === "subagent.updated") {
|
|
20678
20811
|
const status2 = this.#backgroundStatus(event.status);
|
|
20679
|
-
const subagent2 = {
|
|
20680
|
-
...current,
|
|
20681
|
-
status: status2,
|
|
20682
|
-
...event.description ? { description: event.description } : {},
|
|
20683
|
-
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
20684
|
-
};
|
|
20685
|
-
delegation.item = { ...delegation.item, subagents: [subagent2] };
|
|
20686
|
-
this.#event({
|
|
20687
|
-
type: "item.updated",
|
|
20688
|
-
turnId: delegation.turnId,
|
|
20689
|
-
itemId: delegation.item.itemId,
|
|
20690
|
-
update: { type: "subagents.replace", subagents: delegation.item.subagents }
|
|
20691
|
-
});
|
|
20692
20812
|
this.#event({
|
|
20693
20813
|
type: "subagent.state.changed",
|
|
20694
20814
|
nativeSubagentId: event.nativeSubagentId,
|
|
@@ -20698,58 +20818,12 @@ var OmpHarnessSession = class {
|
|
|
20698
20818
|
return;
|
|
20699
20819
|
}
|
|
20700
20820
|
const status = event.isError ? "failed" : "completed";
|
|
20701
|
-
const subagent = {
|
|
20702
|
-
...current,
|
|
20703
|
-
status,
|
|
20704
|
-
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
20705
|
-
};
|
|
20706
|
-
delegation.item = { ...delegation.item, subagents: [subagent] };
|
|
20707
|
-
this.#event({
|
|
20708
|
-
type: "item.updated",
|
|
20709
|
-
turnId: delegation.turnId,
|
|
20710
|
-
itemId: delegation.item.itemId,
|
|
20711
|
-
update: { type: "subagents.replace", subagents: delegation.item.subagents }
|
|
20712
|
-
});
|
|
20713
|
-
this.#event({
|
|
20714
|
-
type: "item.completed",
|
|
20715
|
-
turnId: delegation.turnId,
|
|
20716
|
-
snapshot: {
|
|
20717
|
-
item: delegation.item,
|
|
20718
|
-
outcome: event.isError ? {
|
|
20719
|
-
status: "failed",
|
|
20720
|
-
error: {
|
|
20721
|
-
code: "nativeFailure",
|
|
20722
|
-
message: "Omp background Subagent failed",
|
|
20723
|
-
retryable: false
|
|
20724
|
-
}
|
|
20725
|
-
} : { status: "succeeded" }
|
|
20726
|
-
}
|
|
20727
|
-
});
|
|
20728
20821
|
this.#event({
|
|
20729
20822
|
type: "subagent.state.changed",
|
|
20730
20823
|
nativeSubagentId: event.nativeSubagentId,
|
|
20731
20824
|
status,
|
|
20732
20825
|
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
20733
20826
|
});
|
|
20734
|
-
this.#backgroundTurnFailed ||= event.isError;
|
|
20735
|
-
this.#backgroundSubagents.delete(event.callId);
|
|
20736
|
-
if (this.#backgroundSubagents.size === 0 && this.#backgroundTurnId === delegation.turnId) {
|
|
20737
|
-
const turnId = this.#backgroundTurnId;
|
|
20738
|
-
this.#backgroundTurnId = null;
|
|
20739
|
-
this.#event({
|
|
20740
|
-
type: "turn.completed",
|
|
20741
|
-
turnId,
|
|
20742
|
-
outcome: this.#backgroundTurnFailed ? {
|
|
20743
|
-
status: "failed",
|
|
20744
|
-
error: {
|
|
20745
|
-
code: "nativeFailure",
|
|
20746
|
-
message: "Omp background Subagent failed",
|
|
20747
|
-
retryable: false
|
|
20748
|
-
}
|
|
20749
|
-
} : { status: "succeeded" }
|
|
20750
|
-
});
|
|
20751
|
-
this.#backgroundTurnFailed = false;
|
|
20752
|
-
}
|
|
20753
20827
|
}
|
|
20754
20828
|
async readSnapshot() {
|
|
20755
20829
|
if (this.#phase !== "open" && this.#phase !== "faulted") {
|
|
@@ -20807,6 +20881,8 @@ var OmpHarnessSession = class {
|
|
|
20807
20881
|
}
|
|
20808
20882
|
if (command.type === "turn.cancel")
|
|
20809
20883
|
return this.#cancel(command);
|
|
20884
|
+
if (command.type === "turn.steer")
|
|
20885
|
+
return unsupportedSteer("OMP");
|
|
20810
20886
|
if (command.type === "interaction.respond")
|
|
20811
20887
|
return this.#respond(command);
|
|
20812
20888
|
if (command.type === "model.select")
|
|
@@ -22002,6 +22078,9 @@ var OmpAdapter = class {
|
|
|
22002
22078
|
#inspectionCache = /* @__PURE__ */ new Map();
|
|
22003
22079
|
#inspectionInFlight = /* @__PURE__ */ new Map();
|
|
22004
22080
|
#inspections = /* @__PURE__ */ new Set();
|
|
22081
|
+
#availabilityInFlight = /* @__PURE__ */ new Map();
|
|
22082
|
+
#availabilityListings = /* @__PURE__ */ new Set();
|
|
22083
|
+
#listModels;
|
|
22005
22084
|
#sessions = /* @__PURE__ */ new Set();
|
|
22006
22085
|
#toolOutputLimit;
|
|
22007
22086
|
#closePromise = null;
|
|
@@ -22010,22 +22089,21 @@ var OmpAdapter = class {
|
|
|
22010
22089
|
createTransport: (sessionOptions) => new OmpRpcSession({ ...options, ...sessionOptions })
|
|
22011
22090
|
}) {
|
|
22012
22091
|
this.#createTransport = dependencies.createTransport;
|
|
22092
|
+
const listModels = dependencies.listModels ?? listOmpModels;
|
|
22093
|
+
this.#listModels = ({ cwd, signal }) => listModels({
|
|
22094
|
+
cwd,
|
|
22095
|
+
signal,
|
|
22096
|
+
...options.command ? { command: options.command } : {},
|
|
22097
|
+
...options.environment ? { environment: options.environment } : {}
|
|
22098
|
+
});
|
|
22013
22099
|
this.sessionImport = new OmpSessionImport({ ...process.env, ...options.environment });
|
|
22014
22100
|
this.usageStatistics = createOmpUsageStatistics({ ...process.env, ...options.environment });
|
|
22015
22101
|
this.#closeTimeoutMs = options.closeTimeoutMs ?? 2e3;
|
|
22016
22102
|
this.#toolOutputLimit = options.toolOutputLimit ?? DEFAULT_TOOL_OUTPUT_LIMIT;
|
|
22017
22103
|
}
|
|
22018
22104
|
async inspect(input = {}) {
|
|
22019
|
-
if (this.#closePromise)
|
|
22020
|
-
return
|
|
22021
|
-
status: "unavailable",
|
|
22022
|
-
error: {
|
|
22023
|
-
code: "invalidState",
|
|
22024
|
-
message: "Omp Adapter is closed",
|
|
22025
|
-
retryable: false
|
|
22026
|
-
}
|
|
22027
|
-
};
|
|
22028
|
-
}
|
|
22105
|
+
if (this.#closePromise)
|
|
22106
|
+
return closedInspection();
|
|
22029
22107
|
const cwd = input.cwd ?? process.cwd();
|
|
22030
22108
|
const inFlight = this.#inspectionInFlight.get(cwd);
|
|
22031
22109
|
if (inFlight)
|
|
@@ -22035,6 +22113,37 @@ var OmpAdapter = class {
|
|
|
22035
22113
|
if (cached2)
|
|
22036
22114
|
return cached2;
|
|
22037
22115
|
}
|
|
22116
|
+
if (input.purpose === "availability")
|
|
22117
|
+
return this.#inspectAvailability(cwd, input.refresh);
|
|
22118
|
+
return this.#startFullInspection(cwd);
|
|
22119
|
+
}
|
|
22120
|
+
/**
|
|
22121
|
+
* Availability without a Session: a Session startup runs OMP's own startup work, including
|
|
22122
|
+
* Provider connection prewarm, for a Harness the user may never select. The listed result
|
|
22123
|
+
* carries no native default Model or Thinking option, so it is neither cached nor used to
|
|
22124
|
+
* update `#thinkingSelectionSupported`. When the list cannot answer, a full inspection answers
|
|
22125
|
+
* instead, reusing one that is in flight or finished meanwhile.
|
|
22126
|
+
*/
|
|
22127
|
+
async #inspectAvailability(cwd, refresh = false) {
|
|
22128
|
+
if (refresh)
|
|
22129
|
+
this.#inspectionCache.delete(cwd);
|
|
22130
|
+
let pending = this.#availabilityInFlight.get(cwd);
|
|
22131
|
+
if (!pending) {
|
|
22132
|
+
const listing = this.#listAvailability(cwd);
|
|
22133
|
+
pending = listing.finally(() => {
|
|
22134
|
+
if (this.#availabilityInFlight.get(cwd) === pending)
|
|
22135
|
+
this.#availabilityInFlight.delete(cwd);
|
|
22136
|
+
});
|
|
22137
|
+
this.#availabilityInFlight.set(cwd, pending);
|
|
22138
|
+
}
|
|
22139
|
+
const listed = await pending;
|
|
22140
|
+
if (listed)
|
|
22141
|
+
return listed;
|
|
22142
|
+
if (this.#closePromise)
|
|
22143
|
+
return closedInspection();
|
|
22144
|
+
return this.#inspectionInFlight.get(cwd) ?? this.#inspectionCache.get(cwd) ?? this.#startFullInspection(cwd);
|
|
22145
|
+
}
|
|
22146
|
+
#startFullInspection(cwd) {
|
|
22038
22147
|
const inspection = this.#inspectCwd(cwd).then((result) => {
|
|
22039
22148
|
if (result.status === "ready")
|
|
22040
22149
|
this.#inspectionCache.set(cwd, result);
|
|
@@ -22047,6 +22156,59 @@ var OmpAdapter = class {
|
|
|
22047
22156
|
}
|
|
22048
22157
|
});
|
|
22049
22158
|
}
|
|
22159
|
+
/** Returns null when a Session must answer: this OMP cannot list Models, or lists none. */
|
|
22160
|
+
async #listAvailability(cwd) {
|
|
22161
|
+
const startedAt = Date.now();
|
|
22162
|
+
const stage = "model-list";
|
|
22163
|
+
const controller = new AbortController();
|
|
22164
|
+
this.#availabilityListings.add(controller);
|
|
22165
|
+
let listed;
|
|
22166
|
+
try {
|
|
22167
|
+
listed = await this.#listModels({ cwd, signal: controller.signal });
|
|
22168
|
+
} finally {
|
|
22169
|
+
this.#availabilityListings.delete(controller);
|
|
22170
|
+
}
|
|
22171
|
+
if (listed.kind === "unanswered")
|
|
22172
|
+
return null;
|
|
22173
|
+
if (listed.kind === "notInstalled") {
|
|
22174
|
+
return {
|
|
22175
|
+
status: "notInstalled",
|
|
22176
|
+
error: {
|
|
22177
|
+
code: "notInstalled",
|
|
22178
|
+
message: listed.message,
|
|
22179
|
+
retryable: false,
|
|
22180
|
+
stage,
|
|
22181
|
+
durationMs: Date.now() - startedAt
|
|
22182
|
+
}
|
|
22183
|
+
};
|
|
22184
|
+
}
|
|
22185
|
+
if (listed.kind === "timedOut") {
|
|
22186
|
+
return {
|
|
22187
|
+
status: "error",
|
|
22188
|
+
error: {
|
|
22189
|
+
code: "unavailable",
|
|
22190
|
+
message: "Oh My Pi did not list its models in time",
|
|
22191
|
+
retryable: true,
|
|
22192
|
+
stage,
|
|
22193
|
+
durationMs: Date.now() - startedAt
|
|
22194
|
+
}
|
|
22195
|
+
};
|
|
22196
|
+
}
|
|
22197
|
+
if (listed.models.length === 0)
|
|
22198
|
+
return null;
|
|
22199
|
+
let catalog;
|
|
22200
|
+
try {
|
|
22201
|
+
catalog = normalizeOmpModelCatalog(listed.models, null, null, null);
|
|
22202
|
+
} catch {
|
|
22203
|
+
return null;
|
|
22204
|
+
}
|
|
22205
|
+
return {
|
|
22206
|
+
status: "ready",
|
|
22207
|
+
catalog,
|
|
22208
|
+
permissionModes: OMP_PERMISSION_MODE_CATALOG,
|
|
22209
|
+
capabilities: ompInspectionCapabilities(false)
|
|
22210
|
+
};
|
|
22211
|
+
}
|
|
22050
22212
|
async #inspectCwd(cwd) {
|
|
22051
22213
|
const startedAt = Date.now();
|
|
22052
22214
|
let stage = "spawn";
|
|
@@ -22070,16 +22232,7 @@ var OmpAdapter = class {
|
|
|
22070
22232
|
status: "ready",
|
|
22071
22233
|
catalog,
|
|
22072
22234
|
permissionModes: OMP_PERMISSION_MODE_CATALOG,
|
|
22073
|
-
capabilities:
|
|
22074
|
-
configuration: {
|
|
22075
|
-
selectModel: true,
|
|
22076
|
-
selectThinkingOption: thinkingLevels !== null,
|
|
22077
|
-
selectPermissionMode: true,
|
|
22078
|
-
permissionModeScope: "live"
|
|
22079
|
-
},
|
|
22080
|
-
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
|
|
22081
|
-
subagents: { observe: true, readTranscript: true }
|
|
22082
|
-
}
|
|
22235
|
+
capabilities: ompInspectionCapabilities(thinkingLevels !== null)
|
|
22083
22236
|
};
|
|
22084
22237
|
} catch (error51) {
|
|
22085
22238
|
await transport.close().catch(() => void 0);
|
|
@@ -22290,6 +22443,8 @@ var OmpAdapter = class {
|
|
|
22290
22443
|
}
|
|
22291
22444
|
close() {
|
|
22292
22445
|
if (!this.#closePromise) {
|
|
22446
|
+
for (const listing of this.#availabilityListings)
|
|
22447
|
+
listing.abort();
|
|
22293
22448
|
this.#closePromise = Promise.all([
|
|
22294
22449
|
this.sessionImport.close(),
|
|
22295
22450
|
...[...this.#inspections].map((transport) => transport.close()),
|