bamboo-agents 0.1.16-dev.138.224efdb → 0.1.17-dev.139.dd4593d

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.16-dev.138.224efdb
1
+ 0.1.17-dev.139.dd4593d
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.16-dev.138.224efdb";
3040
+ VERSION = "0.1.17-dev.139.dd4593d";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -7283,8 +7283,8 @@ var init_save = __esm({
7283
7283
  });
7284
7284
  SaveFileResultSchema = external_exports.object({
7285
7285
  path: external_exports.string(),
7286
- /** `auto` = merged to main; `queued` = opened/appended a review PR. */
7287
- routed: external_exports.enum(["auto", "queued"]),
7286
+ /** `pending` waits for the Brain check; only `auto` has landed. */
7287
+ routed: external_exports.enum(["auto", "queued", "pending"]),
7288
7288
  /** Present when a PR was opened (queued, or auto via the queue-PR path). */
7289
7289
  pr_url: external_exports.string().optional(),
7290
7290
  pr_number: external_exports.number().optional()
@@ -7295,7 +7295,9 @@ var init_save = __esm({
7295
7295
  * batch (the core routes a batch as one unit). `auto` when every edit
7296
7296
  * auto-merged, `queued` otherwise.
7297
7297
  */
7298
- routed: external_exports.enum(["auto", "queued"]),
7298
+ routed: external_exports.enum(["auto", "queued", "pending"]),
7299
+ change_id: external_exports.string().optional(),
7300
+ pending_count: external_exports.number().int().nonnegative().default(0),
7299
7301
  classification: external_exports.enum(["self_only", "cross_scope", "forbidden"]),
7300
7302
  /** Per-file detail. One entry per accepted edit. */
7301
7303
  files: external_exports.array(SaveFileResultSchema),
@@ -7360,8 +7362,10 @@ var init_knowledge_save = __esm({
7360
7362
  "submitted",
7361
7363
  "rejected",
7362
7364
  "noop",
7363
- "conflict"
7365
+ "conflict",
7366
+ "pending"
7364
7367
  ]),
7368
+ change_id: external_exports.string().optional(),
7365
7369
  classification: external_exports.enum(["self_only", "cross_scope", "forbidden"]),
7366
7370
  /** Present when a PR was opened (queued/submitted, or auto via queue-PR). */
7367
7371
  pr_url: external_exports.string().optional(),
@@ -12914,113 +12918,100 @@ var init_investigation_waves = __esm({
12914
12918
  });
12915
12919
 
12916
12920
  // ../../src/lib/api-contracts/cli/eval-management.ts
12917
- function parseEvalManagementOperationData(call, data, selectedOrgId) {
12918
- const operation = call.operation;
12919
- let parsed;
12920
- if (operation === "investigation.create" || operation === "investigation.update")
12921
- parsed = InvestigationAuthoringDataSchema.parse(data);
12922
- else if ([
12923
- "investigation.hold",
12924
- "investigation.resume",
12925
- "investigation.cancel"
12926
- ].includes(operation))
12927
- parsed = InvestigationControlReceiptSchema.parse(data);
12928
- else if ([
12929
- "investigation.conclude_claim",
12930
- "investigation.retire_claim",
12931
- "investigation.close",
12932
- "investigation.reopen",
12933
- "investigation.retire"
12934
- ].includes(operation))
12935
- parsed = InvestigationDecisionReceiptSchema.parse(data);
12936
- else if (operation === "wave.create")
12937
- parsed = InvestigationWaveCreateReceiptSchema.parse(data);
12938
- else if (operation === "wave.update")
12939
- parsed = InvestigationWaveUpdateReceiptSchema.parse(data);
12940
- else if (operation === "wave.schedule")
12941
- parsed = InvestigationWaveScheduleReceiptSchema.parse(data);
12942
- else if (operation === "case.create" || operation === "case.update")
12943
- parsed = CaseAuthoringReceiptSchema.parse(data);
12944
- else if (operation === "case.retire")
12945
- parsed = CaseRetireReceiptSchema.parse(data);
12946
- else if (operation === "case.attach" || operation === "case.detach")
12947
- parsed = CaseRefsReceiptSchema.parse(data);
12948
- else return data;
12949
- const mismatch = (label) => {
12950
- throw new Error(`eval_management_receipt_mismatch:${label}`);
12921
+ function mismatch(label) {
12922
+ throw new Error(`eval_management_receipt_mismatch:${label}`);
12923
+ }
12924
+ function sameId(left, right) {
12925
+ return left.toLowerCase() === right.toLowerCase();
12926
+ }
12927
+ function stringInput(input, key) {
12928
+ const value = input[key];
12929
+ return typeof value === "string" ? value : void 0;
12930
+ }
12931
+ function receiptContract(schema, check) {
12932
+ return {
12933
+ parse: (data) => schema.parse(data),
12934
+ verify: (parsed, request) => check?.(parsed, request)
12951
12935
  };
12952
- const sameId = (left, right) => left.toLowerCase() === right.toLowerCase();
12953
- const inputId = typeof call.input.id === "string" ? call.input.id : void 0;
12954
- const inputBrandId = typeof call.input.brand_id === "string" ? call.input.brand_id : void 0;
12955
- const action = operation.split(".")[1];
12956
- if (operation === "investigation.update") {
12957
- const receipt = parsed;
12958
- if (inputId && (!receipt.investigation_id || !sameId(receipt.investigation_id, inputId)))
12959
- mismatch("investigation_id");
12960
- } else if (operation === "investigation.hold" || operation === "investigation.resume" || operation === "investigation.cancel") {
12961
- const receipt = parsed;
12962
- if (receipt.operation !== action) mismatch("operation");
12963
- if (inputId && !sameId(receipt.investigation_id, inputId))
12964
- mismatch("investigation_id");
12965
- } else if (operation === "investigation.conclude_claim" || operation === "investigation.retire_claim" || operation === "investigation.close" || operation === "investigation.reopen" || operation === "investigation.retire") {
12966
- const receipt = parsed;
12967
- if (receipt.operation !== action) mismatch("operation");
12968
- if (inputId && !sameId(receipt.investigation_id, inputId))
12969
- mismatch("investigation_id");
12970
- } else if (operation === "wave.create") {
12971
- const receipt = parsed;
12972
- if (selectedOrgId && !sameId(receipt.wave.org_id, selectedOrgId))
12973
- mismatch("org_id");
12974
- if (inputBrandId && !sameId(receipt.wave.brand_id, inputBrandId))
12975
- mismatch("brand_id");
12976
- } else if (operation === "wave.update") {
12977
- const receipt = parsed;
12978
- if (inputId && !sameId(receipt.wave.id, inputId)) mismatch("wave_id");
12979
- if (receipt.wave.org_id && selectedOrgId && !sameId(receipt.wave.org_id, selectedOrgId))
12980
- mismatch("org_id");
12981
- if (receipt.wave.brand_id && inputBrandId && !sameId(receipt.wave.brand_id, inputBrandId))
12982
- mismatch("brand_id");
12983
- } else if (operation === "wave.schedule") {
12984
- const receipt = parsed;
12985
- if (inputId && !sameId(receipt.wave_id, inputId)) mismatch("wave_id");
12986
- const expectedRevision = call.input.expected_membership_revision;
12987
- if (typeof expectedRevision === "number" && receipt.membership_revision !== expectedRevision)
12988
- mismatch("membership_revision");
12989
- } else if (operation === "case.create" || operation === "case.update") {
12990
- const receipt = parsed;
12991
- if (inputBrandId && !sameId(receipt.brand_id, inputBrandId))
12992
- mismatch("brand_id");
12993
- const inputAgentId = typeof call.input.agent_id === "string" ? call.input.agent_id : void 0;
12994
- if (inputAgentId && !sameId(receipt.agent_id, inputAgentId))
12995
- mismatch("agent_id");
12996
- if (inputId && (!receipt.case_id || !sameId(receipt.case_id, inputId)))
12997
- mismatch("case_id");
12998
- const inputSourcePath = typeof call.input.source_path === "string" ? call.input.source_path : void 0;
12999
- if (inputSourcePath && receipt.source_path !== inputSourcePath)
13000
- mismatch("source_path");
13001
- } else if (operation === "case.retire") {
13002
- const receipt = parsed;
13003
- if (inputBrandId && !sameId(receipt.brand_id, inputBrandId))
13004
- mismatch("brand_id");
13005
- if (inputId && (!receipt.case_id || !sameId(receipt.case_id, inputId)))
13006
- mismatch("case_id");
13007
- const inputSourcePath = typeof call.input.source_path === "string" ? call.input.source_path : void 0;
13008
- if (inputSourcePath && receipt.source_path !== inputSourcePath)
13009
- mismatch("source_path");
13010
- const commandId = typeof call.input.command_id === "string" ? call.input.command_id : void 0;
13011
- if (commandId && receipt.command_id !== commandId) mismatch("command_id");
13012
- } else if (operation === "case.attach" || operation === "case.detach") {
13013
- const receipt = parsed;
13014
- if (receipt.operation !== action) mismatch("operation");
13015
- if (inputId && !sameId(receipt.investigation_id, inputId))
13016
- mismatch("investigation_id");
13017
- const claimKeys = Array.isArray(call.input.claim_keys) ? call.input.claim_keys.filter((k) => typeof k === "string") : [];
13018
- const receiptKeys = new Set(receipt.claims.map((c) => c.key));
13019
- if (claimKeys.some((key) => !receiptKeys.has(key))) mismatch("claim_keys");
13020
- }
12936
+ }
12937
+ function checkInvestigationUpdate(receipt, request) {
12938
+ if (request.inputId && (!receipt.investigation_id || !sameId(receipt.investigation_id, request.inputId)))
12939
+ mismatch("investigation_id");
12940
+ }
12941
+ function checkInvestigationOperation(receipt, request) {
12942
+ if (receipt.operation !== request.action) mismatch("operation");
12943
+ if (request.inputId && !sameId(receipt.investigation_id, request.inputId))
12944
+ mismatch("investigation_id");
12945
+ }
12946
+ function checkWaveCreate(receipt, request) {
12947
+ if (request.selectedOrgId && !sameId(receipt.wave.org_id, request.selectedOrgId))
12948
+ mismatch("org_id");
12949
+ if (request.inputBrandId && !sameId(receipt.wave.brand_id, request.inputBrandId))
12950
+ mismatch("brand_id");
12951
+ }
12952
+ function checkWaveUpdate(receipt, request) {
12953
+ if (request.inputId && !sameId(receipt.wave.id, request.inputId))
12954
+ mismatch("wave_id");
12955
+ if (receipt.wave.org_id && request.selectedOrgId && !sameId(receipt.wave.org_id, request.selectedOrgId))
12956
+ mismatch("org_id");
12957
+ if (receipt.wave.brand_id && request.inputBrandId && !sameId(receipt.wave.brand_id, request.inputBrandId))
12958
+ mismatch("brand_id");
12959
+ }
12960
+ function checkWaveSchedule(receipt, request) {
12961
+ if (request.inputId && !sameId(receipt.wave_id, request.inputId))
12962
+ mismatch("wave_id");
12963
+ const expectedRevision = request.input.expected_membership_revision;
12964
+ if (typeof expectedRevision === "number" && receipt.membership_revision !== expectedRevision)
12965
+ mismatch("membership_revision");
12966
+ }
12967
+ function checkBrandId(receiptBrandId, request) {
12968
+ if (request.inputBrandId && !sameId(receiptBrandId, request.inputBrandId))
12969
+ mismatch("brand_id");
12970
+ }
12971
+ function checkCaseId(caseId, request) {
12972
+ if (request.inputId && (!caseId || !sameId(caseId, request.inputId)))
12973
+ mismatch("case_id");
12974
+ }
12975
+ function checkSourcePath(sourcePath, request) {
12976
+ const inputSourcePath = stringInput(request.input, "source_path");
12977
+ if (inputSourcePath && sourcePath !== inputSourcePath)
12978
+ mismatch("source_path");
12979
+ }
12980
+ function checkCaseAuthoring(receipt, request) {
12981
+ checkBrandId(receipt.brand_id, request);
12982
+ const inputAgentId = stringInput(request.input, "agent_id");
12983
+ if (inputAgentId && !sameId(receipt.agent_id, inputAgentId))
12984
+ mismatch("agent_id");
12985
+ checkCaseId(receipt.case_id, request);
12986
+ checkSourcePath(receipt.source_path, request);
12987
+ }
12988
+ function checkCaseRetire(receipt, request) {
12989
+ checkBrandId(receipt.brand_id, request);
12990
+ checkCaseId(receipt.case_id, request);
12991
+ checkSourcePath(receipt.source_path, request);
12992
+ const commandId = stringInput(request.input, "command_id");
12993
+ if (commandId && receipt.command_id !== commandId) mismatch("command_id");
12994
+ }
12995
+ function checkCaseRefs(receipt, request) {
12996
+ checkInvestigationOperation(receipt, request);
12997
+ const claimKeys = Array.isArray(request.input.claim_keys) ? request.input.claim_keys.filter((k) => typeof k === "string") : [];
12998
+ const receiptKeys = new Set(receipt.claims.map((c) => c.key));
12999
+ if (claimKeys.some((key) => !receiptKeys.has(key))) mismatch("claim_keys");
13000
+ }
13001
+ function parseEvalManagementOperationData(call, data, selectedOrgId) {
13002
+ const contract = RECEIPT_CONTRACTS.get(call.operation);
13003
+ if (!contract) return data;
13004
+ const parsed = contract.parse(data);
13005
+ contract.verify(parsed, {
13006
+ input: call.input,
13007
+ inputId: stringInput(call.input, "id"),
13008
+ inputBrandId: stringInput(call.input, "brand_id"),
13009
+ selectedOrgId,
13010
+ action: call.operation.split(".")[1]
13011
+ });
13021
13012
  return parsed;
13022
13013
  }
13023
- var EvalManagementOperationSchema, EvalManagementBindingSchema, EvalManagementCatalogBindingSchema, EvalManagementInputHelpSchema, EVAL_MANAGEMENT_INPUTS, common, EVAL_MANAGEMENT_BINDINGS, EvalManagementCatalogResponseSchema, EvalManagementCallSchema, EvalManagementScopeSchema, InvestigationPublicationReceiptSchema, InvestigationAuthoringDataSchema, InvestigationControlReceiptSchema, InvestigationDecisionReceiptSchema, InvestigationWaveMemberReceiptSchema, InvestigationWaveCreateReceiptSchema, InvestigationWaveUpdateReceiptSchema, InvestigationWaveScheduleReceiptSchema, CaseAuthoringReceiptSchema, CaseRetireReceiptSchema, CaseRefsReceiptSchema, EvalManagementCatalogResultSchema, EvalManagementResultSchema, EvalManagementWriteErrorSchema;
13014
+ var EvalManagementOperationSchema, EvalManagementBindingSchema, EvalManagementCatalogBindingSchema, EvalManagementInputHelpSchema, EVAL_MANAGEMENT_INPUTS, common, EVAL_MANAGEMENT_BINDINGS, EvalManagementCatalogResponseSchema, EvalManagementCallSchema, EvalManagementScopeSchema, InvestigationPublicationReceiptSchema, InvestigationAuthoringDataSchema, InvestigationControlReceiptSchema, InvestigationDecisionReceiptSchema, InvestigationWaveMemberReceiptSchema, InvestigationWaveCreateReceiptSchema, InvestigationWaveUpdateReceiptSchema, InvestigationWaveScheduleReceiptSchema, CaseAuthoringReceiptSchema, CaseRetireReceiptSchema, CaseRefsReceiptSchema, RECEIPT_CONTRACTS, EvalManagementCatalogResultSchema, EvalManagementResultSchema, EvalManagementWriteErrorSchema;
13024
13015
  var init_eval_management = __esm({
13025
13016
  "../../src/lib/api-contracts/cli/eval-management.ts"() {
13026
13017
  init_zod();
@@ -13671,6 +13662,92 @@ var init_eval_management = __esm({
13671
13662
  ),
13672
13663
  publication: InvestigationPublicationReceiptSchema
13673
13664
  }).passthrough();
13665
+ RECEIPT_CONTRACTS = /* @__PURE__ */ new Map([
13666
+ ["investigation.create", receiptContract(InvestigationAuthoringDataSchema)],
13667
+ [
13668
+ "investigation.update",
13669
+ receiptContract(InvestigationAuthoringDataSchema, checkInvestigationUpdate)
13670
+ ],
13671
+ [
13672
+ "investigation.hold",
13673
+ receiptContract(
13674
+ InvestigationControlReceiptSchema,
13675
+ checkInvestigationOperation
13676
+ )
13677
+ ],
13678
+ [
13679
+ "investigation.resume",
13680
+ receiptContract(
13681
+ InvestigationControlReceiptSchema,
13682
+ checkInvestigationOperation
13683
+ )
13684
+ ],
13685
+ [
13686
+ "investigation.cancel",
13687
+ receiptContract(
13688
+ InvestigationControlReceiptSchema,
13689
+ checkInvestigationOperation
13690
+ )
13691
+ ],
13692
+ [
13693
+ "investigation.conclude_claim",
13694
+ receiptContract(
13695
+ InvestigationDecisionReceiptSchema,
13696
+ checkInvestigationOperation
13697
+ )
13698
+ ],
13699
+ [
13700
+ "investigation.retire_claim",
13701
+ receiptContract(
13702
+ InvestigationDecisionReceiptSchema,
13703
+ checkInvestigationOperation
13704
+ )
13705
+ ],
13706
+ [
13707
+ "investigation.close",
13708
+ receiptContract(
13709
+ InvestigationDecisionReceiptSchema,
13710
+ checkInvestigationOperation
13711
+ )
13712
+ ],
13713
+ [
13714
+ "investigation.reopen",
13715
+ receiptContract(
13716
+ InvestigationDecisionReceiptSchema,
13717
+ checkInvestigationOperation
13718
+ )
13719
+ ],
13720
+ [
13721
+ "investigation.retire",
13722
+ receiptContract(
13723
+ InvestigationDecisionReceiptSchema,
13724
+ checkInvestigationOperation
13725
+ )
13726
+ ],
13727
+ [
13728
+ "wave.create",
13729
+ receiptContract(InvestigationWaveCreateReceiptSchema, checkWaveCreate)
13730
+ ],
13731
+ [
13732
+ "wave.update",
13733
+ receiptContract(InvestigationWaveUpdateReceiptSchema, checkWaveUpdate)
13734
+ ],
13735
+ [
13736
+ "wave.schedule",
13737
+ receiptContract(InvestigationWaveScheduleReceiptSchema, checkWaveSchedule)
13738
+ ],
13739
+ [
13740
+ "case.create",
13741
+ receiptContract(CaseAuthoringReceiptSchema, checkCaseAuthoring)
13742
+ ],
13743
+ [
13744
+ "case.update",
13745
+ receiptContract(CaseAuthoringReceiptSchema, checkCaseAuthoring)
13746
+ ],
13747
+ ["case.retire", receiptContract(CaseRetireReceiptSchema, checkCaseRetire)],
13748
+ ["case.attach", receiptContract(CaseRefsReceiptSchema, checkCaseRefs)],
13749
+ ["case.detach", receiptContract(CaseRefsReceiptSchema, checkCaseRefs)]
13750
+ ]);
13674
13751
  EvalManagementCatalogResultSchema = EvalManagementCatalogResponseSchema.extend({
13675
13752
  scope: EvalManagementScopeSchema.optional()
13676
13753
  });
@@ -15967,13 +16044,19 @@ async function parseError(res, options = {}) {
15967
16044
  }
15968
16045
  const nested = typeof body.error === "object" ? body.error : void 0;
15969
16046
  const flatError = typeof body.error === "string" ? body.error : void 0;
15970
- let message = nested?.message ?? body.message ?? flatError ?? `HTTP ${res.status} from ${res.url}`;
16047
+ let message = saveRefusalMessage(options.saveReason, body.reason) ?? nested?.message ?? body.message ?? flatError ?? `HTTP ${res.status} from ${res.url}`;
15971
16048
  const code = nested?.code ?? flatError;
15972
16049
  if (res.status === 401 && !options.preserveMessage) {
15973
16050
  message += " \u2014 run `bamboo-agents login` to re-authenticate.";
15974
16051
  }
15975
16052
  return new ApiError(message, res.status, code, nested?.details);
15976
16053
  }
16054
+ function saveRefusalMessage(enabled, reason) {
16055
+ if (!enabled || !reason) return void 0;
16056
+ if (reason === "lifecycle_not_allowed")
16057
+ return "Only the person who created this page or a team admin can archive it.";
16058
+ return reason;
16059
+ }
15977
16060
  function userAgent() {
15978
16061
  const nodeVersion = process.versions.node;
15979
16062
  const plat = platform2();
@@ -16061,7 +16144,7 @@ async function saveKnowledge(bambooSession, body) {
16061
16144
  },
16062
16145
  body: JSON.stringify(body)
16063
16146
  });
16064
- if (!res.ok) throw await parseError(res);
16147
+ if (!res.ok) throw await parseError(res, { saveReason: true });
16065
16148
  const json = await res.json();
16066
16149
  return KnowledgeSaveResponseSchema.parse(json);
16067
16150
  }
@@ -16103,7 +16186,7 @@ async function saveWorkspace(bambooSession, body) {
16103
16186
  },
16104
16187
  body: JSON.stringify(body)
16105
16188
  });
16106
- if (!res.ok) throw await parseError(res);
16189
+ if (!res.ok) throw await parseError(res, { saveReason: true });
16107
16190
  const json = await res.json();
16108
16191
  return SaveBatchResponseSchema.parse(json);
16109
16192
  }
@@ -19196,7 +19279,7 @@ function reportSaveError(err, opts) {
19196
19279
  emitError(
19197
19280
  {
19198
19281
  code: "forbidden",
19199
- message: "couldn't save \u2014 you don't have permission to change some of these files.",
19282
+ message: err.message,
19200
19283
  hint: "Ask an org admin to review, or edit only your own brand/agent files."
19201
19284
  },
19202
19285
  opts,
@@ -19316,6 +19399,7 @@ async function runSave(intent, options = {}) {
19316
19399
  saved: 0,
19317
19400
  live: 0,
19318
19401
  queued: 0,
19402
+ landing: 0,
19319
19403
  skipped: skipped.length,
19320
19404
  pr_url: null,
19321
19405
  files: []
@@ -19355,10 +19439,13 @@ async function runSave(intent, options = {}) {
19355
19439
  const total = edits.length;
19356
19440
  const live = result.live_count;
19357
19441
  const queued = result.queued_count;
19442
+ const landing = result.pending_count;
19358
19443
  const payload = {
19359
19444
  saved: total,
19360
19445
  live,
19361
19446
  queued,
19447
+ landing,
19448
+ change_id: result.change_id,
19362
19449
  skipped: skipped.length,
19363
19450
  pr_url: result.pr_url ?? null,
19364
19451
  files: result.files,
@@ -19366,6 +19453,13 @@ async function runSave(intent, options = {}) {
19366
19453
  };
19367
19454
  emitSuccess(payload, opts, () => {
19368
19455
  human("", opts);
19456
+ if (landing > 0) {
19457
+ human(
19458
+ dryRun ? ` Dry run: ${landing} files would be landing. Nothing written.` : ` Landing ${landing} files \u2014 Bamboo will show them in a few minutes.`,
19459
+ opts
19460
+ );
19461
+ return;
19462
+ }
19369
19463
  const verb = dryRun ? "would go live" : "live";
19370
19464
  const qverb = dryRun ? "would queue for review" : "queued for review";
19371
19465
  const parts = [];
@@ -21397,6 +21491,9 @@ function printSaveResult(result, path2, opts) {
21397
21491
  case "auto":
21398
21492
  human(` \u2713 Saved \u2014 auto-merged to main (${path2})`, opts);
21399
21493
  break;
21494
+ case "pending":
21495
+ human(" Landing \u2014 Bamboo will show it in a few minutes.", opts);
21496
+ break;
21400
21497
  case "queued":
21401
21498
  case "submitted":
21402
21499
  human(