@lonca/baron-providers 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @lonca/baron-providers
2
+
3
+ Baron provider registry: builds the live ports a policy binds, plus the native escape hatch.
4
+
5
+ Part of **[Baron](https://github.com/loncadev/baron)** — a platform-agnostic work-orchestration layer for AI coding agents:
6
+ one pane of glass (issues, scm, ci, deploy, notify) across providers, via MCP + CLI.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @lonca/baron-providers
12
+ ```
13
+
14
+ ## Documentation
15
+
16
+ See the [Baron documentation](https://github.com/loncadev/baron#readme). Source: [`packages/providers`](https://github.com/loncadev/baron/tree/main/packages/providers).
17
+
18
+ ## License
19
+
20
+ [Apache-2.0](./LICENSE) © Baron contributors.
@@ -0,0 +1,158 @@
1
+ import { IssuesPort, ScmPort, CiPort, NotifyPort, DeployPort, CapabilityManifest, LinkMap, IssuesTransport, Introspector, ScmManifest, ScmTransport, CiManifest, CiStatusMaps, CiTransport, NotifyManifest, NotifyTransport, DeployManifest, DeployStatusMaps, DeployTransport, GapPolicy, Logger, IssuesProviderConfig, BaronPolicyFile } from '@lonca/baron-core';
2
+
3
+ /** A read-only view of process environment (mirrors {@link Env}; kept local to avoid a cycle). */
4
+ type Env$1 = Record<string, string | undefined>;
5
+ /**
6
+ * The provider-native ESCAPE HATCH (decision #18). A clearly-labeled, last-resort, NON-PORTABLE
7
+ * authenticated REST passthrough so a solopreneur is never blocked by a capability Baron has not yet
8
+ * normalized into a port. The agent supplies the raw provider request; Baron only attaches the
9
+ * provider's base URL + auth and returns the (size-capped) response. This is deliberately outside the
10
+ * normalized port model — using it is an explicit, non-portable choice.
11
+ */
12
+ interface NativeRequest {
13
+ /** HTTP method (GET/POST/PATCH/…). */
14
+ readonly method: string;
15
+ /** Provider-relative path, e.g. '/beekod/_apis/wit/workitems/1?api-version=7.1'. */
16
+ readonly path: string;
17
+ readonly query?: Readonly<Record<string, string>>;
18
+ readonly body?: unknown;
19
+ }
20
+ interface NativeResponse {
21
+ readonly status: number;
22
+ readonly ok: boolean;
23
+ /** Parsed JSON when possible, else raw text. Capped — see `truncated`. */
24
+ readonly body: unknown;
25
+ readonly truncated: boolean;
26
+ }
27
+ /** How a provider exposes raw authenticated HTTP for the escape hatch. */
28
+ interface NativeHttp {
29
+ baseUrl(env: Env$1): string;
30
+ authHeader(env: Env$1): string;
31
+ }
32
+ /** Azure DevOps PATs authenticate as HTTP Basic with an empty username. */
33
+ declare function azureBasicAuth(token: string): string;
34
+ /** Pure request plan (URL + method + headers + body) — unit-testable without the network. */
35
+ declare function nativeRequestPlan(http: NativeHttp, env: Env$1, req: NativeRequest): {
36
+ url: string;
37
+ method: string;
38
+ headers: Record<string, string>;
39
+ body?: string;
40
+ };
41
+ /** Execute a native request via global fetch. The response body is parsed as JSON when possible and
42
+ * capped to keep a large payload from overflowing the caller's context (`truncated` flags it). */
43
+ declare function runNativeRequest(http: NativeHttp, env: Env$1, req: NativeRequest): Promise<NativeResponse>;
44
+
45
+ /**
46
+ * The committed `.baron` config layout, shared by every entrypoint that reads it (the CLI's
47
+ * `doctor` and the MCP server both load `policy.json`). Kept here in shared infrastructure so those
48
+ * entrypoints depend on this, not on each other. POSIX-joined; the Node fs layer accepts these on
49
+ * every platform.
50
+ */
51
+ declare const BARON_DIR = ".baron";
52
+ declare function policyPath(root: string): string;
53
+ /** Directory the default local-markdown knowledge loop persists into. */
54
+ declare function knowledgeDir(root: string): string;
55
+ /** The gitignored credentials file (KEY=VALUE) overlaid onto the environment at run time. */
56
+ declare function credentialsPath(root: string): string;
57
+
58
+ /**
59
+ * Parse a `.baron/credentials` file (dotenv-style `KEY=VALUE` lines; `#` comments and blanks
60
+ * ignored; surrounding quotes stripped). This file is gitignored and holds secrets — the committed
61
+ * `policy.json` never does.
62
+ */
63
+ declare function parseCredentials(text: string): Record<string, string>;
64
+ /**
65
+ * Overlay a `.baron/credentials` file onto the process environment. A real environment variable
66
+ * wins over the file (so CI secrets override a local file); the file fills the gaps. Returns the
67
+ * base env unchanged when no file is present.
68
+ */
69
+ declare function mergeCredentials(baseEnv: Env, fileText: string | undefined): Env;
70
+
71
+ /** A read-only view of process environment (credentials live here, never in committed policy). */
72
+ type Env = Record<string, string | undefined>;
73
+ /**
74
+ * Everything Baron's entrypoints (CLI, MCP server) need to bind a provider id to live behavior: its
75
+ * capability manifest, the env keys carrying its credentials (scaffolded into
76
+ * `.baron/credentials.example`, never committed), and factories for the live transport + introspector.
77
+ * This is shared infrastructure deliberately kept out of any single entrypoint so the CLI and the
78
+ * MCP server depend on it rather than on each other.
79
+ */
80
+ interface ProviderDescriptor {
81
+ readonly id: string;
82
+ readonly manifest?: CapabilityManifest;
83
+ readonly credentialEnvKeys?: readonly string[];
84
+ /** Fixed abstract→native link types (provider knowledge, not policy); see {@link buildIssuesPort}. */
85
+ readonly linkMap?: LinkMap;
86
+ createTransport?(env: Env): IssuesTransport;
87
+ createIntrospector?(env: Env): Introspector;
88
+ readonly scmManifest?: ScmManifest;
89
+ /** Env keys for the scm transport (Azure adds AZURE_DEVOPS_REPO over the issues keys). */
90
+ readonly scmCredentialEnvKeys?: readonly string[];
91
+ createScmTransport?(env: Env): ScmTransport;
92
+ readonly ciManifest?: CiManifest;
93
+ readonly ciStatusMaps?: CiStatusMaps;
94
+ readonly ciCredentialEnvKeys?: readonly string[];
95
+ createCiTransport?(env: Env): CiTransport;
96
+ readonly notifyManifest?: NotifyManifest;
97
+ readonly notifyCredentialEnvKeys?: readonly string[];
98
+ createNotifyTransport?(env: Env): NotifyTransport;
99
+ readonly deployManifest?: DeployManifest;
100
+ readonly deployStatusMaps?: DeployStatusMaps;
101
+ readonly deployCredentialEnvKeys?: readonly string[];
102
+ createDeployTransport?(env: Env): DeployTransport;
103
+ readonly nativeHttp?: NativeHttp;
104
+ }
105
+ declare const KNOWN_PROVIDERS: string[];
106
+ declare function getProviderDescriptor(id: string): ProviderDescriptor;
107
+ /**
108
+ * Build a live {@link IssuesPort} from a resolved policy config plus environment credentials: looks
109
+ * up the provider, creates its live transport, and wraps it in the shared {@link BaseIssuesAdapter}
110
+ * (which carries all role/native translation — invariant #4). This is the one call the MCP server
111
+ * needs to turn a `policy.json` into a working issues port.
112
+ */
113
+ declare function buildIssuesPort(config: IssuesProviderConfig, env: Env, logger?: Logger): IssuesPort;
114
+ /**
115
+ * Build a live {@link ScmPort} for a provider from environment credentials. The scm port has no
116
+ * role/type map to resolve from policy, so it binds directly from the provider id + env + an
117
+ * optional gap policy.
118
+ */
119
+ declare function buildScmPort(provider: string, env: Env, gapPolicy?: GapPolicy, logger?: Logger): ScmPort;
120
+ /**
121
+ * Build a live {@link CiPort} for a provider from environment credentials. Like scm, the ci port has
122
+ * no user-configured map to resolve from policy (CI statuses are vendor-fixed and normalized by the
123
+ * adapter), so it binds from the provider id + env + an optional gap policy.
124
+ */
125
+ declare function buildCiPort(provider: string, env: Env, gapPolicy?: GapPolicy, logger?: Logger): CiPort;
126
+ /**
127
+ * Build a live {@link NotifyPort} for a provider from environment credentials. Like scm/ci, notify
128
+ * has no user-configured map in policy, so it binds from the provider id + env + an optional gap policy.
129
+ */
130
+ declare function buildNotifyPort(provider: string, env: Env, gapPolicy?: GapPolicy, logger?: Logger): NotifyPort;
131
+ /**
132
+ * Execute a provider-native escape-hatch request (decision #18). Looks up the provider's raw-HTTP
133
+ * descriptor and runs the request with its base URL + auth; throws NATIVE_UNSUPPORTED if the provider
134
+ * exposes no escape hatch. This is the last-resort, non-portable path — callers (e.g. the MCP server)
135
+ * should restrict it to providers the active policy actually binds.
136
+ */
137
+ declare function executeNativeRequest(provider: string, env: Env, request: NativeRequest): Promise<NativeResponse>;
138
+ /**
139
+ * Build a live {@link DeployPort} for a provider from environment credentials. Like ci/notify, the
140
+ * deploy port has no user-configured map in policy (deploy statuses are vendor-fixed), so it binds
141
+ * from the provider id + env + an optional gap policy.
142
+ */
143
+ declare function buildDeployPort(provider: string, env: Env, gapPolicy?: GapPolicy, logger?: Logger): DeployPort;
144
+ interface BoundPorts {
145
+ issues?: IssuesPort;
146
+ scm?: ScmPort;
147
+ ci?: CiPort;
148
+ notify?: NotifyPort;
149
+ deploy?: DeployPort;
150
+ }
151
+ /**
152
+ * Build every port a parsed policy binds (issues and/or scm), from environment credentials. Shared
153
+ * by the MCP server and the CLI's `run` so both turn a `policy.json` into live ports identically;
154
+ * neither port is built unless `providers` binds it.
155
+ */
156
+ declare function buildPorts(policy: BaronPolicyFile, env: Env, logger?: Logger): BoundPorts;
157
+
158
+ export { BARON_DIR, type BoundPorts, type Env, KNOWN_PROVIDERS, type NativeHttp, type NativeRequest, type NativeResponse, type ProviderDescriptor, azureBasicAuth, buildCiPort, buildDeployPort, buildIssuesPort, buildNotifyPort, buildPorts, buildScmPort, credentialsPath, executeNativeRequest, getProviderDescriptor, knowledgeDir, mergeCredentials, nativeRequestPlan, parseCredentials, policyPath, runNativeRequest };
package/dist/index.js ADDED
@@ -0,0 +1,396 @@
1
+ // src/index.ts
2
+ import {
3
+ AZURE_DEVOPS_PROVIDER,
4
+ azureDevOpsCiManifest,
5
+ azureDevOpsCiStatusMaps,
6
+ azureDevOpsDeployManifest,
7
+ azureDevOpsDeployStatusMaps,
8
+ azureDevOpsManifest,
9
+ azureDevOpsScmManifest,
10
+ createAzureDevOpsCiTransport,
11
+ createAzureDevOpsDeployTransport,
12
+ createAzureDevOpsIntrospector,
13
+ createAzureDevOpsScmTransport,
14
+ createAzureDevOpsTransport,
15
+ exampleAzureDevOpsLinkMap
16
+ } from "@lonca/baron-adapter-azure-devops";
17
+ import {
18
+ GITHUB_PROVIDER,
19
+ createGithubCiTransport,
20
+ createGithubDeployTransport,
21
+ createGithubIntrospector,
22
+ createGithubScmTransport,
23
+ createGithubTransport,
24
+ exampleGithubLinkMap,
25
+ githubCiManifest,
26
+ githubCiStatusMaps,
27
+ githubDeployManifest,
28
+ githubDeployStatusMaps,
29
+ githubManifest,
30
+ githubScmManifest
31
+ } from "@lonca/baron-adapter-github";
32
+ import {
33
+ SLACK_PROVIDER,
34
+ createSlackNotifyTransport,
35
+ slackNotifyManifest
36
+ } from "@lonca/baron-adapter-slack";
37
+ import {
38
+ BaronError,
39
+ BaseCiAdapter,
40
+ BaseDeployAdapter,
41
+ BaseIssuesAdapter,
42
+ BaseNotifyAdapter,
43
+ BaseScmAdapter,
44
+ parseGapPolicy,
45
+ resolveIssuesConfig
46
+ } from "@lonca/baron-core";
47
+
48
+ // src/native.ts
49
+ import { Buffer } from "buffer";
50
+ function azureBasicAuth(token) {
51
+ return `Basic ${Buffer.from(`:${token}`).toString("base64")}`;
52
+ }
53
+ var MAX_BODY_CHARS = 2e4;
54
+ function nativeRequestPlan(http, env, req) {
55
+ const base = http.baseUrl(env).replace(/\/+$/, "");
56
+ const path = req.path.startsWith("/") ? req.path : `/${req.path}`;
57
+ const qs = req.query !== void 0 && Object.keys(req.query).length > 0 ? `${path.includes("?") ? "&" : "?"}${new URLSearchParams(req.query).toString()}` : "";
58
+ const headers = { authorization: http.authHeader(env) };
59
+ let body;
60
+ if (req.body !== void 0) {
61
+ headers["content-type"] = "application/json";
62
+ body = JSON.stringify(req.body);
63
+ }
64
+ return {
65
+ url: `${base}${path}${qs}`,
66
+ method: req.method.toUpperCase(),
67
+ headers,
68
+ ...body !== void 0 ? { body } : {}
69
+ };
70
+ }
71
+ async function runNativeRequest(http, env, req) {
72
+ const plan = nativeRequestPlan(http, env, req);
73
+ const response = await fetch(plan.url, {
74
+ method: plan.method,
75
+ headers: plan.headers,
76
+ ...plan.body !== void 0 ? { body: plan.body } : {}
77
+ });
78
+ const text = await response.text();
79
+ const truncated = text.length > MAX_BODY_CHARS;
80
+ const slice = truncated ? text.slice(0, MAX_BODY_CHARS) : text;
81
+ let parsed = slice;
82
+ try {
83
+ parsed = JSON.parse(slice);
84
+ } catch {
85
+ }
86
+ return { status: response.status, ok: response.ok, body: parsed, truncated };
87
+ }
88
+
89
+ // src/paths.ts
90
+ var BARON_DIR = ".baron";
91
+ function policyPath(root) {
92
+ return `${root}/${BARON_DIR}/policy.json`;
93
+ }
94
+ function knowledgeDir(root) {
95
+ return `${root}/${BARON_DIR}/knowledge`;
96
+ }
97
+ function credentialsPath(root) {
98
+ return `${root}/${BARON_DIR}/credentials`;
99
+ }
100
+
101
+ // src/credentials.ts
102
+ function parseCredentials(text) {
103
+ const out = {};
104
+ for (const rawLine of text.split(/\r?\n/)) {
105
+ const line = rawLine.trim();
106
+ if (line.length === 0 || line.startsWith("#")) continue;
107
+ const eq = line.indexOf("=");
108
+ if (eq === -1) continue;
109
+ const key = line.slice(0, eq).trim();
110
+ let value = line.slice(eq + 1).trim();
111
+ if (value.length >= 2 && (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'"))) {
112
+ value = value.slice(1, -1);
113
+ }
114
+ if (key.length > 0) out[key] = value;
115
+ }
116
+ return out;
117
+ }
118
+ function mergeCredentials(baseEnv, fileText) {
119
+ if (fileText === void 0) return baseEnv;
120
+ return { ...parseCredentials(fileText), ...baseEnv };
121
+ }
122
+
123
+ // src/index.ts
124
+ var DESCRIPTORS = {
125
+ [AZURE_DEVOPS_PROVIDER]: {
126
+ id: AZURE_DEVOPS_PROVIDER,
127
+ manifest: azureDevOpsManifest,
128
+ credentialEnvKeys: ["AZURE_DEVOPS_ORG", "AZURE_DEVOPS_PROJECT", "AZURE_DEVOPS_TOKEN"],
129
+ linkMap: exampleAzureDevOpsLinkMap,
130
+ createTransport(env) {
131
+ return createAzureDevOpsTransport({
132
+ organization: env.AZURE_DEVOPS_ORG ?? "",
133
+ project: env.AZURE_DEVOPS_PROJECT ?? "",
134
+ token: env.AZURE_DEVOPS_TOKEN ?? ""
135
+ });
136
+ },
137
+ createIntrospector(env) {
138
+ return createAzureDevOpsIntrospector({
139
+ organization: env.AZURE_DEVOPS_ORG ?? "",
140
+ project: env.AZURE_DEVOPS_PROJECT ?? "",
141
+ token: env.AZURE_DEVOPS_TOKEN ?? ""
142
+ });
143
+ },
144
+ scmManifest: azureDevOpsScmManifest,
145
+ scmCredentialEnvKeys: [
146
+ "AZURE_DEVOPS_ORG",
147
+ "AZURE_DEVOPS_PROJECT",
148
+ "AZURE_DEVOPS_REPO",
149
+ "AZURE_DEVOPS_TOKEN"
150
+ ],
151
+ createScmTransport(env) {
152
+ return createAzureDevOpsScmTransport({
153
+ organization: env.AZURE_DEVOPS_ORG ?? "",
154
+ project: env.AZURE_DEVOPS_PROJECT ?? "",
155
+ repository: env.AZURE_DEVOPS_REPO ?? "",
156
+ token: env.AZURE_DEVOPS_TOKEN ?? ""
157
+ });
158
+ },
159
+ ciManifest: azureDevOpsCiManifest,
160
+ ciStatusMaps: azureDevOpsCiStatusMaps,
161
+ ciCredentialEnvKeys: ["AZURE_DEVOPS_ORG", "AZURE_DEVOPS_PROJECT", "AZURE_DEVOPS_TOKEN"],
162
+ createCiTransport(env) {
163
+ return createAzureDevOpsCiTransport({
164
+ organization: env.AZURE_DEVOPS_ORG ?? "",
165
+ project: env.AZURE_DEVOPS_PROJECT ?? "",
166
+ token: env.AZURE_DEVOPS_TOKEN ?? ""
167
+ });
168
+ },
169
+ deployManifest: azureDevOpsDeployManifest,
170
+ deployStatusMaps: azureDevOpsDeployStatusMaps,
171
+ deployCredentialEnvKeys: ["AZURE_DEVOPS_ORG", "AZURE_DEVOPS_PROJECT", "AZURE_DEVOPS_TOKEN"],
172
+ createDeployTransport(env) {
173
+ return createAzureDevOpsDeployTransport({
174
+ organization: env.AZURE_DEVOPS_ORG ?? "",
175
+ project: env.AZURE_DEVOPS_PROJECT ?? "",
176
+ token: env.AZURE_DEVOPS_TOKEN ?? ""
177
+ });
178
+ },
179
+ nativeHttp: {
180
+ baseUrl: (env) => `https://dev.azure.com/${env.AZURE_DEVOPS_ORG ?? ""}`,
181
+ authHeader: (env) => azureBasicAuth(env.AZURE_DEVOPS_TOKEN ?? "")
182
+ }
183
+ },
184
+ [GITHUB_PROVIDER]: {
185
+ id: GITHUB_PROVIDER,
186
+ manifest: githubManifest,
187
+ credentialEnvKeys: ["GITHUB_OWNER", "GITHUB_REPO", "GITHUB_TOKEN"],
188
+ linkMap: exampleGithubLinkMap,
189
+ createTransport(env) {
190
+ return createGithubTransport({
191
+ owner: env.GITHUB_OWNER ?? "",
192
+ repo: env.GITHUB_REPO ?? "",
193
+ token: env.GITHUB_TOKEN ?? ""
194
+ });
195
+ },
196
+ createIntrospector(env) {
197
+ return createGithubIntrospector({
198
+ owner: env.GITHUB_OWNER ?? "",
199
+ repo: env.GITHUB_REPO ?? "",
200
+ token: env.GITHUB_TOKEN ?? ""
201
+ });
202
+ },
203
+ scmManifest: githubScmManifest,
204
+ scmCredentialEnvKeys: ["GITHUB_OWNER", "GITHUB_REPO", "GITHUB_TOKEN"],
205
+ createScmTransport(env) {
206
+ return createGithubScmTransport({
207
+ owner: env.GITHUB_OWNER ?? "",
208
+ repo: env.GITHUB_REPO ?? "",
209
+ token: env.GITHUB_TOKEN ?? ""
210
+ });
211
+ },
212
+ ciManifest: githubCiManifest,
213
+ ciStatusMaps: githubCiStatusMaps,
214
+ ciCredentialEnvKeys: ["GITHUB_OWNER", "GITHUB_REPO", "GITHUB_TOKEN"],
215
+ createCiTransport(env) {
216
+ return createGithubCiTransport({
217
+ owner: env.GITHUB_OWNER ?? "",
218
+ repo: env.GITHUB_REPO ?? "",
219
+ token: env.GITHUB_TOKEN ?? ""
220
+ });
221
+ },
222
+ deployManifest: githubDeployManifest,
223
+ deployStatusMaps: githubDeployStatusMaps,
224
+ deployCredentialEnvKeys: ["GITHUB_OWNER", "GITHUB_REPO", "GITHUB_TOKEN"],
225
+ createDeployTransport(env) {
226
+ return createGithubDeployTransport({
227
+ owner: env.GITHUB_OWNER ?? "",
228
+ repo: env.GITHUB_REPO ?? "",
229
+ token: env.GITHUB_TOKEN ?? ""
230
+ });
231
+ },
232
+ nativeHttp: {
233
+ baseUrl: () => "https://api.github.com",
234
+ authHeader: (env) => `Bearer ${env.GITHUB_TOKEN ?? ""}`
235
+ }
236
+ },
237
+ [SLACK_PROVIDER]: {
238
+ id: SLACK_PROVIDER,
239
+ // Slack is notify-only: no issues/scm/ci groups.
240
+ notifyManifest: slackNotifyManifest,
241
+ notifyCredentialEnvKeys: ["SLACK_BOT_TOKEN", "SLACK_CHANNEL"],
242
+ createNotifyTransport(env) {
243
+ return createSlackNotifyTransport({
244
+ token: env.SLACK_BOT_TOKEN ?? "",
245
+ ...env.SLACK_CHANNEL !== void 0 ? { defaultChannel: env.SLACK_CHANNEL } : {}
246
+ });
247
+ },
248
+ nativeHttp: {
249
+ baseUrl: () => "https://slack.com/api",
250
+ authHeader: (env) => `Bearer ${env.SLACK_BOT_TOKEN ?? ""}`
251
+ }
252
+ }
253
+ };
254
+ var KNOWN_PROVIDERS = Object.keys(DESCRIPTORS);
255
+ function getProviderDescriptor(id) {
256
+ const descriptor = DESCRIPTORS[id];
257
+ if (descriptor === void 0) {
258
+ throw new BaronError(
259
+ `Unknown provider '${id}'. Known providers: ${KNOWN_PROVIDERS.join(", ")}.`,
260
+ "UNKNOWN_PROVIDER"
261
+ );
262
+ }
263
+ return descriptor;
264
+ }
265
+ function buildIssuesPort(config, env, logger) {
266
+ const descriptor = getProviderDescriptor(config.provider);
267
+ if (descriptor.manifest === void 0 || descriptor.createTransport === void 0) {
268
+ throw new BaronError(
269
+ `Provider '${config.provider}' has no issues adapter.`,
270
+ "ISSUES_UNSUPPORTED"
271
+ );
272
+ }
273
+ const resolved = {
274
+ ...config,
275
+ linkMap: config.linkMap ?? descriptor.linkMap ?? {}
276
+ };
277
+ return new BaseIssuesAdapter(
278
+ descriptor.manifest,
279
+ resolved,
280
+ descriptor.createTransport(env),
281
+ logger
282
+ );
283
+ }
284
+ function buildScmPort(provider, env, gapPolicy, logger) {
285
+ const descriptor = getProviderDescriptor(provider);
286
+ if (descriptor.scmManifest === void 0 || descriptor.createScmTransport === void 0) {
287
+ throw new BaronError(`Provider '${provider}' has no scm adapter.`, "SCM_UNSUPPORTED");
288
+ }
289
+ return new BaseScmAdapter(
290
+ descriptor.scmManifest,
291
+ descriptor.createScmTransport(env),
292
+ gapPolicy,
293
+ logger
294
+ );
295
+ }
296
+ function buildCiPort(provider, env, gapPolicy, logger) {
297
+ const descriptor = getProviderDescriptor(provider);
298
+ if (descriptor.ciManifest === void 0 || descriptor.ciStatusMaps === void 0 || descriptor.createCiTransport === void 0) {
299
+ throw new BaronError(`Provider '${provider}' has no ci adapter.`, "CI_UNSUPPORTED");
300
+ }
301
+ return new BaseCiAdapter(
302
+ descriptor.ciManifest,
303
+ descriptor.ciStatusMaps,
304
+ descriptor.createCiTransport(env),
305
+ gapPolicy,
306
+ logger
307
+ );
308
+ }
309
+ function buildNotifyPort(provider, env, gapPolicy, logger) {
310
+ const descriptor = getProviderDescriptor(provider);
311
+ if (descriptor.notifyManifest === void 0 || descriptor.createNotifyTransport === void 0) {
312
+ throw new BaronError(`Provider '${provider}' has no notify adapter.`, "NOTIFY_UNSUPPORTED");
313
+ }
314
+ return new BaseNotifyAdapter(
315
+ descriptor.notifyManifest,
316
+ descriptor.createNotifyTransport(env),
317
+ gapPolicy,
318
+ logger
319
+ );
320
+ }
321
+ function executeNativeRequest(provider, env, request) {
322
+ const descriptor = getProviderDescriptor(provider);
323
+ if (descriptor.nativeHttp === void 0) {
324
+ throw new BaronError(
325
+ `Provider '${provider}' has no native escape hatch.`,
326
+ "NATIVE_UNSUPPORTED"
327
+ );
328
+ }
329
+ return runNativeRequest(descriptor.nativeHttp, env, request);
330
+ }
331
+ function buildDeployPort(provider, env, gapPolicy, logger) {
332
+ const descriptor = getProviderDescriptor(provider);
333
+ if (descriptor.deployManifest === void 0 || descriptor.deployStatusMaps === void 0 || descriptor.createDeployTransport === void 0) {
334
+ throw new BaronError(`Provider '${provider}' has no deploy adapter.`, "DEPLOY_UNSUPPORTED");
335
+ }
336
+ return new BaseDeployAdapter(
337
+ descriptor.deployManifest,
338
+ descriptor.deployStatusMaps,
339
+ descriptor.createDeployTransport(env),
340
+ gapPolicy,
341
+ logger
342
+ );
343
+ }
344
+ function buildPorts(policy, env, logger) {
345
+ const ports = {};
346
+ if (policy.providers.issues !== void 0) {
347
+ ports.issues = buildIssuesPort(resolveIssuesConfig(policy), env, logger);
348
+ }
349
+ const scmProvider = policy.providers.scm;
350
+ if (scmProvider !== void 0) {
351
+ const gapPolicy = parseGapPolicy(policy.gapPolicy?.[scmProvider] ?? {});
352
+ ports.scm = buildScmPort(scmProvider, env, gapPolicy, logger);
353
+ }
354
+ const ciProvider = policy.providers.ci;
355
+ if (ciProvider !== void 0) {
356
+ const gapPolicy = parseGapPolicy(policy.gapPolicy?.[ciProvider] ?? {});
357
+ ports.ci = buildCiPort(ciProvider, env, gapPolicy, logger);
358
+ }
359
+ const notifyProvider = policy.providers.notify;
360
+ if (notifyProvider !== void 0) {
361
+ const gapPolicy = parseGapPolicy(policy.gapPolicy?.[notifyProvider] ?? {});
362
+ ports.notify = buildNotifyPort(notifyProvider, env, gapPolicy, logger);
363
+ }
364
+ const deployProvider = policy.providers.deploy;
365
+ if (deployProvider !== void 0) {
366
+ const gapPolicy = parseGapPolicy(policy.gapPolicy?.[deployProvider] ?? {});
367
+ ports.deploy = buildDeployPort(deployProvider, env, gapPolicy, logger);
368
+ }
369
+ if (policy.providers.docs !== void 0) {
370
+ throw new BaronError(
371
+ "The 'docs' port is declared but not implemented yet (planned for a future release); remove it from policy.providers.",
372
+ "DOCS_UNSUPPORTED"
373
+ );
374
+ }
375
+ return ports;
376
+ }
377
+ export {
378
+ BARON_DIR,
379
+ KNOWN_PROVIDERS,
380
+ azureBasicAuth,
381
+ buildCiPort,
382
+ buildDeployPort,
383
+ buildIssuesPort,
384
+ buildNotifyPort,
385
+ buildPorts,
386
+ buildScmPort,
387
+ credentialsPath,
388
+ executeNativeRequest,
389
+ getProviderDescriptor,
390
+ knowledgeDir,
391
+ mergeCredentials,
392
+ nativeRequestPlan,
393
+ parseCredentials,
394
+ policyPath,
395
+ runNativeRequest
396
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@lonca/baron-providers",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "@lonca/baron-core": "0.1.0",
19
+ "@lonca/baron-adapter-slack": "0.1.0",
20
+ "@lonca/baron-adapter-azure-devops": "0.1.0",
21
+ "@lonca/baron-adapter-github": "0.1.0"
22
+ },
23
+ "description": "Baron provider registry: builds the live ports a policy binds, plus the native escape hatch.",
24
+ "keywords": [
25
+ "baron",
26
+ "ai-agents",
27
+ "mcp",
28
+ "work-orchestration",
29
+ "devops",
30
+ "providers",
31
+ "policy"
32
+ ],
33
+ "author": "Baron contributors",
34
+ "homepage": "https://github.com/loncadev/baron#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/loncadev/baron/issues"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/loncadev/baron.git",
41
+ "directory": "packages/providers"
42
+ },
43
+ "scripts": {
44
+ "build": "tsup src/index.ts --format esm --dts --clean",
45
+ "typecheck": "tsc --noEmit"
46
+ }
47
+ }