@get-bb/plugin-sdk 0.6.150 → 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/README.md CHANGED
@@ -106,7 +106,10 @@ a React slot. The host supplies `{ pluginId, generation, signal }`, awaits
106
106
  mount setup, and owns abort plus exact-once reverse-order disposal across hash
107
107
  reload, disable, removal, failed replacement, and app-window teardown. The old
108
108
  generation is disposed before candidate mounts, so generations never overlap.
109
- Content scripts are trusted same-origin page code, not a sandbox.
109
+ When the page unloads, the host aborts and cleans up content scripts but leaves
110
+ slot components mounted for the browser to discard, so React effect cleanups do
111
+ not run at unload. Save state as it changes, or flush it from a content script
112
+ cleanup. Content scripts are trusted same-origin page code, not a sandbox.
110
113
 
111
114
  Static styles should stay in the normal imported `app.css`. The host keeps
112
115
  that stylesheet active while the plugin has rendered slot, panel-header, or
@@ -151,6 +151,7 @@ declare const appSettingsSchema: z$1.ZodObject<{
151
151
  flat: "flat";
152
152
  }>>;
153
153
  providerOrder: z$1.ZodArray<z$1.ZodString>;
154
+ resumeThreadsAfterRestart: z$1.ZodBoolean;
154
155
  showDiagnosticEvents: z$1.ZodBoolean;
155
156
  showKeyboardHints: z$1.ZodBoolean;
156
157
  steerActiveThreadOnEnter: z$1.ZodBoolean;
@@ -177,6 +178,7 @@ declare const appSettingsUpdateSchema: z$1.ZodUnion<readonly [z$1.ZodObject<{
177
178
  flat: "flat";
178
179
  }>>;
179
180
  providerOrder: z$1.ZodArray<z$1.ZodString>;
181
+ resumeThreadsAfterRestart: z$1.ZodOptional<z$1.ZodBoolean>;
180
182
  showDiagnosticEvents: z$1.ZodBoolean;
181
183
  showKeyboardHints: z$1.ZodBoolean;
182
184
  showUnhandledProviderEvents: z$1.ZodOptional<z$1.ZodBoolean>;
@@ -202,6 +204,7 @@ declare const appSettingsUpdateSchema: z$1.ZodUnion<readonly [z$1.ZodObject<{
202
204
  flat: "flat";
203
205
  }>>;
204
206
  providerOrder: z$1.ZodArray<z$1.ZodString>;
207
+ resumeThreadsAfterRestart: z$1.ZodOptional<z$1.ZodBoolean>;
205
208
  showKeyboardHints: z$1.ZodBoolean;
206
209
  showUnhandledProviderEvents: z$1.ZodBoolean;
207
210
  steerActiveThreadOnEnter: z$1.ZodBoolean;
@@ -610,32 +613,26 @@ type Environment = z$1.infer<typeof environmentSchema>;
610
613
  declare const experimentsSchema: z$1.ZodRecord<z$1.ZodEnum<{
611
614
  agentCpuPriority: "agentCpuPriority";
612
615
  compactExpiredCache: "compactExpiredCache";
613
- dismissReadNotifications: "dismissReadNotifications";
614
616
  keyedPluginCss: "keyedPluginCss";
615
617
  performanceDiagnostics: "performanceDiagnostics";
616
618
  pluginUpdates: "pluginUpdates";
617
- resumeThreadsAfterRestart: "resumeThreadsAfterRestart";
619
+ resumeDaemonSessions: "resumeDaemonSessions";
618
620
  serverMove: "serverMove";
619
621
  skipFocusedThreadNotifications: "skipFocusedThreadNotifications";
620
622
  threadContextCard: "threadContextCard";
621
- threadRowMetadata: "threadRowMetadata";
622
- updateWhenIdle: "updateWhenIdle";
623
623
  walCheckpointWorker: "walCheckpointWorker";
624
624
  }>, z$1.ZodBoolean>;
625
625
  type Experiments = z$1.infer<typeof experimentsSchema>;
626
626
  declare const experimentUpdatesSchema: z$1.ZodRecord<z$1.ZodEnum<{
627
627
  agentCpuPriority: "agentCpuPriority";
628
628
  compactExpiredCache: "compactExpiredCache";
629
- dismissReadNotifications: "dismissReadNotifications";
630
629
  keyedPluginCss: "keyedPluginCss";
631
630
  performanceDiagnostics: "performanceDiagnostics";
632
631
  pluginUpdates: "pluginUpdates";
633
- resumeThreadsAfterRestart: "resumeThreadsAfterRestart";
632
+ resumeDaemonSessions: "resumeDaemonSessions";
634
633
  serverMove: "serverMove";
635
634
  skipFocusedThreadNotifications: "skipFocusedThreadNotifications";
636
635
  threadContextCard: "threadContextCard";
637
- threadRowMetadata: "threadRowMetadata";
638
- updateWhenIdle: "updateWhenIdle";
639
636
  walCheckpointWorker: "walCheckpointWorker";
640
637
  }> & z$1.core.$partial, z$1.ZodBoolean>;
641
638
  type ExperimentUpdates = z$1.infer<typeof experimentUpdatesSchema>;
@@ -7657,6 +7654,7 @@ declare const hostDaemonCommandRegistry: {
7657
7654
  equal: "equal";
7658
7655
  unknown: "unknown";
7659
7656
  }>>;
7657
+ defaultWorktreeBaseBranch: z$1.ZodNullable<z$1.ZodString>;
7660
7658
  hasUncommittedChanges: z$1.ZodBoolean;
7661
7659
  isWorktree: z$1.ZodBoolean;
7662
7660
  operation: z$1.ZodDiscriminatedUnion<[z$1.ZodObject<{
@@ -10721,16 +10719,13 @@ declare const systemConfigResponseSchema: z$1.ZodObject<{
10721
10719
  experiments: z$1.ZodRecord<z$1.ZodEnum<{
10722
10720
  agentCpuPriority: "agentCpuPriority";
10723
10721
  compactExpiredCache: "compactExpiredCache";
10724
- dismissReadNotifications: "dismissReadNotifications";
10725
10722
  keyedPluginCss: "keyedPluginCss";
10726
10723
  performanceDiagnostics: "performanceDiagnostics";
10727
10724
  pluginUpdates: "pluginUpdates";
10728
- resumeThreadsAfterRestart: "resumeThreadsAfterRestart";
10725
+ resumeDaemonSessions: "resumeDaemonSessions";
10729
10726
  serverMove: "serverMove";
10730
10727
  skipFocusedThreadNotifications: "skipFocusedThreadNotifications";
10731
10728
  threadContextCard: "threadContextCard";
10732
- threadRowMetadata: "threadRowMetadata";
10733
- updateWhenIdle: "updateWhenIdle";
10734
10729
  walCheckpointWorker: "walCheckpointWorker";
10735
10730
  }>, z$1.ZodBoolean>;
10736
10731
  featureFlags: z$1.ZodObject<{
@@ -10755,6 +10750,7 @@ declare const systemConfigResponseSchema: z$1.ZodObject<{
10755
10750
  flat: "flat";
10756
10751
  }>>;
10757
10752
  providerOrder: z$1.ZodArray<z$1.ZodString>;
10753
+ resumeThreadsAfterRestart: z$1.ZodBoolean;
10758
10754
  showDiagnosticEvents: z$1.ZodBoolean;
10759
10755
  showKeyboardHints: z$1.ZodBoolean;
10760
10756
  showUnhandledProviderEvents: z$1.ZodOptional<z$1.ZodBoolean>;
@@ -21119,8 +21115,7 @@ interface ExperimentalThreadRowMetadataDataInput {
21119
21115
  /**
21120
21116
  * A small item on a thread row's metadata line, under the title: a badge, not
21121
21117
  * a control. Items share one line, left to right, and the line clips at the
21122
- * row's edge. bb's sidebar draws the line only while the `threadRowMetadata`
21123
- * experiment is on and the user turns on Organize → Rows → Metadata, and only
21118
+ * row's edge. bb's sidebar draws the line when the user turns on Organize → Rows → Metadata, and only
21124
21119
  * on rows where an item shows something.
21125
21120
  * Load the line's data in `useData`, a React hook bb calls once for the
21126
21121
  * whole app while any list draws a metadata line, never per row; it
@@ -7,6 +7,7 @@
7
7
 
8
8
  import { StandardSchemaV1 as StandardSchemaV1$1, StandardSchemaV1InferOutput as StandardSchemaV1InferOutput$1, PluginMachineValidateDecision, JsonValue as JsonValue$2, PluginEnvironmentProviderRequirements as PluginEnvironmentProviderRequirements$1, PluginEnvironmentValidateDecision, BbPluginApi, PluginSettingValue as PluginSettingValue$1, PluginSharedPortTunnelIdentity, PluginRowPresentation, PluginAgentToolContext, PluginAgentToolResult, PluginCliCommandInfo, PluginCliContext, PluginCliResult, PluginHttpAuthMode, PluginHttpHandler, PluginMentionTrigger, PluginMentionSearchContext, PluginMentionItem, PluginMentionProviderRegistration, ExperimentalPluginRpcCaller, PluginCliExecutionResult, PluginThreadEventName, PluginThreadEventPayloads, PluginAgentConfigurationContext, ExperimentalPluginProviderEnvContext, ExperimentalPluginProviderEnvEntry, ExperimentalPluginProviderEnvHealthContext, ExperimentalPluginProviderEnvHealth, PluginSettingDescriptors, ExperimentalPluginWebSocketHandler, PluginAgentConfiguration, PluginHookName, PluginHookHandler, PluginAiServiceDeclaration, InternalDoNotUsePluginNextTunnelConfig, InternalDoNotUsePluginHostNextTunnelStatus, PluginInteractionRequest, ExperimentalPanelController, MessageDispatchHookContext } from '@get-bb/plugin-sdk';
9
9
  import { z } from 'zod';
10
+ import { ChildProcess } from 'node:child_process';
10
11
 
11
12
  type PluginMachineProviderResource = Exclude<JsonValue$2, null>;
12
13
  type PluginMachineProviderInputsSchema = StandardSchemaV1$1 | undefined;
@@ -1603,5 +1604,93 @@ interface PublicSdkOnlyScan {
1603
1604
  */
1604
1605
  declare function scanPublicSdkOnly(packageRoot: string, options?: PublicSdkOnlyScanOptions): PublicSdkOnlyScan;
1605
1606
 
1606
- export { PluginContextStaleError, createFakePluginHost, createFakeSdk, makePanelController as experimental_makePanelController, scanPublicSdkOnly as experimental_scanPublicSdkOnly, makeHostResponse, makeMessageDispatchHookContext, makePluginAgentConfigurationContext, makeQueueEntry, makeThreadResponse, makeTurnFailedEvent };
1607
- export type { CreateFakePluginHostOptions, ExperimentalFakeHostRpcCall, FakeAgentToolRecord, FakeCliRecord, FakeHttpRouteRecord, FakeLogEntry, FakeLogLevel, FakeMentionProviderRecord, FakePluginBehaviorDrivers, FakePluginHarness, FakePluginHost, FakePluginInspectionState, FakePluginLifecycleControls, FakePluginRegistrations, FakeRealtimeSignal, FakeScheduleRecord, FakeSdkCall, FakeSdkHarness, FakeSdkOverrides, FakeServiceRecord, InternalDoNotUseFakeTunnelIngress, PublicSdkOnlyScan, PublicSdkOnlyScanOptions, PublicSdkOnlyViolation };
1607
+ interface ChildProcessTracker {
1608
+ readonly children: readonly ChildProcess[];
1609
+ running(): ChildProcess[];
1610
+ waitForExit(): Promise<void>;
1611
+ waitForClose(): Promise<void>;
1612
+ killRunning(signal?: NodeJS.Signals): void;
1613
+ dispose(): void;
1614
+ [Symbol.dispose](): void;
1615
+ }
1616
+ interface LifelineHolder {
1617
+ readonly label: string;
1618
+ readonly pid: number;
1619
+ readonly exited: Promise<void>;
1620
+ alive(): boolean;
1621
+ kill(signal?: NodeJS.Signals): boolean;
1622
+ }
1623
+ interface ProcessLifeline {
1624
+ readonly path: string;
1625
+ readonly holders: readonly LifelineHolder[];
1626
+ holdSource(label: string, onHeld?: string): string;
1627
+ waitForHolders(count: number): Promise<readonly LifelineHolder[]>;
1628
+ close(): Promise<void>;
1629
+ }
1630
+ interface DescendantPipe {
1631
+ readonly path: string;
1632
+ readonly opened: Promise<void>;
1633
+ readonly closed: Promise<void>;
1634
+ dispose(): Promise<void>;
1635
+ }
1636
+
1637
+ /**
1638
+ * Every `ChildProcess` spawned anywhere in this process (Node's
1639
+ * `child_process` diagnostics channel) after tracking starts. `children` lists
1640
+ * them in spawn order; `running()` excludes those with an exit code or signal;
1641
+ * `waitForExit()` resolves once all have exited, including any spawned while
1642
+ * waiting; `waitForClose()` also waits for each child's stdio to close, which
1643
+ * an unread piped stream can delay indefinitely; `killRunning()` signals the ones still running (SIGKILL by default);
1644
+ * `dispose()` stops recording.
1645
+ */
1646
+ type ExperimentalChildProcessTracker = ChildProcessTracker;
1647
+ /**
1648
+ * A process connected to a lifeline. `pid` is the PID it reported, `label` the
1649
+ * label passed to `holdSource`. `exited` resolves and `alive()` turns false when
1650
+ * its connection closes, which the operating system does when it exits.
1651
+ * `kill(signal)` sends a signal (SIGKILL by default) only while the connection
1652
+ * is open, so a recycled PID is never signalled; it returns whether it sent.
1653
+ */
1654
+ type ExperimentalLifelineHolder = LifelineHolder;
1655
+ /**
1656
+ * A local socket (a named pipe on Windows), at `path`, that processes the test
1657
+ * did not spawn itself connect to. `holdSource(label, onHeld?)` is a JavaScript
1658
+ * statement, with the path embedded, that connects the Node process running it;
1659
+ * embed it in a descendant's script. The optional `onHeld` statement runs once
1660
+ * the lifeline has registered the holder, for a script that blocks next.
1661
+ * `holders` lists connected processes in connection order, and
1662
+ * `waitForHolders(count)` resolves once that many have connected. `close()`
1663
+ * kills holders still connected, waits for them to exit, and removes the
1664
+ * socket.
1665
+ */
1666
+ type ExperimentalProcessLifeline = ProcessLifeline;
1667
+ /**
1668
+ * Starts recording the child processes this process spawns, so a test can
1669
+ * assert that a process exited from its `ChildProcess` state instead of probing
1670
+ * a PID the operating system may have reused. Experimental: see
1671
+ * docs/api_to_audit.md.
1672
+ */
1673
+ declare function experimental_trackChildProcesses(): ExperimentalChildProcessTracker;
1674
+ /**
1675
+ * Creates a lifeline for observing descendants and other processes the test
1676
+ * did not spawn, by the lifetime of a connection they hold rather than by PID.
1677
+ * Experimental: see docs/api_to_audit.md.
1678
+ */
1679
+ declare function experimental_createProcessLifeline(): Promise<ExperimentalProcessLifeline>;
1680
+ /**
1681
+ * A POSIX named pipe at `path` for shell descendants that cannot run Node:
1682
+ * redirect one into it (`sleep 60 > "$pipe" &`). `opened` resolves once a
1683
+ * descendant has opened it for writing, and `closed` once every process holding
1684
+ * it has exited. `dispose()` releases a reader no descendant opened and removes
1685
+ * the pipe.
1686
+ */
1687
+ type ExperimentalDescendantPipe = DescendantPipe;
1688
+ /**
1689
+ * Creates a named pipe that observes shell descendants by the lifetime of the
1690
+ * write end they inherit, with no startup cost of its own. POSIX only; it
1691
+ * throws on Windows. Experimental: see docs/api_to_audit.md.
1692
+ */
1693
+ declare function experimental_createDescendantPipe(): Promise<ExperimentalDescendantPipe>;
1694
+
1695
+ export { PluginContextStaleError, createFakePluginHost, createFakeSdk, experimental_createDescendantPipe, experimental_createProcessLifeline, makePanelController as experimental_makePanelController, scanPublicSdkOnly as experimental_scanPublicSdkOnly, experimental_trackChildProcesses, makeHostResponse, makeMessageDispatchHookContext, makePluginAgentConfigurationContext, makeQueueEntry, makeThreadResponse, makeTurnFailedEvent };
1696
+ export type { CreateFakePluginHostOptions, ExperimentalChildProcessTracker, ExperimentalDescendantPipe, ExperimentalFakeHostRpcCall, ExperimentalLifelineHolder, ExperimentalProcessLifeline, FakeAgentToolRecord, FakeCliRecord, FakeHttpRouteRecord, FakeLogEntry, FakeLogLevel, FakeMentionProviderRecord, FakePluginBehaviorDrivers, FakePluginHarness, FakePluginHost, FakePluginInspectionState, FakePluginLifecycleControls, FakePluginRegistrations, FakeRealtimeSignal, FakeScheduleRecord, FakeSdkCall, FakeSdkHarness, FakeSdkOverrides, FakeServiceRecord, InternalDoNotUseFakeTunnelIngress, PublicSdkOnlyScan, PublicSdkOnlyScanOptions, PublicSdkOnlyViolation };
@@ -236,6 +236,7 @@ declare const appSettingsSchema: z$1.ZodObject<{
236
236
  flat: "flat";
237
237
  }>>;
238
238
  providerOrder: z$1.ZodArray<z$1.ZodString>;
239
+ resumeThreadsAfterRestart: z$1.ZodBoolean;
239
240
  showDiagnosticEvents: z$1.ZodBoolean;
240
241
  showKeyboardHints: z$1.ZodBoolean;
241
242
  steerActiveThreadOnEnter: z$1.ZodBoolean;
@@ -262,6 +263,7 @@ declare const appSettingsUpdateSchema: z$1.ZodUnion<readonly [z$1.ZodObject<{
262
263
  flat: "flat";
263
264
  }>>;
264
265
  providerOrder: z$1.ZodArray<z$1.ZodString>;
266
+ resumeThreadsAfterRestart: z$1.ZodOptional<z$1.ZodBoolean>;
265
267
  showDiagnosticEvents: z$1.ZodBoolean;
266
268
  showKeyboardHints: z$1.ZodBoolean;
267
269
  showUnhandledProviderEvents: z$1.ZodOptional<z$1.ZodBoolean>;
@@ -287,6 +289,7 @@ declare const appSettingsUpdateSchema: z$1.ZodUnion<readonly [z$1.ZodObject<{
287
289
  flat: "flat";
288
290
  }>>;
289
291
  providerOrder: z$1.ZodArray<z$1.ZodString>;
292
+ resumeThreadsAfterRestart: z$1.ZodOptional<z$1.ZodBoolean>;
290
293
  showKeyboardHints: z$1.ZodBoolean;
291
294
  showUnhandledProviderEvents: z$1.ZodBoolean;
292
295
  steerActiveThreadOnEnter: z$1.ZodBoolean;
@@ -701,32 +704,26 @@ type Environment = z$1.infer<typeof environmentSchema>;
701
704
  declare const experimentsSchema: z$1.ZodRecord<z$1.ZodEnum<{
702
705
  agentCpuPriority: "agentCpuPriority";
703
706
  compactExpiredCache: "compactExpiredCache";
704
- dismissReadNotifications: "dismissReadNotifications";
705
707
  keyedPluginCss: "keyedPluginCss";
706
708
  performanceDiagnostics: "performanceDiagnostics";
707
709
  pluginUpdates: "pluginUpdates";
708
- resumeThreadsAfterRestart: "resumeThreadsAfterRestart";
710
+ resumeDaemonSessions: "resumeDaemonSessions";
709
711
  serverMove: "serverMove";
710
712
  skipFocusedThreadNotifications: "skipFocusedThreadNotifications";
711
713
  threadContextCard: "threadContextCard";
712
- threadRowMetadata: "threadRowMetadata";
713
- updateWhenIdle: "updateWhenIdle";
714
714
  walCheckpointWorker: "walCheckpointWorker";
715
715
  }>, z$1.ZodBoolean>;
716
716
  type Experiments = z$1.infer<typeof experimentsSchema>;
717
717
  declare const experimentUpdatesSchema: z$1.ZodRecord<z$1.ZodEnum<{
718
718
  agentCpuPriority: "agentCpuPriority";
719
719
  compactExpiredCache: "compactExpiredCache";
720
- dismissReadNotifications: "dismissReadNotifications";
721
720
  keyedPluginCss: "keyedPluginCss";
722
721
  performanceDiagnostics: "performanceDiagnostics";
723
722
  pluginUpdates: "pluginUpdates";
724
- resumeThreadsAfterRestart: "resumeThreadsAfterRestart";
723
+ resumeDaemonSessions: "resumeDaemonSessions";
725
724
  serverMove: "serverMove";
726
725
  skipFocusedThreadNotifications: "skipFocusedThreadNotifications";
727
726
  threadContextCard: "threadContextCard";
728
- threadRowMetadata: "threadRowMetadata";
729
- updateWhenIdle: "updateWhenIdle";
730
727
  walCheckpointWorker: "walCheckpointWorker";
731
728
  }> & z$1.core.$partial, z$1.ZodBoolean>;
732
729
  type ExperimentUpdates = z$1.infer<typeof experimentUpdatesSchema>;
@@ -7872,6 +7869,7 @@ declare const hostDaemonCommandRegistry: {
7872
7869
  equal: "equal";
7873
7870
  unknown: "unknown";
7874
7871
  }>>;
7872
+ defaultWorktreeBaseBranch: z$1.ZodNullable<z$1.ZodString>;
7875
7873
  hasUncommittedChanges: z$1.ZodBoolean;
7876
7874
  isWorktree: z$1.ZodBoolean;
7877
7875
  operation: z$1.ZodDiscriminatedUnion<[z$1.ZodObject<{
@@ -10936,16 +10934,13 @@ declare const systemConfigResponseSchema: z$1.ZodObject<{
10936
10934
  experiments: z$1.ZodRecord<z$1.ZodEnum<{
10937
10935
  agentCpuPriority: "agentCpuPriority";
10938
10936
  compactExpiredCache: "compactExpiredCache";
10939
- dismissReadNotifications: "dismissReadNotifications";
10940
10937
  keyedPluginCss: "keyedPluginCss";
10941
10938
  performanceDiagnostics: "performanceDiagnostics";
10942
10939
  pluginUpdates: "pluginUpdates";
10943
- resumeThreadsAfterRestart: "resumeThreadsAfterRestart";
10940
+ resumeDaemonSessions: "resumeDaemonSessions";
10944
10941
  serverMove: "serverMove";
10945
10942
  skipFocusedThreadNotifications: "skipFocusedThreadNotifications";
10946
10943
  threadContextCard: "threadContextCard";
10947
- threadRowMetadata: "threadRowMetadata";
10948
- updateWhenIdle: "updateWhenIdle";
10949
10944
  walCheckpointWorker: "walCheckpointWorker";
10950
10945
  }>, z$1.ZodBoolean>;
10951
10946
  featureFlags: z$1.ZodObject<{
@@ -10970,6 +10965,7 @@ declare const systemConfigResponseSchema: z$1.ZodObject<{
10970
10965
  flat: "flat";
10971
10966
  }>>;
10972
10967
  providerOrder: z$1.ZodArray<z$1.ZodString>;
10968
+ resumeThreadsAfterRestart: z$1.ZodBoolean;
10973
10969
  showDiagnosticEvents: z$1.ZodBoolean;
10974
10970
  showKeyboardHints: z$1.ZodBoolean;
10975
10971
  showUnhandledProviderEvents: z$1.ZodOptional<z$1.ZodBoolean>;
@@ -23722,8 +23718,7 @@ interface ExperimentalThreadRowMetadataDataInput {
23722
23718
  /**
23723
23719
  * A small item on a thread row's metadata line, under the title: a badge, not
23724
23720
  * a control. Items share one line, left to right, and the line clips at the
23725
- * row's edge. bb's sidebar draws the line only while the `threadRowMetadata`
23726
- * experiment is on and the user turns on Organize → Rows → Metadata, and only
23721
+ * row's edge. bb's sidebar draws the line when the user turns on Organize → Rows → Metadata, and only
23727
23722
  * on rows where an item shows something.
23728
23723
  * Load the line's data in `useData`, a React hook bb calls once for the
23729
23724
  * whole app while any list draws a metadata line, never per row; it
@@ -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 += Buffer.byteLength(tail);
7094
+ discardedBytes += tailBytes;
7092
7095
  return;
7093
7096
  }
7094
7097
  pending += tail;
7095
- if (Buffer.byteLength(pending) > maxLineBytes) {
7098
+ pendingBytes += tailBytes;
7099
+ if (pendingBytes > maxLineBytes) {
7096
7100
  discarding = true;
7097
- discardedBytes = Buffer.byteLength(pending);
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 += Buffer.byteLength(tail);
1294
+ discardedBytes += tailBytes;
1292
1295
  return;
1293
1296
  }
1294
1297
  pending += tail;
1295
- if (Buffer.byteLength(pending) > maxLineBytes) {
1298
+ pendingBytes += tailBytes;
1299
+ if (pendingBytes > maxLineBytes) {
1296
1300
  discarding = true;
1297
- discardedBytes = Buffer.byteLength(pending);
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) {
@@ -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 += Buffer.byteLength(tail);
761
+ discardedBytes += tailBytes;
759
762
  return;
760
763
  }
761
764
  pending += tail;
762
- if (Buffer.byteLength(pending) > maxLineBytes) {
765
+ pendingBytes += tailBytes;
766
+ if (pendingBytes > maxLineBytes) {
763
767
  discarding = true;
764
- discardedBytes = Buffer.byteLength(pending);
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) {
@@ -2398,8 +2398,8 @@ function normalizeRpcRegistration(contract, handlers, registered, options) {
2398
2398
  }
2399
2399
  return pending;
2400
2400
  }
2401
- function normalizeRealtimePayload(channel, payload) {
2402
- if (typeof channel !== "string" || channel.length === 0) {
2401
+ function normalizeRealtimePayload(channel2, payload) {
2402
+ if (typeof channel2 !== "string" || channel2.length === 0) {
2403
2403
  throw new Error("realtime channel must be a non-empty string");
2404
2404
  }
2405
2405
  if (payload === void 0) return null;
@@ -2411,7 +2411,7 @@ function normalizeRealtimePayload(channel, payload) {
2411
2411
  }
2412
2412
  if (json === void 0) {
2413
2413
  throw new Error(
2414
- `realtime payload for channel "${channel}" is not JSON-serializable`
2414
+ `realtime payload for channel "${channel2}" is not JSON-serializable`
2415
2415
  );
2416
2416
  }
2417
2417
  return JSON.parse(json);
@@ -3322,11 +3322,11 @@ function createFakePluginHostInternal(options, sharedState) {
3322
3322
  };
3323
3323
  const realtimeSignals = [];
3324
3324
  const realtime = {
3325
- publish(channel, payload) {
3325
+ publish(channel2, payload) {
3326
3326
  assertLive();
3327
3327
  realtimeSignals.push({
3328
- channel,
3329
- payload: normalizeRealtimePayload(channel, payload)
3328
+ channel: channel2,
3329
+ payload: normalizeRealtimePayload(channel2, payload)
3330
3330
  });
3331
3331
  }
3332
3332
  };
@@ -5054,9 +5054,9 @@ function isPunct(token, value) {
5054
5054
  function isName(token, value) {
5055
5055
  return token?.kind === "name" && (value === void 0 || token.value === value);
5056
5056
  }
5057
- function closingIndex(tokens, open, opener, closer) {
5057
+ function closingIndex(tokens, open2, opener, closer) {
5058
5058
  let depth = 0;
5059
- for (let index = open; index < tokens.length; index++) {
5059
+ for (let index = open2; index < tokens.length; index++) {
5060
5060
  if (isPunct(tokens[index], opener)) depth++;
5061
5061
  if (isPunct(tokens[index], closer) && --depth === 0) return index;
5062
5062
  }
@@ -5120,11 +5120,11 @@ function moduleReferences(source, options) {
5120
5120
  references.push({ specifier: argument.value, dynamic: false });
5121
5121
  return;
5122
5122
  }
5123
- const open = tokens[index + 1];
5123
+ const open2 = tokens[index + 1];
5124
5124
  const closeToken = tokens[close];
5125
- if (open === void 0 || closeToken === void 0) return;
5125
+ if (open2 === void 0 || closeToken === void 0) return;
5126
5126
  references.push({
5127
- specifier: source.slice(open.end, closeToken.start).trim(),
5127
+ specifier: source.slice(open2.end, closeToken.start).trim(),
5128
5128
  dynamic: true
5129
5129
  });
5130
5130
  return;
@@ -5219,12 +5219,259 @@ function scanPublicSdkOnly(packageRoot, options = {}) {
5219
5219
  )
5220
5220
  };
5221
5221
  }
5222
+
5223
+ // ../test-helpers/src/child-processes.ts
5224
+ import { ChildProcess, execFile } from "node:child_process";
5225
+ import { randomBytes } from "node:crypto";
5226
+ import { channel } from "node:diagnostics_channel";
5227
+ import { mkdtemp, open, rm } from "node:fs/promises";
5228
+ import { createServer } from "node:net";
5229
+ import { tmpdir as tmpdir2 } from "node:os";
5230
+ import { join as join3 } from "node:path";
5231
+ var POSIX_SOCKET_PATH_LIMIT = 100;
5232
+ function hasExited(child) {
5233
+ return child.exitCode !== null || child.signalCode !== null;
5234
+ }
5235
+ function waitForExit(child) {
5236
+ if (hasExited(child)) return Promise.resolve();
5237
+ return new Promise((resolveExit, rejectExit) => {
5238
+ const onExit = () => {
5239
+ child.off("error", onError);
5240
+ resolveExit();
5241
+ };
5242
+ const onError = (error) => {
5243
+ if (child.pid !== void 0) return;
5244
+ child.off("exit", onExit);
5245
+ rejectExit(error);
5246
+ };
5247
+ child.once("exit", onExit);
5248
+ child.on("error", onError);
5249
+ });
5250
+ }
5251
+ function trackChildProcesses() {
5252
+ const children = [];
5253
+ const closures = [];
5254
+ const childProcessChannel = channel("child_process");
5255
+ const onChildProcess = (message) => {
5256
+ if (typeof message === "object" && message !== null && "process" in message && message.process instanceof ChildProcess) {
5257
+ const child = message.process;
5258
+ children.push(child);
5259
+ closures.push(
5260
+ new Promise(
5261
+ (resolveClose) => child.once("close", () => resolveClose())
5262
+ )
5263
+ );
5264
+ }
5265
+ };
5266
+ childProcessChannel.subscribe(onChildProcess);
5267
+ const dispose = () => {
5268
+ childProcessChannel.unsubscribe(onChildProcess);
5269
+ };
5270
+ return {
5271
+ children,
5272
+ running: () => children.filter((child) => child.pid !== void 0 && !hasExited(child)),
5273
+ async waitForExit() {
5274
+ let pending = children.filter((child) => !hasExited(child));
5275
+ while (pending.length > 0) {
5276
+ await Promise.all(pending.map(waitForExit));
5277
+ pending = children.filter((child) => !hasExited(child));
5278
+ }
5279
+ },
5280
+ async waitForClose() {
5281
+ let waited = 0;
5282
+ while (waited < closures.length) {
5283
+ const pending = closures.slice(waited);
5284
+ waited = closures.length;
5285
+ await Promise.all(pending);
5286
+ }
5287
+ },
5288
+ killRunning(signal = "SIGKILL") {
5289
+ for (const child of children) {
5290
+ if (child.pid !== void 0 && !hasExited(child)) child.kill(signal);
5291
+ }
5292
+ },
5293
+ dispose,
5294
+ [Symbol.dispose]: dispose
5295
+ };
5296
+ }
5297
+ async function lifelinePath() {
5298
+ if (process.platform === "win32") {
5299
+ return {
5300
+ path: `\\\\.\\pipe\\bb-lifeline-${randomBytes(8).toString("hex")}`,
5301
+ cleanup: async () => {
5302
+ }
5303
+ };
5304
+ }
5305
+ const base = join3(tmpdir2(), "bb-lifeline-XXXXXX", "s").length < POSIX_SOCKET_PATH_LIMIT ? tmpdir2() : "/tmp";
5306
+ const directory = await mkdtemp(join3(base, "bb-lifeline-"));
5307
+ return {
5308
+ path: join3(directory, "s"),
5309
+ cleanup: () => rm(directory, { recursive: true, force: true })
5310
+ };
5311
+ }
5312
+ function parseHello(line) {
5313
+ try {
5314
+ const value = JSON.parse(line);
5315
+ if (typeof value === "object" && value !== null && "label" in value && "pid" in value && typeof value.label === "string" && typeof value.pid === "number" && Number.isSafeInteger(value.pid)) {
5316
+ return { label: value.label, pid: value.pid };
5317
+ }
5318
+ } catch {
5319
+ }
5320
+ return null;
5321
+ }
5322
+ async function createProcessLifeline() {
5323
+ const { path, cleanup } = await lifelinePath();
5324
+ const holders = [];
5325
+ const sockets = /* @__PURE__ */ new Set();
5326
+ const waiters = /* @__PURE__ */ new Set();
5327
+ const notify = () => {
5328
+ for (const waiter of waiters) waiter();
5329
+ };
5330
+ const server = createServer((socket) => {
5331
+ sockets.add(socket);
5332
+ let buffered = "";
5333
+ let closed = false;
5334
+ let resolveExited = () => {
5335
+ };
5336
+ const exited = new Promise((resolvePromise) => {
5337
+ resolveExited = resolvePromise;
5338
+ });
5339
+ socket.setEncoding("utf8");
5340
+ socket.on("error", () => {
5341
+ });
5342
+ socket.on("close", () => {
5343
+ closed = true;
5344
+ sockets.delete(socket);
5345
+ resolveExited();
5346
+ });
5347
+ const onData = (chunk) => {
5348
+ buffered += chunk;
5349
+ const newline = buffered.indexOf("\n");
5350
+ if (newline === -1) return;
5351
+ socket.off("data", onData);
5352
+ const hello = parseHello(buffered.slice(0, newline));
5353
+ if (hello === null) {
5354
+ socket.destroy();
5355
+ return;
5356
+ }
5357
+ holders.push({
5358
+ label: hello.label,
5359
+ pid: hello.pid,
5360
+ exited,
5361
+ alive: () => !closed,
5362
+ kill(signal = "SIGKILL") {
5363
+ if (closed) return false;
5364
+ try {
5365
+ process.kill(hello.pid, signal);
5366
+ return true;
5367
+ } catch {
5368
+ return false;
5369
+ }
5370
+ }
5371
+ });
5372
+ socket.write("held\n");
5373
+ notify();
5374
+ };
5375
+ socket.on("data", onData);
5376
+ });
5377
+ await new Promise((resolveListen, rejectListen) => {
5378
+ server.once("error", rejectListen);
5379
+ server.listen(path, () => {
5380
+ server.off("error", rejectListen);
5381
+ resolveListen();
5382
+ });
5383
+ });
5384
+ server.unref();
5385
+ return {
5386
+ path,
5387
+ holders,
5388
+ holdSource(label, onHeld) {
5389
+ const afterWrite = onHeld === void 0 ? "s.unref();" : `s.once("data",()=>{s.unref();${onHeld}});`;
5390
+ return `{const s=process.getBuiltinModule("node:net").connect(${JSON.stringify(path)});s.on("error",()=>{});s.write(JSON.stringify({label:${JSON.stringify(label)},pid:process.pid})+"\\n");${afterWrite}}`;
5391
+ },
5392
+ waitForHolders(count) {
5393
+ if (holders.length >= count) return Promise.resolve(holders.slice());
5394
+ return new Promise((resolveHolders) => {
5395
+ const waiter = () => {
5396
+ if (holders.length < count) return;
5397
+ waiters.delete(waiter);
5398
+ resolveHolders(holders.slice());
5399
+ };
5400
+ waiters.add(waiter);
5401
+ });
5402
+ },
5403
+ async close() {
5404
+ for (const holder of holders) holder.kill("SIGKILL");
5405
+ await Promise.all(holders.map((holder) => holder.exited));
5406
+ for (const socket of sockets) socket.destroy();
5407
+ await new Promise(
5408
+ (resolveClose) => server.close(() => resolveClose())
5409
+ );
5410
+ await cleanup();
5411
+ }
5412
+ };
5413
+ }
5414
+ async function createDescendantPipe() {
5415
+ if (process.platform === "win32") {
5416
+ throw new Error("createDescendantPipe needs POSIX named pipes");
5417
+ }
5418
+ const directory = await mkdtemp(join3(tmpdir2(), "bb-descendant-pipe-"));
5419
+ const path = join3(directory, "pipe");
5420
+ await new Promise((resolveFifo, rejectFifo) => {
5421
+ execFile(
5422
+ "mkfifo",
5423
+ [path],
5424
+ (error) => error === null ? resolveFifo() : rejectFifo(error)
5425
+ );
5426
+ });
5427
+ const reader = open(path, "r");
5428
+ const closed = reader.then(
5429
+ (handle) => new Promise((resolveClosed, rejectClosed) => {
5430
+ const stream = handle.createReadStream();
5431
+ stream.on("error", rejectClosed);
5432
+ stream.on("close", () => resolveClosed());
5433
+ stream.resume();
5434
+ })
5435
+ );
5436
+ let isOpen = false;
5437
+ const opened = reader.then(() => {
5438
+ isOpen = true;
5439
+ });
5440
+ return {
5441
+ path,
5442
+ opened,
5443
+ closed,
5444
+ async dispose() {
5445
+ if (!isOpen) {
5446
+ const writer = await open(path, "w");
5447
+ await writer.close();
5448
+ }
5449
+ await closed.catch(() => {
5450
+ });
5451
+ await rm(directory, { recursive: true, force: true });
5452
+ }
5453
+ };
5454
+ }
5455
+
5456
+ // src/testing/processes.ts
5457
+ function experimental_trackChildProcesses() {
5458
+ return trackChildProcesses();
5459
+ }
5460
+ function experimental_createProcessLifeline() {
5461
+ return createProcessLifeline();
5462
+ }
5463
+ function experimental_createDescendantPipe() {
5464
+ return createDescendantPipe();
5465
+ }
5222
5466
  export {
5223
5467
  PluginContextStaleError,
5224
5468
  createFakePluginHost,
5225
5469
  createFakeSdk,
5470
+ experimental_createDescendantPipe,
5471
+ experimental_createProcessLifeline,
5226
5472
  makePanelController as experimental_makePanelController,
5227
5473
  scanPublicSdkOnly as experimental_scanPublicSdkOnly,
5474
+ experimental_trackChildProcesses,
5228
5475
  makeHostResponse,
5229
5476
  makeMessageDispatchHookContext,
5230
5477
  makePluginAgentConfigurationContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.150",
3
+ "version": "0.6.157",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/get-bb/bb#readme",
6
6
  "bugs": {
@@ -179,6 +179,7 @@
179
179
  "@bb/sdk": "workspace:*",
180
180
  "@bb/server-contract": "workspace:*",
181
181
  "@bb/skill-index": "workspace:*",
182
+ "@bb/test-helpers": "workspace:*",
182
183
  "@bb/tsconfig": "workspace:*",
183
184
  "@testing-library/react": "^16.3.3",
184
185
  "@types/better-sqlite3": "^7.6.13",