@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/dist/store.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Database from 'better-sqlite3';
1
+ import Database from './sqlite.js';
2
2
  import { z } from 'zod';
3
3
  export declare const TaskState: z.ZodEnum<{
4
4
  unknown: "unknown";
@@ -90,8 +90,10 @@ export declare const EventSchema: z.ZodObject<{
90
90
  created_ms: z.ZodNumber;
91
91
  }, z.core.$strip>;
92
92
  export type TaskEvent = z.infer<typeof EventSchema>;
93
+ /** Historical transport labels remain distinct; adapters must retain their original identity. */
94
+ export type InboundChannelType = 'unknown' | 'telegram_private' | 'telegram_group' | 'telegram_supergroup' | 'mattermost_dm' | 'mattermost_channel' | 'chattermost_dm' | 'chattermost_channel';
93
95
  export declare class TaskStore {
94
- readonly db: Database.Database;
96
+ readonly db: Database;
95
97
  constructor(path: string);
96
98
  close(): void;
97
99
  admissionFence(): {
@@ -132,7 +134,7 @@ export declare class TaskStore {
132
134
  finishWithAssistant(id: string, state: 'completed' | 'partial', content: string, sessionContent?: string): void;
133
135
  latestSessionTask(sessionId: string, caller: string): Task | undefined;
134
136
  hasInbound(platform: string, account: string, updateId: string): boolean;
135
- claimInbound(platform: string, account: string, updateId: string, channelType?: 'unknown' | 'telegram_private' | 'telegram_group' | 'telegram_supergroup' | 'mattermost_dm' | 'mattermost_channel'): {
137
+ claimInbound(platform: string, account: string, updateId: string, channelType?: InboundChannelType): {
136
138
  claimed: boolean;
137
139
  taskId: string | null;
138
140
  };
package/dist/store.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { mkdirSync } from 'node:fs';
3
3
  import { dirname } from 'node:path';
4
- import Database from 'better-sqlite3';
4
+ import Database from './sqlite.js';
5
5
  import { z } from 'zod';
6
6
  export const TaskState = z.enum(['queued', 'running', 'input_required', 'completed', 'partial', 'failed', 'cancelled', 'unknown']);
7
7
  /** Execution scope of a task. It selects tools and memory; a session belongs to exactly one context. */
@@ -34,7 +34,7 @@ export class TaskStore {
34
34
  task_id TEXT REFERENCES tasks(id), created_ms INTEGER NOT NULL,
35
35
  channel_type TEXT NOT NULL DEFAULT 'unknown' CHECK(channel_type IN
36
36
  ('unknown','telegram_private','telegram_group','telegram_supergroup',
37
- 'mattermost_dm','mattermost_channel')),
37
+ 'mattermost_dm','mattermost_channel','chattermost_dm','chattermost_channel')),
38
38
  PRIMARY KEY(platform, account, update_id));
39
39
  CREATE TABLE IF NOT EXISTS channel_cursors (
40
40
  key TEXT PRIMARY KEY, value TEXT NOT NULL, updated_ms INTEGER NOT NULL);
@@ -87,7 +87,7 @@ export class TaskStore {
87
87
  this.db.exec(`ALTER TABLE channel_inbound ADD COLUMN
88
88
  channel_type TEXT NOT NULL DEFAULT 'unknown' CHECK(channel_type IN
89
89
  ('unknown','telegram_private','telegram_group','telegram_supergroup',
90
- 'mattermost_dm','mattermost_channel'))`);
90
+ 'mattermost_dm','mattermost_channel','chattermost_dm','chattermost_channel'))`);
91
91
  this.db.exec(`CREATE TRIGGER IF NOT EXISTS channel_inbound_type_immutable
92
92
  BEFORE UPDATE OF channel_type ON channel_inbound
93
93
  WHEN OLD.channel_type != NEW.channel_type
@@ -228,10 +228,10 @@ export class TaskStore {
228
228
  claimInbound(platform, account, updateId, channelType = 'unknown') {
229
229
  if (!platform || !account || !updateId || updateId.length > 256)
230
230
  throw new Error('Invalid channel update identity');
231
- if ((platform === 'telegram' && channelType.startsWith('mattermost_')) ||
232
- (platform === 'mattermost' && channelType.startsWith('telegram_')) ||
231
+ if ((platform === 'telegram' && (channelType.startsWith('mattermost_') || channelType.startsWith('chattermost_'))) ||
232
+ (['mattermost', 'chattermost'].includes(platform) && channelType.startsWith('telegram_')) ||
233
233
  !['unknown', 'telegram_private', 'telegram_group', 'telegram_supergroup',
234
- 'mattermost_dm', 'mattermost_channel'].includes(channelType))
234
+ 'mattermost_dm', 'mattermost_channel', 'chattermost_dm', 'chattermost_channel'].includes(channelType))
235
235
  throw new Error('Inbound channel type differs from platform');
236
236
  return this.db.transaction(() => {
237
237
  if (this.admissionFence())
@@ -2,7 +2,7 @@ import { createHash, randomBytes } from 'node:crypto';
2
2
  import { z } from 'zod';
3
3
  import { TaskState } from '@a2a-js/sdk';
4
4
  import { ArdentA2AClient } from './a2a-client.js';
5
- import { TeamEnvelope } from './team-contract.js';
5
+ import { collectPluginTeamEvidence } from './plugin-evidence.js';
6
6
  const digest = z.string().regex(/^[a-f0-9]{64}$/);
7
7
  const identifier = z.string().regex(/^[a-f0-9]{32}$/);
8
8
  const safeName = z.string().regex(/^[A-Za-z0-9._-]{1,128}$/);
@@ -62,16 +62,16 @@ export class TeamArtifacts {
62
62
  if (operation?.state !== 'completed' || operation.context !== 'peer' ||
63
63
  operation.caller !== `a2a:${bound.tenant}:${bound.caller}`)
64
64
  return [];
65
- const envelope = TeamEnvelope.parse(JSON.parse(bound.envelope_json));
66
- if (!envelope.mission.allowed_actions.includes('create_artifact'))
67
- return [];
65
+ const envelope = this.runtime.decodeTeamEnvelope(JSON.parse(bound.envelope_json));
66
+ const extensions = await collectPluginTeamEvidence(this.runtime, operation, envelope, this.env);
68
67
  const events = this.runtime.store.events(bound.operation_id, 0, 500);
69
68
  const event = events.find(item => item.kind === 'research_artifacts');
70
69
  const actual = z.object({ report: z.object({ id: digest }), markdown: z.object({ id: digest }) }).safeParse(event?.detail);
71
- const entries = actual.success ? [
70
+ const entries = envelope.mission.allowed_actions.includes('create_artifact') && actual.success ? [
72
71
  { name: 'research-brief.json', mime: 'application/json', digest: actual.data.report.id, producer: 'ardent-research', sourceId: '' },
73
72
  { name: 'research-brief.md', mime: 'text/markdown', digest: actual.data.markdown.id, producer: 'ardent-research', sourceId: '' }
74
73
  ] : [];
74
+ entries.push(...extensions.artifacts.map(item => ({ name: item.name, mime: item.mime, digest: item.sha256, producer: item.producer, sourceId: item.source })));
75
75
  const result = [];
76
76
  for (const entry of entries) {
77
77
  const bytes = await this.runtime.artifacts.get(entry.digest);
@@ -2,13 +2,23 @@ import { z } from 'zod';
2
2
  export declare const TEAM_VERSION = "1.0";
3
3
  export declare const TEAM_TASK_METADATA_KEY = "hermesTeamTask";
4
4
  export declare const TEAM_CLARIFICATION_METADATA_KEY = "hermesTeamClarification";
5
+ export declare const CoreTeamAction: z.ZodEnum<{
6
+ observe: "observe";
7
+ analyze: "analyze";
8
+ create_artifact: "create_artifact";
9
+ create_draft: "create_draft";
10
+ reversible_change: "reversible_change";
11
+ deploy: "deploy";
12
+ external_publish: "external_publish";
13
+ destructive_response: "destructive_response";
14
+ }>;
5
15
  /** The mission shape without its cross-field rules (Zod 4 cannot omit fields from a refined object). */
6
16
  export declare const TeamMissionShape: z.ZodObject<{
7
17
  id: z.ZodString;
8
18
  revision: z.ZodNumber;
9
19
  parent_task: z.ZodNullable<z.ZodString>;
10
20
  constraints: z.ZodArray<z.ZodString>;
11
- allowed_actions: z.ZodArray<z.ZodEnum<{
21
+ allowed_actions: z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
12
22
  observe: "observe";
13
23
  analyze: "analyze";
14
24
  create_artifact: "create_artifact";
@@ -17,18 +27,19 @@ export declare const TeamMissionShape: z.ZodObject<{
17
27
  deploy: "deploy";
18
28
  external_publish: "external_publish";
19
29
  destructive_response: "destructive_response";
20
- }>>;
30
+ }>, z.ZodString]>>;
21
31
  resources: z.ZodArray<z.ZodString>;
22
32
  deadline: z.ZodNumber;
23
33
  acceptance_criteria: z.ZodArray<z.ZodString>;
24
34
  expected_artifacts: z.ZodArray<z.ZodString>;
35
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
25
36
  }, z.core.$strict>;
26
37
  export declare const TeamMission: z.ZodObject<{
27
38
  id: z.ZodString;
28
39
  revision: z.ZodNumber;
29
40
  parent_task: z.ZodNullable<z.ZodString>;
30
41
  constraints: z.ZodArray<z.ZodString>;
31
- allowed_actions: z.ZodArray<z.ZodEnum<{
42
+ allowed_actions: z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
32
43
  observe: "observe";
33
44
  analyze: "analyze";
34
45
  create_artifact: "create_artifact";
@@ -37,11 +48,12 @@ export declare const TeamMission: z.ZodObject<{
37
48
  deploy: "deploy";
38
49
  external_publish: "external_publish";
39
50
  destructive_response: "destructive_response";
40
- }>>;
51
+ }>, z.ZodString]>>;
41
52
  resources: z.ZodArray<z.ZodString>;
42
53
  deadline: z.ZodNumber;
43
54
  acceptance_criteria: z.ZodArray<z.ZodString>;
44
55
  expected_artifacts: z.ZodArray<z.ZodString>;
56
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
45
57
  }, z.core.$strict>;
46
58
  export type TeamMission = z.infer<typeof TeamMission>;
47
59
  export declare const TeamEnvelope: z.ZodObject<{
@@ -54,7 +66,7 @@ export declare const TeamEnvelope: z.ZodObject<{
54
66
  revision: z.ZodNumber;
55
67
  parent_task: z.ZodNullable<z.ZodString>;
56
68
  constraints: z.ZodArray<z.ZodString>;
57
- allowed_actions: z.ZodArray<z.ZodEnum<{
69
+ allowed_actions: z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
58
70
  observe: "observe";
59
71
  analyze: "analyze";
60
72
  create_artifact: "create_artifact";
@@ -63,11 +75,12 @@ export declare const TeamEnvelope: z.ZodObject<{
63
75
  deploy: "deploy";
64
76
  external_publish: "external_publish";
65
77
  destructive_response: "destructive_response";
66
- }>>;
78
+ }>, z.ZodString]>>;
67
79
  resources: z.ZodArray<z.ZodString>;
68
80
  deadline: z.ZodNumber;
69
81
  acceptance_criteria: z.ZodArray<z.ZodString>;
70
82
  expected_artifacts: z.ZodArray<z.ZodString>;
83
+ extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
71
84
  }, z.core.$strict>;
72
85
  }, z.core.$strict>;
73
86
  export type TeamEnvelope = z.infer<typeof TeamEnvelope>;
@@ -112,5 +125,5 @@ export declare const TeamResult: z.ZodObject<{
112
125
  }, z.core.$strict>>;
113
126
  }, z.core.$strict>;
114
127
  export type TeamResult = z.infer<typeof TeamResult>;
115
- export declare function validateTeamEnvelope(value: unknown, authenticatedPeer: string, messageId: string, objective: string, nowSeconds?: number, child?: boolean): TeamEnvelope;
128
+ export declare function validateTeamEnvelope(value: unknown, authenticatedPeer: string, messageId: string, objective: string, nowSeconds?: number, child?: boolean, decode?: (value: unknown) => TeamEnvelope): TeamEnvelope;
116
129
  export declare function validateTeamResult(raw: string, envelope: TeamEnvelope, knownReferences?: ReadonlySet<string>): TeamResult;
@@ -7,7 +7,11 @@ const role = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/);
7
7
  const boundedId = z.string().regex(/^[A-Za-z0-9._:-]{1,128}$/);
8
8
  const text = (bytes) => z.string().trim().min(1).refine(value => Buffer.byteLength(value, 'utf8') <= bytes, `Exceeds ${bytes} bytes`);
9
9
  const texts = (minimum = 0) => z.array(text(1000)).min(minimum).max(32).refine(value => new Set(value).size === value.length, 'Duplicate entries');
10
- const Action = z.enum(['observe', 'analyze', 'create_artifact', 'create_draft', 'reversible_change', 'deploy', 'external_publish', 'destructive_response']);
10
+ export const CoreTeamAction = z.enum(['observe', 'analyze', 'create_artifact', 'create_draft', 'reversible_change', 'deploy', 'external_publish', 'destructive_response']);
11
+ const Action = z.union([
12
+ CoreTeamAction,
13
+ z.string().regex(/^extension:[a-z][a-z0-9-]{0,63}:[a-z][a-z0-9_]{0,63}$/)
14
+ ]);
11
15
  /** The mission shape without its cross-field rules (Zod 4 cannot omit fields from a refined object). */
12
16
  export const TeamMissionShape = z.object({
13
17
  id: boundedId,
@@ -18,7 +22,9 @@ export const TeamMissionShape = z.object({
18
22
  resources: texts(1),
19
23
  deadline: z.number().int().min(1).max(253402300799),
20
24
  acceptance_criteria: texts(1),
21
- expected_artifacts: texts()
25
+ expected_artifacts: texts(),
26
+ /** Validated only by the explicitly configured extension that owns the key. */
27
+ extensions: z.record(z.string().regex(/^[a-z][a-z0-9-]{0,63}$/), z.json()).optional()
22
28
  }).strict();
23
29
  export const TeamMission = TeamMissionShape;
24
30
  export const TeamEnvelope = z.object({ version: z.literal(TEAM_VERSION), caller: role, task_id: boundedId, objective: text(16000), mission: TeamMission }).strict();
@@ -31,15 +37,15 @@ export const TeamResult = z.object({
31
37
  summary: text(16000), checks: z.array(Check).max(32), artifacts: z.array(Artifact).max(32), uncertain_effects: texts(),
32
38
  clarification: Clarification.optional()
33
39
  }).strict();
34
- export function validateTeamEnvelope(value, authenticatedPeer, messageId, objective, nowSeconds = Date.now() / 1000, child = false) {
35
- const envelope = TeamEnvelope.parse(value);
40
+ export function validateTeamEnvelope(value, authenticatedPeer, messageId, objective, nowSeconds = Date.now() / 1000, child = false, decode = value => TeamEnvelope.parse(value)) {
41
+ const envelope = TeamEnvelope.parse(decode(value));
36
42
  if (envelope.caller !== authenticatedPeer || envelope.task_id !== messageId || envelope.objective !== objective)
37
43
  throw new Error('Team envelope does not match authenticated message');
38
44
  if (child ? envelope.mission.parent_task === null : envelope.mission.parent_task !== null)
39
45
  throw new Error('Child mission requires an exact retained root reservation');
40
46
  if (envelope.mission.deadline <= nowSeconds)
41
47
  throw new Error('Team mission deadline expired');
42
- if (Buffer.byteLength(JSON.stringify(envelope), 'utf8') > 48_000)
48
+ if (Buffer.byteLength(JSON.stringify(value), 'utf8') > 48_000 || Buffer.byteLength(JSON.stringify(envelope), 'utf8') > 48_000)
43
49
  throw new Error('Team envelope exceeds 48 KiB');
44
50
  return envelope;
45
51
  }
@@ -1,6 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { z } from 'zod';
3
- import { TeamEnvelope } from './team-contract.js';
4
3
  const id = z.string().regex(/^[A-Za-z0-9._:-]{1,128}$/);
5
4
  const EventsPayload = z.object({ native_task_id: id, after_cursor: z.number().int().min(0), limit: z.number().int().min(1).max(100) }).strict();
6
5
  const ControlPayload = z.object({ native_task_id: id, task_id: id, mission_revision: z.number().int().min(1), control_id: id, control_version: z.number().int().min(1), action: z.enum(['pause', 'resume', 'cancel']) }).strict();
@@ -54,7 +53,7 @@ export class TeamControlService {
54
53
  if (bound.tenant !== tenant || bound.caller !== caller)
55
54
  throw new Error('Team task owner differs');
56
55
  const raw = JSON.parse(bound.envelope_json);
57
- return { envelope: TeamEnvelope.parse(raw), operationId: bound.operation_id };
56
+ return { envelope: this.runtime.decodeTeamEnvelope(raw), operationId: bound.operation_id };
58
57
  }
59
58
  #events(payload, tenant, caller) {
60
59
  const { envelope } = this.#mission(payload.native_task_id, tenant, caller);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hivemagnus/ardent",
3
- "version": "2.3.1",
3
+ "version": "3.1.0",
4
4
  "description": "Headless TypeScript agent runtime with A2A, scheduled jobs, skills, chat channels, and a plugin API",
5
5
  "keywords": [
6
6
  "agent",
@@ -29,6 +29,10 @@
29
29
  "ardent": "dist/cli.js"
30
30
  },
31
31
  "exports": {
32
+ "./plugin-sdk": {
33
+ "types": "./dist/plugin-sdk.d.ts",
34
+ "default": "./dist/plugin-sdk.js"
35
+ },
32
36
  ".": {
33
37
  "types": "./dist/index.d.ts",
34
38
  "default": "./dist/index.js"
@@ -76,7 +80,6 @@
76
80
  "@hivemagnus/canvas-word-codec": "1.1.0",
77
81
  "@hivemagnus/emberfold": "0.1.0",
78
82
  "@hono/node-server": "^2.1.5",
79
- "better-sqlite3": "^13.0.3",
80
83
  "dotenv": "^18.0.9",
81
84
  "express": "5.3.0",
82
85
  "hono": "^4.13.16",
@@ -85,11 +88,11 @@
85
88
  "pdfmake": "0.3.13",
86
89
  "ws": "^8.22.0",
87
90
  "yaml": "2.9.1",
88
- "zod": "^4.6.7"
91
+ "zod": "^4.6.7",
92
+ "@photostructure/sqlite": "3.3.1"
89
93
  },
90
94
  "devDependencies": {
91
95
  "@apidevtools/swagger-parser": "^13.1.0",
92
- "@types/better-sqlite3": "^9.6.0",
93
96
  "@types/express": "5.0.6",
94
97
  "@types/node": "^24.19.2",
95
98
  "@types/pdfmake": "0.3.3",
@@ -111,8 +114,8 @@
111
114
  }
112
115
  },
113
116
  "allowScripts": {
114
- "better-sqlite3@13.0.3": true,
115
117
  "esbuild@0.28.2": true,
116
- "protobufjs@7.6.6": true
118
+ "protobufjs@7.6.6": true,
119
+ "@photostructure/sqlite@3.3.1": true
117
120
  }
118
121
  }