@taiga-ai/mcp-server 0.37.0-dev.1148 → 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 +1197 -1197
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31290,781 +31290,13 @@ const SIGNAL_KINDS = [
31290
31290
  */
31291
31291
  const DEPLOYMENT_NOTES_MAX_LENGTH = 4e3;
31292
31292
  //#endregion
31293
- //#region src/compat.ts
31294
- /**
31295
- * Why this server should not serve the API it reached, or null when it may
31296
- * (PRO-2844). The server is published to npm and the API deploys on its own
31297
- * schedule, so a newer server can meet an older API. It would not fail
31298
- * loudly: some tools read a 404 as a state of the world (a run not found
31299
- * reads as deleted) and fields they explain would simply be missing. So it
31300
- * refuses to start, and says what to do.
31301
- */
31302
- function apiLevelProblem(introspection, apiUrl, required = 9, version = SERVER_VERSION) {
31303
- const offered = introspection.mcpApiLevel ?? 0;
31304
- if (offered >= required) return null;
31305
- 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.`;
31306
- }
31307
- //#endregion
31308
- //#region src/tools/toolsets.ts
31309
- /**
31310
- * Toolsets (PRO-2846, PRO-2838): the tools an AI tool sees, grouped by what the person does.
31311
- *
31312
- * A role decides what a key MAY do (the API enforces it, and tools a key cannot use are never registered); a toolset
31313
- * decides what it SEES. A toolset never adds a tool the key's capabilities do not allow. Every toolset is on unless
31314
- * the key says otherwise: the person chooses them for the key in Taiga's settings, and the server reads them at
31315
- * start. Toolsets alone barely changed what the task test cost in Claude Code, which loads tool details on demand,
31316
- * so the default is everything rather than a short list someone has to know how to widen. The tool list stays the
31317
- * same for every connection of one server (MCP 2026-07-28), so the set is fixed at start, not mid-session.
31318
- */
31319
- const TOOLSETS = MCP_TOOLSETS;
31320
- /** What each toolset is for, as whoami says it. */
31321
- const TOOLSET_PURPOSE = {
31322
- core: "where products, initiatives, runs, policies and findings stand",
31323
- operate: "moving work: queue, plans, runs, fixes, Action Required",
31324
- setup: "creating and configuring factories, products, repositories, environments and autonomy",
31325
- observe: "deployments, monitoring, delivery metrics, the package inventory and the sweeps that read it",
31326
- documents: "writing documents and knowledge, and regenerating product documents"
31327
- };
31328
- /** Every tool's toolset. A tool missing here fails at registration, so none can be added without a home. */
31329
- const TOOLSET_OF = {
31330
- taiga_list_products: "core",
31331
- taiga_get_product_context: "core",
31332
- taiga_get_product: "core",
31333
- taiga_list_factories: "core",
31334
- taiga_list_initiatives: "core",
31335
- taiga_get_initiative: "core",
31336
- taiga_get_plan: "core",
31337
- taiga_list_runs: "core",
31338
- taiga_get_run: "core",
31339
- taiga_get_line: "core",
31340
- taiga_list_action_required: "core",
31341
- taiga_get_policy_standing: "core",
31342
- taiga_list_findings: "core",
31343
- taiga_get_finding: "core",
31344
- taiga_get_organization_document: "core",
31345
- taiga_get_design_tokens: "core",
31346
- taiga_get_design_token_sync: "core",
31347
- taiga_get_product_document: "core",
31348
- taiga_wait: "core",
31349
- taiga_queue_initiative: "operate",
31350
- taiga_move_initiative: "operate",
31351
- taiga_review_plan: "operate",
31352
- taiga_plan_again: "operate",
31353
- taiga_resume_initiative: "operate",
31354
- taiga_stop_run: "operate",
31355
- taiga_request_changes: "operate",
31356
- taiga_request_initiatives: "operate",
31357
- taiga_fix_finding: "operate",
31358
- taiga_fix_policy_violation: "operate",
31359
- taiga_ignore_finding: "operate",
31360
- taiga_allow_license: "operate",
31361
- taiga_resolve_action: "operate",
31362
- taiga_create_factory: "setup",
31363
- taiga_rename_factory: "setup",
31364
- taiga_create_product: "setup",
31365
- taiga_update_product: "setup",
31366
- taiga_move_product: "setup",
31367
- taiga_preview_product_move: "setup",
31368
- taiga_link_repository: "setup",
31369
- taiga_unlink_repository: "setup",
31370
- taiga_list_linkable_repositories: "setup",
31371
- taiga_list_product_repositories: "setup",
31372
- taiga_list_repository_branches: "setup",
31373
- taiga_set_repository_branch: "setup",
31374
- taiga_start_import: "setup",
31375
- taiga_finish_discovery: "setup",
31376
- taiga_reopen_discovery: "setup",
31377
- taiga_list_setup_tasks: "setup",
31378
- taiga_get_job: "setup",
31379
- taiga_set_auto_build: "setup",
31380
- taiga_set_auto_merge: "setup",
31381
- taiga_set_product_autonomy: "setup",
31382
- taiga_pause_line: "setup",
31383
- taiga_create_environment: "setup",
31384
- taiga_update_environment: "setup",
31385
- taiga_ship_notices: "setup",
31386
- taiga_allow_license_package: "setup",
31387
- taiga_replace_license_package: "setup",
31388
- taiga_get_deployments: "observe",
31389
- taiga_get_monitoring: "observe",
31390
- taiga_get_delivery_metrics: "observe",
31391
- taiga_list_packages: "observe",
31392
- taiga_start_sweep: "observe",
31393
- taiga_list_licenses: "observe",
31394
- taiga_change_license: "setup",
31395
- taiga_get_model_connection: "setup",
31396
- taiga_set_model_connection: "setup",
31397
- taiga_remove_model_connection: "setup",
31398
- taiga_get_sbom: "observe",
31399
- taiga_get_notices: "observe",
31400
- taiga_get_factory_document: "documents",
31401
- taiga_update_organization_document: "documents",
31402
- taiga_publish_organization_document: "documents",
31403
- taiga_update_design_tokens: "documents",
31404
- taiga_sync_design_tokens: "documents",
31405
- taiga_update_factory_document: "documents",
31406
- taiga_publish_factory_document: "documents",
31407
- taiga_update_product_document: "documents",
31408
- taiga_publish_product_document: "documents",
31409
- taiga_mark_product_document_reviewed: "documents",
31410
- taiga_generate_product_documents: "documents",
31411
- taiga_regenerate_product_document: "documents",
31412
- taiga_stop_generating_documents: "documents",
31413
- taiga_refresh_reality_documents: "documents",
31414
- taiga_list_knowledge: "documents",
31415
- taiga_get_knowledge: "documents",
31416
- taiga_add_knowledge: "documents",
31417
- taiga_delete_knowledge: "documents",
31418
- taiga_retry_knowledge: "documents"
31419
- };
31420
- /**
31421
- * What steers agents leaves with them: knowledge, a factory's instructions
31422
- * and the design tokens, as the app hides those pages by the same rule.
31423
- *
31424
- * Deliver & Operate's tools (PRO-3834): initiatives, plans, runs and the line, fixes, environments, deployments,
31425
- * monitoring and delivery metrics. An organization whose plan refuses delivery work does not see them, as its web app
31426
- * shows none of their views; the API says which (`deliveryIncluded` at introspection), so the plan, not the key,
31427
- * decides. Fixing a finding plans and builds, so it goes with them.
31428
- */
31429
- const DELIVERY_TOOLS = /* @__PURE__ */ new Set([
31430
- "taiga_list_initiatives",
31431
- "taiga_get_initiative",
31432
- "taiga_get_plan",
31433
- "taiga_list_runs",
31434
- "taiga_get_run",
31435
- "taiga_get_line",
31436
- "taiga_queue_initiative",
31437
- "taiga_move_initiative",
31438
- "taiga_review_plan",
31439
- "taiga_plan_again",
31440
- "taiga_resume_initiative",
31441
- "taiga_stop_run",
31442
- "taiga_request_changes",
31443
- "taiga_request_initiatives",
31444
- "taiga_fix_finding",
31445
- "taiga_fix_policy_violation",
31446
- "taiga_replace_license_package",
31447
- "taiga_ship_notices",
31448
- "taiga_set_auto_build",
31449
- "taiga_set_auto_merge",
31450
- "taiga_pause_line",
31451
- "taiga_create_environment",
31452
- "taiga_update_environment",
31453
- "taiga_get_deployments",
31454
- "taiga_get_monitoring",
31455
- "taiga_get_delivery_metrics",
31456
- "taiga_sync_design_tokens",
31457
- "taiga_get_design_tokens",
31458
- "taiga_get_design_token_sync",
31459
- "taiga_update_design_tokens",
31460
- "taiga_get_factory_document",
31461
- "taiga_update_factory_document",
31462
- "taiga_publish_factory_document",
31463
- "taiga_list_knowledge",
31464
- "taiga_get_knowledge",
31465
- "taiga_add_knowledge",
31466
- "taiga_delete_knowledge",
31467
- "taiga_retry_knowledge"
31468
- ]);
31469
- /**
31470
- * TAIGA_TOOLSETS as written: comma-separated names, or "all"; a name it does not know is said, not ignored, and so
31471
- * is a value that names none.
31472
- */
31473
- function parseToolsets(raw) {
31474
- const names = raw.split(",").map((name) => name.trim().toLowerCase()).filter(Boolean);
31475
- const unknown = names.filter((name) => name !== "all" && !TOOLSETS.includes(name));
31476
- 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.` };
31477
- return { toolsets: names.includes("all") ? TOOLSETS : [...new Set(names)] };
31478
- }
31479
- /**
31480
- * The toolsets a server turns on: TAIGA_TOOLSETS when the server's config names some, else the ones the key names,
31481
- * else every one. A name the server does not know (a key set by a newer Taiga) is passed over; a key that names
31482
- * none this server knows sees every one, rather than starting with no tools.
31483
- */
31484
- function activeToolsets(fromKey, fromConfig) {
31485
- const named = fromConfig ?? fromKey?.filter((name) => TOOLSETS.includes(name));
31486
- if (!named || named.length === 0) return [...TOOLSETS];
31487
- return TOOLSETS.filter((toolset) => named.includes(toolset));
31488
- }
31489
- //#endregion
31490
- //#region src/config.ts
31491
- /**
31492
- * The one place the MCP server reads its environment (PRO-2511), parsed once
31493
- * at startup.
31494
- */
31495
- const DEFAULT_API_URL = "https://api.eu.tai.ga";
31496
- const envSchema = object({
31497
- TAIGA_API_KEY: string$2().optional(),
31498
- TAIGA_API_URL: string$2().optional(),
31499
- TAIGA_TOOLSETS: string$2().optional()
31500
- });
31501
- /** Hosts a developer runs the API on; the only ones plain http is accepted for. */
31502
- const LOCAL_HOSTS = /* @__PURE__ */ new Set([
31503
- "localhost",
31504
- "127.0.0.1",
31505
- "[::1]"
31506
- ]);
31293
+ //#region ../../packages/types/dist/licenses/spdx-license-list.js
31507
31294
  /**
31508
- * Read the environment (PRO-2844). The key carries its owner's reach, so it
31509
- * goes only to an https API (http for a local one). A pre-release build
31510
- * (`-dev.N`, `-rc.N`) is Taiga's own dev or staging channel, and defaulting it
31511
- * to production sent `npx @taiga-ai/mcp-server@staging` to the production API
31512
- * with a staging key: it must name its API. A released version defaults to
31513
- * production.
31514
- */
31515
- function readConfig(version = SERVER_VERSION) {
31516
- const env = envSchema.parse(process.env);
31517
- 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." };
31518
- const prerelease = version.includes("-");
31519
- 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}.` };
31520
- const apiUrl = (env.TAIGA_API_URL || DEFAULT_API_URL).replace(/\/+$/, "");
31521
- let url;
31522
- try {
31523
- url = new URL(apiUrl);
31524
- } catch {
31525
- return { problem: `TAIGA_API_URL is not a URL: ${apiUrl}` };
31526
- }
31527
- if (url.search || url.hash) return { problem: `TAIGA_API_URL must not carry a query or fragment: ${apiUrl}` };
31528
- 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}` };
31529
- if (env.TAIGA_TOOLSETS?.trim()) {
31530
- const parsed = parseToolsets(env.TAIGA_TOOLSETS);
31531
- if ("problem" in parsed) return { problem: parsed.problem };
31532
- return { config: {
31533
- apiKey: env.TAIGA_API_KEY,
31534
- apiUrl,
31535
- toolsets: parsed.toolsets
31536
- } };
31537
- }
31538
- return { config: {
31539
- apiKey: env.TAIGA_API_KEY,
31540
- apiUrl
31541
- } };
31542
- }
31543
- //#endregion
31544
- //#region src/tools/annotations.ts
31545
- /**
31546
- * Tool annotations shared by the tools. Hints for the client, not a
31547
- * control: the API enforces what a key may do. A client that asks the
31548
- * person before a destructive call reads destructiveHint; the server-side
31549
- * approval gate (PRO-548) is separate work.
31550
- */
31551
- const READ_ONLY = {
31552
- readOnlyHint: true,
31553
- destructiveHint: false,
31554
- idempotentHint: true,
31555
- openWorldHint: false
31556
- };
31557
- /** A write that adds or edits a row and starts nothing: a created initiative, a moved one. */
31558
- const WRITE = {
31559
- readOnlyHint: false,
31560
- destructiveHint: false,
31561
- idempotentHint: false,
31562
- openWorldHint: false
31563
- };
31564
- /**
31565
- * A write that starts or stops paid work, or opens the door to it: queueing
31566
- * an initiative, approving a plan, resuming or stopping a run. Each starts
31567
- * an agent that spends tokens and opens pull requests, or halts one mid-way.
31568
- */
31569
- const OPERATE = {
31570
- readOnlyHint: false,
31571
- destructiveHint: true,
31572
- idempotentHint: false,
31573
- openWorldHint: false
31574
- };
31575
- /**
31576
- * An OPERATE write that sets a value rather than adding one: the same call
31577
- * twice leaves things as one call does (a review gate set, a line paused).
31578
- */
31579
- const OPERATE_SETTING = {
31580
- ...OPERATE,
31581
- idempotentHint: true
31582
- };
31583
- //#endregion
31584
- //#region src/tools/inputs.ts
31585
- /** The inputs several tools share, so a product or a page is named the same way everywhere. */
31586
- /**
31587
- * An ID input whose refusal says where the ID comes from. The client shows the
31588
- * schema's message, not the description, when a call fails validation, and
31589
- * "Invalid UUID" alone sends a model that passed a name to guess again.
31590
- */
31591
- function idInput(what, from, said = from) {
31592
- 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}`);
31593
- }
31594
- 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");
31595
- /** The page inputs every list tool takes; `nextCursor` of one page is the `cursor` of the next. */
31596
- const pagination = {
31597
- limit: number$1().int().min(1).max(100).optional().describe("Max results (default 25)"),
31598
- cursor: string$2().max(256).optional().describe("The previous page's nextCursor; omit for the first page")
31599
- };
31600
- 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");
31601
- 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://");
31602
- //#endregion
31603
- //#region src/tools/catalogue.ts
31604
- /**
31605
- * What exists, from the one place that knows: the shared types package.
31606
- *
31607
- * Tool descriptions are what the model reads to decide what to call, and a
31608
- * description that names a document type the catalogue lacks sends it down a
31609
- * dead end (the walk-through that led here found `policy_acceptable_use` and
31610
- * `policy_ip` named in a description and nowhere else). Every list of types,
31611
- * origins and statuses a tool shows is derived from these constants, and a
31612
- * test holds the descriptions to them.
31613
- */
31614
- /**
31615
- * Display names for every product document type. The reviewable nine come
31616
- * from the shared map the web uses; the three the web never asks a person to
31617
- * review are named here, and the record type keeps the two sets complete.
31618
- */
31619
- const PRODUCT_DOCUMENT_NAMES = {
31620
- ...PRODUCT_DOCUMENT_DISPLAY_NAMES,
31621
- ui_direction: "Look & Feel",
31622
- codebase_snapshot: "Codebase Snapshot",
31623
- product_instructions: "Product Instructions"
31624
- };
31625
- function productDocumentName(type) {
31626
- return PRODUCT_DOCUMENT_NAMES[type] ?? type;
31627
- }
31628
- /**
31629
- * The two document timelines of a product (ADR-017), in the words the tools
31630
- * and the server instructions use. One place, so the list tool, the read
31631
- * tool and the instructions cannot explain them three different ways.
31632
- */
31633
- const ORIGIN_MEANING = {
31634
- plan: "plan: the discovery documents, what is meant to be built.",
31635
- 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."
31636
- };
31637
- /**
31638
- * Which timeline is a product's own (the API's documentOriginForSettings):
31639
- * an imported product has no plan chain by design, so its documents are on
31640
- * the reality side; everything else starts on the plan side. Derived from the
31641
- * same settings key the API reads, so the two cannot disagree.
31642
- */
31643
- function isImportedProduct(product) {
31644
- return product?.settings?.projectType === "brownfield";
31645
- }
31646
- /**
31647
- * The document types no derivation ever writes: a person records or writes
31648
- * them, so they live on the plan side of every product, imported or not.
31649
- */
31650
- const PLAN_ONLY_DOCUMENT_TYPES = PRODUCT_DOCUMENT_TYPES.filter((type) => !REALITY_DERIVED_DOCUMENT_TYPES.includes(type));
31651
- /**
31652
- * The timeline a read should default to: the plan side for a type only a
31653
- * person writes, else the product's own side (reality for an imported
31654
- * product, plan for every other).
31655
- */
31656
- function defaultOriginFor(product, type) {
31657
- if (type !== void 0 && PLAN_ONLY_DOCUMENT_TYPES.includes(type)) return "plan";
31658
- return isImportedProduct(product) ? "reality" : "plan";
31659
- }
31660
- /**
31661
- * Where an imported product's import got to (`settings.importStatus`, written
31662
- * by the API: pending, analyzing, complete, cancelled, failed). Unknown values
31663
- * read as "not known", never as a promise.
31664
- */
31665
- function importStatusOf(product) {
31666
- const status = product?.settings?.importStatus;
31667
- return typeof status === "string" ? status : null;
31668
- }
31669
- /** Why a side of the timeline is empty, for a list or a miss that shows one. */
31670
- function emptyOriginNote(origin, product) {
31671
- const imported = isImportedProduct(product);
31672
- 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.";
31673
- 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.";
31674
- switch (importStatusOf(product)) {
31675
- 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.";
31676
- case "analyzing":
31677
- case "generating_docs": return "No reality documents yet: the import is running and will derive them from the code.";
31678
- case "cancelled": return "No reality documents: the import was cancelled before it derived any. taiga_start_import runs it again.";
31679
- case "failed": return "No reality documents: the import failed before it derived any. taiga_start_import runs it again.";
31680
- default: return "No reality documents: the import derives them from the code, and none have been published.";
31681
- }
31682
- }
31683
- /**
31684
- * What finishing does, in every next step that ends at it (PRO-2857): it
31685
- * starts paid planning, so a client must ask the person before calling it.
31686
- */
31687
- const FINISH_DISCOVERY = "taiga_finish_discovery opens the product and starts planning its first initiatives (paid agent work: ask the person first).";
31688
- /**
31689
- * What a product in setup waits for, as the next call to make. Nothing on a
31690
- * draft product says it otherwise: discoveryStep names the step and
31691
- * importStatus the import, and the way on from each lives in tool
31692
- * descriptions an agent reads only when it already knows which. Null once the
31693
- * product is active.
31694
- */
31695
- function setupNextStep(product) {
31696
- if (product?.status !== "draft") return null;
31697
- if (isImportedProduct(product)) switch (importStatusOf(product)) {
31698
- case "analyzing":
31699
- 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}`;
31700
- case "complete": return "The import is done: review the reality documents (taiga_get_product_document without type), then " + FINISH_DISCOVERY;
31701
- case "failed":
31702
- case "cancelled": return "The last import did not finish: taiga_start_import runs it again.";
31703
- 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.";
31704
- }
31705
- if (product.discoveryStep === void 0) return null;
31706
- switch (product.discoveryStep) {
31707
- 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}`;
31708
- 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}`;
31709
- }
31710
- }
31711
- //#endregion
31712
- //#region src/tools/hints.ts
31713
- /**
31714
- * The next step after the API answers 404. The API's own word is bare
31715
- * ("Initiative not found", "Repository link not found"), and an agent that
31716
- * hears only that guesses another ID, or a name. Each ID a tool takes names
31717
- * the tool that lists the right ones; the tool's arguments say which apply.
31718
- */
31719
- const ITEM_ID_HINT = "taiga_list_initiatives lists a product's initiatives with their IDs; a run or plan ID is not one.";
31720
- const BY_ARGUMENT = {
31721
- initiativeId: ITEM_ID_HINT,
31722
- runId: "taiga_list_runs lists the runs, of one product or of every product the key can see.",
31723
- planId: "taiga_get_plan gives the initiative's active plan and its ID.",
31724
- linkId: "taiga_list_product_repositories lists the product's repository links; a linkable repository id is not a link ID.",
31725
- replacesLinkId: "taiga_list_product_repositories lists the product's repository links.",
31726
- linkableRepositoryId: "taiga_list_linkable_repositories lists the repositories the GitHub, GitLab and Azure DevOps connections reach, with their ids.",
31727
- installationId: "taiga_list_linkable_repositories lists the connected GitHub accounts, GitLab and Azure DevOps connections.",
31728
- jobId: "A job ID is what the tool that started the job returned (taiga_request_initiatives, taiga_start_import).",
31729
- factoryId: "taiga_list_factories lists the factories the key can see.",
31730
- findingId: "taiga_list_findings lists a product's findings.",
31731
- violationId: "taiga_get_policy_standing lists a product's policy violations.",
31732
- environmentId: "taiga_get_deployments lists the product's environments with their IDs; a product ID is not one.",
31733
- knowledgeId: "taiga_list_knowledge lists the knowledge files.",
31734
- productId: "taiga_list_products lists the products the key can see; a name is not an ID (taiga_get_product takes a slug)."
31735
- };
31736
- /**
31737
- * A licence a product does not hold, as against a product the key cannot see
31738
- * (PRO-3879). Any other 404 (the routes do not exist where the licenses
31739
- * feature is off) blames neither.
31740
- */
31741
- 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;
31742
- /** Where an argument means something else on one tool, or the tool's 404 needs its own word. */
31743
- const BY_TOOL = {
31744
- 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."),
31745
- 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."),
31746
- taiga_resolve_action: () => "taiga_list_action_required lists the items with their IDs.",
31747
- 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.",
31748
- 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.",
31749
- 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
31750
- };
31751
- /**
31752
- * What the API calls the thing each ID names, as its 404 says it ("Environment
31753
- * not found"). A tool given a right product and a wrong environment hinted
31754
- * at both, and the product's hint told the agent its correct product ID was
31755
- * the mistake (PRO-2800): a 404 that names its thing gets that ID's hint only.
31756
- */
31757
- const MISSING_THING = {
31758
- initiativeId: /backlog item|initiative/i,
31759
- runId: /\b(build )?run\b/i,
31760
- planId: /\bplan\b/i,
31761
- linkId: /repository link|\blink\b|repository/i,
31762
- replacesLinkId: /repository link|\blink\b/i,
31763
- linkableRepositoryId: /github repository|gitlab project|azure devops (repository|resource|connection)/i,
31764
- installationId: /installation|account|gitlab connection|azure devops connection/i,
31765
- jobId: /\bjob\b/i,
31766
- factoryId: /factory|team/i,
31767
- findingId: /finding/i,
31768
- violationId: /violation/i,
31769
- environmentId: /environment/i,
31770
- knowledgeId: /knowledge|document/i,
31771
- productId: /\b(product|project) not found/i
31772
- };
31773
- /** The hint for a 404 from one tool call: the tool's own, else the one for the ID the API says is missing. */
31774
- function notFoundHint(tool, args) {
31775
- if (BY_TOOL[tool]) return BY_TOOL[tool];
31776
- if (typeof args !== "object" || args === null) return void 0;
31777
- const given = Object.keys(args).filter((key) => args[key] != null && BY_ARGUMENT[key]);
31778
- given.sort((a, b) => Number(a === "productId") - Number(b === "productId"));
31779
- if (given.length === 0) return void 0;
31780
- return (said) => {
31781
- const named = given.filter((key) => MISSING_THING[key]?.test(said));
31782
- return (named.length > 0 ? named : given).map((key) => BY_ARGUMENT[key]).join(" ");
31783
- };
31784
- }
31785
- /** The hint of the tool call in progress, read by runTool when the API answers 404. */
31786
- const notFoundHints = new AsyncLocalStorage();
31787
- /** The API's 404 message with the hint of the call in progress, if it has one. */
31788
- function withNotFoundHint(said) {
31789
- const hint = notFoundHints.getStore()?.(said);
31790
- return hint ? `${withStop(said)} ${hint}` : said;
31791
- }
31792
- /** A sentence ends in a stop before the next one is added to it. */
31793
- function withStop(text) {
31794
- return /[.!?]$/.test(text.trimEnd()) ? text.trimEnd() : `${text.trimEnd()}.`;
31795
- }
31796
- /** Where an ID argument comes from, for a call refused before it reached the API (PRO-2841). */
31797
- function idSource(argument) {
31798
- return BY_ARGUMENT[argument];
31799
- }
31800
- /** The verbs and joining words of tool names: what a tool does, not what it is about. */
31801
- 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(" "));
31802
- /** What a tool name is about, singular: taiga_list_initiatives is about an initiative. */
31803
- const nouns = (tool) => new Set(tool.replace(/^taiga_/, "").split("_").filter((word) => !VERBS.has(word)).map((word) => word.replace(/s$/, "")));
31804
- /**
31805
- * The tool, of those that take `argument`, that is about the same thing as the
31806
- * one that refused it: taiga_get_organization_document refusing productId points at
31807
- * taiga_get_product_document, not at one of the thirty other tools that take a
31808
- * product. Only a tool sharing a noun counts, and a read is never pointed at a
31809
- * write; with none, there is no closest tool and the caller says to leave the
31810
- * argument out.
31811
- */
31812
- function closestToolTaking(argument, refusedBy, inputs, isRead) {
31813
- const mine = nouns(refusedBy);
31814
- const readsOnly = isRead(refusedBy);
31815
- let best;
31816
- for (const [tool, keys] of inputs) {
31817
- if (tool === refusedBy || !keys.includes(argument) || readsOnly && !isRead(tool)) continue;
31818
- const shared = [...nouns(tool)].filter((word) => mine.has(word)).length;
31819
- if (shared === 0) continue;
31820
- if (!best || shared > best.shared || shared === best.shared && tool.length < best.tool.length) best = {
31821
- tool,
31822
- shared
31823
- };
31824
- }
31825
- return best?.tool;
31826
- }
31827
- /** One of the tool's own arguments spelled another way (product_id, initiativeID), if the refused key is one. */
31828
- function ownArgumentLike(key, own) {
31829
- const plain = (name) => name.replace(/[_-]/g, "").toLowerCase();
31830
- return own.find((name) => plain(name) === plain(key));
31831
- }
31832
- //#endregion
31833
- //#region src/tools/errors.ts
31834
- /**
31835
- * The API's names for the two IDs an agent chains most, in the product's
31836
- * words the tools take them in (PRO-2800): a row says initiativeId and runId,
31837
- * as taiga_get_initiative and taiga_get_run ask for them, rather than the
31838
- * storage names backlogItemId and buildRunId.
31839
- */
31840
- const PRODUCT_WORDS = {
31841
- backlogItemId: "initiativeId",
31842
- buildRunId: "runId",
31843
- productRepositoryId: "linkId",
31844
- latestBuild: "latestRun"
31845
- };
31846
- /**
31847
- * Maps whose keys are content, not API fields: a document's sections are keyed
31848
- * by ids a person or agent chose (a section may be called backlogItemId), and
31849
- * metadata and settings hold whatever their writer put there. Copied as they
31850
- * are, keys and all.
31851
- */
31852
- const OPAQUE_MAPS = /* @__PURE__ */ new Set([
31853
- "sections",
31854
- "metadata",
31855
- "settings"
31856
- ]);
31857
- /** A copy of an API value with its keys in the product's words, values untouched. */
31858
- /**
31859
- * Run actions only the web offers (PRO-2800): start_over was listed beside what an agent can call, on runs and on
31860
- * every initiative's latest run, while the descriptions said it was web only. Split apart wherever actions appear.
31861
- */
31862
- const WEB_ONLY_ACTIONS = /* @__PURE__ */ new Set(["start_over"]);
31863
- function inProductWords(value) {
31864
- if (Array.isArray(value)) return value.map(inProductWords);
31865
- if (value === null || typeof value !== "object") return value;
31866
- const out = {};
31867
- const actions = value["actions"];
31868
- if (Array.isArray(actions) && actions.some((action) => WEB_ONLY_ACTIONS.has(String(action)))) {
31869
- const webOnly = actions.filter((action) => WEB_ONLY_ACTIONS.has(String(action)));
31870
- const said = value["webOnlyActions"];
31871
- value = {
31872
- ...value,
31873
- actions: actions.filter((action) => !WEB_ONLY_ACTIONS.has(String(action))),
31874
- webOnlyActions: [.../* @__PURE__ */ new Set([...Array.isArray(said) ? said : [], ...webOnly])]
31875
- };
31876
- }
31877
- for (const [key, inner] of Object.entries(value)) Object.defineProperty(out, PRODUCT_WORDS[key] ?? key, {
31878
- value: OPAQUE_MAPS.has(key) ? inner : inProductWords(inner),
31879
- enumerable: true,
31880
- writable: true,
31881
- configurable: true
31882
- });
31883
- return out;
31884
- }
31885
- /** The API's 404 sentence in the product's words: "Backlog item not found" is an initiative not found. */
31886
- function inProductWording(said) {
31887
- 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.");
31888
- }
31889
- /**
31890
- * A float without its binary noise: six significant digits. Delivery metrics
31891
- * came as `deploysPerWeek: 6.766666666666667`, sixteen digits nobody reads
31892
- * (PRO-2847). Significant digits rather than fixed decimals: an EPSS score of
31893
- * 0.00043, a 0.4% failure rate or 99.995% uptime keep what they say, where
31894
- * two decimals read them as 0, 0 and 100.
31895
- */
31896
- const roundFloats = (_key, value) => typeof value === "number" && Number.isFinite(value) && !Number.isInteger(value) ? Number(value.toPrecision(6)) : value;
31897
- /**
31898
- * A result as the model reads it: compact JSON, in the product's words, its
31899
- * floats rounded. Indentation was a fifth of a list's characters (PRO-2847),
31900
- * paid on every call; the model reads JSON without it.
31901
- */
31902
- function serializeResult(value) {
31903
- return JSON.stringify(inProductWords(value), roundFloats);
31904
- }
31905
- /** A successful tool result: one JSON text block the model reads. */
31906
- function toolResult(value) {
31907
- return { content: [{
31908
- type: "text",
31909
- text: serializeResult(value)
31910
- }] };
31911
- }
31912
- /**
31913
- * A failed tool result the model can branch on: a stable code and a message
31914
- * that says what to do next. Returned, not thrown, so the client sees
31915
- * `isError` rather than a protocol error.
31916
- */
31917
- function toolError(error, message, details) {
31918
- return {
31919
- content: [{
31920
- type: "text",
31921
- text: JSON.stringify(details ? {
31922
- error,
31923
- message,
31924
- details: inProductWords(details)
31925
- } : {
31926
- error,
31927
- message
31928
- })
31929
- }],
31930
- isError: true
31931
- };
31932
- }
31933
- /**
31934
- * fetch rejects with a TypeError carrying a `cause` when the API cannot be
31935
- * reached; a TypeError from our own code carries none and is a bug to surface.
31936
- */
31937
- function isNetworkFailure(error) {
31938
- return error instanceof TypeError && "cause" in error;
31939
- }
31940
- /** What went wrong on the wire: undici's message is the constant "fetch failed", the cause says why. */
31941
- function networkFailureDetail(error) {
31942
- const cause = error.cause;
31943
- const why = typeof cause?.code === "string" ? cause.code : typeof cause?.message === "string" ? cause.message : null;
31944
- return why ? `${error.message} (${why})` : error.message;
31945
- }
31946
- /**
31947
- * The code a status implies when the API sent none. 400 is VALIDATION_ERROR,
31948
- * the code the API itself sends, so a refusal by this server and one by the
31949
- * API read the same.
31950
- */
31951
- const CODE_BY_STATUS = {
31952
- 400: "VALIDATION_ERROR",
31953
- 401: "UNAUTHENTICATED",
31954
- 403: "FORBIDDEN",
31955
- 404: "NOT_FOUND",
31956
- 409: "CONFLICT",
31957
- 429: "RATE_LIMITED"
31958
- };
31959
- /** What the API said, in one phrase: the status, the code it sent (or the one its status implies), its message. */
31960
- function apiFailureText(error) {
31961
- return `${error.status} ${apiFailureCode(error)}${error.apiMessage ? `: ${error.apiMessage}` : ""}`;
31962
- }
31963
- /** The code the API sent, or the one its status implies: the code a model branches on. */
31964
- function apiFailureCode(error) {
31965
- return error.code ?? CODE_BY_STATUS[error.status] ?? "API_ERROR";
31966
- }
31967
- /** Whether a failure is the API's refusal or absence of a thing, as opposed to the API failing. */
31968
- function isMissOrRefusal(error) {
31969
- return error instanceof TaigaApiError && (error.status === 404 || error.status === 403);
31970
- }
31971
- /**
31972
- * Run a tool handler and turn a failure into a structured error. An API
31973
- * refusal keeps the API's own code when it sent one and its message whole:
31974
- * on a refused publish that names the section holding template residue,
31975
- * which is what the model needs to fix the draft. A failed connection is
31976
- * structured too, so every failure the model sees has the same shape.
31977
- */
31978
- async function runTool(handler) {
31979
- try {
31980
- return await handler();
31981
- } catch (error) {
31982
- if (error instanceof TaigaApiError) {
31983
- const code = error.code ?? CODE_BY_STATUS[error.status] ?? "API_ERROR";
31984
- const worded = inProductWording(error.apiMessage ?? `Taiga API answered ${error.status}.`);
31985
- if (code === "PROVIDER_UNSUPPORTED") return toolError(code, `${worded} This forge does not do that in Taiga yet; retrying will not change it.`, {
31986
- ...error.details,
31987
- retryable: false
31988
- });
31989
- return toolError(code, error.status === 404 ? withNotFoundHint(worded) : [
31990
- 502,
31991
- 503,
31992
- 504
31993
- ].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);
31994
- }
31995
- if (isNetworkFailure(error)) return toolError("NETWORK_ERROR", `Could not reach the Taiga API: ${networkFailureDetail(error)}. Check TAIGA_API_URL.`);
31996
- throw error;
31997
- }
31998
- }
31999
- //#endregion
32000
- //#region src/tools/remote.ts
32001
- const SCP_LIKE = /^(?:[^@\s/]+@)?([^:\s/]+):([^\s]+)$/;
32002
- function parseRemote(remote) {
32003
- const trimmed = remote.trim();
32004
- if (trimmed === "") return null;
32005
- let host;
32006
- let path;
32007
- let scheme = "https";
32008
- if (/^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed)) {
32009
- if (hasDotSegment(trimmed.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i, ""))) return null;
32010
- let url;
32011
- try {
32012
- url = new URL(trimmed);
32013
- } catch {
32014
- return null;
32015
- }
32016
- const protocol = url.protocol.replace(/:$/, "").toLowerCase();
32017
- if (protocol === "http" || protocol === "https") {
32018
- scheme = protocol;
32019
- host = url.port ? `${url.hostname}:${url.port}` : url.hostname;
32020
- } else if (protocol === "ssh" || protocol === "git+ssh" || protocol === "git") host = url.hostname;
32021
- else return null;
32022
- path = url.pathname;
32023
- } else {
32024
- const match = SCP_LIKE.exec(trimmed);
32025
- if (!match) return null;
32026
- host = match[1];
32027
- path = match[2];
32028
- if (host.length < 2) return null;
32029
- }
32030
- host = host.toLowerCase();
32031
- if (host === "") return null;
32032
- const segments = path.replace(/\/+$/, "").replace(/\.git$/i, "").split("/").filter((segment) => segment !== "");
32033
- if (segments.length !== 2) return null;
32034
- if (hasDotSegment(path) || segments.some((segment) => segment.includes(":"))) return null;
32035
- const origin = webOrigin(`${scheme}://${host}`);
32036
- if (origin === null) return null;
32037
- return {
32038
- host: origin,
32039
- repository: `${segments[0]}/${segments[1]}`
32040
- };
32041
- }
32042
- /** Whether any segment of the path is `.` or `..`, percent-encoded or not. */
32043
- function hasDotSegment(path) {
32044
- return path.split("/").some((segment) => {
32045
- let decoded = segment;
32046
- try {
32047
- decoded = decodeURIComponent(segment);
32048
- } catch {}
32049
- return decoded === "." || decoded === "..";
32050
- });
32051
- }
32052
- function webOrigin(url) {
32053
- try {
32054
- const origin = new URL(url).origin;
32055
- return origin === "null" ? null : origin;
32056
- } catch {
32057
- return null;
32058
- }
32059
- }
32060
- //#endregion
32061
- //#region ../../packages/types/dist/licenses/spdx-license-list.js
32062
- /**
32063
- * The SPDX License List 3.29.0 (licenses and exceptions), as `license-normalise` reads it: each
32064
- * licence's id, full name, whether the id is deprecated, and its reference URLs reduced to
32065
- * host and path (no scheme, no `www.`, no trailing slash or `.txt`/`.html`). Generated from
32066
- * https://github.com/spdx/license-list-data (json/licenses.json, json/exceptions.json) at
32067
- * 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).
32068
31300
  */
32069
31301
  /** [id, name, deprecated (1), reference URLs]. */
32070
31302
  const SPDX_LICENSES = [
@@ -37120,475 +36352,1243 @@ const SPDX_EXCEPTIONS = [
37120
36352
  "OpenVPN OpenSSL Exception",
37121
36353
  0
37122
36354
  ],
37123
- [
37124
- "polyparse-exception",
37125
- "Polyparse Exception",
37126
- 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"
37127
36706
  ],
37128
- [
37129
- "romic-exception",
37130
- "Romic Exception",
37131
- 0
36707
+ "Apple Public Source License": [
36708
+ "APSL-1.0",
36709
+ "APSL-1.1",
36710
+ "APSL-1.2",
36711
+ "APSL-2.0"
37132
36712
  ],
37133
- [
37134
- "rsync-linking-exception",
37135
- "rsync Linking Exception",
37136
- 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"
37137
36718
  ],
37138
- [
37139
- "sqlitestudio-OpenSSL-exception",
37140
- "sqlitestudio OpenSSL exception",
37141
- 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"
37142
36727
  ],
37143
- [
37144
- "stunnel-exception",
37145
- "stunnel Exception",
37146
- 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"
37147
36735
  ],
37148
- [
37149
- "u-boot-exception-2.0",
37150
- "U-Boot exception 2.0",
37151
- 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"
37152
36748
  ],
37153
- [
37154
- "vsftpd-openssl-exception",
37155
- "vsftpd OpenSSL exception",
37156
- 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"
37157
36755
  ],
37158
- [
37159
- "x11vnc-openssl-exception",
37160
- "x11vnc OpenSSL Exception",
37161
- 0
37162
- ]
37163
- ];
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
+ }
37164
37244
  //#endregion
37165
- //#region ../../packages/types/dist/licenses/spdx-expression.js
37245
+ //#region src/tools/hints.ts
37166
37246
  /**
37167
- * The SPDX license expression grammar (SPDX 2.3, Annex D), parsed once and
37168
- * shared by everything that reads a licence string: the SBOM renderer, which
37169
- * must only emit an expression an SPDX-aware consumer will accept, and the
37170
- * licence summary, which reads an expression against the allowlist (PRO-2945).
37171
- *
37172
- * The parser decides the SHAPE only: operands are any token that is not an
37173
- * operator or a parenthesis, the way osv-scanner's own parser reads them
37174
- * (internal/spdx/satisfies.go, v2.4.0). Whether an operand is a listed SPDX id
37175
- * is the caller's question, since the renderer needs a strict answer and the
37176
- * 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.
37177
37251
  */
37178
- const OPERATORS = /* @__PURE__ */ new Set([
37179
- "AND",
37180
- "OR",
37181
- "WITH",
37182
- "(",
37183
- ")"
37184
- ]);
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
+ };
37185
37269
  /**
37186
- * Licence strings are stored as the scanner reported them, unbounded; the
37187
- * parser recurses once per parenthesis level, so a pathological value could
37188
- * exhaust the stack. Real expressions nest a level or two: past this bound the
37189
- * 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.
37190
37273
  */
37191
- 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
+ };
37192
37284
  /**
37193
- * The expression tree of `text`, or null when it is not one: unbalanced
37194
- * parentheses, a dangling or doubled operator, two operands with no operator
37195
- * between them. AND binds tighter than OR; WITH binds an exception to the one
37196
- * licence before it; operators are upper case, so `mit or isc` is not an
37197
- * 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.
37198
37289
  */
37199
- function parseSpdxExpression(text) {
37200
- const tokens = text.replace(/([()])/g, " $1 ").trim().split(/\s+/).filter((t) => t !== "");
37201
- if (tokens.length === 0) return null;
37202
- let at = 0;
37203
- let depth = 0;
37204
- const peek = () => tokens[at];
37205
- const operand = (token) => token !== void 0 && !OPERATORS.has(token);
37206
- const term = () => {
37207
- const token = peek();
37208
- if (token === "(") {
37209
- if (depth === MAX_DEPTH) return null;
37210
- depth += 1;
37211
- at += 1;
37212
- const inner = compound();
37213
- if (inner === null || peek() !== ")") return null;
37214
- at += 1;
37215
- depth -= 1;
37216
- return inner;
37217
- }
37218
- if (!operand(token)) return null;
37219
- at += 1;
37220
- if (peek() !== "WITH") return {
37221
- kind: "license",
37222
- license: token,
37223
- exception: null
37224
- };
37225
- at += 1;
37226
- const exception = peek();
37227
- if (!operand(exception)) return null;
37228
- at += 1;
37229
- return {
37230
- kind: "license",
37231
- license: token,
37232
- exception
37233
- };
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(" ");
37234
37316
  };
37235
- const chain = (kind, operator, next) => {
37236
- const first = next();
37237
- if (first === null) return null;
37238
- const operands = [first];
37239
- while (peek() === operator) {
37240
- at += 1;
37241
- const operand = next();
37242
- if (operand === null) return null;
37243
- operands.push(operand);
37244
- }
37245
- return operands.length === 1 ? first : {
37246
- kind,
37247
- 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
37248
37356
  };
37249
- };
37250
- const conjunction = () => chain("and", "AND", term);
37251
- const compound = () => chain("or", "OR", conjunction);
37252
- const tree = compound();
37253
- return tree !== null && at === tokens.length ? tree : null;
37357
+ }
37358
+ return best?.tool;
37254
37359
  }
37255
- /** Every licence operand of `tree`, left to right. */
37256
- function licenseOperands(tree) {
37257
- 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));
37258
37364
  }
37259
37365
  //#endregion
37260
- //#region ../../packages/types/dist/licenses/license-normalise.js
37366
+ //#region src/tools/errors.ts
37261
37367
  /**
37262
- * One reading of licence text as SPDX (milestone 2j, design 5.2).
37263
- *
37264
- * Registries and scanners declare licences in every shape: SPDX expressions
37265
- * (`MIT OR Apache-2.0`), deprecated ids (`GPL-2.0-with-classpath-exception`),
37266
- * names (`The Apache Software License, Version 2.0`, `MPL 2.0`), abbreviations
37267
- * (`GPL2 w/ CPE`), URLs, and words that are no licence at all (`Nonstandard`,
37268
- * `SEE LICENSE IN README.md`). deps.dev reduces the hard ones to
37269
- * `non-standard`, and until now that reduction was final, so h2 (`MPL 2.0`,
37270
- * `EPL 1.0`) and mysql-connector-j read as non-standard. This reads the raw
37271
- * text once, the same way for every source:
37272
- *
37273
- * 1. an SPDX expression of listed ids is that expression, in the list's
37274
- * spelling (a deprecated id stays itself; `currentSpelling` compares it
37275
- * with its current form);
37276
- * 2. a name the alias table knows (`ALIASES`: what registries actually
37277
- * write, checked by hand), then the SPDX list's own names and ids compared
37278
- * without punctuation or filler words, then the licence's reference URL;
37279
- * 3. anything else is a licence that is not a standard one, kept with its
37280
- * text and link so a person can read it.
37281
- *
37282
- * A declaration of several licences is a choice in the ecosystems whose
37283
- * manifests say so (a POM's `<licenses>`, a gemspec's `licenses`,
37284
- * composer.json's `license` array): `normaliseDeclared` joins them with OR,
37285
- * a non-standard one as a `LicenseRef-` operand, so `GPL-2.0-only OR
37286
- * GPL-3.0-only OR LicenseRef-nonstandard` still offers the GPLs. Elsewhere
37287
- * 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.
37288
37372
  */
37289
- const DEPRECATED = {
37290
- "AGPL-1.0": "AGPL-1.0-only",
37291
- "AGPL-3.0": "AGPL-3.0-only",
37292
- "GFDL-1.1": "GFDL-1.1-only",
37293
- "GFDL-1.2": "GFDL-1.2-only",
37294
- "GFDL-1.3": "GFDL-1.3-only",
37295
- "GPL-1.0": "GPL-1.0-only",
37296
- "GPL-1.0+": "GPL-1.0-or-later",
37297
- "GPL-2.0": "GPL-2.0-only",
37298
- "GPL-2.0+": "GPL-2.0-or-later",
37299
- "GPL-3.0": "GPL-3.0-only",
37300
- "GPL-3.0+": "GPL-3.0-or-later",
37301
- "LGPL-2.0": "LGPL-2.0-only",
37302
- "LGPL-2.0+": "LGPL-2.0-or-later",
37303
- "LGPL-2.1": "LGPL-2.1-only",
37304
- "LGPL-2.1+": "LGPL-2.1-or-later",
37305
- "LGPL-3.0": "LGPL-3.0-only",
37306
- "LGPL-3.0+": "LGPL-3.0-or-later",
37307
- "GPL-2.0-with-classpath-exception": "GPL-2.0-only WITH Classpath-exception-2.0",
37308
- "GPL-2.0-with-GCC-exception": "GPL-2.0-only WITH GCC-exception-2.0",
37309
- "GPL-2.0-with-autoconf-exception": "GPL-2.0-only WITH Autoconf-exception-2.0",
37310
- "GPL-2.0-with-bison-exception": "GPL-2.0-only WITH Bison-exception-2.2",
37311
- "GPL-2.0-with-font-exception": "GPL-2.0-only WITH Font-exception-2.0",
37312
- "GPL-3.0-with-GCC-exception": "GPL-3.0-only WITH GCC-exception-3.1",
37313
- "GPL-3.0-with-autoconf-exception": "GPL-3.0-only WITH Autoconf-exception-3.0",
37314
- "eCos-2.0": "GPL-2.0-or-later WITH eCos-exception-2.0",
37315
- wxWindows: "GPL-2.0-or-later WITH WxWindows-exception-3.1",
37316
- "BSD-2-Clause-FreeBSD": "BSD-2-Clause",
37317
- "BSD-2-Clause-NetBSD": "BSD-2-Clause",
37318
- "StandardML-NJ": "SMLNJ",
37319
- Nunit: "zlib-acknowledgement",
37320
- "bzip2-1.0.5": "bzip2-1.0.6"
37373
+ const PRODUCT_WORDS = {
37374
+ backlogItemId: "initiativeId",
37375
+ buildRunId: "runId",
37376
+ productRepositoryId: "linkId",
37377
+ latestBuild: "latestRun"
37321
37378
  };
37322
- /** Words a licence name carries that do not tell two licences apart. */
37323
- const FILLER = /* @__PURE__ */ new Set([
37324
- "the",
37325
- "license",
37326
- "licence",
37327
- "licensed",
37328
- "version",
37329
- "v",
37330
- "software",
37331
- "under",
37332
- "terms",
37333
- "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"
37334
37389
  ]);
37335
- /** A name reduced to what distinguishes it: `The Apache Software License, Version 2.0` -> `apache20`. */
37336
- function nameKey(text) {
37337
- return text.toLowerCase().replace(/licence/g, "license").replace(/[^a-z0-9.+]+/g, " ").split(" ").filter((word) => word !== "" && !FILLER.has(word)).join("").replace(/\./g, "");
37338
- }
37339
- let index$1 = null;
37340
- function buildIndex() {
37341
- const ids = /* @__PURE__ */ new Map();
37342
- const currentForms = /* @__PURE__ */ new Map();
37343
- const exceptions = /* @__PURE__ */ new Map();
37344
- const names = /* @__PURE__ */ new Map();
37345
- const urls = /* @__PURE__ */ new Map();
37346
- const add = (map, key, id) => {
37347
- if (key === "") return;
37348
- const held = map.get(key);
37349
- if (held === void 0) map.set(key, id);
37350
- else if (held !== id) map.set(key, null);
37351
- };
37352
- for (const [id, name, deprecated, references] of SPDX_LICENSES) {
37353
- const current = deprecated ? DEPRECATED[id] : id;
37354
- ids.set(id.toLowerCase(), id);
37355
- currentForms.set(id.toLowerCase(), current ?? id);
37356
- if (!current) continue;
37357
- add(names, nameKey(id), current);
37358
- add(names, nameKey(name), current);
37359
- if (/ only$/i.test(name)) add(names, nameKey(name.replace(/ only$/i, "")), current);
37360
- for (const reference of references) add(urls, reference, current);
37361
- }
37362
- for (const [id, , deprecated] of SPDX_EXCEPTIONS) if (!deprecated) exceptions.set(id.toLowerCase(), id);
37363
- const definite = (map) => new Map([...map].filter((entry) => entry[1] !== null));
37364
- return {
37365
- ids,
37366
- current: currentForms,
37367
- exceptions,
37368
- names: definite(names),
37369
- urls: definite(urls)
37370
- };
37371
- }
37372
- function lists() {
37373
- index$1 ??= buildIndex();
37374
- return index$1;
37375
- }
37390
+ /** A copy of an API value with its keys in the product's words, values untouched. */
37376
37391
  /**
37377
- * `text` as an SPDX expression of listed licences and exceptions, in the
37378
- * list's spelling (a deprecated id kept as itself); null when it is not one.
37379
- * `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.
37380
37394
  */
37381
- function spdxExpression(text) {
37382
- const trimmed = text.trim();
37383
- const tree = parseSpdxExpression(/^[^\s()/]+(\/[^\s()/]+)+$/.test(trimmed) ? trimmed.split("/").join(" OR ") : trimmed);
37384
- if (tree === null) return null;
37385
- const { ids, exceptions } = lists();
37386
- const spelled = /* @__PURE__ */ new Map();
37387
- for (const operand of licenseOperands(tree)) {
37388
- let current;
37389
- if (/^licenseref-/i.test(operand.license)) current = operand.license;
37390
- else current = ids.get(operand.license.toLowerCase());
37391
- if (current === void 0) return null;
37392
- if (operand.exception !== null) {
37393
- const exception = exceptions.get(operand.exception.toLowerCase());
37394
- if (exception === void 0 || current.includes(" WITH ")) return null;
37395
- spelled.set(operand.exception, exception);
37396
- }
37397
- 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
+ };
37398
37409
  }
37399
- 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.");
37400
37421
  }
37401
37422
  /**
37402
- * One licence, with or without its exception, in the list's spelling (a
37403
- * deprecated id as itself); null for anything else (an expression of
37404
- * 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.
37405
37428
  */
37406
- function spdxLicenseEntry(text) {
37407
- const expression = spdxExpression(text);
37408
- if (expression === null) return null;
37409
- const plain = unwrap(expression);
37410
- const tree = parseSpdxExpression(plain);
37411
- return tree?.kind === "license" && !/^licenseref-/i.test(tree.license) ? plain : null;
37412
- }
37429
+ const roundFloats = (_key, value) => typeof value === "number" && Number.isFinite(value) && !Number.isInteger(value) ? Number(value.toPrecision(6)) : value;
37413
37430
  /**
37414
- * One licence (or licence WITH exception) as the list and the licences are
37415
- * compared (milestone 2j): its current SPDX form, lower-cased, so a list
37416
- * written with `GPL-2.0` allows a package read as `GPL-2.0-only`, and one with
37417
- * `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.
37418
37434
  */
37419
- function currentSpelling(text) {
37420
- const held = spellings.get(text);
37421
- if (held !== void 0) return held;
37422
- const spelled = (currentForm(text) ?? text.trim()).toLowerCase();
37423
- if (spellings.size >= SPELLINGS_MAX) spellings.clear();
37424
- spellings.set(text, spelled);
37425
- 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
+ }] };
37426
37444
  }
37427
37445
  /**
37428
- * `currentSpelling` by its text. A judgement compares every licence of every
37429
- * package against every list entry, and each spelling parses the text three
37430
- * times: an organization's change of its list, over a few thousand packages,
37431
- * 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.
37432
37449
  */
37433
- const spellings = /* @__PURE__ */ new Map();
37434
- const SPELLINGS_MAX = 1e4;
37435
- /** One list entry in its current form, cased as the list spells it; null for what is no entry. */
37436
- function currentForm(text) {
37437
- const entry = spdxLicenseEntry(text);
37438
- const tree = entry === null ? null : parseSpdxExpression(entry);
37439
- if (tree === null || tree.kind !== "license") return null;
37440
- const base = lists().current.get(tree.license.toLowerCase()) ?? tree.license;
37441
- 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
+ };
37442
37465
  }
37443
- function render$1(tree, spelled) {
37444
- if (tree.kind === "license") {
37445
- const id = spelled.get(tree.license) ?? tree.license;
37446
- if (tree.exception === null) return id;
37447
- return `${id} WITH ${spelled.get(tree.exception) ?? tree.exception}`;
37448
- }
37449
- 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;
37450
37472
  }
37451
- function unwrap(expression) {
37452
- 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;
37453
37478
  }
37454
- //#endregion
37455
- //#region ../../packages/types/dist/licenses/pypi-classifiers.js
37456
37479
  /**
37457
- * A licence family without its version or variant, by the name the inventory
37458
- * keeps for it (the classifier's last segment), with every id it can stand
37459
- * for. The PEP 639 list, plus the classifiers PyPI lists that name a licence
37460
- * 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.
37461
37483
  */
37462
- const AMBIGUOUS = {
37463
- "Academic Free License (AFL)": [
37464
- "AFL-1.1",
37465
- "AFL-1.2",
37466
- "AFL-2.0",
37467
- "AFL-2.1",
37468
- "AFL-3.0"
37469
- ],
37470
- "Apache Software License": [
37471
- "Apache-1.0",
37472
- "Apache-1.1",
37473
- "Apache-2.0"
37474
- ],
37475
- "Apple Public Source License": [
37476
- "APSL-1.0",
37477
- "APSL-1.1",
37478
- "APSL-1.2",
37479
- "APSL-2.0"
37480
- ],
37481
- "Artistic License": ["Artistic-1.0", "Artistic-2.0"],
37482
- "BSD License": [
37483
- "BSD-2-Clause",
37484
- "BSD-2-Clause-Patent",
37485
- "BSD-3-Clause"
37486
- ],
37487
- "GNU Affero General Public License v3": ["AGPL-3.0-only", "AGPL-3.0-or-later"],
37488
- "GNU Free Documentation License (FDL)": [
37489
- "GFDL-1.1-only",
37490
- "GFDL-1.1-or-later",
37491
- "GFDL-1.2-only",
37492
- "GFDL-1.2-or-later",
37493
- "GFDL-1.3-only",
37494
- "GFDL-1.3-or-later"
37495
- ],
37496
- "GNU General Public License (GPL)": [
37497
- "GPL-1.0-only",
37498
- "GPL-1.0-or-later",
37499
- "GPL-2.0-only",
37500
- "GPL-2.0-or-later",
37501
- "GPL-3.0-only",
37502
- "GPL-3.0-or-later"
37503
- ],
37504
- "GNU General Public License v2 (GPLv2)": ["GPL-2.0-only", "GPL-2.0-or-later"],
37505
- "GNU General Public License v3 (GPLv3)": ["GPL-3.0-only", "GPL-3.0-or-later"],
37506
- "GNU Lesser General Public License v2 (LGPLv2)": ["LGPL-2.0-only", "LGPL-2.1-only"],
37507
- "GNU Lesser General Public License v2 or later (LGPLv2+)": ["LGPL-2.0-or-later", "LGPL-2.1-or-later"],
37508
- "GNU Lesser General Public License v3 (LGPLv3)": ["LGPL-3.0-only", "LGPL-3.0-or-later"],
37509
- "GNU Library or Lesser General Public License (LGPL)": [
37510
- "LGPL-2.0-only",
37511
- "LGPL-2.0-or-later",
37512
- "LGPL-2.1-only",
37513
- "LGPL-2.1-or-later",
37514
- "LGPL-3.0-only",
37515
- "LGPL-3.0-or-later"
37516
- ],
37517
- "Eiffel Forum License (EFL)": ["EFL-1.0", "EFL-2.0"],
37518
- "Netscape Public License (NPL)": ["NPL-1.0", "NPL-1.1"],
37519
- "Zope Public License": [
37520
- "ZPL-1.1",
37521
- "ZPL-2.0",
37522
- "ZPL-2.1"
37523
- ],
37524
- "Public Domain": [],
37525
- "Free For Educational Use": [],
37526
- "Free For Home Use": [],
37527
- "Free for non-commercial use": [],
37528
- "Freely Distributable": [],
37529
- "Free To Use But Restricted": [],
37530
- Freeware: [],
37531
- "Other/Proprietary License": [],
37532
- "Repoze Public License": [],
37533
- "GUST Font License 1.0": [],
37534
- "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"
37535
37491
  };
37536
- /**
37537
- * The ids a licence string the inventory holds can stand for, when it is an
37538
- * ambiguous classifier's name; undefined for anything else.
37539
- */
37540
- function classifierCandidates(license) {
37541
- 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}` : ""}`;
37542
37495
  }
37543
- //#endregion
37544
- //#region ../../packages/types/dist/licenses/license-category.js
37545
- const operandText = (o) => o.exception === null ? o.license : `${o.license} WITH ${o.exception}`;
37546
- /**
37547
- * Canonical text of a tree: operands sorted, and parentheses only where they
37548
- * change the meaning (an OR inside an AND), so one decision always reads the
37549
- * same however it was written.
37550
- */
37551
- function canonicalText(node, insideAnd = false) {
37552
- if (node.kind === "license") return operandText(node);
37553
- const flat = (n) => n.kind === node.kind ? n.operands.flatMap(flat) : [n];
37554
- const joined = node.operands.flatMap(flat).map((o) => canonicalText(o, node.kind === "and")).sort().join(node.kind === "and" ? " AND " : " OR ");
37555
- 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);
37556
37503
  }
37557
37504
  /**
37558
- * The part of an expression that is outside the allowlist (PRO-2944): what a
37559
- * reviewer actually decides on. `Apache-2.0 AND LGPL-3.0-or-later` is outside
37560
- * only through `LGPL-3.0-or-later`; `GPL-2.0-only OR LGPL-2.1-only`, with
37561
- * neither allowed, through both choices. An AND keeps its sides that are not
37562
- * allowed, an OR none when any side is allowed and all of them otherwise, and
37563
- * an operand reads like the finding's (compared whole, `WITH` included). The
37564
- * text is canonical (operands sorted, runs of one operator flattened,
37565
- * parentheses only around an OR inside an AND), so one decision always reads
37566
- * the same and groups as one. Null
37567
- * when nothing reads outside, or the string is no expression: the caller then
37568
- * 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.
37569
37510
  */
37570
- function outsideAllowlist(expression, allowlist) {
37571
- const tree = parseSpdxExpression(expression);
37572
- if (tree === null) return null;
37573
- const allowed = new Set(allowlist.map(currentSpelling));
37574
- const isAllowed = (node) => node.kind === "license" ? allowed.has(currentSpelling(operandText(node))) : node.kind === "and" ? node.operands.every(isAllowed) : node.operands.some(isAllowed);
37575
- const prune = (node) => {
37576
- if (node.kind === "license") {
37577
- if (node.exception === null && UNKNOWN_LICENSES.includes(node.license)) return null;
37578
- 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);
37579
37527
  }
37580
- if (node.kind === "or" && node.operands.some(isAllowed)) return null;
37581
- const kept = node.operands.map(prune).filter((n) => n !== null);
37582
- if (kept.length === 0) return null;
37583
- if (kept.length === 1) return kept[0];
37584
- const operands = kept.flatMap((n) => n.kind === node.kind ? n.operands : [n]);
37585
- return {
37586
- kind: node.kind,
37587
- operands
37588
- };
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]}`
37589
37573
  };
37590
- const pruned = prune(tree);
37591
- 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
+ }
37592
37592
  }
37593
37593
  new Map(SPDX_LICENSES.map(([id, name]) => [id.toLowerCase(), name]));
37594
37594
  new Map(SPDX_EXCEPTIONS.map(([id, name]) => [id.toLowerCase(), name]));