melchizedek-agents 1.0.3 → 1.2.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 (172) hide show
  1. package/.env.example +29 -2
  2. package/AGENT_SETUP.md +3 -1
  3. package/CHANGELOG.md +524 -0
  4. package/DOCUMENTATION.md +178 -43
  5. package/ONBOARDING.md +339 -0
  6. package/QUICKSTART.md +15 -2
  7. package/README.md +6 -2
  8. package/config/agents/README.md +2 -2
  9. package/config/agents/examples/ares.yaml +6 -10
  10. package/config/agents/examples/assistant.yaml +6 -6
  11. package/config/agents/examples/augustin.yaml +9 -15
  12. package/config/agents/examples/cartographers.yaml +6 -6
  13. package/config/agents/examples/council.yaml +7 -7
  14. package/config/agents/examples/critic.yaml +24 -24
  15. package/config/agents/examples/harness.yaml +4 -4
  16. package/config/agents/examples/image_production.yaml +37 -35
  17. package/config/agents/examples/librarian.yaml +4 -4
  18. package/config/agents/examples/patient_advocate.yaml +6 -10
  19. package/config/agents/examples/pipeline.yaml +20 -19
  20. package/config/agents/examples/research.yaml +36 -43
  21. package/config/agents/examples/scribe.yaml +31 -32
  22. package/config/agents/examples/scriptorium.yaml +6 -6
  23. package/config/agents/examples/structured_critic.yaml +82 -0
  24. package/config/agents/examples/style_council.yaml +9 -11
  25. package/config/agents/examples/syndicate.yaml +3 -5
  26. package/config/agents/examples/tutor.yaml +2 -2
  27. package/config/agents/examples/weather.yaml +2 -2
  28. package/config/agents/syndicate.schema.json +859 -13
  29. package/config/agents/syndicateSchema.yaml +122 -73
  30. package/config/agents/templates/README.md +1 -1
  31. package/config/agents/templates/account_memory.yaml +4 -4
  32. package/config/agents/templates/case_desk.yaml +6 -6
  33. package/config/agents/templates/conversational.yaml +2 -2
  34. package/config/agents/templates/draft_review.yaml +6 -6
  35. package/config/agents/templates/intake_extractor.yaml +64 -62
  36. package/config/agents/templates/research_brief.yaml +6 -6
  37. package/config/agents/templates/research_desk.yaml +6 -6
  38. package/config/agents/templates/review_panel.yaml +8 -8
  39. package/config/agents/templates/support_triage.yaml +30 -29
  40. package/config/agents/templates/systems_operator.yaml +24 -5
  41. package/db/migrations/0014_durable_runs.sql +31 -0
  42. package/dist/lib/a2a/app.d.ts +27 -0
  43. package/dist/lib/a2a/app.js +64 -5
  44. package/dist/lib/a2a/executor.d.ts +7 -1
  45. package/dist/lib/a2a/executor.js +43 -5
  46. package/dist/lib/a2a/oauthSetup.d.ts +106 -0
  47. package/dist/lib/a2a/oauthSetup.js +259 -0
  48. package/dist/lib/agentDialect.d.ts +76 -0
  49. package/dist/lib/agentDialect.js +151 -0
  50. package/dist/lib/compile.d.ts +42 -6
  51. package/dist/lib/compile.js +97 -45
  52. package/dist/lib/compileNative.d.ts +11 -3
  53. package/dist/lib/compileNative.js +20 -1
  54. package/dist/lib/dispatch.d.ts +10 -5
  55. package/dist/lib/dispatch.js +10 -5
  56. package/dist/lib/doctor.d.ts +110 -1
  57. package/dist/lib/doctor.js +205 -9
  58. package/dist/lib/loadSyndicate.d.ts +54 -2
  59. package/dist/lib/loadSyndicate.js +22 -2
  60. package/dist/lib/memory/namespace.d.ts +6 -5
  61. package/dist/lib/memory/namespace.js +6 -5
  62. package/dist/lib/memory/providers.js +3 -4
  63. package/dist/lib/models/capabilities.d.ts +25 -1
  64. package/dist/lib/models/capabilities.js +79 -1
  65. package/dist/lib/models/chatCompletionsAdapter.d.ts +11 -3
  66. package/dist/lib/models/chatCompletionsAdapter.js +19 -5
  67. package/dist/lib/models/claudeAdapter.js +4 -0
  68. package/dist/lib/models/contract.d.ts +5 -2
  69. package/dist/lib/models/gateway.d.ts +2 -1
  70. package/dist/lib/models/gateway.js +4 -2
  71. package/dist/lib/models/gatewayAdapter.d.ts +7 -1
  72. package/dist/lib/models/gatewayAdapter.js +8 -0
  73. package/dist/lib/models/geminiAdapter.js +8 -2
  74. package/dist/lib/models/genaiMapping.d.ts +8 -4
  75. package/dist/lib/models/genaiMapping.js +23 -9
  76. package/dist/lib/models/gptAdapter.d.ts +4 -2
  77. package/dist/lib/models/gptAdapter.js +11 -4
  78. package/dist/lib/models/grokAdapter.d.ts +3 -1
  79. package/dist/lib/models/grokAdapter.js +11 -3
  80. package/dist/lib/models/kimiAdapter.d.ts +2 -1
  81. package/dist/lib/models/kimiAdapter.js +3 -3
  82. package/dist/lib/models/reasoning.d.ts +30 -2
  83. package/dist/lib/models/reasoning.js +56 -5
  84. package/dist/lib/observability/tracer.d.ts +8 -1
  85. package/dist/lib/observability/tracer.js +33 -5
  86. package/dist/lib/onboarding.d.ts +134 -0
  87. package/dist/lib/onboarding.js +539 -0
  88. package/dist/lib/runtime/approvals.d.ts +8 -0
  89. package/dist/lib/runtime/approvals.js +4 -3
  90. package/dist/lib/runtime/credentials.d.ts +6 -0
  91. package/dist/lib/runtime/native/agentLoop.d.ts +23 -3
  92. package/dist/lib/runtime/native/agentLoop.js +107 -11
  93. package/dist/lib/runtime/native/checkpoint.d.ts +171 -0
  94. package/dist/lib/runtime/native/checkpoint.js +359 -0
  95. package/dist/lib/runtime/native/delegate.d.ts +222 -18
  96. package/dist/lib/runtime/native/delegate.js +390 -39
  97. package/dist/lib/runtime/native/interrupts.d.ts +184 -2
  98. package/dist/lib/runtime/native/interrupts.js +391 -1
  99. package/dist/lib/runtime/native/request.d.ts +13 -3
  100. package/dist/lib/runtime/native/request.js +28 -4
  101. package/dist/lib/runtime/native/telemetry.js +10 -15
  102. package/dist/lib/runtime/questions.d.ts +7 -4
  103. package/dist/lib/runtime/sessions.d.ts +1 -1
  104. package/dist/lib/runtime/syndicateTurn.d.ts +11 -3
  105. package/dist/lib/runtime/syndicateTurn.js +353 -68
  106. package/dist/lib/runtime/turnControl.d.ts +56 -0
  107. package/dist/lib/runtime/turnControl.js +10 -0
  108. package/dist/lib/session/transcript.d.ts +9 -0
  109. package/dist/lib/session/transcript.js +20 -1
  110. package/dist/lib/skills.d.ts +18 -0
  111. package/dist/lib/skills.js +73 -1
  112. package/dist/lib/storage/postgres/index.d.ts +12 -2
  113. package/dist/lib/storage/postgres/index.js +8 -3
  114. package/dist/lib/storage/postgres/taskQueue.d.ts +20 -4
  115. package/dist/lib/storage/postgres/taskQueue.js +29 -5
  116. package/dist/lib/storage/postgres/taskStore.d.ts +26 -2
  117. package/dist/lib/storage/postgres/taskStore.js +74 -8
  118. package/dist/lib/syndicateSchema.d.ts +316 -1
  119. package/dist/lib/syndicateSchema.js +203 -29
  120. package/dist/lib/tools/auth.d.ts +20 -6
  121. package/dist/lib/tools/auth.js +21 -5
  122. package/dist/lib/tools/credentialEnv.d.ts +28 -0
  123. package/dist/lib/tools/credentialEnv.js +52 -0
  124. package/dist/lib/tools/credentialHosts.d.ts +88 -0
  125. package/dist/lib/tools/credentialHosts.js +165 -0
  126. package/dist/lib/tools/credentialStore.js +9 -2
  127. package/dist/lib/tools/credentialUses.d.ts +92 -0
  128. package/dist/lib/tools/credentialUses.js +112 -0
  129. package/dist/lib/tools/mcpToolFactory.d.ts +25 -2
  130. package/dist/lib/tools/mcpToolFactory.js +179 -21
  131. package/dist/lib/tools/oauthConsent.js +8 -1
  132. package/dist/lib/tools/oauthHosts.d.ts +73 -0
  133. package/dist/lib/tools/oauthHosts.js +154 -0
  134. package/dist/lib/tools/oauthTools.d.ts +242 -0
  135. package/dist/lib/tools/oauthTools.js +447 -0
  136. package/dist/lib/tools/openapiTools.d.ts +11 -6
  137. package/dist/lib/tools/openapiTools.js +88 -38
  138. package/dist/lib/tools/taskTools.d.ts +61 -6
  139. package/dist/lib/tools/taskTools.js +145 -21
  140. package/dist/lib/workflow/turn.d.ts +22 -3
  141. package/dist/lib/workflow/turn.js +151 -31
  142. package/dist/lib/workflow.d.ts +14 -7
  143. package/dist/lib/workflow.js +14 -7
  144. package/dist/lib/workflowConfig.d.ts +6 -0
  145. package/dist/scripts/a2a_server.d.ts +36 -0
  146. package/dist/scripts/a2a_server.js +131 -1
  147. package/dist/scripts/assistant_worker.d.ts +12 -0
  148. package/dist/scripts/assistant_worker.js +81 -22
  149. package/dist/scripts/doctor.d.ts +7 -2
  150. package/dist/scripts/doctor.js +9 -4
  151. package/dist/scripts/setup.d.ts +23 -0
  152. package/dist/scripts/setup.js +154 -0
  153. package/dist/scripts/skills_install.d.ts +3 -1
  154. package/dist/scripts/skills_install.js +17 -2
  155. package/dist/scripts/yaml_codemod.d.ts +62 -0
  156. package/dist/scripts/yaml_codemod.js +652 -0
  157. package/package.json +8 -2
  158. package/skills/README.md +11 -2
  159. package/skills/briefs/_shared.md +1 -1
  160. package/skills/briefs/melchizedek-author.md +7 -5
  161. package/skills/briefs/melchizedek-models.md +7 -4
  162. package/skills/briefs/melchizedek.md +1 -0
  163. package/skills/briefs/skills-readme.md +3 -1
  164. package/skills/melchizedek/SKILL.md +1 -0
  165. package/skills/melchizedek-author/SKILL.md +7 -4
  166. package/skills/melchizedek-author/assets/minimal.yaml +13 -13
  167. package/skills/melchizedek-models/SKILL.md +11 -4
  168. package/skills/melchizedek-onboard/SKILL.md +49 -0
  169. package/skills/melchizedek-onboard-cloud/SKILL.md +38 -0
  170. package/skills/melchizedek-onboard-keys/SKILL.md +35 -0
  171. package/skills/melchizedek-onboard-local/SKILL.md +41 -0
  172. package/skills/melchizedek-onboard-serve/SKILL.md +43 -0
@@ -0,0 +1,242 @@
1
+ /**
2
+ * lib/tools/oauthTools.ts — `auth: { oauth2 }` from a syndicate YAML: an
3
+ * OpenAPI entry or an MCP server whose calls carry an OAuth access token
4
+ * (WS6-3c, ADR 0112).
5
+ *
6
+ * WHY this file exists:
7
+ * The credential store (ADR 0072) holds each user's tokens and the consent
8
+ * step (ADR 0085) puts them there, but nothing said which tools send which
9
+ * provider's token. The YAML says it, next to the tool it protects:
10
+ *
11
+ * openapi:
12
+ * - spec: specs/tracker.yaml
13
+ * auth:
14
+ * oauth2:
15
+ * provider: tracker
16
+ * grant: authorization_code
17
+ * authorization_url: https://tracker.example.com/oauth/authorize
18
+ * token_url: https://tracker.example.com/oauth/token
19
+ * client_id_env: TRACKER_CLIENT_ID
20
+ * client_secret_env: TRACKER_CLIENT_SECRET
21
+ * scopes: [issues:read]
22
+ *
23
+ * and `mcp_auth: { oauth2: { ... } }` beside an agent's `mcp_server_url`.
24
+ *
25
+ * THE TWO GRANTS:
26
+ * - authorization_code: the token is the run's own user's, read through
27
+ * `ctx.accessToken(provider)` at each call. A user who has not granted it
28
+ * is asked (the consent pause, when the run has a consent step whose
29
+ * clients include the provider: `oauthClientsFor` builds them from the
30
+ * same YAML, and `oauthRefreshProviders` the store's refresh hooks).
31
+ * The tool never chooses whose token.
32
+ * - client_credentials: the server's own token for the provider, from its
33
+ * token endpoint with the client id and secret, held in this process's
34
+ * memory until shortly before it expires, never in the credential store
35
+ * (no user owns it).
36
+ *
37
+ * SECRETS: the YAML names environment variables, never values; the variable
38
+ * names pass credentialEnvProblem (lib/tools/credentialEnv.ts), so a YAML
39
+ * cannot send a framework secret to a token endpoint. No token, client
40
+ * secret or provider error text reaches a result, an error, a log line or
41
+ * a span: a failure is reported by kind (ToolCredentialError).
42
+ *
43
+ * WHERE A TOKEN MAY GO: a token is sent only over https, or http to a
44
+ * loopback host (local development), to the server the YAML names, and
45
+ * only to a host the operator's allowlist binds to the provider
46
+ * (lib/tools/oauthHosts.ts, ADR 0114): with none configured, an
47
+ * authorization_code grant is refused. The allowlist is checked when a
48
+ * served syndicate loads (`syndicateOAuthHostProblems`), when the tools
49
+ * compile (the server, the token endpoint and the authorization
50
+ * endpoint), and again before each call sends a token
51
+ * (`oauthCallProblem`). The client-credentials token endpoint passes the
52
+ * same SSRF guard as the server it serves (ALLOW_PRIVATE_OPENAPI or
53
+ * ALLOW_PRIVATE_MCP), and no redirect from it is followed.
54
+ *
55
+ * WHERE A CLIENT SECRET MAY GO: to the token endpoint, and, when the
56
+ * operator configures a credential host allowlist
57
+ * (lib/tools/credentialHosts.ts, ADR 0122), only to a host it binds the
58
+ * `client_secret_env` variable to: checked at compile, when the consent
59
+ * clients are built, and before each client-credentials token request,
60
+ * code exchange (lib/tools/oauthConsent.ts) and refresh.
61
+ */
62
+ import type { OAuthProvider } from './auth.ts';
63
+ import type { OAuthHostAllowlist } from './oauthHosts.ts';
64
+ import type { OAuthClientConfig } from './oauthConsent.ts';
65
+ import type { ToolContext } from './tool.ts';
66
+ /** The `oauth2` block of an `auth` (OpenAPI) or an `mcp_auth` (MCP). */
67
+ export interface OAuth2AuthConfig {
68
+ /** The credential store's name for the provider (lowercase). */
69
+ provider: string;
70
+ grant: 'authorization_code' | 'client_credentials';
71
+ /** The provider's authorization endpoint (authorization_code only). */
72
+ authorization_url?: string;
73
+ /** The provider's token endpoint. */
74
+ token_url: string;
75
+ /** The client id, written out (it is not a secret) … */
76
+ client_id?: string;
77
+ /** … or the environment variable holding it. */
78
+ client_id_env?: string;
79
+ /** The environment variable holding the client secret. Required for client_credentials. */
80
+ client_secret_env?: string;
81
+ scopes?: string[];
82
+ /** Extra authorization parameters (authorization_code only), e.g. `access_type: offline`. */
83
+ authorization_params?: Record<string, string>;
84
+ }
85
+ /** An agent's `mcp_auth:` beside its `mcp_server_url`. */
86
+ export interface McpAuthConfig {
87
+ oauth2: OAuth2AuthConfig;
88
+ }
89
+ /** Where a declared grant sits: for the doctor, and for the error messages. */
90
+ export interface OAuthGrantUse {
91
+ /** The agent that holds the tools. */
92
+ agent: string;
93
+ /** `openapi <spec>` or `mcp <url>`. */
94
+ tools: string;
95
+ oauth2: OAuth2AuthConfig;
96
+ }
97
+ /** An agent's declared OAuth grants, OpenAPI entries first, then its MCP server. */
98
+ export declare function agentOAuthGrants(agent: {
99
+ name?: string;
100
+ openapi?: Array<{
101
+ spec?: string;
102
+ auth?: {
103
+ oauth2?: OAuth2AuthConfig;
104
+ };
105
+ }>;
106
+ mcp_server_url?: string;
107
+ mcp_auth?: {
108
+ oauth2?: OAuth2AuthConfig;
109
+ };
110
+ }, prefix?: string): OAuthGrantUse[];
111
+ /** The environment variables a grant reads, by role. */
112
+ export declare function oauthEnvNames(oauth2: OAuth2AuthConfig): string[];
113
+ /** Why a token may not be sent to `raw`, or null: https, or http to a loopback host. */
114
+ export declare function tokenTransportProblem(raw: string): string | null;
115
+ /**
116
+ * Why this grant may not be declared for these servers, one line per
117
+ * refusal: each server the tools call, the token endpoint and the
118
+ * authorization endpoint must be hosts the operator's allowlist binds to the
119
+ * provider (lib/tools/oauthHosts.ts). With no allowlist, an
120
+ * authorization_code grant is refused and a client_credentials one allowed.
121
+ * `allowlist` defaults to the one in force; `null` means none is configured.
122
+ */
123
+ export declare function oauthGrantHostProblems(oauth2: OAuth2AuthConfig, servers: readonly string[], allowlist?: OAuthHostAllowlist | null): string[];
124
+ /**
125
+ * Why a call may not send this grant's token (or secret) to `destination`
126
+ * now, or null: the transport rule and the allowlist in force, checked again
127
+ * at each call. The compile checked the same; this holds if a request is
128
+ * aimed elsewhere, or the allowlist changed. A malformed allowlist refuses.
129
+ */
130
+ export declare function oauthCallProblem(oauth2: Pick<OAuth2AuthConfig, 'provider' | 'grant'>, destination: string): string | null;
131
+ export interface ClientCredentialsOptions {
132
+ provider: string;
133
+ tokenUrl: string;
134
+ clientId: string;
135
+ clientSecret: string;
136
+ scopes?: string[];
137
+ /** Private and loopback token endpoints are allowed (ALLOW_PRIVATE_OPENAPI / ALLOW_PRIVATE_MCP). */
138
+ allowPrivate?: boolean;
139
+ /** A token this close to its expiry is fetched again. Default 60 s. */
140
+ refreshSkewMs?: number;
141
+ /** The token request's time limit, ms. Default 10 s. */
142
+ timeoutMs?: number;
143
+ /** For tests. */
144
+ fetch?: typeof fetch;
145
+ now?: () => number;
146
+ }
147
+ /**
148
+ * The server's own token for a provider (RFC 6749 4.4), fetched when first
149
+ * needed and again shortly before it expires, one request at a time. A
150
+ * failure throws ToolCredentialError('grant_failed'), never the provider's
151
+ * text, which may echo what it refused.
152
+ */
153
+ export declare function clientCredentialsGrant(options: ClientCredentialsOptions): {
154
+ token(signal?: AbortSignal): Promise<string>;
155
+ };
156
+ /**
157
+ * What a tool calls for the token of one call, naming where that call goes.
158
+ * Throws ToolCredentialError, whose message names no value: `host_refused`
159
+ * when the destination is not one of the provider's hosts (`allowlist`
160
+ * `'oauth'`), or when a client secret's token endpoint is not bound to its
161
+ * variable (`allowlist` `'credential'`).
162
+ */
163
+ export type OAuthTokenSource = (ctx: ToolContext | undefined, destination: string) => Promise<string>;
164
+ /**
165
+ * The token source a declared `oauth2` block gives its tools. Reads the
166
+ * client-credentials variables now, so a variable that is not set (or that
167
+ * the allowlist refuses) fails the compile, naming the variable only, and
168
+ * so does a host the operator's OAuth host allowlist does not bind to the
169
+ * provider (ADR 0114). `where` prefixes those messages; `server` is the URL
170
+ * (or URLs) the token is sent to.
171
+ */
172
+ export declare function oauthTokenSource(oauth2: OAuth2AuthConfig, where: string, server: string | readonly string[], options?: {
173
+ allowPrivate?: boolean;
174
+ env?: NodeJS.ProcessEnv;
175
+ fetch?: typeof fetch;
176
+ }): OAuthTokenSource;
177
+ /** The parts of a syndicate config `oauthClientsFor` reads. */
178
+ interface AgentLike {
179
+ name?: string;
180
+ openapi?: Array<{
181
+ spec?: string;
182
+ auth?: {
183
+ oauth2?: OAuth2AuthConfig;
184
+ };
185
+ }>;
186
+ mcp_server_url?: string;
187
+ mcp_auth?: {
188
+ oauth2?: OAuth2AuthConfig;
189
+ };
190
+ yaml_reference?: string;
191
+ }
192
+ interface SyndicateLike {
193
+ orchestrator?: AgentLike;
194
+ subagents?: AgentLike[];
195
+ }
196
+ /**
197
+ * The OAuth clients the consent step needs for these syndicates' declared
198
+ * authorization-code grants, by provider: pass them as
199
+ * `oauthConsent({ providers })` (lib/tools/oauthConsent.ts). Client ids and
200
+ * secrets are read from the variables the YAML names. Two declarations of
201
+ * one provider must agree on its endpoints, client and scopes, or this
202
+ * throws: a provider's grant is one grant, whichever tool asks for it.
203
+ * `load` reads a nested `yaml_reference:` file, when given.
204
+ */
205
+ export declare function oauthClientsFor(configs: readonly SyndicateLike[], options?: {
206
+ env?: NodeJS.ProcessEnv;
207
+ load?: (ref: string) => SyndicateLike;
208
+ allowlist?: OAuthHostAllowlist | null;
209
+ }): Record<string, OAuthClientConfig>;
210
+ /**
211
+ * Every OAuth grant these syndicates declare, orchestrators and subagents,
212
+ * following a nested `yaml_reference:` through `load` when given (once per
213
+ * file; agent names then read "Parent › Child").
214
+ */
215
+ export declare function syndicateOAuthGrants(configs: readonly SyndicateLike[], load?: (ref: string) => SyndicateLike): OAuthGrantUse[];
216
+ /**
217
+ * Why these syndicates may not be served here, one line per refusal
218
+ * (ADR 0114): each declared grant's MCP server, token endpoint and
219
+ * authorization endpoint against the operator's OAuth host allowlist (an
220
+ * OpenAPI entry's servers are in its spec, so its compile checks those).
221
+ * The A2A server checks every syndicate it loads to serve; the compile
222
+ * checks again, and each call once more.
223
+ */
224
+ export declare function syndicateOAuthHostProblems(configs: readonly SyndicateLike[], options?: {
225
+ load?: (ref: string) => SyndicateLike;
226
+ allowlist?: OAuthHostAllowlist | null;
227
+ }): string[];
228
+ /**
229
+ * The credential store's refresh hooks for the same providers
230
+ * (`credentialStore({ providers })`, lib/tools/credentialStore.ts): an
231
+ * expired user token is renewed at the provider's token endpoint with its
232
+ * refresh token (RFC 6749 6) instead of asking the person again. Built from
233
+ * `oauthClientsFor`'s clients; `allowPrivate` lets a private or loopback
234
+ * token endpoint through the guard (development).
235
+ */
236
+ export declare function oauthRefreshProviders(clients: Record<string, OAuthClientConfig>, options?: {
237
+ allowPrivate?: boolean;
238
+ fetch?: typeof fetch;
239
+ timeoutMs?: number;
240
+ now?: () => number;
241
+ }): Record<string, OAuthProvider>;
242
+ export {};