@debugbundle/cli 0.1.7 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/main.cjs +1353 -140
  2. package/package.json +1 -1
package/dist/main.cjs CHANGED
@@ -14507,6 +14507,7 @@ var CapturePolicyOverridesSchema = external_exports.object({
14507
14507
  immediate_client_error_statuses: ImmediateClientErrorStatusesSchema.nullable()
14508
14508
  });
14509
14509
  var CapturePolicyResponseSchema = external_exports.object({
14510
+ access_mode: external_exports.enum(["manage", "preview"]),
14510
14511
  policy: ResolvedCapturePolicySchema,
14511
14512
  overrides: CapturePolicyOverridesSchema
14512
14513
  });
@@ -14604,6 +14605,29 @@ function getRequestAnomalyThreshold(input) {
14604
14605
  return null;
14605
14606
  }
14606
14607
 
14608
+ // ../../packages/shared-types/src/improvement-settings.ts
14609
+ var ImprovementBundleSensitivityValues = [
14610
+ "high_confidence",
14611
+ "balanced",
14612
+ "verbose"
14613
+ ];
14614
+ var ImprovementBundleSensitivitySchema = external_exports.enum(ImprovementBundleSensitivityValues);
14615
+ var ImprovementSettingsSchema = external_exports.object({
14616
+ automated_improvement_bundles_enabled: external_exports.boolean(),
14617
+ improvement_bundle_sensitivity: ImprovementBundleSensitivitySchema
14618
+ });
14619
+ var ImprovementSettingsResponseSchema = external_exports.object({
14620
+ access_mode: external_exports.enum(["manage", "preview"]),
14621
+ cloud_automation_available: external_exports.boolean(),
14622
+ settings: ImprovementSettingsSchema
14623
+ });
14624
+ var ImprovementSettingsUpdateSchema = external_exports.object({
14625
+ automated_improvement_bundles_enabled: external_exports.boolean().optional(),
14626
+ improvement_bundle_sensitivity: ImprovementBundleSensitivitySchema.optional()
14627
+ }).refine((input) => Object.keys(input).length > 0, {
14628
+ message: "At least one improvement settings field must be provided."
14629
+ });
14630
+
14607
14631
  // ../../packages/shared-types/src/index.ts
14608
14632
  function createUuidV4() {
14609
14633
  const cryptoSource = globalThis.crypto;
@@ -15173,6 +15197,25 @@ function buildSkill() {
15173
15197
  "",
15174
15198
  "Use DebugBundle before starting a fresh bug investigation.",
15175
15199
  "",
15200
+ "## Investigation Quickstart",
15201
+ "",
15202
+ "When the user reports a bug, runtime failure, production incident, regression, broken deploy, or unknown error, start here before reading arbitrary source files.",
15203
+ "",
15204
+ "1. Run `debugbundle doctor --json` to learn whether the project is local-only or connected and whether the local scaffold is healthy.",
15205
+ "2. List actionable failures with `debugbundle incidents --source local --status open --json` for local data, or `debugbundle incidents --source cloud --status open --json` when the issue came from a hosted environment.",
15206
+ "3. Inspect the chosen incident with `debugbundle inspect <incident-id> --source <local|cloud> --json` and `debugbundle explain <incident-id> --source <local|cloud> --json`.",
15207
+ "4. Fetch evidence before editing code: `debugbundle bundle <incident-id> --source <local|cloud> --json` and `debugbundle reproduce <incident-id> --source <local|cloud> --json`.",
15208
+ "5. If local SDK or relay events have landed but no bundle exists yet, run `debugbundle process --preset <minimal|balanced|investigative> --json` and then list incidents again.",
15209
+ "",
15210
+ "Key local paths:",
15211
+ "- `.debugbundle/profile.json` \u2014 project map, service paths, and validation state",
15212
+ "- `.debugbundle/local/connection.json` \u2014 local-only vs connected mode and environment delivery policy",
15213
+ "- `.debugbundle/local/events/` \u2014 raw local SDK, relay, ingest, and watch event batches",
15214
+ "- `.debugbundle/local/state.json` \u2014 local incident index, lifecycle state, and bundle paths",
15215
+ "- `.debugbundle/bundles/local/` \u2014 locally generated bundle artifacts",
15216
+ "- `.debugbundle/bundles/local/reproductions/` \u2014 local reproduction artifacts",
15217
+ "- `.debugbundle/bundles/cloud/` \u2014 explicitly fetched cloud artifact cache",
15218
+ "",
15176
15219
  "## Core Workflow",
15177
15220
  "",
15178
15221
  "1. Check DebugBundle incidents first to avoid re-investigating a known failure.",
@@ -15223,23 +15266,35 @@ function buildCliReference() {
15223
15266
  "## Setup",
15224
15267
  "",
15225
15268
  "- `debugbundle setup [--non-interactive] [--json]`",
15226
- "- `debugbundle doctor [--json]`",
15269
+ "- `debugbundle doctor [--check-relay] [--json]`",
15227
15270
  "- `debugbundle validate [--fix] [--json]`",
15228
15271
  "- `debugbundle ingest <file> --format <format> [--json]`",
15229
15272
  "- `debugbundle watch --log <file> --format <format> [--json]`",
15230
15273
  "- `debugbundle watch --cloud --log <file> --format <format> [--json]`",
15231
15274
  "- `debugbundle process [--preset <minimal|balanced|investigative>] [--json]`",
15275
+ "- `debugbundle clean [--events] [--bundles] [--all] [--older-than <Nd>] [--json]`",
15232
15276
  "",
15233
15277
  "## Investigation",
15234
15278
  "",
15235
- "- `debugbundle incidents`",
15236
- "- `debugbundle inspect <incident-id>`",
15237
- "- `debugbundle bundle <incident-id>`",
15238
- "- `debugbundle reproduce <incident-id>`",
15239
- "- `debugbundle resolve <incident-id>`",
15240
- "- `debugbundle reopen <incident-id>`",
15279
+ "- `debugbundle incidents [--source <local|cloud>] [--project-id <id>] [--environment <name>] [--service <name>] [--status <status>] [--severity <severity>] [--cursor <cursor>] [--limit <n>] [--json]`",
15280
+ "- `debugbundle inspect <incident-id> [--source <local|cloud>] [--json]`",
15281
+ "- `debugbundle explain <incident-id> [--source <local|cloud>] [--json]`",
15282
+ "- `debugbundle bundle <incident-id> [--source <local|cloud>] [--json]`",
15283
+ "- `debugbundle reproduce <incident-id> [--source <local|cloud>] [--json]`",
15284
+ "- `debugbundle resolve <incident-id> [--source <local|cloud>] [--json]`",
15285
+ "- `debugbundle reopen <incident-id> [--source <local|cloud>] [--json]`",
15241
15286
  "- `debugbundle analyze --type improvement --local`",
15242
15287
  "",
15288
+ "## Operational Paths",
15289
+ "",
15290
+ "- `.debugbundle/profile.json` \u2014 committed project map and agent validation state",
15291
+ "- `.debugbundle/local/connection.json` \u2014 committed delivery policy and cloud connection metadata",
15292
+ "- `.debugbundle/local/events/` \u2014 gitignored raw local event batches",
15293
+ "- `.debugbundle/local/state.json` \u2014 gitignored local incident index and lifecycle state",
15294
+ "- `.debugbundle/bundles/local/` \u2014 gitignored local bundle artifacts",
15295
+ "- `.debugbundle/bundles/local/reproductions/` \u2014 gitignored local reproduction artifacts",
15296
+ "- `.debugbundle/bundles/cloud/` \u2014 gitignored cache for explicitly fetched cloud artifacts",
15297
+ "",
15243
15298
  "## Incident Hygiene",
15244
15299
  "",
15245
15300
  "Resolve incidents after a fix is verified or after an intentional smoke, dogfood, or verification incident has served its purpose.",
@@ -15271,6 +15326,17 @@ function buildMcpReference() {
15271
15326
  "",
15272
15327
  "Use the same incident-first workflow through MCP when an agent is operating in connected mode.",
15273
15328
  "",
15329
+ "## Investigation Tools",
15330
+ "",
15331
+ "- `doctor` \u2014 validate local profile, connection config, auth state, and setup health.",
15332
+ "- `list_incidents` \u2014 list local, cloud, or connected combined incidents; pass `source`, `status`, `environment`, `service`, `severity`, `cursor`, and `limit` when needed.",
15333
+ "- `get_incident` \u2014 fetch incident metadata by incident id.",
15334
+ "- `get_incident_context` \u2014 fetch deterministic explanation context for triage.",
15335
+ "- `get_bundle` \u2014 fetch the full debug bundle before proposing a fix.",
15336
+ "- `get_reproduction` \u2014 fetch reproduction guidance before editing code.",
15337
+ "- `resolve_incident` / `reopen_incident` \u2014 update lifecycle state after validation.",
15338
+ "- `analyze` \u2014 run local agent-oriented analysis from local bundles and skill schemas.",
15339
+ "",
15274
15340
  "- Prefer bundle retrieval tools before reading raw repository files.",
15275
15341
  "- Use MCP bundle access when the current issue originated in production.",
15276
15342
  "- Resolve fixed or intentionally generated incidents with `resolve_incident` so open incidents stay actionable.",
@@ -15294,8 +15360,12 @@ function buildBundleSchemaReference() {
15294
15360
  "Focus on:",
15295
15361
  "- `summary` for the failure synopsis and recommended action",
15296
15362
  "- `service` and `environment` for routing to the right code path",
15363
+ "- `context.error`, `context.request`, `context.response`, `context.logs`, `context.frontend`, `context.runtime`, `context.git`, `context.dependencies`, and `context.probe_data` for supporting evidence",
15364
+ "- `reproduction` for confidence, commands, and manual steps",
15297
15365
  "- `links.reproduction` for the generated reproduction artifact",
15298
15366
  "- `metadata.source` for whether the bundle came from local or cloud data",
15367
+ "",
15368
+ "Treat the bundle as the source of truth for the failure report. Use repository reads to confirm and patch the implicated code paths, not to rediscover incident context from scratch.",
15299
15369
  ""
15300
15370
  ].join("\n");
15301
15371
  }
@@ -15306,10 +15376,12 @@ function buildProfileEnrichmentReference() {
15306
15376
  "The setup profile is generated from static analysis and must be reviewed before agents rely on it for architecture decisions.",
15307
15377
  "",
15308
15378
  "Checklist:",
15309
- "- verify service kinds, frameworks, and runtime assumptions",
15310
- "- add critical paths and ownership notes",
15311
- "- confirm build, test, and lint workflows",
15312
- "- update `debugbundle.validation_status` to `agent-validated` when complete",
15379
+ "- verify `project.primary_languages`, `project.package_managers`, and `project.deployment_targets`",
15380
+ "- verify each service `kind`, `runtime`, `framework`, `paths`, `owns_routes`, and `depends_on` value against the repository",
15381
+ "- add critical paths for ingestion, processing, retrieval, SDK capture, auth, billing, and any project-specific high-risk workflows",
15382
+ "- confirm `repo.generated_paths` and `repo.do_not_edit_paths` match the local scaffold",
15383
+ "- confirm build, test, lint, and install workflows in `developer_workflows`",
15384
+ "- update `debugbundle.last_reviewed_at` and set `debugbundle.validation_status` to `agent-validated` when complete",
15313
15385
  ""
15314
15386
  ].join("\n");
15315
15387
  }
@@ -15391,6 +15463,22 @@ function buildSkillEvals() {
15391
15463
  "Resolve verified or intentionally generated incidents after the workflow is complete.",
15392
15464
  "Leave unresolved incidents open when the failure is still live or unverified."
15393
15465
  ]
15466
+ },
15467
+ {
15468
+ name: "artifact_path_discovery",
15469
+ prompt: "The user reports an unknown local runtime error. Confirm the skill tells the agent which DebugBundle paths and commands to inspect first.",
15470
+ expected_behavior: [
15471
+ "Run doctor and list local open incidents before broad source exploration.",
15472
+ "Use .debugbundle/local/state.json, .debugbundle/bundles/local/, and reproduction artifact paths as the local evidence map."
15473
+ ]
15474
+ },
15475
+ {
15476
+ name: "connected_incident_fetch",
15477
+ prompt: "The user says a production incident fired in the hosted DebugBundle project. Confirm the skill points the agent to the cloud retrieval path.",
15478
+ expected_behavior: [
15479
+ "List cloud open incidents or use MCP list_incidents with source cloud.",
15480
+ "Fetch inspect, context, bundle, and reproduction artifacts before editing code."
15481
+ ]
15394
15482
  }
15395
15483
  ]
15396
15484
  },
@@ -15802,6 +15890,35 @@ var IncidentSchema = external_exports.object({
15802
15890
  matched_fields: external_exports.array(external_exports.string()),
15803
15891
  incident_reason: IncidentReasonSchema.optional()
15804
15892
  }).strict();
15893
+ var ImprovementSchema = external_exports.object({
15894
+ improvement_id: external_exports.string(),
15895
+ project_id: external_exports.string(),
15896
+ project_name: external_exports.string(),
15897
+ project_slug: external_exports.string(),
15898
+ service_id: external_exports.string().nullable(),
15899
+ service_name: external_exports.string(),
15900
+ service_runtime: external_exports.string().nullable(),
15901
+ service_framework: external_exports.string().nullable(),
15902
+ environment: external_exports.string(),
15903
+ kind: external_exports.enum(["warning_hotspot", "slow_request", "request_failure_pattern", "recurring_incident", "post_deploy_regression"]),
15904
+ status: external_exports.enum(["open", "resolved", "snoozed"]),
15905
+ severity: external_exports.enum(["low", "medium", "high", "critical"]),
15906
+ confidence: external_exports.number(),
15907
+ fingerprint: external_exports.string(),
15908
+ title: external_exports.string(),
15909
+ summary: external_exports.string(),
15910
+ occurrence_count: external_exports.number().int(),
15911
+ evidence: external_exports.record(external_exports.unknown()),
15912
+ related_incident_ids: external_exports.array(external_exports.string()),
15913
+ first_detected_at: external_exports.string(),
15914
+ last_detected_at: external_exports.string(),
15915
+ resolved_at: external_exports.string().nullable(),
15916
+ snoozed_until: external_exports.string().nullable(),
15917
+ bundle_generation_number: external_exports.number().int(),
15918
+ bundle_created_at: external_exports.string().nullable(),
15919
+ bundle_updated_at: external_exports.string().nullable(),
15920
+ bundle_failure_reason: external_exports.string().nullable()
15921
+ }).strict();
15805
15922
  var ServiceSchema3 = external_exports.object({
15806
15923
  service_id: external_exports.string(),
15807
15924
  project_id: external_exports.string(),
@@ -15824,6 +15941,9 @@ var IncidentsResponseSchema = external_exports.object({
15824
15941
  var IncidentResponseSchema = external_exports.object({
15825
15942
  incident: IncidentSchema
15826
15943
  }).strict();
15944
+ var ImprovementResponseSchema = external_exports.object({
15945
+ improvement: ImprovementSchema
15946
+ }).strict();
15827
15947
  var IncidentContextArtifactSchema = external_exports.object({
15828
15948
  status: external_exports.enum(["ready", "pending", "failed"]),
15829
15949
  body: external_exports.unknown().optional(),
@@ -15894,6 +16014,10 @@ var IncidentContextSchema = external_exports.object({
15894
16014
  var ServicesResponseSchema = external_exports.object({
15895
16015
  services: external_exports.array(ServiceSchema3)
15896
16016
  }).strict();
16017
+ var ImprovementsResponseSchema = external_exports.object({
16018
+ improvements: external_exports.array(ImprovementSchema),
16019
+ next_cursor: external_exports.string().nullable().optional()
16020
+ }).strict();
15897
16021
  var LogsResponseSchema = external_exports.object({
15898
16022
  logs: external_exports.array(LogSchema),
15899
16023
  next_cursor: external_exports.string().nullable().optional()
@@ -16092,6 +16216,108 @@ function createRetrievalApi(client) {
16092
16216
  bearerToken: input.bearerToken
16093
16217
  })
16094
16218
  );
16219
+ },
16220
+ async listImprovements(input) {
16221
+ const query = new URLSearchParams();
16222
+ if (input.projectId !== void 0) {
16223
+ query.set("project_id", input.projectId);
16224
+ }
16225
+ if (input.environment !== void 0) {
16226
+ query.set("environment", input.environment);
16227
+ }
16228
+ if (input.service !== void 0) {
16229
+ query.set("service", input.service);
16230
+ }
16231
+ if (input.status !== void 0) {
16232
+ query.set("status", input.status);
16233
+ }
16234
+ if (input.severity !== void 0) {
16235
+ query.set("severity", input.severity);
16236
+ }
16237
+ if (input.kind !== void 0) {
16238
+ query.set("kind", input.kind);
16239
+ }
16240
+ if (input.cursor !== void 0) {
16241
+ query.set("cursor", input.cursor);
16242
+ }
16243
+ if (input.limit !== void 0) {
16244
+ query.set("limit", String(input.limit));
16245
+ }
16246
+ const path = query.size > 0 ? `/v1/improvements?${query.toString()}` : "/v1/improvements";
16247
+ const parsed = await expectParsed(
16248
+ client.request({
16249
+ method: "GET",
16250
+ path,
16251
+ bearerToken: input.bearerToken
16252
+ }),
16253
+ ImprovementsResponseSchema
16254
+ );
16255
+ return {
16256
+ improvements: parsed.improvements,
16257
+ next_cursor: parsed.next_cursor ?? null
16258
+ };
16259
+ },
16260
+ async getImprovement(input) {
16261
+ const parsed = await expectParsed(
16262
+ client.request({
16263
+ method: "GET",
16264
+ path: `/v1/improvements/${input.improvementId}`,
16265
+ bearerToken: input.bearerToken
16266
+ }),
16267
+ ImprovementResponseSchema
16268
+ );
16269
+ return parsed.improvement;
16270
+ },
16271
+ async resolveImprovement(input) {
16272
+ const parsed = await expectParsed(
16273
+ client.request({
16274
+ method: "POST",
16275
+ path: `/v1/improvements/${input.improvementId}/resolve`,
16276
+ bearerToken: input.bearerToken
16277
+ }),
16278
+ ImprovementResponseSchema
16279
+ );
16280
+ return parsed.improvement;
16281
+ },
16282
+ async reopenImprovement(input) {
16283
+ const parsed = await expectParsed(
16284
+ client.request({
16285
+ method: "POST",
16286
+ path: `/v1/improvements/${input.improvementId}/reopen`,
16287
+ bearerToken: input.bearerToken
16288
+ }),
16289
+ ImprovementResponseSchema
16290
+ );
16291
+ return parsed.improvement;
16292
+ },
16293
+ async snoozeImprovement(input) {
16294
+ const parsed = await expectParsed(
16295
+ client.request({
16296
+ method: "POST",
16297
+ path: `/v1/improvements/${input.improvementId}/snooze`,
16298
+ bearerToken: input.bearerToken,
16299
+ body: { snoozed_until: input.snoozedUntil }
16300
+ }),
16301
+ ImprovementResponseSchema
16302
+ );
16303
+ return parsed.improvement;
16304
+ },
16305
+ async getImprovementBundle(input) {
16306
+ return await expectParsed(
16307
+ client.request({
16308
+ method: "GET",
16309
+ path: `/v1/projects/${input.projectId}/improvements/${input.improvementId}/bundle`,
16310
+ bearerToken: input.bearerToken
16311
+ }),
16312
+ external_exports.union([
16313
+ PendingStatusSchema,
16314
+ BundleSchema,
16315
+ external_exports.object({
16316
+ status: external_exports.literal("failed"),
16317
+ reason: external_exports.string()
16318
+ }).strict()
16319
+ ])
16320
+ );
16095
16321
  }
16096
16322
  };
16097
16323
  }
@@ -16750,6 +16976,329 @@ var STORAGE_SCHEMA_MIGRATIONS = [
16750
16976
  "ALTER TABLE users ADD COLUMN IF NOT EXISTS avatar_content_type text",
16751
16977
  "ALTER TABLE users ADD COLUMN IF NOT EXISTS avatar_updated_at timestamptz"
16752
16978
  ]
16979
+ }),
16980
+ defineStorageSchemaMigration({
16981
+ id: "202605170001_add_alert_email_digest_queue",
16982
+ description: "Add queued email alert digests and digest items for fixed-window alert batching.",
16983
+ statements: [
16984
+ `
16985
+ CREATE TABLE IF NOT EXISTS alert_email_digests (
16986
+ id uuid PRIMARY KEY,
16987
+ project_id uuid NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
16988
+ recipient text NOT NULL,
16989
+ status text NOT NULL,
16990
+ next_attempt_at timestamptz,
16991
+ claimed_at timestamptz,
16992
+ last_error text,
16993
+ delivered_at timestamptz,
16994
+ created_at timestamptz NOT NULL DEFAULT now(),
16995
+ updated_at timestamptz NOT NULL DEFAULT now()
16996
+ )
16997
+ `,
16998
+ `
16999
+ CREATE UNIQUE INDEX IF NOT EXISTS alert_email_digests_project_recipient_pending_idx
17000
+ ON alert_email_digests (project_id, recipient)
17001
+ WHERE status = 'pending' AND claimed_at IS NULL
17002
+ `,
17003
+ `
17004
+ CREATE INDEX IF NOT EXISTS alert_email_digests_status_next_attempt_idx
17005
+ ON alert_email_digests (status, next_attempt_at)
17006
+ `,
17007
+ `
17008
+ CREATE TABLE IF NOT EXISTS alert_email_digest_items (
17009
+ id uuid PRIMARY KEY,
17010
+ digest_id uuid NOT NULL REFERENCES alert_email_digests(id) ON DELETE CASCADE,
17011
+ alert_id uuid NOT NULL REFERENCES alert_rules(id) ON DELETE CASCADE,
17012
+ project_id uuid NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
17013
+ incident_id uuid NOT NULL REFERENCES incidents(id) ON DELETE CASCADE,
17014
+ condition_type text NOT NULL,
17015
+ dedupe_key text NOT NULL,
17016
+ payload jsonb NOT NULL,
17017
+ created_at timestamptz NOT NULL DEFAULT now(),
17018
+ UNIQUE (alert_id, incident_id, dedupe_key)
17019
+ )
17020
+ `,
17021
+ `
17022
+ CREATE INDEX IF NOT EXISTS alert_email_digest_items_digest_created_idx
17023
+ ON alert_email_digest_items (digest_id, created_at ASC)
17024
+ `
17025
+ ]
17026
+ }),
17027
+ defineStorageSchemaMigration({
17028
+ id: "202605180001_add_skipped_github_dispatch_status",
17029
+ description: "Allow GitHub dispatch delivery history to record rate-limited skips without retrying them.",
17030
+ statements: [
17031
+ "ALTER TABLE github_dispatch_deliveries DROP CONSTRAINT IF EXISTS github_dispatch_deliveries_status_check",
17032
+ "ALTER TABLE github_dispatch_deliveries ADD CONSTRAINT github_dispatch_deliveries_status_check CHECK (status IN ('pending', 'retrying', 'delivered', 'failed', 'skipped'))"
17033
+ ]
17034
+ }),
17035
+ defineStorageSchemaMigration({
17036
+ id: "202605180002_add_project_improvement_settings",
17037
+ description: "Add project-level automated improvement settings columns.",
17038
+ statements: [
17039
+ "ALTER TABLE projects ADD COLUMN IF NOT EXISTS automated_improvement_bundles_enabled boolean NOT NULL DEFAULT true",
17040
+ "ALTER TABLE projects ADD COLUMN IF NOT EXISTS improvement_bundle_sensitivity text NOT NULL DEFAULT 'balanced'",
17041
+ `
17042
+ ALTER TABLE projects
17043
+ DROP CONSTRAINT IF EXISTS projects_improvement_bundle_sensitivity_check
17044
+ `,
17045
+ `
17046
+ ALTER TABLE projects
17047
+ ADD CONSTRAINT projects_improvement_bundle_sensitivity_check
17048
+ CHECK (improvement_bundle_sensitivity IN ('high_confidence', 'balanced', 'verbose'))
17049
+ `
17050
+ ]
17051
+ }),
17052
+ defineStorageSchemaMigration({
17053
+ id: "202605180003_add_improvement_opportunities_and_bundle_generation_shape",
17054
+ description: "Add hosted improvement opportunity storage and allow bundle generations to reference improvements directly.",
17055
+ statements: [
17056
+ `
17057
+ CREATE TABLE IF NOT EXISTS improvement_opportunities (
17058
+ id uuid PRIMARY KEY,
17059
+ project_id uuid NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
17060
+ service_id uuid REFERENCES services(id) ON DELETE SET NULL,
17061
+ service_name text NOT NULL,
17062
+ environment text NOT NULL DEFAULT 'production',
17063
+ kind text NOT NULL,
17064
+ status text NOT NULL DEFAULT 'open',
17065
+ severity text NOT NULL,
17066
+ confidence numeric NOT NULL,
17067
+ fingerprint text NOT NULL,
17068
+ title text NOT NULL,
17069
+ summary text NOT NULL,
17070
+ occurrence_count integer NOT NULL DEFAULT 1,
17071
+ evidence jsonb NOT NULL,
17072
+ first_detected_at timestamptz NOT NULL,
17073
+ last_detected_at timestamptz NOT NULL,
17074
+ last_source_event_id uuid,
17075
+ related_incident_ids uuid[] NOT NULL DEFAULT '{}',
17076
+ bundle_generation_number integer NOT NULL DEFAULT 0,
17077
+ bundle_created_at timestamptz,
17078
+ bundle_updated_at timestamptz,
17079
+ bundle_source_event_id uuid,
17080
+ bundle_failure_reason text,
17081
+ resolved_at timestamptz,
17082
+ resolved_by_user_id uuid REFERENCES users(id) ON DELETE SET NULL,
17083
+ snoozed_until timestamptz,
17084
+ created_at timestamptz NOT NULL DEFAULT now(),
17085
+ updated_at timestamptz NOT NULL DEFAULT now(),
17086
+ UNIQUE (project_id, fingerprint)
17087
+ )
17088
+ `,
17089
+ `
17090
+ CREATE INDEX IF NOT EXISTS improvement_opportunities_project_status_detected_idx
17091
+ ON improvement_opportunities (project_id, status, last_detected_at DESC)
17092
+ `,
17093
+ `
17094
+ CREATE INDEX IF NOT EXISTS improvement_opportunities_project_kind_detected_idx
17095
+ ON improvement_opportunities (project_id, kind, last_detected_at DESC)
17096
+ `,
17097
+ `
17098
+ CREATE INDEX IF NOT EXISTS improvement_opportunities_project_service_env_idx
17099
+ ON improvement_opportunities (project_id, service_id, environment)
17100
+ `,
17101
+ `
17102
+ CREATE TABLE IF NOT EXISTS improvement_opportunity_events (
17103
+ improvement_opportunity_id uuid NOT NULL REFERENCES improvement_opportunities(id) ON DELETE CASCADE,
17104
+ event_id uuid NOT NULL,
17105
+ event_type text NOT NULL,
17106
+ occurred_at timestamptz NOT NULL,
17107
+ PRIMARY KEY (improvement_opportunity_id, event_id)
17108
+ )
17109
+ `,
17110
+ `
17111
+ CREATE INDEX IF NOT EXISTS improvement_opportunity_events_detected_idx
17112
+ ON improvement_opportunity_events (improvement_opportunity_id, occurred_at DESC, event_id DESC)
17113
+ `,
17114
+ "ALTER TABLE bundle_generations ALTER COLUMN incident_id DROP NOT NULL",
17115
+ "ALTER TABLE bundle_generations ADD COLUMN IF NOT EXISTS improvement_opportunity_id uuid REFERENCES improvement_opportunities(id) ON DELETE CASCADE",
17116
+ "ALTER TABLE bundle_generations DROP CONSTRAINT IF EXISTS bundle_generations_incident_id_source_event_id_key",
17117
+ "DROP INDEX IF EXISTS bundle_generations_incident_source_idx",
17118
+ "DROP INDEX IF EXISTS bundle_generations_improvement_source_idx",
17119
+ `
17120
+ CREATE UNIQUE INDEX IF NOT EXISTS bundle_generations_incident_source_idx
17121
+ ON bundle_generations (incident_id, source_event_id)
17122
+ WHERE incident_id IS NOT NULL
17123
+ `,
17124
+ `
17125
+ CREATE UNIQUE INDEX IF NOT EXISTS bundle_generations_improvement_source_idx
17126
+ ON bundle_generations (improvement_opportunity_id, source_event_id)
17127
+ WHERE improvement_opportunity_id IS NOT NULL
17128
+ `,
17129
+ "DROP INDEX IF EXISTS bundle_generations_improvement_generation_idx",
17130
+ `
17131
+ CREATE INDEX IF NOT EXISTS bundle_generations_improvement_generation_idx
17132
+ ON bundle_generations (improvement_opportunity_id, generation_number DESC)
17133
+ WHERE improvement_opportunity_id IS NOT NULL
17134
+ `,
17135
+ "ALTER TABLE bundle_generations DROP CONSTRAINT IF EXISTS bundle_generations_owner_check",
17136
+ `
17137
+ ALTER TABLE bundle_generations
17138
+ ADD CONSTRAINT bundle_generations_owner_check CHECK (
17139
+ (incident_id IS NOT NULL AND improvement_opportunity_id IS NULL AND bundle_type = 'failure')
17140
+ OR (incident_id IS NULL AND improvement_opportunity_id IS NOT NULL AND bundle_type = 'improvement')
17141
+ )
17142
+ `
17143
+ ]
17144
+ }),
17145
+ defineStorageSchemaMigration({
17146
+ id: "202605180004_add_operational_email_deliveries",
17147
+ description: "Add durable operational email delivery queue with retries and dedupe.",
17148
+ statements: [
17149
+ `
17150
+ CREATE TABLE IF NOT EXISTS operational_email_deliveries (
17151
+ id uuid PRIMARY KEY,
17152
+ organization_id uuid NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
17153
+ project_id uuid NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
17154
+ kind text NOT NULL,
17155
+ dedupe_key text NOT NULL,
17156
+ payload jsonb NOT NULL DEFAULT '{}'::jsonb,
17157
+ status text NOT NULL DEFAULT 'pending',
17158
+ attempt_count integer NOT NULL DEFAULT 0,
17159
+ next_attempt_at timestamptz,
17160
+ last_error text,
17161
+ delivered_at timestamptz,
17162
+ created_at timestamptz NOT NULL DEFAULT now(),
17163
+ updated_at timestamptz NOT NULL DEFAULT now(),
17164
+ UNIQUE (organization_id, kind, dedupe_key)
17165
+ )
17166
+ `,
17167
+ `
17168
+ ALTER TABLE operational_email_deliveries
17169
+ DROP CONSTRAINT IF EXISTS operational_email_deliveries_kind_check
17170
+ `,
17171
+ `
17172
+ ALTER TABLE operational_email_deliveries
17173
+ ADD CONSTRAINT operational_email_deliveries_kind_check
17174
+ CHECK (kind IN ('webhook_auto_disabled', 'allowance_warning_80', 'allowance_limit_reached', 'retention_rotation_notice'))
17175
+ `,
17176
+ `
17177
+ ALTER TABLE operational_email_deliveries
17178
+ DROP CONSTRAINT IF EXISTS operational_email_deliveries_status_check
17179
+ `,
17180
+ `
17181
+ ALTER TABLE operational_email_deliveries
17182
+ ADD CONSTRAINT operational_email_deliveries_status_check
17183
+ CHECK (status IN ('pending', 'retrying', 'delivered', 'failed'))
17184
+ `,
17185
+ `
17186
+ CREATE INDEX IF NOT EXISTS operational_email_deliveries_status_next_attempt_idx
17187
+ ON operational_email_deliveries (status, next_attempt_at, created_at)
17188
+ `
17189
+ ]
17190
+ }),
17191
+ defineStorageSchemaMigration({
17192
+ id: "202605180005_add_github_improvement_dispatch_targets",
17193
+ description: "Allow GitHub dispatch deliveries to target either incidents or hosted improvements.",
17194
+ statements: [
17195
+ "ALTER TABLE github_dispatch_deliveries ALTER COLUMN incident_id DROP NOT NULL",
17196
+ "ALTER TABLE github_dispatch_deliveries RENAME COLUMN incident_fingerprint TO target_fingerprint",
17197
+ "ALTER TABLE github_dispatch_deliveries ADD COLUMN IF NOT EXISTS improvement_opportunity_id uuid REFERENCES improvement_opportunities(id) ON DELETE CASCADE",
17198
+ "DROP INDEX IF EXISTS github_dispatch_deliveries_rule_dedupe_key_idx",
17199
+ `
17200
+ CREATE UNIQUE INDEX IF NOT EXISTS github_dispatch_deliveries_rule_dedupe_key_idx
17201
+ ON github_dispatch_deliveries (rule_id, target_fingerprint, dedupe_key)
17202
+ `,
17203
+ "ALTER TABLE github_dispatch_deliveries DROP CONSTRAINT IF EXISTS github_dispatch_deliveries_check",
17204
+ `
17205
+ ALTER TABLE github_dispatch_deliveries
17206
+ ADD CONSTRAINT github_dispatch_deliveries_check CHECK (
17207
+ (incident_id IS NOT NULL AND improvement_opportunity_id IS NULL)
17208
+ OR (incident_id IS NULL AND improvement_opportunity_id IS NOT NULL)
17209
+ )
17210
+ `
17211
+ ]
17212
+ }),
17213
+ defineStorageSchemaMigration({
17214
+ id: "202605180006_add_missing_bundle_and_creator_columns",
17215
+ description: "Backfill creator ownership columns and incident bundle tracking columns that existed only in bootstrap schema.",
17216
+ statements: [
17217
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_generation_number integer NOT NULL DEFAULT 0",
17218
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_created_at timestamptz",
17219
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_updated_at timestamptz",
17220
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_source_event_id uuid",
17221
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_source_occurred_at timestamptz",
17222
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_trigger text",
17223
+ "ALTER TABLE incidents ADD COLUMN IF NOT EXISTS bundle_failure_reason text",
17224
+ "ALTER TABLE alert_rules ADD COLUMN IF NOT EXISTS created_by_user_id uuid",
17225
+ `
17226
+ UPDATE alert_rules ar
17227
+ SET created_by_user_id = p.owner_user_id
17228
+ FROM projects p
17229
+ WHERE ar.project_id = p.id
17230
+ AND ar.created_by_user_id IS NULL
17231
+ `,
17232
+ "ALTER TABLE alert_rules DROP CONSTRAINT IF EXISTS alert_rules_created_by_user_id_fkey",
17233
+ `
17234
+ ALTER TABLE alert_rules
17235
+ ADD CONSTRAINT alert_rules_created_by_user_id_fkey
17236
+ FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE CASCADE
17237
+ `,
17238
+ "ALTER TABLE alert_rules ALTER COLUMN created_by_user_id SET NOT NULL",
17239
+ "ALTER TABLE agent_webhooks ADD COLUMN IF NOT EXISTS created_by_user_id uuid",
17240
+ `
17241
+ UPDATE agent_webhooks aw
17242
+ SET created_by_user_id = p.owner_user_id
17243
+ FROM projects p
17244
+ WHERE aw.project_id = p.id
17245
+ AND aw.created_by_user_id IS NULL
17246
+ `,
17247
+ "ALTER TABLE agent_webhooks DROP CONSTRAINT IF EXISTS agent_webhooks_created_by_user_id_fkey",
17248
+ `
17249
+ ALTER TABLE agent_webhooks
17250
+ ADD CONSTRAINT agent_webhooks_created_by_user_id_fkey
17251
+ FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE CASCADE
17252
+ `,
17253
+ "ALTER TABLE agent_webhooks ALTER COLUMN created_by_user_id SET NOT NULL",
17254
+ "ALTER TABLE github_dispatch_rules ADD COLUMN IF NOT EXISTS created_by_user_id uuid",
17255
+ `
17256
+ UPDATE github_dispatch_rules gdr
17257
+ SET created_by_user_id = p.owner_user_id
17258
+ FROM projects p
17259
+ WHERE gdr.project_id = p.id
17260
+ AND gdr.created_by_user_id IS NULL
17261
+ `,
17262
+ "ALTER TABLE github_dispatch_rules DROP CONSTRAINT IF EXISTS github_dispatch_rules_created_by_user_id_fkey",
17263
+ `
17264
+ ALTER TABLE github_dispatch_rules
17265
+ ADD CONSTRAINT github_dispatch_rules_created_by_user_id_fkey
17266
+ FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE CASCADE
17267
+ `,
17268
+ "ALTER TABLE github_dispatch_rules ALTER COLUMN created_by_user_id SET NOT NULL"
17269
+ ]
17270
+ }),
17271
+ defineStorageSchemaMigration({
17272
+ id: "202605200001_limit_weekly_report_email_channel_per_project",
17273
+ description: "Keep weekly email reports singular per project.",
17274
+ statements: [
17275
+ `
17276
+ DELETE FROM weekly_report_channels
17277
+ WHERE id IN (
17278
+ SELECT id
17279
+ FROM (
17280
+ SELECT
17281
+ id,
17282
+ row_number() OVER (PARTITION BY project_id ORDER BY created_at ASC, id ASC) AS row_number
17283
+ FROM weekly_report_channels
17284
+ WHERE channel = 'email'
17285
+ ) ranked
17286
+ WHERE ranked.row_number > 1
17287
+ )
17288
+ `,
17289
+ `
17290
+ CREATE UNIQUE INDEX IF NOT EXISTS weekly_report_channels_project_email_unique_idx
17291
+ ON weekly_report_channels (project_id)
17292
+ WHERE channel = 'email'
17293
+ `
17294
+ ]
17295
+ }),
17296
+ defineStorageSchemaMigration({
17297
+ id: "202605220001_add_project_token_allowed_origins",
17298
+ description: "Add optional browser-origin allowlists to project ingestion tokens.",
17299
+ statements: [
17300
+ "ALTER TABLE project_tokens ADD COLUMN IF NOT EXISTS allowed_origins jsonb NOT NULL DEFAULT '[]'::jsonb"
17301
+ ]
16753
17302
  })
16754
17303
  ];
16755
17304
 
@@ -17508,6 +18057,7 @@ var ProjectRecordSchema = external_exports.object({
17508
18057
  owner_user_id: external_exports.string(),
17509
18058
  owner_email: external_exports.string().email(),
17510
18059
  relationship: external_exports.enum(["owned", "shared"]),
18060
+ sharing_state: external_exports.enum(["private", "shared_by_you", "shared_with_you"]),
17511
18061
  effective_role: external_exports.enum(["owner", "admin", "member"]),
17512
18062
  name: external_exports.string(),
17513
18063
  slug: external_exports.string(),
@@ -17529,6 +18079,7 @@ var DeletedProjectRecordSchema = external_exports.object({
17529
18079
  owner_user_id: external_exports.string(),
17530
18080
  owner_email: external_exports.string().email(),
17531
18081
  relationship: external_exports.enum(["owned", "shared"]),
18082
+ sharing_state: external_exports.enum(["private", "shared_by_you", "shared_with_you"]),
17532
18083
  effective_role: external_exports.enum(["owner", "admin", "member"]),
17533
18084
  name: external_exports.string(),
17534
18085
  slug: external_exports.string(),
@@ -17655,6 +18206,7 @@ var ProjectTokenSchema = external_exports.object({
17655
18206
  token_id: external_exports.string(),
17656
18207
  project_id: external_exports.string(),
17657
18208
  label: external_exports.string(),
18209
+ allowed_origins: external_exports.array(external_exports.string()).default([]),
17658
18210
  created_at: external_exports.string(),
17659
18211
  last_used_at: external_exports.string().nullable(),
17660
18212
  revoked_at: external_exports.string().nullable(),
@@ -17739,7 +18291,8 @@ function createTokenManagementApi(client) {
17739
18291
  path: `/v1/projects/${input.projectId}/tokens`,
17740
18292
  bearerToken: input.bearerToken,
17741
18293
  body: {
17742
- label: input.label
18294
+ label: input.label,
18295
+ ...input.allowedOrigins === void 0 ? {} : { allowed_origins: input.allowedOrigins }
17743
18296
  }
17744
18297
  })
17745
18298
  );
@@ -17862,6 +18415,7 @@ var AlertConditionTypeSchema = external_exports.enum([
17862
18415
  var AlertSchema = external_exports.object({
17863
18416
  alert_id: external_exports.string(),
17864
18417
  project_id: external_exports.string(),
18418
+ created_by_user_id: external_exports.string(),
17865
18419
  service_id: external_exports.string().nullable(),
17866
18420
  channel: AlertChannelSchema,
17867
18421
  condition_type: AlertConditionTypeSchema,
@@ -17987,7 +18541,7 @@ function createAlertApi(client) {
17987
18541
  return expectAlert(
17988
18542
  client.request({
17989
18543
  method: "PATCH",
17990
- path: `/v1/alerts/${input.alertId}`,
18544
+ path: `/v1/alerts/${input.alertId}${buildQuery({ project_id: input.projectId })}`,
17991
18545
  bearerToken: input.bearerToken,
17992
18546
  body
17993
18547
  })
@@ -17996,7 +18550,7 @@ function createAlertApi(client) {
17996
18550
  async deleteAlert(input) {
17997
18551
  const response = await client.request({
17998
18552
  method: "DELETE",
17999
- path: `/v1/alerts/${input.alertId}`,
18553
+ path: `/v1/alerts/${input.alertId}${buildQuery({ project_id: input.projectId })}`,
18000
18554
  bearerToken: input.bearerToken
18001
18555
  });
18002
18556
  if (response.status < 200 || response.status >= 300) {
@@ -18079,6 +18633,7 @@ var WebhookFiltersSchema = external_exports.object({
18079
18633
  var WebhookSchema = external_exports.object({
18080
18634
  webhook_id: external_exports.string(),
18081
18635
  project_id: external_exports.string(),
18636
+ created_by_user_id: external_exports.string(),
18082
18637
  url: external_exports.string(),
18083
18638
  events: external_exports.array(WebhookEventTypeSchema),
18084
18639
  filters: WebhookFiltersSchema,
@@ -18249,7 +18804,7 @@ function createWebhookApi(client) {
18249
18804
  return expectWebhook(
18250
18805
  client.request({
18251
18806
  method: "GET",
18252
- path: `/v1/webhooks/${input.webhookId}`,
18807
+ path: `/v1/webhooks/${input.webhookId}${buildQuery2({ project_id: input.projectId })}`,
18253
18808
  bearerToken: input.bearerToken
18254
18809
  })
18255
18810
  );
@@ -18271,7 +18826,7 @@ function createWebhookApi(client) {
18271
18826
  return expectWebhook(
18272
18827
  client.request({
18273
18828
  method: "PATCH",
18274
- path: `/v1/webhooks/${input.webhookId}`,
18829
+ path: `/v1/webhooks/${input.webhookId}${buildQuery2({ project_id: input.projectId })}`,
18275
18830
  bearerToken: input.bearerToken,
18276
18831
  body
18277
18832
  })
@@ -18280,7 +18835,7 @@ function createWebhookApi(client) {
18280
18835
  async deleteWebhook(input) {
18281
18836
  const response = await client.request({
18282
18837
  method: "DELETE",
18283
- path: `/v1/webhooks/${input.webhookId}`,
18838
+ path: `/v1/webhooks/${input.webhookId}${buildQuery2({ project_id: input.projectId })}`,
18284
18839
  bearerToken: input.bearerToken
18285
18840
  });
18286
18841
  if (response.status < 200 || response.status >= 300) {
@@ -18298,7 +18853,7 @@ function createWebhookApi(client) {
18298
18853
  return expectWebhookTestDelivery(
18299
18854
  client.request({
18300
18855
  method: "POST",
18301
- path: `/v1/webhooks/${input.webhookId}/test`,
18856
+ path: `/v1/webhooks/${input.webhookId}/test${buildQuery2({ project_id: input.projectId })}`,
18302
18857
  bearerToken: input.bearerToken,
18303
18858
  body
18304
18859
  })
@@ -18308,7 +18863,7 @@ function createWebhookApi(client) {
18308
18863
  return expectWebhookDeliveries(
18309
18864
  client.request({
18310
18865
  method: "GET",
18311
- path: `/v1/webhooks/${input.webhookId}/deliveries${buildQuery2({ limit: input.limit })}`,
18866
+ path: `/v1/webhooks/${input.webhookId}/deliveries${buildQuery2({ project_id: input.projectId, limit: input.limit })}`,
18312
18867
  bearerToken: input.bearerToken
18313
18868
  })
18314
18869
  );
@@ -18317,7 +18872,7 @@ function createWebhookApi(client) {
18317
18872
  return expectRetryDelivery(
18318
18873
  client.request({
18319
18874
  method: "POST",
18320
- path: `/v1/webhooks/${input.webhookId}/deliveries/${input.deliveryId}/retry`,
18875
+ path: `/v1/webhooks/${input.webhookId}/deliveries/${input.deliveryId}/retry${buildQuery2({ project_id: input.projectId })}`,
18321
18876
  bearerToken: input.bearerToken,
18322
18877
  body: {}
18323
18878
  })
@@ -18507,7 +19062,8 @@ var BillingSummarySchema = external_exports.object({
18507
19062
  monthly_raw_ingested_events: BillingUsageMetricSchema,
18508
19063
  retained_bundle_cap: BillingUsageMetricSchema,
18509
19064
  monthly_remote_activations: BillingUsageMetricSchema,
18510
- monthly_alert_deliveries: BillingUsageMetricSchema
19065
+ monthly_alert_deliveries: BillingUsageMetricSchema,
19066
+ monthly_webhook_deliveries: BillingUsageMetricSchema
18511
19067
  }).strict()
18512
19068
  }).strict();
18513
19069
  var BillingSummaryResponseSchema = external_exports.object({
@@ -18621,6 +19177,7 @@ var ProjectGitHubRepoSchema = external_exports.object({
18621
19177
  var GitHubDispatchRuleSchema = external_exports.object({
18622
19178
  rule_id: external_exports.string(),
18623
19179
  project_id: external_exports.string(),
19180
+ created_by_user_id: external_exports.string(),
18624
19181
  name: external_exports.string(),
18625
19182
  enabled: external_exports.boolean(),
18626
19183
  event_types: external_exports.array(external_exports.string().min(1)),
@@ -18637,9 +19194,10 @@ var GitHubDispatchDeliverySchema = external_exports.object({
18637
19194
  delivery_id: external_exports.string(),
18638
19195
  rule_id: external_exports.string(),
18639
19196
  rule_name: external_exports.string(),
18640
- incident_id: external_exports.string(),
18641
- incident_title: external_exports.string(),
18642
- status: external_exports.enum(["pending", "retrying", "delivered", "failed"]),
19197
+ incident_id: external_exports.string().nullable(),
19198
+ improvement_id: external_exports.string().nullable(),
19199
+ target_title: external_exports.string(),
19200
+ status: external_exports.enum(["pending", "retrying", "delivered", "failed", "skipped"]),
18643
19201
  attempt_count: external_exports.number().int(),
18644
19202
  last_attempt_at: external_exports.string().nullable(),
18645
19203
  last_error: external_exports.string().nullable(),
@@ -18776,19 +19334,21 @@ async function expectNoContent(responsePromise) {
18776
19334
  function createGitHubManagementApi(client) {
18777
19335
  return {
18778
19336
  async getInstallation(input) {
19337
+ const query = input.projectId === void 0 ? "" : `?project_id=${encodeURIComponent(input.projectId)}`;
18779
19338
  return expectInstallation(
18780
19339
  client.request({
18781
19340
  method: "GET",
18782
- path: "/v1/github/installation",
19341
+ path: `/v1/github/installation${query}`,
18783
19342
  bearerToken: input.bearerToken
18784
19343
  })
18785
19344
  );
18786
19345
  },
18787
19346
  async listRepositories(input) {
19347
+ const query = input.projectId === void 0 ? "" : `?project_id=${encodeURIComponent(input.projectId)}`;
18788
19348
  return expectRepositories(
18789
19349
  client.request({
18790
19350
  method: "GET",
18791
- path: "/v1/github/repositories",
19351
+ path: `/v1/github/repositories${query}`,
18792
19352
  bearerToken: input.bearerToken
18793
19353
  })
18794
19354
  );
@@ -25341,7 +25901,7 @@ var CLI_USAGE_LINES = [
25341
25901
  " debugbundle billing capacity schedule-reduction --target-additional-capacity-units <n> [--auth-file <path>] [--json]",
25342
25902
  " debugbundle billing capacity cancel-reduction [--auth-file <path>] [--json]",
25343
25903
  " debugbundle github status [--project-id <id>] [--auth-file <path>] [--json]",
25344
- " debugbundle github repos [--auth-file <path>] [--json]",
25904
+ " debugbundle github repos [--project-id <id>] [--auth-file <path>] [--json]",
25345
25905
  " debugbundle github repo set <owner/repo> --project-id <id> [--auth-file <path>] [--json]",
25346
25906
  " debugbundle github repo remove --project-id <id> [--auth-file <path>] [--json]",
25347
25907
  " debugbundle github rules --project-id <id> [--auth-file <path>] [--json]",
@@ -25355,32 +25915,41 @@ var CLI_USAGE_LINES = [
25355
25915
  " debugbundle project update <project-id> [--name <name>] [--slug <slug>] [--environment-default <env>] [--auth-file <path>] [--json]",
25356
25916
  " debugbundle project delete <project-id> [--auth-file <path>] [--json]",
25357
25917
  " debugbundle token project list <project-id> [--limit <n>] [--auth-file <path>] [--json]",
25358
- " debugbundle token project create <project-id> --label <label> [--auth-file <path>] [--json]",
25918
+ " debugbundle token project create <project-id> --label <label> [--allowed-origin <origin> ...] [--auth-file <path>] [--json]",
25359
25919
  " debugbundle token project revoke <project-id> <token-id> [--auth-file <path>] [--json]",
25360
25920
  " debugbundle token member list [--limit <n>] [--auth-file <path>] [--json]",
25361
25921
  " debugbundle token member create --label <label> [--auth-file <path>] [--json]",
25362
25922
  " debugbundle token member revoke <token-id> [--auth-file <path>] [--json]",
25363
25923
  " debugbundle alert list --project-id <id> [--limit <n>] [--auth-file <path>] [--json]",
25364
25924
  " debugbundle alert create --project-id <id> --channel <channel> --condition <condition> [--service-id <id>] [--severity-min <level>] --config-json <json> [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25365
- " debugbundle alert update <alert-id> [--service-id <id|null>] [--channel <channel>] [--condition <condition>] [--severity-min <level|null>] [--config-json <json|null>] [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25366
- " debugbundle alert delete <alert-id> [--auth-file <path>] [--json]",
25925
+ " debugbundle alert update <alert-id> --project-id <id> [--service-id <id|null>] [--channel <channel>] [--condition <condition>] [--severity-min <level|null>] [--config-json <json|null>] [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25926
+ " debugbundle alert delete <alert-id> --project-id <id> [--auth-file <path>] [--json]",
25367
25927
  " debugbundle slack list --project-id <id> [--auth-file <path>] [--json]",
25368
25928
  " debugbundle slack connect-url --project-id <id> [--return-to </projects/...>] [--auth-file <path>] [--json]",
25369
25929
  " debugbundle slack test <destination-id> --project-id <id> [--auth-file <path>] [--json]",
25370
25930
  " debugbundle slack delete <destination-id> --project-id <id> [--auth-file <path>] [--json]",
25371
25931
  " debugbundle webhook list --project-id <id> [--limit <n>] [--auth-file <path>] [--json]",
25372
25932
  " debugbundle webhook create --project-id <id> --url <url> --event <event[,event]> [--environment <env[,env]>] [--service <svc[,svc]>] [--severity-min <level>] [--bundle-type <type[,type]>] [--verification <true|false>] [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25373
- " debugbundle webhook update <webhook-id> [--url <url>] [--event <event[,event]>] [--environment <env[,env]>] [--service <svc[,svc]>] [--severity-min <level>] [--bundle-type <type[,type]>] [--verification <true|false>] [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25374
- " debugbundle webhook delete <webhook-id> [--auth-file <path>] [--json]",
25375
- " debugbundle webhook test <webhook-id> [--event <verification.passed|verification.failed>] [--auth-file <path>] [--json]",
25376
- " debugbundle webhook deliveries <webhook-id> [--limit <n>] [--auth-file <path>] [--json]",
25377
- " debugbundle webhook retry <webhook-id> <delivery-id> [--auth-file <path>] [--json]",
25933
+ " debugbundle webhook update <webhook-id> --project-id <id> [--url <url>] [--event <event[,event]>] [--environment <env[,env]>] [--service <svc[,svc]>] [--severity-min <level>] [--bundle-type <type[,type]>] [--verification <true|false>] [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25934
+ " debugbundle webhook delete <webhook-id> --project-id <id> [--auth-file <path>] [--json]",
25935
+ " debugbundle webhook test <webhook-id> --project-id <id> [--event <verification.passed|verification.failed>] [--auth-file <path>] [--json]",
25936
+ " debugbundle webhook deliveries <webhook-id> --project-id <id> [--limit <n>] [--auth-file <path>] [--json]",
25937
+ " debugbundle webhook retry <webhook-id> <delivery-id> --project-id <id> [--auth-file <path>] [--json]",
25378
25938
  " debugbundle weekly-report list --project-id <id> [--limit <n>] [--auth-file <path>] [--json]",
25379
25939
  " debugbundle weekly-report create --project-id <id> --channel <email|slack> --day-of-week <day> --hour-of-day <0-23> --timezone <iana> --config-json <json> [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25940
+ ' email --config-json uses {"to":["owner@example.com"]} with up to 3 recipients',
25380
25941
  " debugbundle weekly-report update <channel-id> [--day-of-week <day>] [--hour-of-day <0-23>] [--timezone <iana>] [--config-json <json>] [--is-enabled <true|false>] [--auth-file <path>] [--json]",
25381
25942
  " debugbundle weekly-report delete <channel-id> [--auth-file <path>] [--json]",
25382
25943
  " debugbundle capture-policy get --project <id> [--auth-file <path>] [--json]",
25383
25944
  " debugbundle capture-policy set --project <id> [--preset <minimal|balanced|investigative>] [--override <key=value>] [--client-error-incidents <preset-default|none|recommended|custom>] [--client-error-statuses <400,401,...>] [--auth-file <path>] [--json]",
25945
+ " debugbundle improvements list [--project-id <id>] [--environment <name>] [--service <name>] [--status <status>] [--severity <level>] [--kind <kind>] [--cursor <cursor>] [--limit <n>] [--auth-file <path>] [--json]",
25946
+ " debugbundle improvements get <improvement-id> [--auth-file <path>] [--json]",
25947
+ " debugbundle improvements bundle <improvement-id> --project-id <id> [--auth-file <path>] [--json]",
25948
+ " debugbundle improvements resolve <improvement-id> [--auth-file <path>] [--json]",
25949
+ " debugbundle improvements reopen <improvement-id> [--auth-file <path>] [--json]",
25950
+ " debugbundle improvements snooze <improvement-id> --until <ISO8601> [--auth-file <path>] [--json]",
25951
+ " debugbundle improvements settings get --project <id> [--auth-file <path>] [--json]",
25952
+ " debugbundle improvements settings set --project <id> [--enabled <true|false>] [--sensitivity <high_confidence|balanced|verbose>] [--auth-file <path>] [--json]",
25384
25953
  " debugbundle probe activate <project-id> --label-pattern <pattern> [--service <name>] [--environment <name>] [--ttl-seconds <n>] [--trigger-ttl-seconds <n>] [--auth-file <path>] [--json]",
25385
25954
  " debugbundle probe list <project-id> [--auth-file <path>] [--json]",
25386
25955
  " debugbundle probe deactivate <project-id> <activation-id> [--auth-file <path>] [--json]",
@@ -25401,53 +25970,62 @@ var import_node_path16 = require("node:path");
25401
25970
  var SUGGESTED_ACTIONS2 = [
25402
25971
  "Run debugbundle setup if .debugbundle/profile.json is missing.",
25403
25972
  "Run debugbundle profile validate for field-level profile errors.",
25404
- "Run debugbundle validate --fix to recreate missing local DebugBundle stubs when safe."
25973
+ "Run debugbundle validate --fix to recreate missing or stale local DebugBundle stubs when safe."
25405
25974
  ];
25406
25975
  var FIXABLE_FILES = [
25407
25976
  {
25408
25977
  name: "connection-config",
25409
25978
  filePath: CONNECTION_FILE_PATH,
25410
- buildContent: buildConnectionConfig
25979
+ buildContent: buildConnectionConfig,
25980
+ checkContent: false
25411
25981
  },
25412
25982
  {
25413
25983
  name: "agent-skill",
25414
25984
  filePath: SKILL_FILE_PATH,
25415
- buildContent: buildSkill
25985
+ buildContent: buildSkill,
25986
+ checkContent: true
25416
25987
  },
25417
25988
  {
25418
25989
  name: "cli-reference",
25419
25990
  filePath: CLI_REFERENCE_FILE_PATH,
25420
- buildContent: buildCliReference
25991
+ buildContent: buildCliReference,
25992
+ checkContent: true
25421
25993
  },
25422
25994
  {
25423
25995
  name: "mcp-reference",
25424
25996
  filePath: MCP_REFERENCE_FILE_PATH,
25425
- buildContent: buildMcpReference
25997
+ buildContent: buildMcpReference,
25998
+ checkContent: true
25426
25999
  },
25427
26000
  {
25428
26001
  name: "bundle-schema-reference",
25429
26002
  filePath: BUNDLE_SCHEMA_REFERENCE_FILE_PATH,
25430
- buildContent: buildBundleSchemaReference
26003
+ buildContent: buildBundleSchemaReference,
26004
+ checkContent: true
25431
26005
  },
25432
26006
  {
25433
26007
  name: "profile-enrichment-reference",
25434
26008
  filePath: PROFILE_ENRICHMENT_REFERENCE_FILE_PATH,
25435
- buildContent: buildProfileEnrichmentReference
26009
+ buildContent: buildProfileEnrichmentReference,
26010
+ checkContent: true
25436
26011
  },
25437
26012
  {
25438
26013
  name: "improvement-analysis-recipe",
25439
26014
  filePath: IMPROVEMENT_ANALYSIS_RECIPE_FILE_PATH,
25440
- buildContent: buildImprovementAnalysisRecipe
26015
+ buildContent: buildImprovementAnalysisRecipe,
26016
+ checkContent: true
25441
26017
  },
25442
26018
  {
25443
26019
  name: "performance-analysis-recipe",
25444
26020
  filePath: PERFORMANCE_ANALYSIS_RECIPE_FILE_PATH,
25445
- buildContent: buildPerformanceAnalysisRecipe
26021
+ buildContent: buildPerformanceAnalysisRecipe,
26022
+ checkContent: true
25446
26023
  },
25447
26024
  {
25448
26025
  name: "skill-evals",
25449
26026
  filePath: EVALS_FILE_PATH,
25450
- buildContent: buildSkillEvals
26027
+ buildContent: buildSkillEvals,
26028
+ checkContent: true
25451
26029
  }
25452
26030
  ];
25453
26031
  async function pathExists6(path, stat) {
@@ -25561,6 +26139,28 @@ async function validateCommand(input, dependencies = {}) {
25561
26139
  for (const fixableFile of FIXABLE_FILES) {
25562
26140
  const absoluteFilePath = (0, import_node_path16.join)(rootDirectory, fixableFile.filePath);
25563
26141
  if (await pathExists6(absoluteFilePath, stat)) {
26142
+ if (fixableFile.checkContent) {
26143
+ const currentContents = await readFile(absoluteFilePath);
26144
+ const expectedContents = fixableFile.buildContent();
26145
+ if (currentContents !== expectedContents) {
26146
+ if (input.fix === true) {
26147
+ await writeFile(absoluteFilePath, expectedContents);
26148
+ checks.push({
26149
+ name: fixableFile.name,
26150
+ status: "ok",
26151
+ message: `Updated stale ${fixableFile.filePath}`
26152
+ });
26153
+ continue;
26154
+ }
26155
+ autoFixAvailable = true;
26156
+ checks.push({
26157
+ name: fixableFile.name,
26158
+ status: "warning",
26159
+ message: `Stale ${fixableFile.filePath}; run debugbundle validate --fix to refresh it.`
26160
+ });
26161
+ continue;
26162
+ }
26163
+ }
25564
26164
  checks.push({
25565
26165
  name: fixableFile.name,
25566
26166
  status: "ok",
@@ -25948,6 +26548,7 @@ async function updateAlertCommand(input, api) {
25948
26548
  try {
25949
26549
  const requestInput = {
25950
26550
  bearerToken: input.bearerToken,
26551
+ projectId: input.projectId,
25951
26552
  alertId: input.alertId
25952
26553
  };
25953
26554
  if (input.serviceId !== void 0) {
@@ -25984,6 +26585,7 @@ async function updateAlertWithAuthCommand(input, dependencies) {
25984
26585
  runCommand: (authState, api) => {
25985
26586
  const commandInput = {
25986
26587
  bearerToken: authState.bearer_token,
26588
+ projectId: input.projectId,
25987
26589
  alertId: input.alertId
25988
26590
  };
25989
26591
  if (input.serviceId !== void 0) {
@@ -26017,6 +26619,7 @@ async function deleteAlertCommand(input, api) {
26017
26619
  try {
26018
26620
  const alert = await api.deleteAlert({
26019
26621
  bearerToken: input.bearerToken,
26622
+ projectId: input.projectId,
26020
26623
  alertId: input.alertId
26021
26624
  });
26022
26625
  return {
@@ -26034,6 +26637,7 @@ async function deleteAlertWithAuthCommand(input, dependencies) {
26034
26637
  runCommand: (authState, api) => {
26035
26638
  const commandInput = {
26036
26639
  bearerToken: authState.bearer_token,
26640
+ projectId: input.projectId,
26037
26641
  alertId: input.alertId
26038
26642
  };
26039
26643
  if (input.json !== void 0) {
@@ -26246,9 +26850,9 @@ async function setCapturePolicyWithAuthCommand(input, dependencies) {
26246
26850
  });
26247
26851
  }
26248
26852
 
26249
- // src/project-commands.ts
26853
+ // src/improvement-commands.ts
26250
26854
  function mapErrorToExitCode6(error) {
26251
- if (!(error instanceof ProjectManagementApiError)) {
26855
+ if (!(error instanceof RetrievalApiError)) {
26252
26856
  return 1;
26253
26857
  }
26254
26858
  if (error.status === 401) {
@@ -26260,18 +26864,416 @@ function mapErrorToExitCode6(error) {
26260
26864
  if (error.status === 400) {
26261
26865
  return 4;
26262
26866
  }
26263
- if (error.status === 409) {
26264
- return 5;
26265
- }
26266
26867
  return 1;
26267
26868
  }
26268
- function formatProject(project) {
26269
- return `${project.project_id} ${project.name} (${project.slug})`;
26869
+ function formatImprovementTable(improvements) {
26870
+ if (improvements.length === 0) {
26871
+ return "No improvements found.";
26872
+ }
26873
+ return improvements.map((improvement) => `${improvement.improvement_id} | ${improvement.severity} | ${improvement.status} | ${improvement.title}`).join("\n");
26270
26874
  }
26271
- async function listProjectsCommand(input, api) {
26875
+ function formatImprovementDetail(improvement) {
26876
+ return [
26877
+ `Improvement: ${improvement.improvement_id}`,
26878
+ `Project: ${improvement.project_name}`,
26879
+ `Title: ${improvement.title}`,
26880
+ `Kind: ${improvement.kind}`,
26881
+ `Severity: ${improvement.severity}`,
26882
+ `Status: ${improvement.status}`,
26883
+ `Environment: ${improvement.environment}`,
26884
+ `Service: ${improvement.service_name}`,
26885
+ `Confidence: ${improvement.confidence}`,
26886
+ `Occurrences: ${improvement.occurrence_count}`,
26887
+ `Last detected: ${improvement.last_detected_at}`,
26888
+ ...improvement.related_incident_ids === void 0 || improvement.related_incident_ids.length === 0 ? [] : [`Related incidents: ${improvement.related_incident_ids.join(", ")}`],
26889
+ ...improvement.resolved_at === null ? [] : [`Resolved at: ${improvement.resolved_at}`],
26890
+ `Summary: ${improvement.summary}`
26891
+ ].join("\n");
26892
+ }
26893
+ function formatObjectOutput2(payload) {
26894
+ return JSON.stringify(payload, null, 2);
26895
+ }
26896
+ async function listImprovementsCommand(input, api) {
26272
26897
  try {
26273
- const requestInput = {
26274
- bearerToken: input.bearerToken
26898
+ const response = await api.listImprovements(input);
26899
+ return {
26900
+ exitCode: 0,
26901
+ output: input.json ? JSON.stringify(response) : `${formatImprovementTable(
26902
+ response.improvements
26903
+ )}${response.next_cursor === null ? "" : `
26904
+ next_cursor: ${response.next_cursor}`}`
26905
+ };
26906
+ } catch (error) {
26907
+ return {
26908
+ exitCode: mapErrorToExitCode6(error),
26909
+ output: error instanceof Error ? error.message : String(error)
26910
+ };
26911
+ }
26912
+ }
26913
+ async function getImprovementCommand(input, api) {
26914
+ try {
26915
+ const improvement = await api.getImprovement(input);
26916
+ return {
26917
+ exitCode: 0,
26918
+ output: input.json ? JSON.stringify(improvement) : formatImprovementDetail(improvement)
26919
+ };
26920
+ } catch (error) {
26921
+ return {
26922
+ exitCode: mapErrorToExitCode6(error),
26923
+ output: error instanceof Error ? error.message : String(error)
26924
+ };
26925
+ }
26926
+ }
26927
+ async function resolveImprovementCommand(input, api) {
26928
+ try {
26929
+ const improvement = await api.resolveImprovement(input);
26930
+ return {
26931
+ exitCode: 0,
26932
+ output: input.json ? JSON.stringify(improvement) : `Improvement resolved.
26933
+ ${formatImprovementDetail(improvement)}`
26934
+ };
26935
+ } catch (error) {
26936
+ return {
26937
+ exitCode: mapErrorToExitCode6(error),
26938
+ output: error instanceof Error ? error.message : String(error)
26939
+ };
26940
+ }
26941
+ }
26942
+ async function reopenImprovementCommand(input, api) {
26943
+ try {
26944
+ const improvement = await api.reopenImprovement(input);
26945
+ return {
26946
+ exitCode: 0,
26947
+ output: input.json ? JSON.stringify(improvement) : `Improvement reopened.
26948
+ ${formatImprovementDetail(improvement)}`
26949
+ };
26950
+ } catch (error) {
26951
+ return {
26952
+ exitCode: mapErrorToExitCode6(error),
26953
+ output: error instanceof Error ? error.message : String(error)
26954
+ };
26955
+ }
26956
+ }
26957
+ async function snoozeImprovementCommand(input, api) {
26958
+ try {
26959
+ const improvement = await api.snoozeImprovement(input);
26960
+ return {
26961
+ exitCode: 0,
26962
+ output: input.json ? JSON.stringify(improvement) : `Improvement snoozed.
26963
+ ${formatImprovementDetail(improvement)}`
26964
+ };
26965
+ } catch (error) {
26966
+ return {
26967
+ exitCode: mapErrorToExitCode6(error),
26968
+ output: error instanceof Error ? error.message : String(error)
26969
+ };
26970
+ }
26971
+ }
26972
+ async function getImprovementBundleCommand(input, api) {
26973
+ try {
26974
+ const bundle = await api.getImprovementBundle(input);
26975
+ return {
26976
+ exitCode: 0,
26977
+ output: input.json ? JSON.stringify(bundle) : formatObjectOutput2(bundle)
26978
+ };
26979
+ } catch (error) {
26980
+ return {
26981
+ exitCode: mapErrorToExitCode6(error),
26982
+ output: error instanceof Error ? error.message : String(error)
26983
+ };
26984
+ }
26985
+ }
26986
+ async function listImprovementsWithAuthCommand(input, dependencies) {
26987
+ return runAuthenticatedCliCommand(input, {
26988
+ createApi: createAuthenticatedRetrievalApi,
26989
+ dependencies,
26990
+ runCommand: (authState, api) => listImprovementsCommand(
26991
+ {
26992
+ bearerToken: authState.bearer_token,
26993
+ ...input.projectId === void 0 ? {} : { projectId: input.projectId },
26994
+ ...input.environment === void 0 ? {} : { environment: input.environment },
26995
+ ...input.service === void 0 ? {} : { service: input.service },
26996
+ ...input.status === void 0 ? {} : { status: input.status },
26997
+ ...input.severity === void 0 ? {} : { severity: input.severity },
26998
+ ...input.kind === void 0 ? {} : { kind: input.kind },
26999
+ ...input.cursor === void 0 ? {} : { cursor: input.cursor },
27000
+ ...input.limit === void 0 ? {} : { limit: input.limit },
27001
+ ...input.json === void 0 ? {} : { json: input.json }
27002
+ },
27003
+ api
27004
+ )
27005
+ });
27006
+ }
27007
+ async function getImprovementWithAuthCommand(input, dependencies) {
27008
+ return runAuthenticatedCliCommand(input, {
27009
+ createApi: createAuthenticatedRetrievalApi,
27010
+ dependencies,
27011
+ runCommand: (authState, api) => getImprovementCommand(
27012
+ {
27013
+ bearerToken: authState.bearer_token,
27014
+ improvementId: input.improvementId,
27015
+ ...input.json === void 0 ? {} : { json: input.json }
27016
+ },
27017
+ api
27018
+ )
27019
+ });
27020
+ }
27021
+ async function resolveImprovementWithAuthCommand(input, dependencies) {
27022
+ return runAuthenticatedCliCommand(input, {
27023
+ createApi: createAuthenticatedRetrievalApi,
27024
+ dependencies,
27025
+ runCommand: (authState, api) => resolveImprovementCommand(
27026
+ {
27027
+ bearerToken: authState.bearer_token,
27028
+ improvementId: input.improvementId,
27029
+ ...input.json === void 0 ? {} : { json: input.json }
27030
+ },
27031
+ api
27032
+ )
27033
+ });
27034
+ }
27035
+ async function reopenImprovementWithAuthCommand(input, dependencies) {
27036
+ return runAuthenticatedCliCommand(input, {
27037
+ createApi: createAuthenticatedRetrievalApi,
27038
+ dependencies,
27039
+ runCommand: (authState, api) => reopenImprovementCommand(
27040
+ {
27041
+ bearerToken: authState.bearer_token,
27042
+ improvementId: input.improvementId,
27043
+ ...input.json === void 0 ? {} : { json: input.json }
27044
+ },
27045
+ api
27046
+ )
27047
+ });
27048
+ }
27049
+ async function snoozeImprovementWithAuthCommand(input, dependencies) {
27050
+ return runAuthenticatedCliCommand(input, {
27051
+ createApi: createAuthenticatedRetrievalApi,
27052
+ dependencies,
27053
+ runCommand: (authState, api) => snoozeImprovementCommand(
27054
+ {
27055
+ bearerToken: authState.bearer_token,
27056
+ improvementId: input.improvementId,
27057
+ snoozedUntil: input.snoozedUntil,
27058
+ ...input.json === void 0 ? {} : { json: input.json }
27059
+ },
27060
+ api
27061
+ )
27062
+ });
27063
+ }
27064
+ async function getImprovementBundleWithAuthCommand(input, dependencies) {
27065
+ return runAuthenticatedCliCommand(input, {
27066
+ createApi: createAuthenticatedRetrievalApi,
27067
+ dependencies,
27068
+ runCommand: (authState, api) => getImprovementBundleCommand(
27069
+ {
27070
+ bearerToken: authState.bearer_token,
27071
+ projectId: input.projectId,
27072
+ improvementId: input.improvementId,
27073
+ ...input.json === void 0 ? {} : { json: input.json }
27074
+ },
27075
+ api
27076
+ )
27077
+ });
27078
+ }
27079
+
27080
+ // src/improvement-settings-commands.ts
27081
+ var ImprovementSettingsApiError = class extends Error {
27082
+ status;
27083
+ constructor(status, message) {
27084
+ super(message);
27085
+ this.name = "ImprovementSettingsApiError";
27086
+ this.status = status;
27087
+ }
27088
+ };
27089
+ function toApiError2(status, body, fallback) {
27090
+ if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
27091
+ return new ImprovementSettingsApiError(status, body.error);
27092
+ }
27093
+ return new ImprovementSettingsApiError(status, fallback);
27094
+ }
27095
+ function createImprovementSettingsApi(httpClient) {
27096
+ return {
27097
+ async getImprovementSettings(input) {
27098
+ const response = await httpClient.request({
27099
+ method: "GET",
27100
+ path: `/v1/projects/${encodeURIComponent(input.projectId)}/improvement-settings`,
27101
+ bearerToken: input.bearerToken
27102
+ });
27103
+ if (response.status !== 200) {
27104
+ throw toApiError2(response.status, response.body, "Failed to get improvement settings.");
27105
+ }
27106
+ const parsed = ImprovementSettingsResponseSchema.safeParse(response.body);
27107
+ if (!parsed.success) {
27108
+ throw new ImprovementSettingsApiError(500, "Invalid improvement settings response.");
27109
+ }
27110
+ return parsed.data;
27111
+ },
27112
+ async updateImprovementSettings(input) {
27113
+ const response = await httpClient.request({
27114
+ method: "PATCH",
27115
+ path: `/v1/projects/${encodeURIComponent(input.projectId)}/improvement-settings`,
27116
+ bearerToken: input.bearerToken,
27117
+ body: input.update
27118
+ });
27119
+ if (response.status !== 200) {
27120
+ throw toApiError2(response.status, response.body, "Failed to update improvement settings.");
27121
+ }
27122
+ const parsed = ImprovementSettingsResponseSchema.safeParse(response.body);
27123
+ if (!parsed.success) {
27124
+ throw new ImprovementSettingsApiError(500, "Invalid improvement settings response.");
27125
+ }
27126
+ return parsed.data;
27127
+ }
27128
+ };
27129
+ }
27130
+ function mapErrorToExitCode7(error) {
27131
+ if (!(error instanceof ImprovementSettingsApiError)) {
27132
+ return 1;
27133
+ }
27134
+ if (error.status === 401) {
27135
+ return 2;
27136
+ }
27137
+ if (error.status === 404) {
27138
+ return 3;
27139
+ }
27140
+ if (error.status === 400) {
27141
+ return 4;
27142
+ }
27143
+ return 1;
27144
+ }
27145
+ function formatSettings(response) {
27146
+ return [
27147
+ `access_mode: ${response.access_mode}`,
27148
+ `cloud_automation_available: ${response.cloud_automation_available}`,
27149
+ `automated_improvement_bundles_enabled: ${response.settings.automated_improvement_bundles_enabled}`,
27150
+ `improvement_bundle_sensitivity: ${response.settings.improvement_bundle_sensitivity}`
27151
+ ].join("\n");
27152
+ }
27153
+ async function getImprovementSettingsCommand(input, api) {
27154
+ try {
27155
+ const response = await api.getImprovementSettings({
27156
+ bearerToken: input.bearerToken,
27157
+ projectId: input.projectId
27158
+ });
27159
+ return {
27160
+ exitCode: 0,
27161
+ output: input.json ? JSON.stringify(response) : formatSettings(response)
27162
+ };
27163
+ } catch (error) {
27164
+ return {
27165
+ exitCode: mapErrorToExitCode7(error),
27166
+ output: error instanceof Error ? error.message : String(error)
27167
+ };
27168
+ }
27169
+ }
27170
+ async function setImprovementSettingsCommand(input, api) {
27171
+ try {
27172
+ const parsedUpdate = ImprovementSettingsUpdateSchema.safeParse(input.update);
27173
+ if (!parsedUpdate.success) {
27174
+ return {
27175
+ exitCode: 4,
27176
+ output: "Invalid improvement settings update."
27177
+ };
27178
+ }
27179
+ const response = await api.updateImprovementSettings({
27180
+ bearerToken: input.bearerToken,
27181
+ projectId: input.projectId,
27182
+ update: parsedUpdate.data
27183
+ });
27184
+ return {
27185
+ exitCode: 0,
27186
+ output: input.json ? JSON.stringify(response) : `Improvement settings updated.
27187
+ ${formatSettings(response)}`
27188
+ };
27189
+ } catch (error) {
27190
+ return {
27191
+ exitCode: mapErrorToExitCode7(error),
27192
+ output: error instanceof Error ? error.message : String(error)
27193
+ };
27194
+ }
27195
+ }
27196
+ async function createAuthenticatedImprovementSettingsApi(input, dependencies) {
27197
+ const readAuthState = dependencies?.readAuthState ?? readCliAuthState;
27198
+ const authStateInput = {};
27199
+ if (input.authFilePath !== void 0) {
27200
+ authStateInput.authFilePath = input.authFilePath;
27201
+ }
27202
+ const authState = await readAuthState(authStateInput);
27203
+ const createHttpClient = dependencies?.createHttpClient ?? ((clientInput) => {
27204
+ const httpClientDependencies = {};
27205
+ if (dependencies?.fetchImpl !== void 0) {
27206
+ httpClientDependencies.fetchImpl = dependencies.fetchImpl;
27207
+ }
27208
+ return createCliHttpClient(clientInput, httpClientDependencies);
27209
+ });
27210
+ const httpClient = createHttpClient({ baseUrl: authState.base_url });
27211
+ const createApi = dependencies?.createApi ?? createImprovementSettingsApi;
27212
+ return {
27213
+ authState,
27214
+ api: createApi(httpClient)
27215
+ };
27216
+ }
27217
+ async function getImprovementSettingsWithAuthCommand(input, dependencies) {
27218
+ return runAuthenticatedCliCommand(input, {
27219
+ createApi: createAuthenticatedImprovementSettingsApi,
27220
+ dependencies,
27221
+ runCommand: (authState, api) => {
27222
+ const commandInput = {
27223
+ bearerToken: authState.bearer_token,
27224
+ projectId: input.projectId
27225
+ };
27226
+ if (input.json !== void 0) {
27227
+ commandInput.json = input.json;
27228
+ }
27229
+ return getImprovementSettingsCommand(commandInput, api);
27230
+ }
27231
+ });
27232
+ }
27233
+ async function setImprovementSettingsWithAuthCommand(input, dependencies) {
27234
+ return runAuthenticatedCliCommand(input, {
27235
+ createApi: createAuthenticatedImprovementSettingsApi,
27236
+ dependencies,
27237
+ runCommand: (authState, api) => {
27238
+ const commandInput = {
27239
+ bearerToken: authState.bearer_token,
27240
+ projectId: input.projectId,
27241
+ update: input.update
27242
+ };
27243
+ if (input.json !== void 0) {
27244
+ commandInput.json = input.json;
27245
+ }
27246
+ return setImprovementSettingsCommand(commandInput, api);
27247
+ }
27248
+ });
27249
+ }
27250
+
27251
+ // src/project-commands.ts
27252
+ function mapErrorToExitCode8(error) {
27253
+ if (!(error instanceof ProjectManagementApiError)) {
27254
+ return 1;
27255
+ }
27256
+ if (error.status === 401) {
27257
+ return 2;
27258
+ }
27259
+ if (error.status === 404) {
27260
+ return 3;
27261
+ }
27262
+ if (error.status === 400) {
27263
+ return 4;
27264
+ }
27265
+ if (error.status === 409) {
27266
+ return 5;
27267
+ }
27268
+ return 1;
27269
+ }
27270
+ function formatProject(project) {
27271
+ return `${project.project_id} ${project.name} (${project.slug})`;
27272
+ }
27273
+ async function listProjectsCommand(input, api) {
27274
+ try {
27275
+ const requestInput = {
27276
+ bearerToken: input.bearerToken
26275
27277
  };
26276
27278
  if (input.limit !== void 0) {
26277
27279
  requestInput.limit = input.limit;
@@ -26282,7 +27284,7 @@ async function listProjectsCommand(input, api) {
26282
27284
  output: input.json ? JSON.stringify({ projects }) : projects.length === 0 ? "No projects found." : projects.map(formatProject).join("\n")
26283
27285
  };
26284
27286
  } catch (error) {
26285
- return { exitCode: mapErrorToExitCode6(error), output: error instanceof Error ? error.message : String(error) };
27287
+ return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
26286
27288
  }
26287
27289
  }
26288
27290
  async function createProjectCommand(input, api) {
@@ -26301,7 +27303,7 @@ async function createProjectCommand(input, api) {
26301
27303
  output: input.json ? JSON.stringify({ project }) : `Project created: ${formatProject(project)}`
26302
27304
  };
26303
27305
  } catch (error) {
26304
- return { exitCode: mapErrorToExitCode6(error), output: error instanceof Error ? error.message : String(error) };
27306
+ return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
26305
27307
  }
26306
27308
  }
26307
27309
  async function updateProjectCommand(input, api) {
@@ -26325,7 +27327,7 @@ async function updateProjectCommand(input, api) {
26325
27327
  output: input.json ? JSON.stringify({ project }) : `Project updated: ${formatProject(project)}`
26326
27328
  };
26327
27329
  } catch (error) {
26328
- return { exitCode: mapErrorToExitCode6(error), output: error instanceof Error ? error.message : String(error) };
27330
+ return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
26329
27331
  }
26330
27332
  }
26331
27333
  async function deleteProjectCommand(input, api) {
@@ -26339,7 +27341,7 @@ async function deleteProjectCommand(input, api) {
26339
27341
  output: input.json ? JSON.stringify({ project }) : `Project deleted: ${project.project_id} (${project.name})`
26340
27342
  };
26341
27343
  } catch (error) {
26342
- return { exitCode: mapErrorToExitCode6(error), output: error instanceof Error ? error.message : String(error) };
27344
+ return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
26343
27345
  }
26344
27346
  }
26345
27347
  async function listProjectsWithAuthCommand(input, dependencies) {
@@ -26431,7 +27433,7 @@ async function deleteProjectWithAuthCommand(input, dependencies) {
26431
27433
  }
26432
27434
 
26433
27435
  // src/token-commands.ts
26434
- function mapErrorToExitCode7(error) {
27436
+ function mapErrorToExitCode9(error) {
26435
27437
  if (!(error instanceof TokenManagementApiError)) {
26436
27438
  return 1;
26437
27439
  }
@@ -26452,6 +27454,20 @@ function formatTokenTable(tokens) {
26452
27454
  }
26453
27455
  return tokens.map((token) => `${token.token_id} | ${token.label} | ${token.revoked_at === null ? "active" : "revoked"}`).join("\n");
26454
27456
  }
27457
+ function formatAllowedOrigins(allowedOrigins) {
27458
+ if (allowedOrigins === void 0 || allowedOrigins.length === 0) {
27459
+ return "none";
27460
+ }
27461
+ return allowedOrigins.join(", ");
27462
+ }
27463
+ function formatProjectTokenTable(tokens) {
27464
+ if (tokens.length === 0) {
27465
+ return "No tokens found.";
27466
+ }
27467
+ return tokens.map(
27468
+ (token) => `${token.token_id} | ${token.label} | ${token.revoked_at === null ? "active" : "revoked"} | origins: ${formatAllowedOrigins(token.allowed_origins)}`
27469
+ ).join("\n");
27470
+ }
26455
27471
  async function listProjectTokensCommand(input, api) {
26456
27472
  try {
26457
27473
  const requestInput = {
@@ -26467,10 +27483,10 @@ async function listProjectTokensCommand(input, api) {
26467
27483
  }
26468
27484
  return {
26469
27485
  exitCode: 0,
26470
- output: formatTokenTable(tokens)
27486
+ output: formatProjectTokenTable(tokens)
26471
27487
  };
26472
27488
  } catch (error) {
26473
- return { exitCode: mapErrorToExitCode7(error), output: error instanceof Error ? error.message : String(error) };
27489
+ return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
26474
27490
  }
26475
27491
  }
26476
27492
  async function listProjectTokensWithAuthCommand(input, dependencies) {
@@ -26496,21 +27512,26 @@ async function listProjectTokensWithAuthCommand(input, dependencies) {
26496
27512
  }
26497
27513
  async function createProjectTokenCommand(input, api) {
26498
27514
  try {
26499
- const token = await api.createProjectToken({
27515
+ const requestInput = {
26500
27516
  bearerToken: input.bearerToken,
26501
27517
  projectId: input.projectId,
26502
27518
  label: input.label
26503
- });
27519
+ };
27520
+ if (input.allowedOrigins !== void 0) {
27521
+ requestInput.allowedOrigins = input.allowedOrigins;
27522
+ }
27523
+ const token = await api.createProjectToken(requestInput);
26504
27524
  if (input.json) {
26505
27525
  return { exitCode: 0, output: JSON.stringify({ token }) };
26506
27526
  }
26507
27527
  return {
26508
27528
  exitCode: 0,
26509
27529
  output: `Project token created: ${token.token_id}
27530
+ Allowed origins: ${formatAllowedOrigins(token.allowed_origins)}
26510
27531
  Plaintext: ${token.plaintext ?? "<none>"}`
26511
27532
  };
26512
27533
  } catch (error) {
26513
- return { exitCode: mapErrorToExitCode7(error), output: error instanceof Error ? error.message : String(error) };
27534
+ return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
26514
27535
  }
26515
27536
  }
26516
27537
  async function createProjectTokenWithAuthCommand(input, dependencies) {
@@ -26523,6 +27544,9 @@ async function createProjectTokenWithAuthCommand(input, dependencies) {
26523
27544
  projectId: input.projectId,
26524
27545
  label: input.label
26525
27546
  };
27547
+ if (input.allowedOrigins !== void 0) {
27548
+ commandInput.allowedOrigins = input.allowedOrigins;
27549
+ }
26526
27550
  if (input.json !== void 0) {
26527
27551
  commandInput.json = input.json;
26528
27552
  }
@@ -26547,7 +27571,7 @@ async function revokeProjectTokenCommand(input, api) {
26547
27571
  output: `Project token revoked: ${token.token_id}`
26548
27572
  };
26549
27573
  } catch (error) {
26550
- return { exitCode: mapErrorToExitCode7(error), output: error instanceof Error ? error.message : String(error) };
27574
+ return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
26551
27575
  }
26552
27576
  }
26553
27577
  async function revokeProjectTokenWithAuthCommand(input, dependencies) {
@@ -26586,7 +27610,7 @@ async function listMemberTokensCommand(input, api) {
26586
27610
  output: formatTokenTable(tokens)
26587
27611
  };
26588
27612
  } catch (error) {
26589
- return { exitCode: mapErrorToExitCode7(error), output: error instanceof Error ? error.message : String(error) };
27613
+ return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
26590
27614
  }
26591
27615
  }
26592
27616
  async function listMemberTokensWithAuthCommand(input, dependencies) {
@@ -26624,7 +27648,7 @@ async function createMemberTokenCommand(input, api) {
26624
27648
  Plaintext: ${token.plaintext ?? "<none>"}`
26625
27649
  };
26626
27650
  } catch (error) {
26627
- return { exitCode: mapErrorToExitCode7(error), output: error instanceof Error ? error.message : String(error) };
27651
+ return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
26628
27652
  }
26629
27653
  }
26630
27654
  async function createMemberTokenWithAuthCommand(input, dependencies) {
@@ -26659,7 +27683,7 @@ async function revokeMemberTokenCommand(input, api) {
26659
27683
  output: `Member token revoked: ${token.token_id}`
26660
27684
  };
26661
27685
  } catch (error) {
26662
- return { exitCode: mapErrorToExitCode7(error), output: error instanceof Error ? error.message : String(error) };
27686
+ return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
26663
27687
  }
26664
27688
  }
26665
27689
  async function revokeMemberTokenWithAuthCommand(input, dependencies) {
@@ -26682,7 +27706,7 @@ async function revokeMemberTokenWithAuthCommand(input, dependencies) {
26682
27706
  }
26683
27707
 
26684
27708
  // src/webhook-commands.ts
26685
- function mapErrorToExitCode8(error) {
27709
+ function mapErrorToExitCode10(error) {
26686
27710
  if (!(error instanceof WebhookApiError)) {
26687
27711
  return 1;
26688
27712
  }
@@ -26727,7 +27751,7 @@ async function listWebhooksCommand(input, api) {
26727
27751
  output: input.json ? JSON.stringify({ webhooks }) : formatWebhookTable(webhooks)
26728
27752
  };
26729
27753
  } catch (error) {
26730
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
27754
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26731
27755
  }
26732
27756
  }
26733
27757
  async function listWebhooksWithAuthCommand(input, dependencies) {
@@ -26775,7 +27799,7 @@ async function createWebhookCommand(input, api) {
26775
27799
  Signing secret: ${webhook.signing_secret}`
26776
27800
  };
26777
27801
  } catch (error) {
26778
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
27802
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26779
27803
  }
26780
27804
  }
26781
27805
  async function createWebhookWithAuthCommand(input, dependencies) {
@@ -26808,6 +27832,7 @@ async function updateWebhookCommand(input, api) {
26808
27832
  try {
26809
27833
  const requestInput = {
26810
27834
  bearerToken: input.bearerToken,
27835
+ projectId: input.projectId,
26811
27836
  webhookId: input.webhookId
26812
27837
  };
26813
27838
  if (input.url !== void 0) {
@@ -26828,7 +27853,7 @@ async function updateWebhookCommand(input, api) {
26828
27853
  output: input.json ? JSON.stringify({ webhook }) : `Webhook updated: ${webhook.webhook_id}`
26829
27854
  };
26830
27855
  } catch (error) {
26831
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
27856
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26832
27857
  }
26833
27858
  }
26834
27859
  async function updateWebhookWithAuthCommand(input, dependencies) {
@@ -26838,6 +27863,7 @@ async function updateWebhookWithAuthCommand(input, dependencies) {
26838
27863
  runCommand: (authState, api) => {
26839
27864
  const commandInput = {
26840
27865
  bearerToken: authState.bearer_token,
27866
+ projectId: input.projectId,
26841
27867
  webhookId: input.webhookId
26842
27868
  };
26843
27869
  if (input.url !== void 0) {
@@ -26865,6 +27891,7 @@ async function deleteWebhookCommand(input, api) {
26865
27891
  try {
26866
27892
  const webhook = await api.deleteWebhook({
26867
27893
  bearerToken: input.bearerToken,
27894
+ projectId: input.projectId,
26868
27895
  webhookId: input.webhookId
26869
27896
  });
26870
27897
  return {
@@ -26872,7 +27899,7 @@ async function deleteWebhookCommand(input, api) {
26872
27899
  output: input.json ? JSON.stringify({ webhook }) : `Webhook deleted: ${webhook.webhook_id}`
26873
27900
  };
26874
27901
  } catch (error) {
26875
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
27902
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26876
27903
  }
26877
27904
  }
26878
27905
  async function deleteWebhookWithAuthCommand(input, dependencies) {
@@ -26882,6 +27909,7 @@ async function deleteWebhookWithAuthCommand(input, dependencies) {
26882
27909
  runCommand: (authState, api) => {
26883
27910
  const commandInput = {
26884
27911
  bearerToken: authState.bearer_token,
27912
+ projectId: input.projectId,
26885
27913
  webhookId: input.webhookId
26886
27914
  };
26887
27915
  if (input.json !== void 0) {
@@ -26897,6 +27925,7 @@ async function testWebhookCommand(input, api) {
26897
27925
  try {
26898
27926
  const requestInput = {
26899
27927
  bearerToken: input.bearerToken,
27928
+ projectId: input.projectId,
26900
27929
  webhookId: input.webhookId
26901
27930
  };
26902
27931
  if (input.eventType !== void 0) {
@@ -26908,7 +27937,7 @@ async function testWebhookCommand(input, api) {
26908
27937
  output: input.json ? JSON.stringify({ delivery }) : `Webhook test queued: ${delivery.delivery_id} | ${delivery.event_type} | attempts=${delivery.attempt_count}`
26909
27938
  };
26910
27939
  } catch (error) {
26911
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
27940
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26912
27941
  }
26913
27942
  }
26914
27943
  async function testWebhookWithAuthCommand(input, dependencies) {
@@ -26918,6 +27947,7 @@ async function testWebhookWithAuthCommand(input, dependencies) {
26918
27947
  runCommand: (authState, api) => {
26919
27948
  const commandInput = {
26920
27949
  bearerToken: authState.bearer_token,
27950
+ projectId: input.projectId,
26921
27951
  webhookId: input.webhookId
26922
27952
  };
26923
27953
  if (input.eventType !== void 0) {
@@ -26936,6 +27966,7 @@ async function listWebhookDeliveriesCommand(input, api) {
26936
27966
  try {
26937
27967
  const requestInput = {
26938
27968
  bearerToken: input.bearerToken,
27969
+ projectId: input.projectId,
26939
27970
  webhookId: input.webhookId
26940
27971
  };
26941
27972
  if (input.limit !== void 0) {
@@ -26947,7 +27978,7 @@ async function listWebhookDeliveriesCommand(input, api) {
26947
27978
  output: input.json ? JSON.stringify({ deliveries }) : formatWebhookDeliveriesTable(deliveries)
26948
27979
  };
26949
27980
  } catch (error) {
26950
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
27981
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26951
27982
  }
26952
27983
  }
26953
27984
  async function listWebhookDeliveriesWithAuthCommand(input, dependencies) {
@@ -26957,6 +27988,7 @@ async function listWebhookDeliveriesWithAuthCommand(input, dependencies) {
26957
27988
  runCommand: (authState, api) => {
26958
27989
  const commandInput = {
26959
27990
  bearerToken: authState.bearer_token,
27991
+ projectId: input.projectId,
26960
27992
  webhookId: input.webhookId
26961
27993
  };
26962
27994
  if (input.limit !== void 0) {
@@ -26975,6 +28007,7 @@ async function retryWebhookDeliveryCommand(input, api) {
26975
28007
  try {
26976
28008
  const result = await api.retryWebhookDelivery({
26977
28009
  bearerToken: input.bearerToken,
28010
+ projectId: input.projectId,
26978
28011
  webhookId: input.webhookId,
26979
28012
  deliveryId: input.deliveryId
26980
28013
  });
@@ -26983,7 +28016,7 @@ async function retryWebhookDeliveryCommand(input, api) {
26983
28016
  output: input.json ? JSON.stringify(result) : `Delivery retried: ${result.delivery_id} | ${result.event_type}`
26984
28017
  };
26985
28018
  } catch (error) {
26986
- return { exitCode: mapErrorToExitCode8(error), output: error instanceof Error ? error.message : String(error) };
28019
+ return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
26987
28020
  }
26988
28021
  }
26989
28022
  async function retryWebhookDeliveryWithAuthCommand(input, dependencies) {
@@ -26993,6 +28026,7 @@ async function retryWebhookDeliveryWithAuthCommand(input, dependencies) {
26993
28026
  runCommand: (authState, api) => {
26994
28027
  const commandInput = {
26995
28028
  bearerToken: authState.bearer_token,
28029
+ projectId: input.projectId,
26996
28030
  webhookId: input.webhookId,
26997
28031
  deliveryId: input.deliveryId
26998
28032
  };
@@ -27007,7 +28041,7 @@ async function retryWebhookDeliveryWithAuthCommand(input, dependencies) {
27007
28041
  }
27008
28042
 
27009
28043
  // src/weekly-report-commands.ts
27010
- function mapErrorToExitCode9(error) {
28044
+ function mapErrorToExitCode11(error) {
27011
28045
  if (!(error instanceof WeeklyReportApiError)) {
27012
28046
  return 1;
27013
28047
  }
@@ -27042,7 +28076,7 @@ async function listWeeklyReportChannelsCommand(input, api) {
27042
28076
  output: input.json ? JSON.stringify({ channels }) : formatWeeklyReportChannelTable(channels)
27043
28077
  };
27044
28078
  } catch (error) {
27045
- return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
28079
+ return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
27046
28080
  }
27047
28081
  }
27048
28082
  async function listWeeklyReportChannelsWithAuthCommand(input, dependencies) {
@@ -27075,7 +28109,7 @@ async function createWeeklyReportChannelCommand(input, api) {
27075
28109
  output: input.json ? JSON.stringify({ channel }) : `Weekly report channel created: ${channel.channel_id}`
27076
28110
  };
27077
28111
  } catch (error) {
27078
- return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
28112
+ return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
27079
28113
  }
27080
28114
  }
27081
28115
  async function createWeeklyReportChannelWithAuthCommand(input, dependencies) {
@@ -27110,7 +28144,7 @@ async function updateWeeklyReportChannelCommand(input, api) {
27110
28144
  output: input.json ? JSON.stringify({ channel }) : `Weekly report channel updated: ${channel.channel_id}`
27111
28145
  };
27112
28146
  } catch (error) {
27113
- return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
28147
+ return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
27114
28148
  }
27115
28149
  }
27116
28150
  async function updateWeeklyReportChannelWithAuthCommand(input, dependencies) {
@@ -27141,7 +28175,7 @@ async function deleteWeeklyReportChannelCommand(input, api) {
27141
28175
  output: input.json ? JSON.stringify({ channel: deleted }) : `Weekly report channel deleted: ${deleted.channel_id}`
27142
28176
  };
27143
28177
  } catch (error) {
27144
- return { exitCode: mapErrorToExitCode9(error), output: error instanceof Error ? error.message : String(error) };
28178
+ return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
27145
28179
  }
27146
28180
  }
27147
28181
  async function deleteWeeklyReportChannelWithAuthCommand(input, dependencies) {
@@ -27160,7 +28194,7 @@ async function deleteWeeklyReportChannelWithAuthCommand(input, dependencies) {
27160
28194
  }
27161
28195
 
27162
28196
  // src/slack-commands.ts
27163
- function mapErrorToExitCode10(error) {
28197
+ function mapErrorToExitCode12(error) {
27164
28198
  if (!(error instanceof SlackApiError)) {
27165
28199
  return 1;
27166
28200
  }
@@ -27196,7 +28230,7 @@ async function listSlackDestinationsCommand(input, api) {
27196
28230
  output: input.json ? JSON.stringify({ destinations }) : formatSlackDestinationTable(destinations)
27197
28231
  };
27198
28232
  } catch (error) {
27199
- return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
28233
+ return { exitCode: mapErrorToExitCode12(error), output: error instanceof Error ? error.message : String(error) };
27200
28234
  }
27201
28235
  }
27202
28236
  async function listSlackDestinationsWithAuthCommand(input, dependencies) {
@@ -27225,7 +28259,7 @@ async function getSlackConnectUrlCommand(input, api) {
27225
28259
  output: input.json ? JSON.stringify({ install_url: installUrl }) : installUrl
27226
28260
  };
27227
28261
  } catch (error) {
27228
- return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
28262
+ return { exitCode: mapErrorToExitCode12(error), output: error instanceof Error ? error.message : String(error) };
27229
28263
  }
27230
28264
  }
27231
28265
  async function getSlackConnectUrlWithAuthCommand(input, dependencies) {
@@ -27255,7 +28289,7 @@ async function testSlackDestinationCommand(input, api) {
27255
28289
  output: input.json ? JSON.stringify({ delivery }) : `Slack test message delivered for destination: ${input.destinationId}`
27256
28290
  };
27257
28291
  } catch (error) {
27258
- return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
28292
+ return { exitCode: mapErrorToExitCode12(error), output: error instanceof Error ? error.message : String(error) };
27259
28293
  }
27260
28294
  }
27261
28295
  async function testSlackDestinationWithAuthCommand(input, dependencies) {
@@ -27285,7 +28319,7 @@ async function deleteSlackDestinationCommand(input, api) {
27285
28319
  output: input.json ? JSON.stringify({ destination: deleted }) : `Slack destination deleted: ${deleted.slack_destination_id}`
27286
28320
  };
27287
28321
  } catch (error) {
27288
- return { exitCode: mapErrorToExitCode10(error), output: error instanceof Error ? error.message : String(error) };
28322
+ return { exitCode: mapErrorToExitCode12(error), output: error instanceof Error ? error.message : String(error) };
27289
28323
  }
27290
28324
  }
27291
28325
  async function deleteSlackDestinationWithAuthCommand(input, dependencies) {
@@ -27305,7 +28339,7 @@ async function deleteSlackDestinationWithAuthCommand(input, dependencies) {
27305
28339
  }
27306
28340
 
27307
28341
  // src/billing-commands.ts
27308
- function mapErrorToExitCode11(error) {
28342
+ function mapErrorToExitCode13(error) {
27309
28343
  if (!(error instanceof BillingApiError)) {
27310
28344
  return 1;
27311
28345
  }
@@ -27336,7 +28370,8 @@ function formatBillingSummary(billing) {
27336
28370
  formatMetric("Raw ingested events", billing.allowances.monthly_raw_ingested_events),
27337
28371
  formatMetric("Retained bundles", billing.allowances.retained_bundle_cap),
27338
28372
  formatMetric("Remote activations", billing.allowances.monthly_remote_activations),
27339
- formatMetric("Alert deliveries", billing.allowances.monthly_alert_deliveries)
28373
+ formatMetric("Alert deliveries", billing.allowances.monthly_alert_deliveries),
28374
+ formatMetric("Webhook deliveries", billing.allowances.monthly_webhook_deliveries)
27340
28375
  ];
27341
28376
  if (billing.capacity_units.pending_reduction !== null) {
27342
28377
  lines.push(
@@ -27353,7 +28388,7 @@ async function getBillingSummaryCommand(input, api) {
27353
28388
  output: input.json ? JSON.stringify({ billing }) : formatBillingSummary(billing)
27354
28389
  };
27355
28390
  } catch (error) {
27356
- return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
28391
+ return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
27357
28392
  }
27358
28393
  }
27359
28394
  async function increaseBillingCapacityCommand(input, api) {
@@ -27368,7 +28403,7 @@ async function increaseBillingCapacityCommand(input, api) {
27368
28403
  ${formatBillingSummary(billing)}`
27369
28404
  };
27370
28405
  } catch (error) {
27371
- return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
28406
+ return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
27372
28407
  }
27373
28408
  }
27374
28409
  async function scheduleBillingCapacityReductionCommand(input, api) {
@@ -27383,7 +28418,7 @@ async function scheduleBillingCapacityReductionCommand(input, api) {
27383
28418
  ${formatBillingSummary(billing)}`
27384
28419
  };
27385
28420
  } catch (error) {
27386
- return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
28421
+ return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
27387
28422
  }
27388
28423
  }
27389
28424
  async function cancelBillingCapacityReductionCommand(input, api) {
@@ -27395,7 +28430,7 @@ async function cancelBillingCapacityReductionCommand(input, api) {
27395
28430
  ${formatBillingSummary(billing)}`
27396
28431
  };
27397
28432
  } catch (error) {
27398
- return { exitCode: mapErrorToExitCode11(error), output: error instanceof Error ? error.message : String(error) };
28433
+ return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
27399
28434
  }
27400
28435
  }
27401
28436
  async function getBillingSummaryWithAuthCommand(input, dependencies) {
@@ -27466,7 +28501,7 @@ var MemberApiError = class extends Error {
27466
28501
  this.code = code;
27467
28502
  }
27468
28503
  };
27469
- function toApiError2(status, body) {
28504
+ function toApiError3(status, body) {
27470
28505
  if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
27471
28506
  return new MemberApiError(status, body.error);
27472
28507
  }
@@ -27481,7 +28516,7 @@ function createMemberApi(httpClient) {
27481
28516
  bearerToken: input.bearerToken
27482
28517
  });
27483
28518
  if (response.status !== 200) {
27484
- throw toApiError2(response.status, response.body);
28519
+ throw toApiError3(response.status, response.body);
27485
28520
  }
27486
28521
  return response.body;
27487
28522
  },
@@ -27492,7 +28527,7 @@ function createMemberApi(httpClient) {
27492
28527
  bearerToken: input.bearerToken
27493
28528
  });
27494
28529
  if (response.status !== 200) {
27495
- throw toApiError2(response.status, response.body);
28530
+ throw toApiError3(response.status, response.body);
27496
28531
  }
27497
28532
  return response.body;
27498
28533
  },
@@ -27504,7 +28539,7 @@ function createMemberApi(httpClient) {
27504
28539
  body: { email: input.email, role: input.role }
27505
28540
  });
27506
28541
  if (response.status !== 201) {
27507
- throw toApiError2(response.status, response.body);
28542
+ throw toApiError3(response.status, response.body);
27508
28543
  }
27509
28544
  return response.body;
27510
28545
  },
@@ -27515,7 +28550,7 @@ function createMemberApi(httpClient) {
27515
28550
  bearerToken: input.bearerToken
27516
28551
  });
27517
28552
  if (response.status !== 200) {
27518
- throw toApiError2(response.status, response.body);
28553
+ throw toApiError3(response.status, response.body);
27519
28554
  }
27520
28555
  return response.body;
27521
28556
  },
@@ -27527,7 +28562,7 @@ function createMemberApi(httpClient) {
27527
28562
  body: { role: input.role }
27528
28563
  });
27529
28564
  if (response.status !== 200) {
27530
- throw toApiError2(response.status, response.body);
28565
+ throw toApiError3(response.status, response.body);
27531
28566
  }
27532
28567
  return response.body;
27533
28568
  },
@@ -27538,7 +28573,7 @@ function createMemberApi(httpClient) {
27538
28573
  bearerToken: input.bearerToken
27539
28574
  });
27540
28575
  if (response.status !== 200) {
27541
- throw toApiError2(response.status, response.body);
28576
+ throw toApiError3(response.status, response.body);
27542
28577
  }
27543
28578
  return response.body;
27544
28579
  }
@@ -27556,7 +28591,7 @@ function formatInvitesTable(invites) {
27556
28591
  }
27557
28592
  return invites.map((i) => `${i.invite_id} | ${i.email} | ${i.role} | expires=${i.expires_at}`).join("\n");
27558
28593
  }
27559
- function mapErrorToExitCode12(error) {
28594
+ function mapErrorToExitCode14(error) {
27560
28595
  if (!(error instanceof MemberApiError)) {
27561
28596
  return 1;
27562
28597
  }
@@ -27583,7 +28618,7 @@ async function listMembersCommand(input, api) {
27583
28618
  };
27584
28619
  } catch (error) {
27585
28620
  return {
27586
- exitCode: mapErrorToExitCode12(error),
28621
+ exitCode: mapErrorToExitCode14(error),
27587
28622
  output: error instanceof MemberApiError ? error.code : String(error)
27588
28623
  };
27589
28624
  }
@@ -27597,7 +28632,7 @@ async function listInvitesCommand(input, api) {
27597
28632
  };
27598
28633
  } catch (error) {
27599
28634
  return {
27600
- exitCode: mapErrorToExitCode12(error),
28635
+ exitCode: mapErrorToExitCode14(error),
27601
28636
  output: error instanceof MemberApiError ? error.code : String(error)
27602
28637
  };
27603
28638
  }
@@ -27616,7 +28651,7 @@ async function inviteMemberCommand(input, api) {
27616
28651
  };
27617
28652
  } catch (error) {
27618
28653
  return {
27619
- exitCode: mapErrorToExitCode12(error),
28654
+ exitCode: mapErrorToExitCode14(error),
27620
28655
  output: error instanceof MemberApiError ? error.code : String(error)
27621
28656
  };
27622
28657
  }
@@ -27630,7 +28665,7 @@ async function cancelInviteCommand(input, api) {
27630
28665
  };
27631
28666
  } catch (error) {
27632
28667
  return {
27633
- exitCode: mapErrorToExitCode12(error),
28668
+ exitCode: mapErrorToExitCode14(error),
27634
28669
  output: error instanceof MemberApiError ? error.code : String(error)
27635
28670
  };
27636
28671
  }
@@ -27649,7 +28684,7 @@ async function updateMemberRoleCommand(input, api) {
27649
28684
  };
27650
28685
  } catch (error) {
27651
28686
  return {
27652
- exitCode: mapErrorToExitCode12(error),
28687
+ exitCode: mapErrorToExitCode14(error),
27653
28688
  output: error instanceof MemberApiError ? error.code : String(error)
27654
28689
  };
27655
28690
  }
@@ -27663,7 +28698,7 @@ async function removeMemberCommand(input, api) {
27663
28698
  };
27664
28699
  } catch (error) {
27665
28700
  return {
27666
- exitCode: mapErrorToExitCode12(error),
28701
+ exitCode: mapErrorToExitCode14(error),
27667
28702
  output: error instanceof MemberApiError ? error.code : String(error)
27668
28703
  };
27669
28704
  }
@@ -27774,7 +28809,7 @@ var ProbeApiError = class extends Error {
27774
28809
  this.code = code;
27775
28810
  }
27776
28811
  };
27777
- function toApiError3(status, body) {
28812
+ function toApiError4(status, body) {
27778
28813
  if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
27779
28814
  return new ProbeApiError(status, body.error);
27780
28815
  }
@@ -27805,7 +28840,7 @@ function createProbeApi(httpClient) {
27805
28840
  body
27806
28841
  });
27807
28842
  if (response.status !== 201) {
27808
- throw toApiError3(response.status, response.body);
28843
+ throw toApiError4(response.status, response.body);
27809
28844
  }
27810
28845
  return response.body;
27811
28846
  },
@@ -27816,7 +28851,7 @@ function createProbeApi(httpClient) {
27816
28851
  bearerToken: input.bearerToken
27817
28852
  });
27818
28853
  if (response.status !== 200) {
27819
- throw toApiError3(response.status, response.body);
28854
+ throw toApiError4(response.status, response.body);
27820
28855
  }
27821
28856
  return response.body;
27822
28857
  },
@@ -27828,13 +28863,13 @@ function createProbeApi(httpClient) {
27828
28863
  body: { activation_id: input.activationId }
27829
28864
  });
27830
28865
  if (response.status !== 200) {
27831
- throw toApiError3(response.status, response.body);
28866
+ throw toApiError4(response.status, response.body);
27832
28867
  }
27833
28868
  return response.body;
27834
28869
  }
27835
28870
  };
27836
28871
  }
27837
- function mapErrorToExitCode13(error) {
28872
+ function mapErrorToExitCode15(error) {
27838
28873
  if (!(error instanceof ProbeApiError)) {
27839
28874
  return 1;
27840
28875
  }
@@ -27887,7 +28922,7 @@ async function activateProbeCommand(input, api) {
27887
28922
  Trigger token: ${result.trigger_token}`
27888
28923
  };
27889
28924
  } catch (error) {
27890
- return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
28925
+ return { exitCode: mapErrorToExitCode15(error), output: error instanceof Error ? error.message : String(error) };
27891
28926
  }
27892
28927
  }
27893
28928
  async function listActiveProbesCommand(input, api) {
@@ -27907,7 +28942,7 @@ async function listActiveProbesCommand(input, api) {
27907
28942
  output: result.activations.map((a) => `${a.activation_id} ${a.label_pattern} (${a.service}/${a.environment}) expires ${a.expires_at}`).join("\n")
27908
28943
  };
27909
28944
  } catch (error) {
27910
- return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
28945
+ return { exitCode: mapErrorToExitCode15(error), output: error instanceof Error ? error.message : String(error) };
27911
28946
  }
27912
28947
  }
27913
28948
  async function deactivateProbeCommand(input, api) {
@@ -27925,7 +28960,7 @@ async function deactivateProbeCommand(input, api) {
27925
28960
  output: result.deactivated ? "Probe deactivated." : "Probe was already inactive."
27926
28961
  };
27927
28962
  } catch (error) {
27928
- return { exitCode: mapErrorToExitCode13(error), output: error instanceof Error ? error.message : String(error) };
28963
+ return { exitCode: mapErrorToExitCode15(error), output: error instanceof Error ? error.message : String(error) };
27929
28964
  }
27930
28965
  }
27931
28966
  async function createAuthenticatedProbeApi(input, dependencies) {
@@ -27975,7 +29010,7 @@ async function deactivateProbeWithAuthCommand(input, dependencies) {
27975
29010
  }
27976
29011
 
27977
29012
  // src/github-commands.ts
27978
- function mapErrorToExitCode14(error) {
29013
+ function mapErrorToExitCode16(error) {
27979
29014
  if (!(error instanceof GitHubManagementApiError)) {
27980
29015
  return 1;
27981
29016
  }
@@ -28017,12 +29052,15 @@ function formatGitHubDeliveryTable(deliveries) {
28017
29052
  return "No GitHub deliveries found.";
28018
29053
  }
28019
29054
  return deliveries.map(
28020
- (delivery) => `${delivery.rule_name} | ${delivery.status} | ${delivery.incident_title} | attempts: ${delivery.attempt_count}`
29055
+ (delivery) => `${delivery.rule_name} | ${delivery.status} | ${delivery.target_title} | attempts: ${delivery.attempt_count}`
28021
29056
  ).join("\n");
28022
29057
  }
28023
29058
  async function getGitHubStatusCommand(input, api) {
28024
29059
  try {
28025
- const installation = await api.getInstallation({ bearerToken: input.bearerToken });
29060
+ const installation = await api.getInstallation({
29061
+ bearerToken: input.bearerToken,
29062
+ ...input.projectId === void 0 ? {} : { projectId: input.projectId }
29063
+ });
28026
29064
  const repo = input.projectId === void 0 || api.getProjectRepo === void 0 ? null : await api.getProjectRepo({ bearerToken: input.bearerToken, projectId: input.projectId });
28027
29065
  if (input.json) {
28028
29066
  return {
@@ -28036,18 +29074,21 @@ async function getGitHubStatusCommand(input, api) {
28036
29074
  ${formatProjectRepo(repo)}`
28037
29075
  };
28038
29076
  } catch (error) {
28039
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29077
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28040
29078
  }
28041
29079
  }
28042
29080
  async function listGitHubRepositoriesCommand(input, api) {
28043
29081
  try {
28044
- const repositories = await api.listRepositories({ bearerToken: input.bearerToken });
29082
+ const repositories = await api.listRepositories({
29083
+ bearerToken: input.bearerToken,
29084
+ ...input.projectId === void 0 ? {} : { projectId: input.projectId }
29085
+ });
28045
29086
  return {
28046
29087
  exitCode: 0,
28047
29088
  output: input.json ? JSON.stringify({ repositories }) : repositories.length === 0 ? "No GitHub repositories found." : repositories.map((repository) => `${repository.full_name} (${repository.default_branch})`).join("\n")
28048
29089
  };
28049
29090
  } catch (error) {
28050
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29091
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28051
29092
  }
28052
29093
  }
28053
29094
  async function setProjectGitHubRepoCommand(input, api) {
@@ -28070,7 +29111,7 @@ async function setProjectGitHubRepoCommand(input, api) {
28070
29111
  output: input.json ? JSON.stringify({ repo: assignedRepo }) : `Project repo set: ${formatProjectRepo(assignedRepo)}`
28071
29112
  };
28072
29113
  } catch (error) {
28073
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29114
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28074
29115
  }
28075
29116
  }
28076
29117
  async function removeProjectGitHubRepoCommand(input, api) {
@@ -28081,7 +29122,7 @@ async function removeProjectGitHubRepoCommand(input, api) {
28081
29122
  output: input.json ? JSON.stringify({ removed: true, project_id: input.projectId }) : `Project repo removed: ${input.projectId}`
28082
29123
  };
28083
29124
  } catch (error) {
28084
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29125
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28085
29126
  }
28086
29127
  }
28087
29128
  async function listProjectGitHubRulesCommand(input, api) {
@@ -28095,7 +29136,7 @@ async function listProjectGitHubRulesCommand(input, api) {
28095
29136
  output: input.json ? JSON.stringify({ rules }) : formatGitHubRuleTable(rules)
28096
29137
  };
28097
29138
  } catch (error) {
28098
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29139
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28099
29140
  }
28100
29141
  }
28101
29142
  async function listProjectGitHubDeliveriesCommand(input, api) {
@@ -28111,7 +29152,7 @@ async function listProjectGitHubDeliveriesCommand(input, api) {
28111
29152
  output: input.json ? JSON.stringify({ deliveries }) : formatGitHubDeliveryTable(deliveries)
28112
29153
  };
28113
29154
  } catch (error) {
28114
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29155
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28115
29156
  }
28116
29157
  }
28117
29158
  async function retryProjectGitHubDeliveryCommand(input, api) {
@@ -28126,7 +29167,7 @@ async function retryProjectGitHubDeliveryCommand(input, api) {
28126
29167
  output: input.json ? JSON.stringify({ delivery }) : `GitHub delivery retried: ${delivery.delivery_id} | ${delivery.status}`
28127
29168
  };
28128
29169
  } catch (error) {
28129
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29170
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28130
29171
  }
28131
29172
  }
28132
29173
  async function createProjectGitHubRuleCommand(input, api) {
@@ -28149,7 +29190,7 @@ async function createProjectGitHubRuleCommand(input, api) {
28149
29190
  output: input.json ? JSON.stringify({ rule }) : `GitHub rule created: ${rule.rule_id}`
28150
29191
  };
28151
29192
  } catch (error) {
28152
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29193
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28153
29194
  }
28154
29195
  }
28155
29196
  async function updateProjectGitHubRuleCommand(input, api) {
@@ -28173,7 +29214,7 @@ async function updateProjectGitHubRuleCommand(input, api) {
28173
29214
  output: input.json ? JSON.stringify({ rule }) : `GitHub rule updated: ${rule.rule_id}`
28174
29215
  };
28175
29216
  } catch (error) {
28176
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29217
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28177
29218
  }
28178
29219
  }
28179
29220
  async function deleteProjectGitHubRuleCommand(input, api) {
@@ -28188,7 +29229,7 @@ async function deleteProjectGitHubRuleCommand(input, api) {
28188
29229
  output: input.json ? JSON.stringify({ deleted: true, project_id: input.projectId, rule_id: input.ruleId }) : `GitHub rule deleted: ${input.ruleId}`
28189
29230
  };
28190
29231
  } catch (error) {
28191
- return { exitCode: mapErrorToExitCode14(error), output: error instanceof Error ? error.message : String(error) };
29232
+ return { exitCode: mapErrorToExitCode16(error), output: error instanceof Error ? error.message : String(error) };
28192
29233
  }
28193
29234
  }
28194
29235
  async function getGitHubStatusWithAuthCommand(input, dependencies) {
@@ -28373,11 +29414,14 @@ async function handleGithubCommand(parsedArgv, dependencies) {
28373
29414
  return await (dependencies.getGitHubStatusCommand ?? getGitHubStatusWithAuthCommand)(input);
28374
29415
  }
28375
29416
  if (action === "repos") {
28376
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
29417
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "project-id"]);
28377
29418
  ensureNoExtraPositionals(parsedArgv, 2);
28378
- return await (dependencies.listGitHubRepositoriesCommand ?? listGitHubRepositoriesWithAuthCommand)(
28379
- appendCommonAuthOptions(parsedArgv, {})
28380
- );
29419
+ const input = appendCommonAuthOptions(parsedArgv, {});
29420
+ const projectId = readStringOption(parsedArgv, "project-id");
29421
+ if (projectId !== void 0) {
29422
+ input.projectId = projectId;
29423
+ }
29424
+ return await (dependencies.listGitHubRepositoriesCommand ?? listGitHubRepositoriesWithAuthCommand)(input);
28381
29425
  }
28382
29426
  if (action !== "repo") {
28383
29427
  if (action === "deliveries") {
@@ -28537,6 +29581,133 @@ async function handleGithubCommand(parsedArgv, dependencies) {
28537
29581
  }
28538
29582
  throw new CliInputError("Unknown github repo command.");
28539
29583
  }
29584
+ async function handleImprovementsCommand(parsedArgv, dependencies) {
29585
+ const action = requirePositional(parsedArgv, 1, "action");
29586
+ if (action === "list") {
29587
+ expectNoUnknownOptions(parsedArgv, ["project-id", "environment", "service", "status", "severity", "kind", "cursor", "limit", "auth-file", "json"]);
29588
+ ensureNoExtraPositionals(parsedArgv, 2);
29589
+ const input = appendCommonAuthOptions(parsedArgv, {});
29590
+ const projectId = readStringOption(parsedArgv, "project-id");
29591
+ if (projectId !== void 0) input.projectId = projectId;
29592
+ const environment = readStringOption(parsedArgv, "environment");
29593
+ if (environment !== void 0) input.environment = environment;
29594
+ const service = readStringOption(parsedArgv, "service");
29595
+ if (service !== void 0) input.service = service;
29596
+ const status = readStringOption(parsedArgv, "status");
29597
+ if (status !== void 0) input.status = status;
29598
+ const severity = readStringOption(parsedArgv, "severity");
29599
+ if (severity !== void 0) input.severity = severity;
29600
+ const kind = readStringOption(parsedArgv, "kind");
29601
+ if (kind !== void 0) input.kind = kind;
29602
+ const cursor = readStringOption(parsedArgv, "cursor");
29603
+ if (cursor !== void 0) input.cursor = cursor;
29604
+ const limit = readLimitOption(parsedArgv);
29605
+ if (limit !== void 0) input.limit = limit;
29606
+ return await (dependencies.listImprovementsCommand ?? listImprovementsWithAuthCommand)(input);
29607
+ }
29608
+ if (action === "get") {
29609
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
29610
+ ensureNoExtraPositionals(parsedArgv, 3);
29611
+ return await (dependencies.getImprovementCommand ?? getImprovementWithAuthCommand)(
29612
+ appendCommonAuthOptions(parsedArgv, {
29613
+ improvementId: requirePositional(parsedArgv, 2, "improvement-id")
29614
+ })
29615
+ );
29616
+ }
29617
+ if (action === "bundle") {
29618
+ expectNoUnknownOptions(parsedArgv, ["project-id", "auth-file", "json"]);
29619
+ ensureNoExtraPositionals(parsedArgv, 3);
29620
+ const projectId = readStringOption(parsedArgv, "project-id");
29621
+ if (projectId === void 0) {
29622
+ throw new CliInputError("Missing required option --project-id.");
29623
+ }
29624
+ return await (dependencies.getImprovementBundleCommand ?? getImprovementBundleWithAuthCommand)(
29625
+ appendCommonAuthOptions(parsedArgv, {
29626
+ projectId,
29627
+ improvementId: requirePositional(parsedArgv, 2, "improvement-id")
29628
+ })
29629
+ );
29630
+ }
29631
+ if (action === "resolve") {
29632
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
29633
+ ensureNoExtraPositionals(parsedArgv, 3);
29634
+ return await (dependencies.resolveImprovementCommand ?? resolveImprovementWithAuthCommand)(
29635
+ appendCommonAuthOptions(parsedArgv, {
29636
+ improvementId: requirePositional(parsedArgv, 2, "improvement-id")
29637
+ })
29638
+ );
29639
+ }
29640
+ if (action === "reopen") {
29641
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
29642
+ ensureNoExtraPositionals(parsedArgv, 3);
29643
+ return await (dependencies.reopenImprovementCommand ?? reopenImprovementWithAuthCommand)(
29644
+ appendCommonAuthOptions(parsedArgv, {
29645
+ improvementId: requirePositional(parsedArgv, 2, "improvement-id")
29646
+ })
29647
+ );
29648
+ }
29649
+ if (action === "snooze") {
29650
+ expectNoUnknownOptions(parsedArgv, ["until", "auth-file", "json"]);
29651
+ ensureNoExtraPositionals(parsedArgv, 3);
29652
+ const snoozedUntil = readStringOption(parsedArgv, "until");
29653
+ if (snoozedUntil === void 0) {
29654
+ throw new CliInputError("Missing required option --until.");
29655
+ }
29656
+ return await (dependencies.snoozeImprovementCommand ?? snoozeImprovementWithAuthCommand)(
29657
+ appendCommonAuthOptions(parsedArgv, {
29658
+ improvementId: requirePositional(parsedArgv, 2, "improvement-id"),
29659
+ snoozedUntil
29660
+ })
29661
+ );
29662
+ }
29663
+ if (action !== "settings") {
29664
+ throw new CliInputError("Unknown improvements command.");
29665
+ }
29666
+ const settingsAction = requirePositional(parsedArgv, 2, "settings action");
29667
+ if (settingsAction === "get") {
29668
+ expectNoUnknownOptions(parsedArgv, ["project", "auth-file", "json"]);
29669
+ ensureNoExtraPositionals(parsedArgv, 3);
29670
+ const projectId = readStringOption(parsedArgv, "project");
29671
+ if (projectId === void 0) {
29672
+ throw new CliInputError("Missing required option --project.");
29673
+ }
29674
+ return await (dependencies.getImprovementSettingsCommand ?? getImprovementSettingsWithAuthCommand)(
29675
+ appendCommonAuthOptions(parsedArgv, {
29676
+ projectId
29677
+ })
29678
+ );
29679
+ }
29680
+ if (settingsAction === "set") {
29681
+ expectNoUnknownOptions(parsedArgv, ["project", "enabled", "sensitivity", "auth-file", "json"]);
29682
+ ensureNoExtraPositionals(parsedArgv, 3);
29683
+ const projectId = readStringOption(parsedArgv, "project");
29684
+ if (projectId === void 0) {
29685
+ throw new CliInputError("Missing required option --project.");
29686
+ }
29687
+ const update = {};
29688
+ const enabled = readBooleanStringOption(parsedArgv, "enabled");
29689
+ if (enabled !== void 0) {
29690
+ update.automated_improvement_bundles_enabled = enabled;
29691
+ }
29692
+ const sensitivity = readStringOption(parsedArgv, "sensitivity");
29693
+ if (sensitivity !== void 0) {
29694
+ if (sensitivity !== "high_confidence" && sensitivity !== "balanced" && sensitivity !== "verbose") {
29695
+ throw new CliInputError("Invalid value for --sensitivity.");
29696
+ }
29697
+ update.improvement_bundle_sensitivity = sensitivity;
29698
+ }
29699
+ if (Object.keys(update).length === 0) {
29700
+ throw new CliInputError("At least one improvement settings field must be provided.");
29701
+ }
29702
+ return await (dependencies.setImprovementSettingsCommand ?? setImprovementSettingsWithAuthCommand)(
29703
+ appendCommonAuthOptions(parsedArgv, {
29704
+ projectId,
29705
+ update
29706
+ })
29707
+ );
29708
+ }
29709
+ throw new CliInputError("Unknown improvements settings command.");
29710
+ }
28540
29711
  async function handleBillingCommand(parsedArgv, dependencies) {
28541
29712
  const action = requirePositional(parsedArgv, 1, "action");
28542
29713
  if (action === "get") {
@@ -28732,16 +29903,18 @@ async function handleTokenCommand(parsedArgv, dependencies) {
28732
29903
  return await (dependencies.listProjectTokensCommand ?? listProjectTokensWithAuthCommand)(input);
28733
29904
  }
28734
29905
  if (action === "create") {
28735
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "label"]);
29906
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "label", "allowed-origin"]);
28736
29907
  ensureNoExtraPositionals(parsedArgv, 4);
28737
29908
  const label = readStringOption(parsedArgv, "label");
28738
29909
  if (label === void 0) {
28739
29910
  throw new CliInputError("Missing required option --label.");
28740
29911
  }
29912
+ const allowedOrigins = readStringListOption(parsedArgv, "allowed-origin");
28741
29913
  return await (dependencies.createProjectTokenCommand ?? createProjectTokenWithAuthCommand)(
28742
29914
  appendCommonAuthOptions(parsedArgv, {
28743
29915
  projectId: requirePositional(parsedArgv, 3, "project-id"),
28744
- label
29916
+ label,
29917
+ ...allowedOrigins === void 0 ? {} : { allowedOrigins }
28745
29918
  })
28746
29919
  );
28747
29920
  }
@@ -29035,6 +30208,7 @@ async function handleWebhookCommand(parsedArgv, dependencies) {
29035
30208
  expectNoUnknownOptions(parsedArgv, [
29036
30209
  "auth-file",
29037
30210
  "json",
30211
+ "project-id",
29038
30212
  "url",
29039
30213
  "event",
29040
30214
  "environment",
@@ -29045,7 +30219,12 @@ async function handleWebhookCommand(parsedArgv, dependencies) {
29045
30219
  "is-enabled"
29046
30220
  ]);
29047
30221
  ensureNoExtraPositionals(parsedArgv, 3);
30222
+ const projectId = readStringOption(parsedArgv, "project-id");
30223
+ if (projectId === void 0) {
30224
+ throw new CliInputError("Missing required option --project-id.");
30225
+ }
29048
30226
  const input = appendCommonAuthOptions(parsedArgv, {
30227
+ projectId,
29049
30228
  webhookId: requirePositional(parsedArgv, 2, "webhook-id")
29050
30229
  });
29051
30230
  const url = readStringOption(parsedArgv, "url");
@@ -29090,18 +30269,28 @@ async function handleWebhookCommand(parsedArgv, dependencies) {
29090
30269
  return await (dependencies.updateWebhookCommand ?? updateWebhookWithAuthCommand)(input);
29091
30270
  }
29092
30271
  if (action === "delete") {
29093
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
30272
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "project-id"]);
29094
30273
  ensureNoExtraPositionals(parsedArgv, 3);
30274
+ const projectId = readStringOption(parsedArgv, "project-id");
30275
+ if (projectId === void 0) {
30276
+ throw new CliInputError("Missing required option --project-id.");
30277
+ }
29095
30278
  return await (dependencies.deleteWebhookCommand ?? deleteWebhookWithAuthCommand)(
29096
30279
  appendCommonAuthOptions(parsedArgv, {
30280
+ projectId,
29097
30281
  webhookId: requirePositional(parsedArgv, 2, "webhook-id")
29098
30282
  })
29099
30283
  );
29100
30284
  }
29101
30285
  if (action === "test") {
29102
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "event"]);
30286
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "project-id", "event"]);
29103
30287
  ensureNoExtraPositionals(parsedArgv, 3);
30288
+ const projectId = readStringOption(parsedArgv, "project-id");
30289
+ if (projectId === void 0) {
30290
+ throw new CliInputError("Missing required option --project-id.");
30291
+ }
29104
30292
  const input = appendCommonAuthOptions(parsedArgv, {
30293
+ projectId,
29105
30294
  webhookId: requirePositional(parsedArgv, 2, "webhook-id")
29106
30295
  });
29107
30296
  const eventType = readStringOption(parsedArgv, "event");
@@ -29114,9 +30303,14 @@ async function handleWebhookCommand(parsedArgv, dependencies) {
29114
30303
  return await (dependencies.testWebhookCommand ?? testWebhookWithAuthCommand)(input);
29115
30304
  }
29116
30305
  if (action === "deliveries") {
29117
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "limit"]);
30306
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "project-id", "limit"]);
29118
30307
  ensureNoExtraPositionals(parsedArgv, 3);
30308
+ const projectId = readStringOption(parsedArgv, "project-id");
30309
+ if (projectId === void 0) {
30310
+ throw new CliInputError("Missing required option --project-id.");
30311
+ }
29119
30312
  const input = appendCommonAuthOptions(parsedArgv, {
30313
+ projectId,
29120
30314
  webhookId: requirePositional(parsedArgv, 2, "webhook-id")
29121
30315
  });
29122
30316
  const limit = readLimitOption(parsedArgv);
@@ -29126,9 +30320,14 @@ async function handleWebhookCommand(parsedArgv, dependencies) {
29126
30320
  return await (dependencies.listWebhookDeliveriesCommand ?? listWebhookDeliveriesWithAuthCommand)(input);
29127
30321
  }
29128
30322
  if (action === "retry") {
29129
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
30323
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "project-id"]);
29130
30324
  ensureNoExtraPositionals(parsedArgv, 4);
30325
+ const projectId = readStringOption(parsedArgv, "project-id");
30326
+ if (projectId === void 0) {
30327
+ throw new CliInputError("Missing required option --project-id.");
30328
+ }
29131
30329
  const input = appendCommonAuthOptions(parsedArgv, {
30330
+ projectId,
29132
30331
  webhookId: requirePositional(parsedArgv, 2, "webhook-id"),
29133
30332
  deliveryId: requirePositional(parsedArgv, 3, "delivery-id")
29134
30333
  });
@@ -29207,6 +30406,7 @@ async function handleAlertCommand(parsedArgv, dependencies) {
29207
30406
  expectNoUnknownOptions(parsedArgv, [
29208
30407
  "auth-file",
29209
30408
  "json",
30409
+ "project-id",
29210
30410
  "service-id",
29211
30411
  "channel",
29212
30412
  "condition",
@@ -29215,7 +30415,12 @@ async function handleAlertCommand(parsedArgv, dependencies) {
29215
30415
  "is-enabled"
29216
30416
  ]);
29217
30417
  ensureNoExtraPositionals(parsedArgv, 3);
30418
+ const projectId = readStringOption(parsedArgv, "project-id");
30419
+ if (projectId === void 0) {
30420
+ throw new CliInputError("Missing required option --project-id.");
30421
+ }
29218
30422
  const input = appendCommonAuthOptions(parsedArgv, {
30423
+ projectId,
29219
30424
  alertId: requirePositional(parsedArgv, 2, "alert-id")
29220
30425
  });
29221
30426
  const serviceId = readStringOption(parsedArgv, "service-id");
@@ -29248,10 +30453,15 @@ async function handleAlertCommand(parsedArgv, dependencies) {
29248
30453
  return await (dependencies.updateAlertCommand ?? updateAlertWithAuthCommand)(input);
29249
30454
  }
29250
30455
  if (action === "delete") {
29251
- expectNoUnknownOptions(parsedArgv, ["auth-file", "json"]);
30456
+ expectNoUnknownOptions(parsedArgv, ["auth-file", "json", "project-id"]);
29252
30457
  ensureNoExtraPositionals(parsedArgv, 3);
30458
+ const projectId = readStringOption(parsedArgv, "project-id");
30459
+ if (projectId === void 0) {
30460
+ throw new CliInputError("Missing required option --project-id.");
30461
+ }
29253
30462
  return await (dependencies.deleteAlertCommand ?? deleteAlertWithAuthCommand)(
29254
30463
  appendCommonAuthOptions(parsedArgv, {
30464
+ projectId,
29255
30465
  alertId: requirePositional(parsedArgv, 2, "alert-id")
29256
30466
  })
29257
30467
  );
@@ -29859,6 +31069,9 @@ ${formatUsage()}`
29859
31069
  if (command === "capture-policy") {
29860
31070
  return await handleCapturePolicyCommand(parsedArgv, dependencies);
29861
31071
  }
31072
+ if (command === "improvements") {
31073
+ return await handleImprovementsCommand(parsedArgv, dependencies);
31074
+ }
29862
31075
  if (command === "probe") {
29863
31076
  return await handleProbeCommand(parsedArgv, dependencies);
29864
31077
  }