bamboo-agents 0.1.9 → 0.1.10-dev.104.ffdbe11

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/dist/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10-dev.104.ffdbe11
package/dist/index.js CHANGED
@@ -3037,7 +3037,7 @@ var VERSION;
3037
3037
  var init_version = __esm({
3038
3038
  "src/version.ts"() {
3039
3039
  "use strict";
3040
- VERSION = "0.1.9";
3040
+ VERSION = "0.1.10-dev.104.ffdbe11";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -7436,7 +7436,9 @@ var init_agents = __esm({
7436
7436
  /** ISO timestamp when paused, else null. */
7437
7437
  paused_at: external_exports.string().nullable().optional(),
7438
7438
  /** Lite derived state (active/paused/inactive) — see CliAgentLifecycleStateSchema. */
7439
- state: external_exports.enum(["active", "paused", "inactive"]).optional()
7439
+ state: external_exports.enum(["active", "paused", "inactive"]).optional(),
7440
+ /** Brands this agent is assigned to; additive for older CLI servers. */
7441
+ brand_ids: external_exports.array(external_exports.string().uuid()).optional()
7440
7442
  });
7441
7443
  CliTierCapSchema = external_exports.object({
7442
7444
  limit: external_exports.number().int(),
@@ -12756,10 +12758,19 @@ var init_inbox_apply_revision = __esm({
12756
12758
  });
12757
12759
 
12758
12760
  // ../../src/lib/api-contracts/cli/inbox-management.ts
12759
- var InboxOperationSchema, InboxManageOperationSchema, InboxOperationBindingSchema, common, INBOX_MANAGEMENT_BINDINGS, INBOX_EXISTING_COMMAND_BINDINGS, changeCommon, CHANGE_MANAGEMENT_BINDINGS, opportunityCommon, OPPORTUNITY_MANAGEMENT_BINDINGS, annotationCommon, ANNOTATION_MANAGEMENT_BINDINGS, lifecycleMutationInputs, FDE_ACTION_MANAGEMENT_BINDINGS, GRAPH_RECOVERY_MANAGEMENT_BINDINGS, InboxManagementCatalogResponseSchema, OpportunityDecisionInputBaseSchema, InboxManagementCallSchema, InboxWorkItemSchema, InboxListReceiptSchema, InboxGetReceiptSchema, InboxEnvelopeBaseSchema, UnknownMutationReceiptSchema, ChangeReadBackSchema, OpportunitySnapshotSchema, OpportunityUnknownReceiptSchema, OpportunityCommandSchema, FdeActionSnapshotSchema, GraphRecoverySnapshotSchema, LifecycleUnknownReceiptSchema, AnnotationSnapshotSchema, AnnotationUnknownReceiptSchema, InboxOperationEnvelopeSchema;
12761
+ function inboxSourceVersionsMatch(current, reviewed) {
12762
+ if (typeof current !== "string" || typeof reviewed !== "string") return current === reviewed;
12763
+ const canonicalUtc = (value) => value.replace(/\+00:00$/i, "Z");
12764
+ return canonicalUtc(current) === canonicalUtc(reviewed);
12765
+ }
12766
+ var InboxUtcTimestampSchema, InboxOperationSchema, InboxManageOperationSchema, InboxOperationBindingSchema, common, INBOX_MANAGEMENT_BINDINGS, INBOX_EXISTING_COMMAND_BINDINGS, changeCommon, CHANGE_MANAGEMENT_BINDINGS, opportunityCommon, OPPORTUNITY_MANAGEMENT_BINDINGS, annotationCommon, ANNOTATION_MANAGEMENT_BINDINGS, lifecycleMutationInputs, FDE_ACTION_MANAGEMENT_BINDINGS, GRAPH_RECOVERY_MANAGEMENT_BINDINGS, InboxManagementCatalogResponseSchema, InboxOrganizationsResponseSchema, OpportunityDecisionInputBaseSchema, InboxManagementCallSchema, InboxWorkItemSchema, InboxListReceiptSchema, InboxGetReceiptSchema, InboxEnvelopeBaseSchema, UnknownMutationReceiptSchema, ChangeReadBackSchema, OpportunitySnapshotSchema, OpportunityUnknownReceiptSchema, OpportunityCommandSchema, FdeActionSnapshotSchema, GraphRecoverySnapshotSchema, LifecycleUnknownReceiptSchema, AnnotationSnapshotSchema, AnnotationUnknownReceiptSchema, InboxOperationEnvelopeSchema;
12760
12767
  var init_inbox_management = __esm({
12761
12768
  "../../src/lib/api-contracts/cli/inbox-management.ts"() {
12762
12769
  init_zod();
12770
+ InboxUtcTimestampSchema = external_exports.string().datetime({ offset: true }).refine(
12771
+ (value) => /(?:Z|\+00:00)$/i.test(value),
12772
+ "source version must use UTC (Z or +00:00)"
12773
+ );
12763
12774
  InboxOperationSchema = external_exports.enum([
12764
12775
  "inbox.list",
12765
12776
  "inbox.get",
@@ -13536,10 +13547,17 @@ var init_inbox_management = __esm({
13536
13547
  bindings: external_exports.array(InboxOperationBindingSchema),
13537
13548
  related_cli_commands: external_exports.array(external_exports.string())
13538
13549
  });
13550
+ InboxOrganizationsResponseSchema = external_exports.object({
13551
+ orgs: external_exports.array(external_exports.object({
13552
+ id: external_exports.string().uuid(),
13553
+ name: external_exports.string().min(1),
13554
+ status: external_exports.string()
13555
+ }))
13556
+ });
13539
13557
  OpportunityDecisionInputBaseSchema = external_exports.object({
13540
13558
  opportunity_id: external_exports.string().uuid(),
13541
13559
  brand_id: external_exports.string().uuid().optional(),
13542
- source_version: external_exports.string().datetime(),
13560
+ source_version: InboxUtcTimestampSchema,
13543
13561
  command_id: external_exports.string().min(1).max(128),
13544
13562
  reason: external_exports.string().trim().min(1),
13545
13563
  approved: external_exports.literal(true),
@@ -13700,7 +13718,7 @@ var init_inbox_management = __esm({
13700
13718
  input: external_exports.object({
13701
13719
  opportunity_id: external_exports.string().uuid(),
13702
13720
  brand_id: external_exports.string().uuid().optional(),
13703
- source_version: external_exports.string().datetime(),
13721
+ source_version: InboxUtcTimestampSchema,
13704
13722
  command_id: external_exports.string().min(1).max(128),
13705
13723
  recipient_user_id: external_exports.string().uuid(),
13706
13724
  recipient_name: external_exports.string().trim().min(1),
@@ -13742,7 +13760,7 @@ var init_inbox_management = __esm({
13742
13760
  input: external_exports.object({
13743
13761
  opportunity_id: external_exports.string().uuid(),
13744
13762
  brand_id: external_exports.string().uuid().optional(),
13745
- source_version: external_exports.string().datetime(),
13763
+ source_version: InboxUtcTimestampSchema,
13746
13764
  command_id: external_exports.string().min(1).max(128),
13747
13765
  answer: external_exports.string().trim().min(1).max(2e4),
13748
13766
  subquestion_key: external_exports.string().trim().min(1).max(240).optional(),
@@ -13767,7 +13785,7 @@ var init_inbox_management = __esm({
13767
13785
  input: external_exports.object({
13768
13786
  id: external_exports.string().uuid(),
13769
13787
  brand_id: external_exports.string().uuid().optional(),
13770
- source_version: external_exports.string().datetime(),
13788
+ source_version: InboxUtcTimestampSchema,
13771
13789
  command_id: external_exports.string().min(1).max(128),
13772
13790
  command: external_exports.enum([
13773
13791
  "assign",
@@ -14713,7 +14731,7 @@ var init_eval_test_sets = __esm({
14713
14731
  });
14714
14732
 
14715
14733
  // ../../src/lib/api-contracts/cli/eval-management.ts
14716
- var EvalManagementOperationSchema, EvalManagementBindingSchema, EvalManagementInputHelpSchema, EVAL_MANAGEMENT_INPUTS, common2, EVAL_MANAGEMENT_BINDINGS, EvalManagementCatalogResponseSchema, EvalManagementCallSchema, EvalManagementResultSchema;
14734
+ var EvalManagementOperationSchema, EvalManagementBindingSchema, EvalManagementInputHelpSchema, EVAL_MANAGEMENT_INPUTS, common2, EVAL_MANAGEMENT_BINDINGS, EvalManagementCatalogResponseSchema, EvalManagementCallSchema, EvalManagementScopeSchema, EvalManagementCatalogResultSchema, EvalManagementResultSchema;
14717
14735
  var init_eval_management = __esm({
14718
14736
  "../../src/lib/api-contracts/cli/eval-management.ts"() {
14719
14737
  init_zod();
@@ -14745,7 +14763,8 @@ var init_eval_management = __esm({
14745
14763
  authority: external_exports.string(),
14746
14764
  side_effect: external_exports.string(),
14747
14765
  receipt: external_exports.string(),
14748
- minimum_cli_version: external_exports.string()
14766
+ minimum_cli_version: external_exports.string(),
14767
+ explicit_org_scope: external_exports.boolean()
14749
14768
  });
14750
14769
  EvalManagementInputHelpSchema = external_exports.object({
14751
14770
  required: external_exports.array(external_exports.string()),
@@ -14850,7 +14869,8 @@ var init_eval_management = __esm({
14850
14869
  cli_command: "bamboo-agents eval manage",
14851
14870
  supported_runtimes: ["cli", "api"],
14852
14871
  authority: "Authenticated human or attributed agent with access to the target brand",
14853
- minimum_cli_version: "0.1.8"
14872
+ minimum_cli_version: "0.1.8",
14873
+ explicit_org_scope: false
14854
14874
  };
14855
14875
  EVAL_MANAGEMENT_BINDINGS = [
14856
14876
  {
@@ -14860,7 +14880,8 @@ var init_eval_management = __esm({
14860
14880
  method: "GET",
14861
14881
  path: "/api/v1/plays",
14862
14882
  side_effect: "none",
14863
- receipt: "investigation read model"
14883
+ receipt: "investigation read model",
14884
+ explicit_org_scope: true
14864
14885
  },
14865
14886
  {
14866
14887
  ...common2,
@@ -14869,7 +14890,8 @@ var init_eval_management = __esm({
14869
14890
  method: "GET",
14870
14891
  path: "/api/v1/plays/{id}",
14871
14892
  side_effect: "none",
14872
- receipt: "investigation read model"
14893
+ receipt: "investigation read model",
14894
+ explicit_org_scope: true
14873
14895
  },
14874
14896
  {
14875
14897
  ...common2,
@@ -14959,7 +14981,8 @@ var init_eval_management = __esm({
14959
14981
  method: "GET",
14960
14982
  path: "/api/v1/eval/waves",
14961
14983
  side_effect: "none",
14962
- receipt: "wave read model"
14984
+ receipt: "wave read model",
14985
+ explicit_org_scope: true
14963
14986
  },
14964
14987
  {
14965
14988
  ...common2,
@@ -14968,7 +14991,8 @@ var init_eval_management = __esm({
14968
14991
  method: "GET",
14969
14992
  path: "/api/v1/eval/waves/{id}",
14970
14993
  side_effect: "none",
14971
- receipt: "wave, members, and request receipts"
14994
+ receipt: "wave, members, and request receipts",
14995
+ explicit_org_scope: true
14972
14996
  },
14973
14997
  {
14974
14998
  ...common2,
@@ -15011,9 +15035,25 @@ var init_eval_management = __esm({
15011
15035
  operation: EvalManagementOperationSchema,
15012
15036
  input: external_exports.record(external_exports.string(), external_exports.unknown())
15013
15037
  });
15038
+ EvalManagementScopeSchema = external_exports.object({
15039
+ scope_contract_version: external_exports.literal(1),
15040
+ requested_org_id: external_exports.string().nullable().optional(),
15041
+ effective_org_id: external_exports.string(),
15042
+ real_actor_user_id: external_exports.string().nullable().optional(),
15043
+ effective_actor_user_id: external_exports.string().nullable().optional(),
15044
+ credential_kind: external_exports.enum(["user_session", "api_key"]).optional(),
15045
+ impersonating: external_exports.boolean().optional(),
15046
+ brand_id: external_exports.string().nullable().optional(),
15047
+ agent_id: external_exports.string().nullable().optional(),
15048
+ request_id: external_exports.string().optional()
15049
+ });
15050
+ EvalManagementCatalogResultSchema = EvalManagementCatalogResponseSchema.extend({
15051
+ scope: EvalManagementScopeSchema.optional()
15052
+ });
15014
15053
  EvalManagementResultSchema = external_exports.object({
15015
15054
  operation: EvalManagementOperationSchema,
15016
- data: external_exports.unknown()
15055
+ data: external_exports.unknown(),
15056
+ scope: EvalManagementScopeSchema.optional()
15017
15057
  });
15018
15058
  }
15019
15059
  });
@@ -15032,6 +15072,18 @@ async function getInboxManagementOperations(session) {
15032
15072
  throw new ApiError("The Inbox operation catalog response was malformed.", 502, "malformed_response");
15033
15073
  }
15034
15074
  }
15075
+ async function listInboxOrganizations(session) {
15076
+ const res = await cliApiFetch(`${apiBase()}/api/v1/admin/orgs`, {
15077
+ headers: { Authorization: `Bearer ${session}` }
15078
+ });
15079
+ if (!res.ok) throw await parseError(res);
15080
+ const json = await res.json();
15081
+ try {
15082
+ return InboxOrganizationsResponseSchema.parse(json.data);
15083
+ } catch {
15084
+ throw new ApiError("The organization list response was malformed.", 502, "malformed_response");
15085
+ }
15086
+ }
15035
15087
  async function callInboxManagement(session, orgId, call) {
15036
15088
  const res = await cliApiFetch(`${apiBase()}/api/v1/inbox/manage`, {
15037
15089
  method: "POST",
@@ -15298,17 +15350,23 @@ ${answer}
15298
15350
  Saved by Boo via CLI magic-moment, ${stamp}.
15299
15351
  `;
15300
15352
  }
15301
- async function listCliAgents(bambooSession) {
15353
+ async function listCliAgents(bambooSession, orgId) {
15302
15354
  const res = await cliApiFetch(`${apiBase()}/api/v1/cli/agents`, {
15303
- headers: { Authorization: `Bearer ${bambooSession}` }
15355
+ headers: {
15356
+ Authorization: `Bearer ${bambooSession}`,
15357
+ ...orgId ? { "bamboo-active-org": orgId } : {}
15358
+ }
15304
15359
  });
15305
15360
  if (!res.ok) throw await parseError(res);
15306
15361
  const json = await res.json();
15307
15362
  return CliAgentsListResponseSchema.parse(json);
15308
15363
  }
15309
- async function listCliBrands(bambooSession) {
15364
+ async function listCliBrands(bambooSession, orgId) {
15310
15365
  const res = await cliApiFetch(`${apiBase()}/api/v1/cli/brands`, {
15311
- headers: { Authorization: `Bearer ${bambooSession}` }
15366
+ headers: {
15367
+ Authorization: `Bearer ${bambooSession}`,
15368
+ ...orgId ? { "bamboo-active-org": orgId } : {}
15369
+ }
15312
15370
  });
15313
15371
  if (!res.ok) throw await parseError(res);
15314
15372
  const json = await res.json();
@@ -15568,17 +15626,37 @@ async function createEvalTestSet(bambooSession, body) {
15568
15626
  const json = await res.json();
15569
15627
  return CliEvalTestSetCreateResponseSchema.parse(json.data);
15570
15628
  }
15571
- async function getEvalManagementOperations(bambooSession) {
15629
+ async function getEvalManagementOperations(bambooSession, orgId) {
15572
15630
  const res = await cliApiFetch(`${apiBase()}/api/v1/eval/operations`, {
15573
- headers: { Authorization: `Bearer ${bambooSession}` }
15631
+ headers: {
15632
+ Authorization: `Bearer ${bambooSession}`,
15633
+ ...orgId ? { "bamboo-active-org": orgId } : {}
15634
+ }
15574
15635
  });
15575
15636
  if (!res.ok) throw await parseError(res);
15576
- const json = await res.json();
15577
- return EvalManagementCatalogResponseSchema.parse(json.data);
15637
+ try {
15638
+ const json = await res.json();
15639
+ const result = EvalManagementCatalogResultSchema.parse({
15640
+ ...json.data ?? {},
15641
+ scope: json.meta
15642
+ });
15643
+ assertExplicitOrgReceipt(result.scope, orgId);
15644
+ return result;
15645
+ } catch (error) {
15646
+ if (error instanceof ApiError) throw error;
15647
+ throw malformedEvalManagementResponse();
15648
+ }
15578
15649
  }
15579
- async function callEvalManagement(bambooSession, call) {
15650
+ async function callEvalManagement(bambooSession, call, orgId) {
15580
15651
  const binding = EVAL_MANAGEMENT_BINDINGS.find((candidate) => candidate.operation === call.operation);
15581
15652
  if (!binding) throw new ApiError(`Unsupported operation: ${call.operation}`, 400, "unsupported_operation");
15653
+ if (orgId && binding.explicit_org_scope !== true) {
15654
+ throw new ApiError(
15655
+ `${call.operation} does not support explicit customer organization scope in this release.`,
15656
+ 400,
15657
+ "unsupported_organization_scope"
15658
+ );
15659
+ }
15582
15660
  const help = EVAL_MANAGEMENT_INPUTS[call.operation];
15583
15661
  const missing = help.required.filter(
15584
15662
  (field) => call.input[field] === void 0 || call.input[field] === null || call.input[field] === ""
@@ -15608,7 +15686,10 @@ async function callEvalManagement(bambooSession, call) {
15608
15686
  let url = `${apiBase()}${path2}`;
15609
15687
  const init = {
15610
15688
  method: binding.method,
15611
- headers: { Authorization: `Bearer ${bambooSession}` }
15689
+ headers: {
15690
+ Authorization: `Bearer ${bambooSession}`,
15691
+ ...orgId ? { "bamboo-active-org": orgId } : {}
15692
+ }
15612
15693
  };
15613
15694
  if (binding.method === "GET") {
15614
15695
  const query = new URLSearchParams();
@@ -15623,12 +15704,34 @@ async function callEvalManagement(bambooSession, call) {
15623
15704
  }
15624
15705
  const res = await cliApiFetch(url, init);
15625
15706
  if (!res.ok) throw await parseError(res);
15626
- const json = await res.json();
15627
- const keys = Object.keys(json);
15628
- return EvalManagementResultSchema.parse({
15629
- operation: call.operation,
15630
- data: keys.length === 1 && keys[0] === "data" ? json.data : json
15631
- });
15707
+ try {
15708
+ const json = await res.json();
15709
+ const { data, meta, ...siblings } = json;
15710
+ const result = EvalManagementResultSchema.parse({
15711
+ operation: call.operation,
15712
+ data: Object.keys(siblings).length > 0 ? { data, ...siblings } : data,
15713
+ scope: meta
15714
+ });
15715
+ assertExplicitOrgReceipt(result.scope, orgId);
15716
+ return result;
15717
+ } catch (error) {
15718
+ if (error instanceof ApiError) throw error;
15719
+ throw malformedEvalManagementResponse();
15720
+ }
15721
+ }
15722
+ function malformedEvalManagementResponse() {
15723
+ return new ApiError(
15724
+ "The eval management response was malformed or incompatible with this CLI version.",
15725
+ 502,
15726
+ "malformed_response"
15727
+ );
15728
+ }
15729
+ function assertExplicitOrgReceipt(scope, orgId) {
15730
+ if (!orgId) return;
15731
+ const expected = orgId.toLowerCase();
15732
+ if (!scope || scope.requested_org_id?.toLowerCase() !== expected || scope.effective_org_id.toLowerCase() !== expected) {
15733
+ throw malformedEvalManagementResponse();
15734
+ }
15632
15735
  }
15633
15736
  async function getEvalTestSetMemberships(bambooSession, brandId) {
15634
15737
  const url = `${apiBase()}/api/v1/eval/test-roadmap?brand_id=${encodeURIComponent(brandId)}`;
@@ -20088,14 +20191,50 @@ var init_knowledge = __esm({
20088
20191
  }
20089
20192
  });
20090
20193
 
20194
+ // src/lib/organization-selection.ts
20195
+ async function resolveOrganizationSelection(requested, listOrganizations) {
20196
+ const query = requested.trim();
20197
+ if (!query) {
20198
+ throw Object.assign(new Error("Pass the customer organization with --org."), {
20199
+ code: "organization_scope_required"
20200
+ });
20201
+ }
20202
+ if (UUID.test(query)) return { id: query.toLowerCase() };
20203
+ const { orgs } = await listOrganizations();
20204
+ const normalized = query.toLowerCase();
20205
+ const exact = orgs.filter((org) => org.name?.toLowerCase() === normalized);
20206
+ const matches = exact.length ? exact : orgs.filter((org) => org.name?.toLowerCase().includes(normalized));
20207
+ if (matches.length === 1) return matches[0];
20208
+ if (matches.length === 0) {
20209
+ throw Object.assign(
20210
+ new Error(`No organization matches "${query}". Run \`bamboo-agents inbox organizations ${JSON.stringify(query)}\` to inspect available organizations.`),
20211
+ { code: "organization_scope_not_found" }
20212
+ );
20213
+ }
20214
+ throw Object.assign(
20215
+ new Error(
20216
+ `Organization "${query}" is ambiguous: ${matches.map((org) => `${org.name} (${org.id})`).join(", ")}. Re-run with the exact name or UUID.`
20217
+ ),
20218
+ { code: "organization_scope_ambiguous" }
20219
+ );
20220
+ }
20221
+ var UUID;
20222
+ var init_organization_selection = __esm({
20223
+ "src/lib/organization-selection.ts"() {
20224
+ "use strict";
20225
+ UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
20226
+ }
20227
+ });
20228
+
20091
20229
  // src/commands/inbox-management.ts
20092
20230
  var inbox_management_exports = {};
20093
20231
  __export(inbox_management_exports, {
20094
20232
  runInboxManage: () => runInboxManage,
20095
- runInboxOperations: () => runInboxOperations
20233
+ runInboxOperations: () => runInboxOperations,
20234
+ runInboxOrganizations: () => runInboxOrganizations
20096
20235
  });
20097
20236
  import { readFile as readFile8 } from "node:fs/promises";
20098
- async function sessionForOrg(org) {
20237
+ async function inboxSession() {
20099
20238
  const token = await resolveSession();
20100
20239
  if (!token)
20101
20240
  throw Object.assign(new Error("Run `bamboo-agents login` first."), {
@@ -20108,11 +20247,6 @@ async function sessionForOrg(org) {
20108
20247
  ),
20109
20248
  { code: "organization_scope_required" }
20110
20249
  );
20111
- if (!org)
20112
- throw Object.assign(
20113
- new Error("Pass the customer organization with --org."),
20114
- { code: "organization_scope_required" }
20115
- );
20116
20250
  return token;
20117
20251
  }
20118
20252
  async function inputObject(value) {
@@ -20156,9 +20290,28 @@ async function runInboxOperations(options) {
20156
20290
  fail(error, options);
20157
20291
  }
20158
20292
  }
20293
+ async function runInboxOrganizations(options) {
20294
+ try {
20295
+ const session = await inboxSession();
20296
+ const { orgs } = await listInboxOrganizations(session);
20297
+ const query = options.query?.trim() ?? "";
20298
+ const normalized = query.toLowerCase();
20299
+ const organizations = query ? orgs.filter((org) => org.name.toLowerCase().includes(normalized) || org.id.toLowerCase().includes(normalized)) : orgs;
20300
+ for (const org of organizations) human(` ${org.name} (${org.id}) [${org.status}]`, options);
20301
+ emitSuccess({ organizations, count: organizations.length, query: query || null }, options);
20302
+ } catch (error) {
20303
+ fail(error, options);
20304
+ }
20305
+ }
20159
20306
  async function runInboxManage(options) {
20160
20307
  try {
20161
- const session = await sessionForOrg(options.org);
20308
+ const session = await inboxSession();
20309
+ const organization = await resolveOrganizationSelection(
20310
+ options.org,
20311
+ () => listInboxOrganizations(session)
20312
+ );
20313
+ const orgId = organization.id;
20314
+ if (organization.name) human(`Operating as organization: ${organization.name} (${orgId})`, options);
20162
20315
  if (!InboxManageOperationSchema.safeParse(options.operation).success) {
20163
20316
  throw Object.assign(
20164
20317
  new Error(`Unsupported Inbox operation: ${options.operation}`),
@@ -20214,18 +20367,18 @@ async function runInboxManage(options) {
20214
20367
  });
20215
20368
  const preview = await callInboxManagement(
20216
20369
  session,
20217
- options.org,
20370
+ orgId,
20218
20371
  previewCall
20219
20372
  );
20220
- if (preview.scope.org_id !== options.org)
20373
+ if (preview.scope.org_id !== orgId)
20221
20374
  throw Object.assign(
20222
20375
  new Error(
20223
- `Requested organization ${options.org} but server resolved ${preview.scope.org_id}.`
20376
+ `Requested organization ${orgId} but server resolved ${preview.scope.org_id}.`
20224
20377
  ),
20225
20378
  { code: "organization_scope_mismatch" }
20226
20379
  );
20227
20380
  const suppliedVersion = input.source_version ?? input.subject_revision;
20228
- if (!isProposal && preview.source_version !== suppliedVersion)
20381
+ if (!isProposal && !inboxSourceVersionsMatch(preview.source_version, suppliedVersion))
20229
20382
  throw Object.assign(
20230
20383
  new Error(
20231
20384
  `The reviewed source revision ${String(suppliedVersion)} is stale; current revision is ${preview.source_version}.`
@@ -20252,14 +20405,15 @@ async function runInboxManage(options) {
20252
20405
  ) : String(
20253
20406
  input.opportunity_id ?? input.pr_number ?? input.id ?? input.task_id ?? "unknown"
20254
20407
  );
20255
- human(
20256
- `Approval preview \u2014 organization: ${preview.scope.org_name} (${preview.scope.org_id}); brand: ${preview.scope.brand_name ?? "all brands"}; operation: ${options.operation}; source item: ${sourceItem}; source version: ${preview.source_version ?? "new proposal"}; effect: ${mutation?.effect ?? "unspecified"}; reversible: ${String(mutation?.reversible ?? "unspecified")}${recipient}${wording}`,
20257
- options
20258
- );
20408
+ const command = input.command ? `; command: ${String(input.command)}` : "";
20409
+ const reason = input.reason ? `; reason: ${String(input.reason)}` : "";
20410
+ const commandId = input.command_id ? `; command ID: ${String(input.command_id)}` : "";
20411
+ const previewSummary = `Approval preview \u2014 organization: ${preview.scope.org_name} (${preview.scope.org_id}); brand: ${preview.scope.brand_name ?? "all brands"}; operation: ${options.operation}; source item: ${sourceItem}; source version: ${preview.source_version ?? "new proposal"}; effect: ${mutation?.effect ?? "unspecified"}; reversible: ${String(mutation?.reversible ?? "unspecified")}${command}${reason}${commandId}${recipient}${wording}`;
20412
+ human(previewSummary, options);
20259
20413
  if (!options.approve) {
20260
20414
  throw Object.assign(
20261
20415
  new Error(
20262
- "This operation changes customer state. Review the preview, obtain approval for its exact scope, source version, effect, and reversibility, then re-run with --approve."
20416
+ `${options.quiet ? `${previewSummary}. ` : ""}This operation changes customer state. Review the preview, obtain approval for its exact scope, source version, effect, and reversibility, then re-run with --approve.`
20263
20417
  ),
20264
20418
  { code: "approval_required" }
20265
20419
  );
@@ -20277,11 +20431,11 @@ async function runInboxManage(options) {
20277
20431
  operation: options.operation,
20278
20432
  input
20279
20433
  });
20280
- const result = await callInboxManagement(session, options.org, call);
20281
- if (result.scope.org_id !== options.org)
20434
+ const result = await callInboxManagement(session, orgId, call);
20435
+ if (result.scope.org_id !== orgId)
20282
20436
  throw Object.assign(
20283
20437
  new Error(
20284
- `Requested organization ${options.org} but server resolved ${result.scope.org_id}.`
20438
+ `Requested organization ${orgId} but server resolved ${result.scope.org_id}.`
20285
20439
  ),
20286
20440
  { code: "organization_scope_mismatch" }
20287
20441
  );
@@ -20302,6 +20456,7 @@ var init_inbox_management2 = __esm({
20302
20456
  init_inbox_management();
20303
20457
  init_api();
20304
20458
  init_credentials();
20459
+ init_organization_selection();
20305
20460
  init_output();
20306
20461
  MUTATION_EFFECTS = {
20307
20462
  "change.approve": { effect: "merge_workspace_change", reversible: false },
@@ -21631,9 +21786,38 @@ var init_episode = __esm({
21631
21786
  var eval_management_exports = {};
21632
21787
  __export(eval_management_exports, {
21633
21788
  runEvalManage: () => runEvalManage,
21634
- runEvalOperations: () => runEvalOperations
21789
+ runEvalOperations: () => runEvalOperations,
21790
+ runEvalScope: () => runEvalScope
21635
21791
  });
21636
21792
  import { readFile as readFile10 } from "node:fs/promises";
21793
+ async function runEvalScope(options) {
21794
+ const session = await requireSession12(options);
21795
+ try {
21796
+ const organization = await resolveOrganizationSelection(
21797
+ options.org,
21798
+ () => listInboxOrganizations(session)
21799
+ );
21800
+ const [brandResult, agentResult] = await Promise.all([
21801
+ listCliBrands(session, organization.id),
21802
+ listCliAgents(session, organization.id)
21803
+ ]);
21804
+ const result = {
21805
+ organization,
21806
+ brands: brandResult.brands,
21807
+ agents: agentResult.agents
21808
+ };
21809
+ human(`Operating as organization: ${organization.name ?? organization.id} (${organization.id})`, options);
21810
+ for (const brand2 of result.brands) human(` brand: ${brand2.name} (${brand2.id})`, options);
21811
+ for (const agent of result.agents) human(` agent: ${agent.name} (${agent.id})`, options);
21812
+ emitSuccess(result, options);
21813
+ } catch (error) {
21814
+ const value = error;
21815
+ emitError({
21816
+ code: value.code ?? value.errorCode ?? "scope_discovery_failed",
21817
+ message: value.message ?? "Could not discover the selected organization."
21818
+ }, options, 1);
21819
+ }
21820
+ }
21637
21821
  async function requireSession12(opts) {
21638
21822
  const session = await resolveSession();
21639
21823
  if (!session) {
@@ -21661,7 +21845,8 @@ async function parseInput(value) {
21661
21845
  async function runEvalOperations(options) {
21662
21846
  const session = await requireSession12(options);
21663
21847
  try {
21664
- const catalog = await getEvalManagementOperations(session);
21848
+ const organization = options.org ? await resolveOrganizationSelection(options.org, () => listInboxOrganizations(session)) : null;
21849
+ const catalog = organization ? await getEvalManagementOperations(session, organization.id) : await getEvalManagementOperations(session);
21665
21850
  human("", options);
21666
21851
  for (const binding of catalog.bindings) {
21667
21852
  human(
@@ -21699,18 +21884,23 @@ async function runEvalManage(options) {
21699
21884
  const session = await requireSession12(output);
21700
21885
  try {
21701
21886
  const input = await parseInput(options.input);
21887
+ const organization = options.org ? await resolveOrganizationSelection(options.org, () => listInboxOrganizations(session)) : null;
21702
21888
  const call = EvalManagementCallSchema.parse({
21703
21889
  operation: options.operation,
21704
21890
  input
21705
21891
  });
21706
- const result = await callEvalManagement(session, call);
21707
- human(`Applied ${result.operation}.`, output);
21892
+ const binding = EVAL_MANAGEMENT_BINDINGS.find(
21893
+ (candidate) => candidate.operation === call.operation
21894
+ );
21895
+ const result = organization ? await callEvalManagement(session, call, organization.id) : await callEvalManagement(session, call);
21896
+ human(`${binding?.side_effect === "none" ? "Read" : "Applied"} ${result.operation}.`, output);
21708
21897
  emitSuccess(result, output);
21709
21898
  } catch (error) {
21710
21899
  const value = error;
21900
+ const invalidInput = error instanceof SyntaxError || error instanceof ZodError || value.code === "ENOENT" || value.code === "EACCES";
21711
21901
  emitError(
21712
21902
  {
21713
- code: value.code ?? "management_failed",
21903
+ code: invalidInput ? "invalid_input" : value.code ?? "management_failed",
21714
21904
  message: value.message ?? "Management operation failed.",
21715
21905
  hint: "Run `bamboo-agents eval operations --json` for supported names and bindings."
21716
21906
  },
@@ -21722,9 +21912,11 @@ async function runEvalManage(options) {
21722
21912
  var init_eval_management2 = __esm({
21723
21913
  "src/commands/eval-management.ts"() {
21724
21914
  "use strict";
21915
+ init_zod();
21725
21916
  init_eval_management();
21726
21917
  init_credentials();
21727
21918
  init_api();
21919
+ init_organization_selection();
21728
21920
  init_output();
21729
21921
  }
21730
21922
  });
@@ -22537,7 +22729,11 @@ inbox.command("operations").description("List the supported customer Inbox opera
22537
22729
  const { runInboxOperations: runInboxOperations2 } = await Promise.resolve().then(() => (init_inbox_management2(), inbox_management_exports));
22538
22730
  await runInboxOperations2(options);
22539
22731
  });
22540
- inbox.command("manage").description("Call one exact read operation (`inbox.list` or `inbox.get`)").argument("<operation>", "Exact operation name").requiredOption("--input <json-or-@file>", "JSON object, inline or loaded from @path").requiredOption("--org <uuid>", "Explicit customer organization UUID").option("--approve", "Confirm the exact displayed mutation after user approval").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").action(async (operation, options) => {
22732
+ inbox.command("organizations [query]").description("List or search customer organizations available for --org").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").action(async (query, options) => {
22733
+ const { runInboxOrganizations: runInboxOrganizations2 } = await Promise.resolve().then(() => (init_inbox_management2(), inbox_management_exports));
22734
+ await runInboxOrganizations2({ query, ...options });
22735
+ });
22736
+ inbox.command("manage").description("Call one catalog-advertised customer Inbox operation").argument("<operation>", "Exact operation name").requiredOption("--input <json-or-@file>", "JSON object, inline or loaded from @path").requiredOption("--org <uuid-or-name>", "Explicit customer organization UUID or unique name").option("--approve", "Confirm the exact displayed mutation after user approval").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").action(async (operation, options) => {
22541
22737
  const { runInboxManage: runInboxManage2 } = await Promise.resolve().then(() => (init_inbox_management2(), inbox_management_exports));
22542
22738
  await runInboxManage2({ operation, ...options });
22543
22739
  });
@@ -22660,11 +22856,15 @@ episode.command("log-rec").description(
22660
22856
  await runEpisodeLogRec2(options);
22661
22857
  });
22662
22858
  var evals = program2.command("eval").description("Evaluation surface \u2014 A/B a candidate skill against its baseline");
22663
- evals.command("operations").description("List the exact supported investigation and wave management operations").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").action(async (options) => {
22859
+ evals.command("scope").description("Resolve one organization and list its authoritative brands and agents").requiredOption("--org <uuid-or-name>", "Customer organization UUID, exact name, or unique name fragment").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").action(async (options) => {
22860
+ const { runEvalScope: runEvalScope2 } = await Promise.resolve().then(() => (init_eval_management2(), eval_management_exports));
22861
+ await runEvalScope2(options);
22862
+ });
22863
+ evals.command("operations").description("List the exact supported investigation and wave management operations").option("--org <uuid-or-name>", "Operate in this organization (exact/unique names resolve authoritatively)").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").action(async (options) => {
22664
22864
  const { runEvalOperations: runEvalOperations2 } = await Promise.resolve().then(() => (init_eval_management2(), eval_management_exports));
22665
22865
  await runEvalOperations2(options);
22666
22866
  });
22667
- evals.command("manage").description("Call one canonical investigation or wave operation").argument("<operation>", "Exact name from `eval operations`").requiredOption("--input <json-or-@file>", "JSON object, inline or loaded from @path").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (operation, options) => {
22867
+ evals.command("manage").description("Call one canonical investigation or wave operation").argument("<operation>", "Exact name from `eval operations`").requiredOption("--input <json-or-@file>", "JSON object, inline or loaded from @path").option("--org <uuid-or-name>", "Operate in this organization (exact/unique names resolve authoritatively)").option("--json", "Emit a JSON envelope for agent consumption").option("--fields <list>", "Project only these dotted field paths from data (comma-separated)").option("--quiet", "Suppress human chatter (data/errors only)").option("--no-sync", "Skip the auto-sync git pull on this command").action(async (operation, options) => {
22668
22868
  const { runEvalManage: runEvalManage2 } = await Promise.resolve().then(() => (init_eval_management2(), eval_management_exports));
22669
22869
  await runEvalManage2({ operation, ...options });
22670
22870
  });