@get-bb/plugin-sdk 0.6.146 → 0.6.150

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.
@@ -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 && /[\\/]/u.test(command)) {
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)
@@ -4564,7 +4564,7 @@ function spawnHostProcess(command, args = [], options = {}) {
4564
4564
  env: launch.env,
4565
4565
  windowsHide: options.windowsHide ?? true
4566
4566
  };
4567
- if (process.platform === "win32" && !options.shell && /[\\/]/u.test(command)) {
4567
+ if (process.platform === "win32" && !options.shell) {
4568
4568
  const parsed = parse(launch.command, launch.args, spawnOptions);
4569
4569
  return observe(
4570
4570
  parsed.file ? nodeSpawn(parsed.command, parsed.args, parsed.options) : nodeSpawn(launch.command, launch.args, spawnOptions)
@@ -4653,6 +4653,40 @@ function terminateWindowsProcessTrees(pids) {
4653
4653
  }
4654
4654
  });
4655
4655
  }
4656
+ var heldProcessHandles = /* @__PURE__ */ new WeakMap();
4657
+ function holdProcessHandle(child) {
4658
+ const handle = Reflect.get(child, "_handle");
4659
+ if (typeof handle !== "object" || handle === null) return () => {
4660
+ };
4661
+ let hold = heldProcessHandles.get(handle);
4662
+ if (hold === void 0) {
4663
+ const close = Reflect.get(handle, "close");
4664
+ if (typeof close !== "function") return () => {
4665
+ };
4666
+ const created = {
4667
+ close: (...args) => Reflect.apply(close, handle, args),
4668
+ holders: 0,
4669
+ deferredArgs: null
4670
+ };
4671
+ Reflect.set(handle, "close", (...args) => {
4672
+ created.deferredArgs = args;
4673
+ });
4674
+ heldProcessHandles.set(handle, created);
4675
+ hold = created;
4676
+ }
4677
+ const held = hold;
4678
+ held.holders += 1;
4679
+ let released = false;
4680
+ return () => {
4681
+ if (released) return;
4682
+ released = true;
4683
+ held.holders -= 1;
4684
+ if (held.holders > 0) return;
4685
+ heldProcessHandles.delete(handle);
4686
+ Reflect.deleteProperty(handle, "close");
4687
+ if (held.deferredArgs !== null) held.close(...held.deferredArgs);
4688
+ };
4689
+ }
4656
4690
  function waitForRootExit(child) {
4657
4691
  if (hasExited(child)) return Promise.resolve();
4658
4692
  return new Promise((resolve2, reject) => {
@@ -4671,7 +4705,13 @@ async function stopWindowsProcessTree(child) {
4671
4705
  if (child.pid === void 0 || hasExited(child)) {
4672
4706
  return { treeTermination: "unverified" };
4673
4707
  }
4674
- const terminated = await terminateWindowsProcessTrees([child.pid]);
4708
+ const releaseHandle = holdProcessHandle(child);
4709
+ let terminated;
4710
+ try {
4711
+ terminated = await terminateWindowsProcessTrees([child.pid]);
4712
+ } finally {
4713
+ releaseHandle();
4714
+ }
4675
4715
  if (!hasExited(child)) child.kill("SIGKILL");
4676
4716
  await waitForRootExit(child);
4677
4717
  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;
@@ -1250,27 +1250,36 @@ function createTaggedKeyedQueryOwner(options) {
1250
1250
  }
1251
1251
  };
1252
1252
  }
1253
- function useQuerySelection(subscribe, getSnapshot, select) {
1254
- const committed = useRef(null);
1255
- const getSelection = useMemo(() => {
1256
- let cached;
1257
- return () => {
1258
- const snapshot = getSnapshot();
1259
- if (cached && Object.is(cached.snapshot, snapshot)) return cached.value;
1260
- cached = {
1261
- snapshot,
1262
- value: replaceEqualDeep3(
1263
- cached?.value ?? committed.current?.value,
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
- }, [getSnapshot, select]);
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.current = { value };
1273
- }, [value]);
1281
+ commitSelection(committed, value);
1282
+ }, [committed, value]);
1274
1283
  return value;
1275
1284
  }
1276
1285
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.146",
3
+ "version": "0.6.150",
4
+ "license": "MIT",
4
5
  "homepage": "https://github.com/get-bb/bb#readme",
5
6
  "bugs": {
6
7
  "url": "https://github.com/get-bb/bb/issues"