@enhance-eng/enhance 0.1.5 → 0.1.7

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