@get-bb/plugin-sdk 0.6.157 → 0.6.169
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/bundled-types/bb-plugin-sdk-app.d.ts +1010 -353
- package/bundled-types/bb-plugin-sdk-environment-provider.d.ts +3 -0
- package/bundled-types/bb-plugin-sdk-host.d.ts +4 -1
- package/bundled-types/bb-plugin-sdk-internal-host-policy.d.ts +9 -6
- package/bundled-types/bb-plugin-sdk-internal-plugin-app-collector.d.ts +10 -4
- package/bundled-types/bb-plugin-sdk-internal-thread-event-gate.d.ts +1001 -0
- package/bundled-types/bb-plugin-sdk-internal-thread-status.d.ts +2 -2
- package/bundled-types/bb-plugin-sdk-provider-bridge-acp-next.d.ts +56 -6
- package/bundled-types/bb-plugin-sdk-provider-bridge-acp.d.ts +56 -6
- package/bundled-types/bb-plugin-sdk-provider-bridge.d.ts +45 -8
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +7 -3
- package/bundled-types/bb-plugin-sdk-testing.d.ts +14 -19
- package/bundled-types/bb-plugin-sdk.d.ts +1043 -436
- package/dist/app.js +8 -0
- package/dist/host.js +27 -3
- package/dist/index.js +19 -1
- package/dist/internal/host-policy.js +34 -13
- package/dist/internal/plugin-app-collector.js +35 -3
- package/dist/internal/rpc-query-host.js +1 -0
- package/dist/internal/thread-event-gate.js +95 -0
- package/dist/process.js +7 -1
- package/dist/provider-bridge-acp-next.js +503 -144
- package/dist/provider-bridge-acp.js +503 -144
- package/dist/provider-bridge-testing.js +12 -4
- package/dist/provider-bridge.js +115 -34
- package/dist/replay-provider-child.mjs +158 -31
- package/dist/testing/app.js +647 -351
- package/dist/testing/index.js +184 -77
- package/package.json +8 -1
|
@@ -4487,7 +4487,8 @@ import { z as z26 } from "zod";
|
|
|
4487
4487
|
var providerMaintenanceParamsSchema = z26.object({
|
|
4488
4488
|
providerId: z26.string().min(1),
|
|
4489
4489
|
cwd: z26.string().min(1).optional(),
|
|
4490
|
-
providerOptions: z26.record(z26.string(), z26.unknown()).optional()
|
|
4490
|
+
providerOptions: z26.record(z26.string(), z26.unknown()).optional(),
|
|
4491
|
+
envVars: z26.record(z26.string(), z26.string()).optional()
|
|
4491
4492
|
}).passthrough();
|
|
4492
4493
|
var providerInstallationRequirementSchema = z26.enum(["thread_rewind"]);
|
|
4493
4494
|
var providerInstallationStatusParamsSchema = providerMaintenanceParamsSchema.extend({
|
|
@@ -4655,7 +4656,10 @@ var modelListParamsSchema = z27.object({
|
|
|
4655
4656
|
envVars: z27.record(z27.string(), z27.string()).optional(),
|
|
4656
4657
|
selectedModel: z27.string().min(1).optional()
|
|
4657
4658
|
}).passthrough();
|
|
4658
|
-
var commandListParamsSchema = z27.object({
|
|
4659
|
+
var commandListParamsSchema = z27.object({
|
|
4660
|
+
cwd: z27.string().min(1),
|
|
4661
|
+
envVars: z27.record(z27.string(), z27.string()).optional()
|
|
4662
|
+
}).passthrough();
|
|
4659
4663
|
var threadStartParamsSchema = z27.object({
|
|
4660
4664
|
...sessionConstructionFields,
|
|
4661
4665
|
input: z27.array(promptInputSchema).optional()
|
|
@@ -4741,8 +4745,12 @@ var BRIDGE_NOTIFICATION_METHODS = {
|
|
|
4741
4745
|
sessionReplaced: "session/replaced",
|
|
4742
4746
|
providerRaw: "provider/raw",
|
|
4743
4747
|
providerRecovery: "provider/recovery",
|
|
4744
|
-
error: "error"
|
|
4748
|
+
error: "error",
|
|
4749
|
+
requestCancelled: "notifications/cancelled"
|
|
4745
4750
|
};
|
|
4751
|
+
var requestCancelledNotificationSchema = z29.object({
|
|
4752
|
+
requestId: z29.union([z29.string(), z29.number().int()])
|
|
4753
|
+
}).passthrough();
|
|
4746
4754
|
var threadIdentityNotificationSchema = z29.object({
|
|
4747
4755
|
threadId: z29.string().min(1),
|
|
4748
4756
|
providerThreadId: z29.string().min(1),
|
|
@@ -5220,7 +5228,7 @@ async function runHandshakeScenario(client, fixture) {
|
|
|
5220
5228
|
...await runDeclaredRequestScenario(client, {
|
|
5221
5229
|
id: "commands/list-declared",
|
|
5222
5230
|
method: BRIDGE_REQUEST_METHODS.commandList,
|
|
5223
|
-
params: { cwd: fixture.cwd },
|
|
5231
|
+
params: { envVars: {}, cwd: fixture.cwd },
|
|
5224
5232
|
capability: "commands.list",
|
|
5225
5233
|
declared: parsed.data.capabilities.commands.list
|
|
5226
5234
|
})
|
package/dist/provider-bridge.js
CHANGED
|
@@ -1062,6 +1062,19 @@ function withoutBridgeRuntimeEnv(env) {
|
|
|
1062
1062
|
delete childEnv[PROVIDER_BRIDGE_RECORD_DIR_ENV];
|
|
1063
1063
|
return childEnv;
|
|
1064
1064
|
}
|
|
1065
|
+
function buildProviderCliEnv(envVars) {
|
|
1066
|
+
const inherited = withoutBridgeRuntimeEnv(process.env);
|
|
1067
|
+
const overrides = buildShellEnvOverrides(envVars);
|
|
1068
|
+
if (process.platform === "win32") {
|
|
1069
|
+
const overridden = new Set(
|
|
1070
|
+
Object.keys(overrides).map((name) => name.toUpperCase())
|
|
1071
|
+
);
|
|
1072
|
+
for (const name of Object.keys(inherited)) {
|
|
1073
|
+
if (overridden.has(name.toUpperCase())) delete inherited[name];
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return { ...inherited, ...overrides };
|
|
1077
|
+
}
|
|
1065
1078
|
|
|
1066
1079
|
// ../provider-bridge-protocol/src/bridge-kit/bridge-tool-calls.ts
|
|
1067
1080
|
import { z as z26 } from "zod";
|
|
@@ -2353,6 +2366,27 @@ var interactionLifecycleSchema = z15.union([
|
|
|
2353
2366
|
pluginExtensionInteractionLifecycleSchema
|
|
2354
2367
|
]);
|
|
2355
2368
|
|
|
2369
|
+
// ../text-utils/src/utf16.ts
|
|
2370
|
+
function isHighSurrogateAt(value, index) {
|
|
2371
|
+
const code = value.charCodeAt(index);
|
|
2372
|
+
return code >= 55296 && code <= 56319;
|
|
2373
|
+
}
|
|
2374
|
+
function isLowSurrogateAt(value, index) {
|
|
2375
|
+
const code = value.charCodeAt(index);
|
|
2376
|
+
return code >= 56320 && code <= 57343;
|
|
2377
|
+
}
|
|
2378
|
+
function sliceUtf16Head(value, maxChars) {
|
|
2379
|
+
let end = Math.min(value.length, Math.max(0, maxChars));
|
|
2380
|
+
if (isHighSurrogateAt(value, end - 1) && isLowSurrogateAt(value, end)) {
|
|
2381
|
+
end -= 1;
|
|
2382
|
+
}
|
|
2383
|
+
return value.slice(0, end);
|
|
2384
|
+
}
|
|
2385
|
+
var LONE_SURROGATE = /[\uD800-\uDFFF]/gu;
|
|
2386
|
+
function toWellFormedUtf16(value) {
|
|
2387
|
+
return value.replace(LONE_SURROGATE, "\uFFFD");
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2356
2390
|
// ../domain/src/provider-event.ts
|
|
2357
2391
|
import { z as z20 } from "zod";
|
|
2358
2392
|
|
|
@@ -3877,23 +3911,6 @@ function shouldAutoDenyInteractiveRequest(policy) {
|
|
|
3877
3911
|
return policy.permissionEscalation === "deny";
|
|
3878
3912
|
}
|
|
3879
3913
|
|
|
3880
|
-
// ../text-utils/src/utf16.ts
|
|
3881
|
-
function isHighSurrogateAt(value, index) {
|
|
3882
|
-
const code = value.charCodeAt(index);
|
|
3883
|
-
return code >= 55296 && code <= 56319;
|
|
3884
|
-
}
|
|
3885
|
-
function isLowSurrogateAt(value, index) {
|
|
3886
|
-
const code = value.charCodeAt(index);
|
|
3887
|
-
return code >= 56320 && code <= 57343;
|
|
3888
|
-
}
|
|
3889
|
-
function sliceUtf16Head(value, maxChars) {
|
|
3890
|
-
let end = Math.min(value.length, Math.max(0, maxChars));
|
|
3891
|
-
if (isHighSurrogateAt(value, end - 1) && isLowSurrogateAt(value, end)) {
|
|
3892
|
-
end -= 1;
|
|
3893
|
-
}
|
|
3894
|
-
return value.slice(0, end);
|
|
3895
|
-
}
|
|
3896
|
-
|
|
3897
3914
|
// ../provider-bridge-protocol/src/bridge-kit/presentation.ts
|
|
3898
3915
|
var PRESENTATION_TITLE_MAX_LENGTH = 160;
|
|
3899
3916
|
function presentationTitle(text) {
|
|
@@ -4614,8 +4631,7 @@ function spawnPortableProcess(request) {
|
|
|
4614
4631
|
cwd: request.cwd,
|
|
4615
4632
|
detached: request.detached,
|
|
4616
4633
|
env: request.env,
|
|
4617
|
-
stdio: request.stdio
|
|
4618
|
-
windowsHide: true
|
|
4634
|
+
stdio: request.stdio
|
|
4619
4635
|
});
|
|
4620
4636
|
}
|
|
4621
4637
|
|
|
@@ -4644,7 +4660,7 @@ function terminateWindowsProcessTrees(pids) {
|
|
|
4644
4660
|
"taskkill.exe"
|
|
4645
4661
|
),
|
|
4646
4662
|
[...pids.flatMap((pid) => ["/pid", String(pid)]), "/T", "/F"],
|
|
4647
|
-
{
|
|
4663
|
+
{},
|
|
4648
4664
|
(error) => finish(error === null)
|
|
4649
4665
|
);
|
|
4650
4666
|
timer = setTimeout(() => {
|
|
@@ -11931,14 +11947,14 @@ import path8 from "node:path";
|
|
|
11931
11947
|
import { z as z28 } from "zod";
|
|
11932
11948
|
var CLI_PROBE_TIMEOUT_MS = 5e3;
|
|
11933
11949
|
var INSTALLATION_CHECK_TIMEOUT_MS = 15e3;
|
|
11934
|
-
async function resolveExecutablePath(command) {
|
|
11935
|
-
return hostToolchain.resolve(command);
|
|
11950
|
+
async function resolveExecutablePath(command, env) {
|
|
11951
|
+
return hostToolchain.resolve(command, env === void 0 ? {} : { env });
|
|
11936
11952
|
}
|
|
11937
|
-
async function commandOutput(command, args) {
|
|
11953
|
+
async function commandOutput(command, args, env) {
|
|
11938
11954
|
try {
|
|
11939
11955
|
const { stdout, stderr } = await execPortableFile(command, [...args], {
|
|
11940
11956
|
cwd: process.cwd(),
|
|
11941
|
-
env: process.env,
|
|
11957
|
+
env: env ?? process.env,
|
|
11942
11958
|
maxBuffer: 1024 * 1024,
|
|
11943
11959
|
timeout: INSTALLATION_CHECK_TIMEOUT_MS
|
|
11944
11960
|
});
|
|
@@ -11952,11 +11968,11 @@ function versionFrom(value) {
|
|
|
11952
11968
|
const candidate = value?.match(/\bv?(\d+\.\d+\.\d+[0-9A-Za-z.+-]*)/u)?.[1];
|
|
11953
11969
|
return candidate !== void 0 && (0, import_valid.default)(candidate) !== null ? candidate : null;
|
|
11954
11970
|
}
|
|
11955
|
-
async function readCliVersion(command) {
|
|
11971
|
+
async function readCliVersion(command, env) {
|
|
11956
11972
|
try {
|
|
11957
11973
|
const { stdout, stderr } = await execPortableFile(command, ["--version"], {
|
|
11958
11974
|
cwd: process.cwd(),
|
|
11959
|
-
env: process.env,
|
|
11975
|
+
env: env ?? process.env,
|
|
11960
11976
|
maxBuffer: 1024 * 1024,
|
|
11961
11977
|
timeout: CLI_PROBE_TIMEOUT_MS
|
|
11962
11978
|
});
|
|
@@ -11982,16 +11998,16 @@ function npmGlobalInstallCommand(npmPackage) {
|
|
|
11982
11998
|
const args = ["install", "-g", `${npmPackage}@latest`];
|
|
11983
11999
|
return { command, args, displayCommand: formatCommand(command, args) };
|
|
11984
12000
|
}
|
|
11985
|
-
async function npmLatestVersion(npmPackage) {
|
|
12001
|
+
async function npmLatestVersion(npmPackage, env) {
|
|
11986
12002
|
return versionFrom(
|
|
11987
|
-
await commandOutput(npmCommand(), ["view", npmPackage, "version"])
|
|
12003
|
+
await commandOutput(npmCommand(), ["view", npmPackage, "version"], env)
|
|
11988
12004
|
);
|
|
11989
12005
|
}
|
|
11990
|
-
async function probeNpmGlobalPackage(npmPackage) {
|
|
12006
|
+
async function probeNpmGlobalPackage(npmPackage, env) {
|
|
11991
12007
|
const npm = npmCommand();
|
|
11992
12008
|
const [prefixOutput, listOutput] = await Promise.all([
|
|
11993
|
-
commandOutput(npm, ["prefix", "-g"]),
|
|
11994
|
-
commandOutput(npm, ["list", "-g", npmPackage, "--depth=0", "--json"])
|
|
12009
|
+
commandOutput(npm, ["prefix", "-g"], env),
|
|
12010
|
+
commandOutput(npm, ["list", "-g", npmPackage, "--depth=0", "--json"], env)
|
|
11995
12011
|
]);
|
|
11996
12012
|
const npmPrefix = firstLine(prefixOutput);
|
|
11997
12013
|
return {
|
|
@@ -12111,6 +12127,59 @@ var ProviderResponseEncodeError = class extends Error {
|
|
|
12111
12127
|
}
|
|
12112
12128
|
};
|
|
12113
12129
|
var ignoredJsonRpcResultSchema = z31.unknown();
|
|
12130
|
+
function wellFormedStrings(_key, value) {
|
|
12131
|
+
return typeof value === "string" ? toWellFormedUtf16(value) : value;
|
|
12132
|
+
}
|
|
12133
|
+
function serializeJsonRpcLine(message) {
|
|
12134
|
+
const line = JSON.stringify(message);
|
|
12135
|
+
return line.includes("\\ud") ? JSON.stringify(message, wellFormedStrings) : line;
|
|
12136
|
+
}
|
|
12137
|
+
|
|
12138
|
+
// ../provider-bridge-protocol/src/bridge-kit/unanswered-interaction.ts
|
|
12139
|
+
var UNANSWERED_INTERACTION_WARNING_SUMMARY = "bb answered the agent without you";
|
|
12140
|
+
function sentence(text) {
|
|
12141
|
+
return text.trim().replace(/[.\s]+$/u, "");
|
|
12142
|
+
}
|
|
12143
|
+
function causeText(cause) {
|
|
12144
|
+
switch (cause.kind) {
|
|
12145
|
+
case "unshowable-request":
|
|
12146
|
+
return `it could not show the question: ${sentence(cause.detail)}`;
|
|
12147
|
+
case "runtime-error":
|
|
12148
|
+
return `it stopped waiting for your answer: ${sentence(cause.message)}`;
|
|
12149
|
+
case "unreadable-resolution":
|
|
12150
|
+
return "it could not read the answer it received";
|
|
12151
|
+
case "unmappable-answer":
|
|
12152
|
+
return `your answer did not fit the question: ${sentence(cause.detail)}`;
|
|
12153
|
+
case "withdrawn":
|
|
12154
|
+
return `it withdrew the question: ${sentence(cause.detail)}`;
|
|
12155
|
+
}
|
|
12156
|
+
}
|
|
12157
|
+
function agentCauseText(cause) {
|
|
12158
|
+
switch (cause.kind) {
|
|
12159
|
+
case "unshowable-request":
|
|
12160
|
+
return `bb could not show the question (${sentence(cause.detail)})`;
|
|
12161
|
+
case "runtime-error":
|
|
12162
|
+
return `bb stopped waiting for the answer (${sentence(cause.message)})`;
|
|
12163
|
+
case "unreadable-resolution":
|
|
12164
|
+
return "bb could not read the answer it received";
|
|
12165
|
+
case "unmappable-answer":
|
|
12166
|
+
return `the answer did not fit the question (${sentence(cause.detail)})`;
|
|
12167
|
+
case "withdrawn":
|
|
12168
|
+
return `bb withdrew the question (${sentence(cause.detail)})`;
|
|
12169
|
+
}
|
|
12170
|
+
}
|
|
12171
|
+
function unansweredInteractionErrorMessage(cause) {
|
|
12172
|
+
return `The user did not answer: ${agentCauseText(cause)}.`;
|
|
12173
|
+
}
|
|
12174
|
+
function unansweredInteractionWarning(args) {
|
|
12175
|
+
const answer = args.answer.kind === "error" ? "an error" : JSON.stringify(args.answer.value);
|
|
12176
|
+
return {
|
|
12177
|
+
kind: "provider.warning",
|
|
12178
|
+
summary: UNANSWERED_INTERACTION_WARNING_SUMMARY,
|
|
12179
|
+
details: `bb answered the agent with ${answer} because ${causeText(args.cause)}.`,
|
|
12180
|
+
vouchedTurn: true
|
|
12181
|
+
};
|
|
12182
|
+
}
|
|
12114
12183
|
|
|
12115
12184
|
// ../provider-bridge-protocol/src/version.ts
|
|
12116
12185
|
var PROVIDER_BRIDGE_PROTOCOL_VERSION = 2;
|
|
@@ -12172,7 +12241,8 @@ import { z as z34 } from "zod";
|
|
|
12172
12241
|
var providerMaintenanceParamsSchema = z34.object({
|
|
12173
12242
|
providerId: z34.string().min(1),
|
|
12174
12243
|
cwd: z34.string().min(1).optional(),
|
|
12175
|
-
providerOptions: z34.record(z34.string(), z34.unknown()).optional()
|
|
12244
|
+
providerOptions: z34.record(z34.string(), z34.unknown()).optional(),
|
|
12245
|
+
envVars: z34.record(z34.string(), z34.string()).optional()
|
|
12176
12246
|
}).passthrough();
|
|
12177
12247
|
var providerInstallationRequirementSchema = z34.enum(["thread_rewind"]);
|
|
12178
12248
|
var providerInstallationStatusParamsSchema = providerMaintenanceParamsSchema.extend({
|
|
@@ -12340,7 +12410,10 @@ var modelListParamsSchema = z35.object({
|
|
|
12340
12410
|
envVars: z35.record(z35.string(), z35.string()).optional(),
|
|
12341
12411
|
selectedModel: z35.string().min(1).optional()
|
|
12342
12412
|
}).passthrough();
|
|
12343
|
-
var commandListParamsSchema = z35.object({
|
|
12413
|
+
var commandListParamsSchema = z35.object({
|
|
12414
|
+
cwd: z35.string().min(1),
|
|
12415
|
+
envVars: z35.record(z35.string(), z35.string()).optional()
|
|
12416
|
+
}).passthrough();
|
|
12344
12417
|
var commandListResultSchema = threadProviderCommandsStateSchema;
|
|
12345
12418
|
var threadStartParamsSchema = z35.object({
|
|
12346
12419
|
...sessionConstructionFields,
|
|
@@ -12411,8 +12484,12 @@ var BRIDGE_NOTIFICATION_METHODS = {
|
|
|
12411
12484
|
sessionReplaced: "session/replaced",
|
|
12412
12485
|
providerRaw: "provider/raw",
|
|
12413
12486
|
providerRecovery: "provider/recovery",
|
|
12414
|
-
error: "error"
|
|
12487
|
+
error: "error",
|
|
12488
|
+
requestCancelled: "notifications/cancelled"
|
|
12415
12489
|
};
|
|
12490
|
+
var requestCancelledNotificationSchema = z36.object({
|
|
12491
|
+
requestId: z36.union([z36.string(), z36.number().int()])
|
|
12492
|
+
}).passthrough();
|
|
12416
12493
|
var threadIdentityNotificationSchema = z36.object({
|
|
12417
12494
|
threadId: z36.string().min(1),
|
|
12418
12495
|
providerThreadId: z36.string().min(1),
|
|
@@ -13057,6 +13134,7 @@ export {
|
|
|
13057
13134
|
COMPACTION_PRESENTATION as experimental_COMPACTION_PRESENTATION,
|
|
13058
13135
|
REASONING_PRESENTATION as experimental_REASONING_PRESENTATION,
|
|
13059
13136
|
buildBridgeToolCallContent as experimental_buildBridgeToolCallContent,
|
|
13137
|
+
buildProviderCliEnv as experimental_buildProviderCliEnv,
|
|
13060
13138
|
clampPercent as experimental_clampPercent,
|
|
13061
13139
|
commandOutput as experimental_commandOutput,
|
|
13062
13140
|
compareVersions as experimental_compareVersions,
|
|
@@ -13083,8 +13161,11 @@ export {
|
|
|
13083
13161
|
scanSkillFiles as experimental_scanSkillFiles,
|
|
13084
13162
|
searchPresentation as experimental_searchPresentation,
|
|
13085
13163
|
selectedSkillMentions as experimental_selectedSkillMentions,
|
|
13164
|
+
serializeJsonRpcLine as experimental_serializeJsonRpcLine,
|
|
13086
13165
|
spawnPortableProcess as experimental_spawnPortableProcess,
|
|
13087
13166
|
toolPresentation as experimental_toolPresentation,
|
|
13167
|
+
unansweredInteractionErrorMessage as experimental_unansweredInteractionErrorMessage,
|
|
13168
|
+
unansweredInteractionWarning as experimental_unansweredInteractionWarning,
|
|
13088
13169
|
versionFrom as experimental_versionFrom,
|
|
13089
13170
|
webFetchPresentation as experimental_webFetchPresentation,
|
|
13090
13171
|
webSearchPresentation as experimental_webSearchPresentation,
|
|
@@ -81,7 +81,9 @@ function parseArgs(argv) {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
if (!args.recording || !args.dialect || !args.state) {
|
|
84
|
-
throw new Error(
|
|
84
|
+
throw new Error(
|
|
85
|
+
"usage: --recording <dir> --dialect <json-rpc|claude-cli|pi-rpc> --state <dir>",
|
|
86
|
+
);
|
|
85
87
|
}
|
|
86
88
|
return args;
|
|
87
89
|
}
|
|
@@ -93,7 +95,10 @@ function readLane(dir, direction) {
|
|
|
93
95
|
.split("\n")
|
|
94
96
|
.filter((line) => line.length > 0)
|
|
95
97
|
.map((line) => JSON.parse(line))
|
|
96
|
-
.map((entry) => ({
|
|
98
|
+
.map((entry) => ({
|
|
99
|
+
...entry,
|
|
100
|
+
run: typeof entry.run === "number" ? entry.run : 0,
|
|
101
|
+
}));
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
// ---------------------------------------------------------------------------
|
|
@@ -103,7 +108,8 @@ function readLane(dir, direction) {
|
|
|
103
108
|
const DIALECTS = {
|
|
104
109
|
"json-rpc": {
|
|
105
110
|
classify(message) {
|
|
106
|
-
const hasId =
|
|
111
|
+
const hasId =
|
|
112
|
+
typeof message.id === "string" || typeof message.id === "number";
|
|
107
113
|
if (hasId && typeof message.method === "string") {
|
|
108
114
|
return { kind: "request", id: message.id, key: message.method };
|
|
109
115
|
}
|
|
@@ -135,7 +141,11 @@ const DIALECTS = {
|
|
|
135
141
|
};
|
|
136
142
|
}
|
|
137
143
|
if (message.type === "control_response") {
|
|
138
|
-
return {
|
|
144
|
+
return {
|
|
145
|
+
kind: "response",
|
|
146
|
+
id: message.response?.request_id,
|
|
147
|
+
key: "control_response",
|
|
148
|
+
};
|
|
139
149
|
}
|
|
140
150
|
return {
|
|
141
151
|
kind: "notification",
|
|
@@ -143,7 +153,10 @@ const DIALECTS = {
|
|
|
143
153
|
};
|
|
144
154
|
},
|
|
145
155
|
isInitialize(classified) {
|
|
146
|
-
return
|
|
156
|
+
return (
|
|
157
|
+
classified.kind === "request" &&
|
|
158
|
+
classified.key === "control_request:initialize"
|
|
159
|
+
);
|
|
147
160
|
},
|
|
148
161
|
withResponseId(message, id) {
|
|
149
162
|
return { ...message, response: { ...message.response, request_id: id } };
|
|
@@ -183,9 +196,18 @@ const DIALECTS = {
|
|
|
183
196
|
};
|
|
184
197
|
}
|
|
185
198
|
if (channel.kind === "tool-result" || channel.kind === "reply") {
|
|
186
|
-
return {
|
|
199
|
+
return {
|
|
200
|
+
kind: "response",
|
|
201
|
+
id: channel.id,
|
|
202
|
+
key: "channel:response",
|
|
203
|
+
channel: true,
|
|
204
|
+
};
|
|
187
205
|
}
|
|
188
|
-
return {
|
|
206
|
+
return {
|
|
207
|
+
kind: "notification",
|
|
208
|
+
key: `channel:${channel.kind ?? "?"}`,
|
|
209
|
+
channel: true,
|
|
210
|
+
};
|
|
189
211
|
}
|
|
190
212
|
if (message.type === "response") {
|
|
191
213
|
return { kind: "response", id: message.id, key: "response" };
|
|
@@ -239,8 +261,14 @@ function buildSegments(entries, dialect) {
|
|
|
239
261
|
let current = null;
|
|
240
262
|
for (const entry of entries) {
|
|
241
263
|
const message = parseLine(entry.line);
|
|
242
|
-
const classified =
|
|
243
|
-
|
|
264
|
+
const classified =
|
|
265
|
+
message === null
|
|
266
|
+
? { kind: "raw", key: "raw" }
|
|
267
|
+
: dialect.classify(message);
|
|
268
|
+
const startsSegment =
|
|
269
|
+
entry.dir === "bridge→provider" &&
|
|
270
|
+
message !== null &&
|
|
271
|
+
dialect.isInitialize(classified);
|
|
244
272
|
if (current === null || startsSegment) {
|
|
245
273
|
current = [];
|
|
246
274
|
segments.push(current);
|
|
@@ -294,7 +322,10 @@ function readCursor(stateDir) {
|
|
|
294
322
|
function cursorAllows(cursor, entry) {
|
|
295
323
|
if (cursor === null) return true;
|
|
296
324
|
if (cursor === false) return false;
|
|
297
|
-
return
|
|
325
|
+
return (
|
|
326
|
+
entry.run < cursor.run ||
|
|
327
|
+
(entry.run === cursor.run && entry.seq < cursor.seq)
|
|
328
|
+
);
|
|
298
329
|
}
|
|
299
330
|
|
|
300
331
|
function firstSessionDefiningKey(script) {
|
|
@@ -365,7 +396,7 @@ function connectChannel(channel) {
|
|
|
365
396
|
// Player
|
|
366
397
|
// ---------------------------------------------------------------------------
|
|
367
398
|
|
|
368
|
-
function
|
|
399
|
+
function recordedPiModels(entries) {
|
|
369
400
|
const models = new Map();
|
|
370
401
|
let state = {};
|
|
371
402
|
for (const entry of entries) {
|
|
@@ -389,6 +420,17 @@ function servePiCatalog(entries) {
|
|
|
389
420
|
}
|
|
390
421
|
}
|
|
391
422
|
}
|
|
423
|
+
return { models, state };
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const PI_MODEL_SELECTION_KEYS = new Set([
|
|
427
|
+
"get_available_models",
|
|
428
|
+
"set_model",
|
|
429
|
+
"set_thinking_level",
|
|
430
|
+
]);
|
|
431
|
+
|
|
432
|
+
function servePiCatalog(entries) {
|
|
433
|
+
const { models, state } = recordedPiModels(entries);
|
|
392
434
|
const channel = connectChannel(DIALECTS["pi-rpc"].channel);
|
|
393
435
|
readNewlineDelimitedLines(channel, (line) => {
|
|
394
436
|
const message = parseLine(line);
|
|
@@ -465,9 +507,12 @@ function main() {
|
|
|
465
507
|
process.argv.includes("--no-session-persistence");
|
|
466
508
|
const segmentIndex = diagnosticFork ? null : claimSegmentIndex(args.state);
|
|
467
509
|
let script = segmentIndex === null ? [] : (segments[segmentIndex] ?? []);
|
|
468
|
-
const log = (text) =>
|
|
510
|
+
const log = (text) =>
|
|
511
|
+
process.stderr.write(`[replay-child #${segmentIndex}] ${text}\n`);
|
|
469
512
|
if (script.length === 0) {
|
|
470
|
-
log(
|
|
513
|
+
log(
|
|
514
|
+
`no recorded segment ${segmentIndex} (recording has ${segments.length}); answering generically`,
|
|
515
|
+
);
|
|
471
516
|
}
|
|
472
517
|
const segmentSessionKey = firstSessionDefiningKey(script);
|
|
473
518
|
let sawSessionDefiningRequest = false;
|
|
@@ -486,11 +531,18 @@ function main() {
|
|
|
486
531
|
let piState = null;
|
|
487
532
|
let piStreaming = false;
|
|
488
533
|
let piPromptProbePending = false;
|
|
534
|
+
let piSelectionProbePending = false;
|
|
535
|
+
const piModels =
|
|
536
|
+
args.dialect === "pi-rpc" ? recordedPiModels(entries).models : new Map();
|
|
489
537
|
|
|
490
538
|
const channel = dialect.channel ?? null;
|
|
491
539
|
const channelSocket = channel ? connectChannel(channel) : null;
|
|
492
540
|
function emit(message) {
|
|
493
|
-
if (
|
|
541
|
+
if (
|
|
542
|
+
channel &&
|
|
543
|
+
typeof message[channel.key] === "object" &&
|
|
544
|
+
message[channel.key] !== null
|
|
545
|
+
) {
|
|
494
546
|
channelSocket.write(`${JSON.stringify(message[channel.key])}\n`);
|
|
495
547
|
return;
|
|
496
548
|
}
|
|
@@ -517,7 +569,12 @@ function main() {
|
|
|
517
569
|
}
|
|
518
570
|
if (classified.kind === "response") {
|
|
519
571
|
const liveId = liveIdByRecordedId.get(String(classified.id));
|
|
520
|
-
emit(
|
|
572
|
+
emit(
|
|
573
|
+
dialect.withResponseId(
|
|
574
|
+
message,
|
|
575
|
+
liveId === undefined ? classified.id : liveId,
|
|
576
|
+
),
|
|
577
|
+
);
|
|
521
578
|
return;
|
|
522
579
|
}
|
|
523
580
|
if (
|
|
@@ -528,7 +585,10 @@ function main() {
|
|
|
528
585
|
) {
|
|
529
586
|
emit({
|
|
530
587
|
...message,
|
|
531
|
-
request: {
|
|
588
|
+
request: {
|
|
589
|
+
...message.request,
|
|
590
|
+
callback_id: hookIds.get(message.request.callback_id),
|
|
591
|
+
},
|
|
532
592
|
});
|
|
533
593
|
return;
|
|
534
594
|
}
|
|
@@ -635,7 +695,10 @@ function main() {
|
|
|
635
695
|
}
|
|
636
696
|
if (step.classified.kind === "request") {
|
|
637
697
|
liveIdByRecordedId.set(String(step.classified.id), live.classified.id);
|
|
638
|
-
if (
|
|
698
|
+
if (
|
|
699
|
+
dialect.isInitialize(step.classified) &&
|
|
700
|
+
args.dialect === "claude-cli"
|
|
701
|
+
) {
|
|
639
702
|
hookIds = hookCallbackIdMap(step.message, live.message);
|
|
640
703
|
}
|
|
641
704
|
}
|
|
@@ -666,11 +729,14 @@ function main() {
|
|
|
666
729
|
: step.classified.key === live.classified.key);
|
|
667
730
|
if (!same) continue;
|
|
668
731
|
const cursor = readCursor(args.state);
|
|
669
|
-
const gated = script
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
732
|
+
const gated = script
|
|
733
|
+
.slice(position, index)
|
|
734
|
+
.some(
|
|
735
|
+
(between) =>
|
|
736
|
+
between.dir === "provider→bridge" &&
|
|
737
|
+
between.classified.kind !== "response" &&
|
|
738
|
+
!cursorAllows(cursor, between),
|
|
739
|
+
);
|
|
674
740
|
if (gated) {
|
|
675
741
|
lookaheadTimer = setTimeout(lookAhead, CURSOR_POLL_MS);
|
|
676
742
|
return;
|
|
@@ -692,7 +758,9 @@ function main() {
|
|
|
692
758
|
emitRecorded(between);
|
|
693
759
|
}
|
|
694
760
|
}
|
|
695
|
-
log(
|
|
761
|
+
log(
|
|
762
|
+
`bridge skipped recorded ${skipped.join(", ")}; resuming at ${live.classified.key}`,
|
|
763
|
+
);
|
|
696
764
|
position = index;
|
|
697
765
|
advance();
|
|
698
766
|
armStall();
|
|
@@ -703,10 +771,14 @@ function main() {
|
|
|
703
771
|
|
|
704
772
|
function answerGenerically(live, reason) {
|
|
705
773
|
if (live.classified.kind === "request") {
|
|
706
|
-
log(
|
|
774
|
+
log(
|
|
775
|
+
`${reason}: answering ${live.classified.key} (${String(live.classified.id)}) generically`,
|
|
776
|
+
);
|
|
707
777
|
emit(dialect.genericResponse(live.classified.id, live.classified));
|
|
708
778
|
} else {
|
|
709
|
-
log(
|
|
779
|
+
log(
|
|
780
|
+
`${reason}: dropping unmatched ${live.classified.kind} ${live.classified.key}`,
|
|
781
|
+
);
|
|
710
782
|
}
|
|
711
783
|
}
|
|
712
784
|
|
|
@@ -716,7 +788,9 @@ function main() {
|
|
|
716
788
|
const expected = script[position];
|
|
717
789
|
log(
|
|
718
790
|
`stalled for ${STALL_MS}ms at step ${position}/${script.length}` +
|
|
719
|
-
(expected
|
|
791
|
+
(expected
|
|
792
|
+
? ` (expecting ${expected.dir} ${expected.classified.key})`
|
|
793
|
+
: ""),
|
|
720
794
|
);
|
|
721
795
|
for (const live of pendingLive.splice(0)) {
|
|
722
796
|
answerGenerically(live, "stall");
|
|
@@ -728,7 +802,8 @@ function main() {
|
|
|
728
802
|
if (stallTimer !== null) clearTimeout(stallTimer);
|
|
729
803
|
if (lookaheadTimer !== null) clearTimeout(lookaheadTimer);
|
|
730
804
|
stallTimer = pendingLive.length > 0 ? setTimeout(onStall, STALL_MS) : null;
|
|
731
|
-
lookaheadTimer =
|
|
805
|
+
lookaheadTimer =
|
|
806
|
+
pendingLive.length > 0 ? setTimeout(lookAhead, LOOKAHEAD_MS) : null;
|
|
732
807
|
}
|
|
733
808
|
|
|
734
809
|
/**
|
|
@@ -747,6 +822,46 @@ function main() {
|
|
|
747
822
|
}
|
|
748
823
|
}
|
|
749
824
|
|
|
825
|
+
function nextBridgeExpectationKey() {
|
|
826
|
+
return script.slice(position).find((step) => step.dir === "bridge→provider")
|
|
827
|
+
?.classified.key;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function answerPiModelSelection(live) {
|
|
831
|
+
const { id, key } = live.classified;
|
|
832
|
+
const request = live.message;
|
|
833
|
+
if (key === "get_available_models") {
|
|
834
|
+
emit({
|
|
835
|
+
id,
|
|
836
|
+
type: "response",
|
|
837
|
+
command: key,
|
|
838
|
+
success: true,
|
|
839
|
+
data: { models: [...piModels.values()] },
|
|
840
|
+
});
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
if (key === "set_model") {
|
|
844
|
+
const model = piModels.get(`${request.provider}/${request.modelId}`);
|
|
845
|
+
if (model === undefined) {
|
|
846
|
+
emit({
|
|
847
|
+
id,
|
|
848
|
+
type: "response",
|
|
849
|
+
command: key,
|
|
850
|
+
success: false,
|
|
851
|
+
error: `Model not found: ${request.provider}/${request.modelId}`,
|
|
852
|
+
});
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
piState = { ...(piState ?? {}), model };
|
|
856
|
+
piSelectionProbePending = true;
|
|
857
|
+
emit({ id, type: "response", command: key, success: true, data: model });
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
piState = { ...(piState ?? {}), thinkingLevel: request.level };
|
|
861
|
+
piSelectionProbePending = true;
|
|
862
|
+
emit({ id, type: "response", command: key, success: true });
|
|
863
|
+
}
|
|
864
|
+
|
|
750
865
|
function onLiveMessage(message) {
|
|
751
866
|
const live = { message, classified: dialect.classify(message) };
|
|
752
867
|
if (
|
|
@@ -755,20 +870,32 @@ function main() {
|
|
|
755
870
|
SESSION_DEFINING_KEY.test(live.classified.key)
|
|
756
871
|
) {
|
|
757
872
|
sawSessionDefiningRequest = true;
|
|
758
|
-
if (
|
|
873
|
+
if (
|
|
874
|
+
segmentSessionKey !== null &&
|
|
875
|
+
live.classified.key !== segmentSessionKey
|
|
876
|
+
) {
|
|
759
877
|
releaseSegment(live);
|
|
760
878
|
}
|
|
761
879
|
}
|
|
880
|
+
if (
|
|
881
|
+
args.dialect === "pi-rpc" &&
|
|
882
|
+
live.classified.kind === "request" &&
|
|
883
|
+
PI_MODEL_SELECTION_KEYS.has(live.classified.key) &&
|
|
884
|
+
nextBridgeExpectationKey() !== live.classified.key
|
|
885
|
+
) {
|
|
886
|
+
answerPiModelSelection(live);
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
762
889
|
if (
|
|
763
890
|
args.dialect === "pi-rpc" &&
|
|
764
891
|
live.classified.kind === "request" &&
|
|
765
892
|
live.classified.key === "get_state" &&
|
|
766
|
-
piPromptProbePending &&
|
|
893
|
+
(piPromptProbePending || piSelectionProbePending) &&
|
|
767
894
|
piState !== null &&
|
|
768
|
-
|
|
769
|
-
?.classified.key !== "get_state"
|
|
895
|
+
nextBridgeExpectationKey() !== "get_state"
|
|
770
896
|
) {
|
|
771
897
|
piPromptProbePending = false;
|
|
898
|
+
piSelectionProbePending = false;
|
|
772
899
|
emit({
|
|
773
900
|
id: live.classified.id,
|
|
774
901
|
type: "response",
|