@taiga-ai/mcp-server 0.37.0-dev.1147 → 0.37.0-dev.1149

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/index.js +1355 -1214
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24339,7 +24339,8 @@ const STACK_FACETS = [
24339
24339
  "iac",
24340
24340
  "scripting",
24341
24341
  "data_store",
24342
- "ci_cd"
24342
+ "ci_cd",
24343
+ "iac_state"
24343
24344
  ];
24344
24345
  const LANGUAGES = {
24345
24346
  typescript: {
@@ -24478,18 +24479,21 @@ const LANGUAGES = {
24478
24479
  "apex"
24479
24480
  ],
24480
24481
  files: ["sfdx-project.json"]
24481
- }
24482
+ },
24483
+ clouds: ["salesforce"]
24482
24484
  }
24483
24485
  };
24484
24486
  const FRAMEWORKS = {
24485
24487
  react: {
24486
24488
  label: "React",
24487
24489
  languages: ["typescript"],
24490
+ role: "frontend",
24488
24491
  detectors: { topics: ["react", "reactjs"] }
24489
24492
  },
24490
24493
  nextjs: {
24491
24494
  label: "Next.js",
24492
24495
  languages: ["typescript"],
24496
+ role: "frontend",
24493
24497
  detectors: {
24494
24498
  topics: ["nextjs"],
24495
24499
  files: [
@@ -24502,6 +24506,7 @@ const FRAMEWORKS = {
24502
24506
  angular: {
24503
24507
  label: "Angular",
24504
24508
  languages: ["typescript"],
24509
+ role: "frontend",
24505
24510
  detectors: {
24506
24511
  topics: ["angular"],
24507
24512
  files: ["angular.json"]
@@ -24510,6 +24515,7 @@ const FRAMEWORKS = {
24510
24515
  vue: {
24511
24516
  label: "Vue",
24512
24517
  languages: ["typescript"],
24518
+ role: "frontend",
24513
24519
  detectors: {
24514
24520
  linguist: ["Vue"],
24515
24521
  topics: ["vue", "vuejs"]
@@ -24518,6 +24524,7 @@ const FRAMEWORKS = {
24518
24524
  nuxt: {
24519
24525
  label: "Nuxt",
24520
24526
  languages: ["typescript"],
24527
+ role: "frontend",
24521
24528
  detectors: {
24522
24529
  topics: ["nuxt", "nuxtjs"],
24523
24530
  files: ["nuxt.config.ts", "nuxt.config.js"]
@@ -24526,6 +24533,7 @@ const FRAMEWORKS = {
24526
24533
  sveltekit: {
24527
24534
  label: "SvelteKit",
24528
24535
  languages: ["typescript"],
24536
+ role: "frontend",
24529
24537
  detectors: {
24530
24538
  linguist: ["Svelte"],
24531
24539
  topics: ["svelte", "sveltekit"],
@@ -24535,6 +24543,7 @@ const FRAMEWORKS = {
24535
24543
  react_native: {
24536
24544
  label: "React Native",
24537
24545
  languages: ["typescript"],
24546
+ role: "mobile",
24538
24547
  detectors: {
24539
24548
  topics: ["react-native", "expo"],
24540
24549
  files: ["eas.json"]
@@ -24543,6 +24552,7 @@ const FRAMEWORKS = {
24543
24552
  nestjs: {
24544
24553
  label: "NestJS",
24545
24554
  languages: ["typescript"],
24555
+ role: "backend",
24546
24556
  detectors: {
24547
24557
  topics: ["nestjs"],
24548
24558
  files: ["nest-cli.json"]
@@ -24551,16 +24561,19 @@ const FRAMEWORKS = {
24551
24561
  fastify: {
24552
24562
  label: "Fastify",
24553
24563
  languages: ["typescript"],
24564
+ role: "backend",
24554
24565
  detectors: { topics: ["fastify"] }
24555
24566
  },
24556
24567
  express: {
24557
24568
  label: "Express",
24558
24569
  languages: ["typescript"],
24570
+ role: "backend",
24559
24571
  detectors: { topics: ["express", "expressjs"] }
24560
24572
  },
24561
24573
  django: {
24562
24574
  label: "Django",
24563
24575
  languages: ["python"],
24576
+ role: "backend",
24564
24577
  detectors: {
24565
24578
  topics: ["django"],
24566
24579
  files: ["manage.py"]
@@ -24569,36 +24582,43 @@ const FRAMEWORKS = {
24569
24582
  fastapi: {
24570
24583
  label: "FastAPI",
24571
24584
  languages: ["python"],
24585
+ role: "backend",
24572
24586
  detectors: { topics: ["fastapi"] }
24573
24587
  },
24574
24588
  flask: {
24575
24589
  label: "Flask",
24576
24590
  languages: ["python"],
24591
+ role: "backend",
24577
24592
  detectors: { topics: ["flask"] }
24578
24593
  },
24579
24594
  spring_boot: {
24580
24595
  label: "Spring Boot",
24581
24596
  languages: ["java", "kotlin"],
24597
+ role: "backend",
24582
24598
  detectors: { topics: ["spring-boot", "spring"] }
24583
24599
  },
24584
24600
  quarkus: {
24585
24601
  label: "Quarkus",
24586
24602
  languages: ["java", "kotlin"],
24603
+ role: "backend",
24587
24604
  detectors: { topics: ["quarkus"] }
24588
24605
  },
24589
24606
  micronaut: {
24590
24607
  label: "Micronaut",
24591
24608
  languages: ["java", "kotlin"],
24609
+ role: "backend",
24592
24610
  detectors: { topics: ["micronaut"] }
24593
24611
  },
24594
24612
  ktor: {
24595
24613
  label: "Ktor",
24596
24614
  languages: ["kotlin"],
24615
+ role: "backend",
24597
24616
  detectors: { topics: ["ktor"] }
24598
24617
  },
24599
24618
  aspnet_core: {
24600
24619
  label: "ASP.NET Core",
24601
24620
  languages: ["csharp"],
24621
+ role: "backend",
24602
24622
  detectors: { topics: [
24603
24623
  "aspnetcore",
24604
24624
  "asp-net-core",
@@ -24608,6 +24628,7 @@ const FRAMEWORKS = {
24608
24628
  blazor: {
24609
24629
  label: "Blazor",
24610
24630
  languages: ["csharp"],
24631
+ role: "frontend",
24611
24632
  detectors: {
24612
24633
  topics: ["blazor"],
24613
24634
  files: ["*.razor"]
@@ -24616,6 +24637,7 @@ const FRAMEWORKS = {
24616
24637
  laravel: {
24617
24638
  label: "Laravel",
24618
24639
  languages: ["php"],
24640
+ role: "backend",
24619
24641
  detectors: {
24620
24642
  topics: ["laravel"],
24621
24643
  files: ["artisan"]
@@ -24624,6 +24646,7 @@ const FRAMEWORKS = {
24624
24646
  symfony: {
24625
24647
  label: "Symfony",
24626
24648
  languages: ["php"],
24649
+ role: "backend",
24627
24650
  detectors: {
24628
24651
  topics: ["symfony"],
24629
24652
  files: ["symfony.lock"]
@@ -24632,11 +24655,13 @@ const FRAMEWORKS = {
24632
24655
  drupal: {
24633
24656
  label: "Drupal",
24634
24657
  languages: ["php"],
24658
+ role: "backend",
24635
24659
  detectors: { topics: ["drupal"] }
24636
24660
  },
24637
24661
  rails: {
24638
24662
  label: "Rails",
24639
24663
  languages: ["ruby"],
24664
+ role: "backend",
24640
24665
  detectors: {
24641
24666
  topics: ["rails", "ruby-on-rails"],
24642
24667
  files: ["bin/rails", "config/routes.rb"]
@@ -24645,20 +24670,24 @@ const FRAMEWORKS = {
24645
24670
  phoenix: {
24646
24671
  label: "Phoenix",
24647
24672
  languages: ["elixir"],
24673
+ role: "backend",
24648
24674
  detectors: { topics: ["phoenix", "phoenix-framework"] }
24649
24675
  },
24650
24676
  flutter: {
24651
24677
  label: "Flutter",
24652
24678
  languages: ["dart"],
24679
+ role: "mobile",
24653
24680
  detectors: { topics: ["flutter"] }
24654
24681
  },
24655
24682
  lwc: {
24656
24683
  label: "Lightning Web Components",
24657
24684
  languages: ["apex"],
24685
+ role: "frontend",
24658
24686
  detectors: {
24659
24687
  topics: ["lightning-web-components", "lwc"],
24660
24688
  files: ["force-app/main/default/lwc"]
24661
- }
24689
+ },
24690
+ clouds: ["salesforce"]
24662
24691
  }
24663
24692
  };
24664
24693
  const IAC = {
@@ -24676,21 +24705,24 @@ const IAC = {
24676
24705
  linguist: ["Bicep"],
24677
24706
  topics: ["bicep", "arm-templates"],
24678
24707
  files: ["*.bicep", "azuredeploy.json"]
24679
- }
24708
+ },
24709
+ clouds: ["azure"]
24680
24710
  },
24681
24711
  cloudformation: {
24682
24712
  label: "CloudFormation / SAM",
24683
24713
  detectors: {
24684
24714
  topics: ["cloudformation", "aws-sam"],
24685
24715
  files: ["template.yaml", "samconfig.toml"]
24686
- }
24716
+ },
24717
+ clouds: ["aws"]
24687
24718
  },
24688
24719
  aws_cdk: {
24689
24720
  label: "AWS CDK",
24690
24721
  detectors: {
24691
24722
  topics: ["aws-cdk", "cdk"],
24692
24723
  files: ["cdk.json"]
24693
- }
24724
+ },
24725
+ clouds: ["aws"]
24694
24726
  },
24695
24727
  pulumi: {
24696
24728
  label: "Pulumi",
@@ -24792,11 +24824,13 @@ const DATA_STORES = {
24792
24824
  },
24793
24825
  dynamodb: {
24794
24826
  label: "DynamoDB",
24795
- detectors: { topics: ["dynamodb"] }
24827
+ detectors: { topics: ["dynamodb"] },
24828
+ clouds: ["aws"]
24796
24829
  },
24797
24830
  cosmos_db: {
24798
24831
  label: "Cosmos DB",
24799
- detectors: { topics: ["cosmosdb", "azure-cosmos-db"] }
24832
+ detectors: { topics: ["cosmosdb", "azure-cosmos-db"] },
24833
+ clouds: ["azure"]
24800
24834
  }
24801
24835
  };
24802
24836
  const CI_CD = {
@@ -24843,12 +24877,95 @@ const CI_CD = {
24843
24877
  aws_codebuild: {
24844
24878
  label: "AWS CodeBuild / CodePipeline",
24845
24879
  ciSystem: "external",
24846
- detectors: { files: ["buildspec.yml"] }
24880
+ detectors: { files: ["buildspec.yml"] },
24881
+ clouds: ["aws"]
24847
24882
  },
24848
24883
  google_cloud_build: {
24849
24884
  label: "Google Cloud Build",
24850
24885
  ciSystem: "external",
24851
- detectors: { files: ["cloudbuild.yaml", "cloudbuild.yml"] }
24886
+ detectors: { files: ["cloudbuild.yaml", "cloudbuild.yml"] },
24887
+ clouds: ["gcp"]
24888
+ }
24889
+ };
24890
+ /**
24891
+ * Where Terraform / OpenTofu or Pulumi keeps its state: a bucket in the
24892
+ * organization's own cloud, or a service that holds it. CloudFormation, CDK
24893
+ * and Bicep have no state file of their own (the cloud keeps it), and Ansible
24894
+ * keeps none, so they have no entry here.
24895
+ */
24896
+ const IAC_STATE = {
24897
+ s3: {
24898
+ label: "S3",
24899
+ sublabel: "AWS",
24900
+ iacTools: ["terraform", "pulumi"],
24901
+ detectors: {},
24902
+ clouds: ["aws"]
24903
+ },
24904
+ azure_blob: {
24905
+ label: "Azure Blob Storage",
24906
+ iacTools: ["terraform", "pulumi"],
24907
+ detectors: {},
24908
+ clouds: ["azure"]
24909
+ },
24910
+ gcs: {
24911
+ label: "Cloud Storage",
24912
+ sublabel: "Google Cloud",
24913
+ iacTools: ["terraform", "pulumi"],
24914
+ detectors: {},
24915
+ clouds: ["gcp"]
24916
+ },
24917
+ upcloud_object_storage: {
24918
+ label: "UpCloud Object Storage",
24919
+ iacTools: ["terraform", "pulumi"],
24920
+ detectors: {},
24921
+ clouds: ["upcloud"]
24922
+ },
24923
+ hcp_terraform: {
24924
+ label: "HCP Terraform",
24925
+ sublabel: "Terraform Cloud",
24926
+ iacTools: ["terraform"],
24927
+ detectors: { topics: ["terraform-cloud", "hcp-terraform"] }
24928
+ },
24929
+ terraform_enterprise: {
24930
+ label: "Terraform Enterprise",
24931
+ iacTools: ["terraform"],
24932
+ detectors: { topics: ["terraform-enterprise"] }
24933
+ },
24934
+ spacelift: {
24935
+ label: "Spacelift",
24936
+ iacTools: ["terraform"],
24937
+ detectors: {
24938
+ topics: ["spacelift"],
24939
+ files: [".spacelift/config.yml"]
24940
+ }
24941
+ },
24942
+ env0: {
24943
+ label: "env0",
24944
+ iacTools: ["terraform"],
24945
+ detectors: {
24946
+ topics: ["env0"],
24947
+ files: ["env0.yml"]
24948
+ }
24949
+ },
24950
+ scalr: {
24951
+ label: "Scalr",
24952
+ iacTools: ["terraform"],
24953
+ detectors: { topics: ["scalr"] }
24954
+ },
24955
+ gitlab_terraform_state: {
24956
+ label: "GitLab-managed state",
24957
+ iacTools: ["terraform"],
24958
+ detectors: {}
24959
+ },
24960
+ pulumi_cloud: {
24961
+ label: "Pulumi Cloud",
24962
+ iacTools: ["pulumi"],
24963
+ detectors: {}
24964
+ },
24965
+ pulumi_self_hosted: {
24966
+ label: "Pulumi self-hosted",
24967
+ iacTools: ["pulumi"],
24968
+ detectors: {}
24852
24969
  }
24853
24970
  };
24854
24971
  function entries(facet, group) {
@@ -24858,6 +24975,9 @@ function entries(facet, group) {
24858
24975
  label: shape.label,
24859
24976
  ...shape.sublabel ? { sublabel: shape.sublabel } : {},
24860
24977
  languages: "languages" in shape ? shape.languages : [],
24978
+ role: "role" in shape ? shape.role : null,
24979
+ iacTools: "iacTools" in shape ? shape.iacTools : [],
24980
+ clouds: shape.clouds ?? [],
24861
24981
  ciSystem: "ciSystem" in shape ? shape.ciSystem : null,
24862
24982
  detectors: shape.detectors
24863
24983
  }));
@@ -24869,7 +24989,8 @@ const STACK_CATALOGUE = [
24869
24989
  ...entries("iac", IAC),
24870
24990
  ...entries("scripting", SCRIPTING),
24871
24991
  ...entries("data_store", DATA_STORES),
24872
- ...entries("ci_cd", CI_CD)
24992
+ ...entries("ci_cd", CI_CD),
24993
+ ...entries("iac_state", IAC_STATE)
24873
24994
  ];
24874
24995
  const STACK_ENTRY_IDS = STACK_CATALOGUE.map((entry) => entry.id);
24875
24996
  const BY_ID = new Map(STACK_CATALOGUE.map((entry) => [entry.id, entry]));
@@ -24879,6 +25000,13 @@ function stackEntry(id) {
24879
25000
  return entry;
24880
25001
  }
24881
25002
  /**
25003
+ * The entries an entry sits under, one of which a declaration must name: a
25004
+ * framework's languages, a state location's tools. Empty for the rest.
25005
+ */
25006
+ function stackEntryParents(entry) {
25007
+ return entry.facet === "framework" ? entry.languages : entry.facet === "iac_state" ? entry.iacTools : [];
25008
+ }
25009
+ /**
24882
25010
  * Every name an entry answers to, lowercased: its id, its label, each part of
24883
25011
  * a combined label ("TypeScript / JavaScript" is also JavaScript), and its
24884
25012
  * sublabel ("Node.js").
@@ -24893,18 +25021,30 @@ function namesOf(entry) {
24893
25021
  return new Set(names.map((name) => name.trim().toLowerCase()).filter((name) => name.length > 0));
24894
25022
  }
24895
25023
  /**
25024
+ * The catalogue entry a "not listed" name already is in its facet, if any:
25025
+ * "JavaScript" in languages is TypeScript / JavaScript. The screen says so
25026
+ * before the schema refuses it.
25027
+ */
25028
+ function catalogueEntryNamed(facet, name) {
25029
+ const key = name.trim().toLowerCase();
25030
+ return STACK_CATALOGUE.find((entry) => entry.facet === facet && namesOf(entry).has(key));
25031
+ }
25032
+ /** What a "not listed" name may not contain: it lands in one Markdown table cell. */
25033
+ const STACK_NOT_LISTED_FORBIDDEN = /[\r\n\t|]/;
25034
+ /**
24896
25035
  * What an organization declares: catalogue entries, and technologies the
24897
25036
  * catalogue does not list, each named in its facet. A "not listed" name is
24898
25037
  * stated in the policy as declared and never promises a build.
24899
25038
  *
24900
- * A framework needs one of its languages: a declaration naming Laravel
24901
- * without PHP is refused rather than guessed at.
25039
+ * A framework needs one of its languages, and a state location one of its
25040
+ * tools: a declaration naming Laravel without PHP, or S3 state without
25041
+ * Terraform or Pulumi, is refused rather than guessed at.
24902
25042
  */
24903
25043
  const stackDeclarationSchema = object({
24904
25044
  entries: array(_enum(STACK_ENTRY_IDS)).max(STACK_ENTRY_IDS.length * 2),
24905
25045
  notListed: array(object({
24906
25046
  facet: _enum(STACK_FACETS),
24907
- name: string$2().trim().min(1).max(60).regex(/^[^\r\n\t|]+$/, { message: "Use one line without |" })
25047
+ name: string$2().trim().min(1).max(60).refine((value) => !STACK_NOT_LISTED_FORBIDDEN.test(value), { message: "Use one line without |" })
24908
25048
  })).max(20).default([])
24909
25049
  }).superRefine((declaration, ctx) => {
24910
25050
  if (declaration.entries.length === 0 && declaration.notListed.length === 0) ctx.addIssue({
@@ -24915,16 +25055,17 @@ const stackDeclarationSchema = object({
24915
25055
  const chosen = new Set(declaration.entries);
24916
25056
  declaration.entries.forEach((id, index) => {
24917
25057
  const entry = BY_ID.get(id);
24918
- if (entry?.facet === "framework" && !entry.languages.some((language) => chosen.has(language))) ctx.addIssue({
25058
+ const parents = entry ? stackEntryParents(entry) : [];
25059
+ if (entry && parents.length > 0 && !parents.some((parent) => chosen.has(parent))) ctx.addIssue({
24919
25060
  code: "custom",
24920
25061
  path: ["entries", index],
24921
- message: `${entry.label} needs one of its languages: ${entry.languages.map((l) => stackEntry(l).label).join(", ")}`
25062
+ message: `${entry.label} needs one of: ${parents.map((p) => stackEntry(p).label).join(", ")}`
24922
25063
  });
24923
25064
  });
24924
25065
  const seen = /* @__PURE__ */ new Set();
24925
25066
  declaration.notListed.forEach(({ facet, name }, index) => {
24926
25067
  const key = name.toLowerCase();
24927
- const listed = STACK_CATALOGUE.find((entry) => entry.facet === facet && namesOf(entry).has(key));
25068
+ const listed = catalogueEntryNamed(facet, name);
24928
25069
  if (listed) ctx.addIssue({
24929
25070
  code: "custom",
24930
25071
  path: [
@@ -31149,781 +31290,13 @@ const SIGNAL_KINDS = [
31149
31290
  */
31150
31291
  const DEPLOYMENT_NOTES_MAX_LENGTH = 4e3;
31151
31292
  //#endregion
31152
- //#region src/compat.ts
31153
- /**
31154
- * Why this server should not serve the API it reached, or null when it may
31155
- * (PRO-2844). The server is published to npm and the API deploys on its own
31156
- * schedule, so a newer server can meet an older API. It would not fail
31157
- * loudly: some tools read a 404 as a state of the world (a run not found
31158
- * reads as deleted) and fields they explain would simply be missing. So it
31159
- * refuses to start, and says what to do.
31160
- */
31161
- function apiLevelProblem(introspection, apiUrl, required = 9, version = SERVER_VERSION) {
31162
- const offered = introspection.mcpApiLevel ?? 0;
31163
- if (offered >= required) return null;
31164
- return `The Taiga API at ${apiUrl} is older than @taiga-ai/mcp-server ${version} needs (API level ${offered}, needs ${required}). Run the version published for it, or wait for that API to be updated; an earlier release of this package works against it.`;
31165
- }
31166
- //#endregion
31167
- //#region src/tools/toolsets.ts
31168
- /**
31169
- * Toolsets (PRO-2846, PRO-2838): the tools an AI tool sees, grouped by what the person does.
31170
- *
31171
- * A role decides what a key MAY do (the API enforces it, and tools a key cannot use are never registered); a toolset
31172
- * decides what it SEES. A toolset never adds a tool the key's capabilities do not allow. Every toolset is on unless
31173
- * the key says otherwise: the person chooses them for the key in Taiga's settings, and the server reads them at
31174
- * start. Toolsets alone barely changed what the task test cost in Claude Code, which loads tool details on demand,
31175
- * so the default is everything rather than a short list someone has to know how to widen. The tool list stays the
31176
- * same for every connection of one server (MCP 2026-07-28), so the set is fixed at start, not mid-session.
31177
- */
31178
- const TOOLSETS = MCP_TOOLSETS;
31179
- /** What each toolset is for, as whoami says it. */
31180
- const TOOLSET_PURPOSE = {
31181
- core: "where products, initiatives, runs, policies and findings stand",
31182
- operate: "moving work: queue, plans, runs, fixes, Action Required",
31183
- setup: "creating and configuring factories, products, repositories, environments and autonomy",
31184
- observe: "deployments, monitoring, delivery metrics, the package inventory and the sweeps that read it",
31185
- documents: "writing documents and knowledge, and regenerating product documents"
31186
- };
31187
- /** Every tool's toolset. A tool missing here fails at registration, so none can be added without a home. */
31188
- const TOOLSET_OF = {
31189
- taiga_list_products: "core",
31190
- taiga_get_product_context: "core",
31191
- taiga_get_product: "core",
31192
- taiga_list_factories: "core",
31193
- taiga_list_initiatives: "core",
31194
- taiga_get_initiative: "core",
31195
- taiga_get_plan: "core",
31196
- taiga_list_runs: "core",
31197
- taiga_get_run: "core",
31198
- taiga_get_line: "core",
31199
- taiga_list_action_required: "core",
31200
- taiga_get_policy_standing: "core",
31201
- taiga_list_findings: "core",
31202
- taiga_get_finding: "core",
31203
- taiga_get_organization_document: "core",
31204
- taiga_get_design_tokens: "core",
31205
- taiga_get_design_token_sync: "core",
31206
- taiga_get_product_document: "core",
31207
- taiga_wait: "core",
31208
- taiga_queue_initiative: "operate",
31209
- taiga_move_initiative: "operate",
31210
- taiga_review_plan: "operate",
31211
- taiga_plan_again: "operate",
31212
- taiga_resume_initiative: "operate",
31213
- taiga_stop_run: "operate",
31214
- taiga_request_changes: "operate",
31215
- taiga_request_initiatives: "operate",
31216
- taiga_fix_finding: "operate",
31217
- taiga_fix_policy_violation: "operate",
31218
- taiga_ignore_finding: "operate",
31219
- taiga_allow_license: "operate",
31220
- taiga_resolve_action: "operate",
31221
- taiga_create_factory: "setup",
31222
- taiga_rename_factory: "setup",
31223
- taiga_create_product: "setup",
31224
- taiga_update_product: "setup",
31225
- taiga_move_product: "setup",
31226
- taiga_preview_product_move: "setup",
31227
- taiga_link_repository: "setup",
31228
- taiga_unlink_repository: "setup",
31229
- taiga_list_linkable_repositories: "setup",
31230
- taiga_list_product_repositories: "setup",
31231
- taiga_list_repository_branches: "setup",
31232
- taiga_set_repository_branch: "setup",
31233
- taiga_start_import: "setup",
31234
- taiga_finish_discovery: "setup",
31235
- taiga_reopen_discovery: "setup",
31236
- taiga_list_setup_tasks: "setup",
31237
- taiga_get_job: "setup",
31238
- taiga_set_auto_build: "setup",
31239
- taiga_set_auto_merge: "setup",
31240
- taiga_set_product_autonomy: "setup",
31241
- taiga_pause_line: "setup",
31242
- taiga_create_environment: "setup",
31243
- taiga_update_environment: "setup",
31244
- taiga_ship_notices: "setup",
31245
- taiga_allow_license_package: "setup",
31246
- taiga_replace_license_package: "setup",
31247
- taiga_get_deployments: "observe",
31248
- taiga_get_monitoring: "observe",
31249
- taiga_get_delivery_metrics: "observe",
31250
- taiga_list_packages: "observe",
31251
- taiga_start_sweep: "observe",
31252
- taiga_list_licenses: "observe",
31253
- taiga_change_license: "setup",
31254
- taiga_get_model_connection: "setup",
31255
- taiga_set_model_connection: "setup",
31256
- taiga_remove_model_connection: "setup",
31257
- taiga_get_sbom: "observe",
31258
- taiga_get_notices: "observe",
31259
- taiga_get_factory_document: "documents",
31260
- taiga_update_organization_document: "documents",
31261
- taiga_publish_organization_document: "documents",
31262
- taiga_update_design_tokens: "documents",
31263
- taiga_sync_design_tokens: "documents",
31264
- taiga_update_factory_document: "documents",
31265
- taiga_publish_factory_document: "documents",
31266
- taiga_update_product_document: "documents",
31267
- taiga_publish_product_document: "documents",
31268
- taiga_mark_product_document_reviewed: "documents",
31269
- taiga_generate_product_documents: "documents",
31270
- taiga_regenerate_product_document: "documents",
31271
- taiga_stop_generating_documents: "documents",
31272
- taiga_refresh_reality_documents: "documents",
31273
- taiga_list_knowledge: "documents",
31274
- taiga_get_knowledge: "documents",
31275
- taiga_add_knowledge: "documents",
31276
- taiga_delete_knowledge: "documents",
31277
- taiga_retry_knowledge: "documents"
31278
- };
31279
- /**
31280
- * What steers agents leaves with them: knowledge, a factory's instructions
31281
- * and the design tokens, as the app hides those pages by the same rule.
31282
- *
31283
- * Deliver & Operate's tools (PRO-3834): initiatives, plans, runs and the line, fixes, environments, deployments,
31284
- * monitoring and delivery metrics. An organization whose plan refuses delivery work does not see them, as its web app
31285
- * shows none of their views; the API says which (`deliveryIncluded` at introspection), so the plan, not the key,
31286
- * decides. Fixing a finding plans and builds, so it goes with them.
31287
- */
31288
- const DELIVERY_TOOLS = /* @__PURE__ */ new Set([
31289
- "taiga_list_initiatives",
31290
- "taiga_get_initiative",
31291
- "taiga_get_plan",
31292
- "taiga_list_runs",
31293
- "taiga_get_run",
31294
- "taiga_get_line",
31295
- "taiga_queue_initiative",
31296
- "taiga_move_initiative",
31297
- "taiga_review_plan",
31298
- "taiga_plan_again",
31299
- "taiga_resume_initiative",
31300
- "taiga_stop_run",
31301
- "taiga_request_changes",
31302
- "taiga_request_initiatives",
31303
- "taiga_fix_finding",
31304
- "taiga_fix_policy_violation",
31305
- "taiga_replace_license_package",
31306
- "taiga_ship_notices",
31307
- "taiga_set_auto_build",
31308
- "taiga_set_auto_merge",
31309
- "taiga_pause_line",
31310
- "taiga_create_environment",
31311
- "taiga_update_environment",
31312
- "taiga_get_deployments",
31313
- "taiga_get_monitoring",
31314
- "taiga_get_delivery_metrics",
31315
- "taiga_sync_design_tokens",
31316
- "taiga_get_design_tokens",
31317
- "taiga_get_design_token_sync",
31318
- "taiga_update_design_tokens",
31319
- "taiga_get_factory_document",
31320
- "taiga_update_factory_document",
31321
- "taiga_publish_factory_document",
31322
- "taiga_list_knowledge",
31323
- "taiga_get_knowledge",
31324
- "taiga_add_knowledge",
31325
- "taiga_delete_knowledge",
31326
- "taiga_retry_knowledge"
31327
- ]);
31328
- /**
31329
- * TAIGA_TOOLSETS as written: comma-separated names, or "all"; a name it does not know is said, not ignored, and so
31330
- * is a value that names none.
31331
- */
31332
- function parseToolsets(raw) {
31333
- const names = raw.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean);
31334
- const unknown = names.filter((name) => name !== "all" && !TOOLSETS.includes(name));
31335
- if (unknown.length > 0 || names.length === 0) return { problem: `TAIGA_TOOLSETS ${unknown.length > 0 ? `names ${unknown.join(", ")}, which is no toolset` : "names no toolset"}: use ${TOOLSETS.join(", ")} or all.` };
31336
- return { toolsets: names.includes("all") ? TOOLSETS : [...new Set(names)] };
31337
- }
31338
- /**
31339
- * The toolsets a server turns on: TAIGA_TOOLSETS when the server's config names some, else the ones the key names,
31340
- * else every one. A name the server does not know (a key set by a newer Taiga) is passed over; a key that names
31341
- * none this server knows sees every one, rather than starting with no tools.
31342
- */
31343
- function activeToolsets(fromKey, fromConfig) {
31344
- const named = fromConfig ?? fromKey?.filter((name) => TOOLSETS.includes(name));
31345
- if (!named || named.length === 0) return [...TOOLSETS];
31346
- return TOOLSETS.filter((toolset) => named.includes(toolset));
31347
- }
31348
- //#endregion
31349
- //#region src/config.ts
31293
+ //#region ../../packages/types/dist/licenses/spdx-license-list.js
31350
31294
  /**
31351
- * The one place the MCP server reads its environment (PRO-2511), parsed once
31352
- * at startup.
31353
- */
31354
- const DEFAULT_API_URL = "https://api.eu.tai.ga";
31355
- const envSchema = object({
31356
- TAIGA_API_KEY: string$2().optional(),
31357
- TAIGA_API_URL: string$2().optional(),
31358
- TAIGA_TOOLSETS: string$2().optional()
31359
- });
31360
- /** Hosts a developer runs the API on; the only ones plain http is accepted for. */
31361
- const LOCAL_HOSTS = /* @__PURE__ */ new Set([
31362
- "localhost",
31363
- "127.0.0.1",
31364
- "[::1]"
31365
- ]);
31366
- /**
31367
- * Read the environment (PRO-2844). The key carries its owner's reach, so it
31368
- * goes only to an https API (http for a local one). A pre-release build
31369
- * (`-dev.N`, `-rc.N`) is Taiga's own dev or staging channel, and defaulting it
31370
- * to production sent `npx @taiga-ai/mcp-server@staging` to the production API
31371
- * with a staging key: it must name its API. A released version defaults to
31372
- * production.
31373
- */
31374
- function readConfig(version = SERVER_VERSION) {
31375
- const env = envSchema.parse(process.env);
31376
- if (!env.TAIGA_API_KEY) return { problem: "TAIGA_API_KEY environment variable is required. Create one at https://eu.tai.ga under Settings > Account > MCP." };
31377
- const prerelease = version.includes("-");
31378
- if (!env.TAIGA_API_URL && prerelease) return { problem: `This is a pre-release build (${version}) for one of Taiga's own environments: set TAIGA_API_URL to that environment's API. A released version defaults to ${DEFAULT_API_URL}.` };
31379
- const apiUrl = (env.TAIGA_API_URL || DEFAULT_API_URL).replace(/\/+$/, "");
31380
- let url;
31381
- try {
31382
- url = new URL(apiUrl);
31383
- } catch {
31384
- return { problem: `TAIGA_API_URL is not a URL: ${apiUrl}` };
31385
- }
31386
- if (url.search || url.hash) return { problem: `TAIGA_API_URL must not carry a query or fragment: ${apiUrl}` };
31387
- if (url.protocol !== "https:" && !(url.protocol === "http:" && LOCAL_HOSTS.has(url.hostname))) return { problem: `TAIGA_API_URL must be an https URL (plain http only for localhost), so the key is never sent in the clear: ${apiUrl}` };
31388
- if (env.TAIGA_TOOLSETS?.trim()) {
31389
- const parsed = parseToolsets(env.TAIGA_TOOLSETS);
31390
- if ("problem" in parsed) return { problem: parsed.problem };
31391
- return { config: {
31392
- apiKey: env.TAIGA_API_KEY,
31393
- apiUrl,
31394
- toolsets: parsed.toolsets
31395
- } };
31396
- }
31397
- return { config: {
31398
- apiKey: env.TAIGA_API_KEY,
31399
- apiUrl
31400
- } };
31401
- }
31402
- //#endregion
31403
- //#region src/tools/annotations.ts
31404
- /**
31405
- * Tool annotations shared by the tools. Hints for the client, not a
31406
- * control: the API enforces what a key may do. A client that asks the
31407
- * person before a destructive call reads destructiveHint; the server-side
31408
- * approval gate (PRO-548) is separate work.
31409
- */
31410
- const READ_ONLY = {
31411
- readOnlyHint: true,
31412
- destructiveHint: false,
31413
- idempotentHint: true,
31414
- openWorldHint: false
31415
- };
31416
- /** A write that adds or edits a row and starts nothing: a created initiative, a moved one. */
31417
- const WRITE = {
31418
- readOnlyHint: false,
31419
- destructiveHint: false,
31420
- idempotentHint: false,
31421
- openWorldHint: false
31422
- };
31423
- /**
31424
- * A write that starts or stops paid work, or opens the door to it: queueing
31425
- * an initiative, approving a plan, resuming or stopping a run. Each starts
31426
- * an agent that spends tokens and opens pull requests, or halts one mid-way.
31427
- */
31428
- const OPERATE = {
31429
- readOnlyHint: false,
31430
- destructiveHint: true,
31431
- idempotentHint: false,
31432
- openWorldHint: false
31433
- };
31434
- /**
31435
- * An OPERATE write that sets a value rather than adding one: the same call
31436
- * twice leaves things as one call does (a review gate set, a line paused).
31437
- */
31438
- const OPERATE_SETTING = {
31439
- ...OPERATE,
31440
- idempotentHint: true
31441
- };
31442
- //#endregion
31443
- //#region src/tools/inputs.ts
31444
- /** The inputs several tools share, so a product or a page is named the same way everywhere. */
31445
- /**
31446
- * An ID input whose refusal says where the ID comes from. The client shows the
31447
- * schema's message, not the description, when a call fails validation, and
31448
- * "Invalid UUID" alone sends a model that passed a name to guess again.
31449
- */
31450
- function idInput(what, from, said = from) {
31451
- return string$2().uuid({ message: `${/^[aeiou]/i.test(what) ? "An" : "A"} ${what} ID is a UUID, not a name: ${from}` }).meta({ pattern: void 0 }).describe(`${what[0].toUpperCase()}${what.slice(1)} ID -- ${said}`);
31452
- }
31453
- const productId = idInput("product", "taiga_list_products (query finds one by name), or taiga_get_product with a git remote URL, gives it", "taiga_list_products gives it");
31454
- /** The page inputs every list tool takes; `nextCursor` of one page is the `cursor` of the next. */
31455
- const pagination = {
31456
- limit: number$1().int().min(1).max(100).optional().describe("Max results (default 25)"),
31457
- cursor: string$2().max(256).optional().describe("The previous page's nextCursor; omit for the first page")
31458
- };
31459
- const slug = string$2().max(76).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "A slug is lowercase words joined by hyphens").describe("The segment after /products/ in its Taiga URL (web-shop-5d060fa7460e), or its slug");
31460
- const remoteUrl = string$2().min(1).max(2048).describe("The git remote URL of a checkout (git remote get-url origin): https://, git@host:owner/repo.git or ssh://");
31461
- //#endregion
31462
- //#region src/tools/catalogue.ts
31463
- /**
31464
- * What exists, from the one place that knows: the shared types package.
31465
- *
31466
- * Tool descriptions are what the model reads to decide what to call, and a
31467
- * description that names a document type the catalogue lacks sends it down a
31468
- * dead end (the walk-through that led here found `policy_acceptable_use` and
31469
- * `policy_ip` named in a description and nowhere else). Every list of types,
31470
- * origins and statuses a tool shows is derived from these constants, and a
31471
- * test holds the descriptions to them.
31472
- */
31473
- /**
31474
- * Display names for every product document type. The reviewable nine come
31475
- * from the shared map the web uses; the three the web never asks a person to
31476
- * review are named here, and the record type keeps the two sets complete.
31477
- */
31478
- const PRODUCT_DOCUMENT_NAMES = {
31479
- ...PRODUCT_DOCUMENT_DISPLAY_NAMES,
31480
- ui_direction: "Look & Feel",
31481
- codebase_snapshot: "Codebase Snapshot",
31482
- product_instructions: "Product Instructions"
31483
- };
31484
- function productDocumentName(type) {
31485
- return PRODUCT_DOCUMENT_NAMES[type] ?? type;
31486
- }
31487
- /**
31488
- * The two document timelines of a product (ADR-017), in the words the tools
31489
- * and the server instructions use. One place, so the list tool, the read
31490
- * tool and the instructions cannot explain them three different ways.
31491
- */
31492
- const ORIGIN_MEANING = {
31493
- plan: "plan: the discovery documents, what is meant to be built.",
31494
- reality: "reality: derived from the code on the main branch, what is built; an imported product has them from its import, any other once its first initiative is done (a merged pull request) or code is pushed."
31495
- };
31496
- /**
31497
- * Which timeline is a product's own (the API's documentOriginForSettings):
31498
- * an imported product has no plan chain by design, so its documents are on
31499
- * the reality side; everything else starts on the plan side. Derived from the
31500
- * same settings key the API reads, so the two cannot disagree.
31501
- */
31502
- function isImportedProduct(product) {
31503
- return product?.settings?.projectType === "brownfield";
31504
- }
31505
- /**
31506
- * The document types no derivation ever writes: a person records or writes
31507
- * them, so they live on the plan side of every product, imported or not.
31508
- */
31509
- const PLAN_ONLY_DOCUMENT_TYPES = PRODUCT_DOCUMENT_TYPES.filter((type) => !REALITY_DERIVED_DOCUMENT_TYPES.includes(type));
31510
- /**
31511
- * The timeline a read should default to: the plan side for a type only a
31512
- * person writes, else the product's own side (reality for an imported
31513
- * product, plan for every other).
31514
- */
31515
- function defaultOriginFor(product, type) {
31516
- if (type !== void 0 && PLAN_ONLY_DOCUMENT_TYPES.includes(type)) return "plan";
31517
- return isImportedProduct(product) ? "reality" : "plan";
31518
- }
31519
- /**
31520
- * Where an imported product's import got to (`settings.importStatus`, written
31521
- * by the API: pending, analyzing, complete, cancelled, failed). Unknown values
31522
- * read as "not known", never as a promise.
31523
- */
31524
- function importStatusOf(product) {
31525
- const status = product?.settings?.importStatus;
31526
- return typeof status === "string" ? status : null;
31527
- }
31528
- /** Why a side of the timeline is empty, for a list or a miss that shows one. */
31529
- function emptyOriginNote(origin, product) {
31530
- const imported = isImportedProduct(product);
31531
- if (origin === "plan") return imported ? `This product is set up from its code (an import), so no discovery chain is generated for it: its derived documents are on the reality side. Only the documents a person writes (${PLAN_ONLY_DOCUMENT_TYPES.map(productDocumentName).join(", ")}) would appear here.` : "No plan documents are published yet: they are written during discovery in Taiga.";
31532
- if (!imported) return "No reality documents yet: they are derived from the code once the first initiative is done (a merged pull request marks it done) or the repository is pushed to. Until then read the plan side.";
31533
- switch (importStatusOf(product)) {
31534
- case "pending": return "No reality documents yet: the import has not started. taiga_start_import starts it once a repository is linked; taiga_get_product's readiness says whether one is.";
31535
- case "analyzing":
31536
- case "generating_docs": return "No reality documents yet: the import is running and will derive them from the code.";
31537
- case "cancelled": return "No reality documents: the import was cancelled before it derived any. taiga_start_import runs it again.";
31538
- case "failed": return "No reality documents: the import failed before it derived any. taiga_start_import runs it again.";
31539
- default: return "No reality documents: the import derives them from the code, and none have been published.";
31540
- }
31541
- }
31542
- /**
31543
- * What finishing does, in every next step that ends at it (PRO-2857): it
31544
- * starts paid planning, so a client must ask the person before calling it.
31545
- */
31546
- const FINISH_DISCOVERY = "taiga_finish_discovery opens the product and starts planning its first initiatives (paid agent work: ask the person first).";
31547
- /**
31548
- * What a product in setup waits for, as the next call to make. Nothing on a
31549
- * draft product says it otherwise: discoveryStep names the step and
31550
- * importStatus the import, and the way on from each lives in tool
31551
- * descriptions an agent reads only when it already knows which. Null once the
31552
- * product is active.
31553
- */
31554
- function setupNextStep(product) {
31555
- if (product?.status !== "draft") return null;
31556
- if (isImportedProduct(product)) switch (importStatusOf(product)) {
31557
- case "analyzing":
31558
- case "generating_docs": return `The import is running and derives the documents from the code (taiga_wait (jobId) follows its job). Then review them, and ${FINISH_DISCOVERY}`;
31559
- case "complete": return "The import is done: review the reality documents (taiga_get_product_document without type), then " + FINISH_DISCOVERY;
31560
- case "failed":
31561
- case "cancelled": return "The last import did not finish: taiga_start_import runs it again.";
31562
- default: return "Link its repository if it has none (taiga_list_linkable_repositories, taiga_link_repository), then taiga_start_import: the import derives the documents from the code and runs by itself.";
31563
- }
31564
- if (product.discoveryStep === void 0) return null;
31565
- switch (product.discoveryStep) {
31566
- case "documents": return `The specification is done; the other documents are generated from it (taiga_generate_product_documents starts the ones still missing). Once every required one is published, ${FINISH_DISCOVERY}`;
31567
- default: return `Discovery is a conversation held in the web: the person describes the product there and the specification comes out of it. The other documents follow, then ${FINISH_DISCOVERY}`;
31568
- }
31569
- }
31570
- //#endregion
31571
- //#region src/tools/hints.ts
31572
- /**
31573
- * The next step after the API answers 404. The API's own word is bare
31574
- * ("Initiative not found", "Repository link not found"), and an agent that
31575
- * hears only that guesses another ID, or a name. Each ID a tool takes names
31576
- * the tool that lists the right ones; the tool's arguments say which apply.
31577
- */
31578
- const ITEM_ID_HINT = "taiga_list_initiatives lists a product's initiatives with their IDs; a run or plan ID is not one.";
31579
- const BY_ARGUMENT = {
31580
- initiativeId: ITEM_ID_HINT,
31581
- runId: "taiga_list_runs lists the runs, of one product or of every product the key can see.",
31582
- planId: "taiga_get_plan gives the initiative's active plan and its ID.",
31583
- linkId: "taiga_list_product_repositories lists the product's repository links; a linkable repository id is not a link ID.",
31584
- replacesLinkId: "taiga_list_product_repositories lists the product's repository links.",
31585
- linkableRepositoryId: "taiga_list_linkable_repositories lists the repositories the GitHub, GitLab and Azure DevOps connections reach, with their ids.",
31586
- installationId: "taiga_list_linkable_repositories lists the connected GitHub accounts, GitLab and Azure DevOps connections.",
31587
- jobId: "A job ID is what the tool that started the job returned (taiga_request_initiatives, taiga_start_import).",
31588
- factoryId: "taiga_list_factories lists the factories the key can see.",
31589
- findingId: "taiga_list_findings lists a product's findings.",
31590
- violationId: "taiga_get_policy_standing lists a product's policy violations.",
31591
- environmentId: "taiga_get_deployments lists the product's environments with their IDs; a product ID is not one.",
31592
- knowledgeId: "taiga_list_knowledge lists the knowledge files.",
31593
- productId: "taiga_list_products lists the products the key can see; a name is not an ID (taiga_get_product takes a slug)."
31594
- };
31595
- /**
31596
- * A licence a product does not hold, as against a product the key cannot see
31597
- * (PRO-3879). Any other 404 (the routes do not exist where the licenses
31598
- * feature is off) blames neither.
31599
- */
31600
- const licenseMiss = (hint) => (said) => /\blicen[cs]e\b/i.test(said) ? hint : /\b(product|project) not found/i.test(said) ? BY_ARGUMENT["productId"] : void 0;
31601
- /** Where an argument means something else on one tool, or the tool's 404 needs its own word. */
31602
- const BY_TOOL = {
31603
- taiga_allow_license: licenseMiss("taiga_list_packages (productId) summarizes the product's licenses as its findings name them; a license with no finding there has nothing to allow or reopen."),
31604
- taiga_list_licenses: licenseMiss("taiga_list_licenses without license lists the licenses in use, and taiga_list_packages (productId) one product's, spelled as their findings spell them."),
31605
- taiga_resolve_action: () => "taiga_list_action_required lists the items with their IDs.",
31606
- taiga_get_sbom: () => "An SBOM exists once a sweep has inventoried that repository, where the licenses feature is enabled; taiga_list_packages (linkId) says whether it has packages, and taiga_list_product_repositories lists the links.",
31607
- taiga_get_notices: () => "Notices exist once a sweep has inventoried that repository, where the licenses feature is enabled; taiga_list_product_repositories lists the links.",
31608
- taiga_get_plan: (said) => /\bplan\b/i.test(said) ? "taiga_get_initiative's situation says whether one is being planned or failed, and names the call that asks for one (taiga_queue_initiative off the line, taiga_plan_again for a failed plan)." : ITEM_ID_HINT
31609
- };
31610
- /**
31611
- * What the API calls the thing each ID names, as its 404 says it ("Environment
31612
- * not found"). A tool given a right product and a wrong environment hinted
31613
- * at both, and the product's hint told the agent its correct product ID was
31614
- * the mistake (PRO-2800): a 404 that names its thing gets that ID's hint only.
31615
- */
31616
- const MISSING_THING = {
31617
- initiativeId: /backlog item|initiative/i,
31618
- runId: /\b(build )?run\b/i,
31619
- planId: /\bplan\b/i,
31620
- linkId: /repository link|\blink\b|repository/i,
31621
- replacesLinkId: /repository link|\blink\b/i,
31622
- linkableRepositoryId: /github repository|gitlab project|azure devops (repository|resource|connection)/i,
31623
- installationId: /installation|account|gitlab connection|azure devops connection/i,
31624
- jobId: /\bjob\b/i,
31625
- factoryId: /factory|team/i,
31626
- findingId: /finding/i,
31627
- violationId: /violation/i,
31628
- environmentId: /environment/i,
31629
- knowledgeId: /knowledge|document/i,
31630
- productId: /\b(product|project) not found/i
31631
- };
31632
- /** The hint for a 404 from one tool call: the tool's own, else the one for the ID the API says is missing. */
31633
- function notFoundHint(tool, args) {
31634
- if (BY_TOOL[tool]) return BY_TOOL[tool];
31635
- if (typeof args !== "object" || args === null) return void 0;
31636
- const given = Object.keys(args).filter((key) => args[key] != null && BY_ARGUMENT[key]);
31637
- given.sort((a, b) => Number(a === "productId") - Number(b === "productId"));
31638
- if (given.length === 0) return void 0;
31639
- return (said) => {
31640
- const named = given.filter((key) => MISSING_THING[key]?.test(said));
31641
- return (named.length > 0 ? named : given).map((key) => BY_ARGUMENT[key]).join(" ");
31642
- };
31643
- }
31644
- /** The hint of the tool call in progress, read by runTool when the API answers 404. */
31645
- const notFoundHints = new AsyncLocalStorage();
31646
- /** The API's 404 message with the hint of the call in progress, if it has one. */
31647
- function withNotFoundHint(said) {
31648
- const hint = notFoundHints.getStore()?.(said);
31649
- return hint ? `${withStop(said)} ${hint}` : said;
31650
- }
31651
- /** A sentence ends in a stop before the next one is added to it. */
31652
- function withStop(text) {
31653
- return /[.!?]$/.test(text.trimEnd()) ? text.trimEnd() : `${text.trimEnd()}.`;
31654
- }
31655
- /** Where an ID argument comes from, for a call refused before it reached the API (PRO-2841). */
31656
- function idSource(argument) {
31657
- return BY_ARGUMENT[argument];
31658
- }
31659
- /** The verbs and joining words of tool names: what a tool does, not what it is about. */
31660
- const VERBS = new Set("get list update create set publish move queue approve reject review resume stop wait for fix ignore mark add delete retry regenerate refresh link unlink rename request resolve start finish reopen pause preview define generate again whoami".split(" "));
31661
- /** What a tool name is about, singular: taiga_list_initiatives is about an initiative. */
31662
- const nouns = (tool) => new Set(tool.replace(/^taiga_/, "").split("_").filter((word) => !VERBS.has(word)).map((word) => word.replace(/s$/, "")));
31663
- /**
31664
- * The tool, of those that take `argument`, that is about the same thing as the
31665
- * one that refused it: taiga_get_organization_document refusing productId points at
31666
- * taiga_get_product_document, not at one of the thirty other tools that take a
31667
- * product. Only a tool sharing a noun counts, and a read is never pointed at a
31668
- * write; with none, there is no closest tool and the caller says to leave the
31669
- * argument out.
31670
- */
31671
- function closestToolTaking(argument, refusedBy, inputs, isRead) {
31672
- const mine = nouns(refusedBy);
31673
- const readsOnly = isRead(refusedBy);
31674
- let best;
31675
- for (const [tool, keys] of inputs) {
31676
- if (tool === refusedBy || !keys.includes(argument) || readsOnly && !isRead(tool)) continue;
31677
- const shared = [...nouns(tool)].filter((word) => mine.has(word)).length;
31678
- if (shared === 0) continue;
31679
- if (!best || shared > best.shared || shared === best.shared && tool.length < best.tool.length) best = {
31680
- tool,
31681
- shared
31682
- };
31683
- }
31684
- return best?.tool;
31685
- }
31686
- /** One of the tool's own arguments spelled another way (product_id, initiativeID), if the refused key is one. */
31687
- function ownArgumentLike(key, own) {
31688
- const plain = (name) => name.replace(/[_-]/g, "").toLowerCase();
31689
- return own.find((name) => plain(name) === plain(key));
31690
- }
31691
- //#endregion
31692
- //#region src/tools/errors.ts
31693
- /**
31694
- * The API's names for the two IDs an agent chains most, in the product's
31695
- * words the tools take them in (PRO-2800): a row says initiativeId and runId,
31696
- * as taiga_get_initiative and taiga_get_run ask for them, rather than the
31697
- * storage names backlogItemId and buildRunId.
31698
- */
31699
- const PRODUCT_WORDS = {
31700
- backlogItemId: "initiativeId",
31701
- buildRunId: "runId",
31702
- productRepositoryId: "linkId",
31703
- latestBuild: "latestRun"
31704
- };
31705
- /**
31706
- * Maps whose keys are content, not API fields: a document's sections are keyed
31707
- * by ids a person or agent chose (a section may be called backlogItemId), and
31708
- * metadata and settings hold whatever their writer put there. Copied as they
31709
- * are, keys and all.
31710
- */
31711
- const OPAQUE_MAPS = /* @__PURE__ */ new Set([
31712
- "sections",
31713
- "metadata",
31714
- "settings"
31715
- ]);
31716
- /** A copy of an API value with its keys in the product's words, values untouched. */
31717
- /**
31718
- * Run actions only the web offers (PRO-2800): start_over was listed beside what an agent can call, on runs and on
31719
- * every initiative's latest run, while the descriptions said it was web only. Split apart wherever actions appear.
31720
- */
31721
- const WEB_ONLY_ACTIONS = /* @__PURE__ */ new Set(["start_over"]);
31722
- function inProductWords(value) {
31723
- if (Array.isArray(value)) return value.map(inProductWords);
31724
- if (value === null || typeof value !== "object") return value;
31725
- const out = {};
31726
- const actions = value["actions"];
31727
- if (Array.isArray(actions) && actions.some((action) => WEB_ONLY_ACTIONS.has(String(action)))) {
31728
- const webOnly = actions.filter((action) => WEB_ONLY_ACTIONS.has(String(action)));
31729
- const said = value["webOnlyActions"];
31730
- value = {
31731
- ...value,
31732
- actions: actions.filter((action) => !WEB_ONLY_ACTIONS.has(String(action))),
31733
- webOnlyActions: [.../* @__PURE__ */ new Set([...Array.isArray(said) ? said : [], ...webOnly])]
31734
- };
31735
- }
31736
- for (const [key, inner] of Object.entries(value)) Object.defineProperty(out, PRODUCT_WORDS[key] ?? key, {
31737
- value: OPAQUE_MAPS.has(key) ? inner : inProductWords(inner),
31738
- enumerable: true,
31739
- writable: true,
31740
- configurable: true
31741
- });
31742
- return out;
31743
- }
31744
- /** The API's 404 sentence in the product's words: "Backlog item not found" is an initiative not found. */
31745
- function inProductWording(said) {
31746
- return said.replace(/^Backlog item not found/i, "Initiative not found").replace(/^Build run step not found/i, "Run step not found").replace(/^Build run not found/i, "Run not found").replace(/^Custom document not found/i, "Knowledge file not found").replace(/^(Branch "[^"]*" does not exist in \S+?)\.?$/i, "$1. taiga_list_repository_branches lists the branches it has.");
31747
- }
31748
- /**
31749
- * A float without its binary noise: six significant digits. Delivery metrics
31750
- * came as `deploysPerWeek: 6.766666666666667`, sixteen digits nobody reads
31751
- * (PRO-2847). Significant digits rather than fixed decimals: an EPSS score of
31752
- * 0.00043, a 0.4% failure rate or 99.995% uptime keep what they say, where
31753
- * two decimals read them as 0, 0 and 100.
31754
- */
31755
- const roundFloats = (_key, value) => typeof value === "number" && Number.isFinite(value) && !Number.isInteger(value) ? Number(value.toPrecision(6)) : value;
31756
- /**
31757
- * A result as the model reads it: compact JSON, in the product's words, its
31758
- * floats rounded. Indentation was a fifth of a list's characters (PRO-2847),
31759
- * paid on every call; the model reads JSON without it.
31760
- */
31761
- function serializeResult(value) {
31762
- return JSON.stringify(inProductWords(value), roundFloats);
31763
- }
31764
- /** A successful tool result: one JSON text block the model reads. */
31765
- function toolResult(value) {
31766
- return { content: [{
31767
- type: "text",
31768
- text: serializeResult(value)
31769
- }] };
31770
- }
31771
- /**
31772
- * A failed tool result the model can branch on: a stable code and a message
31773
- * that says what to do next. Returned, not thrown, so the client sees
31774
- * `isError` rather than a protocol error.
31775
- */
31776
- function toolError(error, message, details) {
31777
- return {
31778
- content: [{
31779
- type: "text",
31780
- text: JSON.stringify(details ? {
31781
- error,
31782
- message,
31783
- details: inProductWords(details)
31784
- } : {
31785
- error,
31786
- message
31787
- })
31788
- }],
31789
- isError: true
31790
- };
31791
- }
31792
- /**
31793
- * fetch rejects with a TypeError carrying a `cause` when the API cannot be
31794
- * reached; a TypeError from our own code carries none and is a bug to surface.
31795
- */
31796
- function isNetworkFailure(error) {
31797
- return error instanceof TypeError && "cause" in error;
31798
- }
31799
- /** What went wrong on the wire: undici's message is the constant "fetch failed", the cause says why. */
31800
- function networkFailureDetail(error) {
31801
- const cause = error.cause;
31802
- const why = typeof cause?.code === "string" ? cause.code : typeof cause?.message === "string" ? cause.message : null;
31803
- return why ? `${error.message} (${why})` : error.message;
31804
- }
31805
- /**
31806
- * The code a status implies when the API sent none. 400 is VALIDATION_ERROR,
31807
- * the code the API itself sends, so a refusal by this server and one by the
31808
- * API read the same.
31809
- */
31810
- const CODE_BY_STATUS = {
31811
- 400: "VALIDATION_ERROR",
31812
- 401: "UNAUTHENTICATED",
31813
- 403: "FORBIDDEN",
31814
- 404: "NOT_FOUND",
31815
- 409: "CONFLICT",
31816
- 429: "RATE_LIMITED"
31817
- };
31818
- /** What the API said, in one phrase: the status, the code it sent (or the one its status implies), its message. */
31819
- function apiFailureText(error) {
31820
- return `${error.status} ${apiFailureCode(error)}${error.apiMessage ? `: ${error.apiMessage}` : ""}`;
31821
- }
31822
- /** The code the API sent, or the one its status implies: the code a model branches on. */
31823
- function apiFailureCode(error) {
31824
- return error.code ?? CODE_BY_STATUS[error.status] ?? "API_ERROR";
31825
- }
31826
- /** Whether a failure is the API's refusal or absence of a thing, as opposed to the API failing. */
31827
- function isMissOrRefusal(error) {
31828
- return error instanceof TaigaApiError && (error.status === 404 || error.status === 403);
31829
- }
31830
- /**
31831
- * Run a tool handler and turn a failure into a structured error. An API
31832
- * refusal keeps the API's own code when it sent one and its message whole:
31833
- * on a refused publish that names the section holding template residue,
31834
- * which is what the model needs to fix the draft. A failed connection is
31835
- * structured too, so every failure the model sees has the same shape.
31836
- */
31837
- async function runTool(handler) {
31838
- try {
31839
- return await handler();
31840
- } catch (error) {
31841
- if (error instanceof TaigaApiError) {
31842
- const code = error.code ?? CODE_BY_STATUS[error.status] ?? "API_ERROR";
31843
- const worded = inProductWording(error.apiMessage ?? `Taiga API answered ${error.status}.`);
31844
- if (code === "PROVIDER_UNSUPPORTED") return toolError(code, `${worded} This forge does not do that in Taiga yet; retrying will not change it.`, {
31845
- ...error.details,
31846
- retryable: false
31847
- });
31848
- return toolError(code, error.status === 404 ? withNotFoundHint(worded) : [
31849
- 502,
31850
- 503,
31851
- 504
31852
- ].includes(error.status) ? `${withStop(worded)} This is usually temporary: a read may answer on a retry; after a write, check whether it took effect before repeating it.` : worded, error.details);
31853
- }
31854
- if (isNetworkFailure(error)) return toolError("NETWORK_ERROR", `Could not reach the Taiga API: ${networkFailureDetail(error)}. Check TAIGA_API_URL.`);
31855
- throw error;
31856
- }
31857
- }
31858
- //#endregion
31859
- //#region src/tools/remote.ts
31860
- const SCP_LIKE = /^(?:[^@\s/]+@)?([^:\s/]+):([^\s]+)$/;
31861
- function parseRemote(remote) {
31862
- const trimmed = remote.trim();
31863
- if (trimmed === "") return null;
31864
- let host;
31865
- let path;
31866
- let scheme = "https";
31867
- if (/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)) {
31868
- if (hasDotSegment(trimmed.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i, ""))) return null;
31869
- let url;
31870
- try {
31871
- url = new URL(trimmed);
31872
- } catch {
31873
- return null;
31874
- }
31875
- const protocol = url.protocol.replace(/:$/, "").toLowerCase();
31876
- if (protocol === "http" || protocol === "https") {
31877
- scheme = protocol;
31878
- host = url.port ? `${url.hostname}:${url.port}` : url.hostname;
31879
- } else if (protocol === "ssh" || protocol === "git+ssh" || protocol === "git") host = url.hostname;
31880
- else return null;
31881
- path = url.pathname;
31882
- } else {
31883
- const match = SCP_LIKE.exec(trimmed);
31884
- if (!match) return null;
31885
- host = match[1];
31886
- path = match[2];
31887
- if (host.length < 2) return null;
31888
- }
31889
- host = host.toLowerCase();
31890
- if (host === "") return null;
31891
- const segments = path.replace(/\/+$/, "").replace(/\.git$/i, "").split("/").filter((segment) => segment !== "");
31892
- if (segments.length !== 2) return null;
31893
- if (hasDotSegment(path) || segments.some((segment) => segment.includes(":"))) return null;
31894
- const origin = webOrigin(`${scheme}://${host}`);
31895
- if (origin === null) return null;
31896
- return {
31897
- host: origin,
31898
- repository: `${segments[0]}/${segments[1]}`
31899
- };
31900
- }
31901
- /** Whether any segment of the path is `.` or `..`, percent-encoded or not. */
31902
- function hasDotSegment(path) {
31903
- return path.split("/").some((segment) => {
31904
- let decoded = segment;
31905
- try {
31906
- decoded = decodeURIComponent(segment);
31907
- } catch {}
31908
- return decoded === "." || decoded === "..";
31909
- });
31910
- }
31911
- function webOrigin(url) {
31912
- try {
31913
- const origin = new URL(url).origin;
31914
- return origin === "null" ? null : origin;
31915
- } catch {
31916
- return null;
31917
- }
31918
- }
31919
- //#endregion
31920
- //#region ../../packages/types/dist/licenses/spdx-license-list.js
31921
- /**
31922
- * The SPDX License List 3.29.0 (licenses and exceptions), as `license-normalise` reads it: each
31923
- * licence's id, full name, whether the id is deprecated, and its reference URLs reduced to
31924
- * host and path (no scheme, no `www.`, no trailing slash or `.txt`/`.html`). Generated from
31925
- * https://github.com/spdx/license-list-data (json/licenses.json, json/exceptions.json) at
31926
- * version 3.29.0; regenerate when the list moves. Data, not logic (milestone 2j).
31295
+ * The SPDX License List 3.29.0 (licenses and exceptions), as `license-normalise` reads it: each
31296
+ * licence's id, full name, whether the id is deprecated, and its reference URLs reduced to
31297
+ * host and path (no scheme, no `www.`, no trailing slash or `.txt`/`.html`). Generated from
31298
+ * https://github.com/spdx/license-list-data (json/licenses.json, json/exceptions.json) at
31299
+ * version 3.29.0; regenerate when the list moves. Data, not logic (milestone 2j).
31927
31300
  */
31928
31301
  /** [id, name, deprecated (1), reference URLs]. */
31929
31302
  const SPDX_LICENSES = [
@@ -36979,475 +36352,1243 @@ const SPDX_EXCEPTIONS = [
36979
36352
  "OpenVPN OpenSSL Exception",
36980
36353
  0
36981
36354
  ],
36982
- [
36983
- "polyparse-exception",
36984
- "Polyparse Exception",
36985
- 0
36355
+ [
36356
+ "polyparse-exception",
36357
+ "Polyparse Exception",
36358
+ 0
36359
+ ],
36360
+ [
36361
+ "romic-exception",
36362
+ "Romic Exception",
36363
+ 0
36364
+ ],
36365
+ [
36366
+ "rsync-linking-exception",
36367
+ "rsync Linking Exception",
36368
+ 0
36369
+ ],
36370
+ [
36371
+ "sqlitestudio-OpenSSL-exception",
36372
+ "sqlitestudio OpenSSL exception",
36373
+ 0
36374
+ ],
36375
+ [
36376
+ "stunnel-exception",
36377
+ "stunnel Exception",
36378
+ 0
36379
+ ],
36380
+ [
36381
+ "u-boot-exception-2.0",
36382
+ "U-Boot exception 2.0",
36383
+ 0
36384
+ ],
36385
+ [
36386
+ "vsftpd-openssl-exception",
36387
+ "vsftpd OpenSSL exception",
36388
+ 0
36389
+ ],
36390
+ [
36391
+ "x11vnc-openssl-exception",
36392
+ "x11vnc OpenSSL Exception",
36393
+ 0
36394
+ ]
36395
+ ];
36396
+ //#endregion
36397
+ //#region ../../packages/types/dist/licenses/spdx-expression.js
36398
+ /**
36399
+ * The SPDX license expression grammar (SPDX 2.3, Annex D), parsed once and
36400
+ * shared by everything that reads a licence string: the SBOM renderer, which
36401
+ * must only emit an expression an SPDX-aware consumer will accept, and the
36402
+ * licence summary, which reads an expression against the allowlist (PRO-2945).
36403
+ *
36404
+ * The parser decides the SHAPE only: operands are any token that is not an
36405
+ * operator or a parenthesis, the way osv-scanner's own parser reads them
36406
+ * (internal/spdx/satisfies.go, v2.4.0). Whether an operand is a listed SPDX id
36407
+ * is the caller's question, since the renderer needs a strict answer and the
36408
+ * allowlist only a string comparison.
36409
+ */
36410
+ const OPERATORS = /* @__PURE__ */ new Set([
36411
+ "AND",
36412
+ "OR",
36413
+ "WITH",
36414
+ "(",
36415
+ ")"
36416
+ ]);
36417
+ /**
36418
+ * Licence strings are stored as the scanner reported them, unbounded; the
36419
+ * parser recurses once per parenthesis level, so a pathological value could
36420
+ * exhaust the stack. Real expressions nest a level or two: past this bound the
36421
+ * string does not parse.
36422
+ */
36423
+ const MAX_DEPTH = 32;
36424
+ /**
36425
+ * The expression tree of `text`, or null when it is not one: unbalanced
36426
+ * parentheses, a dangling or doubled operator, two operands with no operator
36427
+ * between them. AND binds tighter than OR; WITH binds an exception to the one
36428
+ * licence before it; operators are upper case, so `mit or isc` is not an
36429
+ * expression.
36430
+ */
36431
+ function parseSpdxExpression(text) {
36432
+ const tokens = text.replace(/([()])/g, " $1 ").trim().split(/\s+/).filter((t) => t !== "");
36433
+ if (tokens.length === 0) return null;
36434
+ let at = 0;
36435
+ let depth = 0;
36436
+ const peek = () => tokens[at];
36437
+ const operand = (token) => token !== void 0 && !OPERATORS.has(token);
36438
+ const term = () => {
36439
+ const token = peek();
36440
+ if (token === "(") {
36441
+ if (depth === MAX_DEPTH) return null;
36442
+ depth += 1;
36443
+ at += 1;
36444
+ const inner = compound();
36445
+ if (inner === null || peek() !== ")") return null;
36446
+ at += 1;
36447
+ depth -= 1;
36448
+ return inner;
36449
+ }
36450
+ if (!operand(token)) return null;
36451
+ at += 1;
36452
+ if (peek() !== "WITH") return {
36453
+ kind: "license",
36454
+ license: token,
36455
+ exception: null
36456
+ };
36457
+ at += 1;
36458
+ const exception = peek();
36459
+ if (!operand(exception)) return null;
36460
+ at += 1;
36461
+ return {
36462
+ kind: "license",
36463
+ license: token,
36464
+ exception
36465
+ };
36466
+ };
36467
+ const chain = (kind, operator, next) => {
36468
+ const first = next();
36469
+ if (first === null) return null;
36470
+ const operands = [first];
36471
+ while (peek() === operator) {
36472
+ at += 1;
36473
+ const operand = next();
36474
+ if (operand === null) return null;
36475
+ operands.push(operand);
36476
+ }
36477
+ return operands.length === 1 ? first : {
36478
+ kind,
36479
+ operands
36480
+ };
36481
+ };
36482
+ const conjunction = () => chain("and", "AND", term);
36483
+ const compound = () => chain("or", "OR", conjunction);
36484
+ const tree = compound();
36485
+ return tree !== null && at === tokens.length ? tree : null;
36486
+ }
36487
+ /** Every licence operand of `tree`, left to right. */
36488
+ function licenseOperands(tree) {
36489
+ return tree.kind === "license" ? [tree] : tree.operands.flatMap(licenseOperands);
36490
+ }
36491
+ //#endregion
36492
+ //#region ../../packages/types/dist/licenses/license-normalise.js
36493
+ /**
36494
+ * One reading of licence text as SPDX (milestone 2j, design 5.2).
36495
+ *
36496
+ * Registries and scanners declare licences in every shape: SPDX expressions
36497
+ * (`MIT OR Apache-2.0`), deprecated ids (`GPL-2.0-with-classpath-exception`),
36498
+ * names (`The Apache Software License, Version 2.0`, `MPL 2.0`), abbreviations
36499
+ * (`GPL2 w/ CPE`), URLs, and words that are no licence at all (`Nonstandard`,
36500
+ * `SEE LICENSE IN README.md`). deps.dev reduces the hard ones to
36501
+ * `non-standard`, and until now that reduction was final, so h2 (`MPL 2.0`,
36502
+ * `EPL 1.0`) and mysql-connector-j read as non-standard. This reads the raw
36503
+ * text once, the same way for every source:
36504
+ *
36505
+ * 1. an SPDX expression of listed ids is that expression, in the list's
36506
+ * spelling (a deprecated id stays itself; `currentSpelling` compares it
36507
+ * with its current form);
36508
+ * 2. a name the alias table knows (`ALIASES`: what registries actually
36509
+ * write, checked by hand), then the SPDX list's own names and ids compared
36510
+ * without punctuation or filler words, then the licence's reference URL;
36511
+ * 3. anything else is a licence that is not a standard one, kept with its
36512
+ * text and link so a person can read it.
36513
+ *
36514
+ * A declaration of several licences is a choice in the ecosystems whose
36515
+ * manifests say so (a POM's `<licenses>`, a gemspec's `licenses`,
36516
+ * composer.json's `license` array): `normaliseDeclared` joins them with OR,
36517
+ * a non-standard one as a `LicenseRef-` operand, so `GPL-2.0-only OR
36518
+ * GPL-3.0-only OR LicenseRef-nonstandard` still offers the GPLs. Elsewhere
36519
+ * several licences all apply (AND).
36520
+ */
36521
+ const DEPRECATED = {
36522
+ "AGPL-1.0": "AGPL-1.0-only",
36523
+ "AGPL-3.0": "AGPL-3.0-only",
36524
+ "GFDL-1.1": "GFDL-1.1-only",
36525
+ "GFDL-1.2": "GFDL-1.2-only",
36526
+ "GFDL-1.3": "GFDL-1.3-only",
36527
+ "GPL-1.0": "GPL-1.0-only",
36528
+ "GPL-1.0+": "GPL-1.0-or-later",
36529
+ "GPL-2.0": "GPL-2.0-only",
36530
+ "GPL-2.0+": "GPL-2.0-or-later",
36531
+ "GPL-3.0": "GPL-3.0-only",
36532
+ "GPL-3.0+": "GPL-3.0-or-later",
36533
+ "LGPL-2.0": "LGPL-2.0-only",
36534
+ "LGPL-2.0+": "LGPL-2.0-or-later",
36535
+ "LGPL-2.1": "LGPL-2.1-only",
36536
+ "LGPL-2.1+": "LGPL-2.1-or-later",
36537
+ "LGPL-3.0": "LGPL-3.0-only",
36538
+ "LGPL-3.0+": "LGPL-3.0-or-later",
36539
+ "GPL-2.0-with-classpath-exception": "GPL-2.0-only WITH Classpath-exception-2.0",
36540
+ "GPL-2.0-with-GCC-exception": "GPL-2.0-only WITH GCC-exception-2.0",
36541
+ "GPL-2.0-with-autoconf-exception": "GPL-2.0-only WITH Autoconf-exception-2.0",
36542
+ "GPL-2.0-with-bison-exception": "GPL-2.0-only WITH Bison-exception-2.2",
36543
+ "GPL-2.0-with-font-exception": "GPL-2.0-only WITH Font-exception-2.0",
36544
+ "GPL-3.0-with-GCC-exception": "GPL-3.0-only WITH GCC-exception-3.1",
36545
+ "GPL-3.0-with-autoconf-exception": "GPL-3.0-only WITH Autoconf-exception-3.0",
36546
+ "eCos-2.0": "GPL-2.0-or-later WITH eCos-exception-2.0",
36547
+ wxWindows: "GPL-2.0-or-later WITH WxWindows-exception-3.1",
36548
+ "BSD-2-Clause-FreeBSD": "BSD-2-Clause",
36549
+ "BSD-2-Clause-NetBSD": "BSD-2-Clause",
36550
+ "StandardML-NJ": "SMLNJ",
36551
+ Nunit: "zlib-acknowledgement",
36552
+ "bzip2-1.0.5": "bzip2-1.0.6"
36553
+ };
36554
+ /** Words a licence name carries that do not tell two licences apart. */
36555
+ const FILLER = /* @__PURE__ */ new Set([
36556
+ "the",
36557
+ "license",
36558
+ "licence",
36559
+ "licensed",
36560
+ "version",
36561
+ "v",
36562
+ "software",
36563
+ "under",
36564
+ "terms",
36565
+ "of"
36566
+ ]);
36567
+ /** A name reduced to what distinguishes it: `The Apache Software License, Version 2.0` -> `apache20`. */
36568
+ function nameKey(text) {
36569
+ return text.toLowerCase().replace(/licence/g, "license").replace(/[^a-z0-9.+]+/g, " ").split(" ").filter((word) => word !== "" && !FILLER.has(word)).join("").replace(/\./g, "");
36570
+ }
36571
+ let index$1 = null;
36572
+ function buildIndex() {
36573
+ const ids = /* @__PURE__ */ new Map();
36574
+ const currentForms = /* @__PURE__ */ new Map();
36575
+ const exceptions = /* @__PURE__ */ new Map();
36576
+ const names = /* @__PURE__ */ new Map();
36577
+ const urls = /* @__PURE__ */ new Map();
36578
+ const add = (map, key, id) => {
36579
+ if (key === "") return;
36580
+ const held = map.get(key);
36581
+ if (held === void 0) map.set(key, id);
36582
+ else if (held !== id) map.set(key, null);
36583
+ };
36584
+ for (const [id, name, deprecated, references] of SPDX_LICENSES) {
36585
+ const current = deprecated ? DEPRECATED[id] : id;
36586
+ ids.set(id.toLowerCase(), id);
36587
+ currentForms.set(id.toLowerCase(), current ?? id);
36588
+ if (!current) continue;
36589
+ add(names, nameKey(id), current);
36590
+ add(names, nameKey(name), current);
36591
+ if (/ only$/i.test(name)) add(names, nameKey(name.replace(/ only$/i, "")), current);
36592
+ for (const reference of references) add(urls, reference, current);
36593
+ }
36594
+ for (const [id, , deprecated] of SPDX_EXCEPTIONS) if (!deprecated) exceptions.set(id.toLowerCase(), id);
36595
+ const definite = (map) => new Map([...map].filter((entry) => entry[1] !== null));
36596
+ return {
36597
+ ids,
36598
+ current: currentForms,
36599
+ exceptions,
36600
+ names: definite(names),
36601
+ urls: definite(urls)
36602
+ };
36603
+ }
36604
+ function lists() {
36605
+ index$1 ??= buildIndex();
36606
+ return index$1;
36607
+ }
36608
+ /**
36609
+ * `text` as an SPDX expression of listed licences and exceptions, in the
36610
+ * list's spelling (a deprecated id kept as itself); null when it is not one.
36611
+ * `LicenseRef-` operands are kept as written.
36612
+ */
36613
+ function spdxExpression(text) {
36614
+ const trimmed = text.trim();
36615
+ const tree = parseSpdxExpression(/^[^\s()/]+(\/[^\s()/]+)+$/.test(trimmed) ? trimmed.split("/").join(" OR ") : trimmed);
36616
+ if (tree === null) return null;
36617
+ const { ids, exceptions } = lists();
36618
+ const spelled = /* @__PURE__ */ new Map();
36619
+ for (const operand of licenseOperands(tree)) {
36620
+ let current;
36621
+ if (/^licenseref-/i.test(operand.license)) current = operand.license;
36622
+ else current = ids.get(operand.license.toLowerCase());
36623
+ if (current === void 0) return null;
36624
+ if (operand.exception !== null) {
36625
+ const exception = exceptions.get(operand.exception.toLowerCase());
36626
+ if (exception === void 0 || current.includes(" WITH ")) return null;
36627
+ spelled.set(operand.exception, exception);
36628
+ }
36629
+ spelled.set(operand.license, / (AND|OR) /.test(current) ? `(${current})` : current);
36630
+ }
36631
+ return render$1(tree, spelled);
36632
+ }
36633
+ /**
36634
+ * One licence, with or without its exception, in the list's spelling (a
36635
+ * deprecated id as itself); null for anything else (an expression of
36636
+ * several licences, a LicenseRef, an exception alone).
36637
+ */
36638
+ function spdxLicenseEntry(text) {
36639
+ const expression = spdxExpression(text);
36640
+ if (expression === null) return null;
36641
+ const plain = unwrap(expression);
36642
+ const tree = parseSpdxExpression(plain);
36643
+ return tree?.kind === "license" && !/^licenseref-/i.test(tree.license) ? plain : null;
36644
+ }
36645
+ /**
36646
+ * One licence (or licence WITH exception) as the list and the licences are
36647
+ * compared (milestone 2j): its current SPDX form, lower-cased, so a list
36648
+ * written with `GPL-2.0` allows a package read as `GPL-2.0-only`, and one with
36649
+ * `GPL-2.0-with-classpath-exception` the same licence in its current spelling.
36650
+ */
36651
+ function currentSpelling(text) {
36652
+ const held = spellings.get(text);
36653
+ if (held !== void 0) return held;
36654
+ const spelled = (currentForm(text) ?? text.trim()).toLowerCase();
36655
+ if (spellings.size >= SPELLINGS_MAX) spellings.clear();
36656
+ spellings.set(text, spelled);
36657
+ return spelled;
36658
+ }
36659
+ /**
36660
+ * `currentSpelling` by its text. A judgement compares every licence of every
36661
+ * package against every list entry, and each spelling parses the text three
36662
+ * times: an organization's change of its list, over a few thousand packages,
36663
+ * spent seconds parsing the same few dozen strings.
36664
+ */
36665
+ const spellings = /* @__PURE__ */ new Map();
36666
+ const SPELLINGS_MAX = 1e4;
36667
+ /** One list entry in its current form, cased as the list spells it; null for what is no entry. */
36668
+ function currentForm(text) {
36669
+ const entry = spdxLicenseEntry(text);
36670
+ const tree = entry === null ? null : parseSpdxExpression(entry);
36671
+ if (tree === null || tree.kind !== "license") return null;
36672
+ const base = lists().current.get(tree.license.toLowerCase()) ?? tree.license;
36673
+ return tree.exception === null ? base : `${base} WITH ${tree.exception}`;
36674
+ }
36675
+ function render$1(tree, spelled) {
36676
+ if (tree.kind === "license") {
36677
+ const id = spelled.get(tree.license) ?? tree.license;
36678
+ if (tree.exception === null) return id;
36679
+ return `${id} WITH ${spelled.get(tree.exception) ?? tree.exception}`;
36680
+ }
36681
+ return tree.operands.map((operand) => operand.kind === "license" ? render$1(operand, spelled) : `(${render$1(operand, spelled)})`).join(tree.kind === "and" ? " AND " : " OR ");
36682
+ }
36683
+ function unwrap(expression) {
36684
+ return expression.startsWith("(") && expression.endsWith(")") && parseSpdxExpression(expression.slice(1, -1)) ? expression.slice(1, -1) : expression;
36685
+ }
36686
+ //#endregion
36687
+ //#region ../../packages/types/dist/licenses/pypi-classifiers.js
36688
+ /**
36689
+ * A licence family without its version or variant, by the name the inventory
36690
+ * keeps for it (the classifier's last segment), with every id it can stand
36691
+ * for. The PEP 639 list, plus the classifiers PyPI lists that name a licence
36692
+ * with several published versions and none given (EFL, NPL, Zope).
36693
+ */
36694
+ const AMBIGUOUS = {
36695
+ "Academic Free License (AFL)": [
36696
+ "AFL-1.1",
36697
+ "AFL-1.2",
36698
+ "AFL-2.0",
36699
+ "AFL-2.1",
36700
+ "AFL-3.0"
36701
+ ],
36702
+ "Apache Software License": [
36703
+ "Apache-1.0",
36704
+ "Apache-1.1",
36705
+ "Apache-2.0"
36986
36706
  ],
36987
- [
36988
- "romic-exception",
36989
- "Romic Exception",
36990
- 0
36707
+ "Apple Public Source License": [
36708
+ "APSL-1.0",
36709
+ "APSL-1.1",
36710
+ "APSL-1.2",
36711
+ "APSL-2.0"
36991
36712
  ],
36992
- [
36993
- "rsync-linking-exception",
36994
- "rsync Linking Exception",
36995
- 0
36713
+ "Artistic License": ["Artistic-1.0", "Artistic-2.0"],
36714
+ "BSD License": [
36715
+ "BSD-2-Clause",
36716
+ "BSD-2-Clause-Patent",
36717
+ "BSD-3-Clause"
36996
36718
  ],
36997
- [
36998
- "sqlitestudio-OpenSSL-exception",
36999
- "sqlitestudio OpenSSL exception",
37000
- 0
36719
+ "GNU Affero General Public License v3": ["AGPL-3.0-only", "AGPL-3.0-or-later"],
36720
+ "GNU Free Documentation License (FDL)": [
36721
+ "GFDL-1.1-only",
36722
+ "GFDL-1.1-or-later",
36723
+ "GFDL-1.2-only",
36724
+ "GFDL-1.2-or-later",
36725
+ "GFDL-1.3-only",
36726
+ "GFDL-1.3-or-later"
37001
36727
  ],
37002
- [
37003
- "stunnel-exception",
37004
- "stunnel Exception",
37005
- 0
36728
+ "GNU General Public License (GPL)": [
36729
+ "GPL-1.0-only",
36730
+ "GPL-1.0-or-later",
36731
+ "GPL-2.0-only",
36732
+ "GPL-2.0-or-later",
36733
+ "GPL-3.0-only",
36734
+ "GPL-3.0-or-later"
37006
36735
  ],
37007
- [
37008
- "u-boot-exception-2.0",
37009
- "U-Boot exception 2.0",
37010
- 0
36736
+ "GNU General Public License v2 (GPLv2)": ["GPL-2.0-only", "GPL-2.0-or-later"],
36737
+ "GNU General Public License v3 (GPLv3)": ["GPL-3.0-only", "GPL-3.0-or-later"],
36738
+ "GNU Lesser General Public License v2 (LGPLv2)": ["LGPL-2.0-only", "LGPL-2.1-only"],
36739
+ "GNU Lesser General Public License v2 or later (LGPLv2+)": ["LGPL-2.0-or-later", "LGPL-2.1-or-later"],
36740
+ "GNU Lesser General Public License v3 (LGPLv3)": ["LGPL-3.0-only", "LGPL-3.0-or-later"],
36741
+ "GNU Library or Lesser General Public License (LGPL)": [
36742
+ "LGPL-2.0-only",
36743
+ "LGPL-2.0-or-later",
36744
+ "LGPL-2.1-only",
36745
+ "LGPL-2.1-or-later",
36746
+ "LGPL-3.0-only",
36747
+ "LGPL-3.0-or-later"
37011
36748
  ],
37012
- [
37013
- "vsftpd-openssl-exception",
37014
- "vsftpd OpenSSL exception",
37015
- 0
36749
+ "Eiffel Forum License (EFL)": ["EFL-1.0", "EFL-2.0"],
36750
+ "Netscape Public License (NPL)": ["NPL-1.0", "NPL-1.1"],
36751
+ "Zope Public License": [
36752
+ "ZPL-1.1",
36753
+ "ZPL-2.0",
36754
+ "ZPL-2.1"
37016
36755
  ],
37017
- [
37018
- "x11vnc-openssl-exception",
37019
- "x11vnc OpenSSL Exception",
37020
- 0
37021
- ]
37022
- ];
36756
+ "Public Domain": [],
36757
+ "Free For Educational Use": [],
36758
+ "Free For Home Use": [],
36759
+ "Free for non-commercial use": [],
36760
+ "Freely Distributable": [],
36761
+ "Free To Use But Restricted": [],
36762
+ Freeware: [],
36763
+ "Other/Proprietary License": [],
36764
+ "Repoze Public License": [],
36765
+ "GUST Font License 1.0": [],
36766
+ "GUST Font License 2006-09-30": []
36767
+ };
36768
+ /**
36769
+ * The ids a licence string the inventory holds can stand for, when it is an
36770
+ * ambiguous classifier's name; undefined for anything else.
36771
+ */
36772
+ function classifierCandidates(license) {
36773
+ return Object.prototype.hasOwnProperty.call(AMBIGUOUS, license) ? AMBIGUOUS[license] : void 0;
36774
+ }
36775
+ //#endregion
36776
+ //#region ../../packages/types/dist/licenses/license-category.js
36777
+ const operandText = (o) => o.exception === null ? o.license : `${o.license} WITH ${o.exception}`;
36778
+ /**
36779
+ * Canonical text of a tree: operands sorted, and parentheses only where they
36780
+ * change the meaning (an OR inside an AND), so one decision always reads the
36781
+ * same however it was written.
36782
+ */
36783
+ function canonicalText(node, insideAnd = false) {
36784
+ if (node.kind === "license") return operandText(node);
36785
+ const flat = (n) => n.kind === node.kind ? n.operands.flatMap(flat) : [n];
36786
+ const joined = node.operands.flatMap(flat).map((o) => canonicalText(o, node.kind === "and")).sort().join(node.kind === "and" ? " AND " : " OR ");
36787
+ return node.kind === "or" && insideAnd ? `(${joined})` : joined;
36788
+ }
36789
+ /**
36790
+ * The part of an expression that is outside the allowlist (PRO-2944): what a
36791
+ * reviewer actually decides on. `Apache-2.0 AND LGPL-3.0-or-later` is outside
36792
+ * only through `LGPL-3.0-or-later`; `GPL-2.0-only OR LGPL-2.1-only`, with
36793
+ * neither allowed, through both choices. An AND keeps its sides that are not
36794
+ * allowed, an OR none when any side is allowed and all of them otherwise, and
36795
+ * an operand reads like the finding's (compared whole, `WITH` included). The
36796
+ * text is canonical (operands sorted, runs of one operator flattened,
36797
+ * parentheses only around an OR inside an AND), so one decision always reads
36798
+ * the same and groups as one. Null
36799
+ * when nothing reads outside, or the string is no expression: the caller then
36800
+ * falls back to the whole licence.
36801
+ */
36802
+ function outsideAllowlist(expression, allowlist) {
36803
+ const tree = parseSpdxExpression(expression);
36804
+ if (tree === null) return null;
36805
+ const allowed = new Set(allowlist.map(currentSpelling));
36806
+ const isAllowed = (node) => node.kind === "license" ? allowed.has(currentSpelling(operandText(node))) : node.kind === "and" ? node.operands.every(isAllowed) : node.operands.some(isAllowed);
36807
+ const prune = (node) => {
36808
+ if (node.kind === "license") {
36809
+ if (node.exception === null && UNKNOWN_LICENSES.includes(node.license)) return null;
36810
+ return isAllowed(node) ? null : node;
36811
+ }
36812
+ if (node.kind === "or" && node.operands.some(isAllowed)) return null;
36813
+ const kept = node.operands.map(prune).filter((n) => n !== null);
36814
+ if (kept.length === 0) return null;
36815
+ if (kept.length === 1) return kept[0];
36816
+ const operands = kept.flatMap((n) => n.kind === node.kind ? n.operands : [n]);
36817
+ return {
36818
+ kind: node.kind,
36819
+ operands
36820
+ };
36821
+ };
36822
+ const pruned = prune(tree);
36823
+ return pruned === null ? null : canonicalText(pruned);
36824
+ }
36825
+ //#endregion
36826
+ //#region src/compat.ts
36827
+ /**
36828
+ * Why this server should not serve the API it reached, or null when it may
36829
+ * (PRO-2844). The server is published to npm and the API deploys on its own
36830
+ * schedule, so a newer server can meet an older API. It would not fail
36831
+ * loudly: some tools read a 404 as a state of the world (a run not found
36832
+ * reads as deleted) and fields they explain would simply be missing. So it
36833
+ * refuses to start, and says what to do.
36834
+ */
36835
+ function apiLevelProblem(introspection, apiUrl, required = 9, version = SERVER_VERSION) {
36836
+ const offered = introspection.mcpApiLevel ?? 0;
36837
+ if (offered >= required) return null;
36838
+ return `The Taiga API at ${apiUrl} is older than @taiga-ai/mcp-server ${version} needs (API level ${offered}, needs ${required}). Run the version published for it, or wait for that API to be updated; an earlier release of this package works against it.`;
36839
+ }
36840
+ //#endregion
36841
+ //#region src/tools/toolsets.ts
36842
+ /**
36843
+ * Toolsets (PRO-2846, PRO-2838): the tools an AI tool sees, grouped by what the person does.
36844
+ *
36845
+ * A role decides what a key MAY do (the API enforces it, and tools a key cannot use are never registered); a toolset
36846
+ * decides what it SEES. A toolset never adds a tool the key's capabilities do not allow. Every toolset is on unless
36847
+ * the key says otherwise: the person chooses them for the key in Taiga's settings, and the server reads them at
36848
+ * start. Toolsets alone barely changed what the task test cost in Claude Code, which loads tool details on demand,
36849
+ * so the default is everything rather than a short list someone has to know how to widen. The tool list stays the
36850
+ * same for every connection of one server (MCP 2026-07-28), so the set is fixed at start, not mid-session.
36851
+ */
36852
+ const TOOLSETS = MCP_TOOLSETS;
36853
+ /** What each toolset is for, as whoami says it. */
36854
+ const TOOLSET_PURPOSE = {
36855
+ core: "where products, initiatives, runs, policies and findings stand",
36856
+ operate: "moving work: queue, plans, runs, fixes, Action Required",
36857
+ setup: "creating and configuring factories, products, repositories, environments and autonomy",
36858
+ observe: "deployments, monitoring, delivery metrics, the package inventory and the sweeps that read it",
36859
+ documents: "writing documents and knowledge, and regenerating product documents"
36860
+ };
36861
+ /** Every tool's toolset. A tool missing here fails at registration, so none can be added without a home. */
36862
+ const TOOLSET_OF = {
36863
+ taiga_list_products: "core",
36864
+ taiga_get_product_context: "core",
36865
+ taiga_get_product: "core",
36866
+ taiga_list_factories: "core",
36867
+ taiga_list_initiatives: "core",
36868
+ taiga_get_initiative: "core",
36869
+ taiga_get_plan: "core",
36870
+ taiga_list_runs: "core",
36871
+ taiga_get_run: "core",
36872
+ taiga_get_line: "core",
36873
+ taiga_list_action_required: "core",
36874
+ taiga_get_policy_standing: "core",
36875
+ taiga_list_findings: "core",
36876
+ taiga_get_finding: "core",
36877
+ taiga_get_organization_document: "core",
36878
+ taiga_get_design_tokens: "core",
36879
+ taiga_get_design_token_sync: "core",
36880
+ taiga_get_product_document: "core",
36881
+ taiga_wait: "core",
36882
+ taiga_queue_initiative: "operate",
36883
+ taiga_move_initiative: "operate",
36884
+ taiga_review_plan: "operate",
36885
+ taiga_plan_again: "operate",
36886
+ taiga_resume_initiative: "operate",
36887
+ taiga_stop_run: "operate",
36888
+ taiga_request_changes: "operate",
36889
+ taiga_request_initiatives: "operate",
36890
+ taiga_fix_finding: "operate",
36891
+ taiga_fix_policy_violation: "operate",
36892
+ taiga_ignore_finding: "operate",
36893
+ taiga_allow_license: "operate",
36894
+ taiga_resolve_action: "operate",
36895
+ taiga_create_factory: "setup",
36896
+ taiga_rename_factory: "setup",
36897
+ taiga_create_product: "setup",
36898
+ taiga_update_product: "setup",
36899
+ taiga_move_product: "setup",
36900
+ taiga_preview_product_move: "setup",
36901
+ taiga_link_repository: "setup",
36902
+ taiga_unlink_repository: "setup",
36903
+ taiga_list_linkable_repositories: "setup",
36904
+ taiga_list_product_repositories: "setup",
36905
+ taiga_list_repository_branches: "setup",
36906
+ taiga_set_repository_branch: "setup",
36907
+ taiga_start_import: "setup",
36908
+ taiga_finish_discovery: "setup",
36909
+ taiga_reopen_discovery: "setup",
36910
+ taiga_list_setup_tasks: "setup",
36911
+ taiga_get_job: "setup",
36912
+ taiga_set_auto_build: "setup",
36913
+ taiga_set_auto_merge: "setup",
36914
+ taiga_set_product_autonomy: "setup",
36915
+ taiga_pause_line: "setup",
36916
+ taiga_create_environment: "setup",
36917
+ taiga_update_environment: "setup",
36918
+ taiga_ship_notices: "setup",
36919
+ taiga_allow_license_package: "setup",
36920
+ taiga_replace_license_package: "setup",
36921
+ taiga_get_deployments: "observe",
36922
+ taiga_get_monitoring: "observe",
36923
+ taiga_get_delivery_metrics: "observe",
36924
+ taiga_list_packages: "observe",
36925
+ taiga_start_sweep: "observe",
36926
+ taiga_list_licenses: "observe",
36927
+ taiga_change_license: "setup",
36928
+ taiga_get_model_connection: "setup",
36929
+ taiga_set_model_connection: "setup",
36930
+ taiga_remove_model_connection: "setup",
36931
+ taiga_get_sbom: "observe",
36932
+ taiga_get_notices: "observe",
36933
+ taiga_get_factory_document: "documents",
36934
+ taiga_update_organization_document: "documents",
36935
+ taiga_publish_organization_document: "documents",
36936
+ taiga_update_design_tokens: "documents",
36937
+ taiga_sync_design_tokens: "documents",
36938
+ taiga_update_factory_document: "documents",
36939
+ taiga_publish_factory_document: "documents",
36940
+ taiga_update_product_document: "documents",
36941
+ taiga_publish_product_document: "documents",
36942
+ taiga_mark_product_document_reviewed: "documents",
36943
+ taiga_generate_product_documents: "documents",
36944
+ taiga_regenerate_product_document: "documents",
36945
+ taiga_stop_generating_documents: "documents",
36946
+ taiga_refresh_reality_documents: "documents",
36947
+ taiga_list_knowledge: "documents",
36948
+ taiga_get_knowledge: "documents",
36949
+ taiga_add_knowledge: "documents",
36950
+ taiga_delete_knowledge: "documents",
36951
+ taiga_retry_knowledge: "documents"
36952
+ };
36953
+ /**
36954
+ * What steers agents leaves with them: knowledge, a factory's instructions
36955
+ * and the design tokens, as the app hides those pages by the same rule.
36956
+ *
36957
+ * Deliver & Operate's tools (PRO-3834): initiatives, plans, runs and the line, fixes, environments, deployments,
36958
+ * monitoring and delivery metrics. An organization whose plan refuses delivery work does not see them, as its web app
36959
+ * shows none of their views; the API says which (`deliveryIncluded` at introspection), so the plan, not the key,
36960
+ * decides. Fixing a finding plans and builds, so it goes with them.
36961
+ */
36962
+ const DELIVERY_TOOLS = /* @__PURE__ */ new Set([
36963
+ "taiga_list_initiatives",
36964
+ "taiga_get_initiative",
36965
+ "taiga_get_plan",
36966
+ "taiga_list_runs",
36967
+ "taiga_get_run",
36968
+ "taiga_get_line",
36969
+ "taiga_queue_initiative",
36970
+ "taiga_move_initiative",
36971
+ "taiga_review_plan",
36972
+ "taiga_plan_again",
36973
+ "taiga_resume_initiative",
36974
+ "taiga_stop_run",
36975
+ "taiga_request_changes",
36976
+ "taiga_request_initiatives",
36977
+ "taiga_fix_finding",
36978
+ "taiga_fix_policy_violation",
36979
+ "taiga_replace_license_package",
36980
+ "taiga_ship_notices",
36981
+ "taiga_set_auto_build",
36982
+ "taiga_set_auto_merge",
36983
+ "taiga_pause_line",
36984
+ "taiga_create_environment",
36985
+ "taiga_update_environment",
36986
+ "taiga_get_deployments",
36987
+ "taiga_get_monitoring",
36988
+ "taiga_get_delivery_metrics",
36989
+ "taiga_sync_design_tokens",
36990
+ "taiga_get_design_tokens",
36991
+ "taiga_get_design_token_sync",
36992
+ "taiga_update_design_tokens",
36993
+ "taiga_get_factory_document",
36994
+ "taiga_update_factory_document",
36995
+ "taiga_publish_factory_document",
36996
+ "taiga_list_knowledge",
36997
+ "taiga_get_knowledge",
36998
+ "taiga_add_knowledge",
36999
+ "taiga_delete_knowledge",
37000
+ "taiga_retry_knowledge"
37001
+ ]);
37002
+ /**
37003
+ * TAIGA_TOOLSETS as written: comma-separated names, or "all"; a name it does not know is said, not ignored, and so
37004
+ * is a value that names none.
37005
+ */
37006
+ function parseToolsets(raw) {
37007
+ const names = raw.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean);
37008
+ const unknown = names.filter((name) => name !== "all" && !TOOLSETS.includes(name));
37009
+ if (unknown.length > 0 || names.length === 0) return { problem: `TAIGA_TOOLSETS ${unknown.length > 0 ? `names ${unknown.join(", ")}, which is no toolset` : "names no toolset"}: use ${TOOLSETS.join(", ")} or all.` };
37010
+ return { toolsets: names.includes("all") ? TOOLSETS : [...new Set(names)] };
37011
+ }
37012
+ /**
37013
+ * The toolsets a server turns on: TAIGA_TOOLSETS when the server's config names some, else the ones the key names,
37014
+ * else every one. A name the server does not know (a key set by a newer Taiga) is passed over; a key that names
37015
+ * none this server knows sees every one, rather than starting with no tools.
37016
+ */
37017
+ function activeToolsets(fromKey, fromConfig) {
37018
+ const named = fromConfig ?? fromKey?.filter((name) => TOOLSETS.includes(name));
37019
+ if (!named || named.length === 0) return [...TOOLSETS];
37020
+ return TOOLSETS.filter((toolset) => named.includes(toolset));
37021
+ }
37022
+ //#endregion
37023
+ //#region src/config.ts
37024
+ /**
37025
+ * The one place the MCP server reads its environment (PRO-2511), parsed once
37026
+ * at startup.
37027
+ */
37028
+ const DEFAULT_API_URL = "https://api.eu.tai.ga";
37029
+ const envSchema = object({
37030
+ TAIGA_API_KEY: string$2().optional(),
37031
+ TAIGA_API_URL: string$2().optional(),
37032
+ TAIGA_TOOLSETS: string$2().optional()
37033
+ });
37034
+ /** Hosts a developer runs the API on; the only ones plain http is accepted for. */
37035
+ const LOCAL_HOSTS = /* @__PURE__ */ new Set([
37036
+ "localhost",
37037
+ "127.0.0.1",
37038
+ "[::1]"
37039
+ ]);
37040
+ /**
37041
+ * Read the environment (PRO-2844). The key carries its owner's reach, so it
37042
+ * goes only to an https API (http for a local one). A pre-release build
37043
+ * (`-dev.N`, `-rc.N`) is Taiga's own dev or staging channel, and defaulting it
37044
+ * to production sent `npx @taiga-ai/mcp-server@staging` to the production API
37045
+ * with a staging key: it must name its API. A released version defaults to
37046
+ * production.
37047
+ */
37048
+ function readConfig(version = SERVER_VERSION) {
37049
+ const env = envSchema.parse(process.env);
37050
+ if (!env.TAIGA_API_KEY) return { problem: "TAIGA_API_KEY environment variable is required. Create one at https://eu.tai.ga under Settings > Account > MCP." };
37051
+ const prerelease = version.includes("-");
37052
+ if (!env.TAIGA_API_URL && prerelease) return { problem: `This is a pre-release build (${version}) for one of Taiga's own environments: set TAIGA_API_URL to that environment's API. A released version defaults to ${DEFAULT_API_URL}.` };
37053
+ const apiUrl = (env.TAIGA_API_URL || DEFAULT_API_URL).replace(/\/+$/, "");
37054
+ let url;
37055
+ try {
37056
+ url = new URL(apiUrl);
37057
+ } catch {
37058
+ return { problem: `TAIGA_API_URL is not a URL: ${apiUrl}` };
37059
+ }
37060
+ if (url.search || url.hash) return { problem: `TAIGA_API_URL must not carry a query or fragment: ${apiUrl}` };
37061
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && LOCAL_HOSTS.has(url.hostname))) return { problem: `TAIGA_API_URL must be an https URL (plain http only for localhost), so the key is never sent in the clear: ${apiUrl}` };
37062
+ if (env.TAIGA_TOOLSETS?.trim()) {
37063
+ const parsed = parseToolsets(env.TAIGA_TOOLSETS);
37064
+ if ("problem" in parsed) return { problem: parsed.problem };
37065
+ return { config: {
37066
+ apiKey: env.TAIGA_API_KEY,
37067
+ apiUrl,
37068
+ toolsets: parsed.toolsets
37069
+ } };
37070
+ }
37071
+ return { config: {
37072
+ apiKey: env.TAIGA_API_KEY,
37073
+ apiUrl
37074
+ } };
37075
+ }
37076
+ //#endregion
37077
+ //#region src/tools/annotations.ts
37078
+ /**
37079
+ * Tool annotations shared by the tools. Hints for the client, not a
37080
+ * control: the API enforces what a key may do. A client that asks the
37081
+ * person before a destructive call reads destructiveHint; the server-side
37082
+ * approval gate (PRO-548) is separate work.
37083
+ */
37084
+ const READ_ONLY = {
37085
+ readOnlyHint: true,
37086
+ destructiveHint: false,
37087
+ idempotentHint: true,
37088
+ openWorldHint: false
37089
+ };
37090
+ /** A write that adds or edits a row and starts nothing: a created initiative, a moved one. */
37091
+ const WRITE = {
37092
+ readOnlyHint: false,
37093
+ destructiveHint: false,
37094
+ idempotentHint: false,
37095
+ openWorldHint: false
37096
+ };
37097
+ /**
37098
+ * A write that starts or stops paid work, or opens the door to it: queueing
37099
+ * an initiative, approving a plan, resuming or stopping a run. Each starts
37100
+ * an agent that spends tokens and opens pull requests, or halts one mid-way.
37101
+ */
37102
+ const OPERATE = {
37103
+ readOnlyHint: false,
37104
+ destructiveHint: true,
37105
+ idempotentHint: false,
37106
+ openWorldHint: false
37107
+ };
37108
+ /**
37109
+ * An OPERATE write that sets a value rather than adding one: the same call
37110
+ * twice leaves things as one call does (a review gate set, a line paused).
37111
+ */
37112
+ const OPERATE_SETTING = {
37113
+ ...OPERATE,
37114
+ idempotentHint: true
37115
+ };
37116
+ //#endregion
37117
+ //#region src/tools/inputs.ts
37118
+ /** The inputs several tools share, so a product or a page is named the same way everywhere. */
37119
+ /**
37120
+ * An ID input whose refusal says where the ID comes from. The client shows the
37121
+ * schema's message, not the description, when a call fails validation, and
37122
+ * "Invalid UUID" alone sends a model that passed a name to guess again.
37123
+ */
37124
+ function idInput(what, from, said = from) {
37125
+ return string$2().uuid({ message: `${/^[aeiou]/i.test(what) ? "An" : "A"} ${what} ID is a UUID, not a name: ${from}` }).meta({ pattern: void 0 }).describe(`${what[0].toUpperCase()}${what.slice(1)} ID -- ${said}`);
37126
+ }
37127
+ const productId = idInput("product", "taiga_list_products (query finds one by name), or taiga_get_product with a git remote URL, gives it", "taiga_list_products gives it");
37128
+ /** The page inputs every list tool takes; `nextCursor` of one page is the `cursor` of the next. */
37129
+ const pagination = {
37130
+ limit: number$1().int().min(1).max(100).optional().describe("Max results (default 25)"),
37131
+ cursor: string$2().max(256).optional().describe("The previous page's nextCursor; omit for the first page")
37132
+ };
37133
+ const slug = string$2().max(76).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "A slug is lowercase words joined by hyphens").describe("The segment after /products/ in its Taiga URL (web-shop-5d060fa7460e), or its slug");
37134
+ const remoteUrl = string$2().min(1).max(2048).describe("The git remote URL of a checkout (git remote get-url origin): https://, git@host:owner/repo.git or ssh://");
37135
+ //#endregion
37136
+ //#region src/tools/catalogue.ts
37137
+ /**
37138
+ * What exists, from the one place that knows: the shared types package.
37139
+ *
37140
+ * Tool descriptions are what the model reads to decide what to call, and a
37141
+ * description that names a document type the catalogue lacks sends it down a
37142
+ * dead end (the walk-through that led here found `policy_acceptable_use` and
37143
+ * `policy_ip` named in a description and nowhere else). Every list of types,
37144
+ * origins and statuses a tool shows is derived from these constants, and a
37145
+ * test holds the descriptions to them.
37146
+ */
37147
+ /**
37148
+ * Display names for every product document type. The reviewable nine come
37149
+ * from the shared map the web uses; the three the web never asks a person to
37150
+ * review are named here, and the record type keeps the two sets complete.
37151
+ */
37152
+ const PRODUCT_DOCUMENT_NAMES = {
37153
+ ...PRODUCT_DOCUMENT_DISPLAY_NAMES,
37154
+ ui_direction: "Look & Feel",
37155
+ codebase_snapshot: "Codebase Snapshot",
37156
+ product_instructions: "Product Instructions"
37157
+ };
37158
+ function productDocumentName(type) {
37159
+ return PRODUCT_DOCUMENT_NAMES[type] ?? type;
37160
+ }
37161
+ /**
37162
+ * The two document timelines of a product (ADR-017), in the words the tools
37163
+ * and the server instructions use. One place, so the list tool, the read
37164
+ * tool and the instructions cannot explain them three different ways.
37165
+ */
37166
+ const ORIGIN_MEANING = {
37167
+ plan: "plan: the discovery documents, what is meant to be built.",
37168
+ reality: "reality: derived from the code on the main branch, what is built; an imported product has them from its import, any other once its first initiative is done (a merged pull request) or code is pushed."
37169
+ };
37170
+ /**
37171
+ * Which timeline is a product's own (the API's documentOriginForSettings):
37172
+ * an imported product has no plan chain by design, so its documents are on
37173
+ * the reality side; everything else starts on the plan side. Derived from the
37174
+ * same settings key the API reads, so the two cannot disagree.
37175
+ */
37176
+ function isImportedProduct(product) {
37177
+ return product?.settings?.projectType === "brownfield";
37178
+ }
37179
+ /**
37180
+ * The document types no derivation ever writes: a person records or writes
37181
+ * them, so they live on the plan side of every product, imported or not.
37182
+ */
37183
+ const PLAN_ONLY_DOCUMENT_TYPES = PRODUCT_DOCUMENT_TYPES.filter((type) => !REALITY_DERIVED_DOCUMENT_TYPES.includes(type));
37184
+ /**
37185
+ * The timeline a read should default to: the plan side for a type only a
37186
+ * person writes, else the product's own side (reality for an imported
37187
+ * product, plan for every other).
37188
+ */
37189
+ function defaultOriginFor(product, type) {
37190
+ if (type !== void 0 && PLAN_ONLY_DOCUMENT_TYPES.includes(type)) return "plan";
37191
+ return isImportedProduct(product) ? "reality" : "plan";
37192
+ }
37193
+ /**
37194
+ * Where an imported product's import got to (`settings.importStatus`, written
37195
+ * by the API: pending, analyzing, complete, cancelled, failed). Unknown values
37196
+ * read as "not known", never as a promise.
37197
+ */
37198
+ function importStatusOf(product) {
37199
+ const status = product?.settings?.importStatus;
37200
+ return typeof status === "string" ? status : null;
37201
+ }
37202
+ /** Why a side of the timeline is empty, for a list or a miss that shows one. */
37203
+ function emptyOriginNote(origin, product) {
37204
+ const imported = isImportedProduct(product);
37205
+ if (origin === "plan") return imported ? `This product is set up from its code (an import), so no discovery chain is generated for it: its derived documents are on the reality side. Only the documents a person writes (${PLAN_ONLY_DOCUMENT_TYPES.map(productDocumentName).join(", ")}) would appear here.` : "No plan documents are published yet: they are written during discovery in Taiga.";
37206
+ if (!imported) return "No reality documents yet: they are derived from the code once the first initiative is done (a merged pull request marks it done) or the repository is pushed to. Until then read the plan side.";
37207
+ switch (importStatusOf(product)) {
37208
+ case "pending": return "No reality documents yet: the import has not started. taiga_start_import starts it once a repository is linked; taiga_get_product's readiness says whether one is.";
37209
+ case "analyzing":
37210
+ case "generating_docs": return "No reality documents yet: the import is running and will derive them from the code.";
37211
+ case "cancelled": return "No reality documents: the import was cancelled before it derived any. taiga_start_import runs it again.";
37212
+ case "failed": return "No reality documents: the import failed before it derived any. taiga_start_import runs it again.";
37213
+ default: return "No reality documents: the import derives them from the code, and none have been published.";
37214
+ }
37215
+ }
37216
+ /**
37217
+ * What finishing does, in every next step that ends at it (PRO-2857): it
37218
+ * starts paid planning, so a client must ask the person before calling it.
37219
+ */
37220
+ const FINISH_DISCOVERY = "taiga_finish_discovery opens the product and starts planning its first initiatives (paid agent work: ask the person first).";
37221
+ /**
37222
+ * What a product in setup waits for, as the next call to make. Nothing on a
37223
+ * draft product says it otherwise: discoveryStep names the step and
37224
+ * importStatus the import, and the way on from each lives in tool
37225
+ * descriptions an agent reads only when it already knows which. Null once the
37226
+ * product is active.
37227
+ */
37228
+ function setupNextStep(product) {
37229
+ if (product?.status !== "draft") return null;
37230
+ if (isImportedProduct(product)) switch (importStatusOf(product)) {
37231
+ case "analyzing":
37232
+ case "generating_docs": return `The import is running and derives the documents from the code (taiga_wait (jobId) follows its job). Then review them, and ${FINISH_DISCOVERY}`;
37233
+ case "complete": return "The import is done: review the reality documents (taiga_get_product_document without type), then " + FINISH_DISCOVERY;
37234
+ case "failed":
37235
+ case "cancelled": return "The last import did not finish: taiga_start_import runs it again.";
37236
+ default: return "Link its repository if it has none (taiga_list_linkable_repositories, taiga_link_repository), then taiga_start_import: the import derives the documents from the code and runs by itself.";
37237
+ }
37238
+ if (product.discoveryStep === void 0) return null;
37239
+ switch (product.discoveryStep) {
37240
+ case "documents": return `The specification is done; the other documents are generated from it (taiga_generate_product_documents starts the ones still missing). Once every required one is published, ${FINISH_DISCOVERY}`;
37241
+ default: return `Discovery is a conversation held in the web: the person describes the product there and the specification comes out of it. The other documents follow, then ${FINISH_DISCOVERY}`;
37242
+ }
37243
+ }
37023
37244
  //#endregion
37024
- //#region ../../packages/types/dist/licenses/spdx-expression.js
37245
+ //#region src/tools/hints.ts
37025
37246
  /**
37026
- * The SPDX license expression grammar (SPDX 2.3, Annex D), parsed once and
37027
- * shared by everything that reads a licence string: the SBOM renderer, which
37028
- * must only emit an expression an SPDX-aware consumer will accept, and the
37029
- * licence summary, which reads an expression against the allowlist (PRO-2945).
37030
- *
37031
- * The parser decides the SHAPE only: operands are any token that is not an
37032
- * operator or a parenthesis, the way osv-scanner's own parser reads them
37033
- * (internal/spdx/satisfies.go, v2.4.0). Whether an operand is a listed SPDX id
37034
- * is the caller's question, since the renderer needs a strict answer and the
37035
- * allowlist only a string comparison.
37247
+ * The next step after the API answers 404. The API's own word is bare
37248
+ * ("Initiative not found", "Repository link not found"), and an agent that
37249
+ * hears only that guesses another ID, or a name. Each ID a tool takes names
37250
+ * the tool that lists the right ones; the tool's arguments say which apply.
37036
37251
  */
37037
- const OPERATORS = /* @__PURE__ */ new Set([
37038
- "AND",
37039
- "OR",
37040
- "WITH",
37041
- "(",
37042
- ")"
37043
- ]);
37252
+ const ITEM_ID_HINT = "taiga_list_initiatives lists a product's initiatives with their IDs; a run or plan ID is not one.";
37253
+ const BY_ARGUMENT = {
37254
+ initiativeId: ITEM_ID_HINT,
37255
+ runId: "taiga_list_runs lists the runs, of one product or of every product the key can see.",
37256
+ planId: "taiga_get_plan gives the initiative's active plan and its ID.",
37257
+ linkId: "taiga_list_product_repositories lists the product's repository links; a linkable repository id is not a link ID.",
37258
+ replacesLinkId: "taiga_list_product_repositories lists the product's repository links.",
37259
+ linkableRepositoryId: "taiga_list_linkable_repositories lists the repositories the GitHub, GitLab and Azure DevOps connections reach, with their ids.",
37260
+ installationId: "taiga_list_linkable_repositories lists the connected GitHub accounts, GitLab and Azure DevOps connections.",
37261
+ jobId: "A job ID is what the tool that started the job returned (taiga_request_initiatives, taiga_start_import).",
37262
+ factoryId: "taiga_list_factories lists the factories the key can see.",
37263
+ findingId: "taiga_list_findings lists a product's findings.",
37264
+ violationId: "taiga_get_policy_standing lists a product's policy violations.",
37265
+ environmentId: "taiga_get_deployments lists the product's environments with their IDs; a product ID is not one.",
37266
+ knowledgeId: "taiga_list_knowledge lists the knowledge files.",
37267
+ productId: "taiga_list_products lists the products the key can see; a name is not an ID (taiga_get_product takes a slug)."
37268
+ };
37044
37269
  /**
37045
- * Licence strings are stored as the scanner reported them, unbounded; the
37046
- * parser recurses once per parenthesis level, so a pathological value could
37047
- * exhaust the stack. Real expressions nest a level or two: past this bound the
37048
- * string does not parse.
37270
+ * A licence a product does not hold, as against a product the key cannot see
37271
+ * (PRO-3879). Any other 404 (the routes do not exist where the licenses
37272
+ * feature is off) blames neither.
37049
37273
  */
37050
- const MAX_DEPTH = 32;
37274
+ const licenseMiss = (hint) => (said) => /\blicen[cs]e\b/i.test(said) ? hint : /\b(product|project) not found/i.test(said) ? BY_ARGUMENT["productId"] : void 0;
37275
+ /** Where an argument means something else on one tool, or the tool's 404 needs its own word. */
37276
+ const BY_TOOL = {
37277
+ taiga_allow_license: licenseMiss("taiga_list_packages (productId) summarizes the product's licenses as its findings name them; a license with no finding there has nothing to allow or reopen."),
37278
+ taiga_list_licenses: licenseMiss("taiga_list_licenses without license lists the licenses in use, and taiga_list_packages (productId) one product's, spelled as their findings spell them."),
37279
+ taiga_resolve_action: () => "taiga_list_action_required lists the items with their IDs.",
37280
+ taiga_get_sbom: () => "An SBOM exists once a sweep has inventoried that repository, where the licenses feature is enabled; taiga_list_packages (linkId) says whether it has packages, and taiga_list_product_repositories lists the links.",
37281
+ taiga_get_notices: () => "Notices exist once a sweep has inventoried that repository, where the licenses feature is enabled; taiga_list_product_repositories lists the links.",
37282
+ taiga_get_plan: (said) => /\bplan\b/i.test(said) ? "taiga_get_initiative's situation says whether one is being planned or failed, and names the call that asks for one (taiga_queue_initiative off the line, taiga_plan_again for a failed plan)." : ITEM_ID_HINT
37283
+ };
37051
37284
  /**
37052
- * The expression tree of `text`, or null when it is not one: unbalanced
37053
- * parentheses, a dangling or doubled operator, two operands with no operator
37054
- * between them. AND binds tighter than OR; WITH binds an exception to the one
37055
- * licence before it; operators are upper case, so `mit or isc` is not an
37056
- * expression.
37285
+ * What the API calls the thing each ID names, as its 404 says it ("Environment
37286
+ * not found"). A tool given a right product and a wrong environment hinted
37287
+ * at both, and the product's hint told the agent its correct product ID was
37288
+ * the mistake (PRO-2800): a 404 that names its thing gets that ID's hint only.
37057
37289
  */
37058
- function parseSpdxExpression(text) {
37059
- const tokens = text.replace(/([()])/g, " $1 ").trim().split(/\s+/).filter((t) => t !== "");
37060
- if (tokens.length === 0) return null;
37061
- let at = 0;
37062
- let depth = 0;
37063
- const peek = () => tokens[at];
37064
- const operand = (token) => token !== void 0 && !OPERATORS.has(token);
37065
- const term = () => {
37066
- const token = peek();
37067
- if (token === "(") {
37068
- if (depth === MAX_DEPTH) return null;
37069
- depth += 1;
37070
- at += 1;
37071
- const inner = compound();
37072
- if (inner === null || peek() !== ")") return null;
37073
- at += 1;
37074
- depth -= 1;
37075
- return inner;
37076
- }
37077
- if (!operand(token)) return null;
37078
- at += 1;
37079
- if (peek() !== "WITH") return {
37080
- kind: "license",
37081
- license: token,
37082
- exception: null
37083
- };
37084
- at += 1;
37085
- const exception = peek();
37086
- if (!operand(exception)) return null;
37087
- at += 1;
37088
- return {
37089
- kind: "license",
37090
- license: token,
37091
- exception
37092
- };
37290
+ const MISSING_THING = {
37291
+ initiativeId: /backlog item|initiative/i,
37292
+ runId: /\b(build )?run\b/i,
37293
+ planId: /\bplan\b/i,
37294
+ linkId: /repository link|\blink\b|repository/i,
37295
+ replacesLinkId: /repository link|\blink\b/i,
37296
+ linkableRepositoryId: /github repository|gitlab project|azure devops (repository|resource|connection)/i,
37297
+ installationId: /installation|account|gitlab connection|azure devops connection/i,
37298
+ jobId: /\bjob\b/i,
37299
+ factoryId: /factory|team/i,
37300
+ findingId: /finding/i,
37301
+ violationId: /violation/i,
37302
+ environmentId: /environment/i,
37303
+ knowledgeId: /knowledge|document/i,
37304
+ productId: /\b(product|project) not found/i
37305
+ };
37306
+ /** The hint for a 404 from one tool call: the tool's own, else the one for the ID the API says is missing. */
37307
+ function notFoundHint(tool, args) {
37308
+ if (BY_TOOL[tool]) return BY_TOOL[tool];
37309
+ if (typeof args !== "object" || args === null) return void 0;
37310
+ const given = Object.keys(args).filter((key) => args[key] != null && BY_ARGUMENT[key]);
37311
+ given.sort((a, b) => Number(a === "productId") - Number(b === "productId"));
37312
+ if (given.length === 0) return void 0;
37313
+ return (said) => {
37314
+ const named = given.filter((key) => MISSING_THING[key]?.test(said));
37315
+ return (named.length > 0 ? named : given).map((key) => BY_ARGUMENT[key]).join(" ");
37093
37316
  };
37094
- const chain = (kind, operator, next) => {
37095
- const first = next();
37096
- if (first === null) return null;
37097
- const operands = [first];
37098
- while (peek() === operator) {
37099
- at += 1;
37100
- const operand = next();
37101
- if (operand === null) return null;
37102
- operands.push(operand);
37103
- }
37104
- return operands.length === 1 ? first : {
37105
- kind,
37106
- operands
37317
+ }
37318
+ /** The hint of the tool call in progress, read by runTool when the API answers 404. */
37319
+ const notFoundHints = new AsyncLocalStorage();
37320
+ /** The API's 404 message with the hint of the call in progress, if it has one. */
37321
+ function withNotFoundHint(said) {
37322
+ const hint = notFoundHints.getStore()?.(said);
37323
+ return hint ? `${withStop(said)} ${hint}` : said;
37324
+ }
37325
+ /** A sentence ends in a stop before the next one is added to it. */
37326
+ function withStop(text) {
37327
+ return /[.!?]$/.test(text.trimEnd()) ? text.trimEnd() : `${text.trimEnd()}.`;
37328
+ }
37329
+ /** Where an ID argument comes from, for a call refused before it reached the API (PRO-2841). */
37330
+ function idSource(argument) {
37331
+ return BY_ARGUMENT[argument];
37332
+ }
37333
+ /** The verbs and joining words of tool names: what a tool does, not what it is about. */
37334
+ const VERBS = new Set("get list update create set publish move queue approve reject review resume stop wait for fix ignore mark add delete retry regenerate refresh link unlink rename request resolve start finish reopen pause preview define generate again whoami".split(" "));
37335
+ /** What a tool name is about, singular: taiga_list_initiatives is about an initiative. */
37336
+ const nouns = (tool) => new Set(tool.replace(/^taiga_/, "").split("_").filter((word) => !VERBS.has(word)).map((word) => word.replace(/s$/, "")));
37337
+ /**
37338
+ * The tool, of those that take `argument`, that is about the same thing as the
37339
+ * one that refused it: taiga_get_organization_document refusing productId points at
37340
+ * taiga_get_product_document, not at one of the thirty other tools that take a
37341
+ * product. Only a tool sharing a noun counts, and a read is never pointed at a
37342
+ * write; with none, there is no closest tool and the caller says to leave the
37343
+ * argument out.
37344
+ */
37345
+ function closestToolTaking(argument, refusedBy, inputs, isRead) {
37346
+ const mine = nouns(refusedBy);
37347
+ const readsOnly = isRead(refusedBy);
37348
+ let best;
37349
+ for (const [tool, keys] of inputs) {
37350
+ if (tool === refusedBy || !keys.includes(argument) || readsOnly && !isRead(tool)) continue;
37351
+ const shared = [...nouns(tool)].filter((word) => mine.has(word)).length;
37352
+ if (shared === 0) continue;
37353
+ if (!best || shared > best.shared || shared === best.shared && tool.length < best.tool.length) best = {
37354
+ tool,
37355
+ shared
37107
37356
  };
37108
- };
37109
- const conjunction = () => chain("and", "AND", term);
37110
- const compound = () => chain("or", "OR", conjunction);
37111
- const tree = compound();
37112
- return tree !== null && at === tokens.length ? tree : null;
37357
+ }
37358
+ return best?.tool;
37113
37359
  }
37114
- /** Every licence operand of `tree`, left to right. */
37115
- function licenseOperands(tree) {
37116
- return tree.kind === "license" ? [tree] : tree.operands.flatMap(licenseOperands);
37360
+ /** One of the tool's own arguments spelled another way (product_id, initiativeID), if the refused key is one. */
37361
+ function ownArgumentLike(key, own) {
37362
+ const plain = (name) => name.replace(/[_-]/g, "").toLowerCase();
37363
+ return own.find((name) => plain(name) === plain(key));
37117
37364
  }
37118
37365
  //#endregion
37119
- //#region ../../packages/types/dist/licenses/license-normalise.js
37366
+ //#region src/tools/errors.ts
37120
37367
  /**
37121
- * One reading of licence text as SPDX (milestone 2j, design 5.2).
37122
- *
37123
- * Registries and scanners declare licences in every shape: SPDX expressions
37124
- * (`MIT OR Apache-2.0`), deprecated ids (`GPL-2.0-with-classpath-exception`),
37125
- * names (`The Apache Software License, Version 2.0`, `MPL 2.0`), abbreviations
37126
- * (`GPL2 w/ CPE`), URLs, and words that are no licence at all (`Nonstandard`,
37127
- * `SEE LICENSE IN README.md`). deps.dev reduces the hard ones to
37128
- * `non-standard`, and until now that reduction was final, so h2 (`MPL 2.0`,
37129
- * `EPL 1.0`) and mysql-connector-j read as non-standard. This reads the raw
37130
- * text once, the same way for every source:
37131
- *
37132
- * 1. an SPDX expression of listed ids is that expression, in the list's
37133
- * spelling (a deprecated id stays itself; `currentSpelling` compares it
37134
- * with its current form);
37135
- * 2. a name the alias table knows (`ALIASES`: what registries actually
37136
- * write, checked by hand), then the SPDX list's own names and ids compared
37137
- * without punctuation or filler words, then the licence's reference URL;
37138
- * 3. anything else is a licence that is not a standard one, kept with its
37139
- * text and link so a person can read it.
37140
- *
37141
- * A declaration of several licences is a choice in the ecosystems whose
37142
- * manifests say so (a POM's `<licenses>`, a gemspec's `licenses`,
37143
- * composer.json's `license` array): `normaliseDeclared` joins them with OR,
37144
- * a non-standard one as a `LicenseRef-` operand, so `GPL-2.0-only OR
37145
- * GPL-3.0-only OR LicenseRef-nonstandard` still offers the GPLs. Elsewhere
37146
- * several licences all apply (AND).
37368
+ * The API's names for the two IDs an agent chains most, in the product's
37369
+ * words the tools take them in (PRO-2800): a row says initiativeId and runId,
37370
+ * as taiga_get_initiative and taiga_get_run ask for them, rather than the
37371
+ * storage names backlogItemId and buildRunId.
37147
37372
  */
37148
- const DEPRECATED = {
37149
- "AGPL-1.0": "AGPL-1.0-only",
37150
- "AGPL-3.0": "AGPL-3.0-only",
37151
- "GFDL-1.1": "GFDL-1.1-only",
37152
- "GFDL-1.2": "GFDL-1.2-only",
37153
- "GFDL-1.3": "GFDL-1.3-only",
37154
- "GPL-1.0": "GPL-1.0-only",
37155
- "GPL-1.0+": "GPL-1.0-or-later",
37156
- "GPL-2.0": "GPL-2.0-only",
37157
- "GPL-2.0+": "GPL-2.0-or-later",
37158
- "GPL-3.0": "GPL-3.0-only",
37159
- "GPL-3.0+": "GPL-3.0-or-later",
37160
- "LGPL-2.0": "LGPL-2.0-only",
37161
- "LGPL-2.0+": "LGPL-2.0-or-later",
37162
- "LGPL-2.1": "LGPL-2.1-only",
37163
- "LGPL-2.1+": "LGPL-2.1-or-later",
37164
- "LGPL-3.0": "LGPL-3.0-only",
37165
- "LGPL-3.0+": "LGPL-3.0-or-later",
37166
- "GPL-2.0-with-classpath-exception": "GPL-2.0-only WITH Classpath-exception-2.0",
37167
- "GPL-2.0-with-GCC-exception": "GPL-2.0-only WITH GCC-exception-2.0",
37168
- "GPL-2.0-with-autoconf-exception": "GPL-2.0-only WITH Autoconf-exception-2.0",
37169
- "GPL-2.0-with-bison-exception": "GPL-2.0-only WITH Bison-exception-2.2",
37170
- "GPL-2.0-with-font-exception": "GPL-2.0-only WITH Font-exception-2.0",
37171
- "GPL-3.0-with-GCC-exception": "GPL-3.0-only WITH GCC-exception-3.1",
37172
- "GPL-3.0-with-autoconf-exception": "GPL-3.0-only WITH Autoconf-exception-3.0",
37173
- "eCos-2.0": "GPL-2.0-or-later WITH eCos-exception-2.0",
37174
- wxWindows: "GPL-2.0-or-later WITH WxWindows-exception-3.1",
37175
- "BSD-2-Clause-FreeBSD": "BSD-2-Clause",
37176
- "BSD-2-Clause-NetBSD": "BSD-2-Clause",
37177
- "StandardML-NJ": "SMLNJ",
37178
- Nunit: "zlib-acknowledgement",
37179
- "bzip2-1.0.5": "bzip2-1.0.6"
37373
+ const PRODUCT_WORDS = {
37374
+ backlogItemId: "initiativeId",
37375
+ buildRunId: "runId",
37376
+ productRepositoryId: "linkId",
37377
+ latestBuild: "latestRun"
37180
37378
  };
37181
- /** Words a licence name carries that do not tell two licences apart. */
37182
- const FILLER = /* @__PURE__ */ new Set([
37183
- "the",
37184
- "license",
37185
- "licence",
37186
- "licensed",
37187
- "version",
37188
- "v",
37189
- "software",
37190
- "under",
37191
- "terms",
37192
- "of"
37379
+ /**
37380
+ * Maps whose keys are content, not API fields: a document's sections are keyed
37381
+ * by ids a person or agent chose (a section may be called backlogItemId), and
37382
+ * metadata and settings hold whatever their writer put there. Copied as they
37383
+ * are, keys and all.
37384
+ */
37385
+ const OPAQUE_MAPS = /* @__PURE__ */ new Set([
37386
+ "sections",
37387
+ "metadata",
37388
+ "settings"
37193
37389
  ]);
37194
- /** A name reduced to what distinguishes it: `The Apache Software License, Version 2.0` -> `apache20`. */
37195
- function nameKey(text) {
37196
- return text.toLowerCase().replace(/licence/g, "license").replace(/[^a-z0-9.+]+/g, " ").split(" ").filter((word) => word !== "" && !FILLER.has(word)).join("").replace(/\./g, "");
37197
- }
37198
- let index$1 = null;
37199
- function buildIndex() {
37200
- const ids = /* @__PURE__ */ new Map();
37201
- const currentForms = /* @__PURE__ */ new Map();
37202
- const exceptions = /* @__PURE__ */ new Map();
37203
- const names = /* @__PURE__ */ new Map();
37204
- const urls = /* @__PURE__ */ new Map();
37205
- const add = (map, key, id) => {
37206
- if (key === "") return;
37207
- const held = map.get(key);
37208
- if (held === void 0) map.set(key, id);
37209
- else if (held !== id) map.set(key, null);
37210
- };
37211
- for (const [id, name, deprecated, references] of SPDX_LICENSES) {
37212
- const current = deprecated ? DEPRECATED[id] : id;
37213
- ids.set(id.toLowerCase(), id);
37214
- currentForms.set(id.toLowerCase(), current ?? id);
37215
- if (!current) continue;
37216
- add(names, nameKey(id), current);
37217
- add(names, nameKey(name), current);
37218
- if (/ only$/i.test(name)) add(names, nameKey(name.replace(/ only$/i, "")), current);
37219
- for (const reference of references) add(urls, reference, current);
37220
- }
37221
- for (const [id, , deprecated] of SPDX_EXCEPTIONS) if (!deprecated) exceptions.set(id.toLowerCase(), id);
37222
- const definite = (map) => new Map([...map].filter((entry) => entry[1] !== null));
37223
- return {
37224
- ids,
37225
- current: currentForms,
37226
- exceptions,
37227
- names: definite(names),
37228
- urls: definite(urls)
37229
- };
37230
- }
37231
- function lists() {
37232
- index$1 ??= buildIndex();
37233
- return index$1;
37234
- }
37390
+ /** A copy of an API value with its keys in the product's words, values untouched. */
37235
37391
  /**
37236
- * `text` as an SPDX expression of listed licences and exceptions, in the
37237
- * list's spelling (a deprecated id kept as itself); null when it is not one.
37238
- * `LicenseRef-` operands are kept as written.
37392
+ * Run actions only the web offers (PRO-2800): start_over was listed beside what an agent can call, on runs and on
37393
+ * every initiative's latest run, while the descriptions said it was web only. Split apart wherever actions appear.
37239
37394
  */
37240
- function spdxExpression(text) {
37241
- const trimmed = text.trim();
37242
- const tree = parseSpdxExpression(/^[^\s()/]+(\/[^\s()/]+)+$/.test(trimmed) ? trimmed.split("/").join(" OR ") : trimmed);
37243
- if (tree === null) return null;
37244
- const { ids, exceptions } = lists();
37245
- const spelled = /* @__PURE__ */ new Map();
37246
- for (const operand of licenseOperands(tree)) {
37247
- let current;
37248
- if (/^licenseref-/i.test(operand.license)) current = operand.license;
37249
- else current = ids.get(operand.license.toLowerCase());
37250
- if (current === void 0) return null;
37251
- if (operand.exception !== null) {
37252
- const exception = exceptions.get(operand.exception.toLowerCase());
37253
- if (exception === void 0 || current.includes(" WITH ")) return null;
37254
- spelled.set(operand.exception, exception);
37255
- }
37256
- spelled.set(operand.license, / (AND|OR) /.test(current) ? `(${current})` : current);
37395
+ const WEB_ONLY_ACTIONS = /* @__PURE__ */ new Set(["start_over"]);
37396
+ function inProductWords(value) {
37397
+ if (Array.isArray(value)) return value.map(inProductWords);
37398
+ if (value === null || typeof value !== "object") return value;
37399
+ const out = {};
37400
+ const actions = value["actions"];
37401
+ if (Array.isArray(actions) && actions.some((action) => WEB_ONLY_ACTIONS.has(String(action)))) {
37402
+ const webOnly = actions.filter((action) => WEB_ONLY_ACTIONS.has(String(action)));
37403
+ const said = value["webOnlyActions"];
37404
+ value = {
37405
+ ...value,
37406
+ actions: actions.filter((action) => !WEB_ONLY_ACTIONS.has(String(action))),
37407
+ webOnlyActions: [.../* @__PURE__ */ new Set([...Array.isArray(said) ? said : [], ...webOnly])]
37408
+ };
37257
37409
  }
37258
- return render$1(tree, spelled);
37410
+ for (const [key, inner] of Object.entries(value)) Object.defineProperty(out, PRODUCT_WORDS[key] ?? key, {
37411
+ value: OPAQUE_MAPS.has(key) ? inner : inProductWords(inner),
37412
+ enumerable: true,
37413
+ writable: true,
37414
+ configurable: true
37415
+ });
37416
+ return out;
37417
+ }
37418
+ /** The API's 404 sentence in the product's words: "Backlog item not found" is an initiative not found. */
37419
+ function inProductWording(said) {
37420
+ return said.replace(/^Backlog item not found/i, "Initiative not found").replace(/^Build run step not found/i, "Run step not found").replace(/^Build run not found/i, "Run not found").replace(/^Custom document not found/i, "Knowledge file not found").replace(/^(Branch "[^"]*" does not exist in \S+?)\.?$/i, "$1. taiga_list_repository_branches lists the branches it has.");
37259
37421
  }
37260
37422
  /**
37261
- * One licence, with or without its exception, in the list's spelling (a
37262
- * deprecated id as itself); null for anything else (an expression of
37263
- * several licences, a LicenseRef, an exception alone).
37423
+ * A float without its binary noise: six significant digits. Delivery metrics
37424
+ * came as `deploysPerWeek: 6.766666666666667`, sixteen digits nobody reads
37425
+ * (PRO-2847). Significant digits rather than fixed decimals: an EPSS score of
37426
+ * 0.00043, a 0.4% failure rate or 99.995% uptime keep what they say, where
37427
+ * two decimals read them as 0, 0 and 100.
37264
37428
  */
37265
- function spdxLicenseEntry(text) {
37266
- const expression = spdxExpression(text);
37267
- if (expression === null) return null;
37268
- const plain = unwrap(expression);
37269
- const tree = parseSpdxExpression(plain);
37270
- return tree?.kind === "license" && !/^licenseref-/i.test(tree.license) ? plain : null;
37271
- }
37429
+ const roundFloats = (_key, value) => typeof value === "number" && Number.isFinite(value) && !Number.isInteger(value) ? Number(value.toPrecision(6)) : value;
37272
37430
  /**
37273
- * One licence (or licence WITH exception) as the list and the licences are
37274
- * compared (milestone 2j): its current SPDX form, lower-cased, so a list
37275
- * written with `GPL-2.0` allows a package read as `GPL-2.0-only`, and one with
37276
- * `GPL-2.0-with-classpath-exception` the same licence in its current spelling.
37431
+ * A result as the model reads it: compact JSON, in the product's words, its
37432
+ * floats rounded. Indentation was a fifth of a list's characters (PRO-2847),
37433
+ * paid on every call; the model reads JSON without it.
37277
37434
  */
37278
- function currentSpelling(text) {
37279
- const held = spellings.get(text);
37280
- if (held !== void 0) return held;
37281
- const spelled = (currentForm(text) ?? text.trim()).toLowerCase();
37282
- if (spellings.size >= SPELLINGS_MAX) spellings.clear();
37283
- spellings.set(text, spelled);
37284
- return spelled;
37435
+ function serializeResult(value) {
37436
+ return JSON.stringify(inProductWords(value), roundFloats);
37437
+ }
37438
+ /** A successful tool result: one JSON text block the model reads. */
37439
+ function toolResult(value) {
37440
+ return { content: [{
37441
+ type: "text",
37442
+ text: serializeResult(value)
37443
+ }] };
37285
37444
  }
37286
37445
  /**
37287
- * `currentSpelling` by its text. A judgement compares every licence of every
37288
- * package against every list entry, and each spelling parses the text three
37289
- * times: an organization's change of its list, over a few thousand packages,
37290
- * spent seconds parsing the same few dozen strings.
37446
+ * A failed tool result the model can branch on: a stable code and a message
37447
+ * that says what to do next. Returned, not thrown, so the client sees
37448
+ * `isError` rather than a protocol error.
37291
37449
  */
37292
- const spellings = /* @__PURE__ */ new Map();
37293
- const SPELLINGS_MAX = 1e4;
37294
- /** One list entry in its current form, cased as the list spells it; null for what is no entry. */
37295
- function currentForm(text) {
37296
- const entry = spdxLicenseEntry(text);
37297
- const tree = entry === null ? null : parseSpdxExpression(entry);
37298
- if (tree === null || tree.kind !== "license") return null;
37299
- const base = lists().current.get(tree.license.toLowerCase()) ?? tree.license;
37300
- return tree.exception === null ? base : `${base} WITH ${tree.exception}`;
37450
+ function toolError(error, message, details) {
37451
+ return {
37452
+ content: [{
37453
+ type: "text",
37454
+ text: JSON.stringify(details ? {
37455
+ error,
37456
+ message,
37457
+ details: inProductWords(details)
37458
+ } : {
37459
+ error,
37460
+ message
37461
+ })
37462
+ }],
37463
+ isError: true
37464
+ };
37301
37465
  }
37302
- function render$1(tree, spelled) {
37303
- if (tree.kind === "license") {
37304
- const id = spelled.get(tree.license) ?? tree.license;
37305
- if (tree.exception === null) return id;
37306
- return `${id} WITH ${spelled.get(tree.exception) ?? tree.exception}`;
37307
- }
37308
- return tree.operands.map((operand) => operand.kind === "license" ? render$1(operand, spelled) : `(${render$1(operand, spelled)})`).join(tree.kind === "and" ? " AND " : " OR ");
37466
+ /**
37467
+ * fetch rejects with a TypeError carrying a `cause` when the API cannot be
37468
+ * reached; a TypeError from our own code carries none and is a bug to surface.
37469
+ */
37470
+ function isNetworkFailure(error) {
37471
+ return error instanceof TypeError && "cause" in error;
37309
37472
  }
37310
- function unwrap(expression) {
37311
- return expression.startsWith("(") && expression.endsWith(")") && parseSpdxExpression(expression.slice(1, -1)) ? expression.slice(1, -1) : expression;
37473
+ /** What went wrong on the wire: undici's message is the constant "fetch failed", the cause says why. */
37474
+ function networkFailureDetail(error) {
37475
+ const cause = error.cause;
37476
+ const why = typeof cause?.code === "string" ? cause.code : typeof cause?.message === "string" ? cause.message : null;
37477
+ return why ? `${error.message} (${why})` : error.message;
37312
37478
  }
37313
- //#endregion
37314
- //#region ../../packages/types/dist/licenses/pypi-classifiers.js
37315
37479
  /**
37316
- * A licence family without its version or variant, by the name the inventory
37317
- * keeps for it (the classifier's last segment), with every id it can stand
37318
- * for. The PEP 639 list, plus the classifiers PyPI lists that name a licence
37319
- * with several published versions and none given (EFL, NPL, Zope).
37480
+ * The code a status implies when the API sent none. 400 is VALIDATION_ERROR,
37481
+ * the code the API itself sends, so a refusal by this server and one by the
37482
+ * API read the same.
37320
37483
  */
37321
- const AMBIGUOUS = {
37322
- "Academic Free License (AFL)": [
37323
- "AFL-1.1",
37324
- "AFL-1.2",
37325
- "AFL-2.0",
37326
- "AFL-2.1",
37327
- "AFL-3.0"
37328
- ],
37329
- "Apache Software License": [
37330
- "Apache-1.0",
37331
- "Apache-1.1",
37332
- "Apache-2.0"
37333
- ],
37334
- "Apple Public Source License": [
37335
- "APSL-1.0",
37336
- "APSL-1.1",
37337
- "APSL-1.2",
37338
- "APSL-2.0"
37339
- ],
37340
- "Artistic License": ["Artistic-1.0", "Artistic-2.0"],
37341
- "BSD License": [
37342
- "BSD-2-Clause",
37343
- "BSD-2-Clause-Patent",
37344
- "BSD-3-Clause"
37345
- ],
37346
- "GNU Affero General Public License v3": ["AGPL-3.0-only", "AGPL-3.0-or-later"],
37347
- "GNU Free Documentation License (FDL)": [
37348
- "GFDL-1.1-only",
37349
- "GFDL-1.1-or-later",
37350
- "GFDL-1.2-only",
37351
- "GFDL-1.2-or-later",
37352
- "GFDL-1.3-only",
37353
- "GFDL-1.3-or-later"
37354
- ],
37355
- "GNU General Public License (GPL)": [
37356
- "GPL-1.0-only",
37357
- "GPL-1.0-or-later",
37358
- "GPL-2.0-only",
37359
- "GPL-2.0-or-later",
37360
- "GPL-3.0-only",
37361
- "GPL-3.0-or-later"
37362
- ],
37363
- "GNU General Public License v2 (GPLv2)": ["GPL-2.0-only", "GPL-2.0-or-later"],
37364
- "GNU General Public License v3 (GPLv3)": ["GPL-3.0-only", "GPL-3.0-or-later"],
37365
- "GNU Lesser General Public License v2 (LGPLv2)": ["LGPL-2.0-only", "LGPL-2.1-only"],
37366
- "GNU Lesser General Public License v2 or later (LGPLv2+)": ["LGPL-2.0-or-later", "LGPL-2.1-or-later"],
37367
- "GNU Lesser General Public License v3 (LGPLv3)": ["LGPL-3.0-only", "LGPL-3.0-or-later"],
37368
- "GNU Library or Lesser General Public License (LGPL)": [
37369
- "LGPL-2.0-only",
37370
- "LGPL-2.0-or-later",
37371
- "LGPL-2.1-only",
37372
- "LGPL-2.1-or-later",
37373
- "LGPL-3.0-only",
37374
- "LGPL-3.0-or-later"
37375
- ],
37376
- "Eiffel Forum License (EFL)": ["EFL-1.0", "EFL-2.0"],
37377
- "Netscape Public License (NPL)": ["NPL-1.0", "NPL-1.1"],
37378
- "Zope Public License": [
37379
- "ZPL-1.1",
37380
- "ZPL-2.0",
37381
- "ZPL-2.1"
37382
- ],
37383
- "Public Domain": [],
37384
- "Free For Educational Use": [],
37385
- "Free For Home Use": [],
37386
- "Free for non-commercial use": [],
37387
- "Freely Distributable": [],
37388
- "Free To Use But Restricted": [],
37389
- Freeware: [],
37390
- "Other/Proprietary License": [],
37391
- "Repoze Public License": [],
37392
- "GUST Font License 1.0": [],
37393
- "GUST Font License 2006-09-30": []
37484
+ const CODE_BY_STATUS = {
37485
+ 400: "VALIDATION_ERROR",
37486
+ 401: "UNAUTHENTICATED",
37487
+ 403: "FORBIDDEN",
37488
+ 404: "NOT_FOUND",
37489
+ 409: "CONFLICT",
37490
+ 429: "RATE_LIMITED"
37394
37491
  };
37395
- /**
37396
- * The ids a licence string the inventory holds can stand for, when it is an
37397
- * ambiguous classifier's name; undefined for anything else.
37398
- */
37399
- function classifierCandidates(license) {
37400
- return Object.prototype.hasOwnProperty.call(AMBIGUOUS, license) ? AMBIGUOUS[license] : void 0;
37492
+ /** What the API said, in one phrase: the status, the code it sent (or the one its status implies), its message. */
37493
+ function apiFailureText(error) {
37494
+ return `${error.status} ${apiFailureCode(error)}${error.apiMessage ? `: ${error.apiMessage}` : ""}`;
37401
37495
  }
37402
- //#endregion
37403
- //#region ../../packages/types/dist/licenses/license-category.js
37404
- const operandText = (o) => o.exception === null ? o.license : `${o.license} WITH ${o.exception}`;
37405
- /**
37406
- * Canonical text of a tree: operands sorted, and parentheses only where they
37407
- * change the meaning (an OR inside an AND), so one decision always reads the
37408
- * same however it was written.
37409
- */
37410
- function canonicalText(node, insideAnd = false) {
37411
- if (node.kind === "license") return operandText(node);
37412
- const flat = (n) => n.kind === node.kind ? n.operands.flatMap(flat) : [n];
37413
- const joined = node.operands.flatMap(flat).map((o) => canonicalText(o, node.kind === "and")).sort().join(node.kind === "and" ? " AND " : " OR ");
37414
- return node.kind === "or" && insideAnd ? `(${joined})` : joined;
37496
+ /** The code the API sent, or the one its status implies: the code a model branches on. */
37497
+ function apiFailureCode(error) {
37498
+ return error.code ?? CODE_BY_STATUS[error.status] ?? "API_ERROR";
37499
+ }
37500
+ /** Whether a failure is the API's refusal or absence of a thing, as opposed to the API failing. */
37501
+ function isMissOrRefusal(error) {
37502
+ return error instanceof TaigaApiError && (error.status === 404 || error.status === 403);
37415
37503
  }
37416
37504
  /**
37417
- * The part of an expression that is outside the allowlist (PRO-2944): what a
37418
- * reviewer actually decides on. `Apache-2.0 AND LGPL-3.0-or-later` is outside
37419
- * only through `LGPL-3.0-or-later`; `GPL-2.0-only OR LGPL-2.1-only`, with
37420
- * neither allowed, through both choices. An AND keeps its sides that are not
37421
- * allowed, an OR none when any side is allowed and all of them otherwise, and
37422
- * an operand reads like the finding's (compared whole, `WITH` included). The
37423
- * text is canonical (operands sorted, runs of one operator flattened,
37424
- * parentheses only around an OR inside an AND), so one decision always reads
37425
- * the same and groups as one. Null
37426
- * when nothing reads outside, or the string is no expression: the caller then
37427
- * falls back to the whole licence.
37505
+ * Run a tool handler and turn a failure into a structured error. An API
37506
+ * refusal keeps the API's own code when it sent one and its message whole:
37507
+ * on a refused publish that names the section holding template residue,
37508
+ * which is what the model needs to fix the draft. A failed connection is
37509
+ * structured too, so every failure the model sees has the same shape.
37428
37510
  */
37429
- function outsideAllowlist(expression, allowlist) {
37430
- const tree = parseSpdxExpression(expression);
37431
- if (tree === null) return null;
37432
- const allowed = new Set(allowlist.map(currentSpelling));
37433
- const isAllowed = (node) => node.kind === "license" ? allowed.has(currentSpelling(operandText(node))) : node.kind === "and" ? node.operands.every(isAllowed) : node.operands.some(isAllowed);
37434
- const prune = (node) => {
37435
- if (node.kind === "license") {
37436
- if (node.exception === null && UNKNOWN_LICENSES.includes(node.license)) return null;
37437
- return isAllowed(node) ? null : node;
37511
+ async function runTool(handler) {
37512
+ try {
37513
+ return await handler();
37514
+ } catch (error) {
37515
+ if (error instanceof TaigaApiError) {
37516
+ const code = error.code ?? CODE_BY_STATUS[error.status] ?? "API_ERROR";
37517
+ const worded = inProductWording(error.apiMessage ?? `Taiga API answered ${error.status}.`);
37518
+ if (code === "PROVIDER_UNSUPPORTED") return toolError(code, `${worded} This forge does not do that in Taiga yet; retrying will not change it.`, {
37519
+ ...error.details,
37520
+ retryable: false
37521
+ });
37522
+ return toolError(code, error.status === 404 ? withNotFoundHint(worded) : [
37523
+ 502,
37524
+ 503,
37525
+ 504
37526
+ ].includes(error.status) ? `${withStop(worded)} This is usually temporary: a read may answer on a retry; after a write, check whether it took effect before repeating it.` : worded, error.details);
37438
37527
  }
37439
- if (node.kind === "or" && node.operands.some(isAllowed)) return null;
37440
- const kept = node.operands.map(prune).filter((n) => n !== null);
37441
- if (kept.length === 0) return null;
37442
- if (kept.length === 1) return kept[0];
37443
- const operands = kept.flatMap((n) => n.kind === node.kind ? n.operands : [n]);
37444
- return {
37445
- kind: node.kind,
37446
- operands
37447
- };
37528
+ if (isNetworkFailure(error)) return toolError("NETWORK_ERROR", `Could not reach the Taiga API: ${networkFailureDetail(error)}. Check TAIGA_API_URL.`);
37529
+ throw error;
37530
+ }
37531
+ }
37532
+ //#endregion
37533
+ //#region src/tools/remote.ts
37534
+ const SCP_LIKE = /^(?:[^@\s/]+@)?([^:\s/]+):([^\s]+)$/;
37535
+ function parseRemote(remote) {
37536
+ const trimmed = remote.trim();
37537
+ if (trimmed === "") return null;
37538
+ let host;
37539
+ let path;
37540
+ let scheme = "https";
37541
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)) {
37542
+ if (hasDotSegment(trimmed.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i, ""))) return null;
37543
+ let url;
37544
+ try {
37545
+ url = new URL(trimmed);
37546
+ } catch {
37547
+ return null;
37548
+ }
37549
+ const protocol = url.protocol.replace(/:$/, "").toLowerCase();
37550
+ if (protocol === "http" || protocol === "https") {
37551
+ scheme = protocol;
37552
+ host = url.port ? `${url.hostname}:${url.port}` : url.hostname;
37553
+ } else if (protocol === "ssh" || protocol === "git+ssh" || protocol === "git") host = url.hostname;
37554
+ else return null;
37555
+ path = url.pathname;
37556
+ } else {
37557
+ const match = SCP_LIKE.exec(trimmed);
37558
+ if (!match) return null;
37559
+ host = match[1];
37560
+ path = match[2];
37561
+ if (host.length < 2) return null;
37562
+ }
37563
+ host = host.toLowerCase();
37564
+ if (host === "") return null;
37565
+ const segments = path.replace(/\/+$/, "").replace(/\.git$/i, "").split("/").filter((segment) => segment !== "");
37566
+ if (segments.length !== 2) return null;
37567
+ if (hasDotSegment(path) || segments.some((segment) => segment.includes(":"))) return null;
37568
+ const origin = webOrigin(`${scheme}://${host}`);
37569
+ if (origin === null) return null;
37570
+ return {
37571
+ host: origin,
37572
+ repository: `${segments[0]}/${segments[1]}`
37448
37573
  };
37449
- const pruned = prune(tree);
37450
- return pruned === null ? null : canonicalText(pruned);
37574
+ }
37575
+ /** Whether any segment of the path is `.` or `..`, percent-encoded or not. */
37576
+ function hasDotSegment(path) {
37577
+ return path.split("/").some((segment) => {
37578
+ let decoded = segment;
37579
+ try {
37580
+ decoded = decodeURIComponent(segment);
37581
+ } catch {}
37582
+ return decoded === "." || decoded === "..";
37583
+ });
37584
+ }
37585
+ function webOrigin(url) {
37586
+ try {
37587
+ const origin = new URL(url).origin;
37588
+ return origin === "null" ? null : origin;
37589
+ } catch {
37590
+ return null;
37591
+ }
37451
37592
  }
37452
37593
  new Map(SPDX_LICENSES.map(([id, name]) => [id.toLowerCase(), name]));
37453
37594
  new Map(SPDX_EXCEPTIONS.map(([id, name]) => [id.toLowerCase(), name]));