@get-bb/plugin-sdk 0.6.146 → 0.6.157
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/LICENSE +21 -0
- package/README.md +4 -1
- package/bundled-types/bb-plugin-sdk-app.d.ts +20 -14
- package/bundled-types/bb-plugin-sdk-testing.d.ts +91 -2
- package/bundled-types/bb-plugin-sdk.d.ts +20 -14
- package/dist/host.js +1 -1
- package/dist/internal/rpc-query-host.js +27 -18
- package/dist/process.js +1 -1
- package/dist/provider-bridge-acp-next.js +1250 -1058
- package/dist/provider-bridge-acp.js +1250 -1058
- package/dist/provider-bridge-testing.js +10 -4
- package/dist/provider-bridge-worker-entry.mjs +9 -3
- package/dist/provider-bridge.js +51 -5
- package/dist/replay-provider-child.mjs +82 -0
- package/dist/testing/app.js +27 -18
- package/dist/testing/index.js +258 -11
- package/package.json +3 -1
|
@@ -6906,7 +6906,7 @@ function spawnHostProcess(command, args = [], options = {}) {
|
|
|
6906
6906
|
env: launch.env,
|
|
6907
6907
|
windowsHide: options.windowsHide ?? true
|
|
6908
6908
|
};
|
|
6909
|
-
if (process.platform === "win32" && !options.shell
|
|
6909
|
+
if (process.platform === "win32" && !options.shell) {
|
|
6910
6910
|
const parsed = parse(launch.command, launch.args, spawnOptions);
|
|
6911
6911
|
return observe(
|
|
6912
6912
|
parsed.file ? nodeSpawn(parsed.command, parsed.args, parsed.options) : nodeSpawn(launch.command, launch.args, spawnOptions)
|
|
@@ -7066,6 +7066,7 @@ function readBoundedLines(args) {
|
|
|
7066
7066
|
const maxLineBytes = args.maxLineBytes ?? MAX_JSON_RPC_LINE_BYTES;
|
|
7067
7067
|
const decoder = new StringDecoder("utf8");
|
|
7068
7068
|
let pending = "";
|
|
7069
|
+
let pendingBytes = 0;
|
|
7069
7070
|
let discarding = false;
|
|
7070
7071
|
let discardedBytes = 0;
|
|
7071
7072
|
args.input.on("data", (chunk) => {
|
|
@@ -7084,18 +7085,22 @@ function readBoundedLines(args) {
|
|
|
7084
7085
|
emit(pending + text.slice(start, newlineIndex));
|
|
7085
7086
|
}
|
|
7086
7087
|
pending = "";
|
|
7088
|
+
pendingBytes = 0;
|
|
7087
7089
|
start = newlineIndex + 1;
|
|
7088
7090
|
}
|
|
7089
7091
|
const tail = text.slice(start);
|
|
7092
|
+
const tailBytes = Buffer.byteLength(tail);
|
|
7090
7093
|
if (discarding) {
|
|
7091
|
-
discardedBytes +=
|
|
7094
|
+
discardedBytes += tailBytes;
|
|
7092
7095
|
return;
|
|
7093
7096
|
}
|
|
7094
7097
|
pending += tail;
|
|
7095
|
-
|
|
7098
|
+
pendingBytes += tailBytes;
|
|
7099
|
+
if (pendingBytes > maxLineBytes) {
|
|
7096
7100
|
discarding = true;
|
|
7097
|
-
discardedBytes =
|
|
7101
|
+
discardedBytes = pendingBytes;
|
|
7098
7102
|
pending = "";
|
|
7103
|
+
pendingBytes = 0;
|
|
7099
7104
|
}
|
|
7100
7105
|
});
|
|
7101
7106
|
args.input.on("end", () => {
|
|
@@ -7103,6 +7108,7 @@ function readBoundedLines(args) {
|
|
|
7103
7108
|
emit(pending);
|
|
7104
7109
|
}
|
|
7105
7110
|
pending = "";
|
|
7111
|
+
pendingBytes = 0;
|
|
7106
7112
|
args.onClose?.();
|
|
7107
7113
|
});
|
|
7108
7114
|
function emit(line) {
|
|
@@ -1266,6 +1266,7 @@ function readBoundedLines(args) {
|
|
|
1266
1266
|
const maxLineBytes = args.maxLineBytes ?? MAX_JSON_RPC_LINE_BYTES;
|
|
1267
1267
|
const decoder = new StringDecoder("utf8");
|
|
1268
1268
|
let pending = "";
|
|
1269
|
+
let pendingBytes = 0;
|
|
1269
1270
|
let discarding = false;
|
|
1270
1271
|
let discardedBytes = 0;
|
|
1271
1272
|
args.input.on("data", (chunk) => {
|
|
@@ -1284,18 +1285,22 @@ function readBoundedLines(args) {
|
|
|
1284
1285
|
emit(pending + text.slice(start, newlineIndex));
|
|
1285
1286
|
}
|
|
1286
1287
|
pending = "";
|
|
1288
|
+
pendingBytes = 0;
|
|
1287
1289
|
start = newlineIndex + 1;
|
|
1288
1290
|
}
|
|
1289
1291
|
const tail = text.slice(start);
|
|
1292
|
+
const tailBytes = Buffer.byteLength(tail);
|
|
1290
1293
|
if (discarding) {
|
|
1291
|
-
discardedBytes +=
|
|
1294
|
+
discardedBytes += tailBytes;
|
|
1292
1295
|
return;
|
|
1293
1296
|
}
|
|
1294
1297
|
pending += tail;
|
|
1295
|
-
|
|
1298
|
+
pendingBytes += tailBytes;
|
|
1299
|
+
if (pendingBytes > maxLineBytes) {
|
|
1296
1300
|
discarding = true;
|
|
1297
|
-
discardedBytes =
|
|
1301
|
+
discardedBytes = pendingBytes;
|
|
1298
1302
|
pending = "";
|
|
1303
|
+
pendingBytes = 0;
|
|
1299
1304
|
}
|
|
1300
1305
|
});
|
|
1301
1306
|
args.input.on("end", () => {
|
|
@@ -1303,6 +1308,7 @@ function readBoundedLines(args) {
|
|
|
1303
1308
|
emit(pending);
|
|
1304
1309
|
}
|
|
1305
1310
|
pending = "";
|
|
1311
|
+
pendingBytes = 0;
|
|
1306
1312
|
args.onClose?.();
|
|
1307
1313
|
});
|
|
1308
1314
|
function emit(line) {
|
package/dist/provider-bridge.js
CHANGED
|
@@ -733,6 +733,7 @@ function readBoundedLines(args) {
|
|
|
733
733
|
const maxLineBytes = args.maxLineBytes ?? MAX_JSON_RPC_LINE_BYTES;
|
|
734
734
|
const decoder = new StringDecoder("utf8");
|
|
735
735
|
let pending = "";
|
|
736
|
+
let pendingBytes = 0;
|
|
736
737
|
let discarding = false;
|
|
737
738
|
let discardedBytes = 0;
|
|
738
739
|
args.input.on("data", (chunk) => {
|
|
@@ -751,18 +752,22 @@ function readBoundedLines(args) {
|
|
|
751
752
|
emit(pending + text.slice(start, newlineIndex));
|
|
752
753
|
}
|
|
753
754
|
pending = "";
|
|
755
|
+
pendingBytes = 0;
|
|
754
756
|
start = newlineIndex + 1;
|
|
755
757
|
}
|
|
756
758
|
const tail = text.slice(start);
|
|
759
|
+
const tailBytes = Buffer.byteLength(tail);
|
|
757
760
|
if (discarding) {
|
|
758
|
-
discardedBytes +=
|
|
761
|
+
discardedBytes += tailBytes;
|
|
759
762
|
return;
|
|
760
763
|
}
|
|
761
764
|
pending += tail;
|
|
762
|
-
|
|
765
|
+
pendingBytes += tailBytes;
|
|
766
|
+
if (pendingBytes > maxLineBytes) {
|
|
763
767
|
discarding = true;
|
|
764
|
-
discardedBytes =
|
|
768
|
+
discardedBytes = pendingBytes;
|
|
765
769
|
pending = "";
|
|
770
|
+
pendingBytes = 0;
|
|
766
771
|
}
|
|
767
772
|
});
|
|
768
773
|
args.input.on("end", () => {
|
|
@@ -770,6 +775,7 @@ function readBoundedLines(args) {
|
|
|
770
775
|
emit(pending);
|
|
771
776
|
}
|
|
772
777
|
pending = "";
|
|
778
|
+
pendingBytes = 0;
|
|
773
779
|
args.onClose?.();
|
|
774
780
|
});
|
|
775
781
|
function emit(line) {
|
|
@@ -4564,7 +4570,7 @@ function spawnHostProcess(command, args = [], options = {}) {
|
|
|
4564
4570
|
env: launch.env,
|
|
4565
4571
|
windowsHide: options.windowsHide ?? true
|
|
4566
4572
|
};
|
|
4567
|
-
if (process.platform === "win32" && !options.shell
|
|
4573
|
+
if (process.platform === "win32" && !options.shell) {
|
|
4568
4574
|
const parsed = parse(launch.command, launch.args, spawnOptions);
|
|
4569
4575
|
return observe(
|
|
4570
4576
|
parsed.file ? nodeSpawn(parsed.command, parsed.args, parsed.options) : nodeSpawn(launch.command, launch.args, spawnOptions)
|
|
@@ -4653,6 +4659,40 @@ function terminateWindowsProcessTrees(pids) {
|
|
|
4653
4659
|
}
|
|
4654
4660
|
});
|
|
4655
4661
|
}
|
|
4662
|
+
var heldProcessHandles = /* @__PURE__ */ new WeakMap();
|
|
4663
|
+
function holdProcessHandle(child) {
|
|
4664
|
+
const handle = Reflect.get(child, "_handle");
|
|
4665
|
+
if (typeof handle !== "object" || handle === null) return () => {
|
|
4666
|
+
};
|
|
4667
|
+
let hold = heldProcessHandles.get(handle);
|
|
4668
|
+
if (hold === void 0) {
|
|
4669
|
+
const close = Reflect.get(handle, "close");
|
|
4670
|
+
if (typeof close !== "function") return () => {
|
|
4671
|
+
};
|
|
4672
|
+
const created = {
|
|
4673
|
+
close: (...args) => Reflect.apply(close, handle, args),
|
|
4674
|
+
holders: 0,
|
|
4675
|
+
deferredArgs: null
|
|
4676
|
+
};
|
|
4677
|
+
Reflect.set(handle, "close", (...args) => {
|
|
4678
|
+
created.deferredArgs = args;
|
|
4679
|
+
});
|
|
4680
|
+
heldProcessHandles.set(handle, created);
|
|
4681
|
+
hold = created;
|
|
4682
|
+
}
|
|
4683
|
+
const held = hold;
|
|
4684
|
+
held.holders += 1;
|
|
4685
|
+
let released = false;
|
|
4686
|
+
return () => {
|
|
4687
|
+
if (released) return;
|
|
4688
|
+
released = true;
|
|
4689
|
+
held.holders -= 1;
|
|
4690
|
+
if (held.holders > 0) return;
|
|
4691
|
+
heldProcessHandles.delete(handle);
|
|
4692
|
+
Reflect.deleteProperty(handle, "close");
|
|
4693
|
+
if (held.deferredArgs !== null) held.close(...held.deferredArgs);
|
|
4694
|
+
};
|
|
4695
|
+
}
|
|
4656
4696
|
function waitForRootExit(child) {
|
|
4657
4697
|
if (hasExited(child)) return Promise.resolve();
|
|
4658
4698
|
return new Promise((resolve2, reject) => {
|
|
@@ -4671,7 +4711,13 @@ async function stopWindowsProcessTree(child) {
|
|
|
4671
4711
|
if (child.pid === void 0 || hasExited(child)) {
|
|
4672
4712
|
return { treeTermination: "unverified" };
|
|
4673
4713
|
}
|
|
4674
|
-
const
|
|
4714
|
+
const releaseHandle = holdProcessHandle(child);
|
|
4715
|
+
let terminated;
|
|
4716
|
+
try {
|
|
4717
|
+
terminated = await terminateWindowsProcessTrees([child.pid]);
|
|
4718
|
+
} finally {
|
|
4719
|
+
releaseHandle();
|
|
4720
|
+
}
|
|
4675
4721
|
if (!hasExited(child)) child.kill("SIGKILL");
|
|
4676
4722
|
await waitForRootExit(child);
|
|
4677
4723
|
return { treeTermination: terminated ? "confirmed" : "unverified" };
|
|
@@ -433,6 +433,15 @@ function main() {
|
|
|
433
433
|
process.stdout.write("0.0.0-replay\n");
|
|
434
434
|
return;
|
|
435
435
|
}
|
|
436
|
+
const apiIndex = process.argv.indexOf("api");
|
|
437
|
+
if (apiIndex !== -1) {
|
|
438
|
+
process.stdout.write(
|
|
439
|
+
process.argv[apiIndex + 1] === "GET"
|
|
440
|
+
? `${JSON.stringify({ data: { permissions: [] } })}\n`
|
|
441
|
+
: "{}\n",
|
|
442
|
+
);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
436
445
|
const args = parseArgs(process.argv.slice(2));
|
|
437
446
|
const dialect = DIALECTS[args.dialect];
|
|
438
447
|
if (!dialect) throw new Error(`unknown dialect ${args.dialect}`);
|
|
@@ -474,6 +483,9 @@ function main() {
|
|
|
474
483
|
let stallTimer = null;
|
|
475
484
|
let lookaheadTimer = null;
|
|
476
485
|
let emitTimer = null;
|
|
486
|
+
let piState = null;
|
|
487
|
+
let piStreaming = false;
|
|
488
|
+
let piPromptProbePending = false;
|
|
477
489
|
|
|
478
490
|
const channel = dialect.channel ?? null;
|
|
479
491
|
const channelSocket = channel ? connectChannel(channel) : null;
|
|
@@ -487,6 +499,22 @@ function main() {
|
|
|
487
499
|
|
|
488
500
|
function emitRecorded(step) {
|
|
489
501
|
const { message, classified } = step;
|
|
502
|
+
if (args.dialect === "pi-rpc") {
|
|
503
|
+
if (
|
|
504
|
+
message.type === "response" &&
|
|
505
|
+
message.command === "get_state" &&
|
|
506
|
+
message.success === true &&
|
|
507
|
+
typeof message.data === "object" &&
|
|
508
|
+
message.data !== null
|
|
509
|
+
) {
|
|
510
|
+
piState = message.data;
|
|
511
|
+
piStreaming = piState?.isStreaming === true;
|
|
512
|
+
} else if (message.type === "agent_start") {
|
|
513
|
+
piStreaming = true;
|
|
514
|
+
} else if (message.type === "agent_end") {
|
|
515
|
+
piStreaming = false;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
490
518
|
if (classified.kind === "response") {
|
|
491
519
|
const liveId = liveIdByRecordedId.get(String(classified.id));
|
|
492
520
|
emit(dialect.withResponseId(message, liveId === undefined ? classified.id : liveId));
|
|
@@ -584,6 +612,27 @@ function main() {
|
|
|
584
612
|
if (live === null) {
|
|
585
613
|
return;
|
|
586
614
|
}
|
|
615
|
+
if (args.dialect === "pi-rpc" && step.classified.key === "get_state") {
|
|
616
|
+
piPromptProbePending = false;
|
|
617
|
+
}
|
|
618
|
+
if (args.dialect === "pi-rpc" && step.classified.key === "prompt") {
|
|
619
|
+
piPromptProbePending = live.message.streamingBehavior !== "steer";
|
|
620
|
+
for (let index = position + 1; index < script.length; index += 1) {
|
|
621
|
+
const next = script[index];
|
|
622
|
+
if (
|
|
623
|
+
next.dir === "bridge→provider" &&
|
|
624
|
+
next.classified.key === "prompt"
|
|
625
|
+
)
|
|
626
|
+
break;
|
|
627
|
+
if (
|
|
628
|
+
next.dir === "provider→bridge" &&
|
|
629
|
+
next.message?.type === "agent_start"
|
|
630
|
+
) {
|
|
631
|
+
piStreaming = true;
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
587
636
|
if (step.classified.kind === "request") {
|
|
588
637
|
liveIdByRecordedId.set(String(step.classified.id), live.classified.id);
|
|
589
638
|
if (dialect.isInitialize(step.classified) && args.dialect === "claude-cli") {
|
|
@@ -602,6 +651,10 @@ function main() {
|
|
|
602
651
|
*/
|
|
603
652
|
function lookAhead() {
|
|
604
653
|
lookaheadTimer = null;
|
|
654
|
+
if (emitTimer !== null) {
|
|
655
|
+
lookaheadTimer = setTimeout(lookAhead, CURSOR_POLL_MS);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
605
658
|
for (const live of pendingLive) {
|
|
606
659
|
for (let index = position + 1; index < script.length; index += 1) {
|
|
607
660
|
const step = script[index];
|
|
@@ -612,6 +665,16 @@ function main() {
|
|
|
612
665
|
? String(step.classified.id) === String(live.classified.id)
|
|
613
666
|
: step.classified.key === live.classified.key);
|
|
614
667
|
if (!same) continue;
|
|
668
|
+
const cursor = readCursor(args.state);
|
|
669
|
+
const gated = script.slice(position, index).some((between) =>
|
|
670
|
+
between.dir === "provider→bridge" &&
|
|
671
|
+
between.classified.kind !== "response" &&
|
|
672
|
+
!cursorAllows(cursor, between),
|
|
673
|
+
);
|
|
674
|
+
if (gated) {
|
|
675
|
+
lookaheadTimer = setTimeout(lookAhead, CURSOR_POLL_MS);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
615
678
|
const skipped = [];
|
|
616
679
|
for (let cursor = position; cursor < index; cursor += 1) {
|
|
617
680
|
const between = script[cursor];
|
|
@@ -696,6 +759,25 @@ function main() {
|
|
|
696
759
|
releaseSegment(live);
|
|
697
760
|
}
|
|
698
761
|
}
|
|
762
|
+
if (
|
|
763
|
+
args.dialect === "pi-rpc" &&
|
|
764
|
+
live.classified.kind === "request" &&
|
|
765
|
+
live.classified.key === "get_state" &&
|
|
766
|
+
piPromptProbePending &&
|
|
767
|
+
piState !== null &&
|
|
768
|
+
script.slice(position).find((step) => step.dir === "bridge→provider")
|
|
769
|
+
?.classified.key !== "get_state"
|
|
770
|
+
) {
|
|
771
|
+
piPromptProbePending = false;
|
|
772
|
+
emit({
|
|
773
|
+
id: live.classified.id,
|
|
774
|
+
type: "response",
|
|
775
|
+
command: "get_state",
|
|
776
|
+
success: true,
|
|
777
|
+
data: { ...piState, isStreaming: piStreaming },
|
|
778
|
+
});
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
699
781
|
if (position >= script.length) {
|
|
700
782
|
answerGenerically(live, "past end of segment");
|
|
701
783
|
return;
|
package/dist/testing/app.js
CHANGED
|
@@ -1250,27 +1250,36 @@ function createTaggedKeyedQueryOwner(options) {
|
|
|
1250
1250
|
}
|
|
1251
1251
|
};
|
|
1252
1252
|
}
|
|
1253
|
-
function
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
select(snapshot)
|
|
1265
|
-
)
|
|
1266
|
-
};
|
|
1267
|
-
return cached.value;
|
|
1253
|
+
function createSelectionGetter(getSnapshot, select, committed) {
|
|
1254
|
+
let cached;
|
|
1255
|
+
return () => {
|
|
1256
|
+
const snapshot = getSnapshot();
|
|
1257
|
+
if (cached && Object.is(cached.snapshot, snapshot)) return cached.value;
|
|
1258
|
+
cached = {
|
|
1259
|
+
snapshot,
|
|
1260
|
+
value: replaceEqualDeep3(
|
|
1261
|
+
cached?.value ?? committed.current,
|
|
1262
|
+
select(snapshot)
|
|
1263
|
+
)
|
|
1268
1264
|
};
|
|
1269
|
-
|
|
1265
|
+
return cached.value;
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
function commitSelection(committed, value) {
|
|
1269
|
+
committed.current = value;
|
|
1270
|
+
}
|
|
1271
|
+
function useQuerySelection(subscribe, getSnapshot, select) {
|
|
1272
|
+
const [committed] = useState(() => ({
|
|
1273
|
+
current: void 0
|
|
1274
|
+
}));
|
|
1275
|
+
const getSelection = useMemo(
|
|
1276
|
+
() => createSelectionGetter(getSnapshot, select, committed),
|
|
1277
|
+
[committed, getSnapshot, select]
|
|
1278
|
+
);
|
|
1270
1279
|
const value = useSyncExternalStore(subscribe, getSelection, getSelection);
|
|
1271
1280
|
useEffect(() => {
|
|
1272
|
-
committed
|
|
1273
|
-
}, [value]);
|
|
1281
|
+
commitSelection(committed, value);
|
|
1282
|
+
}, [committed, value]);
|
|
1274
1283
|
return value;
|
|
1275
1284
|
}
|
|
1276
1285
|
|