@get-bb/plugin-sdk 0.6.144 → 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
 
@@ -1278,7 +1287,7 @@ function useQuerySelection(subscribe, getSnapshot, select) {
1278
1287
  import { QueryClient } from "@tanstack/react-query";
1279
1288
 
1280
1289
  // src/internal/rpc-query-host.ts
1281
- import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
1290
+ import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
1282
1291
  import { useIsFetching } from "@tanstack/react-query";
1283
1292
 
1284
1293
  // ../domain/src/shared-types.ts
@@ -2381,6 +2390,17 @@ var tagsOf = (data) => [
2381
2390
  ...data.tags,
2382
2391
  ...Object.values(data.keyTags).flat()
2383
2392
  ];
2393
+ function useParsedRpcInput(input) {
2394
+ const identity = JSON.stringify(input ?? null);
2395
+ const [parsed, setParsed] = useState2(() => ({
2396
+ identity,
2397
+ value: jsonValueSchema.parse(input ?? null)
2398
+ }));
2399
+ if (parsed.identity === identity) return parsed.value;
2400
+ const next = { identity, value: jsonValueSchema.parse(input ?? null) };
2401
+ setParsed(next);
2402
+ return next.value;
2403
+ }
2384
2404
  var owners = /* @__PURE__ */ new WeakMap();
2385
2405
  function createRpcQueryHooks(useHost) {
2386
2406
  function useSubscription(host, pluginId, enabled) {
@@ -2392,8 +2412,11 @@ function createRpcQueryHooks(useHost) {
2392
2412
  const experimental_useRpcQuery = (options) => {
2393
2413
  const host = useHost();
2394
2414
  const pluginId = resolvePluginId(host, options.pluginId);
2395
- const input = jsonValueSchema.parse(options.input ?? null);
2396
- const queryKey = rpcQueryKey(pluginId, options.method, input);
2415
+ const input = useParsedRpcInput(options.input);
2416
+ const queryKey = useMemo2(
2417
+ () => rpcQueryKey(pluginId, options.method, input),
2418
+ [input, options.method, pluginId]
2419
+ );
2397
2420
  useSubscription(host, pluginId, options.enabled ?? true);
2398
2421
  const watchIdentity = canonicalPluginReadInput(input);
2399
2422
  useEffect2(() => {
@@ -2418,18 +2441,24 @@ function createRpcQueryHooks(useHost) {
2418
2441
  },
2419
2442
  host.queryClient
2420
2443
  );
2421
- return {
2422
- data: query.data?.result,
2423
- error: query.error === null ? null : experimental_PluginRpcCallError.from(
2424
- query.error,
2444
+ const { refetch: refetchQuery, error: queryError } = query;
2445
+ const refetch = useCallback2(async () => {
2446
+ await refetchQuery();
2447
+ }, [refetchQuery]);
2448
+ const error = useMemo2(
2449
+ () => queryError === null ? null : experimental_PluginRpcCallError.from(
2450
+ queryError,
2425
2451
  "invalid_response"
2426
2452
  ),
2427
- isLoading: (options.enabled ?? true) && query.isLoading,
2428
- isFetching: query.isFetching,
2429
- refetch: async () => {
2430
- await query.refetch();
2431
- }
2432
- };
2453
+ [queryError]
2454
+ );
2455
+ const data = query.data?.result;
2456
+ const isLoading = (options.enabled ?? true) && query.isLoading;
2457
+ const isFetching = query.isFetching;
2458
+ return useMemo2(
2459
+ () => ({ data, error, isLoading, isFetching, refetch }),
2460
+ [data, error, isFetching, isLoading, refetch]
2461
+ );
2433
2462
  };
2434
2463
  function experimental_useRpcKeyedQuery(options) {
2435
2464
  const host = useHost();
@@ -2535,11 +2564,14 @@ function createRpcQueryHooks(useHost) {
2535
2564
  },
2536
2565
  [current, keys]
2537
2566
  );
2538
- return {
2539
- ...query,
2540
- refetch,
2541
- refetchKeys
2542
- };
2567
+ return useMemo2(
2568
+ () => ({
2569
+ ...query,
2570
+ refetch,
2571
+ refetchKeys
2572
+ }),
2573
+ [query, refetch, refetchKeys]
2574
+ );
2543
2575
  }
2544
2576
  function experimental_useRpcMutation(options) {
2545
2577
  const host = useHost();
@@ -2621,7 +2653,7 @@ import {
2621
2653
  useEffect as useEffect3,
2622
2654
  useMemo as useMemo3,
2623
2655
  useRef as useRef3,
2624
- useState as useState2,
2656
+ useState as useState3,
2625
2657
  useSyncExternalStore as useSyncExternalStore2
2626
2658
  } from "react";
2627
2659
  import { act, render } from "@testing-library/react";
@@ -4969,7 +5001,7 @@ function useTestMenuOpenState({
4969
5001
  onOpenChange,
4970
5002
  onCloseAutoFocus
4971
5003
  }) {
4972
- const [open, setOpen] = useState2(false);
5004
+ const [open, setOpen] = useState3(false);
4973
5005
  return {
4974
5006
  open,
4975
5007
  show: () => {
@@ -5237,7 +5269,7 @@ function TestNewThreadComposer({
5237
5269
  draftKey,
5238
5270
  onSubmit
5239
5271
  }) {
5240
- const [text, setText] = useState2(initialPrompt ?? "");
5272
+ const [text, setText] = useState3(initialPrompt ?? "");
5241
5273
  return /* @__PURE__ */ jsxs(
5242
5274
  "div",
5243
5275
  {
@@ -5297,7 +5329,7 @@ function TestProviderModelPicker({
5297
5329
  disabled,
5298
5330
  className
5299
5331
  }) {
5300
- const [draft, setDraft] = useState2(value);
5332
+ const [draft, setDraft] = useState3(value);
5301
5333
  const { providerId, model, reasoningLevel, serviceTier } = value;
5302
5334
  useEffect3(
5303
5335
  () => setDraft({
@@ -5574,7 +5606,10 @@ function TestVoiceInputTextarea({
5574
5606
  }
5575
5607
  );
5576
5608
  }
5577
- function TestFilePreview({ target, renderPreview }) {
5609
+ function TestFilePreview({
5610
+ target,
5611
+ renderPreview
5612
+ }) {
5578
5613
  const file = useSlotEnv("experimental_FilePreview").filePreview(target);
5579
5614
  return /* @__PURE__ */ jsx("div", { "data-testid": "bb-file-preview", "data-path": target.path, children: file === null ? null : renderPreview(file) });
5580
5615
  }
@@ -5991,18 +6026,23 @@ var testPluginSdkApp = {
5991
6026
  experimental_SidebarNavigationIcon: TestSidebarNavigationIcon,
5992
6027
  experimental_useSidebarThreadSplit(threadId) {
5993
6028
  const env = useSlotEnv("experimental_useSidebarThreadSplit");
5994
- return useMemo3(
5995
- () => ({
6029
+ return useMemo3(() => {
6030
+ const panes = env.sidebarSplitLayout?.panes.map((pane) => ({
6031
+ paneId: pane.paneId,
6032
+ rect: pane.rect,
6033
+ isMe: pane.threadId === threadId,
6034
+ isFocused: pane.isFocused
6035
+ })) ?? [];
6036
+ return {
5996
6037
  splitProps: {
5997
6038
  onPointerDown: () => {
5998
6039
  env.sidebarActionCalls.push({ method: "open", threadId });
5999
6040
  }
6000
6041
  },
6001
6042
  isAvailable: true,
6002
- layout: null
6003
- }),
6004
- [env, threadId]
6005
- );
6043
+ layout: panes.some((pane) => pane.isMe) ? { panes } : null
6044
+ };
6045
+ }, [env, threadId]);
6006
6046
  },
6007
6047
  useSidebarThreadDraft(threadId) {
6008
6048
  const env = useSlotEnv("useSidebarThreadDraft");
@@ -3641,7 +3641,8 @@ function createFakePluginHostInternal(options, sharedState) {
3641
3641
  method: String(method),
3642
3642
  input: validatedInput,
3643
3643
  hostId: callOptions.hostId,
3644
- ...callOptions.signal === void 0 ? {} : { signal: callOptions.signal }
3644
+ ...callOptions.signal === void 0 ? {} : { signal: callOptions.signal },
3645
+ ...callOptions.timeoutMs === void 0 ? {} : { timeoutMs: callOptions.timeoutMs }
3645
3646
  };
3646
3647
  hostRpcCalls.push(call);
3647
3648
  if (options.experimental_callHostRpc === void 0) {
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.144",
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"