@kaddo/cli 3.83.0 → 3.85.0

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.
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>admin</title>
8
- <script type="module" crossorigin src="/assets/index-CsOMxNTw.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-MJauSqlv.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-DNkI-1xG.css">
10
10
  </head>
11
11
  <body>
@@ -86,6 +86,9 @@ import {
86
86
  getExternalWorkItem as coreGetExternalWorkItem,
87
87
  previewImport as corePreviewImport,
88
88
  importExternalWorkItem as coreImportExternalWorkItem,
89
+ discoverExternalWorkItems as coreDiscoverExternalWorkItems,
90
+ getIntegrationFilters as coreGetIntegrationFilters,
91
+ updateIntegrationFilters as coreUpdateIntegrationFilters,
89
92
  IntegrationError,
90
93
  IntegrationServiceError,
91
94
  WorkItemWriteError,
@@ -375,7 +378,7 @@ async function getIntegrationStatus(dir, id) {
375
378
  }
376
379
  async function getExternalWorkItems(dir, id, opts) {
377
380
  try {
378
- return await coreListExternalWorkItems(dir, id, { cursor: opts.cursor, pageSize: opts.pageSize, filters: { status: opts.status, query: opts.query } });
381
+ return await coreListExternalWorkItems(dir, id, { cursor: opts.cursor, pageSize: opts.pageSize, filters: opts.filters });
379
382
  } catch (err) {
380
383
  mapIntegrationError(err);
381
384
  }
@@ -471,6 +474,27 @@ async function removeIntegrationSecretAdmin(dir, id, secretName) {
471
474
  mapIntegrationError(err);
472
475
  }
473
476
  }
477
+ async function discoverExternalWorkItemsAdmin(dir, opts) {
478
+ try {
479
+ return await coreDiscoverExternalWorkItems(dir, opts);
480
+ } catch (err) {
481
+ mapIntegrationError(err);
482
+ }
483
+ }
484
+ function getIntegrationFiltersAdmin(dir, id) {
485
+ try {
486
+ return coreGetIntegrationFilters(dir, id);
487
+ } catch (err) {
488
+ mapIntegrationError(err);
489
+ }
490
+ }
491
+ function updateIntegrationFiltersAdmin(dir, id, filters) {
492
+ try {
493
+ return coreUpdateIntegrationFilters(dir, id, filters);
494
+ } catch (err) {
495
+ mapIntegrationError(err);
496
+ }
497
+ }
474
498
 
475
499
  // src/contracts/schemas.ts
476
500
  import { z } from "zod";
@@ -1038,12 +1062,20 @@ async function createAdminServer(opts) {
1038
1062
  );
1039
1063
  app.get(
1040
1064
  "/api/v1/admin/integrations/:id/work-items",
1041
- async (request, reply) => asyncCore(reply, () => getExternalWorkItems(projectDir, request.params.id, {
1042
- cursor: request.query.cursor,
1043
- pageSize: request.query.pageSize ? Number.parseInt(request.query.pageSize, 10) : void 0,
1044
- status: request.query.status,
1045
- query: request.query.query
1046
- }))
1065
+ async (request, reply) => {
1066
+ const q = request.query;
1067
+ const filters = {};
1068
+ if (q.statuses) filters.statuses = q.statuses.split(",");
1069
+ if (q.types) filters.types = q.types.split(",");
1070
+ if (q.labels) filters.labels = q.labels.split(",");
1071
+ if (q.assignees) filters.assignees = q.assignees.split(",");
1072
+ if (q.search) filters.search = q.search;
1073
+ return asyncCore(reply, () => getExternalWorkItems(projectDir, request.params.id, {
1074
+ cursor: q.cursor,
1075
+ pageSize: q.pageSize ? Number.parseInt(q.pageSize, 10) : void 0,
1076
+ filters: Object.keys(filters).length ? filters : void 0
1077
+ }));
1078
+ }
1047
1079
  );
1048
1080
  app.get(
1049
1081
  "/api/v1/admin/integrations/:id/work-items/:externalId",
@@ -1061,6 +1093,35 @@ async function createAdminServer(opts) {
1061
1093
  return asyncCore(reply, () => importIntegrationWorkItem(projectDir, request.params.id, request.params.externalId, { type }));
1062
1094
  }
1063
1095
  );
1096
+ app.get(
1097
+ "/api/v1/admin/integrations/discover",
1098
+ async (request, reply) => {
1099
+ const q = request.query;
1100
+ const filters = {};
1101
+ if (q.statuses) filters.statuses = q.statuses.split(",");
1102
+ if (q.types) filters.types = q.types.split(",");
1103
+ if (q.labels) filters.labels = q.labels.split(",");
1104
+ if (q.assignees) filters.assignees = q.assignees.split(",");
1105
+ if (q.search) filters.search = q.search;
1106
+ return asyncCore(reply, () => discoverExternalWorkItemsAdmin(projectDir, {
1107
+ filters: Object.keys(filters).length ? filters : void 0,
1108
+ pageSize: q.pageSize ? Number.parseInt(q.pageSize, 10) : void 0,
1109
+ integrationIds: q.integrationIds ? q.integrationIds.split(",") : void 0
1110
+ }));
1111
+ }
1112
+ );
1113
+ app.get("/api/v1/admin/integrations/:id/filters", async (request, reply) => {
1114
+ try {
1115
+ return getIntegrationFiltersAdmin(projectDir, request.params.id);
1116
+ } catch (err) {
1117
+ if (err instanceof CoreError) return reply.code(statusForCode(err.code)).send({ error: { code: err.code, message: err.message } });
1118
+ throw err;
1119
+ }
1120
+ });
1121
+ app.put(
1122
+ "/api/v1/admin/integrations/:id/filters",
1123
+ async (request, reply) => writeHandler(reply, () => updateIntegrationFiltersAdmin(projectDir, request.params.id, request.body ?? {}))
1124
+ );
1064
1125
  app.get("/api/v1/admin/knowledge/inventory", coreRoute(getKnowledgeInventory));
1065
1126
  app.get("/api/v1/admin/knowledge/artifact/:artifactId", async (request) => {
1066
1127
  try {
package/dist/core.js CHANGED
@@ -9480,6 +9480,51 @@ function parseSecrets(raw, id, findings) {
9480
9480
  }
9481
9481
  return secrets;
9482
9482
  }
9483
+ function toStringArray3(raw) {
9484
+ if (raw == null) return void 0;
9485
+ if (Array.isArray(raw)) return raw.filter((v) => typeof v === "string" && v.trim() !== "").map((v) => v.trim());
9486
+ if (typeof raw === "string" && raw.trim()) return [raw.trim()];
9487
+ return void 0;
9488
+ }
9489
+ function parseFilters(raw) {
9490
+ if (raw == null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
9491
+ const o = raw;
9492
+ const filters = {};
9493
+ let hasAny = false;
9494
+ const types = toStringArray3(o.types);
9495
+ if (types?.length) {
9496
+ filters.types = types;
9497
+ hasAny = true;
9498
+ }
9499
+ const statuses = toStringArray3(o.statuses);
9500
+ if (statuses?.length) {
9501
+ filters.statuses = statuses;
9502
+ hasAny = true;
9503
+ }
9504
+ const labels = toStringArray3(o.labels);
9505
+ if (labels?.length) {
9506
+ filters.labels = labels;
9507
+ hasAny = true;
9508
+ }
9509
+ const assignees = toStringArray3(o.assignees);
9510
+ if (assignees?.length) {
9511
+ filters.assignees = assignees;
9512
+ hasAny = true;
9513
+ }
9514
+ if (typeof o.updatedAfter === "string" && o.updatedAfter.trim()) {
9515
+ filters.updatedAfter = o.updatedAfter.trim();
9516
+ hasAny = true;
9517
+ }
9518
+ if (typeof o.search === "string" && o.search.trim()) {
9519
+ filters.search = o.search.trim();
9520
+ hasAny = true;
9521
+ }
9522
+ if (typeof o.providerQuery === "string" && o.providerQuery.trim()) {
9523
+ filters.providerQuery = o.providerQuery.trim();
9524
+ hasAny = true;
9525
+ }
9526
+ return hasAny ? filters : void 0;
9527
+ }
9483
9528
  function parseIntegrationsConfig(raw, opts) {
9484
9529
  const findings = [];
9485
9530
  const integrations = [];
@@ -9513,8 +9558,9 @@ function parseIntegrationsConfig(raw, opts) {
9513
9558
  const config = o.config && typeof o.config === "object" && !Array.isArray(o.config) ? o.config : {};
9514
9559
  const credentials = parseCredentials(o.credentials, id, findings);
9515
9560
  const secrets = parseSecrets(o.secrets, id, findings);
9561
+ const filters = parseFilters(o.filters);
9516
9562
  const timeoutMs = typeof o.timeout_ms === "number" ? o.timeout_ms : typeof o.timeoutMs === "number" ? o.timeoutMs : void 0;
9517
- integrations.push({ id, adapter, enabled, config, credentials, secrets, timeoutMs });
9563
+ integrations.push({ id, adapter, enabled, config, credentials, secrets, filters, timeoutMs });
9518
9564
  }
9519
9565
  return { integrations, findings };
9520
9566
  }
@@ -9551,6 +9597,7 @@ function serializeIntegrationsConfig(integrations) {
9551
9597
  entry.credentials = creds;
9552
9598
  }
9553
9599
  if (Object.keys(i.secrets).length > 0) entry.secrets = i.secrets;
9600
+ if (i.filters && Object.keys(i.filters).length > 0) entry.filters = i.filters;
9554
9601
  if (i.timeoutMs !== void 0) entry.timeout_ms = i.timeoutMs;
9555
9602
  return entry;
9556
9603
  })
@@ -9564,9 +9611,68 @@ function integrationConfigFromInput(input) {
9564
9611
  config: input.config ?? {},
9565
9612
  credentials: {},
9566
9613
  secrets: input.secrets ?? {},
9614
+ filters: input.filters,
9567
9615
  timeoutMs: input.timeoutMs
9568
9616
  };
9569
9617
  }
9618
+ function validateConfigAgainstSchema(config, schema) {
9619
+ const findings = [];
9620
+ for (const [key, field] of Object.entries(schema)) {
9621
+ const value = config[key];
9622
+ const missing = value === void 0 || value === null || typeof value === "string" && !value.trim();
9623
+ if (field.required && missing) {
9624
+ findings.push({ field: key, message: `${field.label} is required.` });
9625
+ continue;
9626
+ }
9627
+ if (missing) continue;
9628
+ switch (field.type) {
9629
+ case "url":
9630
+ if (typeof value !== "string" || !/^https?:\/\/.+/.test(value)) {
9631
+ findings.push({ field: key, message: `${field.label} must be a valid URL.` });
9632
+ }
9633
+ break;
9634
+ case "number":
9635
+ if (typeof value !== "number" || Number.isNaN(value)) {
9636
+ findings.push({ field: key, message: `${field.label} must be a number.` });
9637
+ }
9638
+ break;
9639
+ case "boolean":
9640
+ if (typeof value !== "boolean") {
9641
+ findings.push({ field: key, message: `${field.label} must be a boolean.` });
9642
+ }
9643
+ break;
9644
+ case "select":
9645
+ if (field.options && !field.options.some((o) => o.value === value)) {
9646
+ findings.push({ field: key, message: `${field.label} must be one of the available options.` });
9647
+ }
9648
+ break;
9649
+ case "multi-select":
9650
+ if (!Array.isArray(value)) {
9651
+ findings.push({ field: key, message: `${field.label} must be an array.` });
9652
+ } else if (field.options) {
9653
+ const valid = new Set(field.options.map((o) => o.value));
9654
+ const invalid = value.filter((v) => !valid.has(String(v)));
9655
+ if (invalid.length) findings.push({ field: key, message: `${field.label} contains invalid options.` });
9656
+ }
9657
+ break;
9658
+ }
9659
+ }
9660
+ return findings;
9661
+ }
9662
+ function mergeFilters(base, overlay) {
9663
+ if (!base && !overlay) return {};
9664
+ if (!base) return { ...overlay };
9665
+ if (!overlay) return { ...base };
9666
+ return {
9667
+ types: overlay.types?.length ? overlay.types : base.types,
9668
+ statuses: overlay.statuses?.length ? overlay.statuses : base.statuses,
9669
+ labels: overlay.labels?.length ? overlay.labels : base.labels,
9670
+ assignees: overlay.assignees?.length ? overlay.assignees : base.assignees,
9671
+ updatedAfter: overlay.updatedAfter ?? base.updatedAfter,
9672
+ search: overlay.search ?? base.search,
9673
+ providerQuery: overlay.providerQuery ?? base.providerQuery
9674
+ };
9675
+ }
9570
9676
 
9571
9677
  // ../integrations/src/preview.ts
9572
9678
  function buildImportPreview(item, opts) {
@@ -9707,6 +9813,7 @@ var DEFAULT_ITEMS = [
9707
9813
  status: "Open",
9708
9814
  url: "https://example.test/mock/EXT-001",
9709
9815
  labels: ["registration", "beta"],
9816
+ assignees: [{ name: "Alice" }],
9710
9817
  createdAt: "2026-01-05T10:00:00.000Z",
9711
9818
  updatedAt: "2026-02-01T09:30:00.000Z",
9712
9819
  rawMetadata: { board: "delivery" }
@@ -9720,8 +9827,86 @@ var DEFAULT_ITEMS = [
9720
9827
  status: "To Do",
9721
9828
  url: "https://example.test/mock/EXT-002",
9722
9829
  labels: ["onboarding"],
9830
+ assignees: [{ name: "Bob" }],
9723
9831
  createdAt: "2026-01-08T12:00:00.000Z",
9724
9832
  updatedAt: "2026-01-20T15:00:00.000Z"
9833
+ },
9834
+ {
9835
+ externalId: "EXT-003",
9836
+ provider: MOCK_ADAPTER_ID,
9837
+ title: "Fix authentication error on mobile",
9838
+ description: "Users on iOS 17 see a blank screen after OAuth redirect.",
9839
+ type: "Bug",
9840
+ status: "In Progress",
9841
+ url: "https://example.test/mock/EXT-003",
9842
+ labels: ["auth", "mobile", "critical"],
9843
+ assignees: [{ name: "Alice" }],
9844
+ createdAt: "2026-02-10T08:00:00.000Z",
9845
+ updatedAt: "2026-03-01T14:00:00.000Z"
9846
+ },
9847
+ {
9848
+ externalId: "EXT-004",
9849
+ provider: MOCK_ADAPTER_ID,
9850
+ title: "Design system token audit",
9851
+ description: "Review and consolidate design tokens across the component library.",
9852
+ type: "Task",
9853
+ status: "To Do",
9854
+ url: "https://example.test/mock/EXT-004",
9855
+ labels: ["frontend", "design-system"],
9856
+ createdAt: "2026-02-15T10:00:00.000Z",
9857
+ updatedAt: "2026-02-20T11:00:00.000Z"
9858
+ },
9859
+ {
9860
+ externalId: "EXT-005",
9861
+ provider: MOCK_ADAPTER_ID,
9862
+ title: "Migrate billing service to new payment gateway",
9863
+ description: "Stripe v2 migration \u2014 switch from legacy Charges API to Payment Intents.",
9864
+ type: "Epic",
9865
+ status: "Open",
9866
+ url: "https://example.test/mock/EXT-005",
9867
+ labels: ["billing", "backend", "migration"],
9868
+ assignees: [{ name: "Carol" }],
9869
+ createdAt: "2026-01-20T09:00:00.000Z",
9870
+ updatedAt: "2026-03-05T16:00:00.000Z"
9871
+ },
9872
+ {
9873
+ externalId: "EXT-006",
9874
+ provider: MOCK_ADAPTER_ID,
9875
+ title: "Add CSV export to reports",
9876
+ description: "Users need to export analytics reports as CSV for external tools.",
9877
+ type: "Feature",
9878
+ status: "In Progress",
9879
+ url: "https://example.test/mock/EXT-006",
9880
+ labels: ["reports", "backend"],
9881
+ assignees: [{ name: "Bob" }],
9882
+ createdAt: "2026-02-25T13:00:00.000Z",
9883
+ updatedAt: "2026-03-10T10:00:00.000Z"
9884
+ },
9885
+ {
9886
+ externalId: "EXT-007",
9887
+ provider: MOCK_ADAPTER_ID,
9888
+ title: "Improve search relevance scoring",
9889
+ description: "Tweak TF-IDF weights and add trigram matching for better search results.",
9890
+ type: "Task",
9891
+ status: "Done",
9892
+ url: "https://example.test/mock/EXT-007",
9893
+ labels: ["search", "backend"],
9894
+ assignees: [{ name: "Alice" }],
9895
+ createdAt: "2026-01-12T07:00:00.000Z",
9896
+ updatedAt: "2026-02-28T17:00:00.000Z"
9897
+ },
9898
+ {
9899
+ externalId: "EXT-008",
9900
+ provider: MOCK_ADAPTER_ID,
9901
+ title: "Set up E2E test pipeline",
9902
+ description: "Configure Playwright tests running on every PR via GitHub Actions.",
9903
+ type: "Task",
9904
+ status: "Done",
9905
+ url: "https://example.test/mock/EXT-008",
9906
+ labels: ["testing", "ci"],
9907
+ assignees: [{ name: "Carol" }],
9908
+ createdAt: "2026-01-30T11:00:00.000Z",
9909
+ updatedAt: "2026-02-15T09:00:00.000Z"
9725
9910
  }
9726
9911
  ];
9727
9912
  function simulationOf(context, fallback) {
@@ -9753,6 +9938,16 @@ function createMockAdapter(opts = {}) {
9753
9938
  displayName: "Mock Work Source",
9754
9939
  version: "1.0.0",
9755
9940
  description: "Deterministic offline reference adapter for validating the integration foundation.",
9941
+ icon: "mock",
9942
+ filterCapabilities: {
9943
+ types: { supported: true, multiple: true },
9944
+ statuses: { supported: true, multiple: true },
9945
+ labels: { supported: true, multiple: true },
9946
+ assignees: { supported: true, multiple: true },
9947
+ updatedAfter: { supported: true },
9948
+ search: { supported: true },
9949
+ providerQuery: { supported: false }
9950
+ },
9756
9951
  configSchema: {
9757
9952
  simulate: {
9758
9953
  type: "select",
@@ -9771,7 +9966,7 @@ function createMockAdapter(opts = {}) {
9771
9966
  },
9772
9967
  secretSchema: {
9773
9968
  token: {
9774
- type: "string",
9969
+ type: "password",
9775
9970
  required: false,
9776
9971
  label: "API Token",
9777
9972
  description: "Optional token for testing secret handling (not used by the mock adapter)."
@@ -9799,9 +9994,24 @@ function createMockAdapter(opts = {}) {
9799
9994
  readFailure(simulationOf(request.context, defaultSim));
9800
9995
  let pool = items;
9801
9996
  const f = request.filters;
9802
- if (f?.status) pool = pool.filter((i) => (i.status ?? "").toLowerCase() === f.status.toLowerCase());
9803
- if (f?.query) pool = pool.filter((i) => `${i.title} ${i.description ?? ""}`.toLowerCase().includes(f.query.toLowerCase()));
9804
- if (f?.updatedSince) pool = pool.filter((i) => (i.updatedAt ?? "") >= f.updatedSince);
9997
+ if (f?.statuses?.length) {
9998
+ const lower = f.statuses.map((s) => s.toLowerCase());
9999
+ pool = pool.filter((i) => lower.includes((i.status ?? "").toLowerCase()));
10000
+ }
10001
+ if (f?.types?.length) {
10002
+ const lower = f.types.map((t) => t.toLowerCase());
10003
+ pool = pool.filter((i) => lower.includes((i.type ?? "").toLowerCase()));
10004
+ }
10005
+ if (f?.labels?.length) {
10006
+ const lower = f.labels.map((l) => l.toLowerCase());
10007
+ pool = pool.filter((i) => i.labels?.some((il) => lower.includes(il.toLowerCase())));
10008
+ }
10009
+ if (f?.assignees?.length) {
10010
+ const lower = f.assignees.map((a) => a.toLowerCase());
10011
+ pool = pool.filter((i) => i.assignees?.some((a) => lower.includes((a.name ?? "").toLowerCase())));
10012
+ }
10013
+ if (f?.search) pool = pool.filter((i) => `${i.title} ${i.description ?? ""}`.toLowerCase().includes(f.search.toLowerCase()));
10014
+ if (f?.updatedAfter) pool = pool.filter((i) => (i.updatedAt ?? "") >= f.updatedAfter);
9805
10015
  const size = Math.max(1, request.pageSize ?? defaultPageSize);
9806
10016
  const start = request.cursor ? Math.max(0, Number.parseInt(request.cursor, 10) || 0) : 0;
9807
10017
  const slice = pool.slice(start, start + size);
@@ -9882,6 +10092,7 @@ function listIntegrations(dir) {
9882
10092
  credentialRefs: Object.values(integration.credentials).map((c) => c.env),
9883
10093
  secretRefs: Object.values(integration.secrets),
9884
10094
  secretStatus: {},
10095
+ filters: integration.filters,
9885
10096
  findings: findings.filter((f) => f.id === integration.id)
9886
10097
  };
9887
10098
  });
@@ -9902,6 +10113,7 @@ function getIntegration(dir, id) {
9902
10113
  credentialRefs: Object.values(integration.credentials).map((c) => c.env),
9903
10114
  secretRefs: Object.values(integration.secrets),
9904
10115
  secretStatus: {},
10116
+ filters: integration.filters,
9905
10117
  findings: findings.filter((f) => f.id === integration.id)
9906
10118
  };
9907
10119
  }
@@ -9925,8 +10137,10 @@ function getAvailableIntegrationTypes() {
9925
10137
  id: a.id,
9926
10138
  displayName: a.metadata.displayName,
9927
10139
  description: a.metadata.description,
10140
+ icon: a.metadata.icon,
9928
10141
  configSchema: a.metadata.configSchema ?? {},
9929
10142
  secretSchema: a.metadata.secretSchema ?? {},
10143
+ filterCapabilities: a.metadata.filterCapabilities,
9930
10144
  capabilities: a.capabilities
9931
10145
  }));
9932
10146
  }
@@ -9968,10 +10182,18 @@ function validateId(id) {
9968
10182
  function createIntegration(dir, input) {
9969
10183
  validateId(input.id);
9970
10184
  if (!input.adapter || !input.adapter.trim()) throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", "An adapter type is required.");
10185
+ const adapter = registry.get(input.adapter);
10186
+ if (!adapter) throw new IntegrationServiceError("ADAPTER_NOT_FOUND", `Unknown integration adapter "${input.adapter}".`);
9971
10187
  const { integrations } = loadIntegrations(dir);
9972
10188
  if (integrations.find((i) => i.id === input.id)) {
9973
10189
  throw new IntegrationServiceError("INTEGRATION_ALREADY_EXISTS", `An integration with id "${input.id}" already exists.`);
9974
10190
  }
10191
+ if (adapter.metadata.configSchema && input.config) {
10192
+ const findings = validateConfigAgainstSchema(input.config, adapter.metadata.configSchema);
10193
+ if (findings.length) {
10194
+ throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", findings.map((f) => f.message).join(" "));
10195
+ }
10196
+ }
9975
10197
  const newConfig = integrationConfigFromInput(input);
9976
10198
  integrations.push(newConfig);
9977
10199
  saveIntegrations(dir, integrations);
@@ -9982,8 +10204,17 @@ function updateIntegration(dir, id, input) {
9982
10204
  const idx = integrations.findIndex((i) => i.id === id);
9983
10205
  if (idx < 0) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured.`);
9984
10206
  const existing = integrations[idx];
10207
+ if (input.config !== void 0) {
10208
+ const adapter = registry.get(existing.adapter);
10209
+ if (adapter?.metadata.configSchema) {
10210
+ const findings = validateConfigAgainstSchema(input.config, adapter.metadata.configSchema);
10211
+ if (findings.length) {
10212
+ throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", findings.map((f) => f.message).join(" "));
10213
+ }
10214
+ }
10215
+ existing.config = input.config;
10216
+ }
9985
10217
  if (input.enabled !== void 0) existing.enabled = input.enabled;
9986
- if (input.config !== void 0) existing.config = input.config;
9987
10218
  if (input.secrets !== void 0) existing.secrets = input.secrets;
9988
10219
  if (input.timeoutMs !== void 0) existing.timeoutMs = input.timeoutMs;
9989
10220
  integrations[idx] = existing;
@@ -10064,12 +10295,101 @@ function statusOf(connection) {
10064
10295
  return "invalid-config";
10065
10296
  }
10066
10297
  }
10298
+ function getIntegrationFilters(dir, id) {
10299
+ const { integration } = requireIntegration(dir, id);
10300
+ return integration.filters ?? {};
10301
+ }
10302
+ function updateIntegrationFilters(dir, id, filters) {
10303
+ const { integrations } = loadIntegrations(dir);
10304
+ const idx = integrations.findIndex((i) => i.id === id);
10305
+ if (idx < 0) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured.`);
10306
+ const clean = {};
10307
+ let hasAny = false;
10308
+ if (filters.types?.length) {
10309
+ clean.types = filters.types;
10310
+ hasAny = true;
10311
+ }
10312
+ if (filters.statuses?.length) {
10313
+ clean.statuses = filters.statuses;
10314
+ hasAny = true;
10315
+ }
10316
+ if (filters.labels?.length) {
10317
+ clean.labels = filters.labels;
10318
+ hasAny = true;
10319
+ }
10320
+ if (filters.assignees?.length) {
10321
+ clean.assignees = filters.assignees;
10322
+ hasAny = true;
10323
+ }
10324
+ if (filters.updatedAfter) {
10325
+ clean.updatedAfter = filters.updatedAfter;
10326
+ hasAny = true;
10327
+ }
10328
+ if (filters.search) {
10329
+ clean.search = filters.search;
10330
+ hasAny = true;
10331
+ }
10332
+ if (filters.providerQuery) {
10333
+ clean.providerQuery = filters.providerQuery;
10334
+ hasAny = true;
10335
+ }
10336
+ integrations[idx].filters = hasAny ? clean : void 0;
10337
+ saveIntegrations(dir, integrations);
10338
+ return getIntegration(dir, id);
10339
+ }
10340
+ async function discoverExternalWorkItems(dir, opts = {}, env = process.env) {
10341
+ const { integrations, findings } = loadIntegrations(dir);
10342
+ const candidates = integrations.filter((i) => {
10343
+ if (!i.enabled) return false;
10344
+ if (configStatus(i, findings) === "invalid-config") return false;
10345
+ if (opts.integrationIds?.length && !opts.integrationIds.includes(i.id)) return false;
10346
+ const adapter = registry.get(i.adapter);
10347
+ return adapter?.capabilities.workItems.list === true;
10348
+ });
10349
+ const settled = await Promise.allSettled(
10350
+ candidates.map(async (integration) => {
10351
+ const adapter = resolveAdapter(integration);
10352
+ const { context } = await buildContextWithSecrets(dir, integration, env);
10353
+ const filters = mergeFilters(integration.filters, opts.filters);
10354
+ const page = await withTimeout(
10355
+ adapter.listWorkItems({ context, pageSize: opts.pageSize, filters }),
10356
+ context.timeoutMs
10357
+ );
10358
+ return {
10359
+ integrationId: integration.id,
10360
+ adapter: integration.adapter,
10361
+ displayName: adapter.metadata.displayName,
10362
+ icon: adapter.metadata.icon,
10363
+ items: page.items,
10364
+ hasMore: page.hasMore,
10365
+ nextCursor: page.nextCursor
10366
+ };
10367
+ })
10368
+ );
10369
+ const results = settled.map((s, i) => {
10370
+ if (s.status === "fulfilled") return s.value;
10371
+ const integration = candidates[i];
10372
+ const adapter = registry.get(integration.adapter);
10373
+ const msg = s.reason instanceof IntegrationError ? s.reason.safeMessage : "An unexpected error occurred.";
10374
+ return {
10375
+ integrationId: integration.id,
10376
+ adapter: integration.adapter,
10377
+ displayName: adapter?.metadata.displayName ?? integration.adapter,
10378
+ icon: adapter?.metadata.icon,
10379
+ items: [],
10380
+ hasMore: false,
10381
+ error: msg
10382
+ };
10383
+ });
10384
+ return { results, totalItems: results.reduce((sum, r) => sum + r.items.length, 0) };
10385
+ }
10067
10386
  async function listExternalWorkItems(dir, id, opts = {}, env = process.env) {
10068
10387
  const { integration } = requireIntegration(dir, id);
10069
10388
  const adapter = resolveAdapter(integration);
10070
10389
  if (!adapter.capabilities.workItems.list) throw integrationError("UNSUPPORTED_CAPABILITY", `Adapter "${adapter.id}" cannot list work items.`);
10071
10390
  const { context } = await buildContextWithSecrets(dir, integration, env);
10072
- return withTimeout(adapter.listWorkItems({ context, cursor: opts.cursor, pageSize: opts.pageSize, filters: opts.filters }), context.timeoutMs);
10391
+ const filters = mergeFilters(integration.filters, opts.filters);
10392
+ return withTimeout(adapter.listWorkItems({ context, cursor: opts.cursor, pageSize: opts.pageSize, filters }), context.timeoutMs);
10073
10393
  }
10074
10394
  async function getExternalWorkItem(dir, id, externalId, env = process.env) {
10075
10395
  const { integration } = requireIntegration(dir, id);
@@ -10144,6 +10464,7 @@ export {
10144
10464
  cwd,
10145
10465
  deleteIntegration,
10146
10466
  disableIntegration,
10467
+ discoverExternalWorkItems,
10147
10468
  discoverKnowledge,
10148
10469
  discoverWorkItems,
10149
10470
  enableIntegration,
@@ -10154,6 +10475,7 @@ export {
10154
10475
  getExternalWorkItem,
10155
10476
  getImpactCandidates,
10156
10477
  getIntegration,
10478
+ getIntegrationFilters,
10157
10479
  getIntegrationSecretStatus,
10158
10480
  getSystemMapProjection,
10159
10481
  getSystemNeighbors,
@@ -10184,7 +10506,9 @@ export {
10184
10506
  topologyRevision,
10185
10507
  transitionWorkItem,
10186
10508
  updateIntegration,
10509
+ updateIntegrationFilters,
10187
10510
  updateWorkItem,
10511
+ validateConfigAgainstSchema,
10188
10512
  validateSystemTopology,
10189
10513
  validateTopologyProposal,
10190
10514
  validateWorkItem,