melchizedek-agents 1.1.0 → 1.3.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.
Files changed (146) hide show
  1. package/.env.example +19 -0
  2. package/AGENT_SETUP.md +3 -1
  3. package/CHANGELOG.md +373 -0
  4. package/DOCUMENTATION.md +193 -21
  5. package/ONBOARDING.md +378 -0
  6. package/QUICKSTART.md +15 -2
  7. package/README.md +26 -3
  8. package/config/agents/examples/connectors.yaml +82 -0
  9. package/config/agents/examples/council.yaml +1 -1
  10. package/config/agents/examples/critic.yaml +8 -8
  11. package/config/agents/examples/image_production.yaml +4 -3
  12. package/config/agents/syndicate.schema.json +389 -33
  13. package/config/agents/syndicateSchema.yaml +18 -6
  14. package/config/agents/templates/intake_extractor.yaml +3 -2
  15. package/config/agents/templates/systems_operator.yaml +5 -2
  16. package/dist/lib/a2a/app.d.ts +12 -0
  17. package/dist/lib/a2a/app.js +25 -11
  18. package/dist/lib/a2a/executor.js +14 -6
  19. package/dist/lib/a2a/oauthSetup.d.ts +16 -0
  20. package/dist/lib/a2a/oauthSetup.js +77 -8
  21. package/dist/lib/agentDialect.d.ts +18 -8
  22. package/dist/lib/agentDialect.js +36 -19
  23. package/dist/lib/chatgpt/adapter.d.ts +50 -0
  24. package/dist/lib/chatgpt/adapter.js +107 -0
  25. package/dist/lib/chatgpt/cli.d.ts +23 -0
  26. package/dist/lib/chatgpt/cli.js +77 -0
  27. package/dist/lib/chatgpt/oauth.d.ts +103 -0
  28. package/dist/lib/chatgpt/oauth.js +448 -0
  29. package/dist/lib/chatgpt/state.d.ts +98 -0
  30. package/dist/lib/chatgpt/state.js +145 -0
  31. package/dist/lib/chatgpt/store.d.ts +24 -0
  32. package/dist/lib/chatgpt/store.js +94 -0
  33. package/dist/lib/compile.d.ts +38 -7
  34. package/dist/lib/compile.js +97 -62
  35. package/dist/lib/compileNative.d.ts +11 -3
  36. package/dist/lib/compileNative.js +18 -1
  37. package/dist/lib/dispatch.js +6 -2
  38. package/dist/lib/doctor.d.ts +107 -0
  39. package/dist/lib/doctor.js +217 -7
  40. package/dist/lib/loadSyndicate.d.ts +15 -0
  41. package/dist/lib/mcp/server.d.ts +195 -0
  42. package/dist/lib/mcp/server.js +564 -0
  43. package/dist/lib/memory/supabaseMemoryService.js +2 -2
  44. package/dist/lib/models/adapterResolver.js +6 -1
  45. package/dist/lib/models/capabilities.d.ts +9 -0
  46. package/dist/lib/models/capabilities.js +24 -0
  47. package/dist/lib/models/chatCompletionsAdapter.d.ts +11 -3
  48. package/dist/lib/models/chatCompletionsAdapter.js +19 -5
  49. package/dist/lib/models/claudeAdapter.js +4 -0
  50. package/dist/lib/models/contract.d.ts +5 -2
  51. package/dist/lib/models/gateway.d.ts +3 -2
  52. package/dist/lib/models/gateway.js +8 -4
  53. package/dist/lib/models/gatewayAdapter.d.ts +7 -1
  54. package/dist/lib/models/gatewayAdapter.js +8 -0
  55. package/dist/lib/models/geminiAdapter.js +8 -2
  56. package/dist/lib/models/genaiMapping.d.ts +8 -4
  57. package/dist/lib/models/genaiMapping.js +23 -9
  58. package/dist/lib/models/gptAdapter.d.ts +4 -2
  59. package/dist/lib/models/gptAdapter.js +11 -4
  60. package/dist/lib/models/grokAdapter.d.ts +3 -1
  61. package/dist/lib/models/grokAdapter.js +11 -3
  62. package/dist/lib/models/kimiAdapter.d.ts +2 -1
  63. package/dist/lib/models/kimiAdapter.js +3 -3
  64. package/dist/lib/models/reasoning.d.ts +30 -2
  65. package/dist/lib/models/reasoning.js +56 -5
  66. package/dist/lib/onboarding.d.ts +135 -0
  67. package/dist/lib/onboarding.js +578 -0
  68. package/dist/lib/runtime/approvals.d.ts +2 -0
  69. package/dist/lib/runtime/approvals.js +4 -3
  70. package/dist/lib/runtime/credentials.d.ts +6 -0
  71. package/dist/lib/runtime/native/agentLoop.d.ts +5 -2
  72. package/dist/lib/runtime/native/agentLoop.js +2 -0
  73. package/dist/lib/runtime/native/checkpoint.d.ts +12 -5
  74. package/dist/lib/runtime/native/checkpoint.js +13 -19
  75. package/dist/lib/runtime/native/delegate.d.ts +82 -1
  76. package/dist/lib/runtime/native/delegate.js +157 -2
  77. package/dist/lib/runtime/native/interrupts.d.ts +88 -5
  78. package/dist/lib/runtime/native/interrupts.js +220 -30
  79. package/dist/lib/runtime/syndicateTurn.d.ts +4 -2
  80. package/dist/lib/runtime/syndicateTurn.js +324 -77
  81. package/dist/lib/runtime/turnControl.d.ts +41 -0
  82. package/dist/lib/session/transcript.d.ts +9 -0
  83. package/dist/lib/session/transcript.js +20 -1
  84. package/dist/lib/skills.d.ts +18 -0
  85. package/dist/lib/skills.js +73 -1
  86. package/dist/lib/storage/postgres/index.d.ts +6 -1
  87. package/dist/lib/storage/postgres/index.js +1 -1
  88. package/dist/lib/storage/postgres/taskQueue.d.ts +7 -3
  89. package/dist/lib/storage/postgres/taskQueue.js +10 -3
  90. package/dist/lib/syndicateSchema.d.ts +184 -9
  91. package/dist/lib/syndicateSchema.js +143 -29
  92. package/dist/lib/tools/auth.d.ts +13 -1
  93. package/dist/lib/tools/auth.js +10 -2
  94. package/dist/lib/tools/credentialHosts.d.ts +88 -0
  95. package/dist/lib/tools/credentialHosts.js +165 -0
  96. package/dist/lib/tools/credentialUses.d.ts +98 -0
  97. package/dist/lib/tools/credentialUses.js +120 -0
  98. package/dist/lib/tools/generateImageTool.js +2 -1
  99. package/dist/lib/tools/inspectImageTool.js +1 -1
  100. package/dist/lib/tools/mcpToolFactory.d.ts +29 -1
  101. package/dist/lib/tools/mcpToolFactory.js +72 -26
  102. package/dist/lib/tools/mcpTransports.d.ts +12 -0
  103. package/dist/lib/tools/mcpTransports.js +11 -0
  104. package/dist/lib/tools/oauthConsent.d.ts +18 -3
  105. package/dist/lib/tools/oauthConsent.js +57 -15
  106. package/dist/lib/tools/oauthDiscovery.d.ts +202 -0
  107. package/dist/lib/tools/oauthDiscovery.js +616 -0
  108. package/dist/lib/tools/oauthHosts.d.ts +2 -0
  109. package/dist/lib/tools/oauthHosts.js +2 -2
  110. package/dist/lib/tools/oauthTools.d.ts +54 -13
  111. package/dist/lib/tools/oauthTools.js +106 -23
  112. package/dist/lib/tools/openapiTools.d.ts +7 -0
  113. package/dist/lib/tools/openapiTools.js +49 -3
  114. package/dist/lib/tools/taskTools.d.ts +32 -2
  115. package/dist/lib/tools/taskTools.js +93 -33
  116. package/dist/lib/tools/xApiSearchTool.js +2 -2
  117. package/dist/lib/workflow/turn.d.ts +22 -3
  118. package/dist/lib/workflow/turn.js +151 -31
  119. package/dist/lib/workflow.d.ts +10 -7
  120. package/dist/lib/workflow.js +10 -7
  121. package/dist/scripts/a2a_server.d.ts +2 -2
  122. package/dist/scripts/a2a_server.js +19 -2
  123. package/dist/scripts/assistant_worker.d.ts +2 -0
  124. package/dist/scripts/assistant_worker.js +24 -5
  125. package/dist/scripts/doctor.d.ts +4 -2
  126. package/dist/scripts/doctor.js +6 -4
  127. package/dist/scripts/mcp_server.d.ts +12 -0
  128. package/dist/scripts/mcp_server.js +345 -0
  129. package/dist/scripts/setup.d.ts +25 -0
  130. package/dist/scripts/setup.js +181 -0
  131. package/dist/scripts/skills_install.d.ts +3 -1
  132. package/dist/scripts/skills_install.js +17 -2
  133. package/dist/scripts/syndicate_chat.js +12 -3
  134. package/dist/scripts/yaml_codemod.d.ts +12 -2
  135. package/dist/scripts/yaml_codemod.js +115 -33
  136. package/package.json +8 -2
  137. package/skills/README.md +11 -2
  138. package/skills/briefs/_shared.md +1 -1
  139. package/skills/briefs/melchizedek-models.md +4 -2
  140. package/skills/briefs/skills-readme.md +3 -1
  141. package/skills/melchizedek-models/SKILL.md +6 -2
  142. package/skills/melchizedek-onboard/SKILL.md +71 -0
  143. package/skills/melchizedek-onboard-cloud/SKILL.md +38 -0
  144. package/skills/melchizedek-onboard-keys/SKILL.md +47 -0
  145. package/skills/melchizedek-onboard-local/SKILL.md +41 -0
  146. package/skills/melchizedek-onboard-serve/SKILL.md +43 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * lib/tools/oauthDiscovery.ts — an MCP server's authorization server,
3
+ * discovered, and this deployment registered at it as an OAuth client
4
+ * (ADR 0124).
5
+ *
6
+ * WHY this file exists:
7
+ * The official remote MCP servers (an issue tracker's, a wiki's, a code
8
+ * host's) take each user's own OAuth token, and most issue no client id in
9
+ * advance: the MCP authorization spec has a client find the authorization
10
+ * server from the MCP server (protected-resource metadata, RFC 9728; then
11
+ * authorization-server metadata, RFC 8414 or OpenID discovery) and register
12
+ * itself (dynamic client registration, RFC 7591). A YAML says so with
13
+ * `client_registration: dynamic` on the server's `oauth2` grant; this module
14
+ * does the discovery and the registration, and keeps the registered client.
15
+ *
16
+ * WHAT IT GUARANTEES:
17
+ * - The MCP server is asked first, as the MCP authorization spec has a
18
+ * client do: an unauthenticated initialize request, and on a 401 the
19
+ * Bearer challenge's `resource_metadata` (and `scope`) parameters in its
20
+ * WWW-Authenticate header (RFC 9728 5.1). The URL it names is read first;
21
+ * the well-known URLs are the fallback. The header is read by a linear,
22
+ * length-bounded tokenizer (no regular expression), and never logged.
23
+ * - Discovery never widens the operator's OAuth host allowlist (ADR 0114):
24
+ * every URL it fetches (the MCP server's challenge, the metadata
25
+ * documents, including one the header names, the registration
26
+ * endpoint) and every endpoint it returns (authorization, token) must be
27
+ * a host the allowlist binds to the provider, checked before the request
28
+ * and again whenever the client is used. A discovered host outside it is
29
+ * refused by name, not skipped.
30
+ * - Every request passes the transport rule (https, or http to a loopback
31
+ * host) and the SSRF guard (lib/net/addressGuard.ts) unless private hosts
32
+ * are allowed (ALLOW_PRIVATE_MCP), follows no redirect, has a time limit,
33
+ * and reads a bounded JSON body.
34
+ * - The authorization server must advertise PKCE S256; one that does not is
35
+ * refused (MCP authorization spec). The client registers as a public
36
+ * client (`token_endpoint_auth_method: none`) for the one configured
37
+ * redirect URI, with the authorization_code and refresh_token grants.
38
+ * - The registered client is kept per provider, MCP server and redirect URI
39
+ * in the credential store's rows, sealed by its cipher
40
+ * (MELCHIZEDEK_CREDENTIAL_KEY), under an app name no run can have (it
41
+ * carries `:`, which a memory namespace cannot), so no tool call can read
42
+ * it as a token. A row this key cannot open, an expired client secret, or
43
+ * endpoints that moved are registered again.
44
+ * - No client secret, metadata body or server error text reaches a log
45
+ * line, an error message or a result: refusals name roles and hosts.
46
+ */
47
+ import type { CredentialKey } from './auth.ts';
48
+ import type { CredentialCipher } from './credentialCipher.ts';
49
+ import type { CredentialRows } from './credentialStore.ts';
50
+ import type { OAuthHostAllowlist } from './oauthHosts.ts';
51
+ import type { OAuthClientSource } from './oauthConsent.ts';
52
+ /** A discovery or registration that cannot proceed. The message names roles and hosts, never a value. */
53
+ export declare class OAuthDiscoveryError extends Error {
54
+ readonly provider: string;
55
+ constructor(provider: string, message: string);
56
+ }
57
+ /** What discovery found: the MCP server as a resource, and its authorization server's endpoints. */
58
+ export interface DiscoveredAuthorization {
59
+ /** The MCP server's canonical URI, sent as the RFC 8707 `resource` parameter. */
60
+ resource: string;
61
+ /** The authorization server's issuer identifier. */
62
+ issuer: string;
63
+ authorizationEndpoint: string;
64
+ tokenEndpoint: string;
65
+ registrationEndpoint: string;
66
+ /**
67
+ * The scopes the MCP server's 401 challenge named (its `scope` parameter),
68
+ * when it named any: the MCP spec's first choice when the grant names none.
69
+ */
70
+ challengeScopes?: string[];
71
+ }
72
+ export interface DiscoveryOptions {
73
+ /** The provider the grant names: the allowlist is read for it. */
74
+ provider: string;
75
+ /** Private and loopback hosts pass the SSRF guard (ALLOW_PRIVATE_MCP). The allowlist still applies. */
76
+ allowPrivate?: boolean;
77
+ /** The allowlist; default the one in force (`null`: none configured, which refuses). */
78
+ allowlist?: OAuthHostAllowlist | null;
79
+ /** Each request's time limit, ms. Default 10 s. */
80
+ timeoutMs?: number;
81
+ /** For tests. */
82
+ fetch?: typeof fetch;
83
+ }
84
+ /** The MCP server's canonical URI (RFC 8707, MCP authorization spec): no fragment, no trailing slash on a path. */
85
+ export declare function canonicalResource(serverUrl: string): string;
86
+ /** A WWW-Authenticate header longer than this is ignored whole. */
87
+ export declare const MAX_CHALLENGE_HEADER: number;
88
+ /** What a Bearer challenge tells a client that has no token yet. */
89
+ export interface BearerChallenge {
90
+ /** The `resource_metadata` parameter: the protected-resource metadata URL (RFC 9728 5.1), unparsed. */
91
+ resourceMetadata?: string;
92
+ /** The `scope` parameter, split, each a valid scope token (RFC 6750 3). */
93
+ scopes?: string[];
94
+ }
95
+ /**
96
+ * The first Bearer challenge's parameters in a WWW-Authenticate header, or
97
+ * undefined (no Bearer challenge, or a header that is too long or malformed:
98
+ * either is ignored whole, and discovery falls back to the well-known URLs).
99
+ * One pass over the header, each step advancing: linear in its length, with
100
+ * no regular expression. Several challenges in one header, quoted-string
101
+ * values with escapes, case-insensitive scheme and parameter names, and a
102
+ * token68 credential on another scheme are understood. A parameter given
103
+ * twice in the Bearer challenge makes it ambiguous, and malformed.
104
+ */
105
+ export declare function parseBearerChallenge(header: string | null | undefined): BearerChallenge | undefined;
106
+ /** RFC 9728 3.1: the protected-resource metadata URLs for a server, path-specific first. */
107
+ export declare function protectedResourceMetadataUrls(serverUrl: string): URL[];
108
+ /** RFC 8414 3.1 and OpenID discovery, in the order the MCP authorization spec gives. */
109
+ export declare function authorizationServerMetadataUrls(issuer: string): URL[];
110
+ /**
111
+ * The MCP server's authorization server, as the MCP authorization spec finds
112
+ * it: the protected-resource metadata URL named by the server's 401 challenge
113
+ * (WWW-Authenticate, RFC 9728 5.1), then the well-known URLs (RFC 9728 3.1);
114
+ * the metadata names the authorization server (a server with none is its
115
+ * own, as the 2025-03-26 revision had it), and its own metadata (RFC 8414, or
116
+ * OpenID discovery) names the endpoints. Every host involved, the one the
117
+ * header names included, passes the provider's allowlist before any request;
118
+ * PKCE S256 and a registration endpoint are required. Throws
119
+ * OAuthDiscoveryError.
120
+ */
121
+ export declare function discoverAuthorization(serverUrl: string, options: DiscoveryOptions): Promise<DiscoveredAuthorization>;
122
+ /** A client this deployment registered at an authorization server. */
123
+ export interface RegisteredClient {
124
+ clientId: string;
125
+ /** A confidential client's secret, when the server issued one anyway. */
126
+ clientSecret?: string;
127
+ /** Epoch ms after which the secret stops working; absent when it does not expire. */
128
+ secretExpiresAt?: number;
129
+ }
130
+ export interface RegistrationOptions extends DiscoveryOptions {
131
+ /** The consent callback, exactly as every authorization will send it. */
132
+ redirectUri: string;
133
+ /** Shown to the person on the provider's consent screen. Default "Melchizedek agents". */
134
+ clientName?: string;
135
+ scopes?: string[];
136
+ }
137
+ /**
138
+ * Registers this deployment at the authorization server (RFC 7591) as a
139
+ * public PKCE client for the one redirect URI. Throws OAuthDiscoveryError,
140
+ * never the server's text.
141
+ */
142
+ export declare function registerOAuthClient(discovered: DiscoveredAuthorization, options: RegistrationOptions): Promise<RegisteredClient>;
143
+ /**
144
+ * The app name registered clients are filed under. It carries `:`, which a
145
+ * memory namespace (the app a run pins, `[A-Za-z0-9._-]`) cannot, so no
146
+ * run's credential key ever reaches one of these rows.
147
+ */
148
+ export declare const REGISTERED_CLIENTS_APP = "oauth-client:dcr";
149
+ /** The row a provider's registered client is kept in: one per MCP server (resource) and redirect URI. */
150
+ export declare function registeredClientKey(provider: string, resource: string, redirectUri: string): CredentialKey;
151
+ /** What a sealed registration holds. */
152
+ interface StoredRegistration {
153
+ v: 1;
154
+ clientId: string;
155
+ clientSecret?: string;
156
+ issuer: string;
157
+ authorizationEndpoint: string;
158
+ tokenEndpoint: string;
159
+ resource: string;
160
+ redirectUri: string;
161
+ }
162
+ export interface OAuthClientRegistry {
163
+ /** The registration kept for this key, or undefined (none, unreadable under this key, or its secret expired). */
164
+ get(key: CredentialKey): Promise<(StoredRegistration & {
165
+ secretExpiresAt?: number;
166
+ }) | undefined>;
167
+ put(key: CredentialKey, registration: Omit<StoredRegistration, 'v'>, secretExpiresAt?: number): Promise<void>;
168
+ }
169
+ /** Registered clients over the credential store's rows, sealed by its cipher (the same key as every user's tokens). */
170
+ export declare function oauthClientRegistry(options: {
171
+ rows: CredentialRows;
172
+ cipher: CredentialCipher;
173
+ now?: () => number;
174
+ }): OAuthClientRegistry;
175
+ /** A dynamic grant as a served YAML declares it (lib/tools/oauthTools.ts dynamicOAuthGrantsFor). */
176
+ export interface DynamicOAuthGrant {
177
+ provider: string;
178
+ /** The MCP server the grant is for. */
179
+ server: string;
180
+ scopes: string[];
181
+ authorizationParams?: Record<string, string>;
182
+ }
183
+ export interface DynamicClientOptions {
184
+ /** The consent callback, as configured (OAUTH_REDIRECT_URI). */
185
+ redirectUri: string;
186
+ /** Where registrations are kept; without one, each process registers once in memory. */
187
+ registry?: OAuthClientRegistry;
188
+ allowPrivate?: boolean;
189
+ clientName?: string;
190
+ timeoutMs?: number;
191
+ fetch?: typeof fetch;
192
+ /** For tests. */
193
+ allowlist?: OAuthHostAllowlist | null;
194
+ }
195
+ /**
196
+ * The consent step's client for a dynamic grant (oauthConsent and
197
+ * oauthRefreshProviders take it in place of a fixed config): discovered and
198
+ * registered on first use, kept, and re-checked against the allowlist in
199
+ * force on every use. A failure is not cached; the next use tries again.
200
+ */
201
+ export declare function dynamicOAuthClient(grant: DynamicOAuthGrant, options: DynamicClientOptions): OAuthClientSource;
202
+ export {};