@agentproto/agent-runtime 0.1.0-alpha.0 → 0.1.1
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/LICENSE +202 -21
- package/dist/adapters/dispatcher-mention.d.ts +2 -1
- package/dist/adapters/participant-agent-cli.d.ts +3 -0
- package/dist/adapters/participant-agent-cli.mjs +8 -6
- package/dist/adapters/participant-agent-cli.mjs.map +1 -1
- package/dist/adapters/state-fs.d.ts +2 -1
- package/dist/adapters/substrate-file.d.ts +2 -1
- package/dist/adapters/telemetry.d.ts +1 -39
- package/dist/adapters/telemetry.mjs +1 -74
- package/dist/adapters/telemetry.mjs.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/dist/manifest.d.ts +12 -1
- package/dist/manifest.mjs +6 -0
- package/dist/manifest.mjs.map +1 -1
- package/dist/ports.d.ts +14 -81
- package/package.json +4 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ParticipantExecutor, ParticipantExecuteInput, ParticipantExecuteOutput } from '../ports.js';
|
|
2
2
|
export { parseClaudeJsonOutput } from '@agentproto/cli-exec';
|
|
3
|
+
import '@agentproto/telemetry';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Agent-CLI participant — spawns a CLI binary, pipes the assembled prompt
|
|
@@ -17,6 +18,8 @@ type AgentCliParticipantOptions = {
|
|
|
17
18
|
readonly args?: readonly string[];
|
|
18
19
|
/** Working directory. Defaults to process.cwd(). */
|
|
19
20
|
readonly cwd?: string;
|
|
21
|
+
/** Manifest base directory; relative role paths resolve against this. */
|
|
22
|
+
readonly baseDir?: string;
|
|
20
23
|
/** Hard timeout in ms. Default 90000. */
|
|
21
24
|
readonly timeoutMs?: number;
|
|
22
25
|
/** Optional output parser — if returns null, content falls back to raw stdout. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile } from 'fs/promises';
|
|
2
|
+
import { resolve } from 'path';
|
|
2
3
|
import matter from 'gray-matter';
|
|
3
4
|
import { spawnWithStdin } from '@agentproto/cli-exec';
|
|
4
5
|
export { parseClaudeJsonOutput } from '@agentproto/cli-exec';
|
|
@@ -17,7 +18,7 @@ var AgentCliParticipant = class {
|
|
|
17
18
|
opts;
|
|
18
19
|
kind = "agent-cli";
|
|
19
20
|
async executeTurn(input) {
|
|
20
|
-
const prompt = await assemblePrompt(input);
|
|
21
|
+
const prompt = await assemblePrompt(input, this.opts.baseDir);
|
|
21
22
|
const stdout = await spawnWithStdin({
|
|
22
23
|
command: this.opts.command,
|
|
23
24
|
args: this.opts.args ?? [],
|
|
@@ -31,8 +32,8 @@ var AgentCliParticipant = class {
|
|
|
31
32
|
return { content };
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
|
-
async function assemblePrompt(input) {
|
|
35
|
-
const roleText = input.participant.role ? await loadRole(input.participant.role) : "";
|
|
35
|
+
async function assemblePrompt(input, baseDir) {
|
|
36
|
+
const roleText = input.participant.role ? await loadRole(input.participant.role, baseDir) : "";
|
|
36
37
|
const transcript = input.recentTurns.map((t) => `[${t.participantId}] ${t.content}`).join("\n\n");
|
|
37
38
|
return [
|
|
38
39
|
roleText && `# Your role
|
|
@@ -47,16 +48,17 @@ You are ${input.participant.displayName}. The latest message in the conversation
|
|
|
47
48
|
].filter(Boolean).join("\n\n");
|
|
48
49
|
}
|
|
49
50
|
var ROLE_FILE_EXTENSIONS = [".md", ".markdown", ".txt"];
|
|
50
|
-
async function loadRole(roleField) {
|
|
51
|
+
async function loadRole(roleField, baseDir) {
|
|
51
52
|
if (!looksLikeRoleFile(roleField)) return roleField;
|
|
53
|
+
const path = baseDir ? resolve(baseDir, roleField) : roleField;
|
|
52
54
|
try {
|
|
53
|
-
const raw = await readFile(
|
|
55
|
+
const raw = await readFile(path, "utf8");
|
|
54
56
|
const parsed = matter(raw);
|
|
55
57
|
return parsed.content.trim();
|
|
56
58
|
} catch (err) {
|
|
57
59
|
const code = err.code;
|
|
58
60
|
process.stderr.write(
|
|
59
|
-
`agent-cli participant: role path '${roleField}' not readable (${code ?? "unknown"}); using the literal string as inline role text.
|
|
61
|
+
`agent-cli participant: role path '${roleField}' (resolved to ${path}) not readable (${code ?? "unknown"}); using the literal string as inline role text.
|
|
60
62
|
`
|
|
61
63
|
);
|
|
62
64
|
return roleField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapters/participant-agent-cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/participant-agent-cli.ts"],"names":["resolvePath"],"mappings":";;;;;;;;;;;;;AAsCO,IAAM,sBAAN,MAAyD;AAAA,EAG9D,YAA6B,IAAA,EAAkC;AAAlC,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmC;AAAA,EAAnC,IAAA;AAAA,EAFpB,IAAA,GAAO,WAAA;AAAA,EAIhB,MAAM,YACJ,KAAA,EACmC;AACnC,IAAA,MAAM,SAAS,MAAM,cAAA,CAAe,KAAA,E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CAAO,OAAO,CAAA,CACd,KAAK,MAAM,CAAA;AAChB;AAKA,IAAM,oBAAA,GAAuB,CAAC,KAAA,EAAO,WAAA,EAAa,MAAM,CAAA;AAExD,eAAe,QAAA,CAAS,WAAmB,OAAA,EAAmC;AAC5E,EAAA,IAAI,CAAC,iBAAA,CAAkB,SAAS,CAAA,EAAG,OAAO,SAAA;AAC1C,EAAA,MAAM,IAAA,GAAO,OAAA,GAAUA,OAAA,CAAY,OAAA,EAAS,SAAS,CAAA,GAAI,SAAA;AACzD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AAIvC,IAAA,MAAM,MAAA,GAAS,OAAO,GAAG,CAAA;AACzB,IAAA,OAAO,MAAA,CAAO,QAAQ,IAAA,EAAK;AAAA,EAC7B,SAAS,GAAA,EAAK;AAKZ,IAAA,MAAM,OAAQ,GAAA,CAA8B,IAAA;AAC5C,IAAA,OAAA,CAAQ,MAAA,CAAO,KAAA;AAAA,MACb,qCAAqC,SAAS,CAAA,eAAA,EAAkB,IAAI,CAAA,gBAAA,EAAmB,QAAQ,SAAS,CAAA;AAAA;AAAA,KAC1G;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AACF;AAEA,SAAS,kBAAkB,CAAA,EAAoB;AAC7C,EAAA,MAAM,KAAA,GAAQ,EAAE,WAAA,EAAY;AAC5B,EAAA,OAAO,qBAAqB,IAAA,CAAK,CAAC,QAAQ,KAAA,CAAM,QAAA,CAAS,GAAG,CAAC,CAAA;AAC/D","file":"participant-agent-cli.mjs","sourcesContent":["/**\n * Agent-CLI participant — spawns a CLI binary, pipes the assembled prompt\n * over stdin, and uses captured stdout as the turn content.\n *\n * Works for any CLI that supports a one-shot \"read prompt from stdin,\n * print response to stdout\" mode (claude-code's `--print`, hermes' `-p`,\n * etc.).\n */\n\nimport { readFile } from \"node:fs/promises\"\nimport { resolve as resolvePath } from \"node:path\"\nimport matter from \"gray-matter\"\nimport { spawnWithStdin } from \"@agentproto/cli-exec\"\nimport type {\n ParticipantExecuteInput,\n ParticipantExecuteOutput,\n ParticipantExecutor,\n} from \"../ports.js\"\n\n// Re-exported for back-compat: the JSON-envelope parser now lives in the shared\n// @agentproto/cli-exec package alongside the spawn helper.\nexport { parseClaudeJsonOutput } from \"@agentproto/cli-exec\"\n\nexport type AgentCliParticipantOptions = {\n /** Executable to invoke. Examples: \"claude\", \"hermes\", \"goose\". */\n readonly command: string\n /** Static args. The prompt is fed over stdin, not as an argument. */\n readonly args?: readonly string[]\n /** Working directory. Defaults to process.cwd(). */\n readonly cwd?: string\n /** Manifest base directory; relative role paths resolve against this. */\n readonly baseDir?: string\n /** Hard timeout in ms. Default 90000. */\n readonly timeoutMs?: number\n /** Optional output parser — if returns null, content falls back to raw stdout. */\n readonly parseOutput?: (stdout: string) => string | null\n}\n\nexport class AgentCliParticipant implements ParticipantExecutor {\n readonly kind = \"agent-cli\"\n\n constructor(private readonly opts: AgentCliParticipantOptions) {}\n\n async executeTurn(\n input: ParticipantExecuteInput\n ): Promise<ParticipantExecuteOutput> {\n const prompt = await assemblePrompt(input, this.opts.baseDir)\n const stdout = await spawnWithStdin({\n command: this.opts.command,\n args: this.opts.args ?? [],\n cwd: this.opts.cwd ?? process.cwd(),\n timeoutMs: this.opts.timeoutMs ?? 90000,\n stdin: prompt,\n signal: input.signal,\n })\n const parsed = this.opts.parseOutput?.(stdout) ?? null\n const content = parsed ?? stdout.trimEnd()\n return { content }\n }\n}\n\nasync function assemblePrompt(\n input: ParticipantExecuteInput,\n baseDir?: string\n): Promise<string> {\n const roleText = input.participant.role\n ? await loadRole(input.participant.role, baseDir)\n : \"\"\n\n const transcript = input.recentTurns\n .map((t) => `[${t.participantId}] ${t.content}`)\n .join(\"\\n\\n\")\n\n return [\n roleText && `# Your role\\n\\n${roleText}`,\n `# Recent conversation\\n\\n${transcript}`,\n `# Your turn\\n\\nYou are ${input.participant.displayName}. The latest message in the conversation triggered you (most likely because it mentions you). Read the transcript above and reply in character. Keep it conversational unless the trigger asks for detailed work. Output only your reply — no preamble, no role labels, no quotes around the response.`,\n ]\n .filter(Boolean)\n .join(\"\\n\\n\")\n}\n\n// File extensions we treat as a path-to-role-file. Anything else is\n// inline role text — even strings that contain `/`, which are common\n// in normal sentences (\"I am an AI/ML reviewer\").\nconst ROLE_FILE_EXTENSIONS = [\".md\", \".markdown\", \".txt\"]\n\nasync function loadRole(roleField: string, baseDir?: string): Promise<string> {\n if (!looksLikeRoleFile(roleField)) return roleField\n const path = baseDir ? resolvePath(baseDir, roleField) : roleField\n try {\n const raw = await readFile(path, \"utf8\")\n // Strip optional YAML frontmatter — lets a Claude Code agent\n // definition file (.claude/agents/*.md) double as a swarm role\n // without ferrying the agent's metadata into the prompt.\n const parsed = matter(raw)\n return parsed.content.trim()\n } catch (err) {\n // The string had a role-file extension but the file isn't readable\n // — surface a hint on stderr so authors don't silently get the\n // literal path as a prompt. Still fall back to inline so the swarm\n // doesn't crash on a typo.\n const code = (err as NodeJS.ErrnoException).code\n process.stderr.write(\n `agent-cli participant: role path '${roleField}' (resolved to ${path}) not readable (${code ?? \"unknown\"}); using the literal string as inline role text.\\n`\n )\n return roleField\n }\n}\n\nfunction looksLikeRoleFile(s: string): boolean {\n const lower = s.toLowerCase()\n return ROLE_FILE_EXTENSIONS.some((ext) => lower.endsWith(ext))\n}\n"]}
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Reference Telemetry adapters.
|
|
5
|
-
*
|
|
6
|
-
* Wire `RuntimePorts.telemetry` to one of these (or your own
|
|
7
|
-
* implementation) to receive structured events from each cycle.
|
|
8
|
-
* Sinks may also be composed via `composeTelemetry()`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** No-op sink. Equivalent to leaving `telemetry` undefined on RuntimePorts. */
|
|
12
|
-
declare const noopTelemetry: Telemetry;
|
|
13
|
-
interface StderrTelemetryOptions {
|
|
14
|
-
/** Event kinds to include. Omit to emit all kinds. */
|
|
15
|
-
readonly include?: ReadonlySet<TelemetryEvent["kind"]>;
|
|
16
|
-
/** Event kinds to suppress. Wins over `include`. */
|
|
17
|
-
readonly exclude?: ReadonlySet<TelemetryEvent["kind"]>;
|
|
18
|
-
/** Prefix prepended to every line. Default "agentproto: ". */
|
|
19
|
-
readonly prefix?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Human-readable stderr sink — one line per event. Cheaper than wiring
|
|
23
|
-
* a real exporter; good default for `--verbose` mode.
|
|
24
|
-
*/
|
|
25
|
-
declare function stderrTelemetry(options?: StderrTelemetryOptions): Telemetry;
|
|
26
|
-
/**
|
|
27
|
-
* In-memory sink — every event pushed onto an array. Intended for
|
|
28
|
-
* tests; reach into `events` after `runTurn` to assert.
|
|
29
|
-
*/
|
|
30
|
-
declare function arrayTelemetry(): Telemetry & {
|
|
31
|
-
readonly events: readonly TelemetryEvent[];
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Fan-out — emits every event to all wrapped sinks in order. Useful
|
|
35
|
-
* for "log to stderr AND export to OTEL" setups.
|
|
36
|
-
*/
|
|
37
|
-
declare function composeTelemetry(...sinks: readonly Telemetry[]): Telemetry;
|
|
38
|
-
|
|
39
|
-
export { type StderrTelemetryOptions, arrayTelemetry, composeTelemetry, noopTelemetry, stderrTelemetry };
|
|
1
|
+
export { StderrTelemetryOptions, arrayTelemetry, composeTelemetry, noopTelemetry, stderrTelemetry } from '@agentproto/telemetry';
|
|
@@ -1,76 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* @agentproto/agent-runtime v0.1.0-alpha
|
|
3
|
-
* MultiAgentRuntime kernel — swappable ports + reference adapters
|
|
4
|
-
* (file substrate, mention dispatcher, fs state, agent-cli participant).
|
|
5
|
-
* Transport-specific adapters ship in separate packages.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// src/adapters/telemetry.ts
|
|
9
|
-
var noopTelemetry = {
|
|
10
|
-
emit() {
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
function stderrTelemetry(options = {}) {
|
|
14
|
-
const prefix = options.prefix ?? "agentproto: ";
|
|
15
|
-
return {
|
|
16
|
-
emit(event) {
|
|
17
|
-
if (options.exclude?.has(event.kind)) return;
|
|
18
|
-
if (options.include && !options.include.has(event.kind)) return;
|
|
19
|
-
process.stderr.write(`${prefix}${formatEvent(event)}
|
|
20
|
-
`);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function arrayTelemetry() {
|
|
25
|
-
const events = [];
|
|
26
|
-
return {
|
|
27
|
-
events,
|
|
28
|
-
emit(event) {
|
|
29
|
-
events.push(event);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function composeTelemetry(...sinks) {
|
|
34
|
-
return {
|
|
35
|
-
emit(event) {
|
|
36
|
-
for (const sink of sinks) {
|
|
37
|
-
try {
|
|
38
|
-
sink.emit(event);
|
|
39
|
-
} catch {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function formatEvent(event) {
|
|
46
|
-
switch (event.kind) {
|
|
47
|
-
case "cycle.started":
|
|
48
|
-
return `${event.cycleId} cycle.started${event.since !== void 0 ? ` since=${event.since}` : ""}`;
|
|
49
|
-
case "substrate.read":
|
|
50
|
-
return `${event.cycleId} substrate.read ${event.substrateKind} turns=${event.turnCount} ${event.durationMs}ms`;
|
|
51
|
-
case "dispatch.decided":
|
|
52
|
-
return `${event.cycleId} dispatch.decided ${event.dispatcherKind} selected=[${event.selected.join(",") || "(none)"}] ${event.durationMs}ms`;
|
|
53
|
-
case "participant.started":
|
|
54
|
-
return `${event.cycleId} participant.started ${event.participantId} (${event.executorKind})`;
|
|
55
|
-
case "participant.finished":
|
|
56
|
-
return `${event.cycleId} participant.finished ${event.participantId} ${event.durationMs}ms content=${event.contentLength}b`;
|
|
57
|
-
case "participant.failed":
|
|
58
|
-
return `${event.cycleId} participant.failed ${event.participantId} \u2014 ${event.error}`;
|
|
59
|
-
case "substrate.appended":
|
|
60
|
-
return `${event.cycleId} substrate.appended turn=${event.turnId} by=${event.participantId}`;
|
|
61
|
-
case "state.written":
|
|
62
|
-
return `${event.cycleId} state.written ${event.participantId}`;
|
|
63
|
-
case "cycle.idle":
|
|
64
|
-
return `${event.cycleId} cycle.idle`;
|
|
65
|
-
case "cycle.finished":
|
|
66
|
-
return `${event.cycleId} cycle.finished ${event.outcome} appended=${event.turnsAppended} ${event.durationMs}ms`;
|
|
67
|
-
default: {
|
|
68
|
-
const _exhaustive = event;
|
|
69
|
-
return JSON.stringify(_exhaustive);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { arrayTelemetry, composeTelemetry, noopTelemetry, stderrTelemetry };
|
|
1
|
+
export { arrayTelemetry, composeTelemetry, noopTelemetry, stderrTelemetry } from '@agentproto/telemetry';
|
|
75
2
|
//# sourceMappingURL=telemetry.mjs.map
|
|
76
3
|
//# sourceMappingURL=telemetry.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"telemetry.mjs","sourcesContent":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Dispatcher, DispatcherInput, Lifecycle, ParticipantDescriptor, ParticipantExecuteInput, ParticipantExecuteOutput, ParticipantExecutor,
|
|
3
|
-
|
|
1
|
+
import { Turn, RuntimePorts } from './ports.js';
|
|
2
|
+
export { Dispatcher, DispatcherInput, Lifecycle, ParticipantConfig, ParticipantDescriptor, ParticipantExecuteInput, ParticipantExecuteOutput, ParticipantExecutor, StateStore, Substrate, TurnInput } from './ports.js';
|
|
3
|
+
import { TurnId } from '@agentproto/telemetry';
|
|
4
|
+
export { ParticipantId, Telemetry, TelemetryEvent, TurnId } from '@agentproto/telemetry';
|
|
5
|
+
export { LoadedManifest, MULTI_AGENT_RUNTIME_KIND, MULTI_AGENT_RUNTIME_SCHEMA, MultiAgentRuntimeManifest, MultiAgentRuntimeManifestSchema, ParticipantManifestConfig, loadManifest, parseManifest, resolveManifestPath } from './manifest.js';
|
|
4
6
|
import 'zod';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -33,4 +35,4 @@ type RunTurnResult = {
|
|
|
33
35
|
*/
|
|
34
36
|
declare function runTurn(ports: RuntimePorts, options?: RunTurnOptions): Promise<RunTurnResult>;
|
|
35
37
|
|
|
36
|
-
export { type RunTurnOptions, type RunTurnResult, RuntimePorts, Turn,
|
|
38
|
+
export { type RunTurnOptions, type RunTurnResult, RuntimePorts, Turn, runTurn };
|
package/dist/index.mjs
CHANGED
|
@@ -78,7 +78,7 @@ async function runTurn(ports, options = {}) {
|
|
|
78
78
|
if (!participant) {
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
|
-
const executor = ports.executors.get(
|
|
81
|
+
const executor = ports.executors.get(participantId);
|
|
82
82
|
if (!executor) {
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
@@ -179,11 +179,17 @@ var MULTI_AGENT_RUNTIME_KIND = "MultiAgentRuntime";
|
|
|
179
179
|
var AdapterConfigSchema = z.object({
|
|
180
180
|
kind: z.string().min(1)
|
|
181
181
|
}).loose();
|
|
182
|
+
var ParticipantConfigSchema = z.object({
|
|
183
|
+
command: z.string().min(1).optional(),
|
|
184
|
+
args: z.array(z.string()).optional(),
|
|
185
|
+
model: z.string().min(1).optional()
|
|
186
|
+
}).loose();
|
|
182
187
|
var ParticipantManifestSchema = z.object({
|
|
183
188
|
id: z.string().min(1),
|
|
184
189
|
executor: z.string().min(1),
|
|
185
190
|
displayName: z.string().min(1).optional(),
|
|
186
191
|
role: z.string().optional(),
|
|
192
|
+
config: ParticipantConfigSchema.optional(),
|
|
187
193
|
meta: z.record(z.string(), z.unknown()).optional()
|
|
188
194
|
}).loose();
|
|
189
195
|
var MultiAgentRuntimeManifestSchema = z.object({
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime.ts","../src/manifest.ts"],"names":["resolvePath"],"mappings":";;;;;;;;;;;;;AAwCA,eAAsB,OAAA,CACpB,KAAA,EACA,OAAA,GAA0B,EAAC,EACH;AACxB,EAAA,MAAM,YAAA,GAAe,QAAQ,YAAA,IAAgB,EAAA;AAC7C,EAAA,MAAM,UAAU,UAAA,EAAW;AAC3B,EAAA,MAAM,UAAA,GAAa,KAAK,GAAA,EAAI;AAE5B,EAAA,IAAA,CAAK,MAAM,SAAA,EAAW;AAAA,IACpB,IAAA,EAAM,eAAA;AAAA,IACN,OAAA;AAAA,IACA,IAAI,MAAA,EAAO;AAAA,IACX,GAAI,QAAQ,KAAA,KAAU,MAAA,GAAY,EAAE,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI;AAAC,GAC/D,CAAA;AAED,EAAA,MAAM,SAAA,GAAY,KAAK,GAAA,EAAI;AAC3B,EAAA,MAAM,MAAM,MAAM,KAAA,CAAM,SAAA,CAAU,IAAA,CAAK,QAAQ,KAAK,CAAA;AACpD,EAAA,MAAM,WAAA,GAAc,GAAA,CAAI,KAAA,CAAM,CAAC,YAAY,CAAA;AAC3C,EAAA,IAAA,CAAK,MAAM,SAAA,EAAW;AAAA,IACpB,IAAA,EAAM,gBAAA;AAAA,IACN,OAAA;AAAA,IACA,IAAI,MAAA,EAAO;AAAA,IACX,aAAA,EAAe,MAAM,SAAA,CAAU,IAAA;AAAA,IAC/B,WAAW,WAAA,CAAY,MAAA;AAAA,IACvB,UAAA,EAAY,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,GAC1B,CAAA;AAED,EAAA,MAAM,aAAA,GAAgB,KAAK,GAAA,EAAI;AAC/B,EAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CA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B,EACA,QAAA;AACL,CAAC,EACA,KAAA;AAcI,SAAS,cAAc,MAAA,EAA2C;AACvE,EAAA,MAAM,MAAA,GAAS,OAAO,MAAM,CAAA;AAC5B,EAAA,OAAO,+BAAA,CAAgC,KAAA,CAAM,MAAA,CAAO,IAAI,CAAA;AAC1D;AAEA,eAAsB,aAAa,IAAA,EAAuC;AACxE,EAAA,MAAM,GAAA,GAAMA,QAAY,IAAI,CAAA;AAC5B,EAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,GAAA,EAAK,MAAM,CAAA;AACtC,EAAA,MAAM,MAAA,GAAS,OAAO,GAAG,CAAA;AACzB,EAAA,MAAM,QAAA,GAAW,+BAAA,CAAgC,KAAA,CAAM,MAAA,CAAO,IAAI,CAAA;AAClE,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,MAAM,MAAA,CAAO,OAAA;AAAA,IACb,IAAA,EAAM,GAAA;AAAA,IACN,OAAA,EAAS,QAAQ,GAAG;AAAA,GACtB;AACF;AAGO,SAAS,mBAAA,CAAoB,QAAwB,KAAA,EAAuB;AACjF,EAAA,OAAOA,OAAA,CAAY,MAAA,CAAO,OAAA,EAAS,KAAK,CAAA;AAC1C","file":"index.mjs","sourcesContent":["/**\n * Runtime orchestrator. One cycle =\n * read substrate → dispatch → execute selected participants → append → fire lifecycle.\n *\n * The kernel knows nothing about specific substrates, dispatchers, or\n * executors — it only routes through the port interfaces. Telemetry,\n * if wired, receives a structured event at every phase boundary; the\n * cycleId on each event lets a sink rebuild OTEL-style spans by\n * grouping.\n */\n\nimport { randomBytes } from \"node:crypto\"\nimport type {\n ParticipantDescriptor,\n RuntimePorts,\n Telemetry,\n TelemetryEvent,\n Turn,\n TurnId,\n} from \"./ports.js\"\n\nexport type RunTurnOptions = {\n /** How far back to read from the substrate when building dispatcher input. Default 30. */\n readonly historyLimit?: number\n /** Read turns strictly newer than this id. Default undefined (full snapshot, truncated by historyLimit). */\n readonly since?: TurnId\n /** Abort signal forwarded to participant executors. */\n readonly signal?: AbortSignal\n}\n\nexport type RunTurnResult = {\n readonly cycle: \"executed\" | \"idle\"\n readonly selected: readonly string[]\n readonly turnsAppended: readonly Turn[]\n}\n\n/**\n * Run a single dispatcher cycle. Returns synchronously after one round of\n * dispatch + execute + append. Callers loop for continuous operation.\n */\nexport async function runTurn(\n ports: RuntimePorts,\n options: RunTurnOptions = {}\n): Promise<RunTurnResult> {\n const historyLimit = options.historyLimit ?? 30\n const cycleId = newCycleId()\n const cycleStart = Date.now()\n\n emit(ports.telemetry, {\n kind: \"cycle.started\",\n cycleId,\n at: nowIso(),\n ...(options.since !== undefined ? { since: options.since } : {}),\n })\n\n const readStart = Date.now()\n const all = await ports.substrate.read(options.since)\n const recentTurns = all.slice(-historyLimit)\n emit(ports.telemetry, {\n kind: \"substrate.read\",\n cycleId,\n at: nowIso(),\n substrateKind: ports.substrate.kind,\n turnCount: recentTurns.length,\n durationMs: Date.now() - readStart,\n })\n\n const dispatchStart = Date.now()\n const selected = await ports.dispatcher.selectNext({\n recentTurns,\n participants: ports.participants,\n })\n emit(ports.telemetry, {\n kind: \"dispatch.decided\",\n cycleId,\n at: nowIso(),\n dispatcherKind: ports.dispatcher.kind,\n selected,\n durationMs: Date.now() - dispatchStart,\n })\n\n if (selected.length === 0) {\n await ports.lifecycle?.onIdle?.()\n emit(ports.telemetry, { kind: \"cycle.idle\", cycleId, at: nowIso() })\n emit(ports.telemetry, {\n kind: \"cycle.finished\",\n cycleId,\n at: nowIso(),\n outcome: \"idle\",\n turnsAppended: 0,\n durationMs: Date.now() - cycleStart,\n })\n return { cycle: \"idle\", selected: [], turnsAppended: [] }\n }\n\n const triggerTurn = recentTurns[recentTurns.length - 1]\n if (!triggerTurn) {\n // Dispatcher selected someone but there's no recent turn to trigger off.\n // Treat as idle — dispatchers should not pick speakers from an empty substrate.\n await ports.lifecycle?.onIdle?.()\n emit(ports.telemetry, { kind: \"cycle.idle\", cycleId, at: nowIso() })\n emit(ports.telemetry, {\n kind: \"cycle.finished\",\n cycleId,\n at: nowIso(),\n outcome: \"idle\",\n turnsAppended: 0,\n durationMs: Date.now() - cycleStart,\n })\n return { cycle: \"idle\", selected: [], turnsAppended: [] }\n }\n\n const appended: Turn[] = []\n\n for (const participantId of selected) {\n const participant = findParticipant(ports.participants, participantId)\n if (!participant) {\n // Dispatcher hallucinated an unknown participant. Skip rather than crash —\n // a malformed dispatcher shouldn't take down the loop.\n continue\n }\n const executor = ports.executors.get(participant.executor)\n if (!executor) {\n // Manifest declared a participant whose executor isn't registered.\n // Skip; misconfiguration shows up in logs but the loop survives.\n continue\n }\n\n await ports.lifecycle?.onMention?.(participantId, triggerTurn)\n\n const state = await ports.state.read(participantId)\n\n emit(ports.telemetry, {\n kind: \"participant.started\",\n cycleId,\n at: nowIso(),\n participantId,\n executorKind: participant.executor,\n })\n\n const execStart = Date.now()\n let output\n try {\n output = await executor.executeTurn({\n participant,\n recentTurns,\n triggerTurn,\n state,\n signal: options.signal,\n })\n } catch (err) {\n emit(ports.telemetry, {\n kind: \"participant.failed\",\n cycleId,\n at: nowIso(),\n participantId,\n executorKind: participant.executor,\n error: err instanceof Error ? err.message : String(err),\n })\n throw err\n }\n\n emit(ports.telemetry, {\n kind: \"participant.finished\",\n cycleId,\n at: nowIso(),\n participantId,\n executorKind: participant.executor,\n durationMs: Date.now() - execStart,\n contentLength: output.content.length,\n })\n\n const turn = await ports.substrate.append({\n participantId,\n content: output.content,\n meta: output.meta,\n })\n appended.push(turn)\n emit(ports.telemetry, {\n kind: \"substrate.appended\",\n cycleId,\n at: nowIso(),\n turnId: turn.id,\n participantId,\n })\n\n if (output.stateUpdate) {\n await ports.state.write(participantId, output.stateUpdate)\n emit(ports.telemetry, {\n kind: \"state.written\",\n cycleId,\n at: nowIso(),\n participantId,\n })\n }\n\n await ports.lifecycle?.onTurnEnd?.(turn)\n }\n\n emit(ports.telemetry, {\n kind: \"cycle.finished\",\n cycleId,\n at: nowIso(),\n outcome: \"executed\",\n turnsAppended: appended.length,\n durationMs: Date.now() - cycleStart,\n })\n\n return { cycle: \"executed\", selected, turnsAppended: appended }\n}\n\nfunction findParticipant(\n participants: readonly ParticipantDescriptor[],\n id: string\n): ParticipantDescriptor | undefined {\n for (const p of participants) {\n if (p.id === id) return p\n }\n return undefined\n}\n\nfunction emit(telemetry: Telemetry | undefined, event: TelemetryEvent): void {\n // Sinks throwing must not take down the cycle — observability is\n // non-load-bearing for the conversation.\n if (!telemetry) return\n try {\n telemetry.emit(event)\n } catch {\n // Swallow. Better to lose a metric than to corrupt a turn.\n }\n}\n\nfunction nowIso(): string {\n return new Date().toISOString()\n}\n\nfunction newCycleId(): string {\n // 96-bit random id, base32-ish — short enough to read, wide enough\n // to be unique within a swarm process's lifetime.\n return `c_${randomBytes(6).toString(\"hex\")}`\n}\n","/**\n * MultiAgentRuntime manifest schema + loader.\n *\n * The manifest is markdown with YAML frontmatter (matching @agentproto's\n * doctype convention used by ROLE.md, OPERATOR.md, etc.). The frontmatter\n * is the structured contract; the markdown body is human-readable\n * documentation of what the swarm does.\n *\n * Loader is filesystem-bound but parsing is pure — the schema can be used\n * by tests with inline strings via `parseManifest()`.\n */\n\nimport { readFile } from \"node:fs/promises\"\nimport { resolve as resolvePath, dirname } from \"node:path\"\nimport matter from \"gray-matter\"\nimport { z } from \"zod\"\n\nexport const MULTI_AGENT_RUNTIME_SCHEMA = \"agentruntimes/v1\"\nexport const MULTI_AGENT_RUNTIME_KIND = \"MultiAgentRuntime\"\n\nconst AdapterConfigSchema = z\n .object({\n kind: z.string().min(1),\n })\n .loose()\n\nconst ParticipantManifestSchema = z\n .object({\n id: z.string().min(1),\n executor: z.string().min(1),\n displayName: z.string().min(1).optional(),\n role: z.string().optional(),\n meta: z.record(z.string(), z.unknown()).optional(),\n })\n .loose()\n\nexport const MultiAgentRuntimeManifestSchema = z\n .object({\n schema: z.literal(MULTI_AGENT_RUNTIME_SCHEMA),\n kind: z.literal(MULTI_AGENT_RUNTIME_KIND),\n id: z.string().min(1),\n participants: z.array(ParticipantManifestSchema).min(1),\n substrate: AdapterConfigSchema,\n dispatcher: AdapterConfigSchema,\n state: AdapterConfigSchema.optional(),\n lifecycle: z\n .object({\n onTurnEnd: z.boolean().optional(),\n onMention: z.boolean().optional(),\n onIdle: z.boolean().optional(),\n })\n .optional(),\n })\n .loose()\n\nexport type MultiAgentRuntimeManifest = z.infer<\n typeof MultiAgentRuntimeManifestSchema\n>\n\nexport type LoadedManifest = {\n readonly manifest: MultiAgentRuntimeManifest\n readonly body: string\n readonly path: string\n /** Absolute directory of the manifest file — adapter configs that reference paths resolve relative to this. */\n readonly baseDir: string\n}\n\nexport function parseManifest(source: string): MultiAgentRuntimeManifest {\n const parsed = matter(source)\n return MultiAgentRuntimeManifestSchema.parse(parsed.data)\n}\n\nexport async function loadManifest(path: string): Promise<LoadedManifest> {\n const abs = resolvePath(path)\n const raw = await readFile(abs, \"utf8\")\n const parsed = matter(raw)\n const manifest = MultiAgentRuntimeManifestSchema.parse(parsed.data)\n return {\n manifest,\n body: parsed.content,\n path: abs,\n baseDir: dirname(abs),\n }\n}\n\n/** Resolve a path string from a manifest field, relative to the manifest's directory. */\nexport function resolveManifestPath(loaded: LoadedManifest, value: string): string {\n return resolvePath(loaded.baseDir, value)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts","../src/manifest.ts"],"names":["resolvePath"],"mappings":";;;;;;;;;;;;;AAwCA,eAAsB,OAAA,CACpB,KAAA,EACA,OAAA,GAA0B,EAAC,EACH;AACxB,EAAA,MAAM,YAAA,GAAe,QAAQ,YAAA,IAAgB,EAAA;AAC7C,EAAA,MAAM,UAAU,UAAA,EAAW;AAC3B,EAAA,MAAM,UAAA,GAAa,KAAK,GAAA,EAAI;AAE5B,EAAA,IAAA,CAAK,MAAM,SAAA,EAAW;AAAA,IACpB,IAAA,EAAM,eAAA;AAAA,IACN,OAAA;AAAA,IACA,IAAI,MAAA,EAAO;AAAA,IACX,GAAI,QAAQ,KAAA,KAA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EAAA,MAAM,GAAA,GAAMA,QAAY,IAAI,CAAA;AAC5B,EAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,GAAA,EAAK,MAAM,CAAA;AACtC,EAAA,MAAM,MAAA,GAAS,OAAO,GAAG,CAAA;AACzB,EAAA,MAAM,QAAA,GAAW,+BAAA,CAAgC,KAAA,CAAM,MAAA,CAAO,IAAI,CAAA;AAClE,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,MAAM,MAAA,CAAO,OAAA;AAAA,IACb,IAAA,EAAM,GAAA;AAAA,IACN,OAAA,EAAS,QAAQ,GAAG;AAAA,GACtB;AACF;AAGO,SAAS,mBAAA,CAAoB,QAAwB,KAAA,EAAuB;AACjF,EAAA,OAAOA,OAAA,CAAY,MAAA,CAAO,OAAA,EAAS,KAAK,CAAA;AAC1C","file":"index.mjs","sourcesContent":["/**\n * Runtime orchestrator. One cycle =\n * read substrate → dispatch → execute selected participants → append → fire lifecycle.\n *\n * The kernel knows nothing about specific substrates, dispatchers, or\n * executors — it only routes through the port interfaces. Telemetry,\n * if wired, receives a structured event at every phase boundary; the\n * cycleId on each event lets a sink rebuild OTEL-style spans by\n * grouping.\n */\n\nimport { randomBytes } from \"node:crypto\"\nimport type {\n ParticipantDescriptor,\n RuntimePorts,\n Telemetry,\n TelemetryEvent,\n Turn,\n TurnId,\n} from \"./ports.js\"\n\nexport type RunTurnOptions = {\n /** How far back to read from the substrate when building dispatcher input. Default 30. */\n readonly historyLimit?: number\n /** Read turns strictly newer than this id. Default undefined (full snapshot, truncated by historyLimit). */\n readonly since?: TurnId\n /** Abort signal forwarded to participant executors. */\n readonly signal?: AbortSignal\n}\n\nexport type RunTurnResult = {\n readonly cycle: \"executed\" | \"idle\"\n readonly selected: readonly string[]\n readonly turnsAppended: readonly Turn[]\n}\n\n/**\n * Run a single dispatcher cycle. Returns synchronously after one round of\n * dispatch + execute + append. Callers loop for continuous operation.\n */\nexport async function runTurn(\n ports: RuntimePorts,\n options: RunTurnOptions = {}\n): Promise<RunTurnResult> {\n const historyLimit = options.historyLimit ?? 30\n const cycleId = newCycleId()\n const cycleStart = Date.now()\n\n emit(ports.telemetry, {\n kind: \"cycle.started\",\n cycleId,\n at: nowIso(),\n ...(options.since !== undefined ? { since: options.since } : {}),\n })\n\n const readStart = Date.now()\n const all = await ports.substrate.read(options.since)\n const recentTurns = all.slice(-historyLimit)\n emit(ports.telemetry, {\n kind: \"substrate.read\",\n cycleId,\n at: nowIso(),\n substrateKind: ports.substrate.kind,\n turnCount: recentTurns.length,\n durationMs: Date.now() - readStart,\n })\n\n const dispatchStart = Date.now()\n const selected = await ports.dispatcher.selectNext({\n recentTurns,\n participants: ports.participants,\n })\n emit(ports.telemetry, {\n kind: \"dispatch.decided\",\n cycleId,\n at: nowIso(),\n dispatcherKind: ports.dispatcher.kind,\n selected,\n durationMs: Date.now() - dispatchStart,\n })\n\n if (selected.length === 0) {\n await ports.lifecycle?.onIdle?.()\n emit(ports.telemetry, { kind: \"cycle.idle\", cycleId, at: nowIso() })\n emit(ports.telemetry, {\n kind: \"cycle.finished\",\n cycleId,\n at: nowIso(),\n outcome: \"idle\",\n turnsAppended: 0,\n durationMs: Date.now() - cycleStart,\n })\n return { cycle: \"idle\", selected: [], turnsAppended: [] }\n }\n\n const triggerTurn = recentTurns[recentTurns.length - 1]\n if (!triggerTurn) {\n // Dispatcher selected someone but there's no recent turn to trigger off.\n // Treat as idle — dispatchers should not pick speakers from an empty substrate.\n await ports.lifecycle?.onIdle?.()\n emit(ports.telemetry, { kind: \"cycle.idle\", cycleId, at: nowIso() })\n emit(ports.telemetry, {\n kind: \"cycle.finished\",\n cycleId,\n at: nowIso(),\n outcome: \"idle\",\n turnsAppended: 0,\n durationMs: Date.now() - cycleStart,\n })\n return { cycle: \"idle\", selected: [], turnsAppended: [] }\n }\n\n const appended: Turn[] = []\n\n for (const participantId of selected) {\n const participant = findParticipant(ports.participants, participantId)\n if (!participant) {\n // Dispatcher hallucinated an unknown participant. Skip rather than crash —\n // a malformed dispatcher shouldn't take down the loop.\n continue\n }\n const executor = ports.executors.get(participantId)\n if (!executor) {\n // Manifest declared a participant whose executor isn't registered.\n // Skip; misconfiguration shows up in logs but the loop survives.\n continue\n }\n\n await ports.lifecycle?.onMention?.(participantId, triggerTurn)\n\n const state = await ports.state.read(participantId)\n\n emit(ports.telemetry, {\n kind: \"participant.started\",\n cycleId,\n at: nowIso(),\n participantId,\n executorKind: participant.executor,\n })\n\n const execStart = Date.now()\n let output\n try {\n output = await executor.executeTurn({\n participant,\n recentTurns,\n triggerTurn,\n state,\n signal: options.signal,\n })\n } catch (err) {\n emit(ports.telemetry, {\n kind: \"participant.failed\",\n cycleId,\n at: nowIso(),\n participantId,\n executorKind: participant.executor,\n error: err instanceof Error ? err.message : String(err),\n })\n throw err\n }\n\n emit(ports.telemetry, {\n kind: \"participant.finished\",\n cycleId,\n at: nowIso(),\n participantId,\n executorKind: participant.executor,\n durationMs: Date.now() - execStart,\n contentLength: output.content.length,\n })\n\n const turn = await ports.substrate.append({\n participantId,\n content: output.content,\n meta: output.meta,\n })\n appended.push(turn)\n emit(ports.telemetry, {\n kind: \"substrate.appended\",\n cycleId,\n at: nowIso(),\n turnId: turn.id,\n participantId,\n })\n\n if (output.stateUpdate) {\n await ports.state.write(participantId, output.stateUpdate)\n emit(ports.telemetry, {\n kind: \"state.written\",\n cycleId,\n at: nowIso(),\n participantId,\n })\n }\n\n await ports.lifecycle?.onTurnEnd?.(turn)\n }\n\n emit(ports.telemetry, {\n kind: \"cycle.finished\",\n cycleId,\n at: nowIso(),\n outcome: \"executed\",\n turnsAppended: appended.length,\n durationMs: Date.now() - cycleStart,\n })\n\n return { cycle: \"executed\", selected, turnsAppended: appended }\n}\n\nfunction findParticipant(\n participants: readonly ParticipantDescriptor[],\n id: string\n): ParticipantDescriptor | undefined {\n for (const p of participants) {\n if (p.id === id) return p\n }\n return undefined\n}\n\nfunction emit(telemetry: Telemetry | undefined, event: TelemetryEvent): void {\n // Sinks throwing must not take down the cycle — observability is\n // non-load-bearing for the conversation.\n if (!telemetry) return\n try {\n telemetry.emit(event)\n } catch {\n // Swallow. Better to lose a metric than to corrupt a turn.\n }\n}\n\nfunction nowIso(): string {\n return new Date().toISOString()\n}\n\nfunction newCycleId(): string {\n // 96-bit random id, base32-ish — short enough to read, wide enough\n // to be unique within a swarm process's lifetime.\n return `c_${randomBytes(6).toString(\"hex\")}`\n}\n","/**\n * MultiAgentRuntime manifest schema + loader.\n *\n * The manifest is markdown with YAML frontmatter (matching @agentproto's\n * doctype convention used by ROLE.md, OPERATOR.md, etc.). The frontmatter\n * is the structured contract; the markdown body is human-readable\n * documentation of what the swarm does.\n *\n * Loader is filesystem-bound but parsing is pure — the schema can be used\n * by tests with inline strings via `parseManifest()`.\n */\n\nimport { readFile } from \"node:fs/promises\"\nimport { resolve as resolvePath, dirname } from \"node:path\"\nimport matter from \"gray-matter\"\nimport { z } from \"zod\"\n\nexport const MULTI_AGENT_RUNTIME_SCHEMA = \"agentruntimes/v1\"\nexport const MULTI_AGENT_RUNTIME_KIND = \"MultiAgentRuntime\"\n\nconst AdapterConfigSchema = z\n .object({\n kind: z.string().min(1),\n })\n .loose()\n\nconst ParticipantConfigSchema = z\n .object({\n command: z.string().min(1).optional(),\n args: z.array(z.string()).optional(),\n model: z.string().min(1).optional(),\n })\n .loose()\n\nconst ParticipantManifestSchema = z\n .object({\n id: z.string().min(1),\n executor: z.string().min(1),\n displayName: z.string().min(1).optional(),\n role: z.string().optional(),\n config: ParticipantConfigSchema.optional(),\n meta: z.record(z.string(), z.unknown()).optional(),\n })\n .loose()\n\nexport type ParticipantManifestConfig = z.infer<typeof ParticipantConfigSchema>\n\nexport const MultiAgentRuntimeManifestSchema = z\n .object({\n schema: z.literal(MULTI_AGENT_RUNTIME_SCHEMA),\n kind: z.literal(MULTI_AGENT_RUNTIME_KIND),\n id: z.string().min(1),\n participants: z.array(ParticipantManifestSchema).min(1),\n substrate: AdapterConfigSchema,\n dispatcher: AdapterConfigSchema,\n state: AdapterConfigSchema.optional(),\n lifecycle: z\n .object({\n onTurnEnd: z.boolean().optional(),\n onMention: z.boolean().optional(),\n onIdle: z.boolean().optional(),\n })\n .optional(),\n })\n .loose()\n\nexport type MultiAgentRuntimeManifest = z.infer<\n typeof MultiAgentRuntimeManifestSchema\n>\n\nexport type LoadedManifest = {\n readonly manifest: MultiAgentRuntimeManifest\n readonly body: string\n readonly path: string\n /** Absolute directory of the manifest file — adapter configs that reference paths resolve relative to this. */\n readonly baseDir: string\n}\n\nexport function parseManifest(source: string): MultiAgentRuntimeManifest {\n const parsed = matter(source)\n return MultiAgentRuntimeManifestSchema.parse(parsed.data)\n}\n\nexport async function loadManifest(path: string): Promise<LoadedManifest> {\n const abs = resolvePath(path)\n const raw = await readFile(abs, \"utf8\")\n const parsed = matter(raw)\n const manifest = MultiAgentRuntimeManifestSchema.parse(parsed.data)\n return {\n manifest,\n body: parsed.content,\n path: abs,\n baseDir: dirname(abs),\n }\n}\n\n/** Resolve a path string from a manifest field, relative to the manifest's directory. */\nexport function resolveManifestPath(loaded: LoadedManifest, value: string): string {\n return resolvePath(loaded.baseDir, value)\n}\n"]}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ import { z } from 'zod';
|
|
|
14
14
|
|
|
15
15
|
declare const MULTI_AGENT_RUNTIME_SCHEMA = "agentruntimes/v1";
|
|
16
16
|
declare const MULTI_AGENT_RUNTIME_KIND = "MultiAgentRuntime";
|
|
17
|
+
declare const ParticipantConfigSchema: z.ZodObject<{
|
|
18
|
+
command: z.ZodOptional<z.ZodString>;
|
|
19
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
model: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$loose>;
|
|
22
|
+
type ParticipantManifestConfig = z.infer<typeof ParticipantConfigSchema>;
|
|
17
23
|
declare const MultiAgentRuntimeManifestSchema: z.ZodObject<{
|
|
18
24
|
schema: z.ZodLiteral<"agentruntimes/v1">;
|
|
19
25
|
kind: z.ZodLiteral<"MultiAgentRuntime">;
|
|
@@ -23,6 +29,11 @@ declare const MultiAgentRuntimeManifestSchema: z.ZodObject<{
|
|
|
23
29
|
executor: z.ZodString;
|
|
24
30
|
displayName: z.ZodOptional<z.ZodString>;
|
|
25
31
|
role: z.ZodOptional<z.ZodString>;
|
|
32
|
+
config: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
command: z.ZodOptional<z.ZodString>;
|
|
34
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
35
|
+
model: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$loose>>;
|
|
26
37
|
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
27
38
|
}, z.core.$loose>>;
|
|
28
39
|
substrate: z.ZodObject<{
|
|
@@ -53,4 +64,4 @@ declare function loadManifest(path: string): Promise<LoadedManifest>;
|
|
|
53
64
|
/** Resolve a path string from a manifest field, relative to the manifest's directory. */
|
|
54
65
|
declare function resolveManifestPath(loaded: LoadedManifest, value: string): string;
|
|
55
66
|
|
|
56
|
-
export { type LoadedManifest, MULTI_AGENT_RUNTIME_KIND, MULTI_AGENT_RUNTIME_SCHEMA, type MultiAgentRuntimeManifest, MultiAgentRuntimeManifestSchema, loadManifest, parseManifest, resolveManifestPath };
|
|
67
|
+
export { type LoadedManifest, MULTI_AGENT_RUNTIME_KIND, MULTI_AGENT_RUNTIME_SCHEMA, type MultiAgentRuntimeManifest, MultiAgentRuntimeManifestSchema, type ParticipantManifestConfig, loadManifest, parseManifest, resolveManifestPath };
|
package/dist/manifest.mjs
CHANGED
|
@@ -15,11 +15,17 @@ var MULTI_AGENT_RUNTIME_KIND = "MultiAgentRuntime";
|
|
|
15
15
|
var AdapterConfigSchema = z.object({
|
|
16
16
|
kind: z.string().min(1)
|
|
17
17
|
}).loose();
|
|
18
|
+
var ParticipantConfigSchema = z.object({
|
|
19
|
+
command: z.string().min(1).optional(),
|
|
20
|
+
args: z.array(z.string()).optional(),
|
|
21
|
+
model: z.string().min(1).optional()
|
|
22
|
+
}).loose();
|
|
18
23
|
var ParticipantManifestSchema = z.object({
|
|
19
24
|
id: z.string().min(1),
|
|
20
25
|
executor: z.string().min(1),
|
|
21
26
|
displayName: z.string().min(1).optional(),
|
|
22
27
|
role: z.string().optional(),
|
|
28
|
+
config: ParticipantConfigSchema.optional(),
|
|
23
29
|
meta: z.record(z.string(), z.unknown()).optional()
|
|
24
30
|
}).loose();
|
|
25
31
|
var MultiAgentRuntimeManifestSchema = z.object({
|
package/dist/manifest.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/manifest.ts"],"names":["resolvePath"],"mappings":";;;;;;;;;;;;AAiBO,IAAM,0BAAA,GAA6B;AACnC,IAAM,wBAAA,GAA2B;AAExC,IAAM,mBAAA,GAAsB,EACzB,MAAA,CAAO;AAAA,EACN,IAAA,EAAM,CAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC;AACxB,CAAC,EACA,KAAA,EAAM;AAET,IAAM,yBAAA,GAA4B,EAC/B,MAAA,CAAO;AAAA,EACN,EAAA,EAAI,CAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EACpB,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EAC1B,aAAa,CAAA,CAAE,MAAA,GAAS,GAAA,CAAI,CAAC,EAAE,QAAA,EAAS;AAAA,EACxC,IAAA,EAAM,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC1B,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,MAAA,IAAU,CAAA,CAAE,OAAA,EAAS,CAAA,CAAE,QAAA;AAC1C,CAAC,EACA,KAAA,EAAM;
|
|
1
|
+
{"version":3,"sources":["../src/manifest.ts"],"names":["resolvePath"],"mappings":";;;;;;;;;;;;AA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esContent":["/**\n * MultiAgentRuntime manifest schema + loader.\n *\n * The manifest is markdown with YAML frontmatter (matching @agentproto's\n * doctype convention used by ROLE.md, OPERATOR.md, etc.). The frontmatter\n * is the structured contract; the markdown body is human-readable\n * documentation of what the swarm does.\n *\n * Loader is filesystem-bound but parsing is pure — the schema can be used\n * by tests with inline strings via `parseManifest()`.\n */\n\nimport { readFile } from \"node:fs/promises\"\nimport { resolve as resolvePath, dirname } from \"node:path\"\nimport matter from \"gray-matter\"\nimport { z } from \"zod\"\n\nexport const MULTI_AGENT_RUNTIME_SCHEMA = \"agentruntimes/v1\"\nexport const MULTI_AGENT_RUNTIME_KIND = \"MultiAgentRuntime\"\n\nconst AdapterConfigSchema = z\n .object({\n kind: z.string().min(1),\n })\n .loose()\n\nconst ParticipantConfigSchema = z\n .object({\n command: z.string().min(1).optional(),\n args: z.array(z.string()).optional(),\n model: z.string().min(1).optional(),\n })\n .loose()\n\nconst ParticipantManifestSchema = z\n .object({\n id: z.string().min(1),\n executor: z.string().min(1),\n displayName: z.string().min(1).optional(),\n role: z.string().optional(),\n config: ParticipantConfigSchema.optional(),\n meta: z.record(z.string(), z.unknown()).optional(),\n })\n .loose()\n\nexport type ParticipantManifestConfig = z.infer<typeof ParticipantConfigSchema>\n\nexport const MultiAgentRuntimeManifestSchema = z\n .object({\n schema: z.literal(MULTI_AGENT_RUNTIME_SCHEMA),\n kind: z.literal(MULTI_AGENT_RUNTIME_KIND),\n id: z.string().min(1),\n participants: z.array(ParticipantManifestSchema).min(1),\n substrate: AdapterConfigSchema,\n dispatcher: AdapterConfigSchema,\n state: AdapterConfigSchema.optional(),\n lifecycle: z\n .object({\n onTurnEnd: z.boolean().optional(),\n onMention: z.boolean().optional(),\n onIdle: z.boolean().optional(),\n })\n .optional(),\n })\n .loose()\n\nexport type MultiAgentRuntimeManifest = z.infer<\n typeof MultiAgentRuntimeManifestSchema\n>\n\nexport type LoadedManifest = {\n readonly manifest: MultiAgentRuntimeManifest\n readonly body: string\n readonly path: string\n /** Absolute directory of the manifest file — adapter configs that reference paths resolve relative to this. */\n readonly baseDir: string\n}\n\nexport function parseManifest(source: string): MultiAgentRuntimeManifest {\n const parsed = matter(source)\n return MultiAgentRuntimeManifestSchema.parse(parsed.data)\n}\n\nexport async function loadManifest(path: string): Promise<LoadedManifest> {\n const abs = resolvePath(path)\n const raw = await readFile(abs, \"utf8\")\n const parsed = matter(raw)\n const manifest = MultiAgentRuntimeManifestSchema.parse(parsed.data)\n return {\n manifest,\n body: parsed.content,\n path: abs,\n baseDir: dirname(abs),\n }\n}\n\n/** Resolve a path string from a manifest field, relative to the manifest's directory. */\nexport function resolveManifestPath(loaded: LoadedManifest, value: string): string {\n return resolvePath(loaded.baseDir, value)\n}\n"]}
|
package/dist/ports.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { TurnId, ParticipantId, Telemetry } from '@agentproto/telemetry';
|
|
2
|
+
export { ParticipantId, Telemetry, TelemetryEvent, TurnId } from '@agentproto/telemetry';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Port contracts for the MultiAgentRuntime kernel.
|
|
3
6
|
*
|
|
@@ -6,8 +9,7 @@
|
|
|
6
9
|
* the kernel dispatches polymorphically by looking up factories in the
|
|
7
10
|
* registry, never by matching kind strings inside the kernel itself.
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
type TurnId = string;
|
|
12
|
+
|
|
11
13
|
type Turn = {
|
|
12
14
|
readonly id: TurnId;
|
|
13
15
|
readonly participantId: ParticipantId;
|
|
@@ -25,12 +27,18 @@ interface Substrate {
|
|
|
25
27
|
/** Snapshot. If `since` is provided, returns turns strictly newer than that TurnId, oldest first. */
|
|
26
28
|
read(since?: TurnId): Promise<readonly Turn[]>;
|
|
27
29
|
}
|
|
30
|
+
type ParticipantConfig = {
|
|
31
|
+
readonly command?: string;
|
|
32
|
+
readonly args?: readonly string[];
|
|
33
|
+
readonly model?: string;
|
|
34
|
+
};
|
|
28
35
|
type ParticipantDescriptor = {
|
|
29
36
|
readonly id: ParticipantId;
|
|
30
37
|
readonly displayName: string;
|
|
31
|
-
/** Executor kind —
|
|
38
|
+
/** Executor kind — e.g. "agent-cli". The runtime looks up the concrete executor per participant. */
|
|
32
39
|
readonly executor: string;
|
|
33
40
|
readonly role?: string;
|
|
41
|
+
readonly config?: ParticipantConfig;
|
|
34
42
|
readonly meta?: Readonly<Record<string, unknown>>;
|
|
35
43
|
};
|
|
36
44
|
type ParticipantExecuteInput = {
|
|
@@ -71,82 +79,6 @@ interface Lifecycle {
|
|
|
71
79
|
onMention?(target: ParticipantId, byTurn: Turn): Promise<void> | void;
|
|
72
80
|
onIdle?(): Promise<void> | void;
|
|
73
81
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Discriminated union of every event the kernel emits during a cycle.
|
|
76
|
-
*
|
|
77
|
-
* Every event carries `cycleId` (a per-cycle ULID-ish identifier) and
|
|
78
|
-
* `at` (ISO timestamp), so a sink can rebuild OTEL-style spans by
|
|
79
|
-
* grouping on cycleId.
|
|
80
|
-
*
|
|
81
|
-
* Sinks MUST tolerate unknown kinds — future kernel versions may add
|
|
82
|
-
* event types under the same `agentproto/telemetry/v1` schema.
|
|
83
|
-
*/
|
|
84
|
-
type TelemetryEvent = {
|
|
85
|
-
readonly kind: "cycle.started";
|
|
86
|
-
readonly cycleId: string;
|
|
87
|
-
readonly at: string;
|
|
88
|
-
readonly since?: TurnId;
|
|
89
|
-
} | {
|
|
90
|
-
readonly kind: "substrate.read";
|
|
91
|
-
readonly cycleId: string;
|
|
92
|
-
readonly at: string;
|
|
93
|
-
readonly substrateKind: string;
|
|
94
|
-
readonly turnCount: number;
|
|
95
|
-
readonly durationMs: number;
|
|
96
|
-
} | {
|
|
97
|
-
readonly kind: "dispatch.decided";
|
|
98
|
-
readonly cycleId: string;
|
|
99
|
-
readonly at: string;
|
|
100
|
-
readonly dispatcherKind: string;
|
|
101
|
-
readonly selected: readonly ParticipantId[];
|
|
102
|
-
readonly durationMs: number;
|
|
103
|
-
} | {
|
|
104
|
-
readonly kind: "participant.started";
|
|
105
|
-
readonly cycleId: string;
|
|
106
|
-
readonly at: string;
|
|
107
|
-
readonly participantId: ParticipantId;
|
|
108
|
-
readonly executorKind: string;
|
|
109
|
-
} | {
|
|
110
|
-
readonly kind: "participant.finished";
|
|
111
|
-
readonly cycleId: string;
|
|
112
|
-
readonly at: string;
|
|
113
|
-
readonly participantId: ParticipantId;
|
|
114
|
-
readonly executorKind: string;
|
|
115
|
-
readonly durationMs: number;
|
|
116
|
-
readonly contentLength: number;
|
|
117
|
-
} | {
|
|
118
|
-
readonly kind: "participant.failed";
|
|
119
|
-
readonly cycleId: string;
|
|
120
|
-
readonly at: string;
|
|
121
|
-
readonly participantId: ParticipantId;
|
|
122
|
-
readonly executorKind: string;
|
|
123
|
-
readonly error: string;
|
|
124
|
-
} | {
|
|
125
|
-
readonly kind: "substrate.appended";
|
|
126
|
-
readonly cycleId: string;
|
|
127
|
-
readonly at: string;
|
|
128
|
-
readonly turnId: TurnId;
|
|
129
|
-
readonly participantId: ParticipantId;
|
|
130
|
-
} | {
|
|
131
|
-
readonly kind: "state.written";
|
|
132
|
-
readonly cycleId: string;
|
|
133
|
-
readonly at: string;
|
|
134
|
-
readonly participantId: ParticipantId;
|
|
135
|
-
} | {
|
|
136
|
-
readonly kind: "cycle.idle";
|
|
137
|
-
readonly cycleId: string;
|
|
138
|
-
readonly at: string;
|
|
139
|
-
} | {
|
|
140
|
-
readonly kind: "cycle.finished";
|
|
141
|
-
readonly cycleId: string;
|
|
142
|
-
readonly at: string;
|
|
143
|
-
readonly outcome: "executed" | "idle";
|
|
144
|
-
readonly turnsAppended: number;
|
|
145
|
-
readonly durationMs: number;
|
|
146
|
-
};
|
|
147
|
-
interface Telemetry {
|
|
148
|
-
emit(event: TelemetryEvent): void;
|
|
149
|
-
}
|
|
150
82
|
type RuntimePorts = {
|
|
151
83
|
readonly substrate: Substrate;
|
|
152
84
|
readonly dispatcher: Dispatcher;
|
|
@@ -159,7 +91,8 @@ type RuntimePorts = {
|
|
|
159
91
|
*/
|
|
160
92
|
readonly telemetry?: Telemetry;
|
|
161
93
|
readonly participants: readonly ParticipantDescriptor[];
|
|
162
|
-
|
|
94
|
+
/** One executor instance per participant (keyed by participant id), so per-participant overrides are honored. */
|
|
95
|
+
readonly executors: ReadonlyMap<ParticipantId, ParticipantExecutor>;
|
|
163
96
|
};
|
|
164
97
|
|
|
165
|
-
export type { Dispatcher, DispatcherInput, Lifecycle, ParticipantDescriptor, ParticipantExecuteInput, ParticipantExecuteOutput, ParticipantExecutor,
|
|
98
|
+
export type { Dispatcher, DispatcherInput, Lifecycle, ParticipantConfig, ParticipantDescriptor, ParticipantExecuteInput, ParticipantExecuteOutput, ParticipantExecutor, RuntimePorts, StateStore, Substrate, Turn, TurnInput };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentproto/agent-runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "@agentproto/agent-runtime — MultiAgentRuntime kernel: swappable ports (substrate, dispatcher, participant executors, state, lifecycle, effectors) plus reference adapters (file journal substrate, mention dispatcher, fs state store, agent-cli participant). Transport-specific adapters (chat servers, MCP bridges, etc.) ship in separate packages and register through the agentproto CLI's plugin API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentproto",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/agentproto/ts/issues"
|
|
21
21
|
},
|
|
22
|
-
"license": "
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
23
|
"type": "module",
|
|
24
24
|
"main": "dist/index.mjs",
|
|
25
25
|
"module": "dist/index.mjs",
|
|
@@ -84,7 +84,8 @@
|
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"gray-matter": "^4.0.3",
|
|
86
86
|
"zod": "^4.4.3",
|
|
87
|
-
"@agentproto/cli-exec": "0.1.0
|
|
87
|
+
"@agentproto/cli-exec": "0.1.0",
|
|
88
|
+
"@agentproto/telemetry": "0.2.1"
|
|
88
89
|
},
|
|
89
90
|
"devDependencies": {
|
|
90
91
|
"@types/node": "^25.6.2",
|