@get-bb/plugin-sdk 0.6.52 → 0.6.59

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.
@@ -809,6 +809,7 @@ var systemMessageKindValues = [
809
809
  "child-interrupted",
810
810
  "child-outcome-batch",
811
811
  "tool-result-delivered",
812
+ "environment-directory-updated",
812
813
  "unlabeled"
813
814
  ];
814
815
  var systemMessageKindSchema = z10.enum(systemMessageKindValues);
@@ -842,6 +843,10 @@ var systemMessageSubjectSchema = z10.discriminatedUnion("kind", [
842
843
  kind: z10.literal("tool-call"),
843
844
  toolName: z10.string(),
844
845
  suppress: z10.boolean()
846
+ }),
847
+ z10.object({
848
+ kind: z10.literal("directory"),
849
+ path: z10.string()
845
850
  })
846
851
  ]);
847
852
 
@@ -1085,6 +1090,7 @@ var threadEventScopeDefinitionByType = {
1085
1090
  },
1086
1091
  "turn/plan/updated": { policy: "turn" },
1087
1092
  "turn/diff/updated": { policy: "turn" },
1093
+ "turn/mainRun/updated": { policy: "turn" },
1088
1094
  "provider/error": {
1089
1095
  policy: "thread-or-turn",
1090
1096
  rationale: "Provider diagnostics use thread scope for provider setup/session failures; in-turn failures use turn scope."
@@ -1468,6 +1474,7 @@ var threadEventBackgroundTaskItemSchema = z14.object({
1468
1474
  status: threadEventItemStatusSchema,
1469
1475
  taskStatus: backgroundTaskStatusSchema,
1470
1476
  skipTranscript: z14.boolean(),
1477
+ foreground: z14.boolean(),
1471
1478
  workflowName: z14.string().optional(),
1472
1479
  workflow: workflowProgressSnapshotSchema.optional(),
1473
1480
  usage: backgroundTaskUsageSchema.optional(),
@@ -1512,6 +1519,7 @@ var threadEventItemSchema = z14.discriminatedUnion("type", [
1512
1519
  changes: z14.array(threadEventFileChangeSchema),
1513
1520
  status: threadEventItemStatusSchema,
1514
1521
  approvalStatus: threadEventItemApprovalStatusSchema,
1522
+ error: z14.string().optional(),
1515
1523
  ...itemPresentationField,
1516
1524
  parentToolCallId: z14.string().optional()
1517
1525
  }),
@@ -1712,6 +1720,12 @@ var unscopedProviderEventSchema = z14.discriminatedUnion("type", [
1712
1720
  plan: z14.array(threadEventPlanStepSchema),
1713
1721
  explanation: z14.string().optional()
1714
1722
  }),
1723
+ z14.object({
1724
+ type: z14.literal("turn/mainRun/updated"),
1725
+ threadId: z14.string(),
1726
+ providerThreadId: z14.string(),
1727
+ state: z14.enum(["idle", "running"])
1728
+ }),
1715
1729
  z14.object({
1716
1730
  type: z14.literal("turn/diff/updated"),
1717
1731
  threadId: z14.string(),
@@ -2121,6 +2135,7 @@ var deltaBackgroundTaskShapeSchema = z18.object({
2121
2135
  status: threadEventItemStatusSchema,
2122
2136
  taskStatus: backgroundTaskStatusSchema,
2123
2137
  skipTranscript: z18.boolean(),
2138
+ foreground: z18.boolean().optional(),
2124
2139
  workflowName: z18.string().optional(),
2125
2140
  workflow: workflowProgressSnapshotSchema.optional(),
2126
2141
  usage: backgroundTaskUsageSchema.optional(),
@@ -2255,6 +2270,10 @@ var threadDeltaSchema = z18.discriminatedUnion("kind", [
2255
2270
  providerTurnId: providerTurnIdSchema.optional(),
2256
2271
  parentRef: deltaKeyPartSchema.optional()
2257
2272
  }),
2273
+ z18.object({
2274
+ kind: z18.literal("turn.mainRun"),
2275
+ state: z18.enum(["idle", "running"])
2276
+ }),
2258
2277
  z18.object({
2259
2278
  kind: z18.literal("turn.boundary"),
2260
2279
  status: threadEventTurnStatusSchema,
@@ -2942,6 +2961,7 @@ function createDeltaAssembler(options) {
2942
2961
  status: shape.status,
2943
2962
  taskStatus: shape.taskStatus,
2944
2963
  skipTranscript: shape.skipTranscript,
2964
+ foreground: shape.foreground ?? false,
2945
2965
  ...shape.workflowName === void 0 ? {} : { workflowName: shape.workflowName },
2946
2966
  ...shape.workflow === void 0 ? {} : { workflow: shape.workflow },
2947
2967
  ...shape.usage === void 0 ? {} : { usage: shape.usage },
@@ -3189,6 +3209,9 @@ function createDeltaAssembler(options) {
3189
3209
  );
3190
3210
  }
3191
3211
  }
3212
+ function fileChangeErrorField(close) {
3213
+ return close.status === "failed" && close.resultText?.trim() ? { error: close.resultText } : {};
3214
+ }
3192
3215
  function completeStartedItem(started, close, parentToolCallId) {
3193
3216
  const parent = parentToolCallId ?? started.parentToolCallId;
3194
3217
  switch (started.type) {
@@ -3213,7 +3236,8 @@ function createDeltaAssembler(options) {
3213
3236
  id: started.id,
3214
3237
  changes: started.changes,
3215
3238
  status: close.status,
3216
- approvalStatus: started.approvalStatus
3239
+ approvalStatus: started.approvalStatus,
3240
+ ...fileChangeErrorField(close)
3217
3241
  },
3218
3242
  parent
3219
3243
  );
@@ -3301,7 +3325,8 @@ function createDeltaAssembler(options) {
3301
3325
  id: bbItemId,
3302
3326
  changes: buildFileChanges(shape),
3303
3327
  status: close.status,
3304
- approvalStatus: close.approvalStatus ?? null
3328
+ approvalStatus: close.approvalStatus ?? null,
3329
+ ...fileChangeErrorField(close)
3305
3330
  },
3306
3331
  parentToolCallId
3307
3332
  );
@@ -4098,6 +4123,19 @@ function createDeltaAssembler(options) {
4098
4123
  });
4099
4124
  return;
4100
4125
  }
4126
+ case "turn.mainRun": {
4127
+ if (state.currentTurnId === void 0) {
4128
+ return;
4129
+ }
4130
+ events.push({
4131
+ type: "turn/mainRun/updated",
4132
+ threadId: UNSTAMPED_THREAD_ID,
4133
+ providerThreadId: "",
4134
+ scope: turnScope(state.currentTurnId),
4135
+ state: delta.state
4136
+ });
4137
+ return;
4138
+ }
4101
4139
  case "turn.diff": {
4102
4140
  const turnId = delta.providerTurnId !== void 0 ? resolveVouchedTurnId(state, delta.providerTurnId) : state.currentTurnId;
4103
4141
  if (turnId === void 0) {
@@ -4438,7 +4476,8 @@ var bridgeCapabilitiesSchema = z22.object({
4438
4476
  PROVIDER_BRIDGE_PROTOCOL_VERSION
4439
4477
  ]),
4440
4478
  steerMode: bridgeSteerModeSchema.default("queue"),
4441
- skills: z22.object({ configure: z22.boolean().default(false) }).default({ configure: false })
4479
+ skills: z22.object({ configure: z22.boolean().default(false) }).default({ configure: false }),
4480
+ commands: z22.object({ list: z22.boolean().default(false) }).default({ list: false })
4442
4481
  }).passthrough();
4443
4482
  var initializeParamsSchema = z22.object({
4444
4483
  protocolVersion: z22.number().int().positive(),
@@ -4610,6 +4649,7 @@ import { z as z25 } from "zod";
4610
4649
  var BRIDGE_REQUEST_METHODS = {
4611
4650
  initialize: "initialize",
4612
4651
  modelList: "model/list",
4652
+ commandList: "commands/list",
4613
4653
  providerHealth: "provider/health",
4614
4654
  providerUsage: "provider/usage",
4615
4655
  providerInstallationStatus: "provider/installation/status",
@@ -4635,7 +4675,11 @@ var sessionConstructionFields = {
4635
4675
  disallowedTools: z25.array(z25.string().min(1)).optional(),
4636
4676
  instructionMode: instructionModeSchema
4637
4677
  };
4638
- var modelListParamsSchema = z25.object({ cwd: z25.string().min(1).optional() }).passthrough();
4678
+ var modelListParamsSchema = z25.object({
4679
+ cwd: z25.string().min(1).optional(),
4680
+ envVars: z25.record(z25.string(), z25.string()).optional()
4681
+ }).passthrough();
4682
+ var commandListParamsSchema = z25.object({ cwd: z25.string().min(1) }).passthrough();
4639
4683
  var threadStartParamsSchema = z25.object({
4640
4684
  ...sessionConstructionFields,
4641
4685
  input: z25.array(promptInputSchema).optional()
@@ -5151,7 +5195,7 @@ async function runRpcHygieneScenarios(client) {
5151
5195
  }
5152
5196
  return results;
5153
5197
  }
5154
- async function runHandshakeScenario(client) {
5198
+ async function runHandshakeScenario(client, fixture) {
5155
5199
  const id = client.request(BRIDGE_REQUEST_METHODS.initialize, {
5156
5200
  protocolVersion: PROVIDER_BRIDGE_PROTOCOL_VERSION,
5157
5201
  client: { name: "bb-conformance", version: "0.0.1" },
@@ -5192,44 +5236,45 @@ async function runHandshakeScenario(client) {
5192
5236
  return {
5193
5237
  results: [
5194
5238
  pass("handshake/initialize", title),
5195
- ...await runSkillsConfigureDeclaredScenario(
5196
- client,
5197
- parsed.data.capabilities.skills.configure
5198
- )
5239
+ ...await runDeclaredRequestScenario(client, {
5240
+ id: "skills/configure-declared",
5241
+ method: BRIDGE_REQUEST_METHODS.skillsConfigure,
5242
+ params: { roots: [] },
5243
+ capability: "skills.configure",
5244
+ declared: parsed.data.capabilities.skills.configure
5245
+ }),
5246
+ ...await runDeclaredRequestScenario(client, {
5247
+ id: "commands/list-declared",
5248
+ method: BRIDGE_REQUEST_METHODS.commandList,
5249
+ params: { cwd: fixture.cwd },
5250
+ capability: "commands.list",
5251
+ declared: parsed.data.capabilities.commands.list
5252
+ })
5199
5253
  ],
5200
5254
  capabilities: parsed.data.capabilities
5201
5255
  };
5202
5256
  }
5203
- var SKILLS_CONFIGURE_DECLARED_ID = "skills/configure-declared";
5204
- var SKILLS_CONFIGURE_DECLARED_TITLE = "skills/configure is handled iff the handshake declares skills.configure";
5205
- async function runSkillsConfigureDeclaredScenario(client, declared) {
5206
- const id = client.request(BRIDGE_REQUEST_METHODS.skillsConfigure, {
5207
- roots: []
5208
- });
5257
+ async function runDeclaredRequestScenario(client, args) {
5258
+ const title = `${args.method} is handled iff the handshake declares ${args.capability}`;
5259
+ const id = client.request(args.method, args.params);
5209
5260
  const response = await client.waitForResponse(id);
5210
5261
  if (response === null) {
5211
- return [
5212
- fail(
5213
- SKILLS_CONFIGURE_DECLARED_ID,
5214
- SKILLS_CONFIGURE_DECLARED_TITLE,
5215
- "skills/configure was not answered"
5216
- )
5217
- ];
5262
+ return [fail(args.id, title, `${args.method} was not answered`)];
5218
5263
  }
5219
- if (declared) {
5220
- return response.error === void 0 ? [pass(SKILLS_CONFIGURE_DECLARED_ID, SKILLS_CONFIGURE_DECLARED_TITLE)] : [
5264
+ if (args.declared) {
5265
+ return response.error === void 0 ? [pass(args.id, title)] : [
5221
5266
  fail(
5222
- SKILLS_CONFIGURE_DECLARED_ID,
5223
- SKILLS_CONFIGURE_DECLARED_TITLE,
5224
- `the handshake declares skills.configure but the request failed: ${JSON.stringify(response.error)}`
5267
+ args.id,
5268
+ title,
5269
+ `the handshake declares ${args.capability} but the request failed: ${JSON.stringify(response.error)}`
5225
5270
  )
5226
5271
  ];
5227
5272
  }
5228
- return errorCode(response) === BRIDGE_JSON_RPC_ERRORS.METHOD_NOT_FOUND ? [pass(SKILLS_CONFIGURE_DECLARED_ID, SKILLS_CONFIGURE_DECLARED_TITLE)] : [
5273
+ return errorCode(response) === BRIDGE_JSON_RPC_ERRORS.METHOD_NOT_FOUND ? [pass(args.id, title)] : [
5229
5274
  fail(
5230
- SKILLS_CONFIGURE_DECLARED_ID,
5231
- SKILLS_CONFIGURE_DECLARED_TITLE,
5232
- `the handshake does not declare skills.configure, yet the bridge answered the request with ${JSON.stringify(response.error ?? response.result)}; declare it (the runtime never sends an undeclared request)`
5275
+ args.id,
5276
+ title,
5277
+ `the handshake does not declare ${args.capability}, yet the bridge answered the request with ${JSON.stringify(response.error ?? response.result)}; declare it (the runtime never sends an undeclared request)`
5233
5278
  )
5234
5279
  ];
5235
5280
  }
@@ -6079,7 +6124,7 @@ async function runBridgeConformance(options) {
6079
6124
  );
6080
6125
  const results = [];
6081
6126
  results.push(...await runRpcHygieneScenarios(client));
6082
- const handshake = await runHandshakeScenario(client);
6127
+ const handshake = await runHandshakeScenario(client, options.session);
6083
6128
  results.push(...handshake.results);
6084
6129
  results.push(
6085
6130
  ...await runSessionLifecycleScenarios({
@@ -545,6 +545,142 @@ import { pathToFileURL } from "node:url";
545
545
  // ../process-utils/src/spawn.ts
546
546
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
547
547
 
548
+ // ../process-utils/src/vcs-process-scheduler.ts
549
+ import { AsyncLocalStorage } from "node:async_hooks";
550
+ import { availableParallelism } from "node:os";
551
+ var ranks = { interactive: 0, status: 1, background: 2 };
552
+ function localProcessCapacities(parallelism) {
553
+ const total = Math.min(6, Math.max(4, parallelism - 2));
554
+ return [total, total - 1, total - 2];
555
+ }
556
+ var capacities = {
557
+ local: localProcessCapacities(availableParallelism()),
558
+ network: [4, 3, 2]
559
+ };
560
+ var githubCapacity = 2;
561
+ var agingMs = 15e3;
562
+ var networkGitSubcommands = /* @__PURE__ */ new Set([
563
+ "fetch",
564
+ "pull",
565
+ "push",
566
+ "clone",
567
+ "ls-remote"
568
+ ]);
569
+ var gitGlobalOptionsWithValue = /* @__PURE__ */ new Set([
570
+ "-C",
571
+ "-c",
572
+ "--git-dir",
573
+ "--work-tree",
574
+ "--namespace",
575
+ "--config-env"
576
+ ]);
577
+ function isNetworkGitCommand(args) {
578
+ let index = 0;
579
+ while (index < args.length && args[index].startsWith("-")) {
580
+ index += gitGlobalOptionsWithValue.has(args[index]) ? 2 : 1;
581
+ }
582
+ const subcommand = args[index];
583
+ if (subcommand === void 0) return false;
584
+ if (networkGitSubcommands.has(subcommand)) return true;
585
+ const action = args.slice(index + 1).find((arg) => !arg.startsWith("-"));
586
+ return (subcommand === "submodule" || subcommand === "remote") && action === "update";
587
+ }
588
+ var VcsProcessScheduler = class {
589
+ priority = new AsyncLocalStorage();
590
+ admitted = new AsyncLocalStorage();
591
+ active = { local: 0, network: 0 };
592
+ githubActive = 0;
593
+ queue = [];
594
+ timer;
595
+ acquire(command, args, options) {
596
+ const pool = command === "gh" || isNetworkGitCommand(args) ? "network" : "local";
597
+ const slots = options.slots ?? 1;
598
+ if (!Number.isInteger(slots) || slots < 1 || slots > capacities[pool][ranks.background]) {
599
+ return Promise.reject(new Error("Invalid VCS process slot count"));
600
+ }
601
+ if (options.signal?.aborted) {
602
+ return Promise.reject(this.abortError(options.signal));
603
+ }
604
+ return new Promise((grant, reject) => {
605
+ const waiter = {
606
+ command,
607
+ pool,
608
+ priority: options.priority ?? this.priority.getStore() ?? "status",
609
+ slots,
610
+ queuedAt: performance.now(),
611
+ signal: options.signal,
612
+ grant,
613
+ onAbort: () => {
614
+ const index = this.queue.indexOf(waiter);
615
+ if (index === -1) return;
616
+ this.queue.splice(index, 1);
617
+ reject(this.abortError(options.signal));
618
+ this.drain();
619
+ }
620
+ };
621
+ this.queue.push(waiter);
622
+ options.signal?.addEventListener("abort", waiter.onAbort, { once: true });
623
+ this.drain();
624
+ });
625
+ }
626
+ abortError(signal) {
627
+ return Object.assign(
628
+ new Error("The operation was aborted", { cause: signal?.reason }),
629
+ {
630
+ name: "AbortError",
631
+ code: "ABORT_ERR"
632
+ }
633
+ );
634
+ }
635
+ rank(waiter) {
636
+ return Math.max(
637
+ 0,
638
+ ranks[waiter.priority] - Math.floor((performance.now() - waiter.queuedAt) / agingMs)
639
+ );
640
+ }
641
+ drain() {
642
+ clearTimeout(this.timer);
643
+ this.queue.sort(
644
+ (a, b) => this.rank(a) - this.rank(b) || a.queuedAt - b.queuedAt
645
+ );
646
+ const blocked = /* @__PURE__ */ new Set();
647
+ for (let index = 0; index < this.queue.length; ) {
648
+ const waiter = this.queue[index];
649
+ if (blocked.has(waiter.pool) || waiter.command === "gh" && this.githubActive + waiter.slots > githubCapacity) {
650
+ index += 1;
651
+ continue;
652
+ }
653
+ if (this.active[waiter.pool] + waiter.slots > capacities[waiter.pool][this.rank(waiter)]) {
654
+ blocked.add(waiter.pool);
655
+ index += 1;
656
+ continue;
657
+ }
658
+ this.queue.splice(index, 1);
659
+ waiter.signal?.removeEventListener("abort", waiter.onAbort);
660
+ this.active[waiter.pool] += waiter.slots;
661
+ if (waiter.command === "gh") this.githubActive += waiter.slots;
662
+ let released = false;
663
+ waiter.grant(() => {
664
+ if (released) return;
665
+ released = true;
666
+ this.active[waiter.pool] -= waiter.slots;
667
+ if (waiter.command === "gh") this.githubActive -= waiter.slots;
668
+ this.drain();
669
+ });
670
+ }
671
+ if (this.queue.length > 0) {
672
+ const delay = Math.min(
673
+ ...this.queue.map(
674
+ (waiter) => agingMs - (performance.now() - waiter.queuedAt) % agingMs
675
+ )
676
+ );
677
+ this.timer = setTimeout(() => this.drain(), delay);
678
+ }
679
+ }
680
+ };
681
+ var registry = globalThis;
682
+ var scheduler = registry.__bbVcsProcessScheduler ??= new VcsProcessScheduler();
683
+
548
684
  // ../process-utils/src/plugin-process-paths.ts
549
685
  import { mkdir, mkdtemp } from "node:fs/promises";
550
686
  import { tmpdir } from "node:os";
@@ -563,11 +699,6 @@ import { execFile } from "node:child_process";
563
699
  import { promisify } from "node:util";
564
700
  var execFileAsync = promisify(execFile);
565
701
 
566
- // ../process-utils/src/performance-diagnostics.ts
567
- import { Session } from "node:inspector/promises";
568
- var PROFILE_RETENTION_MS = 12 * 60 * 60 * 1e3;
569
- var MAX_PROFILE_BYTES = 12 * 1024 * 1024;
570
-
571
702
  // ../provider-bridge-protocol/src/bridge-kit/bounded-line-reader.ts
572
703
  import { StringDecoder } from "node:string_decoder";
573
704
  var MAX_JSON_RPC_LINE_BYTES = 64 * 1024 * 1024;