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
@@ -45,6 +45,47 @@ export interface TurnControl {
45
45
  stopReason?: TurnStopReason;
46
46
  /** Stop the turn. The first reason wins. */
47
47
  stop(reason: TurnStopReason): void;
48
+ /**
49
+ * Runs a nested dispatch syndicate as its own turn on its own
50
+ * conversation, under this turn's controls (ADR 0120): set by the turn
51
+ * runner (lib/runtime/syndicateTurn.ts), read where a nested dispatch
52
+ * syndicate runs (a delegated call, a dispatch route, a workflow node),
53
+ * which sit below the turn runner and cannot import it.
54
+ */
55
+ nestedDispatch?: (run: NestedDispatchRun) => Promise<NestedDispatchEnd>;
56
+ }
57
+ /** One run of a nested dispatch syndicate (ADR 0120): what it is, where its conversation is filed, and the message. */
58
+ export interface NestedDispatchRun {
59
+ /** The nested syndicate's config (a SyndicateYamlConfig with a `dispatch:` block). */
60
+ config: unknown;
61
+ /** The compile options it loads its routes with (CompileOptions, its nesting chain included). */
62
+ compile: unknown;
63
+ /** The entry's name: the nested syndicate as its caller lists it. */
64
+ name: string;
65
+ /** The store, and the key its conversation is filed under (already opened by the caller). */
66
+ sessions: unknown;
67
+ appName: string;
68
+ userId: string;
69
+ sessionId: string;
70
+ /** The message's parts: the request, or the answer to what waits in it. */
71
+ parts: unknown[];
72
+ }
73
+ /** How a nested dispatch syndicate's turn ended (ADR 0120). */
74
+ export interface NestedDispatchEnd {
75
+ status: 'completed' | 'input-required' | 'failed' | 'canceled';
76
+ /** The route's final text: the nested syndicate's answer. */
77
+ text: string;
78
+ /** Its conversation's state writes this run, `temp:` keys aside. */
79
+ stateDelta: Record<string, unknown>;
80
+ /** What it waits on, when paused: the request's id, and the request as the turn reports it (a PendingApproval, a PendingInput, a PendingConsent). */
81
+ interruptId?: string;
82
+ approval?: unknown;
83
+ input?: unknown;
84
+ consent?: unknown;
85
+ error?: {
86
+ code: string;
87
+ message: string;
88
+ };
48
89
  }
49
90
  export interface TurnControlOptions {
50
91
  maxLlmCalls?: number;
@@ -232,6 +232,15 @@ export declare class ProjectedSessionService implements SessionService {
232
232
  * The event lands in the projected session the runtime holds and, through
233
233
  * the store, in the real one `get` read. A session `get` did not hand out
234
234
  * is the real one, and the store alone applies the event to it.
235
+ *
236
+ * A store may answer an append with events of its own: a durable run's
237
+ * store restoring a checkpoint (lib/runtime/native/checkpoint.ts, ADR 0113)
238
+ * answers the opening message with the run's stored events, the stored
239
+ * opening returned in place of the one given. The projected session then
240
+ * takes, in place of the event given, every event the real session gained,
241
+ * unprojected: they are the current turn, which is never projected. The
242
+ * agent loop thereby reads the restored steps, as it would on the store's
243
+ * own session.
235
244
  */
236
245
  append(session: EngineSession, event: TurnEvent): Promise<TurnEvent>;
237
246
  }
@@ -340,6 +340,15 @@ export class ProjectedSessionService {
340
340
  * The event lands in the projected session the runtime holds and, through
341
341
  * the store, in the real one `get` read. A session `get` did not hand out
342
342
  * is the real one, and the store alone applies the event to it.
343
+ *
344
+ * A store may answer an append with events of its own: a durable run's
345
+ * store restoring a checkpoint (lib/runtime/native/checkpoint.ts, ADR 0113)
346
+ * answers the opening message with the run's stored events, the stored
347
+ * opening returned in place of the one given. The projected session then
348
+ * takes, in place of the event given, every event the real session gained,
349
+ * unprojected: they are the current turn, which is never projected. The
350
+ * agent loop thereby reads the restored steps, as it would on the store's
351
+ * own session.
343
352
  */
344
353
  async append(session, event) {
345
354
  if (event.partial)
@@ -347,7 +356,17 @@ export class ProjectedSessionService {
347
356
  const real = this.stored.get(this.key(session.appName, session.userId, session.id));
348
357
  if (!real || real === session)
349
358
  return this.own.append(session, event);
359
+ const before = real.events.length;
360
+ const at = session.events.length;
350
361
  applyEvent(session, event);
351
- return this.own.append(real, event);
362
+ const stored = await this.own.append(real, event);
363
+ if (stored.id !== event.id) {
364
+ // The store answered with its own events: they replace the one applied above.
365
+ if (session.events[at]?.id === event.id)
366
+ session.events.splice(at, 1);
367
+ for (const gained of real.events.slice(before))
368
+ applyEvent(session, gained);
369
+ }
370
+ return stored;
352
371
  }
353
372
  }
@@ -48,3 +48,21 @@ export interface InstallResult {
48
48
  export declare function destinationsFor(opts: InstallOptions): string[];
49
49
  /** Copy the suite into every destination. Returns one result per destination. */
50
50
  export declare function installSkills(opts?: InstallOptions): InstallResult[];
51
+ /** The markers that delimit the block this installer owns inside AGENTS.md. */
52
+ export declare const AGENTS_MD_BEGIN = "<!-- melchizedek-skills:begin -->";
53
+ export declare const AGENTS_MD_END = "<!-- melchizedek-skills:end -->";
54
+ /** The pointer: where the skills are, and the onboarding entry point. */
55
+ export declare function agentsMdBlock(destinations: string[], projectRoot: string): string;
56
+ export interface AgentsMdResult {
57
+ path: string;
58
+ status: 'created' | 'appended' | 'updated' | 'unchanged';
59
+ }
60
+ /**
61
+ * Write the pointer into `<projectRoot>/AGENTS.md`, the instructions file
62
+ * Codex and other agents read: create the file when absent, append the block
63
+ * when the file has none, or replace only the block between the markers.
64
+ * Nothing outside the markers is ever changed.
65
+ */
66
+ export declare function writeAgentsMdPointer(projectRoot: string, destinations: string[], opts?: {
67
+ dryRun?: boolean;
68
+ }): AgentsMdResult;
@@ -15,7 +15,7 @@
15
15
  * A SKILL.md's frontmatter is read by the skills harness's own parser
16
16
  * (lib/tools/skills/frontmatter.ts), the one an agent's `skills:` uses.
17
17
  */
18
- import { closeSync, existsSync, fstatSync, lstatSync, mkdirSync, openSync, readSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
18
+ import { closeSync, constants as fsConstants, existsSync, fstatSync, ftruncateSync, lstatSync, mkdirSync, openSync, readSync, readdirSync, readFileSync, statSync, writeFileSync, writeSync } from 'node:fs';
19
19
  import { homedir } from 'node:os';
20
20
  import { dirname, join, relative, resolve } from 'node:path';
21
21
  import { fileURLToPath } from 'node:url';
@@ -162,3 +162,75 @@ export function installSkills(opts = {}) {
162
162
  }
163
163
  return results;
164
164
  }
165
+ // ── The AGENTS.md pointer ────────────────────────────────────────────────────
166
+ /** The markers that delimit the block this installer owns inside AGENTS.md. */
167
+ export const AGENTS_MD_BEGIN = '<!-- melchizedek-skills:begin -->';
168
+ export const AGENTS_MD_END = '<!-- melchizedek-skills:end -->';
169
+ /** The pointer: where the skills are, and the onboarding entry point. */
170
+ export function agentsMdBlock(destinations, projectRoot) {
171
+ const where = destinations.map((d) => `\`${relative(projectRoot, d) || '.'}/\``).join(' and ');
172
+ return [
173
+ AGENTS_MD_BEGIN,
174
+ '## Melchizedek agent skills',
175
+ '',
176
+ `The melchizedek-agents skills are installed in ${where}, one directory per skill with a SKILL.md.`,
177
+ 'To onboard someone, start with `melchizedek-onboard/SKILL.md`, or run `npx melchizedek-setup --auto`.',
178
+ 'Never ask for an API key in chat and never print a value from `.env`: the person types keys into `.env` themselves.',
179
+ AGENTS_MD_END,
180
+ ].join('\n');
181
+ }
182
+ /**
183
+ * Write the pointer into `<projectRoot>/AGENTS.md`, the instructions file
184
+ * Codex and other agents read: create the file when absent, append the block
185
+ * when the file has none, or replace only the block between the markers.
186
+ * Nothing outside the markers is ever changed.
187
+ */
188
+ export function writeAgentsMdPointer(projectRoot, destinations, opts = {}) {
189
+ const path = join(resolve(projectRoot), 'AGENTS.md');
190
+ const block = agentsMdBlock(destinations, resolve(projectRoot));
191
+ const plan = (text) => {
192
+ if (text === undefined)
193
+ return { status: 'created', next: `# AGENTS.md\n\n${block}\n` };
194
+ const start = text.indexOf(AGENTS_MD_BEGIN);
195
+ const end = text.indexOf(AGENTS_MD_END);
196
+ if (start !== -1 && end > start) {
197
+ const next = text.slice(0, start) + block + text.slice(end + AGENTS_MD_END.length);
198
+ return { status: next === text ? 'unchanged' : 'updated', next };
199
+ }
200
+ return { status: 'appended', next: `${text}${text.endsWith('\n') ? '' : '\n'}\n${block}\n` };
201
+ };
202
+ if (opts.dryRun) {
203
+ // Nothing is written, so a path check is enough to report what would happen.
204
+ if (existsSync(path) && lstatSync(path).isSymbolicLink())
205
+ throw new Error(`refusing to write through a symlink: ${path}`);
206
+ return { path, status: plan(existsSync(path) ? readFileSync(path, 'utf-8') : undefined).status };
207
+ }
208
+ // One handle for the read and the write, so the file read is the file written:
209
+ // created if absent, never followed through a symlink (O_NOFOLLOW).
210
+ let fd;
211
+ try {
212
+ fd = openSync(path, fsConstants.O_RDWR | fsConstants.O_CREAT | (fsConstants.O_NOFOLLOW ?? 0), 0o644);
213
+ }
214
+ catch (err) {
215
+ if (err.code === 'ELOOP')
216
+ throw new Error(`refusing to write through a symlink: ${path}`);
217
+ throw err;
218
+ }
219
+ let status;
220
+ try {
221
+ const stat = fstatSync(fd);
222
+ if (!stat.isFile())
223
+ throw new Error(`not a regular file: ${path}`);
224
+ const existing = stat.size > 0 ? readFileSync(fd, 'utf-8') : undefined;
225
+ const result = plan(existing);
226
+ status = result.status;
227
+ if (status !== 'unchanged') {
228
+ ftruncateSync(fd, 0);
229
+ writeSync(fd, result.next, 0);
230
+ }
231
+ }
232
+ finally {
233
+ closeSync(fd);
234
+ }
235
+ return { path, status };
236
+ }
@@ -21,7 +21,7 @@ import type { CredentialStoreOptions } from '../../tools/credentialStore.ts';
21
21
  import type { CredentialStore } from '../../tools/auth.ts';
22
22
  import type { AuditSink } from '../../observability/audit.ts';
23
23
  import type { RlsHardeningStatus } from '../rlsStatus.ts';
24
- import type { TaskBackend } from '../../tools/taskTools.ts';
24
+ import type { TaskBackend, TaskBackendOptions } from '../../tools/taskTools.ts';
25
25
  import type { TurnLock } from '../../a2a/turnLock.ts';
26
26
  import type { PostgresTaskStoreOptions } from './taskStore.ts';
27
27
  export { PostgresSessionService } from './sessionService.ts';
@@ -73,6 +73,11 @@ export interface PostgresStorageOptions {
73
73
  * go to this storage's audit trail.
74
74
  */
75
75
  credentials?: Omit<CredentialStoreOptions, 'rows' | 'audit'>;
76
+ /**
77
+ * The job queue's checkpoints (ADR 0113): the largest one stored, in bytes
78
+ * of JSON (default 5 MiB), and where a skipped save is logged.
79
+ */
80
+ taskQueue?: TaskBackendOptions;
76
81
  }
77
82
  export interface PostgresStorage {
78
83
  pool: Pool;
@@ -120,7 +120,7 @@ export function postgresStorage(options) {
120
120
  reap: () => reapExpiredTasks(pool),
121
121
  cancelRequested: () => cancelRequestedTasks(pool, lease),
122
122
  },
123
- taskQueue: postgresTaskBackend(pool),
123
+ taskQueue: postgresTaskBackend(pool, options.taskQueue),
124
124
  async schemaVersion() {
125
125
  try {
126
126
  const r = await pool.query('SELECT max(version) AS v FROM melchizedek_schema_version');
@@ -27,8 +27,12 @@
27
27
  * survives while the job is running or queued: recover's requeue keeps it,
28
28
  * so the next claim resumes from it, and claimNext leaves it; a mutate that
29
29
  * moves the job to any other status, or recover failing it, clears it; a
30
- * deleted row takes it along.
30
+ * deleted row takes it along. A checkpoint whose JSON is above the cap
31
+ * (TaskBackendOptions.checkpointMaxBytes, default 5 MiB) is not written:
32
+ * the column keeps the previous one, the save still reports the claim, and
33
+ * one line names the job id and the sizes.
31
34
  */
32
35
  import type { Pool } from 'pg';
33
- import type { TaskBackend } from '../../tools/taskTools.ts';
34
- export declare function postgresTaskBackend(pool: Pool): TaskBackend;
36
+ import type { TaskBackend, TaskBackendOptions } from '../../tools/taskTools.ts';
37
+ /** The task backend on `pool`; `options` caps the checkpoint a save stores (TaskBackendOptions). */
38
+ export declare function postgresTaskBackend(pool: Pool, options?: TaskBackendOptions): TaskBackend;
@@ -1,4 +1,4 @@
1
- import { applyFinish, applyInterrupted } from '../../tools/taskTools.js';
1
+ import { applyFinish, applyInterrupted, checkpointJson } from '../../tools/taskTools.js';
2
2
  const seqOf = (id) => Number(id.slice(1)) || 0;
3
3
  async function loadOwner(db, owner, lock) {
4
4
  const head = await db.query(`SELECT next_id FROM melchizedek_task_owners WHERE owner = $1${lock ? ' FOR UPDATE' : ''}`, [owner]);
@@ -21,7 +21,8 @@ async function inTransaction(pool, run) {
21
21
  client.release();
22
22
  }
23
23
  }
24
- export function postgresTaskBackend(pool) {
24
+ /** The task backend on `pool`; `options` caps the checkpoint a save stores (TaskBackendOptions). */
25
+ export function postgresTaskBackend(pool, options = {}) {
25
26
  return {
26
27
  read: (owner) => loadOwner(pool, owner, false),
27
28
  async mutate(owner, change) {
@@ -82,8 +83,14 @@ export function postgresTaskBackend(pool) {
82
83
  return (r.rowCount ?? 0) > 0;
83
84
  },
84
85
  async saveCheckpoint(worker, job, checkpoint) {
86
+ const json = checkpointJson(job, checkpoint, options);
87
+ if (json === null) {
88
+ // Over the cap: the previous checkpoint is kept; the answer is still whether the claim holds.
89
+ const held = await pool.query(`SELECT 1 FROM melchizedek_tasks WHERE owner = $1 AND id = $2 AND lease_owner = $3 AND status = 'running'`, [job.owner, job.id, worker.workerId]);
90
+ return (held.rowCount ?? 0) > 0;
91
+ }
85
92
  const r = await pool.query(`UPDATE melchizedek_tasks SET checkpoint = $4::jsonb, checkpoint_at = NOW()
86
- WHERE owner = $1 AND id = $2 AND lease_owner = $3 AND status = 'running'`, [job.owner, job.id, worker.workerId, JSON.stringify(checkpoint)]);
93
+ WHERE owner = $1 AND id = $2 AND lease_owner = $3 AND status = 'running'`, [job.owner, job.id, worker.workerId, json]);
87
94
  return (r.rowCount ?? 0) > 0;
88
95
  },
89
96
  async loadCheckpoint(job) {
@@ -24,9 +24,12 @@
24
24
  import { z } from 'zod';
25
25
  import type { SyndicateYamlConfig } from './loadSyndicate.ts';
26
26
  export declare const MEMORY_SYSTEMS: readonly ['internal-only', 'session-only', 'long-term'];
27
- export declare const REASONING_LEVELS: readonly ['none', 'low', 'medium', 'high'];
27
+ export declare const REASONING_LEVELS: readonly ['none', 'low', 'medium', 'high', 'xhigh', 'max'];
28
28
  export declare const OUTPUT_MIMES: readonly ['application/json', 'text/plain'];
29
+ export declare const TOOL_CHOICE_MODES: readonly ['auto', 'none', 'required'];
29
30
  export declare const SKILL_SCRIPT_MODES: readonly ['none', 'local'];
31
+ /** An `mcp_servers` entry's name: lowercase, bounded, one character class (no backtracking). */
32
+ export declare const MCP_SERVER_NAME: RegExp;
30
33
  export declare const agentSchema: z.ZodObject<{
31
34
  name: z.ZodString;
32
35
  description: z.ZodOptional<z.ZodString>;
@@ -67,8 +70,10 @@ export declare const agentSchema: z.ZodObject<{
67
70
  reasoning: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
68
71
  high: "high";
69
72
  low: "low";
73
+ max: "max";
70
74
  medium: "medium";
71
75
  none: "none";
76
+ xhigh: "xhigh";
72
77
  }>, z.ZodObject<{
73
78
  budget_tokens: z.ZodNumber;
74
79
  }, z.core.$strict>]>>;
@@ -85,6 +90,13 @@ export declare const agentSchema: z.ZodObject<{
85
90
  "text/plain": "text/plain";
86
91
  }>>;
87
92
  }, z.core.$strict>>;
93
+ tool_choice: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
94
+ auto: "auto";
95
+ none: "none";
96
+ required: "required";
97
+ }>, z.ZodObject<{
98
+ name: z.ZodString;
99
+ }, z.core.$strict>]>>;
88
100
  model_overrides: z.ZodOptional<z.ZodObject<{
89
101
  gemini: z.ZodOptional<z.ZodObject<{
90
102
  instruction: z.ZodOptional<z.ZodString>;
@@ -121,8 +133,9 @@ export declare const agentSchema: z.ZodObject<{
121
133
  authorization_code: "authorization_code";
122
134
  client_credentials: "client_credentials";
123
135
  }>;
136
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
124
137
  authorization_url: z.ZodOptional<z.ZodString>;
125
- token_url: z.ZodString;
138
+ token_url: z.ZodOptional<z.ZodString>;
126
139
  client_id: z.ZodOptional<z.ZodString>;
127
140
  client_id_env: z.ZodOptional<z.ZodString>;
128
141
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -130,6 +143,38 @@ export declare const agentSchema: z.ZodObject<{
130
143
  authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
131
144
  }, z.core.$strict>;
132
145
  }, z.core.$strict>>;
146
+ mcp_transport: z.ZodOptional<z.ZodEnum<{
147
+ auto: "auto";
148
+ sse: "sse";
149
+ streamable_http: "streamable_http";
150
+ }>>;
151
+ mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
152
+ name: z.ZodString;
153
+ url: z.ZodString;
154
+ tools: z.ZodArray<z.ZodString>;
155
+ auth: z.ZodOptional<z.ZodObject<{
156
+ oauth2: z.ZodObject<{
157
+ provider: z.ZodString;
158
+ grant: z.ZodEnum<{
159
+ authorization_code: "authorization_code";
160
+ client_credentials: "client_credentials";
161
+ }>;
162
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
163
+ authorization_url: z.ZodOptional<z.ZodString>;
164
+ token_url: z.ZodOptional<z.ZodString>;
165
+ client_id: z.ZodOptional<z.ZodString>;
166
+ client_id_env: z.ZodOptional<z.ZodString>;
167
+ client_secret_env: z.ZodOptional<z.ZodString>;
168
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
169
+ authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
170
+ }, z.core.$strict>;
171
+ }, z.core.$strict>>;
172
+ transport: z.ZodOptional<z.ZodEnum<{
173
+ auto: "auto";
174
+ sse: "sse";
175
+ streamable_http: "streamable_http";
176
+ }>>;
177
+ }, z.core.$strict>>>;
133
178
  skills: z.ZodOptional<z.ZodObject<{
134
179
  dir: z.ZodString;
135
180
  scripts: z.ZodOptional<z.ZodEnum<{
@@ -161,8 +206,9 @@ export declare const agentSchema: z.ZodObject<{
161
206
  authorization_code: "authorization_code";
162
207
  client_credentials: "client_credentials";
163
208
  }>;
209
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
164
210
  authorization_url: z.ZodOptional<z.ZodString>;
165
- token_url: z.ZodString;
211
+ token_url: z.ZodOptional<z.ZodString>;
166
212
  client_id: z.ZodOptional<z.ZodString>;
167
213
  client_id_env: z.ZodOptional<z.ZodString>;
168
214
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -233,8 +279,10 @@ export declare const subagentSchema: z.ZodObject<{
233
279
  reasoning: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
234
280
  high: "high";
235
281
  low: "low";
282
+ max: "max";
236
283
  medium: "medium";
237
284
  none: "none";
285
+ xhigh: "xhigh";
238
286
  }>, z.ZodObject<{
239
287
  budget_tokens: z.ZodNumber;
240
288
  }, z.core.$strict>]>>;
@@ -251,6 +299,13 @@ export declare const subagentSchema: z.ZodObject<{
251
299
  "text/plain": "text/plain";
252
300
  }>>;
253
301
  }, z.core.$strict>>;
302
+ tool_choice: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
303
+ auto: "auto";
304
+ none: "none";
305
+ required: "required";
306
+ }>, z.ZodObject<{
307
+ name: z.ZodString;
308
+ }, z.core.$strict>]>>;
254
309
  model_overrides: z.ZodOptional<z.ZodObject<{
255
310
  gemini: z.ZodOptional<z.ZodObject<{
256
311
  instruction: z.ZodOptional<z.ZodString>;
@@ -287,8 +342,9 @@ export declare const subagentSchema: z.ZodObject<{
287
342
  authorization_code: "authorization_code";
288
343
  client_credentials: "client_credentials";
289
344
  }>;
345
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
290
346
  authorization_url: z.ZodOptional<z.ZodString>;
291
- token_url: z.ZodString;
347
+ token_url: z.ZodOptional<z.ZodString>;
292
348
  client_id: z.ZodOptional<z.ZodString>;
293
349
  client_id_env: z.ZodOptional<z.ZodString>;
294
350
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -296,6 +352,38 @@ export declare const subagentSchema: z.ZodObject<{
296
352
  authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
297
353
  }, z.core.$strict>;
298
354
  }, z.core.$strict>>;
355
+ mcp_transport: z.ZodOptional<z.ZodEnum<{
356
+ auto: "auto";
357
+ sse: "sse";
358
+ streamable_http: "streamable_http";
359
+ }>>;
360
+ mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
361
+ name: z.ZodString;
362
+ url: z.ZodString;
363
+ tools: z.ZodArray<z.ZodString>;
364
+ auth: z.ZodOptional<z.ZodObject<{
365
+ oauth2: z.ZodObject<{
366
+ provider: z.ZodString;
367
+ grant: z.ZodEnum<{
368
+ authorization_code: "authorization_code";
369
+ client_credentials: "client_credentials";
370
+ }>;
371
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
372
+ authorization_url: z.ZodOptional<z.ZodString>;
373
+ token_url: z.ZodOptional<z.ZodString>;
374
+ client_id: z.ZodOptional<z.ZodString>;
375
+ client_id_env: z.ZodOptional<z.ZodString>;
376
+ client_secret_env: z.ZodOptional<z.ZodString>;
377
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
378
+ authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
379
+ }, z.core.$strict>;
380
+ }, z.core.$strict>>;
381
+ transport: z.ZodOptional<z.ZodEnum<{
382
+ auto: "auto";
383
+ sse: "sse";
384
+ streamable_http: "streamable_http";
385
+ }>>;
386
+ }, z.core.$strict>>>;
299
387
  skills: z.ZodOptional<z.ZodObject<{
300
388
  dir: z.ZodString;
301
389
  scripts: z.ZodOptional<z.ZodEnum<{
@@ -327,8 +415,9 @@ export declare const subagentSchema: z.ZodObject<{
327
415
  authorization_code: "authorization_code";
328
416
  client_credentials: "client_credentials";
329
417
  }>;
418
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
330
419
  authorization_url: z.ZodOptional<z.ZodString>;
331
- token_url: z.ZodString;
420
+ token_url: z.ZodOptional<z.ZodString>;
332
421
  client_id: z.ZodOptional<z.ZodString>;
333
422
  client_id_env: z.ZodOptional<z.ZodString>;
334
423
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -403,8 +492,10 @@ export declare const syndicateSchema: z.ZodObject<{
403
492
  reasoning: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
404
493
  high: "high";
405
494
  low: "low";
495
+ max: "max";
406
496
  medium: "medium";
407
497
  none: "none";
498
+ xhigh: "xhigh";
408
499
  }>, z.ZodObject<{
409
500
  budget_tokens: z.ZodNumber;
410
501
  }, z.core.$strict>]>>;
@@ -421,6 +512,13 @@ export declare const syndicateSchema: z.ZodObject<{
421
512
  "text/plain": "text/plain";
422
513
  }>>;
423
514
  }, z.core.$strict>>;
515
+ tool_choice: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
516
+ auto: "auto";
517
+ none: "none";
518
+ required: "required";
519
+ }>, z.ZodObject<{
520
+ name: z.ZodString;
521
+ }, z.core.$strict>]>>;
424
522
  model_overrides: z.ZodOptional<z.ZodObject<{
425
523
  gemini: z.ZodOptional<z.ZodObject<{
426
524
  instruction: z.ZodOptional<z.ZodString>;
@@ -457,8 +555,9 @@ export declare const syndicateSchema: z.ZodObject<{
457
555
  authorization_code: "authorization_code";
458
556
  client_credentials: "client_credentials";
459
557
  }>;
558
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
460
559
  authorization_url: z.ZodOptional<z.ZodString>;
461
- token_url: z.ZodString;
560
+ token_url: z.ZodOptional<z.ZodString>;
462
561
  client_id: z.ZodOptional<z.ZodString>;
463
562
  client_id_env: z.ZodOptional<z.ZodString>;
464
563
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -466,6 +565,38 @@ export declare const syndicateSchema: z.ZodObject<{
466
565
  authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
467
566
  }, z.core.$strict>;
468
567
  }, z.core.$strict>>;
568
+ mcp_transport: z.ZodOptional<z.ZodEnum<{
569
+ auto: "auto";
570
+ sse: "sse";
571
+ streamable_http: "streamable_http";
572
+ }>>;
573
+ mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
574
+ name: z.ZodString;
575
+ url: z.ZodString;
576
+ tools: z.ZodArray<z.ZodString>;
577
+ auth: z.ZodOptional<z.ZodObject<{
578
+ oauth2: z.ZodObject<{
579
+ provider: z.ZodString;
580
+ grant: z.ZodEnum<{
581
+ authorization_code: "authorization_code";
582
+ client_credentials: "client_credentials";
583
+ }>;
584
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
585
+ authorization_url: z.ZodOptional<z.ZodString>;
586
+ token_url: z.ZodOptional<z.ZodString>;
587
+ client_id: z.ZodOptional<z.ZodString>;
588
+ client_id_env: z.ZodOptional<z.ZodString>;
589
+ client_secret_env: z.ZodOptional<z.ZodString>;
590
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
591
+ authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
592
+ }, z.core.$strict>;
593
+ }, z.core.$strict>>;
594
+ transport: z.ZodOptional<z.ZodEnum<{
595
+ auto: "auto";
596
+ sse: "sse";
597
+ streamable_http: "streamable_http";
598
+ }>>;
599
+ }, z.core.$strict>>>;
469
600
  skills: z.ZodOptional<z.ZodObject<{
470
601
  dir: z.ZodString;
471
602
  scripts: z.ZodOptional<z.ZodEnum<{
@@ -497,8 +628,9 @@ export declare const syndicateSchema: z.ZodObject<{
497
628
  authorization_code: "authorization_code";
498
629
  client_credentials: "client_credentials";
499
630
  }>;
631
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
500
632
  authorization_url: z.ZodOptional<z.ZodString>;
501
- token_url: z.ZodString;
633
+ token_url: z.ZodOptional<z.ZodString>;
502
634
  client_id: z.ZodOptional<z.ZodString>;
503
635
  client_id_env: z.ZodOptional<z.ZodString>;
504
636
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -563,8 +695,10 @@ export declare const syndicateSchema: z.ZodObject<{
563
695
  reasoning: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
564
696
  high: "high";
565
697
  low: "low";
698
+ max: "max";
566
699
  medium: "medium";
567
700
  none: "none";
701
+ xhigh: "xhigh";
568
702
  }>, z.ZodObject<{
569
703
  budget_tokens: z.ZodNumber;
570
704
  }, z.core.$strict>]>>;
@@ -581,6 +715,13 @@ export declare const syndicateSchema: z.ZodObject<{
581
715
  "text/plain": "text/plain";
582
716
  }>>;
583
717
  }, z.core.$strict>>;
718
+ tool_choice: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
719
+ auto: "auto";
720
+ none: "none";
721
+ required: "required";
722
+ }>, z.ZodObject<{
723
+ name: z.ZodString;
724
+ }, z.core.$strict>]>>;
584
725
  model_overrides: z.ZodOptional<z.ZodObject<{
585
726
  gemini: z.ZodOptional<z.ZodObject<{
586
727
  instruction: z.ZodOptional<z.ZodString>;
@@ -617,8 +758,9 @@ export declare const syndicateSchema: z.ZodObject<{
617
758
  authorization_code: "authorization_code";
618
759
  client_credentials: "client_credentials";
619
760
  }>;
761
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
620
762
  authorization_url: z.ZodOptional<z.ZodString>;
621
- token_url: z.ZodString;
763
+ token_url: z.ZodOptional<z.ZodString>;
622
764
  client_id: z.ZodOptional<z.ZodString>;
623
765
  client_id_env: z.ZodOptional<z.ZodString>;
624
766
  client_secret_env: z.ZodOptional<z.ZodString>;
@@ -626,6 +768,38 @@ export declare const syndicateSchema: z.ZodObject<{
626
768
  authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
627
769
  }, z.core.$strict>;
628
770
  }, z.core.$strict>>;
771
+ mcp_transport: z.ZodOptional<z.ZodEnum<{
772
+ auto: "auto";
773
+ sse: "sse";
774
+ streamable_http: "streamable_http";
775
+ }>>;
776
+ mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
777
+ name: z.ZodString;
778
+ url: z.ZodString;
779
+ tools: z.ZodArray<z.ZodString>;
780
+ auth: z.ZodOptional<z.ZodObject<{
781
+ oauth2: z.ZodObject<{
782
+ provider: z.ZodString;
783
+ grant: z.ZodEnum<{
784
+ authorization_code: "authorization_code";
785
+ client_credentials: "client_credentials";
786
+ }>;
787
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
788
+ authorization_url: z.ZodOptional<z.ZodString>;
789
+ token_url: z.ZodOptional<z.ZodString>;
790
+ client_id: z.ZodOptional<z.ZodString>;
791
+ client_id_env: z.ZodOptional<z.ZodString>;
792
+ client_secret_env: z.ZodOptional<z.ZodString>;
793
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
794
+ authorization_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
795
+ }, z.core.$strict>;
796
+ }, z.core.$strict>>;
797
+ transport: z.ZodOptional<z.ZodEnum<{
798
+ auto: "auto";
799
+ sse: "sse";
800
+ streamable_http: "streamable_http";
801
+ }>>;
802
+ }, z.core.$strict>>>;
629
803
  skills: z.ZodOptional<z.ZodObject<{
630
804
  dir: z.ZodString;
631
805
  scripts: z.ZodOptional<z.ZodEnum<{
@@ -657,8 +831,9 @@ export declare const syndicateSchema: z.ZodObject<{
657
831
  authorization_code: "authorization_code";
658
832
  client_credentials: "client_credentials";
659
833
  }>;
834
+ client_registration: z.ZodOptional<z.ZodLiteral<"dynamic">>;
660
835
  authorization_url: z.ZodOptional<z.ZodString>;
661
- token_url: z.ZodString;
836
+ token_url: z.ZodOptional<z.ZodString>;
662
837
  client_id: z.ZodOptional<z.ZodString>;
663
838
  client_id_env: z.ZodOptional<z.ZodString>;
664
839
  client_secret_env: z.ZodOptional<z.ZodString>;