@hivemagnus/ardent 2.3.1 → 3.1.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.
- package/README.md +79 -2
- package/dist/a2a-idempotency.d.ts +3 -3
- package/dist/a2a-push-inbox.d.ts +3 -3
- package/dist/a2a-push.d.ts +3 -3
- package/dist/a2a-server.js +1 -1
- package/dist/a2a-store.d.ts +3 -3
- package/dist/a2a.js +19 -11
- package/dist/api.js +2 -0
- package/dist/cli.js +46 -20
- package/dist/context-maintenance.d.ts +4 -4
- package/dist/context-maintenance.js +1 -1
- package/dist/development.d.ts +1 -1
- package/dist/hermes-compat.d.ts +1 -1
- package/dist/hermes-compat.js +19 -2
- package/dist/index.d.ts +1 -1
- package/dist/job-engine.d.ts +9 -30
- package/dist/job-engine.js +4 -3
- package/dist/missions.d.ts +7 -6
- package/dist/missions.js +2 -2
- package/dist/plugin-evidence.d.ts +16 -0
- package/dist/plugin-evidence.js +44 -0
- package/dist/plugin-http.d.ts +4 -0
- package/dist/plugin-http.js +43 -0
- package/dist/plugin-inputs.d.ts +3 -0
- package/dist/plugin-inputs.js +40 -0
- package/dist/plugin-sdk.d.ts +25 -0
- package/dist/plugin-sdk.js +24 -0
- package/dist/plugins.d.ts +118 -7
- package/dist/plugins.js +93 -6
- package/dist/runtime.d.ts +20 -1
- package/dist/runtime.js +162 -23
- package/dist/sqlite.d.ts +30 -0
- package/dist/sqlite.js +81 -0
- package/dist/store.d.ts +5 -3
- package/dist/store.js +6 -6
- package/dist/team-artifacts.js +5 -5
- package/dist/team-contract.d.ts +20 -7
- package/dist/team-contract.js +11 -5
- package/dist/team-control.js +1 -2
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -45,8 +45,14 @@ isolated provider acceptance, and verifies an actual old-runtime rollback.
|
|
|
45
45
|
|
|
46
46
|
## Install
|
|
47
47
|
|
|
48
|
-
Ardent needs Node.js 24.22.1+ or 26.13.0
|
|
49
|
-
|
|
48
|
+
Ardent needs Node.js 24.22.1+ or 26.13.0+. Its pinned `@photostructure/sqlite`
|
|
49
|
+
driver bundles SQLite 3.54.1 and stable Node-API binaries for supported x64/arm64
|
|
50
|
+
platforms. Existing profile databases keep their format and journal history.
|
|
51
|
+
Node.js 26 is recommended for its patched built-in libraries.
|
|
52
|
+
|
|
53
|
+
Version 3 replaces the low-level `TaskStore.db` driver surface with the application's
|
|
54
|
+
storage boundary. Code that used better-sqlite3-specific methods must migrate;
|
|
55
|
+
the management API, CLI and plugin hooks retain their existing contracts.
|
|
50
56
|
|
|
51
57
|
```bash
|
|
52
58
|
npm i -g @hivemagnus/ardent
|
|
@@ -437,6 +443,10 @@ export default definePlugin({
|
|
|
437
443
|
jobHandlers: ctx => ({ /* 'weather.daily': JobHandler */ }),
|
|
438
444
|
jobOwnership: ctx => async (job, now) => { /* throw to refuse a job window */ },
|
|
439
445
|
peerTool: (tool, task, envelope) => false, // allow a peer to call one of your tools
|
|
446
|
+
taskTools: ctx => [], // additions bound to the exact persisted task
|
|
447
|
+
filterTool: (ctx, tool) => true, // restrictive final filter
|
|
448
|
+
drain: async (ctx, timeoutMs) => true, // stop intake and await owned work
|
|
449
|
+
close: ctx => {}, // synchronous cleanup after a successful drain
|
|
440
450
|
});
|
|
441
451
|
```
|
|
442
452
|
|
|
@@ -455,6 +465,73 @@ peer still needs an explicit mission grant (`tool:<name>`) or `peerTool`.
|
|
|
455
465
|
Plugin routes sit behind the same bearer-token check as the rest of the
|
|
456
466
|
management API.
|
|
457
467
|
|
|
468
|
+
A module may also export an asynchronous factory receiving `{ config, profileDir,
|
|
469
|
+
env }`. It returns a plugin or an array of plugins. This allows profile-specific
|
|
470
|
+
configuration and offline validation without constructing a runtime, claiming jobs,
|
|
471
|
+
or starting channel consumers. The CLI supplies the selected profile environment;
|
|
472
|
+
embedders can pass it as the third argument of `loadPlugins`.
|
|
473
|
+
|
|
474
|
+
Import supported extension primitives from `@hivemagnus/ardent/plugin-sdk` rather
|
|
475
|
+
than reaching into `dist`. This entry point includes the runtime, tool and job
|
|
476
|
+
contracts, profile/configuration helpers, provider clients, artifact and identity
|
|
477
|
+
helpers, and the application SQLite boundary (`SqliteDatabase`). Task additions retain their declared contexts and peer/mission grants. Preview
|
|
478
|
+
additions must be read-only. Restrictive filters apply to built-in and extension
|
|
479
|
+
tools; duplicate names cannot replace a tool silently. Stateful plugins must stop
|
|
480
|
+
intake and await their owned work in `drain`. A false or timed-out drain keeps the
|
|
481
|
+
journal open and ownership unsettled; `close` cannot bypass it. Cleanup runs in
|
|
482
|
+
reverse registration order, including partially initialized plugins.
|
|
483
|
+
|
|
484
|
+
Additional hooks support extensions that retain an existing workflow contract:
|
|
485
|
+
|
|
486
|
+
| Hook | Boundary |
|
|
487
|
+
| --- | --- |
|
|
488
|
+
| `systemPrompt` | Supplies trusted policy text; the full model input is still budgeted. |
|
|
489
|
+
| `allowMemory` | Can deny an admitted read; cannot grant a different scope. |
|
|
490
|
+
| `observeToolResult`, `beforeFinish`, `taskSettled` | Track actual task evidence, validate before success, and release task-local resources. |
|
|
491
|
+
| `teamEnvelope`, `admitTeamEnvelope` | Validate a legacy wire shape and apply extra admission restrictions. Identity, deadlines, parent reservations, constraints and resources remain core-validated. |
|
|
492
|
+
| `taskExecutor` | Runs one owned deterministic workflow. Attempts precede invocation in the journal; lost or unknown effects stay held across restart. Preview and mission execution cannot be replaced. |
|
|
493
|
+
| `inputImages` | Supplies at most five owned, digest-verified PNG/JPEG artifacts to a direct Codex task. Paths outside the selected profile's artifacts are rejected. |
|
|
494
|
+
| `teamEvidence` | Validates retained extension receipts. Artifacts require an exact mission grant and verified bytes; format-only citation aliases must target observed references. |
|
|
495
|
+
| `teamCard` | Describes private role capabilities without granting permissions or claiming backend readiness. |
|
|
496
|
+
| `prepareGateway`, `start` | Verify prior consumer ownership, then start background intake only in gateway mode. CLI inspection does not start consumers. |
|
|
497
|
+
| `channelAdapter` | Replaces one enabled built-in channel consumer. Multiple owners are refused. Intake and delivery receive separate abort signals. |
|
|
498
|
+
| `httpRoutes` | Adds explicit compatibility paths; overlapping core routes and authentication-boundary changes are refused. |
|
|
499
|
+
|
|
500
|
+
An envelope extension uses `mission.extensions[plugin.name]` and action names
|
|
501
|
+
`extension:<plugin-name>:<action>`. No extension is accepted without its configured
|
|
502
|
+
validator. A codec may retain an old wire action while translating it into its
|
|
503
|
+
own namespace; it cannot add a resource or substitute a core action grant.
|
|
504
|
+
Ardent retains the original wire envelope in its journal and revalidates it
|
|
505
|
+
when reading lifecycle controls or export receipts.
|
|
506
|
+
|
|
507
|
+
Normal plugin `routes` remain under `/api/v1/plugins/<name>/` and require the
|
|
508
|
+
management bearer token. `httpRoutes` declares each mount as `management` or
|
|
509
|
+
`independent`. Management aliases must remain under `/api/v1/` and inherit its
|
|
510
|
+
authentication. Independent device/webhook ingress must authenticate every
|
|
511
|
+
handler with its own credential and replay protection; it cannot use API,
|
|
512
|
+
health or A2A paths. All compatibility handlers receive a 1 MiB body bound and
|
|
513
|
+
share a bounded per-plugin rate bucket (600/minute, burst 120), applied before
|
|
514
|
+
handler authentication and parsing. Wildcard routes and middleware mounts are
|
|
515
|
+
refused so an extension cannot intercept unrelated core requests.
|
|
516
|
+
|
|
517
|
+
Offline job-validation contexts expose `runtimeAvailable: false`; their runtime
|
|
518
|
+
and tool registry getters throw. CLI extensions receive `rawArgs` for their own
|
|
519
|
+
option grammar, declare `valueOptions` to recognize values before the command, and can use `matches(invocation)` to select one subcommand while
|
|
520
|
+
leaving other core subcommands available. Plugin code has the profile owner's
|
|
521
|
+
process privileges: install only reviewed, pinned artifacts. These hooks preserve
|
|
522
|
+
authority boundaries between tasks; they do not sandbox an untrusted plugin.
|
|
523
|
+
|
|
524
|
+
Job owner labels other than `ardent` remain external references and never admit
|
|
525
|
+
work. A custom delivery kind requires its registered handler to validate the exact
|
|
526
|
+
descriptor. Existing definition bytes, revisions and receipts need not be rewritten
|
|
527
|
+
to rename an external scheduler. Historical channel labels also remain distinct;
|
|
528
|
+
a compatibility adapter must retain its original platform, account and receipt
|
|
529
|
+
identity instead of creating a second consumer under a renamed transport.
|
|
530
|
+
|
|
531
|
+
Extensions should
|
|
532
|
+
use `ctx.runtime.store` for the active journal and must not introduce a second
|
|
533
|
+
SQLite driver or rewrite another extension's state.
|
|
534
|
+
|
|
458
535
|
## Security model
|
|
459
536
|
|
|
460
537
|
- The model never gets a shell, deployment, or credential tool from Ardent
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Message, type SendMessageRequest, type StreamResponse, type Task } from '@a2a-js/sdk';
|
|
2
2
|
import { DefaultRequestHandler, type ServerCallContext } from '@a2a-js/sdk/server';
|
|
3
|
-
import type Database from '
|
|
3
|
+
import type Database from './sqlite.js';
|
|
4
4
|
import type { PeerTaskGate } from './a2a-rate-limit.js';
|
|
5
5
|
import type { SqliteA2ATaskStore } from './a2a-store.js';
|
|
6
6
|
/** Binds transport retries to the original task before invoking the executor. */
|
|
7
7
|
export declare class IdempotentA2AHandler extends DefaultRequestHandler {
|
|
8
8
|
#private;
|
|
9
|
-
readonly db: Database
|
|
9
|
+
readonly db: Database;
|
|
10
10
|
readonly durableStore: SqliteA2ATaskStore;
|
|
11
11
|
readonly taskGate: PeerTaskGate;
|
|
12
|
-
constructor(db: Database
|
|
12
|
+
constructor(db: Database, durableStore: SqliteA2ATaskStore, taskGate: PeerTaskGate, ...args: ConstructorParameters<typeof DefaultRequestHandler>);
|
|
13
13
|
sendMessage(params: SendMessageRequest, context: ServerCallContext): Promise<Task | Message>;
|
|
14
14
|
sendMessageStream(params: SendMessageRequest, context: ServerCallContext): AsyncGenerator<StreamResponse, void, undefined>;
|
|
15
15
|
}
|
package/dist/a2a-push-inbox.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type Database from '
|
|
1
|
+
import type Database from './sqlite.js';
|
|
2
2
|
import { type StreamResponse } from '@a2a-js/sdk';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import type { PeerConfig } from './a2a-peers.js';
|
|
@@ -8,10 +8,10 @@ declare const Outbound: z.ZodObject<{
|
|
|
8
8
|
task_id: z.ZodNullable<z.ZodString>;
|
|
9
9
|
}, z.core.$strip>;
|
|
10
10
|
export declare class A2APushInbox {
|
|
11
|
-
readonly db: Database
|
|
11
|
+
readonly db: Database;
|
|
12
12
|
readonly peers: PeerConfig[];
|
|
13
13
|
readonly publicUrl: string;
|
|
14
|
-
constructor(db: Database
|
|
14
|
+
constructor(db: Database, peers: PeerConfig[], publicUrl: string);
|
|
15
15
|
register(peerId: string, messageId: string): {
|
|
16
16
|
id: string;
|
|
17
17
|
token: string;
|
package/dist/a2a-push.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type Database from '
|
|
1
|
+
import type Database from './sqlite.js';
|
|
2
2
|
import { type StreamResponse, type Task, type TaskPushNotificationConfig } from '@a2a-js/sdk';
|
|
3
3
|
import type { PushNotificationSender, PushNotificationStore, ServerCallContext, StoredPushNotificationConfig } from '@a2a-js/sdk/server';
|
|
4
4
|
import type { PeerConfig } from './a2a-peers.js';
|
|
5
5
|
export declare class SqliteA2APushStore implements PushNotificationStore {
|
|
6
|
-
readonly db: Database
|
|
6
|
+
readonly db: Database;
|
|
7
7
|
readonly peers: PeerConfig[];
|
|
8
|
-
constructor(db: Database
|
|
8
|
+
constructor(db: Database, peers: PeerConfig[]);
|
|
9
9
|
save(taskId: string, context: ServerCallContext, config: TaskPushNotificationConfig): Promise<void>;
|
|
10
10
|
load(taskId: string, context: ServerCallContext): Promise<TaskPushNotificationConfig[]>;
|
|
11
11
|
loadWithMetadata(taskId: string, context: ServerCallContext): Promise<StoredPushNotificationConfig[]>;
|
package/dist/a2a-server.js
CHANGED
|
@@ -41,7 +41,7 @@ export async function createA2ASurface(runtime, config, env = process.env) {
|
|
|
41
41
|
if (!['http:', 'https:'].includes(publicUrl.protocol) || publicUrl.username || publicUrl.password)
|
|
42
42
|
throw new Error('Invalid A2A public URL');
|
|
43
43
|
const { authenticate, peers } = await loadPeers(runtime.profileDir, config, env);
|
|
44
|
-
const teamCard = config.a2a.hermes_compat ? await hermesTeamCard(runtime, config) : undefined;
|
|
44
|
+
const teamCard = config.a2a.hermes_compat ? await hermesTeamCard(runtime, config, env) : undefined;
|
|
45
45
|
const grpcPort = Number(publicUrl.port || (publicUrl.protocol === 'https:' ? 443 : 80)) + 1;
|
|
46
46
|
if (grpcPort > 65535)
|
|
47
47
|
throw new Error('A2A gRPC port is unavailable');
|
package/dist/a2a-store.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type ListTasksRequest, type ListTasksResponse, type Task } from '@a2a-js/sdk';
|
|
2
2
|
import type { ServerCallContext, TaskStore as A2ATaskStore } from '@a2a-js/sdk/server';
|
|
3
|
-
import type Database from '
|
|
3
|
+
import type Database from './sqlite.js';
|
|
4
4
|
export declare class SqliteA2ATaskStore implements A2ATaskStore {
|
|
5
|
-
readonly db: Database
|
|
6
|
-
constructor(db: Database
|
|
5
|
+
readonly db: Database;
|
|
6
|
+
constructor(db: Database);
|
|
7
7
|
save(task: Task, context: ServerCallContext): Promise<void>;
|
|
8
8
|
load(taskId: string, context: ServerCallContext): Promise<Task | undefined>;
|
|
9
9
|
list(params: ListTasksRequest, context: ServerCallContext): Promise<ListTasksResponse>;
|
package/dist/a2a.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { collectPluginTeamEvidence } from './plugin-evidence.js';
|
|
1
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
3
|
import { Role, TaskState } from '@a2a-js/sdk';
|
|
3
4
|
import { AgentEvent } from '@a2a-js/sdk/server';
|
|
4
5
|
import { z } from 'zod';
|
|
5
|
-
import { TEAM_TASK_METADATA_KEY, TEAM_CLARIFICATION_METADATA_KEY,
|
|
6
|
+
import { TEAM_TASK_METADATA_KEY, TEAM_CLARIFICATION_METADATA_KEY, TeamResult as TeamResultSchema, validateTeamEnvelope, validateTeamResult } from './team-contract.js';
|
|
6
7
|
import { TeamControlService } from './team-control.js';
|
|
7
8
|
import { TeamChildService } from './team-child.js';
|
|
8
9
|
import { TeamArtifacts } from './team-artifacts.js';
|
|
@@ -137,6 +138,7 @@ export class ArdentA2AExecutor {
|
|
|
137
138
|
const rawEnvelope = metadata[TEAM_TASK_METADATA_KEY];
|
|
138
139
|
let envelope;
|
|
139
140
|
let childReference;
|
|
141
|
+
let wireEnvelope = rawEnvelope;
|
|
140
142
|
try {
|
|
141
143
|
const tenant = request.context.tenant ?? '';
|
|
142
144
|
const existing = this.runtime.store.db.prepare('SELECT tenant,caller,envelope_json FROM a2a_team_missions WHERE a2a_task_id=?').get(taskId);
|
|
@@ -149,19 +151,21 @@ export class ArdentA2AExecutor {
|
|
|
149
151
|
throw new Error('Cancelled team task cannot continue');
|
|
150
152
|
}
|
|
151
153
|
if (rawEnvelope !== undefined) {
|
|
152
|
-
envelope = validateTeamEnvelope(rawEnvelope, caller.userName, request.userMessage.messageId, prompt, Date.now() / 1000, 'hermesTeamChild' in metadata);
|
|
154
|
+
envelope = validateTeamEnvelope(rawEnvelope, caller.userName, request.userMessage.messageId, prompt, Date.now() / 1000, 'hermesTeamChild' in metadata, value => this.runtime.decodeTeamEnvelope(value));
|
|
155
|
+
this.runtime.assertTeamEnvelopeAdmission(envelope, rawEnvelope, this.env);
|
|
153
156
|
if ('hermesTeamChild' in metadata)
|
|
154
157
|
childReference = await this.#children.claim(metadata.hermesTeamChild, envelope, taskId, contextId, caller.userName, JSON.stringify(request.userMessage));
|
|
155
|
-
if (stored && stored.envelope_json !== JSON.stringify(
|
|
158
|
+
if (stored && stored.envelope_json !== JSON.stringify(rawEnvelope))
|
|
156
159
|
throw new Error('Team mission changed during continuation');
|
|
157
160
|
if (!stored)
|
|
158
|
-
this.runtime.store.db.prepare('INSERT INTO a2a_team_missions(a2a_task_id,tenant,caller,envelope_json) VALUES (?,?,?,?)').run(taskId, tenant, caller.userName, JSON.stringify(
|
|
161
|
+
this.runtime.store.db.prepare('INSERT INTO a2a_team_missions(a2a_task_id,tenant,caller,envelope_json) VALUES (?,?,?,?)').run(taskId, tenant, caller.userName, JSON.stringify(rawEnvelope));
|
|
159
162
|
}
|
|
160
163
|
else if (stored) {
|
|
161
164
|
if (request.task?.status?.state !== TaskState.TASK_STATE_INPUT_REQUIRED)
|
|
162
165
|
throw new Error('Team continuation requires an input-required task');
|
|
163
166
|
const parsed = JSON.parse(stored.envelope_json);
|
|
164
|
-
|
|
167
|
+
wireEnvelope = parsed;
|
|
168
|
+
envelope = this.runtime.decodeTeamEnvelope(parsed);
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
catch {
|
|
@@ -180,7 +184,7 @@ export class ArdentA2AExecutor {
|
|
|
180
184
|
const existedBefore = Boolean(request.userMessage.messageId && this.runtime.store.db.prepare("SELECT 1 FROM tasks WHERE caller=? AND context='peer' AND idempotency_key=?").get(owner, request.userMessage.messageId));
|
|
181
185
|
const operation = this.runtime.accept(prompt, owner, 'peer', request.userMessage.messageId, session.id, deadline ? deadline * 1000 : undefined);
|
|
182
186
|
if (envelope && operation.state === 'queued')
|
|
183
|
-
this.runtime.store.append(operation.id, 'team_envelope',
|
|
187
|
+
this.runtime.store.append(operation.id, 'team_envelope', wireEnvelope);
|
|
184
188
|
try {
|
|
185
189
|
this.runtime.store.db.transaction(() => {
|
|
186
190
|
this.runtime.store.db.prepare(`INSERT INTO a2a_operation_map(a2a_task_id,operation_id,tenant,caller) VALUES (?,?,?,?)
|
|
@@ -309,7 +313,9 @@ export class ArdentA2AExecutor {
|
|
|
309
313
|
{ name: 'research-brief.md', reference: `ardent-artifact:${detail.data.markdown.id}`, sha256: detail.data.markdown.id }
|
|
310
314
|
];
|
|
311
315
|
});
|
|
312
|
-
const
|
|
316
|
+
const extensions = await collectPluginTeamEvidence(this.runtime, result.task, envelope, this.env);
|
|
317
|
+
artifacts.push(...extensions.artifacts.map(({ name, reference, sha256 }) => ({ name, reference, sha256 })));
|
|
318
|
+
const knownReferences = new Set([...artifacts.map(item => item.reference), ...extensions.references]);
|
|
313
319
|
for (const event of events.filter(item => item.kind === 'evidence_register')) {
|
|
314
320
|
const register = z.object({ source_ids: z.array(z.string()), artifact_ids: z.array(z.string()) }).safeParse(event.detail);
|
|
315
321
|
if (!register.success)
|
|
@@ -350,7 +356,7 @@ export class ArdentA2AExecutor {
|
|
|
350
356
|
const reason = error instanceof Error ? error.message : 'Invalid team result';
|
|
351
357
|
this.runtime.store.append(operationId, 'team_result_rejected', { reason: reason.slice(0, 1000) });
|
|
352
358
|
if (envelope.mission.allowed_actions.every(action => action === 'observe' || action === 'analyze')) {
|
|
353
|
-
const repaired = await this.#repairTeamResult(submitted, reason, envelope, result, operationId, artifacts, knownReferences, observedOwnerSources);
|
|
359
|
+
const repaired = await this.#repairTeamResult(submitted, reason, envelope, result, operationId, artifacts, knownReferences, observedOwnerSources, extensions.aliases);
|
|
354
360
|
if (repaired)
|
|
355
361
|
return repaired;
|
|
356
362
|
}
|
|
@@ -366,7 +372,7 @@ export class ArdentA2AExecutor {
|
|
|
366
372
|
}
|
|
367
373
|
#validateSubmittedTeamResult(submitted, artifacts, envelope, knownReferences) {
|
|
368
374
|
const parsed = TeamResultSchema.parse(submitted);
|
|
369
|
-
if (!envelope.mission.allowed_actions.includes('create_artifact') && parsed.artifacts.
|
|
375
|
+
if (!envelope.mission.allowed_actions.includes('create_artifact') && parsed.artifacts.some(item => !artifacts.some(actual => actual.name === item.name && actual.sha256 === item.sha256 && actual.reference === item.reference)))
|
|
370
376
|
throw new Error('Team result declares an artifact without create_artifact authority');
|
|
371
377
|
for (const item of parsed.artifacts)
|
|
372
378
|
if (!knownReferences.has(item.reference) || item.reference !== `ardent-artifact:${item.sha256}`)
|
|
@@ -374,7 +380,7 @@ export class ArdentA2AExecutor {
|
|
|
374
380
|
return validateTeamResult(JSON.stringify({ ...parsed,
|
|
375
381
|
artifacts: [...artifacts, ...parsed.artifacts.filter(item => !artifacts.some(real => real.name === item.name))] }), envelope, knownReferences);
|
|
376
382
|
}
|
|
377
|
-
async #repairTeamResult(submitted, reason, envelope, result, operationId, artifacts, knownReferences, observedOwnerSources) {
|
|
383
|
+
async #repairTeamResult(submitted, reason, envelope, result, operationId, artifacts, knownReferences, observedOwnerSources, citationAliases) {
|
|
378
384
|
const shape = z.object({ version: z.unknown().optional(), mission_id: z.string(), mission_revision: z.number(), task_id: z.string(),
|
|
379
385
|
outcome: z.string(), summary: z.string(), checks: z.array(z.object({ criterion: z.string(), status: z.string(),
|
|
380
386
|
evidence: z.union([z.array(z.string()), z.string()]) }).strict()), artifacts: z.array(z.unknown()), uncertain_effects: z.array(z.string()) }).strict();
|
|
@@ -397,7 +403,9 @@ export class ArdentA2AExecutor {
|
|
|
397
403
|
const originalEvidence = original.data.checks[0]?.evidence;
|
|
398
404
|
const executionCitation = singleReadCheck && Array.isArray(originalEvidence) && originalEvidence.length === 1
|
|
399
405
|
&& /^source:exec-[A-Za-z0-9._:-]{1,128}$/.test(originalEvidence[0] ?? '') ? originalEvidence[0] : undefined;
|
|
400
|
-
const
|
|
406
|
+
const alias = singleReadCheck && Array.isArray(originalEvidence) && originalEvidence.length === 1 ? citationAliases.get(originalEvidence[0] ?? '') : undefined;
|
|
407
|
+
const citationCorrection = executionCitation && soleOwnerSource ? { from: executionCitation, to: soleOwnerSource }
|
|
408
|
+
: alias && knownReferences.has(alias) ? { from: originalEvidence[0], to: alias } : undefined;
|
|
401
409
|
const evidenceArrayCorrection = singleReadCheck && typeof originalEvidence === 'string' && knownReferences.has(originalEvidence)
|
|
402
410
|
? { from: originalEvidence, to: [originalEvidence] } : undefined;
|
|
403
411
|
// These are format-only aliases for one observed, read-only owner check.
|
package/dist/api.js
CHANGED
|
@@ -16,6 +16,7 @@ import { ArdentA2AClient } from './a2a-client.js';
|
|
|
16
16
|
import { TelegramAdapter } from './telegram.js';
|
|
17
17
|
import { MattermostAdapter } from './mattermost.js';
|
|
18
18
|
import { EventSchema, SessionMessageSchema, SessionSchema, TaskSchema, TaskState } from './store.js';
|
|
19
|
+
import { mountPluginHttp } from './plugin-http.js';
|
|
19
20
|
import { pluginContext } from './plugins.js';
|
|
20
21
|
import { MissionSubmit } from './missions.js';
|
|
21
22
|
import { ArtifactRecordSchema } from './artifact-manifests.js';
|
|
@@ -547,5 +548,6 @@ export function createArdentApi(runtime, loaded, env = process.env, jobEngine, o
|
|
|
547
548
|
plugin.routes(sub, ctx);
|
|
548
549
|
app.route(`/api/v1/plugins/${plugin.name}`, sub);
|
|
549
550
|
}
|
|
551
|
+
mountPluginHttp(app, runtime, env, jobEngine);
|
|
550
552
|
return app;
|
|
551
553
|
}
|
package/dist/cli.js
CHANGED
|
@@ -20,24 +20,24 @@ import { CodexAppServer, assertCodexProtocol, compactWithCodex } from './codex.j
|
|
|
20
20
|
import { LlamaCppBackend } from './llamacpp.js';
|
|
21
21
|
import { toJsonSchema } from './json-schema.js';
|
|
22
22
|
import { hermesTeamCard } from './hermes-compat.js';
|
|
23
|
-
import Database from '
|
|
23
|
+
import Database from './sqlite.js';
|
|
24
24
|
import { JobEngine, validateJobDefinitions } from './job-engine.js';
|
|
25
25
|
import { composeOwnershipChecks } from './job-ownership.js';
|
|
26
26
|
import { BUILTIN_JOB_VALIDATION_REGISTRY, builtinJobHandlers } from './job-news-handlers.js';
|
|
27
27
|
import { acquireGatewayLock, createLockFile } from './gateway-lock.js';
|
|
28
28
|
import { ContextCheckpoints } from './context-checkpoints.js';
|
|
29
29
|
import { loadModelPolicy } from './model-policy.js';
|
|
30
|
-
import { loadPlugins, pluginContext, pluginJobHandlers, validationContext } from './plugins.js';
|
|
30
|
+
import { loadPlugins, pluginContext, pluginChannelAdapter, pluginJobHandlers, validationContext } from './plugins.js';
|
|
31
31
|
import { ARDENT_VERSION } from './version.js';
|
|
32
32
|
import { acceptRuntime } from './acceptance.js';
|
|
33
33
|
import { readProfileEnv } from './profile-env.js';
|
|
34
34
|
import { PlainTextFilter } from './live-text.js';
|
|
35
35
|
import { developmentQuery, missionSubmitInput, previewInput } from './cli-commands.js';
|
|
36
36
|
import { developmentPage, DevelopmentRecords, recordSkillChange } from './development.js';
|
|
37
|
-
function args(argv) {
|
|
37
|
+
function args(argv, extraValues = []) {
|
|
38
38
|
const words = [];
|
|
39
39
|
const options = new Map();
|
|
40
|
-
const valued = new Set(['env-file', 'profile', 'profile-path', 'api-port', 'template', 'prompt', 'prompt-file', 'idempotency-key', 'session-id', 'login-id', 'source', 'schedule-id', 'window-key', 'release-id', 'caller', 'context', 'expected-head', 'expected-policy-revision', 'mission-file', 'after', 'limit', 'kind', 'soul-file', 'identity-file', 'skills', 'model']);
|
|
40
|
+
const valued = new Set([...extraValues, 'env-file', 'profile', 'profile-path', 'api-port', 'template', 'prompt', 'prompt-file', 'idempotency-key', 'session-id', 'login-id', 'source', 'schedule-id', 'window-key', 'release-id', 'caller', 'context', 'expected-head', 'expected-policy-revision', 'mission-file', 'after', 'limit', 'kind', 'soul-file', 'identity-file', 'skills', 'model']);
|
|
41
41
|
for (let i = 0; i < argv.length; i++) {
|
|
42
42
|
const arg = argv[i];
|
|
43
43
|
if (!arg)
|
|
@@ -125,8 +125,8 @@ Commands:
|
|
|
125
125
|
tasks pause | resume <id> Hold a queued task, or release and run it
|
|
126
126
|
gateway run Serve the management API, A2A, channels and jobs`;
|
|
127
127
|
async function main() {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
let parsed = args(process.argv.slice(2));
|
|
129
|
+
let [command, subcommand, id] = parsed.words;
|
|
130
130
|
if (parsed.options.has('version')) {
|
|
131
131
|
stdout.write(`${ARDENT_VERSION}\n`);
|
|
132
132
|
return;
|
|
@@ -160,11 +160,16 @@ async function main() {
|
|
|
160
160
|
process.exitCode = 1;
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
|
-
const plugins = await loadPlugins(loaded.config, dir);
|
|
163
|
+
const plugins = await loadPlugins(loaded.config, dir, env);
|
|
164
|
+
parsed = args(process.argv.slice(2), plugins.flatMap(plugin => Object.values(plugin.cliCommands ?? {}).flatMap(command => [...command.valueOptions ?? []])));
|
|
165
|
+
[command, subcommand, id] = parsed.words;
|
|
164
166
|
for (const plugin of plugins) {
|
|
165
167
|
const pluginCommand = command ? plugin.cliCommands?.[command] : undefined;
|
|
166
168
|
if (pluginCommand) {
|
|
167
|
-
|
|
169
|
+
const invocation = { rawArgs: process.argv.slice(2), words: parsed.words.slice(1), options: parsed.options, profileDir: dir, config: loaded.config, env, print };
|
|
170
|
+
if (pluginCommand.matches?.(invocation) === false)
|
|
171
|
+
continue;
|
|
172
|
+
await pluginCommand.run(invocation);
|
|
168
173
|
return;
|
|
169
174
|
}
|
|
170
175
|
}
|
|
@@ -316,13 +321,23 @@ async function main() {
|
|
|
316
321
|
if (command === 'a2a' && subcommand === 'team-card') {
|
|
317
322
|
if (!loaded.config.a2a.hermes_compat)
|
|
318
323
|
throw new Error('Hermes team card requires a2a.hermes_compat: true');
|
|
319
|
-
const
|
|
324
|
+
const lock = await createLockFile(join(dir, 'state', 'gateway.lock'));
|
|
325
|
+
let runtime;
|
|
320
326
|
try {
|
|
327
|
+
runtime = new ArdentRuntime(dir, loaded.config, env);
|
|
321
328
|
await runtime.usePlugins(plugins, env);
|
|
322
|
-
print(await hermesTeamCard(runtime, loaded.config));
|
|
329
|
+
print(await hermesTeamCard(runtime, loaded.config, env));
|
|
323
330
|
}
|
|
324
331
|
finally {
|
|
325
|
-
runtime
|
|
332
|
+
if (runtime) {
|
|
333
|
+
if (await runtime.drain(30_000))
|
|
334
|
+
runtime.close();
|
|
335
|
+
else {
|
|
336
|
+
stderr.write('Plugin work remains unsettled; retain the owner record.\n');
|
|
337
|
+
process.exit(1);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
await lock.release();
|
|
326
341
|
}
|
|
327
342
|
return;
|
|
328
343
|
}
|
|
@@ -486,6 +501,7 @@ async function main() {
|
|
|
486
501
|
try {
|
|
487
502
|
runtime = new ArdentRuntime(dir, loaded.config, env);
|
|
488
503
|
await runtime.usePlugins(plugins, env);
|
|
504
|
+
await runtime.prepareGateway(env);
|
|
489
505
|
// Legacy scheduled tasks are not replayed by a new gateway generation.
|
|
490
506
|
// The job engine owns its own window recovery and never replays uncertain effects.
|
|
491
507
|
for (const task of runtime.recovered.queued)
|
|
@@ -560,16 +576,18 @@ async function main() {
|
|
|
560
576
|
a2aGrpc = surface.grpcServer;
|
|
561
577
|
}
|
|
562
578
|
}
|
|
579
|
+
await runtime.startPlugins(env);
|
|
563
580
|
if (loaded.config.channels.telegram.enabled) {
|
|
564
581
|
const fixtureBase = env.ARDENT_TELEGRAM_API_FIXTURE_URL;
|
|
565
582
|
if (fixtureBase && (env.NODE_ENV !== 'test' || !/^http:\/\/(?:127\.0\.0\.1|localhost):\d+$/.test(fixtureBase)))
|
|
566
583
|
throw new Error('Telegram API fixture URL is permitted only for loopback tests');
|
|
567
|
-
const telegram = new TelegramAdapter(runtime, loaded.config.channels.telegram, env, fixtureBase ?? 'https://api.telegram.org', jobEngine);
|
|
584
|
+
const telegram = pluginChannelAdapter(plugins, ctx, 'telegram', jobEngine) ?? new TelegramAdapter(runtime, loaded.config.channels.telegram, env, fixtureBase ?? 'https://api.telegram.org', jobEngine);
|
|
568
585
|
telegramRun = telegram.run(channelAbort.signal, deliveryAbort.signal);
|
|
569
586
|
}
|
|
570
587
|
if (loaded.config.channels.mattermost.enabled) {
|
|
571
|
-
const
|
|
572
|
-
|
|
588
|
+
const replacement = pluginChannelAdapter(plugins, ctx, 'mattermost', jobEngine);
|
|
589
|
+
const mattermost = replacement ?? { run: (intake, _delivery) => new MattermostAdapter(runtime, loaded.config.channels.mattermost, env, jobEngine).run(intake) };
|
|
590
|
+
mattermostRun = mattermost.run(channelAbort.signal, deliveryAbort.signal);
|
|
573
591
|
}
|
|
574
592
|
print({ profile, host: loaded.config.api.host, port: loaded.config.api.port, a2a: a2aHttp ? 'listening' : 'disabled', status: 'listening' });
|
|
575
593
|
await new Promise((resolve, reject) => {
|
|
@@ -625,7 +643,8 @@ async function main() {
|
|
|
625
643
|
if (settled)
|
|
626
644
|
runtime.close();
|
|
627
645
|
}
|
|
628
|
-
|
|
646
|
+
if (!shutdownUnsettled)
|
|
647
|
+
await lock.release();
|
|
629
648
|
}
|
|
630
649
|
if (shutdownUnsettled) {
|
|
631
650
|
stderr.write('Gateway shutdown left unresolved work; interrupted tasks will be marked unknown on restart.\n');
|
|
@@ -647,6 +666,13 @@ async function main() {
|
|
|
647
666
|
await runtime.usePlugins(plugins, env);
|
|
648
667
|
}
|
|
649
668
|
catch (error) {
|
|
669
|
+
if (runtime) {
|
|
670
|
+
if (!await runtime.drain(30_000)) {
|
|
671
|
+
stderr.write('Plugin initialization left unresolved work; retain the owner record for recovery.\n');
|
|
672
|
+
process.exit(1);
|
|
673
|
+
}
|
|
674
|
+
runtime.close();
|
|
675
|
+
}
|
|
650
676
|
await ownerLock.release();
|
|
651
677
|
throw error;
|
|
652
678
|
}
|
|
@@ -873,12 +899,12 @@ async function main() {
|
|
|
873
899
|
}
|
|
874
900
|
}
|
|
875
901
|
finally {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
finally {
|
|
880
|
-
await ownerLock.release();
|
|
902
|
+
if (!await runtime.drain(30_000)) {
|
|
903
|
+
stderr.write('Command shutdown left unresolved work; retain the owner record for recovery.\n');
|
|
904
|
+
process.exit(1);
|
|
881
905
|
}
|
|
906
|
+
runtime.close();
|
|
907
|
+
await ownerLock.release();
|
|
882
908
|
}
|
|
883
909
|
}
|
|
884
910
|
main().catch((error) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Database from '
|
|
1
|
+
import { Database } from './sqlite.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { type CompactionCall } from './context-checkpoints.js';
|
|
4
4
|
import { TaskStore } from './store.js';
|
|
@@ -13,9 +13,9 @@ declare const snapshotSchema: z.ZodObject<{
|
|
|
13
13
|
}, z.core.$strict>>;
|
|
14
14
|
}, z.core.$strict>;
|
|
15
15
|
export type ContextSnapshot = z.infer<typeof snapshotSchema>;
|
|
16
|
-
export declare function snapshotContext(database: Database
|
|
17
|
-
export declare function verifyContextSnapshot(database: Database
|
|
18
|
-
export declare function assertContextIdle(database: Database
|
|
16
|
+
export declare function snapshotContext(database: Database): ContextSnapshot;
|
|
17
|
+
export declare function verifyContextSnapshot(database: Database, input: unknown): void;
|
|
18
|
+
export declare function assertContextIdle(database: Database): void;
|
|
19
19
|
export declare function exerciseContext(store: TaskStore, summarize: CompactionCall, loaded: NonNullable<Awaited<ReturnType<typeof loadModelPolicy>>>, previousModule: string, continueContext: (messages: unknown) => Promise<string>): Promise<Record<string, unknown>>;
|
|
20
20
|
export declare function contextMaintenance(input: unknown): Promise<Record<string, unknown>>;
|
|
21
21
|
export {};
|
|
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { lstat, mkdir, open, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import Database from '
|
|
5
|
+
import { Database } from './sqlite.js';
|
|
6
6
|
import { parse } from 'dotenv';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
import { ContextCheckpoints } from './context-checkpoints.js';
|
package/dist/development.d.ts
CHANGED
package/dist/hermes-compat.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export type HermesTeamCard = {
|
|
|
12
12
|
tags: string[];
|
|
13
13
|
}>;
|
|
14
14
|
};
|
|
15
|
-
export declare function hermesTeamCard(runtime: Pick<ArdentRuntime, 'tools'
|
|
15
|
+
export declare function hermesTeamCard(runtime: Pick<ArdentRuntime, 'tools'> & Partial<Pick<ArdentRuntime, 'plugins' | 'config' | 'profileDir'>>, config: ArdentConfig, env?: NodeJS.ProcessEnv): Promise<HermesTeamCard>;
|
package/dist/hermes-compat.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { readFile, readdir } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { pluginContext } from './plugins.js';
|
|
4
6
|
/**
|
|
5
7
|
* Optional Hermes Agent team-card compatibility (`a2a.hermes_compat: true`).
|
|
6
8
|
* The card describes this profile's registered peer-callable tools so a Hermes
|
|
@@ -28,7 +30,8 @@ function toolset(name) {
|
|
|
28
30
|
const prefix = /^([a-z][a-z0-9]*)_/.exec(name)?.[1];
|
|
29
31
|
return prefix ?? 'tools';
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
function isRuntime(value) { return 'store' in value && 'profileDir' in value && 'plugins' in value; }
|
|
34
|
+
export async function hermesTeamCard(runtime, config, env = process.env) {
|
|
32
35
|
const now = Math.floor(Date.now() / 1000);
|
|
33
36
|
const description = config.a2a.skill?.description ?? `${config.name}: bounded tasks with this profile's registered tools`;
|
|
34
37
|
const grouped = new Map();
|
|
@@ -49,7 +52,7 @@ export async function hermesTeamCard(runtime, config) {
|
|
|
49
52
|
tags: [entry.id, 'task-conditional'] }));
|
|
50
53
|
const sourceDigest = await digestRuntimeSource();
|
|
51
54
|
const taskPolicyDigest = await digestModules(['a2a', 'a2a-client', 'a2a-idempotency', 'a2a-peers', 'runtime', 'team-contract', 'tools']);
|
|
52
|
-
|
|
55
|
+
const card = { description, skills, metadata: { hermesTeam: {
|
|
53
56
|
schemaVersion: '1.0', missionContractVersions: ['1.0'], coordinationProtocolVersions: [],
|
|
54
57
|
lifecycleProtocolVersions: ['1.0'], missionControlScopes: [], taskExecutionBoundaryVersion: '1.0',
|
|
55
58
|
genericSurfacePolicyVersion: '1.0', sourceDigest, role: config.profile,
|
|
@@ -59,4 +62,18 @@ export async function hermesTeamCard(runtime, config) {
|
|
|
59
62
|
taskPolicyDigest, runtimeKind: 'ardent', discovery: { schemaVersion: '1.0', observedAt: now, expiresAt: now + 300,
|
|
60
63
|
registryStatus: 'observed', configurationStatus: 'observed', toolsets }
|
|
61
64
|
} } };
|
|
65
|
+
const configured = runtime.plugins?.filter(plugin => plugin.teamCard) ?? [];
|
|
66
|
+
if (configured.length > 1)
|
|
67
|
+
throw new Error('Multiple plugins own the team card');
|
|
68
|
+
const plugin = configured[0];
|
|
69
|
+
if (!plugin?.teamCard)
|
|
70
|
+
return card;
|
|
71
|
+
// A real runtime supplies this context; tools-only callers retain the default card.
|
|
72
|
+
if (!isRuntime(runtime))
|
|
73
|
+
throw new Error('A plugin team card requires the selected runtime');
|
|
74
|
+
const custom = await plugin.teamCard(pluginContext(runtime, env), card);
|
|
75
|
+
if (Buffer.byteLength(JSON.stringify(custom)) > 64_000)
|
|
76
|
+
throw new Error('Plugin team card exceeds 64 KiB');
|
|
77
|
+
return z.object({ description: z.string().min(1).max(1000), metadata: z.object({ hermesTeam: z.record(z.string(), z.json()) }).strict(),
|
|
78
|
+
skills: z.array(z.object({ id: z.string().min(1).max(100), name: z.string().min(1).max(100), description: z.string().min(1).max(1000), tags: z.array(z.string().max(100)).max(32) }).strict()).max(64) }).strict().parse(custom);
|
|
62
79
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export { TaskStore, type Task } from './store.js';
|
|
|
5
5
|
export { defineTool, ToolRegistry, ProvenNoEffectError, type Tool, type ToolContext, type ToolEffect, type ToolResult } from './tools.js';
|
|
6
6
|
export { createArdentApi, ardentOpenApi } from './api.js';
|
|
7
7
|
export { JobEngine, validateJobDefinitions, type JobContext, type JobDefinition, type JobHandler, type JobRegistry, type JobResult, type OwnershipCheck } from './job-engine.js';
|
|
8
|
-
export { definePlugin, registerPlugin, registeredPlugins, clearRegisteredPlugins, loadPlugins, type ArdentPlugin, type ArdentPluginContext, type ArdentCliCommand, type ArdentCliInvocation } from './plugins.js';
|
|
8
|
+
export { definePlugin, registerPlugin, registeredPlugins, clearRegisteredPlugins, loadPlugins, type ArdentPlugin, type ArdentPluginContext, type ArdentCliCommand, type ArdentCliInvocation, type ArdentPluginFactory, type ArdentPluginFactoryContext, type ArdentTaskPluginContext } from './plugins.js';
|
|
9
9
|
export type { TeamEnvelope, TeamMission, TeamResult } from './team-contract.js';
|