bamboo-agents 0.1.10-dev.104.ffdbe11 → 0.1.10-dev.106.12d3cfa

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/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.10-dev.104.ffdbe11";
3040
+ VERSION = "0.1.10-dev.106.12d3cfa";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -14730,11 +14730,129 @@ var init_eval_test_sets = __esm({
14730
14730
  }
14731
14731
  });
14732
14732
 
14733
+ // ../../src/lib/api-contracts/investigation-waves.ts
14734
+ var InvestigationWaveMemberSchema, InvestigationWaveCoreSchema, InvestigationWaveSchema, InvestigationWaveRequestMemberSchema, InvestigationWaveRequestSchema, InvestigationWaveDetailSchema;
14735
+ var init_investigation_waves = __esm({
14736
+ "../../src/lib/api-contracts/investigation-waves.ts"() {
14737
+ init_zod();
14738
+ InvestigationWaveMemberSchema = external_exports.object({
14739
+ investigation_id: external_exports.string().uuid(),
14740
+ position: external_exports.number().int().nonnegative(),
14741
+ title: external_exports.string().nullable().optional(),
14742
+ agent_id: external_exports.string().uuid().nullable().optional(),
14743
+ lifecycle_state: external_exports.string().nullable().optional()
14744
+ });
14745
+ InvestigationWaveCoreSchema = external_exports.object({
14746
+ id: external_exports.string().uuid(),
14747
+ org_id: external_exports.string().uuid(),
14748
+ brand_id: external_exports.string().uuid(),
14749
+ name: external_exports.string(),
14750
+ status: external_exports.enum(["active", "retired"]),
14751
+ membership_revision: external_exports.number().int().nonnegative(),
14752
+ not_before: external_exports.string().nullable(),
14753
+ timezone: external_exports.string(),
14754
+ created_at: external_exports.string(),
14755
+ updated_at: external_exports.string()
14756
+ });
14757
+ InvestigationWaveSchema = InvestigationWaveCoreSchema.extend({
14758
+ members: external_exports.array(InvestigationWaveMemberSchema)
14759
+ });
14760
+ InvestigationWaveRequestMemberSchema = external_exports.object({
14761
+ investigation_id: external_exports.string().uuid(),
14762
+ position: external_exports.number().int().nonnegative(),
14763
+ case_ids: external_exports.array(external_exports.string().uuid()),
14764
+ child_key: external_exports.string(),
14765
+ status: external_exports.enum(["pending", "admitted", "blocked"]),
14766
+ run_id: external_exports.string().uuid().nullable(),
14767
+ blocker: external_exports.string().nullable()
14768
+ });
14769
+ InvestigationWaveRequestSchema = external_exports.object({
14770
+ id: external_exports.string().uuid(),
14771
+ membership_revision: external_exports.number().int().nonnegative(),
14772
+ target_agent_id: external_exports.string().uuid().nullable(),
14773
+ request_fingerprint: external_exports.string().nullable(),
14774
+ not_before: external_exports.string().nullable(),
14775
+ status: external_exports.enum(["pending", "partial", "completed", "blocked", "failed"]),
14776
+ created_at: external_exports.string(),
14777
+ members: external_exports.array(InvestigationWaveRequestMemberSchema)
14778
+ });
14779
+ InvestigationWaveDetailSchema = InvestigationWaveSchema.extend({
14780
+ requests: external_exports.array(InvestigationWaveRequestSchema)
14781
+ });
14782
+ }
14783
+ });
14784
+
14733
14785
  // ../../src/lib/api-contracts/cli/eval-management.ts
14734
- var EvalManagementOperationSchema, EvalManagementBindingSchema, EvalManagementInputHelpSchema, EVAL_MANAGEMENT_INPUTS, common2, EVAL_MANAGEMENT_BINDINGS, EvalManagementCatalogResponseSchema, EvalManagementCallSchema, EvalManagementScopeSchema, EvalManagementCatalogResultSchema, EvalManagementResultSchema;
14786
+ function parseEvalManagementOperationData(call, data, selectedOrgId) {
14787
+ const operation = call.operation;
14788
+ let parsed;
14789
+ if (operation === "investigation.create" || operation === "investigation.update")
14790
+ parsed = InvestigationAuthoringDataSchema.parse(data);
14791
+ else if ([
14792
+ "investigation.hold",
14793
+ "investigation.resume",
14794
+ "investigation.cancel"
14795
+ ].includes(operation))
14796
+ parsed = InvestigationControlReceiptSchema.parse(data);
14797
+ else if ([
14798
+ "investigation.conclude_claim",
14799
+ "investigation.close",
14800
+ "investigation.reopen",
14801
+ "investigation.retire"
14802
+ ].includes(operation))
14803
+ parsed = InvestigationDecisionReceiptSchema.parse(data);
14804
+ else if (operation === "wave.create")
14805
+ parsed = InvestigationWaveCreateReceiptSchema.parse(data);
14806
+ else if (operation === "wave.update")
14807
+ parsed = InvestigationWaveUpdateReceiptSchema.parse(data);
14808
+ else if (operation === "wave.schedule")
14809
+ parsed = InvestigationWaveScheduleReceiptSchema.parse(data);
14810
+ else return data;
14811
+ const mismatch = (label) => {
14812
+ throw new Error(`eval_management_receipt_mismatch:${label}`);
14813
+ };
14814
+ const sameId = (left, right) => left.toLowerCase() === right.toLowerCase();
14815
+ const inputId = typeof call.input.id === "string" ? call.input.id : void 0;
14816
+ const inputBrandId = typeof call.input.brand_id === "string" ? call.input.brand_id : void 0;
14817
+ const action = operation.split(".")[1];
14818
+ if (operation === "investigation.update") {
14819
+ const receipt = parsed;
14820
+ if (inputId && (!receipt.investigation_id || !sameId(receipt.investigation_id, inputId)))
14821
+ mismatch("investigation_id");
14822
+ } else if (operation === "investigation.hold" || operation === "investigation.resume" || operation === "investigation.cancel") {
14823
+ const receipt = parsed;
14824
+ if (receipt.operation !== action) mismatch("operation");
14825
+ if (inputId && !sameId(receipt.investigation_id, inputId))
14826
+ mismatch("investigation_id");
14827
+ } else if (operation === "investigation.conclude_claim" || operation === "investigation.close" || operation === "investigation.reopen" || operation === "investigation.retire") {
14828
+ const receipt = parsed;
14829
+ if (receipt.operation !== action) mismatch("operation");
14830
+ if (inputId && !sameId(receipt.investigation_id, inputId))
14831
+ mismatch("investigation_id");
14832
+ } else if (operation === "wave.create") {
14833
+ const receipt = parsed;
14834
+ if (selectedOrgId && !sameId(receipt.wave.org_id, selectedOrgId))
14835
+ mismatch("org_id");
14836
+ if (inputBrandId && !sameId(receipt.wave.brand_id, inputBrandId))
14837
+ mismatch("brand_id");
14838
+ } else if (operation === "wave.update") {
14839
+ const receipt = parsed;
14840
+ if (inputId && !sameId(receipt.wave.id, inputId)) mismatch("wave_id");
14841
+ if (receipt.wave.org_id && selectedOrgId && !sameId(receipt.wave.org_id, selectedOrgId))
14842
+ mismatch("org_id");
14843
+ if (receipt.wave.brand_id && inputBrandId && !sameId(receipt.wave.brand_id, inputBrandId))
14844
+ mismatch("brand_id");
14845
+ } else if (operation === "wave.schedule") {
14846
+ const receipt = parsed;
14847
+ if (inputId && !sameId(receipt.wave_id, inputId)) mismatch("wave_id");
14848
+ }
14849
+ return parsed;
14850
+ }
14851
+ var EvalManagementOperationSchema, EvalManagementBindingSchema, EvalManagementInputHelpSchema, EVAL_MANAGEMENT_INPUTS, common2, EVAL_MANAGEMENT_BINDINGS, EvalManagementCatalogResponseSchema, EvalManagementCallSchema, EvalManagementScopeSchema, InvestigationPublicationReceiptSchema, InvestigationAuthoringDataSchema, InvestigationControlReceiptSchema, InvestigationDecisionReceiptSchema, InvestigationWaveMemberReceiptSchema, InvestigationWaveCreateReceiptSchema, InvestigationWaveUpdateReceiptSchema, InvestigationWaveScheduleReceiptSchema, EvalManagementCatalogResultSchema, EvalManagementResultSchema;
14735
14852
  var init_eval_management = __esm({
14736
14853
  "../../src/lib/api-contracts/cli/eval-management.ts"() {
14737
14854
  init_zod();
14855
+ init_investigation_waves();
14738
14856
  EvalManagementOperationSchema = external_exports.enum([
14739
14857
  "investigation.list",
14740
14858
  "investigation.get",
@@ -14900,7 +15018,9 @@ var init_eval_management = __esm({
14900
15018
  method: "POST",
14901
15019
  path: "/api/v1/plays",
14902
15020
  side_effect: "repo-authored investigation revision",
14903
- receipt: "source path, source SHA, and investigation id"
15021
+ receipt: "source path, source SHA, and investigation id",
15022
+ minimum_cli_version: "0.1.11",
15023
+ explicit_org_scope: true
14904
15024
  },
14905
15025
  {
14906
15026
  ...common2,
@@ -14909,7 +15029,9 @@ var init_eval_management = __esm({
14909
15029
  method: "PATCH",
14910
15030
  path: "/api/v1/plays/{id}",
14911
15031
  side_effect: "repo-authored investigation revision",
14912
- receipt: "source SHA and publication result"
15032
+ receipt: "source SHA and publication result",
15033
+ minimum_cli_version: "0.1.11",
15034
+ explicit_org_scope: true
14913
15035
  },
14914
15036
  {
14915
15037
  ...common2,
@@ -14918,7 +15040,9 @@ var init_eval_management = __esm({
14918
15040
  method: "POST",
14919
15041
  path: "/api/v1/eval/investigations/{id}/control",
14920
15042
  side_effect: "execution gate becomes held",
14921
- receipt: "control receipt and resulting revision"
15043
+ receipt: "control receipt and resulting revision",
15044
+ minimum_cli_version: "0.1.11",
15045
+ explicit_org_scope: true
14922
15046
  },
14923
15047
  {
14924
15048
  ...common2,
@@ -14927,7 +15051,9 @@ var init_eval_management = __esm({
14927
15051
  method: "POST",
14928
15052
  path: "/api/v1/eval/investigations/{id}/control",
14929
15053
  side_effect: "execution gate becomes active",
14930
- receipt: "control receipt and resulting revision"
15054
+ receipt: "control receipt and resulting revision",
15055
+ minimum_cli_version: "0.1.11",
15056
+ explicit_org_scope: true
14931
15057
  },
14932
15058
  {
14933
15059
  ...common2,
@@ -14936,7 +15062,9 @@ var init_eval_management = __esm({
14936
15062
  method: "POST",
14937
15063
  path: "/api/v1/eval/investigations/{id}/control",
14938
15064
  side_effect: "pending queue items are canceled",
14939
- receipt: "control receipt with affected count and served ids"
15065
+ receipt: "control receipt with affected count and served ids",
15066
+ minimum_cli_version: "0.1.11",
15067
+ explicit_org_scope: true
14940
15068
  },
14941
15069
  {
14942
15070
  ...common2,
@@ -14945,7 +15073,9 @@ var init_eval_management = __esm({
14945
15073
  method: "POST",
14946
15074
  path: "/api/v1/eval/investigations/{id}/decisions",
14947
15075
  side_effect: "append-only judgment plus repo publication",
14948
- receipt: "decision, judgment, publication, and evidence references"
15076
+ receipt: "decision, judgment, publication, and evidence references",
15077
+ minimum_cli_version: "0.1.11",
15078
+ explicit_org_scope: true
14949
15079
  },
14950
15080
  {
14951
15081
  ...common2,
@@ -14954,7 +15084,9 @@ var init_eval_management = __esm({
14954
15084
  method: "POST",
14955
15085
  path: "/api/v1/eval/investigations/{id}/decisions",
14956
15086
  side_effect: "repo lifecycle closes and pending work is canceled",
14957
- receipt: "decision, publication, cancellation count, and served ids"
15087
+ receipt: "decision, publication, cancellation count, and served ids",
15088
+ minimum_cli_version: "0.1.11",
15089
+ explicit_org_scope: true
14958
15090
  },
14959
15091
  {
14960
15092
  ...common2,
@@ -14963,7 +15095,9 @@ var init_eval_management = __esm({
14963
15095
  method: "POST",
14964
15096
  path: "/api/v1/eval/investigations/{id}/decisions",
14965
15097
  side_effect: "repo lifecycle opens and held execution resumes",
14966
- receipt: "decision and publication receipt"
15098
+ receipt: "decision and publication receipt",
15099
+ minimum_cli_version: "0.1.11",
15100
+ explicit_org_scope: true
14967
15101
  },
14968
15102
  {
14969
15103
  ...common2,
@@ -14972,7 +15106,9 @@ var init_eval_management = __esm({
14972
15106
  method: "POST",
14973
15107
  path: "/api/v1/eval/investigations/{id}/decisions",
14974
15108
  side_effect: "repo lifecycle retires and pending work is canceled",
14975
- receipt: "decision, publication, cancellation count, and served ids"
15109
+ receipt: "decision, publication, cancellation count, and served ids",
15110
+ minimum_cli_version: "0.1.11",
15111
+ explicit_org_scope: true
14976
15112
  },
14977
15113
  {
14978
15114
  ...common2,
@@ -15001,7 +15137,9 @@ var init_eval_management = __esm({
15001
15137
  method: "POST",
15002
15138
  path: "/api/v1/eval/waves",
15003
15139
  side_effect: "operational wave row",
15004
- receipt: "wave id and membership revision"
15140
+ receipt: "wave id and membership revision",
15141
+ minimum_cli_version: "0.1.11",
15142
+ explicit_org_scope: true
15005
15143
  },
15006
15144
  {
15007
15145
  ...common2,
@@ -15010,7 +15148,9 @@ var init_eval_management = __esm({
15010
15148
  method: "PATCH",
15011
15149
  path: "/api/v1/eval/waves/{id}",
15012
15150
  side_effect: "wave metadata or membership revision",
15013
- receipt: "wave and resulting membership revision"
15151
+ receipt: "wave and resulting membership revision",
15152
+ minimum_cli_version: "0.1.11",
15153
+ explicit_org_scope: true
15014
15154
  },
15015
15155
  {
15016
15156
  ...common2,
@@ -15019,7 +15159,9 @@ var init_eval_management = __esm({
15019
15159
  method: "POST",
15020
15160
  path: "/api/v1/eval/waves/{id}/schedule",
15021
15161
  side_effect: "durable run and queue admission",
15022
- receipt: "wave request and per-investigation run receipts"
15162
+ receipt: "wave request and per-investigation run receipts",
15163
+ minimum_cli_version: "0.1.11",
15164
+ explicit_org_scope: true
15023
15165
  }
15024
15166
  ];
15025
15167
  EvalManagementCatalogResponseSchema = external_exports.object({
@@ -15043,10 +15185,118 @@ var init_eval_management = __esm({
15043
15185
  effective_actor_user_id: external_exports.string().nullable().optional(),
15044
15186
  credential_kind: external_exports.enum(["user_session", "api_key"]).optional(),
15045
15187
  impersonating: external_exports.boolean().optional(),
15188
+ acting_in_org: external_exports.boolean().optional(),
15046
15189
  brand_id: external_exports.string().nullable().optional(),
15047
15190
  agent_id: external_exports.string().nullable().optional(),
15048
15191
  request_id: external_exports.string().optional()
15049
15192
  });
15193
+ InvestigationPublicationReceiptSchema = external_exports.object({
15194
+ status: external_exports.enum(["published", "pending", "existing", "noop"]),
15195
+ source_path: external_exports.string().min(1),
15196
+ source_sha: external_exports.string().min(1).optional(),
15197
+ pending_commit_sha: external_exports.string().min(1).optional(),
15198
+ pr_number: external_exports.number().int().positive().optional(),
15199
+ pr_url: external_exports.string().url().optional(),
15200
+ projection_status: external_exports.enum(["projected", "pending"]),
15201
+ projection_error: external_exports.literal("projection_failed").optional()
15202
+ }).superRefine((receipt, ctx) => {
15203
+ if (receipt.status === "published" && !receipt.source_sha) {
15204
+ ctx.addIssue({
15205
+ code: external_exports.ZodIssueCode.custom,
15206
+ path: ["source_sha"],
15207
+ message: `${receipt.status} publication requires a source SHA`
15208
+ });
15209
+ }
15210
+ if (receipt.status === "pending" && !receipt.pending_commit_sha && !receipt.pr_number && !receipt.pr_url) {
15211
+ ctx.addIssue({
15212
+ code: external_exports.ZodIssueCode.custom,
15213
+ path: ["status"],
15214
+ message: "pending publication requires a recoverable commit or PR receipt"
15215
+ });
15216
+ }
15217
+ });
15218
+ InvestigationAuthoringDataSchema = external_exports.object({
15219
+ investigation_id: external_exports.string().uuid().nullable(),
15220
+ source_path: external_exports.string().min(1),
15221
+ publication: InvestigationPublicationReceiptSchema
15222
+ }).passthrough();
15223
+ InvestigationControlReceiptSchema = external_exports.object({
15224
+ id: external_exports.string().uuid(),
15225
+ receipt_version: external_exports.literal(1),
15226
+ investigation_id: external_exports.string().uuid(),
15227
+ operation: external_exports.enum(["hold", "resume", "cancel"]),
15228
+ expected_revision: external_exports.number().int().nonnegative(),
15229
+ resulting_gate_state: external_exports.enum(["active", "held"]),
15230
+ resulting_revision: external_exports.number().int().nonnegative(),
15231
+ affected_pending_count: external_exports.number().int().nonnegative(),
15232
+ served_ids: external_exports.array(external_exports.string().uuid()),
15233
+ terminal_count: external_exports.number().int().nonnegative(),
15234
+ idempotent: external_exports.boolean()
15235
+ }).passthrough();
15236
+ InvestigationDecisionReceiptSchema = external_exports.object({
15237
+ id: external_exports.string().uuid(),
15238
+ judgment_id: external_exports.string().uuid(),
15239
+ investigation_id: external_exports.string().uuid(),
15240
+ operation: external_exports.enum(["conclude_claim", "close", "reopen", "retire"]),
15241
+ publication_status: external_exports.enum(["pending", "published", "failed"]),
15242
+ source_sha: external_exports.string().nullable().optional(),
15243
+ pr_url: external_exports.string().url().nullable().optional(),
15244
+ canceled_pending_count: external_exports.number().int().nonnegative(),
15245
+ served_ids: external_exports.array(external_exports.string().uuid()),
15246
+ actor_user_id: external_exports.string().uuid()
15247
+ }).passthrough();
15248
+ InvestigationWaveMemberReceiptSchema = external_exports.object({
15249
+ investigation_id: external_exports.string().uuid(),
15250
+ position: external_exports.number().int().nonnegative().optional(),
15251
+ case_ids: external_exports.array(external_exports.string().uuid()).optional(),
15252
+ child_key: external_exports.string().optional(),
15253
+ status: external_exports.enum(["pending", "admitted", "blocked"]).optional(),
15254
+ run_id: external_exports.string().uuid().nullable().optional(),
15255
+ blocker: external_exports.string().nullable().optional()
15256
+ });
15257
+ InvestigationWaveCreateReceiptSchema = external_exports.object({
15258
+ wave: InvestigationWaveCoreSchema.omit({
15259
+ created_at: true,
15260
+ updated_at: true
15261
+ }).passthrough()
15262
+ });
15263
+ InvestigationWaveUpdateReceiptSchema = external_exports.object({
15264
+ wave: InvestigationWaveCoreSchema.pick({
15265
+ id: true,
15266
+ org_id: true,
15267
+ brand_id: true,
15268
+ name: true,
15269
+ status: true,
15270
+ membership_revision: true,
15271
+ not_before: true,
15272
+ timezone: true
15273
+ }).partial({
15274
+ org_id: true,
15275
+ brand_id: true,
15276
+ name: true,
15277
+ status: true,
15278
+ not_before: true,
15279
+ timezone: true
15280
+ }).extend({ members: external_exports.array(InvestigationWaveMemberSchema) })
15281
+ });
15282
+ InvestigationWaveScheduleReceiptSchema = external_exports.object({
15283
+ request_id: external_exports.string().uuid(),
15284
+ wave_id: external_exports.string().uuid(),
15285
+ membership_revision: external_exports.number().int().nonnegative(),
15286
+ not_before: external_exports.string().nullable(),
15287
+ request_fingerprint: external_exports.string().min(1),
15288
+ status: external_exports.enum(["pending", "partial", "completed", "blocked", "failed"]),
15289
+ already_scheduled: external_exports.boolean(),
15290
+ members: external_exports.array(
15291
+ InvestigationWaveMemberReceiptSchema.extend({
15292
+ case_ids: external_exports.array(external_exports.string().uuid()),
15293
+ child_key: external_exports.string(),
15294
+ status: external_exports.enum(["pending", "admitted", "blocked"]),
15295
+ run_id: external_exports.string().uuid().nullable(),
15296
+ blocker: external_exports.string().nullable()
15297
+ })
15298
+ )
15299
+ });
15050
15300
  EvalManagementCatalogResultSchema = EvalManagementCatalogResponseSchema.extend({
15051
15301
  scope: EvalManagementScopeSchema.optional()
15052
15302
  });
@@ -15069,7 +15319,11 @@ async function getInboxManagementOperations(session) {
15069
15319
  try {
15070
15320
  return InboxManagementCatalogResponseSchema.parse(json.data);
15071
15321
  } catch {
15072
- throw new ApiError("The Inbox operation catalog response was malformed.", 502, "malformed_response");
15322
+ throw new ApiError(
15323
+ "The Inbox operation catalog response was malformed.",
15324
+ 502,
15325
+ "malformed_response"
15326
+ );
15073
15327
  }
15074
15328
  }
15075
15329
  async function listInboxOrganizations(session) {
@@ -15081,13 +15335,21 @@ async function listInboxOrganizations(session) {
15081
15335
  try {
15082
15336
  return InboxOrganizationsResponseSchema.parse(json.data);
15083
15337
  } catch {
15084
- throw new ApiError("The organization list response was malformed.", 502, "malformed_response");
15338
+ throw new ApiError(
15339
+ "The organization list response was malformed.",
15340
+ 502,
15341
+ "malformed_response"
15342
+ );
15085
15343
  }
15086
15344
  }
15087
15345
  async function callInboxManagement(session, orgId, call) {
15088
15346
  const res = await cliApiFetch(`${apiBase()}/api/v1/inbox/manage`, {
15089
15347
  method: "POST",
15090
- headers: { Authorization: `Bearer ${session}`, "bamboo-active-org": orgId, "Content-Type": "application/json" },
15348
+ headers: {
15349
+ Authorization: `Bearer ${session}`,
15350
+ "bamboo-active-org": orgId,
15351
+ "Content-Type": "application/json"
15352
+ },
15091
15353
  body: JSON.stringify(call)
15092
15354
  });
15093
15355
  if (!res.ok) throw await parseError(res);
@@ -15095,7 +15357,11 @@ async function callInboxManagement(session, orgId, call) {
15095
15357
  try {
15096
15358
  return InboxOperationEnvelopeSchema.parse(json.data);
15097
15359
  } catch {
15098
- throw new ApiError("The Inbox operation response was malformed.", 502, "malformed_response");
15360
+ throw new ApiError(
15361
+ "The Inbox operation response was malformed.",
15362
+ 502,
15363
+ "malformed_response"
15364
+ );
15099
15365
  }
15100
15366
  }
15101
15367
  function defaultApiBase(version) {
@@ -15206,14 +15472,17 @@ async function requestInboxRevision(bambooSession, body) {
15206
15472
  return InboxReviseResponseSchema.parse(json);
15207
15473
  }
15208
15474
  async function requestInboxApplyRevision(bambooSession, body) {
15209
- const res = await cliApiFetch(`${apiBase()}/api/v1/cli/inbox/apply-revision`, {
15210
- method: "POST",
15211
- headers: {
15212
- Authorization: `Bearer ${bambooSession}`,
15213
- "Content-Type": "application/json"
15214
- },
15215
- body: JSON.stringify(body)
15216
- });
15475
+ const res = await cliApiFetch(
15476
+ `${apiBase()}/api/v1/cli/inbox/apply-revision`,
15477
+ {
15478
+ method: "POST",
15479
+ headers: {
15480
+ Authorization: `Bearer ${bambooSession}`,
15481
+ "Content-Type": "application/json"
15482
+ },
15483
+ body: JSON.stringify(body)
15484
+ }
15485
+ );
15217
15486
  if (!res.ok) throw await parseError(res);
15218
15487
  const json = await res.json();
15219
15488
  return InboxApplyRevisionResponseSchema.parse(json);
@@ -15266,7 +15535,8 @@ async function getContextHealth(bambooSession, opts = {}) {
15266
15535
  async function getAgentUsage(bambooSession, opts = {}) {
15267
15536
  const url = new URL(`${apiBase()}/api/v1/cli/usage`);
15268
15537
  if (opts.agentId) url.searchParams.set("agent_id", opts.agentId);
15269
- if (opts.windowDays) url.searchParams.set("window_days", String(opts.windowDays));
15538
+ if (opts.windowDays)
15539
+ url.searchParams.set("window_days", String(opts.windowDays));
15270
15540
  const res = await cliApiFetch(url.toString(), {
15271
15541
  headers: { Authorization: `Bearer ${bambooSession}` }
15272
15542
  });
@@ -15601,14 +15871,17 @@ async function startAbTest(bambooSession, body) {
15601
15871
  return EvalAbResponseSchema.parse(json.data);
15602
15872
  }
15603
15873
  async function promoteBaseline(bambooSession, body) {
15604
- const res = await cliApiFetch(`${apiBase()}/api/v1/eval/baseline-promotions`, {
15605
- method: "POST",
15606
- headers: {
15607
- Authorization: `Bearer ${bambooSession}`,
15608
- "Content-Type": "application/json"
15609
- },
15610
- body: JSON.stringify(body)
15611
- });
15874
+ const res = await cliApiFetch(
15875
+ `${apiBase()}/api/v1/eval/baseline-promotions`,
15876
+ {
15877
+ method: "POST",
15878
+ headers: {
15879
+ Authorization: `Bearer ${bambooSession}`,
15880
+ "Content-Type": "application/json"
15881
+ },
15882
+ body: JSON.stringify(body)
15883
+ }
15884
+ );
15612
15885
  if (!res.ok) throw await parseError(res);
15613
15886
  const json = await res.json();
15614
15887
  return EvalBaselinePromoteResponseSchema.parse(json.data);
@@ -15648,8 +15921,15 @@ async function getEvalManagementOperations(bambooSession, orgId) {
15648
15921
  }
15649
15922
  }
15650
15923
  async function callEvalManagement(bambooSession, call, orgId) {
15651
- const binding = EVAL_MANAGEMENT_BINDINGS.find((candidate) => candidate.operation === call.operation);
15652
- if (!binding) throw new ApiError(`Unsupported operation: ${call.operation}`, 400, "unsupported_operation");
15924
+ const binding = EVAL_MANAGEMENT_BINDINGS.find(
15925
+ (candidate) => candidate.operation === call.operation
15926
+ );
15927
+ if (!binding)
15928
+ throw new ApiError(
15929
+ `Unsupported operation: ${call.operation}`,
15930
+ 400,
15931
+ "unsupported_operation"
15932
+ );
15653
15933
  if (orgId && binding.explicit_org_scope !== true) {
15654
15934
  throw new ApiError(
15655
15935
  `${call.operation} does not support explicit customer organization scope in this release.`,
@@ -15662,25 +15942,47 @@ async function callEvalManagement(bambooSession, call, orgId) {
15662
15942
  (field) => call.input[field] === void 0 || call.input[field] === null || call.input[field] === ""
15663
15943
  );
15664
15944
  if (missing.length) {
15665
- throw new ApiError(`${call.operation} requires input fields: ${missing.join(", ")}`, 400, "missing_required_input");
15945
+ throw new ApiError(
15946
+ `${call.operation} requires input fields: ${missing.join(", ")}`,
15947
+ 400,
15948
+ "missing_required_input"
15949
+ );
15666
15950
  }
15667
15951
  const allowed = /* @__PURE__ */ new Set([...help.required, ...help.optional]);
15668
- const unknown = Object.keys(call.input).filter((field) => !allowed.has(field));
15952
+ const unknown = Object.keys(call.input).filter(
15953
+ (field) => !allowed.has(field)
15954
+ );
15669
15955
  if (unknown.length) {
15670
- throw new ApiError(`${call.operation} does not accept input fields: ${unknown.join(", ")}`, 400, "unknown_input");
15956
+ throw new ApiError(
15957
+ `${call.operation} does not accept input fields: ${unknown.join(", ")}`,
15958
+ 400,
15959
+ "unknown_input"
15960
+ );
15671
15961
  }
15672
15962
  const input = { ...call.input };
15673
15963
  let path2 = binding.path;
15674
15964
  if (path2.includes("{id}")) {
15675
15965
  const id = input.id;
15676
15966
  if (typeof id !== "string" || id.length === 0) {
15677
- throw new ApiError(`${call.operation} requires input.id`, 400, "missing_resource_id");
15967
+ throw new ApiError(
15968
+ `${call.operation} requires input.id`,
15969
+ 400,
15970
+ "missing_resource_id"
15971
+ );
15678
15972
  }
15679
15973
  path2 = path2.replace("{id}", encodeURIComponent(id));
15680
15974
  delete input.id;
15681
15975
  }
15682
15976
  const action = call.operation.split(".")[1] ?? "";
15683
- if (call.operation.startsWith("investigation.") && ["hold", "resume", "cancel", "conclude_claim", "close", "reopen", "retire"].includes(action)) {
15977
+ if (call.operation.startsWith("investigation.") && [
15978
+ "hold",
15979
+ "resume",
15980
+ "cancel",
15981
+ "conclude_claim",
15982
+ "close",
15983
+ "reopen",
15984
+ "retire"
15985
+ ].includes(action)) {
15684
15986
  input.operation = action;
15685
15987
  }
15686
15988
  let url = `${apiBase()}${path2}`;
@@ -15702,8 +16004,27 @@ async function callEvalManagement(bambooSession, call, orgId) {
15702
16004
  init.headers["Content-Type"] = "application/json";
15703
16005
  init.body = JSON.stringify(input);
15704
16006
  }
15705
- const res = await cliApiFetch(url, init);
15706
- if (!res.ok) throw await parseError(res);
16007
+ const isMutation = binding.method !== "GET";
16008
+ let res;
16009
+ try {
16010
+ res = await cliApiFetch(url, init);
16011
+ } catch (error) {
16012
+ if (!isMutation) throw error;
16013
+ throw unknownEvalMutationOutcome(call, orgId);
16014
+ }
16015
+ if (!res.ok) {
16016
+ const parsedError = await parseError(res);
16017
+ const knownPrewriteFailures = /* @__PURE__ */ new Set([
16018
+ "scope_validation_failed",
16019
+ "investigation_recovery_failed",
16020
+ "investigation_read_failed",
16021
+ "workspace_unavailable",
16022
+ "source_unavailable"
16023
+ ]);
16024
+ if (isMutation && res.status >= 500 && !knownPrewriteFailures.has(parsedError.errorCode ?? ""))
16025
+ throw unknownEvalMutationOutcome(call, orgId);
16026
+ throw parsedError;
16027
+ }
15707
16028
  try {
15708
16029
  const json = await res.json();
15709
16030
  const { data, meta, ...siblings } = json;
@@ -15712,13 +16033,32 @@ async function callEvalManagement(bambooSession, call, orgId) {
15712
16033
  data: Object.keys(siblings).length > 0 ? { data, ...siblings } : data,
15713
16034
  scope: meta
15714
16035
  });
16036
+ result.data = parseEvalManagementOperationData(call, result.data, orgId);
15715
16037
  assertExplicitOrgReceipt(result.scope, orgId);
16038
+ if (isMutation) {
16039
+ const expectedBrand = call.input.brand_id;
16040
+ const expectedAgent = call.input.agent_id;
16041
+ if (typeof expectedBrand === "string" && result.scope?.brand_id?.toLowerCase() !== expectedBrand.toLowerCase())
16042
+ throw new Error("eval_management_scope_mismatch:brand_id");
16043
+ if (typeof expectedAgent === "string" && result.scope?.agent_id?.toLowerCase() !== expectedAgent.toLowerCase())
16044
+ throw new Error("eval_management_scope_mismatch:agent_id");
16045
+ }
15716
16046
  return result;
15717
16047
  } catch (error) {
15718
16048
  if (error instanceof ApiError) throw error;
16049
+ if (isMutation) throw unknownEvalMutationOutcome(call, orgId);
15719
16050
  throw malformedEvalManagementResponse();
15720
16051
  }
15721
16052
  }
16053
+ function unknownEvalMutationOutcome(call, orgId) {
16054
+ const operation = call.operation;
16055
+ const recovery = operation === "investigation.create" ? `Do not blindly retry. Reconcile the selected scope first with: bamboo-agents eval manage investigation.list${orgId ? ` --org ${orgId}` : ""} --input '${JSON.stringify({ brand_id: call.input.brand_id, agent_id: call.input.agent_id, search: call.input.title })}'` : "Read the scoped investigation and repository receipt before retrying.";
16056
+ return new ApiError(
16057
+ `The ${operation} request was dispatched, but its outcome is unknown. ${recovery}`,
16058
+ 502,
16059
+ "outcome_unknown"
16060
+ );
16061
+ }
15722
16062
  function malformedEvalManagementResponse() {
15723
16063
  return new ApiError(
15724
16064
  "The eval management response was malformed or incompatible with this CLI version.",
@@ -15760,14 +16100,17 @@ function absoluteUrl(relativePath) {
15760
16100
  return `${apiBase()}${relativePath}`;
15761
16101
  }
15762
16102
  async function postRecEpisode(bambooSession, body) {
15763
- const res = await cliApiFetch(`${apiBase()}/api/v1/cli/episodes/recommendation`, {
15764
- method: "POST",
15765
- headers: {
15766
- Authorization: `Bearer ${bambooSession}`,
15767
- "Content-Type": "application/json"
15768
- },
15769
- body: JSON.stringify(body)
15770
- });
16103
+ const res = await cliApiFetch(
16104
+ `${apiBase()}/api/v1/cli/episodes/recommendation`,
16105
+ {
16106
+ method: "POST",
16107
+ headers: {
16108
+ Authorization: `Bearer ${bambooSession}`,
16109
+ "Content-Type": "application/json"
16110
+ },
16111
+ body: JSON.stringify(body)
16112
+ }
16113
+ );
15771
16114
  if (!res.ok) throw await parseError(res);
15772
16115
  const json = await res.json();
15773
16116
  return CliRecEpisodeResponseSchema.parse(json);
@@ -21806,16 +22149,25 @@ async function runEvalScope(options) {
21806
22149
  brands: brandResult.brands,
21807
22150
  agents: agentResult.agents
21808
22151
  };
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);
22152
+ human(
22153
+ `Operating as organization: ${organization.name ?? organization.id} (${organization.id})`,
22154
+ options
22155
+ );
22156
+ for (const brand2 of result.brands)
22157
+ human(` brand: ${brand2.name} (${brand2.id})`, options);
22158
+ for (const agent of result.agents)
22159
+ human(` agent: ${agent.name} (${agent.id})`, options);
21812
22160
  emitSuccess(result, options);
21813
22161
  } catch (error) {
21814
22162
  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);
22163
+ emitError(
22164
+ {
22165
+ code: value.code ?? value.errorCode ?? "scope_discovery_failed",
22166
+ message: value.message ?? "Could not discover the selected organization."
22167
+ },
22168
+ options,
22169
+ 1
22170
+ );
21819
22171
  }
21820
22172
  }
21821
22173
  async function requireSession12(opts) {
@@ -21845,7 +22197,10 @@ async function parseInput(value) {
21845
22197
  async function runEvalOperations(options) {
21846
22198
  const session = await requireSession12(options);
21847
22199
  try {
21848
- const organization = options.org ? await resolveOrganizationSelection(options.org, () => listInboxOrganizations(session)) : null;
22200
+ const organization = options.org ? await resolveOrganizationSelection(
22201
+ options.org,
22202
+ () => listInboxOrganizations(session)
22203
+ ) : null;
21849
22204
  const catalog = organization ? await getEvalManagementOperations(session, organization.id) : await getEvalManagementOperations(session);
21850
22205
  human("", options);
21851
22206
  for (const binding of catalog.bindings) {
@@ -21871,7 +22226,7 @@ async function runEvalOperations(options) {
21871
22226
  const value = error;
21872
22227
  emitError(
21873
22228
  {
21874
- code: value.code ?? "operations_failed",
22229
+ code: value.code ?? value.errorCode ?? "operations_failed",
21875
22230
  message: value.message ?? "Could not load operations."
21876
22231
  },
21877
22232
  options,
@@ -21884,7 +22239,10 @@ async function runEvalManage(options) {
21884
22239
  const session = await requireSession12(output);
21885
22240
  try {
21886
22241
  const input = await parseInput(options.input);
21887
- const organization = options.org ? await resolveOrganizationSelection(options.org, () => listInboxOrganizations(session)) : null;
22242
+ const organization = options.org ? await resolveOrganizationSelection(
22243
+ options.org,
22244
+ () => listInboxOrganizations(session)
22245
+ ) : null;
21888
22246
  const call = EvalManagementCallSchema.parse({
21889
22247
  operation: options.operation,
21890
22248
  input
@@ -21892,15 +22250,34 @@ async function runEvalManage(options) {
21892
22250
  const binding = EVAL_MANAGEMENT_BINDINGS.find(
21893
22251
  (candidate) => candidate.operation === call.operation
21894
22252
  );
22253
+ if (organization && binding?.side_effect !== "none") {
22254
+ const advertised = await getEvalManagementOperations(
22255
+ session,
22256
+ organization.id
22257
+ );
22258
+ const serverBinding = advertised.bindings.find(
22259
+ (candidate) => candidate.operation === call.operation
22260
+ );
22261
+ if (!serverBinding || serverBinding.explicit_org_scope !== true) {
22262
+ const unsupported = new Error(
22263
+ `${call.operation} is not advertised for explicit customer organization scope by the selected server.`
22264
+ );
22265
+ unsupported.code = "unsupported_organization_scope";
22266
+ throw unsupported;
22267
+ }
22268
+ }
21895
22269
  const result = organization ? await callEvalManagement(session, call, organization.id) : await callEvalManagement(session, call);
21896
- human(`${binding?.side_effect === "none" ? "Read" : "Applied"} ${result.operation}.`, output);
22270
+ human(
22271
+ managementOutcomeLine(result, binding?.side_effect === "none"),
22272
+ output
22273
+ );
21897
22274
  emitSuccess(result, output);
21898
22275
  } catch (error) {
21899
22276
  const value = error;
21900
22277
  const invalidInput = error instanceof SyntaxError || error instanceof ZodError || value.code === "ENOENT" || value.code === "EACCES";
21901
22278
  emitError(
21902
22279
  {
21903
- code: invalidInput ? "invalid_input" : value.code ?? "management_failed",
22280
+ code: invalidInput ? "invalid_input" : value.code ?? value.errorCode ?? "management_failed",
21904
22281
  message: value.message ?? "Management operation failed.",
21905
22282
  hint: "Run `bamboo-agents eval operations --json` for supported names and bindings."
21906
22283
  },
@@ -21909,6 +22286,43 @@ async function runEvalManage(options) {
21909
22286
  );
21910
22287
  }
21911
22288
  }
22289
+ function managementOutcomeLine(result, readOnly) {
22290
+ if (readOnly) return `Read ${result.operation}.`;
22291
+ const data = result.data && typeof result.data === "object" ? result.data : {};
22292
+ const publication = data.publication && typeof data.publication === "object" ? data.publication : null;
22293
+ if (publication?.status === "published" && publication.projection_status === "projected") {
22294
+ return `Published ${result.operation} and projected it into Tests.`;
22295
+ }
22296
+ if (publication?.status === "published") {
22297
+ return `Published ${result.operation}; Tests projection is pending.`;
22298
+ }
22299
+ if (publication?.status === "pending") {
22300
+ return `Authored ${result.operation}; publication and Tests projection are pending.`;
22301
+ }
22302
+ if (publication?.status === "existing") {
22303
+ return `Found the existing authored investigation; no second create was sent.`;
22304
+ }
22305
+ if (publication?.status === "noop") {
22306
+ return `No change for ${result.operation}; the existing publication is current.`;
22307
+ }
22308
+ if (result.operation === "wave.schedule") {
22309
+ const status = typeof data.status === "string" ? data.status : "recorded";
22310
+ return `Scheduled the investigation wave; admission status is ${status}.`;
22311
+ }
22312
+ if (result.operation === "wave.create")
22313
+ return "Created the investigation wave without scheduling it.";
22314
+ if (result.operation === "wave.update")
22315
+ return "Updated the investigation wave without scheduling it.";
22316
+ const lifecycle = result.operation.split(".")[1];
22317
+ if (["hold", "resume", "cancel"].includes(lifecycle ?? "")) {
22318
+ return `${lifecycle === "hold" ? "Held" : lifecycle === "resume" ? "Resumed" : "Canceled pending work for"} the investigation.`;
22319
+ }
22320
+ if (["conclude_claim", "close", "reopen", "retire"].includes(lifecycle ?? "")) {
22321
+ const publicationStatus = data.publication_status;
22322
+ return publicationStatus === "pending" ? `Recorded ${result.operation}; repository publication is pending.` : `Published ${result.operation} with its decision receipt.`;
22323
+ }
22324
+ return `Applied ${result.operation}.`;
22325
+ }
21912
22326
  var init_eval_management2 = __esm({
21913
22327
  "src/commands/eval-management.ts"() {
21914
22328
  "use strict";