@get-bb/plugin-sdk 0.6.19 → 0.6.26
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/bundled-types/bb-plugin-sdk-app.d.ts +428 -20
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +1 -0
- package/bundled-types/bb-plugin-sdk.d.ts +426 -19
- package/dist/app.js +4 -0
- package/dist/provider-bridge-acp.js +15 -9
- package/dist/provider-bridge-testing.js +306 -248
- package/dist/testing/app.js +22 -1
- package/package.json +1 -1
package/dist/app.js
CHANGED
|
@@ -50,6 +50,9 @@ var UrlLink = runtimeComponent("UrlLink");
|
|
|
50
50
|
var experimental_NewThreadComposer = runtimeComponent(
|
|
51
51
|
"experimental_NewThreadComposer"
|
|
52
52
|
);
|
|
53
|
+
var experimental_VoiceInputTextarea = runtimeComponent(
|
|
54
|
+
"experimental_VoiceInputTextarea"
|
|
55
|
+
);
|
|
53
56
|
var experimental_ProviderModelPicker = runtimeComponent(
|
|
54
57
|
"experimental_ProviderModelPicker"
|
|
55
58
|
);
|
|
@@ -154,6 +157,7 @@ export {
|
|
|
154
157
|
experimental_ProviderModelPicker,
|
|
155
158
|
experimental_SidebarNavigationIcon,
|
|
156
159
|
experimental_SourceCode,
|
|
160
|
+
experimental_VoiceInputTextarea,
|
|
157
161
|
experimental_useAppPanel,
|
|
158
162
|
experimental_useBranches,
|
|
159
163
|
experimental_useCheckoutState,
|
|
@@ -15976,7 +15976,7 @@ function resolveBridgeProcessEnvForMcpServer() {
|
|
|
15976
15976
|
}
|
|
15977
15977
|
async function forwardDynamicToolCall(args, signal) {
|
|
15978
15978
|
const session = sessionsByBbThreadId.get(args.threadId);
|
|
15979
|
-
if (!session || !session.providerThreadId || session.stopping) {
|
|
15979
|
+
if (!session || !session.providerThreadId || session.stopping || session.connection.exited) {
|
|
15980
15980
|
return { ok: false, error: "No active ACP session for dynamic tool call." };
|
|
15981
15981
|
}
|
|
15982
15982
|
const controller = new AbortController();
|
|
@@ -16984,8 +16984,8 @@ async function startAgentSession(request) {
|
|
|
16984
16984
|
onExit: (info) => {
|
|
16985
16985
|
const wasCurrent = sessionsByBbThreadId.get(bbThreadId) === session;
|
|
16986
16986
|
cancelPendingPermissions(session);
|
|
16987
|
-
removeSession(session);
|
|
16988
16987
|
if (!wasCurrent || session.stopping || session.providerThreadId === "") {
|
|
16988
|
+
removeSession(session);
|
|
16989
16989
|
return;
|
|
16990
16990
|
}
|
|
16991
16991
|
void releaseCursorMcpApproval(session);
|
|
@@ -16993,6 +16993,7 @@ async function startAgentSession(request) {
|
|
|
16993
16993
|
session,
|
|
16994
16994
|
`ACP agent "${agentLabel}" exited unexpectedly${info.code !== null ? ` (code ${info.code})` : ""}${info.stderrTail ? `: ${info.stderrTail}` : ""}`
|
|
16995
16995
|
);
|
|
16996
|
+
session.activePromptKind = null;
|
|
16996
16997
|
}
|
|
16997
16998
|
});
|
|
16998
16999
|
session = {
|
|
@@ -17353,11 +17354,16 @@ function runTurn(session, firstInput) {
|
|
|
17353
17354
|
"ACP turn failed before the steer was sent"
|
|
17354
17355
|
);
|
|
17355
17356
|
session.cancelRequested = false;
|
|
17356
|
-
if (!session.stopping
|
|
17357
|
-
|
|
17358
|
-
|
|
17359
|
-
|
|
17360
|
-
)
|
|
17357
|
+
if (!session.stopping) {
|
|
17358
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17359
|
+
if (!session.connection.exited) {
|
|
17360
|
+
emitSessionError(session, message);
|
|
17361
|
+
} else if (session.activePromptKind === "turn") {
|
|
17362
|
+
emitForSession(session, "error", {
|
|
17363
|
+
threadId: session.bbThreadId,
|
|
17364
|
+
message
|
|
17365
|
+
});
|
|
17366
|
+
}
|
|
17361
17367
|
}
|
|
17362
17368
|
session.activePromptKind = null;
|
|
17363
17369
|
return;
|
|
@@ -17403,7 +17409,7 @@ function reconcileExecutionSettings(session, options) {
|
|
|
17403
17409
|
construction.permissionMode
|
|
17404
17410
|
)
|
|
17405
17411
|
);
|
|
17406
|
-
const restart = session.restartAfterCancelError || launchArgsChanged || !isDeepStrictEqual(envVars ?? {}, session.construction.envVars ?? {});
|
|
17412
|
+
const restart = session.connection.exited || session.restartAfterCancelError || launchArgsChanged || !isDeepStrictEqual(envVars ?? {}, session.construction.envVars ?? {});
|
|
17407
17413
|
cancelPendingPermissions(session);
|
|
17408
17414
|
session.policy = {
|
|
17409
17415
|
permissionMode: options.permissionMode,
|
|
@@ -17417,7 +17423,7 @@ function reconcileExecutionSettings(session, options) {
|
|
|
17417
17423
|
}
|
|
17418
17424
|
async function rebuildAgentSession(session, construction) {
|
|
17419
17425
|
const previousProviderThreadId = session.providerThreadId;
|
|
17420
|
-
const reason = session.restartAfterCancelError ? "The ACP agent failed during cancellation; its session was rebuilt before continuing." : "Execution settings changed; the ACP session was rebuilt to apply them.";
|
|
17426
|
+
const reason = session.connection.exited ? "The ACP agent exited unexpectedly; its session was rebuilt before continuing." : session.restartAfterCancelError ? "The ACP agent failed during cancellation; its session was rebuilt before continuing." : "Execution settings changed; the ACP session was rebuilt to apply them.";
|
|
17421
17427
|
const queuedInputs = session.queuedInputs.splice(0);
|
|
17422
17428
|
const continuingTurn = session.activePromptKind === "turn";
|
|
17423
17429
|
finishTurn(session, "cancelled");
|
|
@@ -6540,6 +6540,26 @@ var PARITY_INITIALIZE_ID = "parity-initialize";
|
|
|
6540
6540
|
function sleep(ms) {
|
|
6541
6541
|
return new Promise((resolveSleep) => setTimeout(resolveSleep, ms));
|
|
6542
6542
|
}
|
|
6543
|
+
var REPLAY_STARTUP_CONCURRENCY = 4;
|
|
6544
|
+
var replayStartupQueue = [];
|
|
6545
|
+
var startingReplays = 0;
|
|
6546
|
+
async function acquireReplayStartup() {
|
|
6547
|
+
if (startingReplays < REPLAY_STARTUP_CONCURRENCY) {
|
|
6548
|
+
startingReplays += 1;
|
|
6549
|
+
} else {
|
|
6550
|
+
await new Promise(
|
|
6551
|
+
(resolveSlot) => replayStartupQueue.push(resolveSlot)
|
|
6552
|
+
);
|
|
6553
|
+
}
|
|
6554
|
+
let released = false;
|
|
6555
|
+
return () => {
|
|
6556
|
+
if (released) return;
|
|
6557
|
+
released = true;
|
|
6558
|
+
const next = replayStartupQueue.shift();
|
|
6559
|
+
if (next === void 0) startingReplays -= 1;
|
|
6560
|
+
else next();
|
|
6561
|
+
};
|
|
6562
|
+
}
|
|
6543
6563
|
async function replayRecording(options) {
|
|
6544
6564
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
6545
6565
|
const orderTimeoutMs = options.orderTimeoutMs ?? 5e3;
|
|
@@ -6582,275 +6602,313 @@ async function replayRecording(options) {
|
|
|
6582
6602
|
);
|
|
6583
6603
|
profile.prepareState?.({ recording, stateDir, workspaceDir });
|
|
6584
6604
|
const launch = options.bridge;
|
|
6585
|
-
const
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
6593
|
-
});
|
|
6594
|
-
const recordedCwd = recordedWorkspaceDir(recording);
|
|
6595
|
-
const jsonText = (value) => JSON.stringify(value).slice(1, -1);
|
|
6596
|
-
const restoreRecordedWorkspace = (line) => recordedCwd === null || recordedCwd === workspaceDir ? line : line.split(jsonText(workspaceDir)).join(jsonText(recordedCwd));
|
|
6597
|
-
const initializeId = PARITY_INITIALIZE_ID;
|
|
6598
|
-
const startedAt = Date.now();
|
|
6599
|
-
const lines = [];
|
|
6600
|
-
const lineTimes = [];
|
|
6601
|
-
const lineAfter = [];
|
|
6602
|
-
let lastSentRuntimeEntry = null;
|
|
6603
|
-
const events = [];
|
|
6604
|
-
const grammarViolations = [];
|
|
6605
|
-
const stalls = [];
|
|
6606
|
-
let stderr = "";
|
|
6607
|
-
const grammar = new ThreadEventGrammar();
|
|
6608
|
-
const liveAssembler = options.createAssembler(providerId);
|
|
6609
|
-
const planAssembler = (options.createPlanAssembler ?? options.createAssembler)(providerId);
|
|
6610
|
-
const exactPlan = options.planFromCurrentLane === true;
|
|
6611
|
-
const planRecording = exactPlan ? withCurrentBridgeLane(recording) : recording;
|
|
6612
|
-
const steps = planRuntimeSteps(planRecording, planAssembler);
|
|
6613
|
-
const plannedEventCount = exactPlan ? assembleRecordedEvents(
|
|
6614
|
-
planRecording,
|
|
6615
|
-
options.createPlanAssembler ?? options.createAssembler,
|
|
6616
|
-
providerId
|
|
6617
|
-
).events.length : null;
|
|
6618
|
-
const answeredIds = /* @__PURE__ */ new Set();
|
|
6619
|
-
const pendingBridgeRequests = [];
|
|
6620
|
-
const recordedAnswers = /* @__PURE__ */ new Map();
|
|
6621
|
-
for (const step of steps) {
|
|
6622
|
-
if (step.message !== null && isResponse(step.message)) {
|
|
6623
|
-
const method = methodOfRecordedBridgeRequest(
|
|
6624
|
-
recording,
|
|
6625
|
-
step.entry,
|
|
6626
|
-
step.message.id
|
|
6627
|
-
) ?? "?";
|
|
6628
|
-
const queue = recordedAnswers.get(method) ?? [];
|
|
6629
|
-
queue.push(step.message);
|
|
6630
|
-
recordedAnswers.set(method, queue);
|
|
6631
|
-
}
|
|
6632
|
-
}
|
|
6633
|
-
let lastOutputAt = Date.now();
|
|
6634
|
-
const exited = new Promise((resolveExit) => {
|
|
6635
|
-
child.on("exit", (code) => resolveExit(code));
|
|
6636
|
-
});
|
|
6637
|
-
child.stderr?.setEncoding("utf8").on("data", (chunk) => {
|
|
6638
|
-
stderr += chunk;
|
|
6639
|
-
options.onStderr?.(chunk);
|
|
6640
|
-
});
|
|
6641
|
-
function write(line) {
|
|
6642
|
-
if (child.stdin?.writable) {
|
|
6643
|
-
child.stdin.write(`${line}
|
|
6605
|
+
const releaseStartup = await acquireReplayStartup();
|
|
6606
|
+
let spawnedChild;
|
|
6607
|
+
let childEnded;
|
|
6608
|
+
try {
|
|
6609
|
+
let write2 = function(line) {
|
|
6610
|
+
if (child.stdin?.writable) {
|
|
6611
|
+
child.stdin.write(`${line}
|
|
6644
6612
|
`);
|
|
6645
|
-
}
|
|
6646
|
-
}
|
|
6647
|
-
function answerBridgeRequest(message) {
|
|
6648
|
-
const method = message.method ?? "?";
|
|
6649
|
-
const queue = recordedAnswers.get(method);
|
|
6650
|
-
const recorded = queue?.shift();
|
|
6651
|
-
if (recorded === void 0) {
|
|
6652
|
-
stalls.push(
|
|
6653
|
-
`no recorded answer for bridge request ${method} (${String(message.id)})`
|
|
6654
|
-
);
|
|
6655
|
-
write(
|
|
6656
|
-
JSON.stringify({
|
|
6657
|
-
jsonrpc: "2.0",
|
|
6658
|
-
id: message.id,
|
|
6659
|
-
error: { code: -32e3, message: "parity replay: no recorded answer" }
|
|
6660
|
-
})
|
|
6661
|
-
);
|
|
6662
|
-
return;
|
|
6663
|
-
}
|
|
6664
|
-
write(JSON.stringify({ ...recorded, id: message.id }));
|
|
6665
|
-
}
|
|
6666
|
-
readBoundedLines({
|
|
6667
|
-
input: child.stdout,
|
|
6668
|
-
onLine: (rawLine) => {
|
|
6669
|
-
const line = restoreRecordedWorkspace(rawLine);
|
|
6670
|
-
lastOutputAt = Date.now();
|
|
6671
|
-
lines.push(line);
|
|
6672
|
-
lineTimes.push(lastOutputAt - startedAt);
|
|
6673
|
-
lineAfter.push(lastSentRuntimeEntry);
|
|
6674
|
-
const message = parseWire(line);
|
|
6675
|
-
if (message === null) return;
|
|
6676
|
-
if (isResponse(message)) {
|
|
6677
|
-
answeredIds.add(String(message.id));
|
|
6678
|
-
return;
|
|
6679
6613
|
}
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6614
|
+
}, answerBridgeRequest2 = function(message) {
|
|
6615
|
+
const method = message.method ?? "?";
|
|
6616
|
+
const queue = recordedAnswers.get(method);
|
|
6617
|
+
const recorded = queue?.shift();
|
|
6618
|
+
if (recorded === void 0) {
|
|
6619
|
+
stalls.push(
|
|
6620
|
+
`no recorded answer for bridge request ${method} (${String(message.id)})`
|
|
6621
|
+
);
|
|
6622
|
+
write2(
|
|
6623
|
+
JSON.stringify({
|
|
6624
|
+
jsonrpc: "2.0",
|
|
6625
|
+
id: message.id,
|
|
6626
|
+
error: {
|
|
6627
|
+
code: -32e3,
|
|
6628
|
+
message: "parity replay: no recorded answer"
|
|
6629
|
+
}
|
|
6630
|
+
})
|
|
6631
|
+
);
|
|
6686
6632
|
return;
|
|
6687
6633
|
}
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6634
|
+
write2(JSON.stringify({ ...recorded, id: message.id }));
|
|
6635
|
+
};
|
|
6636
|
+
var write = write2, answerBridgeRequest = answerBridgeRequest2;
|
|
6637
|
+
const child = spawn(launch.command, launch.args, {
|
|
6638
|
+
cwd: launch.cwd,
|
|
6639
|
+
env: {
|
|
6640
|
+
...process.env,
|
|
6641
|
+
...launch.env,
|
|
6642
|
+
...profile.env({ replayCommand, wrapperPath, stateDir })
|
|
6643
|
+
},
|
|
6644
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
6645
|
+
});
|
|
6646
|
+
spawnedChild = child;
|
|
6647
|
+
childEnded = new Promise((resolveEnded) => {
|
|
6648
|
+
const onEnded = () => {
|
|
6649
|
+
releaseStartup();
|
|
6650
|
+
resolveEnded();
|
|
6651
|
+
};
|
|
6652
|
+
child.once("exit", onEnded);
|
|
6653
|
+
child.once("error", onEnded);
|
|
6654
|
+
});
|
|
6655
|
+
const recordedCwd = recordedWorkspaceDir(recording);
|
|
6656
|
+
const jsonText = (value) => JSON.stringify(value).slice(1, -1);
|
|
6657
|
+
const restoreRecordedWorkspace = (line) => recordedCwd === null || recordedCwd === workspaceDir ? line : line.split(jsonText(workspaceDir)).join(jsonText(recordedCwd));
|
|
6658
|
+
const initializeId = PARITY_INITIALIZE_ID;
|
|
6659
|
+
const startedAt = Date.now();
|
|
6660
|
+
const lines = [];
|
|
6661
|
+
const lineTimes = [];
|
|
6662
|
+
const lineAfter = [];
|
|
6663
|
+
let lastSentRuntimeEntry = null;
|
|
6664
|
+
const events = [];
|
|
6665
|
+
const grammarViolations = [];
|
|
6666
|
+
const stalls = [];
|
|
6667
|
+
let stderr = "";
|
|
6668
|
+
const grammar = new ThreadEventGrammar();
|
|
6669
|
+
const liveAssembler = options.createAssembler(providerId);
|
|
6670
|
+
const planAssembler = (options.createPlanAssembler ?? options.createAssembler)(providerId);
|
|
6671
|
+
const exactPlan = options.planFromCurrentLane === true;
|
|
6672
|
+
const planRecording = exactPlan ? withCurrentBridgeLane(recording) : recording;
|
|
6673
|
+
const steps = planRuntimeSteps(planRecording, planAssembler);
|
|
6674
|
+
const plannedEventCount = exactPlan ? assembleRecordedEvents(
|
|
6675
|
+
planRecording,
|
|
6676
|
+
options.createPlanAssembler ?? options.createAssembler,
|
|
6677
|
+
providerId
|
|
6678
|
+
).events.length : null;
|
|
6679
|
+
const answeredIds = /* @__PURE__ */ new Set();
|
|
6680
|
+
const pendingBridgeRequests = [];
|
|
6681
|
+
const recordedAnswers = /* @__PURE__ */ new Map();
|
|
6682
|
+
for (const step of steps) {
|
|
6683
|
+
if (step.message !== null && isResponse(step.message)) {
|
|
6684
|
+
const method = methodOfRecordedBridgeRequest(
|
|
6685
|
+
recording,
|
|
6686
|
+
step.entry,
|
|
6687
|
+
step.message.id
|
|
6688
|
+
) ?? "?";
|
|
6689
|
+
const queue = recordedAnswers.get(method) ?? [];
|
|
6690
|
+
queue.push(step.message);
|
|
6691
|
+
recordedAnswers.set(method, queue);
|
|
6692
|
+
}
|
|
6693
|
+
}
|
|
6694
|
+
let lastOutputAt = Date.now();
|
|
6695
|
+
const exited = new Promise((resolveExit) => {
|
|
6696
|
+
child.on("exit", (code) => resolveExit(code));
|
|
6697
|
+
child.on("error", (error) => {
|
|
6698
|
+
stalls.push(`bridge spawn failed: ${error.message}`);
|
|
6699
|
+
resolveExit(null);
|
|
6700
|
+
});
|
|
6701
|
+
});
|
|
6702
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => {
|
|
6703
|
+
stderr += chunk;
|
|
6704
|
+
options.onStderr?.(chunk);
|
|
6705
|
+
});
|
|
6706
|
+
readBoundedLines({
|
|
6707
|
+
input: child.stdout,
|
|
6708
|
+
onLine: (rawLine) => {
|
|
6709
|
+
const line = restoreRecordedWorkspace(rawLine);
|
|
6710
|
+
lastOutputAt = Date.now();
|
|
6711
|
+
lines.push(line);
|
|
6712
|
+
lineTimes.push(lastOutputAt - startedAt);
|
|
6713
|
+
lineAfter.push(lastSentRuntimeEntry);
|
|
6714
|
+
const message = parseWire(line);
|
|
6715
|
+
if (message === null) return;
|
|
6716
|
+
if (isResponse(message)) {
|
|
6717
|
+
answeredIds.add(String(message.id));
|
|
6696
6718
|
return;
|
|
6697
6719
|
}
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6720
|
+
if (isRequest(message)) {
|
|
6721
|
+
pendingBridgeRequests.push({
|
|
6722
|
+
id: message.id,
|
|
6723
|
+
method: message.method
|
|
6724
|
+
});
|
|
6725
|
+
answerBridgeRequest2(message);
|
|
6726
|
+
return;
|
|
6727
|
+
}
|
|
6728
|
+
if (message.method === THREAD_DELTA_NOTIFICATION_METHOD) {
|
|
6729
|
+
let assembled;
|
|
6730
|
+
try {
|
|
6731
|
+
assembled = liveAssembler.assembleMessage(message);
|
|
6732
|
+
} catch (error) {
|
|
6733
|
+
stalls.push(
|
|
6734
|
+
`invalid thread/delta: ${error instanceof Error ? error.message : String(error)}`
|
|
6735
|
+
);
|
|
6736
|
+
return;
|
|
6737
|
+
}
|
|
6738
|
+
for (const event of assembled) {
|
|
6739
|
+
const result2 = grammar.observe(event);
|
|
6740
|
+
if (result2.kind === "violation") {
|
|
6741
|
+
grammarViolations.push({
|
|
6742
|
+
rule: result2.rule,
|
|
6743
|
+
reason: result2.reason,
|
|
6744
|
+
eventType: event.type
|
|
6745
|
+
});
|
|
6746
|
+
continue;
|
|
6747
|
+
}
|
|
6748
|
+
events.push(event);
|
|
6707
6749
|
}
|
|
6708
|
-
events.push(event);
|
|
6709
6750
|
}
|
|
6751
|
+
},
|
|
6752
|
+
onOverflow: (bytes) => {
|
|
6753
|
+
stalls.push(`oversized bridge line (${bytes} bytes)`);
|
|
6710
6754
|
}
|
|
6711
|
-
}
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
if (reportStall) stalls.push(`timed out waiting for ${label}`);
|
|
6725
|
-
return;
|
|
6755
|
+
});
|
|
6756
|
+
async function waitFor(label, predicate, limitMs = timeoutMs, reportStall = true) {
|
|
6757
|
+
const deadline = Date.now() + limitMs;
|
|
6758
|
+
while (!predicate()) {
|
|
6759
|
+
if (child.exitCode !== null || child.signalCode !== null || child.pid === void 0) {
|
|
6760
|
+
stalls.push(`bridge exited while waiting for ${label}`);
|
|
6761
|
+
return;
|
|
6762
|
+
}
|
|
6763
|
+
if (Date.now() > deadline) {
|
|
6764
|
+
if (reportStall) stalls.push(`timed out waiting for ${label}`);
|
|
6765
|
+
return;
|
|
6766
|
+
}
|
|
6767
|
+
await sleep(10);
|
|
6726
6768
|
}
|
|
6727
|
-
await sleep(10);
|
|
6728
6769
|
}
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6770
|
+
const firstStep = steps.find(
|
|
6771
|
+
(step) => step.message !== null && isRequest(step.message)
|
|
6772
|
+
);
|
|
6773
|
+
setCursor(
|
|
6774
|
+
firstStep === void 0 ? "end" : { run: firstStep.entry.run, seq: firstStep.entry.seq }
|
|
6775
|
+
);
|
|
6776
|
+
write2(
|
|
6777
|
+
JSON.stringify({
|
|
6778
|
+
jsonrpc: "2.0",
|
|
6779
|
+
id: initializeId,
|
|
6780
|
+
method: "initialize",
|
|
6781
|
+
params: {
|
|
6782
|
+
protocolVersion: PROVIDER_BRIDGE_PROTOCOL_VERSION,
|
|
6783
|
+
client: { name: "bb-parity", version: "0" }
|
|
6784
|
+
}
|
|
6785
|
+
})
|
|
6786
|
+
);
|
|
6787
|
+
await waitFor("initialize response", () => answeredIds.has(initializeId));
|
|
6788
|
+
const initialized = answeredIds.has(initializeId);
|
|
6789
|
+
if (!initialized) {
|
|
6790
|
+
if (child.pid !== void 0 && child.exitCode === null && child.signalCode === null)
|
|
6791
|
+
child.kill("SIGKILL");
|
|
6792
|
+
await childEnded;
|
|
6793
|
+
}
|
|
6794
|
+
releaseStartup();
|
|
6795
|
+
const sentRequestIds = [];
|
|
6796
|
+
for (const step of initialized ? steps : []) {
|
|
6797
|
+
if (step.message === null || !isRequest(step.message)) {
|
|
6798
|
+
if (step.message !== null && !isResponse(step.message)) {
|
|
6799
|
+
lastSentRuntimeEntry = {
|
|
6800
|
+
run: step.entry.run,
|
|
6801
|
+
seq: step.entry.seq,
|
|
6802
|
+
ts: step.entry.ts
|
|
6803
|
+
};
|
|
6804
|
+
write2(step.entry.line);
|
|
6805
|
+
}
|
|
6806
|
+
continue;
|
|
6744
6807
|
}
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
}
|
|
6757
|
-
|
|
6808
|
+
const request = step.message;
|
|
6809
|
+
const method = request.method;
|
|
6810
|
+
await waitFor(
|
|
6811
|
+
`earlier requests before ${method}`,
|
|
6812
|
+
() => sentRequestIds.every((id) => answeredIds.has(id))
|
|
6813
|
+
);
|
|
6814
|
+
await waitFor(
|
|
6815
|
+
`${step.gate.started} turn/started and ${step.gate.completed} turn/completed before ${method}`,
|
|
6816
|
+
() => {
|
|
6817
|
+
const live = countTurns(events);
|
|
6818
|
+
return live.started >= step.gate.started && live.completed >= step.gate.completed;
|
|
6819
|
+
}
|
|
6820
|
+
);
|
|
6821
|
+
await waitFor(
|
|
6822
|
+
`${step.eventsBefore} events before ${method}`,
|
|
6823
|
+
() => events.length >= step.eventsBefore || !exactPlan && Date.now() - lastOutputAt >= orderTimeoutMs,
|
|
6824
|
+
timeoutMs,
|
|
6825
|
+
exactPlan
|
|
6826
|
+
);
|
|
6827
|
+
await waitFor(
|
|
6828
|
+
`the stream to drain before ${method}`,
|
|
6829
|
+
() => Date.now() - lastOutputAt >= drainMs,
|
|
6830
|
+
timeoutMs,
|
|
6831
|
+
false
|
|
6832
|
+
);
|
|
6833
|
+
if (child.exitCode !== null) break;
|
|
6834
|
+
if (method === "thread/stop" && typeof request.params === "object" && request.params !== null && request.params.intent === "release") {
|
|
6835
|
+
const threadId = request.params.threadId;
|
|
6836
|
+
if (typeof threadId === "string") grammar.clearThread(threadId);
|
|
6758
6837
|
}
|
|
6759
|
-
|
|
6838
|
+
const rewritten = rewriteRecordedMachineFacts(
|
|
6839
|
+
step.entry.line,
|
|
6840
|
+
workspaceDir
|
|
6841
|
+
);
|
|
6842
|
+
const line = profile.rewriteRuntimeLine === void 0 ? rewritten : profile.rewriteRuntimeLine(rewritten, { replayCommand });
|
|
6843
|
+
lastSentRuntimeEntry = {
|
|
6844
|
+
run: step.entry.run,
|
|
6845
|
+
seq: step.entry.seq,
|
|
6846
|
+
ts: step.entry.ts
|
|
6847
|
+
};
|
|
6848
|
+
write2(line);
|
|
6849
|
+
sentRequestIds.push(String(request.id));
|
|
6850
|
+
const nextStep = steps.slice(steps.indexOf(step) + 1).find(
|
|
6851
|
+
(candidate) => candidate.message !== null && isRequest(candidate.message)
|
|
6852
|
+
);
|
|
6853
|
+
setCursor(
|
|
6854
|
+
nextStep === void 0 ? "end" : { run: nextStep.entry.run, seq: nextStep.entry.seq }
|
|
6855
|
+
);
|
|
6760
6856
|
}
|
|
6761
|
-
|
|
6762
|
-
const method = request.method;
|
|
6857
|
+
setCursor("end");
|
|
6763
6858
|
await waitFor(
|
|
6764
|
-
|
|
6859
|
+
"the last responses",
|
|
6765
6860
|
() => sentRequestIds.every((id) => answeredIds.has(id))
|
|
6766
6861
|
);
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
}
|
|
6773
|
-
);
|
|
6774
|
-
await waitFor(
|
|
6775
|
-
`${step.eventsBefore} events before ${method}`,
|
|
6776
|
-
() => events.length >= step.eventsBefore || !exactPlan && Date.now() - lastOutputAt >= orderTimeoutMs,
|
|
6777
|
-
timeoutMs,
|
|
6778
|
-
exactPlan
|
|
6779
|
-
);
|
|
6780
|
-
await waitFor(
|
|
6781
|
-
`the stream to drain before ${method}`,
|
|
6782
|
-
() => Date.now() - lastOutputAt >= drainMs,
|
|
6783
|
-
timeoutMs,
|
|
6784
|
-
false
|
|
6785
|
-
);
|
|
6786
|
-
if (child.exitCode !== null) break;
|
|
6787
|
-
if (method === "thread/stop" && typeof request.params === "object" && request.params !== null && request.params.intent === "release") {
|
|
6788
|
-
const threadId = request.params.threadId;
|
|
6789
|
-
if (typeof threadId === "string") grammar.clearThread(threadId);
|
|
6862
|
+
if (plannedEventCount !== null) {
|
|
6863
|
+
await waitFor(
|
|
6864
|
+
`all ${plannedEventCount} planned events before closing the bridge`,
|
|
6865
|
+
() => events.length >= plannedEventCount
|
|
6866
|
+
);
|
|
6790
6867
|
}
|
|
6791
|
-
const rewritten = rewriteRecordedMachineFacts(
|
|
6792
|
-
step.entry.line,
|
|
6793
|
-
workspaceDir
|
|
6794
|
-
);
|
|
6795
|
-
const line = profile.rewriteRuntimeLine === void 0 ? rewritten : profile.rewriteRuntimeLine(rewritten, { replayCommand });
|
|
6796
|
-
lastSentRuntimeEntry = {
|
|
6797
|
-
run: step.entry.run,
|
|
6798
|
-
seq: step.entry.seq,
|
|
6799
|
-
ts: step.entry.ts
|
|
6800
|
-
};
|
|
6801
|
-
write(line);
|
|
6802
|
-
sentRequestIds.push(String(request.id));
|
|
6803
|
-
const nextStep = steps.slice(steps.indexOf(step) + 1).find(
|
|
6804
|
-
(candidate) => candidate.message !== null && isRequest(candidate.message)
|
|
6805
|
-
);
|
|
6806
|
-
setCursor(
|
|
6807
|
-
nextStep === void 0 ? "end" : { run: nextStep.entry.run, seq: nextStep.entry.seq }
|
|
6808
|
-
);
|
|
6809
|
-
}
|
|
6810
|
-
setCursor("end");
|
|
6811
|
-
await waitFor(
|
|
6812
|
-
"the last responses",
|
|
6813
|
-
() => sentRequestIds.every((id) => answeredIds.has(id))
|
|
6814
|
-
);
|
|
6815
|
-
if (plannedEventCount !== null) {
|
|
6816
6868
|
await waitFor(
|
|
6817
|
-
|
|
6818
|
-
() =>
|
|
6869
|
+
"the stream to settle",
|
|
6870
|
+
() => Date.now() - lastOutputAt >= settleMs
|
|
6819
6871
|
);
|
|
6872
|
+
child.stdin?.end();
|
|
6873
|
+
let shutdownTimer;
|
|
6874
|
+
const exitCode = await Promise.race([
|
|
6875
|
+
exited,
|
|
6876
|
+
new Promise((resolveTimeout) => {
|
|
6877
|
+
shutdownTimer = setTimeout(() => {
|
|
6878
|
+
stalls.push("bridge did not exit after stdin closed; killed");
|
|
6879
|
+
child.kill("SIGKILL");
|
|
6880
|
+
resolveTimeout(null);
|
|
6881
|
+
}, timeoutMs);
|
|
6882
|
+
})
|
|
6883
|
+
]);
|
|
6884
|
+
clearTimeout(shutdownTimer);
|
|
6885
|
+
return {
|
|
6886
|
+
providerId,
|
|
6887
|
+
recordingDir: options.recordingDir,
|
|
6888
|
+
lines,
|
|
6889
|
+
lineTimes,
|
|
6890
|
+
lineAfter,
|
|
6891
|
+
events,
|
|
6892
|
+
grammarViolations,
|
|
6893
|
+
stalls,
|
|
6894
|
+
stderr,
|
|
6895
|
+
exitCode
|
|
6896
|
+
};
|
|
6897
|
+
} finally {
|
|
6898
|
+
if (spawnedChild !== void 0 && spawnedChild.pid !== void 0 && spawnedChild.exitCode === null && spawnedChild.signalCode === null) {
|
|
6899
|
+
spawnedChild.kill("SIGKILL");
|
|
6900
|
+
await childEnded;
|
|
6901
|
+
}
|
|
6902
|
+
releaseStartup();
|
|
6903
|
+
for (const directory of [stateDir, workspaceDir]) {
|
|
6904
|
+
await rm(directory, {
|
|
6905
|
+
force: true,
|
|
6906
|
+
maxRetries: REPLAY_CLEANUP_RETRIES,
|
|
6907
|
+
recursive: true,
|
|
6908
|
+
retryDelay: REPLAY_CLEANUP_RETRY_DELAY_MS
|
|
6909
|
+
});
|
|
6910
|
+
}
|
|
6820
6911
|
}
|
|
6821
|
-
await waitFor(
|
|
6822
|
-
"the stream to settle",
|
|
6823
|
-
() => Date.now() - lastOutputAt >= settleMs
|
|
6824
|
-
);
|
|
6825
|
-
child.stdin?.end();
|
|
6826
|
-
const exitCode = await Promise.race([
|
|
6827
|
-
exited,
|
|
6828
|
-
sleep(timeoutMs).then(() => {
|
|
6829
|
-
stalls.push("bridge did not exit after stdin closed; killed");
|
|
6830
|
-
child.kill("SIGKILL");
|
|
6831
|
-
return null;
|
|
6832
|
-
})
|
|
6833
|
-
]);
|
|
6834
|
-
for (const directory of [stateDir, workspaceDir]) {
|
|
6835
|
-
await rm(directory, {
|
|
6836
|
-
force: true,
|
|
6837
|
-
maxRetries: REPLAY_CLEANUP_RETRIES,
|
|
6838
|
-
recursive: true,
|
|
6839
|
-
retryDelay: REPLAY_CLEANUP_RETRY_DELAY_MS
|
|
6840
|
-
});
|
|
6841
|
-
}
|
|
6842
|
-
return {
|
|
6843
|
-
providerId,
|
|
6844
|
-
recordingDir: options.recordingDir,
|
|
6845
|
-
lines,
|
|
6846
|
-
lineTimes,
|
|
6847
|
-
lineAfter,
|
|
6848
|
-
events,
|
|
6849
|
-
grammarViolations,
|
|
6850
|
-
stalls,
|
|
6851
|
-
stderr,
|
|
6852
|
-
exitCode
|
|
6853
|
-
};
|
|
6854
6912
|
}
|
|
6855
6913
|
function assembleRecordedEvents(recording, createAssembler, providerId) {
|
|
6856
6914
|
const assembler = createAssembler(providerId);
|