@enhance-eng/enhance 0.1.6 → 0.1.13

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.
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+ import { i as toFailurePayload } from "./cli-output-identity.lib-DAJiBMGX.mjs";
3
+ import { a as createOauthLoopbackAdapter, f as createAuthUseCase, n as createHttpRemoteAdapter, o as createCapabilityInvocationAdapter, t as createMutationKeyAdapter } from "./mutation-key.adapter-BffKsNR-.mjs";
4
+ import { z } from "zod";
5
+
6
+ //#region src/infrastructure/mcp-auth.adapter.ts
7
+ const loginInputSchema = z.object({ openBrowser: z.boolean() });
8
+ const createMcpAuthAdapter = (credentials, remote) => {
9
+ const auth = createAuthUseCase(credentials, remote, createOauthLoopbackAdapter(remote));
10
+ let active = null;
11
+ let state = null;
12
+ return {
13
+ login: async (offered) => {
14
+ if (active !== null) return active.ready;
15
+ const input = loginInputSchema.parse(offered);
16
+ const controller = new AbortController();
17
+ const ready = Promise.withResolvers();
18
+ state = null;
19
+ const complete = async () => {
20
+ try {
21
+ await auth.loginWithBrowser({
22
+ label: "Agent plugin",
23
+ openBrowser: input.openBrowser,
24
+ signal: controller.signal,
25
+ onReady: (url) => {
26
+ state = {
27
+ authenticated: false,
28
+ status: "waiting_for_browser",
29
+ url
30
+ };
31
+ ready.resolve(state);
32
+ }
33
+ });
34
+ state = null;
35
+ } catch (error) {
36
+ state = {
37
+ authenticated: false,
38
+ status: "failed",
39
+ error: toFailurePayload(error, null)
40
+ };
41
+ ready.reject(error);
42
+ } finally {
43
+ active = null;
44
+ }
45
+ };
46
+ const completion = complete();
47
+ active = {
48
+ controller,
49
+ ready: ready.promise,
50
+ completion
51
+ };
52
+ return ready.promise;
53
+ },
54
+ status: async () => {
55
+ if (state !== null) return state;
56
+ if (await credentials.read() === null) return { authenticated: false };
57
+ return auth.status();
58
+ },
59
+ logout: async () => {
60
+ active?.controller.abort();
61
+ await active?.completion;
62
+ state = null;
63
+ return auth.logout();
64
+ }
65
+ };
66
+ };
67
+
68
+ //#endregion
69
+ //#region src/infrastructure/mcp-invocation.adapter.ts
70
+ const TRANSPORT_CAPABILITIES = /* @__PURE__ */ new Set([
71
+ "auth.login",
72
+ "auth.logout",
73
+ "auth.status",
74
+ "doctor"
75
+ ]);
76
+ const invokeTransport = async (input) => {
77
+ switch (input.capability) {
78
+ case "auth.login": return input.auth.login(input.arguments);
79
+ case "auth.logout": return input.auth.logout();
80
+ case "auth.status": return input.auth.status();
81
+ case "doctor": {
82
+ const [api, credential] = await Promise.all([input.remote.health(), input.credentials.read()]);
83
+ return {
84
+ status: credential !== null && api.reachable ? "ok" : "degraded",
85
+ runtimeVersion: input.version,
86
+ api: {
87
+ reachable: api.reachable,
88
+ status: api.status,
89
+ ...api.error !== void 0 && { error: api.error }
90
+ },
91
+ credential: { present: credential !== null }
92
+ };
93
+ }
94
+ default: throw new TypeError(`${input.capability} has no MCP transport execution`);
95
+ }
96
+ };
97
+ const createMcpInvocationAdapter = (apiUrl, credentials, configDirectory, version) => {
98
+ const transportRemote = createHttpRemoteAdapter(apiUrl, credentials, createMutationKeyAdapter());
99
+ const auth = createMcpAuthAdapter(credentials, transportRemote);
100
+ return { invoke: async (request) => {
101
+ if (TRANSPORT_CAPABILITIES.has(request.capability.id)) return invokeTransport({
102
+ capability: request.capability.id,
103
+ arguments: request.arguments,
104
+ credentials,
105
+ remote: transportRemote,
106
+ version,
107
+ auth
108
+ });
109
+ const mutationKey = createMutationKeyAdapter();
110
+ return createCapabilityInvocationAdapter({
111
+ remote: createHttpRemoteAdapter(apiUrl, credentials, mutationKey),
112
+ mutationKey,
113
+ configDirectory
114
+ }).invoke(request);
115
+ } };
116
+ };
117
+
118
+ //#endregion
119
+ export { createMcpInvocationAdapter as t };
package/dist/mcp-main.mjs CHANGED
@@ -1,19 +1,185 @@
1
1
  #!/usr/bin/env node
2
- import { r as CLI_CONFIG } from "./mutation-key.adapter-B7Ss_464.mjs";
3
- import { t as createFileCredentialAdapter } from "./file-credential.adapter-WNl4GM58.mjs";
4
- import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-D0o0vb_-.mjs";
5
- import { t as createMcpServerAdapter } from "./mcp-server.adapter-T8UqHf6A.mjs";
2
+ import { f as toCapabilityDefinition, l as createCapabilityCatalogAdapter } from "./cli-output-identity.lib-DAJiBMGX.mjs";
3
+ import { r as CLI_CONFIG } from "./mutation-key.adapter-BffKsNR-.mjs";
4
+ import { t as createFileCredentialAdapter } from "./file-credential.adapter-rI5HpMEo.mjs";
5
+ import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-BG-WBGEr.mjs";
6
+ import { t as createMcpServerAdapter } from "./mcp-server.adapter-BgUZCdl4.mjs";
7
+ import { z } from "zod";
6
8
  import process from "node:process";
7
9
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
10
+
11
+ //#region src/infrastructure/mcp-transport-capability.adapter.ts
12
+ const unauthenticatedSchema = z.object({ authenticated: z.literal(false) });
13
+ const pendingLoginSchema = z.object({
14
+ authenticated: z.literal(false),
15
+ status: z.literal("waiting_for_browser"),
16
+ url: z.url()
17
+ });
18
+ const failedLoginSchema = z.object({
19
+ authenticated: z.literal(false),
20
+ status: z.literal("failed"),
21
+ error: z.object({
22
+ code: z.string(),
23
+ message: z.string(),
24
+ remediation: z.string()
25
+ })
26
+ });
27
+ const authenticatedSchema = z.object({
28
+ authenticated: z.literal(true),
29
+ personId: z.uuid(),
30
+ displayName: z.string().min(1),
31
+ tokenId: z.uuid(),
32
+ tokenLabel: z.string().min(1),
33
+ expiresAt: z.iso.datetime().nullable()
34
+ });
35
+ const loginInputSchema = z.object({ openBrowser: z.boolean().default(true).describe("Open the system browser for human sign-in; return its URL immediately.") });
36
+ const statusInputSchema = z.strictObject({});
37
+ const statusOutputSchema = z.union([
38
+ pendingLoginSchema,
39
+ failedLoginSchema,
40
+ unauthenticatedSchema,
41
+ authenticatedSchema
42
+ ]);
43
+ const logoutOutputSchema = z.object({ loggedOut: z.boolean() });
44
+ const doctorOutputSchema = z.object({
45
+ status: z.enum(["ok", "degraded"]),
46
+ runtimeVersion: z.string().min(1),
47
+ api: z.object({
48
+ reachable: z.boolean(),
49
+ status: z.number().int().nullable(),
50
+ error: z.string().optional()
51
+ }),
52
+ credential: z.object({ present: z.boolean() })
53
+ });
54
+ const guideFor = (input) => ({
55
+ summary: input.summary,
56
+ useWhen: input.useWhen,
57
+ preconditions: ["Run through the local Enhance MCP runtime, which owns the user-scoped credential.", "Keep credential values outside model-visible input and output."],
58
+ input: [],
59
+ output: [],
60
+ result: input.result,
61
+ recovery: [
62
+ "BAD_REQUEST: correct the named option and call again.",
63
+ "UNAUTHORIZED: start browser sign-in and let the person complete consent.",
64
+ "FORBIDDEN: leave the credential unchanged and report the governing account policy.",
65
+ "INTERNAL: call doctor, report the failing boundary, and stop repeating the call."
66
+ ],
67
+ next: input.next,
68
+ examples: [{
69
+ input: input.exampleInput,
70
+ output: input.exampleOutput
71
+ }]
72
+ });
73
+ const definition = (input) => toCapabilityDefinition({
74
+ ...input,
75
+ source: "composite",
76
+ idempotency: input.operation === "query" ? "none" : "single",
77
+ execution: {
78
+ kind: "composite",
79
+ procedures: []
80
+ },
81
+ meta: { description: input.guide.summary },
82
+ policy: {
83
+ exposure: "mcp-transport",
84
+ reason: "The local MCP runtime owns its own authentication and installation diagnostics.",
85
+ owner: "mcp"
86
+ },
87
+ cliPath: null,
88
+ inputExample: input.guide.examples[0]?.input,
89
+ outputExample: input.guide.examples[0]?.output
90
+ });
91
+ const capabilities = [
92
+ definition({
93
+ id: "auth.login",
94
+ operation: "mutation",
95
+ effect: "external",
96
+ inputSchema: loginInputSchema,
97
+ outputSchema: pendingLoginSchema,
98
+ guide: guideFor({
99
+ summary: "Open browser sign-in and store a revocable user-scoped Enhance credential.",
100
+ useWhen: "Use when Enhance is not authenticated or its credential was revoked.",
101
+ result: "Returns waiting_for_browser and the exact sign-in URL immediately. Show this URL to the person if their browser restores another page. Consent continues in the background; auth.status reports completion or a failure.",
102
+ next: ["Show the sign-in URL, then check auth.status after the person finishes. Only report success after authenticated is true and a canvas read succeeds."],
103
+ exampleInput: { openBrowser: true },
104
+ exampleOutput: {
105
+ authenticated: false,
106
+ status: "waiting_for_browser",
107
+ url: "https://app.example.test/oauth/authorize?client_id=client_enhance_cli"
108
+ }
109
+ })
110
+ }),
111
+ definition({
112
+ id: "auth.logout",
113
+ operation: "mutation",
114
+ effect: "delete",
115
+ inputSchema: statusInputSchema,
116
+ outputSchema: logoutOutputSchema,
117
+ guide: guideFor({
118
+ summary: "Remove the user-scoped local Enhance credential.",
119
+ useWhen: "Use only when the person asks to disconnect this local agent host.",
120
+ result: "Reports whether a local credential was removed without returning its value.",
121
+ next: ["Call auth.status to confirm the local runtime is disconnected."],
122
+ exampleInput: {},
123
+ exampleOutput: { loggedOut: true }
124
+ })
125
+ }),
126
+ definition({
127
+ id: "auth.status",
128
+ operation: "query",
129
+ effect: "read",
130
+ inputSchema: statusInputSchema,
131
+ outputSchema: statusOutputSchema,
132
+ guide: guideFor({
133
+ summary: "Check whether the local Enhance MCP runtime is authenticated.",
134
+ useWhen: "Use before a workflow or after login, logout, expiry, or an authorization failure.",
135
+ result: "Returns safe identity metadata, a pending sign-in URL, a sign-in failure, or authenticated false; never a credential value.",
136
+ next: ["While waiting_for_browser, show the URL and let the person finish. After failure, report the error before retrying auth.login. Continue the workflow only when authenticated is true."],
137
+ exampleInput: {},
138
+ exampleOutput: { authenticated: false }
139
+ })
140
+ }),
141
+ definition({
142
+ id: "doctor",
143
+ operation: "query",
144
+ effect: "read",
145
+ inputSchema: statusInputSchema,
146
+ outputSchema: doctorOutputSchema,
147
+ guide: guideFor({
148
+ summary: "Check MCP runtime identity, API reachability, and credential presence without changes.",
149
+ useWhen: "Use after repeated connection, authentication, or compatibility failure.",
150
+ result: "Returns bounded diagnostics without machine paths, credentials, or customer data.",
151
+ next: ["Follow the failing boundary; do not repeat a mutation while diagnostics are degraded."],
152
+ exampleInput: {},
153
+ exampleOutput: {
154
+ status: "ok",
155
+ runtimeVersion: "0.1.13",
156
+ api: {
157
+ reachable: true,
158
+ status: 200
159
+ },
160
+ credential: { present: true }
161
+ }
162
+ })
163
+ })
164
+ ].toSorted((left, right) => left.id.localeCompare(right.id));
165
+ const createMcpTransportCapabilityAdapter = () => capabilities;
166
+
167
+ //#endregion
8
168
  //#region src/mcp-main.ts
9
169
  const credentials = createFileCredentialAdapter(CLI_CONFIG.configDirectory);
10
- const invocation = createMcpInvocationAdapter(CLI_CONFIG.apiUrl, credentials, CLI_CONFIG.configDirectory);
170
+ const invocation = createMcpInvocationAdapter(CLI_CONFIG.apiUrl, credentials, CLI_CONFIG.configDirectory, "0.1.13");
171
+ const catalog = [...createCapabilityCatalogAdapter(), ...createMcpTransportCapabilityAdapter()];
11
172
  serveStdio(() => createMcpServerAdapter({
12
- version: "0.1.6",
13
- invocation
173
+ version: "0.1.13",
174
+ name: CLI_CONFIG.mcpServiceName,
175
+ commandName: CLI_CONFIG.commandName,
176
+ invocation,
177
+ catalog,
178
+ exposures: ["shared", "mcp-transport"]
14
179
  }), {
15
180
  legacy: "serve",
16
- onerror: () => process.stderr.write("enhance-mcp transport failure\n")
181
+ onerror: () => process.stderr.write(`${CLI_CONFIG.mcpServiceName} transport failure\n`)
17
182
  });
183
+
18
184
  //#endregion
19
- export {};
185
+ export { };