@kaddo/cli 3.82.0 → 3.84.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.
package/dist/core.js CHANGED
@@ -7,6 +7,10 @@ function exists(p2) {
7
7
  function readFile(p2) {
8
8
  return fs.readFileSync(p2, "utf-8");
9
9
  }
10
+ function writeFile(filePath, content) {
11
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
12
+ fs.writeFileSync(filePath, content, "utf-8");
13
+ }
10
14
  function readDir(dirPath) {
11
15
  if (!exists(dirPath)) return [];
12
16
  return fs.readdirSync(dirPath);
@@ -9371,7 +9375,7 @@ function buildRefinementHandoff(dir, workItemId) {
9371
9375
 
9372
9376
  // src/services/integrations.ts
9373
9377
  import matter8 from "gray-matter";
9374
- import { parse as parseYaml9 } from "yaml";
9378
+ import { parse as parseYaml9, stringify as stringifyYaml5 } from "yaml";
9375
9379
 
9376
9380
  // ../integrations/src/errors.ts
9377
9381
  var RETRYABLE = /* @__PURE__ */ new Set([
@@ -9456,6 +9460,71 @@ function parseCredentials(raw, id, findings) {
9456
9460
  }
9457
9461
  return creds;
9458
9462
  }
9463
+ function parseSecrets(raw, id, findings) {
9464
+ const secrets = {};
9465
+ if (raw == null) return secrets;
9466
+ if (typeof raw !== "object" || Array.isArray(raw)) {
9467
+ findings.push({ level: "blocking", id, message: `Integration "${id}": secrets must be a mapping of logical references.` });
9468
+ return secrets;
9469
+ }
9470
+ for (const [key, value] of Object.entries(raw)) {
9471
+ if (typeof value === "string" && value.trim()) {
9472
+ if (value.length > 100 || /^(ghp_|sk-|xox[bpsa]-|glpat-|ey[A-Za-z0-9])/i.test(value)) {
9473
+ findings.push({ level: "blocking", id, message: `Integration "${id}": secret "${key}" appears to contain an actual credential, not a reference name.` });
9474
+ continue;
9475
+ }
9476
+ secrets[key] = value.trim();
9477
+ } else {
9478
+ findings.push({ level: "warning", id, message: `Integration "${id}": ignoring non-string secret entry "${key}".` });
9479
+ }
9480
+ }
9481
+ return secrets;
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
+ }
9459
9528
  function parseIntegrationsConfig(raw, opts) {
9460
9529
  const findings = [];
9461
9530
  const integrations = [];
@@ -9488,12 +9557,14 @@ function parseIntegrationsConfig(raw, opts) {
9488
9557
  const enabled = o.enabled === void 0 ? true : o.enabled === true || o.enabled === "true";
9489
9558
  const config = o.config && typeof o.config === "object" && !Array.isArray(o.config) ? o.config : {};
9490
9559
  const credentials = parseCredentials(o.credentials, id, findings);
9560
+ const secrets = parseSecrets(o.secrets, id, findings);
9561
+ const filters = parseFilters(o.filters);
9491
9562
  const timeoutMs = typeof o.timeout_ms === "number" ? o.timeout_ms : typeof o.timeoutMs === "number" ? o.timeoutMs : void 0;
9492
- integrations.push({ id, adapter, enabled, config, credentials, timeoutMs });
9563
+ integrations.push({ id, adapter, enabled, config, credentials, secrets, filters, timeoutMs });
9493
9564
  }
9494
9565
  return { integrations, findings };
9495
9566
  }
9496
- function resolveCredentials(integration, env) {
9567
+ async function resolveAllCredentials(integration, resolver, env) {
9497
9568
  const credentials = {};
9498
9569
  const missing = [];
9499
9570
  for (const [name, ref] of Object.entries(integration.credentials)) {
@@ -9501,8 +9572,63 @@ function resolveCredentials(integration, env) {
9501
9572
  if (value && value.length > 0) credentials[name] = value;
9502
9573
  else missing.push(ref.env);
9503
9574
  }
9575
+ for (const [name, ref] of Object.entries(integration.secrets)) {
9576
+ if (credentials[name]) continue;
9577
+ const value = await resolver.resolve(ref);
9578
+ if (value !== void 0) credentials[name] = value;
9579
+ else missing.push(ref);
9580
+ }
9504
9581
  return { credentials, missing };
9505
9582
  }
9583
+ function serializeIntegrationsConfig(integrations) {
9584
+ return {
9585
+ integrations: integrations.map((i) => {
9586
+ const entry = {
9587
+ id: i.id,
9588
+ adapter: i.adapter,
9589
+ enabled: i.enabled
9590
+ };
9591
+ if (Object.keys(i.config).length > 0) entry.config = i.config;
9592
+ if (Object.keys(i.credentials).length > 0) {
9593
+ const creds = {};
9594
+ for (const [name, ref] of Object.entries(i.credentials)) {
9595
+ creds[`${name}${ENV_SUFFIX}`] = ref.env;
9596
+ }
9597
+ entry.credentials = creds;
9598
+ }
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;
9601
+ if (i.timeoutMs !== void 0) entry.timeout_ms = i.timeoutMs;
9602
+ return entry;
9603
+ })
9604
+ };
9605
+ }
9606
+ function integrationConfigFromInput(input) {
9607
+ return {
9608
+ id: input.id,
9609
+ adapter: input.adapter,
9610
+ enabled: input.enabled ?? true,
9611
+ config: input.config ?? {},
9612
+ credentials: {},
9613
+ secrets: input.secrets ?? {},
9614
+ filters: input.filters,
9615
+ timeoutMs: input.timeoutMs
9616
+ };
9617
+ }
9618
+ function mergeFilters(base, overlay) {
9619
+ if (!base && !overlay) return {};
9620
+ if (!base) return { ...overlay };
9621
+ if (!overlay) return { ...base };
9622
+ return {
9623
+ types: overlay.types?.length ? overlay.types : base.types,
9624
+ statuses: overlay.statuses?.length ? overlay.statuses : base.statuses,
9625
+ labels: overlay.labels?.length ? overlay.labels : base.labels,
9626
+ assignees: overlay.assignees?.length ? overlay.assignees : base.assignees,
9627
+ updatedAfter: overlay.updatedAfter ?? base.updatedAfter,
9628
+ search: overlay.search ?? base.search,
9629
+ providerQuery: overlay.providerQuery ?? base.providerQuery
9630
+ };
9631
+ }
9506
9632
 
9507
9633
  // ../integrations/src/preview.ts
9508
9634
  function buildImportPreview(item, opts) {
@@ -9525,6 +9651,85 @@ function buildImportPreview(item, opts) {
9525
9651
  };
9526
9652
  }
9527
9653
 
9654
+ // ../integrations/src/secrets.ts
9655
+ import { readFileSync as readFileSync2, writeFileSync, mkdirSync, existsSync as existsSync2, unlinkSync } from "fs";
9656
+ import { dirname as dirname2 } from "path";
9657
+ function secretRefKey(integrationId, secretName) {
9658
+ return `${integrationId}.${secretName}`;
9659
+ }
9660
+ var SECRETS_FILENAME = ".secrets.json";
9661
+ function secretsPath(projectDir) {
9662
+ return `${projectDir}/.kaddo/${SECRETS_FILENAME}`;
9663
+ }
9664
+ function loadStore(filePath) {
9665
+ if (!existsSync2(filePath)) return {};
9666
+ try {
9667
+ const raw = readFileSync2(filePath, "utf-8");
9668
+ const parsed = JSON.parse(raw);
9669
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
9670
+ return {};
9671
+ } catch {
9672
+ return {};
9673
+ }
9674
+ }
9675
+ function saveStore(filePath, store) {
9676
+ mkdirSync(dirname2(filePath), { recursive: true });
9677
+ writeFileSync(filePath, JSON.stringify(store, null, 2) + "\n", "utf-8");
9678
+ }
9679
+ function createLocalSecretProvider(projectDir) {
9680
+ const fp = secretsPath(projectDir);
9681
+ return {
9682
+ async get(key) {
9683
+ const store = loadStore(fp);
9684
+ const val = store[key];
9685
+ return val !== void 0 && val !== "" ? val : void 0;
9686
+ },
9687
+ async set(key, value) {
9688
+ const store = loadStore(fp);
9689
+ store[key] = value;
9690
+ saveStore(fp, store);
9691
+ },
9692
+ async delete(key) {
9693
+ const store = loadStore(fp);
9694
+ delete store[key];
9695
+ saveStore(fp, store);
9696
+ },
9697
+ async exists(key) {
9698
+ const store = loadStore(fp);
9699
+ return key in store && store[key] !== void 0 && store[key] !== "";
9700
+ }
9701
+ };
9702
+ }
9703
+ function createEnvSecretProvider(env = process.env) {
9704
+ return {
9705
+ async get(key) {
9706
+ const val = env[key];
9707
+ return val !== void 0 && val !== "" ? val : void 0;
9708
+ },
9709
+ async set() {
9710
+ throw new Error("Environment secret provider is read-only.");
9711
+ },
9712
+ async delete() {
9713
+ throw new Error("Environment secret provider is read-only.");
9714
+ },
9715
+ async exists(key) {
9716
+ const val = env[key];
9717
+ return val !== void 0 && val !== "";
9718
+ }
9719
+ };
9720
+ }
9721
+ function createCompositeResolver(...providers) {
9722
+ return {
9723
+ async resolve(reference) {
9724
+ for (const provider of providers) {
9725
+ const val = await provider.get(reference);
9726
+ if (val !== void 0) return val;
9727
+ }
9728
+ return void 0;
9729
+ }
9730
+ };
9731
+ }
9732
+
9528
9733
  // ../integrations/src/registry.ts
9529
9734
  var DuplicateAdapterError = class extends Error {
9530
9735
  constructor(id) {
@@ -9564,6 +9769,7 @@ var DEFAULT_ITEMS = [
9564
9769
  status: "Open",
9565
9770
  url: "https://example.test/mock/EXT-001",
9566
9771
  labels: ["registration", "beta"],
9772
+ assignees: [{ name: "Alice" }],
9567
9773
  createdAt: "2026-01-05T10:00:00.000Z",
9568
9774
  updatedAt: "2026-02-01T09:30:00.000Z",
9569
9775
  rawMetadata: { board: "delivery" }
@@ -9577,8 +9783,86 @@ var DEFAULT_ITEMS = [
9577
9783
  status: "To Do",
9578
9784
  url: "https://example.test/mock/EXT-002",
9579
9785
  labels: ["onboarding"],
9786
+ assignees: [{ name: "Bob" }],
9580
9787
  createdAt: "2026-01-08T12:00:00.000Z",
9581
9788
  updatedAt: "2026-01-20T15:00:00.000Z"
9789
+ },
9790
+ {
9791
+ externalId: "EXT-003",
9792
+ provider: MOCK_ADAPTER_ID,
9793
+ title: "Fix authentication error on mobile",
9794
+ description: "Users on iOS 17 see a blank screen after OAuth redirect.",
9795
+ type: "Bug",
9796
+ status: "In Progress",
9797
+ url: "https://example.test/mock/EXT-003",
9798
+ labels: ["auth", "mobile", "critical"],
9799
+ assignees: [{ name: "Alice" }],
9800
+ createdAt: "2026-02-10T08:00:00.000Z",
9801
+ updatedAt: "2026-03-01T14:00:00.000Z"
9802
+ },
9803
+ {
9804
+ externalId: "EXT-004",
9805
+ provider: MOCK_ADAPTER_ID,
9806
+ title: "Design system token audit",
9807
+ description: "Review and consolidate design tokens across the component library.",
9808
+ type: "Task",
9809
+ status: "To Do",
9810
+ url: "https://example.test/mock/EXT-004",
9811
+ labels: ["frontend", "design-system"],
9812
+ createdAt: "2026-02-15T10:00:00.000Z",
9813
+ updatedAt: "2026-02-20T11:00:00.000Z"
9814
+ },
9815
+ {
9816
+ externalId: "EXT-005",
9817
+ provider: MOCK_ADAPTER_ID,
9818
+ title: "Migrate billing service to new payment gateway",
9819
+ description: "Stripe v2 migration \u2014 switch from legacy Charges API to Payment Intents.",
9820
+ type: "Epic",
9821
+ status: "Open",
9822
+ url: "https://example.test/mock/EXT-005",
9823
+ labels: ["billing", "backend", "migration"],
9824
+ assignees: [{ name: "Carol" }],
9825
+ createdAt: "2026-01-20T09:00:00.000Z",
9826
+ updatedAt: "2026-03-05T16:00:00.000Z"
9827
+ },
9828
+ {
9829
+ externalId: "EXT-006",
9830
+ provider: MOCK_ADAPTER_ID,
9831
+ title: "Add CSV export to reports",
9832
+ description: "Users need to export analytics reports as CSV for external tools.",
9833
+ type: "Feature",
9834
+ status: "In Progress",
9835
+ url: "https://example.test/mock/EXT-006",
9836
+ labels: ["reports", "backend"],
9837
+ assignees: [{ name: "Bob" }],
9838
+ createdAt: "2026-02-25T13:00:00.000Z",
9839
+ updatedAt: "2026-03-10T10:00:00.000Z"
9840
+ },
9841
+ {
9842
+ externalId: "EXT-007",
9843
+ provider: MOCK_ADAPTER_ID,
9844
+ title: "Improve search relevance scoring",
9845
+ description: "Tweak TF-IDF weights and add trigram matching for better search results.",
9846
+ type: "Task",
9847
+ status: "Done",
9848
+ url: "https://example.test/mock/EXT-007",
9849
+ labels: ["search", "backend"],
9850
+ assignees: [{ name: "Alice" }],
9851
+ createdAt: "2026-01-12T07:00:00.000Z",
9852
+ updatedAt: "2026-02-28T17:00:00.000Z"
9853
+ },
9854
+ {
9855
+ externalId: "EXT-008",
9856
+ provider: MOCK_ADAPTER_ID,
9857
+ title: "Set up E2E test pipeline",
9858
+ description: "Configure Playwright tests running on every PR via GitHub Actions.",
9859
+ type: "Task",
9860
+ status: "Done",
9861
+ url: "https://example.test/mock/EXT-008",
9862
+ labels: ["testing", "ci"],
9863
+ assignees: [{ name: "Carol" }],
9864
+ createdAt: "2026-01-30T11:00:00.000Z",
9865
+ updatedAt: "2026-02-15T09:00:00.000Z"
9582
9866
  }
9583
9867
  ];
9584
9868
  function simulationOf(context, fallback) {
@@ -9609,7 +9893,41 @@ function createMockAdapter(opts = {}) {
9609
9893
  id: MOCK_ADAPTER_ID,
9610
9894
  displayName: "Mock Work Source",
9611
9895
  version: "1.0.0",
9612
- description: "Deterministic offline reference adapter for validating the integration foundation."
9896
+ description: "Deterministic offline reference adapter for validating the integration foundation.",
9897
+ icon: "mock",
9898
+ filterCapabilities: {
9899
+ types: { supported: true, multiple: true },
9900
+ statuses: { supported: true, multiple: true },
9901
+ labels: { supported: true, multiple: true },
9902
+ assignees: { supported: true, multiple: true },
9903
+ updatedAfter: { supported: true },
9904
+ search: { supported: true },
9905
+ providerQuery: { supported: false }
9906
+ },
9907
+ configSchema: {
9908
+ simulate: {
9909
+ type: "select",
9910
+ required: false,
9911
+ label: "Simulation mode",
9912
+ description: "Controls what the mock adapter simulates during verify/read operations.",
9913
+ options: [
9914
+ { value: "available", label: "Available" },
9915
+ { value: "unauthorized", label: "Unauthorized" },
9916
+ { value: "rate-limited", label: "Rate Limited" },
9917
+ { value: "unavailable", label: "Unavailable" },
9918
+ { value: "timeout", label: "Timeout" }
9919
+ ],
9920
+ defaultValue: "available"
9921
+ }
9922
+ },
9923
+ secretSchema: {
9924
+ token: {
9925
+ type: "string",
9926
+ required: false,
9927
+ label: "API Token",
9928
+ description: "Optional token for testing secret handling (not used by the mock adapter)."
9929
+ }
9930
+ }
9613
9931
  },
9614
9932
  capabilities: {
9615
9933
  workItems: { list: true, read: true, import: true, write: false, statusSync: false, comments: false, webhooks: false }
@@ -9632,9 +9950,24 @@ function createMockAdapter(opts = {}) {
9632
9950
  readFailure(simulationOf(request.context, defaultSim));
9633
9951
  let pool = items;
9634
9952
  const f = request.filters;
9635
- if (f?.status) pool = pool.filter((i) => (i.status ?? "").toLowerCase() === f.status.toLowerCase());
9636
- if (f?.query) pool = pool.filter((i) => `${i.title} ${i.description ?? ""}`.toLowerCase().includes(f.query.toLowerCase()));
9637
- if (f?.updatedSince) pool = pool.filter((i) => (i.updatedAt ?? "") >= f.updatedSince);
9953
+ if (f?.statuses?.length) {
9954
+ const lower = f.statuses.map((s) => s.toLowerCase());
9955
+ pool = pool.filter((i) => lower.includes((i.status ?? "").toLowerCase()));
9956
+ }
9957
+ if (f?.types?.length) {
9958
+ const lower = f.types.map((t) => t.toLowerCase());
9959
+ pool = pool.filter((i) => lower.includes((i.type ?? "").toLowerCase()));
9960
+ }
9961
+ if (f?.labels?.length) {
9962
+ const lower = f.labels.map((l) => l.toLowerCase());
9963
+ pool = pool.filter((i) => i.labels?.some((il) => lower.includes(il.toLowerCase())));
9964
+ }
9965
+ if (f?.assignees?.length) {
9966
+ const lower = f.assignees.map((a) => a.toLowerCase());
9967
+ pool = pool.filter((i) => i.assignees?.some((a) => lower.includes((a.name ?? "").toLowerCase())));
9968
+ }
9969
+ if (f?.search) pool = pool.filter((i) => `${i.title} ${i.description ?? ""}`.toLowerCase().includes(f.search.toLowerCase()));
9970
+ if (f?.updatedAfter) pool = pool.filter((i) => (i.updatedAt ?? "") >= f.updatedAfter);
9638
9971
  const size = Math.max(1, request.pageSize ?? defaultPageSize);
9639
9972
  const start = request.cursor ? Math.max(0, Number.parseInt(request.cursor, 10) || 0) : 0;
9640
9973
  const slice = pool.slice(start, start + size);
@@ -9683,12 +10016,23 @@ function loadRaw(dir) {
9683
10016
  function loadIntegrations(dir) {
9684
10017
  return parseIntegrationsConfig(loadRaw(dir), { adapterIds: registry.ids() });
9685
10018
  }
10019
+ function saveIntegrations(dir, integrations) {
10020
+ const abs = join(dir, INTEGRATIONS_FILE);
10021
+ const data = serializeIntegrationsConfig(integrations);
10022
+ writeFile(abs, stringifyYaml5(data, { lineWidth: 120 }));
10023
+ }
9686
10024
  function configStatus(integration, findings) {
9687
10025
  if (!integration.enabled) return "disabled";
9688
10026
  const blocking = findings.some((f) => f.id === integration.id && f.level === "blocking");
9689
10027
  if (blocking || !registry.has(integration.adapter)) return "invalid-config";
9690
10028
  return "configured";
9691
10029
  }
10030
+ function secretProvider(dir) {
10031
+ return createLocalSecretProvider(dir);
10032
+ }
10033
+ function secretResolver(dir, env) {
10034
+ return createCompositeResolver(createLocalSecretProvider(dir), createEnvSecretProvider(env));
10035
+ }
9692
10036
  function listIntegrations(dir) {
9693
10037
  const { integrations, findings } = loadIntegrations(dir);
9694
10038
  return integrations.map((integration) => {
@@ -9702,23 +10046,74 @@ function listIntegrations(dir) {
9702
10046
  capabilities: adapter?.capabilities ?? null,
9703
10047
  metadata: adapter?.metadata ?? null,
9704
10048
  credentialRefs: Object.values(integration.credentials).map((c) => c.env),
10049
+ secretRefs: Object.values(integration.secrets),
10050
+ secretStatus: {},
10051
+ filters: integration.filters,
9705
10052
  findings: findings.filter((f) => f.id === integration.id)
9706
10053
  };
9707
10054
  });
9708
10055
  }
10056
+ function getIntegration(dir, id) {
10057
+ const { integrations, findings } = loadIntegrations(dir);
10058
+ const integration = integrations.find((i) => i.id === id);
10059
+ if (!integration) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured in this project.`);
10060
+ const adapter = registry.get(integration.adapter);
10061
+ return {
10062
+ id: integration.id,
10063
+ adapter: integration.adapter,
10064
+ enabled: integration.enabled,
10065
+ status: configStatus(integration, findings),
10066
+ displayName: adapter?.metadata.displayName ?? integration.adapter,
10067
+ capabilities: adapter?.capabilities ?? null,
10068
+ metadata: adapter?.metadata ?? null,
10069
+ credentialRefs: Object.values(integration.credentials).map((c) => c.env),
10070
+ secretRefs: Object.values(integration.secrets),
10071
+ secretStatus: {},
10072
+ filters: integration.filters,
10073
+ findings: findings.filter((f) => f.id === integration.id)
10074
+ };
10075
+ }
10076
+ async function getIntegrationSecretStatus(dir, id) {
10077
+ const { integrations } = loadIntegrations(dir);
10078
+ const integration = integrations.find((i) => i.id === id);
10079
+ if (!integration) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured.`);
10080
+ const sp = secretProvider(dir);
10081
+ const status = {};
10082
+ for (const [name, ref] of Object.entries(integration.secrets)) {
10083
+ status[name] = await sp.exists(ref);
10084
+ }
10085
+ for (const [name, ref] of Object.entries(integration.credentials)) {
10086
+ const val = process.env[ref.env];
10087
+ status[name] = val !== void 0 && val !== "";
10088
+ }
10089
+ return status;
10090
+ }
10091
+ function getAvailableIntegrationTypes() {
10092
+ return registry.list().map((a) => ({
10093
+ id: a.id,
10094
+ displayName: a.metadata.displayName,
10095
+ description: a.metadata.description,
10096
+ icon: a.metadata.icon,
10097
+ configSchema: a.metadata.configSchema ?? {},
10098
+ secretSchema: a.metadata.secretSchema ?? {},
10099
+ filterCapabilities: a.metadata.filterCapabilities,
10100
+ capabilities: a.capabilities
10101
+ }));
10102
+ }
9709
10103
  function requireIntegration(dir, id) {
9710
10104
  const { integrations, findings } = loadIntegrations(dir);
9711
10105
  const integration = integrations.find((i) => i.id === id);
9712
10106
  if (!integration) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured in this project.`);
9713
- return { integration, findings };
10107
+ return { integration, findings, all: integrations };
9714
10108
  }
9715
10109
  function resolveAdapter(integration) {
9716
10110
  const adapter = registry.get(integration.adapter);
9717
10111
  if (!adapter) throw new IntegrationServiceError("ADAPTER_NOT_FOUND", `Unknown integration adapter "${integration.adapter}".`);
9718
10112
  return adapter;
9719
10113
  }
9720
- function buildContext(integration, env) {
9721
- const { credentials, missing } = resolveCredentials(integration, env);
10114
+ async function buildContextWithSecrets(dir, integration, env) {
10115
+ const resolver = secretResolver(dir, env);
10116
+ const { credentials, missing } = await resolveAllCredentials(integration, resolver, env);
9722
10117
  return {
9723
10118
  context: { integrationId: integration.id, config: integration.config, credentials, timeoutMs: integration.timeoutMs ?? DEFAULT_TIMEOUT_MS },
9724
10119
  missing
@@ -9735,13 +10130,90 @@ async function withTimeout(op, ms) {
9735
10130
  if (timer) clearTimeout(timer);
9736
10131
  }
9737
10132
  }
10133
+ function validateId(id) {
10134
+ if (!id || !id.trim()) throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", "Integration id is required.");
10135
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(id)) throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", "Integration id must be alphanumeric with dashes, dots or underscores.");
10136
+ if (id.length > 64) throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", "Integration id must be 64 characters or fewer.");
10137
+ }
10138
+ function createIntegration(dir, input) {
10139
+ validateId(input.id);
10140
+ if (!input.adapter || !input.adapter.trim()) throw new IntegrationServiceError("INTEGRATION_INVALID_INPUT", "An adapter type is required.");
10141
+ const { integrations } = loadIntegrations(dir);
10142
+ if (integrations.find((i) => i.id === input.id)) {
10143
+ throw new IntegrationServiceError("INTEGRATION_ALREADY_EXISTS", `An integration with id "${input.id}" already exists.`);
10144
+ }
10145
+ const newConfig = integrationConfigFromInput(input);
10146
+ integrations.push(newConfig);
10147
+ saveIntegrations(dir, integrations);
10148
+ return getIntegration(dir, input.id);
10149
+ }
10150
+ function updateIntegration(dir, id, input) {
10151
+ const { integrations } = loadIntegrations(dir);
10152
+ const idx = integrations.findIndex((i) => i.id === id);
10153
+ if (idx < 0) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured.`);
10154
+ const existing = integrations[idx];
10155
+ if (input.enabled !== void 0) existing.enabled = input.enabled;
10156
+ if (input.config !== void 0) existing.config = input.config;
10157
+ if (input.secrets !== void 0) existing.secrets = input.secrets;
10158
+ if (input.timeoutMs !== void 0) existing.timeoutMs = input.timeoutMs;
10159
+ integrations[idx] = existing;
10160
+ saveIntegrations(dir, integrations);
10161
+ return getIntegration(dir, id);
10162
+ }
10163
+ function deleteIntegration(dir, id) {
10164
+ const { integrations } = loadIntegrations(dir);
10165
+ const idx = integrations.findIndex((i) => i.id === id);
10166
+ if (idx < 0) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured.`);
10167
+ const removed = integrations[idx];
10168
+ integrations.splice(idx, 1);
10169
+ saveIntegrations(dir, integrations);
10170
+ const sp = secretProvider(dir);
10171
+ for (const ref of Object.values(removed.secrets)) {
10172
+ sp.delete(ref).catch(() => {
10173
+ });
10174
+ }
10175
+ }
10176
+ function enableIntegration(dir, id) {
10177
+ return updateIntegration(dir, id, { enabled: true });
10178
+ }
10179
+ function disableIntegration(dir, id) {
10180
+ return updateIntegration(dir, id, { enabled: false });
10181
+ }
10182
+ async function setIntegrationSecret(dir, id, secretName, value) {
10183
+ const { integration } = requireIntegration(dir, id);
10184
+ const refKey = secretRefKey(id, secretName);
10185
+ const sp = secretProvider(dir);
10186
+ await sp.set(refKey, value);
10187
+ if (!integration.secrets[secretName] || integration.secrets[secretName] !== refKey) {
10188
+ const { integrations } = loadIntegrations(dir);
10189
+ const idx = integrations.findIndex((i) => i.id === id);
10190
+ if (idx >= 0) {
10191
+ integrations[idx].secrets[secretName] = refKey;
10192
+ saveIntegrations(dir, integrations);
10193
+ }
10194
+ }
10195
+ }
10196
+ async function removeIntegrationSecret(dir, id, secretName) {
10197
+ const { integration } = requireIntegration(dir, id);
10198
+ const refKey = integration.secrets[secretName];
10199
+ if (refKey) {
10200
+ const sp = secretProvider(dir);
10201
+ await sp.delete(refKey);
10202
+ }
10203
+ const { integrations } = loadIntegrations(dir);
10204
+ const idx = integrations.findIndex((i) => i.id === id);
10205
+ if (idx >= 0 && integrations[idx].secrets[secretName]) {
10206
+ delete integrations[idx].secrets[secretName];
10207
+ saveIntegrations(dir, integrations);
10208
+ }
10209
+ }
9738
10210
  async function verifyIntegration(dir, id, env = process.env) {
9739
10211
  const { integration, findings } = requireIntegration(dir, id);
9740
10212
  const cfgStatus = configStatus(integration, findings);
9741
10213
  if (cfgStatus === "disabled") return { id, status: "disabled", connection: null, missingCredentials: [] };
9742
10214
  if (cfgStatus === "invalid-config") return { id, status: "invalid-config", connection: null, missingCredentials: [] };
9743
10215
  const adapter = resolveAdapter(integration);
9744
- const { context, missing } = buildContext(integration, env);
10216
+ const { context, missing } = await buildContextWithSecrets(dir, integration, env);
9745
10217
  try {
9746
10218
  const connection = await withTimeout(adapter.verifyConnection(context), context.timeoutMs);
9747
10219
  return { id, status: statusOf(connection), connection, missingCredentials: missing, message: connection.message };
@@ -9762,18 +10234,107 @@ function statusOf(connection) {
9762
10234
  return "invalid-config";
9763
10235
  }
9764
10236
  }
10237
+ function getIntegrationFilters(dir, id) {
10238
+ const { integration } = requireIntegration(dir, id);
10239
+ return integration.filters ?? {};
10240
+ }
10241
+ function updateIntegrationFilters(dir, id, filters) {
10242
+ const { integrations } = loadIntegrations(dir);
10243
+ const idx = integrations.findIndex((i) => i.id === id);
10244
+ if (idx < 0) throw new IntegrationServiceError("INTEGRATION_NOT_CONFIGURED", `No integration "${id}" is configured.`);
10245
+ const clean = {};
10246
+ let hasAny = false;
10247
+ if (filters.types?.length) {
10248
+ clean.types = filters.types;
10249
+ hasAny = true;
10250
+ }
10251
+ if (filters.statuses?.length) {
10252
+ clean.statuses = filters.statuses;
10253
+ hasAny = true;
10254
+ }
10255
+ if (filters.labels?.length) {
10256
+ clean.labels = filters.labels;
10257
+ hasAny = true;
10258
+ }
10259
+ if (filters.assignees?.length) {
10260
+ clean.assignees = filters.assignees;
10261
+ hasAny = true;
10262
+ }
10263
+ if (filters.updatedAfter) {
10264
+ clean.updatedAfter = filters.updatedAfter;
10265
+ hasAny = true;
10266
+ }
10267
+ if (filters.search) {
10268
+ clean.search = filters.search;
10269
+ hasAny = true;
10270
+ }
10271
+ if (filters.providerQuery) {
10272
+ clean.providerQuery = filters.providerQuery;
10273
+ hasAny = true;
10274
+ }
10275
+ integrations[idx].filters = hasAny ? clean : void 0;
10276
+ saveIntegrations(dir, integrations);
10277
+ return getIntegration(dir, id);
10278
+ }
10279
+ async function discoverExternalWorkItems(dir, opts = {}, env = process.env) {
10280
+ const { integrations, findings } = loadIntegrations(dir);
10281
+ const candidates = integrations.filter((i) => {
10282
+ if (!i.enabled) return false;
10283
+ if (configStatus(i, findings) === "invalid-config") return false;
10284
+ if (opts.integrationIds?.length && !opts.integrationIds.includes(i.id)) return false;
10285
+ const adapter = registry.get(i.adapter);
10286
+ return adapter?.capabilities.workItems.list === true;
10287
+ });
10288
+ const settled = await Promise.allSettled(
10289
+ candidates.map(async (integration) => {
10290
+ const adapter = resolveAdapter(integration);
10291
+ const { context } = await buildContextWithSecrets(dir, integration, env);
10292
+ const filters = mergeFilters(integration.filters, opts.filters);
10293
+ const page = await withTimeout(
10294
+ adapter.listWorkItems({ context, pageSize: opts.pageSize, filters }),
10295
+ context.timeoutMs
10296
+ );
10297
+ return {
10298
+ integrationId: integration.id,
10299
+ adapter: integration.adapter,
10300
+ displayName: adapter.metadata.displayName,
10301
+ icon: adapter.metadata.icon,
10302
+ items: page.items,
10303
+ hasMore: page.hasMore,
10304
+ nextCursor: page.nextCursor
10305
+ };
10306
+ })
10307
+ );
10308
+ const results = settled.map((s, i) => {
10309
+ if (s.status === "fulfilled") return s.value;
10310
+ const integration = candidates[i];
10311
+ const adapter = registry.get(integration.adapter);
10312
+ const msg = s.reason instanceof IntegrationError ? s.reason.safeMessage : "An unexpected error occurred.";
10313
+ return {
10314
+ integrationId: integration.id,
10315
+ adapter: integration.adapter,
10316
+ displayName: adapter?.metadata.displayName ?? integration.adapter,
10317
+ icon: adapter?.metadata.icon,
10318
+ items: [],
10319
+ hasMore: false,
10320
+ error: msg
10321
+ };
10322
+ });
10323
+ return { results, totalItems: results.reduce((sum, r) => sum + r.items.length, 0) };
10324
+ }
9765
10325
  async function listExternalWorkItems(dir, id, opts = {}, env = process.env) {
9766
10326
  const { integration } = requireIntegration(dir, id);
9767
10327
  const adapter = resolveAdapter(integration);
9768
10328
  if (!adapter.capabilities.workItems.list) throw integrationError("UNSUPPORTED_CAPABILITY", `Adapter "${adapter.id}" cannot list work items.`);
9769
- const { context } = buildContext(integration, env);
9770
- return withTimeout(adapter.listWorkItems({ context, cursor: opts.cursor, pageSize: opts.pageSize, filters: opts.filters }), context.timeoutMs);
10329
+ const { context } = await buildContextWithSecrets(dir, integration, env);
10330
+ const filters = mergeFilters(integration.filters, opts.filters);
10331
+ return withTimeout(adapter.listWorkItems({ context, cursor: opts.cursor, pageSize: opts.pageSize, filters }), context.timeoutMs);
9771
10332
  }
9772
10333
  async function getExternalWorkItem(dir, id, externalId, env = process.env) {
9773
10334
  const { integration } = requireIntegration(dir, id);
9774
10335
  const adapter = resolveAdapter(integration);
9775
10336
  if (!adapter.capabilities.workItems.read) throw integrationError("UNSUPPORTED_CAPABILITY", `Adapter "${adapter.id}" cannot read work items.`);
9776
- const { context } = buildContext(integration, env);
10337
+ const { context } = await buildContextWithSecrets(dir, integration, env);
9777
10338
  return withTimeout(adapter.getWorkItem({ context, externalId }), context.timeoutMs);
9778
10339
  }
9779
10340
  function findLinkedWorkItem(dir, integrationId, externalId) {
@@ -9837,15 +10398,24 @@ export {
9837
10398
  buildRefinementHandoff,
9838
10399
  buildTopologyEnrichmentHandoff,
9839
10400
  computeRefinementStatus,
10401
+ createIntegration,
9840
10402
  createWorkItem,
9841
10403
  cwd,
10404
+ deleteIntegration,
10405
+ disableIntegration,
10406
+ discoverExternalWorkItems,
9842
10407
  discoverKnowledge,
9843
10408
  discoverWorkItems,
10409
+ enableIntegration,
9844
10410
  exists,
9845
10411
  findLinkedWorkItem,
9846
10412
  findSystemPaths,
10413
+ getAvailableIntegrationTypes,
9847
10414
  getExternalWorkItem,
9848
10415
  getImpactCandidates,
10416
+ getIntegration,
10417
+ getIntegrationFilters,
10418
+ getIntegrationSecretStatus,
9849
10419
  getSystemMapProjection,
9850
10420
  getSystemNeighbors,
9851
10421
  getSystemNodeContext,
@@ -9869,9 +10439,13 @@ export {
9869
10439
  loadSystemTopology,
9870
10440
  previewImport,
9871
10441
  readFile,
10442
+ removeIntegrationSecret,
9872
10443
  searchSystemNodes,
10444
+ setIntegrationSecret,
9873
10445
  topologyRevision,
9874
10446
  transitionWorkItem,
10447
+ updateIntegration,
10448
+ updateIntegrationFilters,
9875
10449
  updateWorkItem,
9876
10450
  validateSystemTopology,
9877
10451
  validateTopologyProposal,