@cotal-ai/connector-hermes 0.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/LICENSE +202 -0
- package/bin/install.mjs +99 -0
- package/dist/bridge.d.ts +7 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +199 -0
- package/dist/bridge.js.map +1 -0
- package/dist/extension.d.ts +13 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +49 -0
- package/dist/extension.js.map +1 -0
- package/dist/hermes-hooks.d.ts +15 -0
- package/dist/hermes-hooks.d.ts.map +1 -0
- package/dist/hermes-hooks.js +51 -0
- package/dist/hermes-hooks.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/launch.d.ts +2 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/launch.js +149 -0
- package/dist/launch.js.map +1 -0
- package/dist/sidecar.d.ts +10 -0
- package/dist/sidecar.d.ts.map +1 -0
- package/dist/sidecar.js +60 -0
- package/dist/sidecar.js.map +1 -0
- package/dist/standalone.d.ts +2 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +31 -0
- package/dist/standalone.js.map +1 -0
- package/dist/tool-schema.d.ts +10 -0
- package/dist/tool-schema.d.ts.map +1 -0
- package/dist/tool-schema.js +34 -0
- package/dist/tool-schema.js.map +1 -0
- package/package.json +51 -0
- package/plugin/cotal/__init__.py +148 -0
- package/plugin/cotal/_sidecar/standalone.cjs +33188 -0
- package/plugin/cotal/adapter.py +114 -0
- package/plugin/cotal/bridge_client.py +153 -0
- package/plugin/cotal/hooks.py +74 -0
- package/plugin/cotal/plugin.yaml +10 -0
- package/plugin/cotal/tools.py +62 -0
- package/pyproject.toml +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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.
|
package/bin/install.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `npx @cotal-ai/connector-hermes install`
|
|
4
|
+
*
|
|
5
|
+
* Installs the Cotal plugin into an existing Hermes so the gateway can join a Cotal mesh.
|
|
6
|
+
* Copies this package's `plugin/cotal` (including the bundled `_sidecar/standalone.cjs`) into
|
|
7
|
+
* `<HERMES_HOME>/plugins/cotal` and enables it.
|
|
8
|
+
*
|
|
9
|
+
* House rule: no fallbacks. If Hermes isn't installed we fail loudly and write NOTHING — no
|
|
10
|
+
* orphaned `~/.hermes/plugins/`. We resolve the Hermes home honestly (HERMES_HOME first), never
|
|
11
|
+
* assuming a fixed path.
|
|
12
|
+
*/
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join, sep } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
19
|
+
const PKG_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
20
|
+
const PLUGIN_SRC = join(PKG_ROOT, "plugin", "cotal");
|
|
21
|
+
const SIDECAR = join(PLUGIN_SRC, "_sidecar", "standalone.cjs");
|
|
22
|
+
|
|
23
|
+
function die(msg) {
|
|
24
|
+
process.stderr.write(`✗ ${msg}\n`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
function info(msg) {
|
|
28
|
+
process.stdout.write(`${msg}\n`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function usage() {
|
|
32
|
+
info("usage: npx @cotal-ai/connector-hermes install");
|
|
33
|
+
info(" Installs the Cotal plugin into your Hermes (HERMES_HOME or ~/.hermes).");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cmd = process.argv[2];
|
|
37
|
+
if (cmd !== "install") {
|
|
38
|
+
usage();
|
|
39
|
+
process.exit(cmd ? 1 : 0);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 1. Require a working Hermes — refuse (writing nothing) if absent.
|
|
43
|
+
function hermesVersion() {
|
|
44
|
+
try {
|
|
45
|
+
return execFileSync("hermes", ["--version"], { encoding: "utf8" }).trim();
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const version = hermesVersion();
|
|
51
|
+
if (!version) {
|
|
52
|
+
die(
|
|
53
|
+
"Hermes isn't installed (no `hermes` on PATH). Install it first:\n" +
|
|
54
|
+
" curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash\n" +
|
|
55
|
+
" then re-run: npx @cotal-ai/connector-hermes install",
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 2. The bundled sidecar must be present (it ships in the npm package; a raw source checkout
|
|
60
|
+
// needs `pnpm --filter @cotal-ai/connector-hermes build` first). No silent half-install.
|
|
61
|
+
if (!existsSync(SIDECAR)) {
|
|
62
|
+
die(
|
|
63
|
+
`bundled sidecar missing at ${SIDECAR}\n` +
|
|
64
|
+
" (running from source? build it first: pnpm --filter @cotal-ai/connector-hermes build)",
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 3. Resolve the Hermes home honestly: HERMES_HOME wins, else ~/.hermes.
|
|
69
|
+
const hermesHome = process.env.HERMES_HOME?.trim() || join(homedir(), ".hermes");
|
|
70
|
+
const pluginsDir = join(hermesHome, "plugins");
|
|
71
|
+
const dest = join(pluginsDir, "cotal");
|
|
72
|
+
|
|
73
|
+
info(`Hermes: ${version}`);
|
|
74
|
+
info(`Installing the Cotal plugin into ${dest} ...`);
|
|
75
|
+
mkdirSync(pluginsDir, { recursive: true });
|
|
76
|
+
rmSync(dest, { recursive: true, force: true }); // clean reinstall (overwrite stale code)
|
|
77
|
+
cpSync(PLUGIN_SRC, dest, {
|
|
78
|
+
recursive: true,
|
|
79
|
+
filter: (src) => !src.includes(`${sep}__pycache__`) && !src.endsWith(".pyc"),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// 4. Enable it via Hermes' own command (it's discovered now that it's in plugins/).
|
|
83
|
+
try {
|
|
84
|
+
execFileSync("hermes", ["plugins", "enable", "cotal"], { stdio: "inherit" });
|
|
85
|
+
} catch {
|
|
86
|
+
die(
|
|
87
|
+
"copied the plugin but `hermes plugins enable cotal` failed.\n" +
|
|
88
|
+
" Enable it manually: `hermes plugins enable cotal` (or add `cotal` to plugins.enabled in config.yaml).",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
info("\n✓ Cotal plugin installed + enabled.\n");
|
|
93
|
+
info("Next: point it at a mesh, then run the gateway:");
|
|
94
|
+
info(" # add to ~/.hermes/.env (or the matching HERMES_HOME)");
|
|
95
|
+
info(" COTAL_SPACE=demo");
|
|
96
|
+
info(" COTAL_NAME=my-hermes");
|
|
97
|
+
info(" COTAL_SERVERS=nats://127.0.0.1:4222");
|
|
98
|
+
info("");
|
|
99
|
+
info(" hermes gateway run");
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type MeshAgent, type AgentConfig } from "@cotal-ai/connector-core";
|
|
2
|
+
export interface BridgeServer {
|
|
3
|
+
close(): void;
|
|
4
|
+
}
|
|
5
|
+
/** Start the adapter bridge. Returns a handle whose `close()` stops the server. */
|
|
6
|
+
export declare function startBridgeServer(agent: MeshAgent, config: AgentConfig, socketPath: string): BridgeServer;
|
|
7
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAkB,KAAK,SAAS,EAAE,KAAK,WAAW,EAAsC,MAAM,0BAA0B,CAAC;AAgChI,MAAM,WAAW,YAAY;IAC3B,KAAK,IAAI,IAAI,CAAC;CACf;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,YAAY,CA8IzG"}
|
package/dist/bridge.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hermes adapter bridge — a local unix-socket server the in-gateway Python plugin connects
|
|
3
|
+
* to. It is the half of the integration that connector-core's one-shot control socket (used for
|
|
4
|
+
* presence hooks, via the relay.ts pattern) can't do: a **persistent, bidirectional** channel so
|
|
5
|
+
* the sidecar can *push* inbound mesh messages into a live gateway turn (wake / queue / interrupt)
|
|
6
|
+
* and the plugin can route turn replies + cotal_* tool calls back out over the same {@link MeshAgent}.
|
|
7
|
+
*
|
|
8
|
+
* Wire format: newline-delimited JSON, both directions.
|
|
9
|
+
*
|
|
10
|
+
* Python → sidecar
|
|
11
|
+
* {t:"subscribe"} adapter: start receiving inbound pushes
|
|
12
|
+
* {t:"delivered", id} adapter: turn accepted msg <id> → ack it on the stream
|
|
13
|
+
* {t:"reply", target, text} adapter: route a turn's reply back to its origin
|
|
14
|
+
* {t:"tool", id, name, args} tools: invoke a cotal_* tool (full shared surface)
|
|
15
|
+
*
|
|
16
|
+
* sidecar → Python
|
|
17
|
+
* {t:"incoming", msg} push one buffered mesh message (for handle_message)
|
|
18
|
+
* {t:"tool_result", id, ok, text?, isError?, error?} reply to a {t:"tool"} request
|
|
19
|
+
*
|
|
20
|
+
* Delivery is **serial + ack-on-surface**: the sidecar pushes the oldest buffered message, waits
|
|
21
|
+
* for the adapter's `delivered`, then `drainInbox(1)` acks exactly that message before pushing the
|
|
22
|
+
* next. A crash before `delivered` redelivers — nothing is lost, matching the stream-backed inbox
|
|
23
|
+
* contract. (One adapter connection at a time; a fresh `subscribe` supersedes the previous.)
|
|
24
|
+
*
|
|
25
|
+
* Tool calls are dispatched generically over {@link cotalToolSpecs} (looked up by name), so this
|
|
26
|
+
* bridge never has to enumerate the surface — full parity by construction.
|
|
27
|
+
*/
|
|
28
|
+
import { createServer } from "node:net";
|
|
29
|
+
import { existsSync, unlinkSync } from "node:fs";
|
|
30
|
+
import { cotalToolSpecs } from "@cotal-ai/connector-core";
|
|
31
|
+
function log(msg) {
|
|
32
|
+
process.stderr.write(`[cotal-hermes/bridge] ${msg}\n`);
|
|
33
|
+
}
|
|
34
|
+
/** The inbox item, flattened for the Python side (handle_message builds a MessageEvent from it). */
|
|
35
|
+
function wireItem(i) {
|
|
36
|
+
return {
|
|
37
|
+
id: i.id,
|
|
38
|
+
ts: i.ts,
|
|
39
|
+
kind: i.kind,
|
|
40
|
+
channel: i.channel,
|
|
41
|
+
service: i.service,
|
|
42
|
+
fromId: i.fromId,
|
|
43
|
+
fromName: i.fromName,
|
|
44
|
+
fromRole: i.fromRole,
|
|
45
|
+
mentions: i.mentions,
|
|
46
|
+
mentionsMe: i.mentionsMe,
|
|
47
|
+
text: i.text,
|
|
48
|
+
replyTo: i.replyTo,
|
|
49
|
+
contextId: i.contextId,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Start the adapter bridge. Returns a handle whose `close()` stops the server. */
|
|
53
|
+
export function startBridgeServer(agent, config, socketPath) {
|
|
54
|
+
if (existsSync(socketPath)) {
|
|
55
|
+
try {
|
|
56
|
+
unlinkSync(socketPath); // clear a stale socket from a dead predecessor
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
/* ignore */
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// The shared tool surface, indexed by name — calls are dispatched straight onto these specs.
|
|
63
|
+
const specs = new Map(cotalToolSpecs(config, "hermes").map((s) => [s.name, s]));
|
|
64
|
+
/** The single subscribed adapter connection, and the id we're currently awaiting an ack for. */
|
|
65
|
+
let adapter;
|
|
66
|
+
let awaitingId;
|
|
67
|
+
const sendFrame = (sock, frame) => {
|
|
68
|
+
try {
|
|
69
|
+
sock.write(JSON.stringify(frame) + "\n");
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
log(`write failed: ${e.message}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/** Push the oldest buffered message to the adapter, one at a time. Acks happen only on the
|
|
76
|
+
* adapter's `delivered` (see below), so a turn that never surfaces a message redelivers it. */
|
|
77
|
+
const pump = () => {
|
|
78
|
+
if (!adapter || awaitingId)
|
|
79
|
+
return;
|
|
80
|
+
const pending = agent.peekInbox();
|
|
81
|
+
if (!pending.length)
|
|
82
|
+
return;
|
|
83
|
+
const next = pending[0];
|
|
84
|
+
awaitingId = next.id;
|
|
85
|
+
sendFrame(adapter, { t: "incoming", msg: wireItem(next) });
|
|
86
|
+
};
|
|
87
|
+
agent.on("incoming", () => pump());
|
|
88
|
+
// The Stop→idle batch flush (see the hook handle): an idle gateway has nothing in flight, so a
|
|
89
|
+
// wake is just another reason to drain whatever is buffered.
|
|
90
|
+
agent.on("wake", () => pump());
|
|
91
|
+
const onReply = async (target, text) => {
|
|
92
|
+
if (!text.trim())
|
|
93
|
+
return;
|
|
94
|
+
if (target.channel)
|
|
95
|
+
await agent.send(text, target.channel);
|
|
96
|
+
else if (target.peerId)
|
|
97
|
+
await agent.dm(target.peerId, text);
|
|
98
|
+
};
|
|
99
|
+
/** Run a cotal_* tool by name against the shared specs. cotal_inbox is forced read-only (peek)
|
|
100
|
+
* so a tool call never races the connector's per-turn delivery ack. */
|
|
101
|
+
const onTool = async (name, args) => {
|
|
102
|
+
const spec = specs.get(name);
|
|
103
|
+
if (!spec)
|
|
104
|
+
throw new Error(`unknown cotal tool: ${name}`);
|
|
105
|
+
const a = name === "cotal_inbox" ? { peek: true } : (args ?? {});
|
|
106
|
+
const r = await spec.run(agent, config, a);
|
|
107
|
+
return { text: r.text, isError: !!r.isError };
|
|
108
|
+
};
|
|
109
|
+
const handleFrame = async (sock, frame) => {
|
|
110
|
+
switch (frame.t) {
|
|
111
|
+
case "subscribe":
|
|
112
|
+
adapter = sock;
|
|
113
|
+
awaitingId = undefined;
|
|
114
|
+
log("adapter subscribed");
|
|
115
|
+
pump();
|
|
116
|
+
return;
|
|
117
|
+
case "delivered":
|
|
118
|
+
if (frame.id && frame.id === awaitingId) {
|
|
119
|
+
// Ack exactly the surfaced message — but ONLY if it's still the front. MeshAgent
|
|
120
|
+
// force-evicts (and acks) from the FRONT at MAX_INBOX, so a large ambient burst during a
|
|
121
|
+
// long turn can already have evicted our in-flight item; draining the front then would
|
|
122
|
+
// mis-ack a newer, unsurfaced message (losing it). If the front is no longer ours, the
|
|
123
|
+
// overflow already acked it — just resync and let pump() surface the new front.
|
|
124
|
+
if (agent.peekInbox()[0]?.id === awaitingId)
|
|
125
|
+
agent.drainInbox(1);
|
|
126
|
+
awaitingId = undefined;
|
|
127
|
+
pump();
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
case "reply":
|
|
131
|
+
try {
|
|
132
|
+
await onReply((frame.target ?? {}), String(frame.text ?? ""));
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
log(`reply failed: ${e.message}`);
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
case "tool": {
|
|
139
|
+
const id = frame.id;
|
|
140
|
+
try {
|
|
141
|
+
const { text, isError } = await onTool(String(frame.name), (frame.args ?? {}));
|
|
142
|
+
sendFrame(sock, { t: "tool_result", id, ok: true, text, isError });
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
sendFrame(sock, { t: "tool_result", id, ok: false, error: e.message });
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
log(`unknown frame: ${JSON.stringify(frame).slice(0, 120)}`);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const server = createServer((sock) => {
|
|
154
|
+
let buf = "";
|
|
155
|
+
sock.setEncoding("utf8");
|
|
156
|
+
sock.on("data", (d) => {
|
|
157
|
+
buf += d;
|
|
158
|
+
let nl;
|
|
159
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
160
|
+
const line = buf.slice(0, nl);
|
|
161
|
+
buf = buf.slice(nl + 1);
|
|
162
|
+
if (!line.trim())
|
|
163
|
+
continue;
|
|
164
|
+
let frame = {};
|
|
165
|
+
try {
|
|
166
|
+
frame = JSON.parse(line);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
log(`malformed frame dropped`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
void handleFrame(sock, frame);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
sock.on("close", () => {
|
|
176
|
+
if (sock === adapter) {
|
|
177
|
+
adapter = undefined;
|
|
178
|
+
awaitingId = undefined;
|
|
179
|
+
log("adapter disconnected");
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
sock.on("error", () => {
|
|
183
|
+
/* ignore client errors */
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
server.on("error", (e) => log(`server error: ${e.message}`));
|
|
187
|
+
server.listen(socketPath, () => log(`listening: ${socketPath}`));
|
|
188
|
+
return {
|
|
189
|
+
close() {
|
|
190
|
+
try {
|
|
191
|
+
server.close();
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
/* ignore */
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;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,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACpB,0BAA0B;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,iBAAkB,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,cAAc,UAAU,EAAE,CAAC,CAAC,CAAC;IAEjE,OAAO;QACL,KAAK;YACH,IAAI,CAAC;gBACH,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Connector } from "@cotal-ai/core";
|
|
2
|
+
/**
|
|
3
|
+
* The Hermes (Nous Research) connector. Unlike Claude Code / Codex — where the harness *is* the
|
|
4
|
+
* process and an MCP server rides inside it — Hermes runs as a long-lived **gateway daemon** that
|
|
5
|
+
* spins up a fresh `AIAgent` per inbound message. So the mesh endpoint can't live inside a
|
|
6
|
+
* per-turn MCP server; it must outlive every turn. The connector's command is therefore a small
|
|
7
|
+
* **launcher/supervisor** (`launch.ts`) that owns the {@link MeshAgent} for the gateway's whole
|
|
8
|
+
* life, bridges to an in-gateway Python plugin (platform adapter + hooks + tools) over two local
|
|
9
|
+
* sockets, and spawns `hermes gateway run` as its child. Self-registers on import; the manager
|
|
10
|
+
* resolves it by agent type "hermes".
|
|
11
|
+
*/
|
|
12
|
+
export declare const hermesConnector: Connector;
|
|
13
|
+
//# sourceMappingURL=extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAoC,MAAM,gBAAgB,CAAC;AAc5F;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,SAgB7B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { registry } from "@cotal-ai/core";
|
|
3
|
+
/** The launcher (run via tsx, which loads both) owns the mesh endpoint and supervises the Hermes
|
|
4
|
+
* gateway as a child — see launch.ts. Resolve `.ts` when this module loads from source (dev) and
|
|
5
|
+
* `.js` when it loads from the build: the package's `import` resolves to dist/, so a hardcoded
|
|
6
|
+
* `./launch.ts` would point at a file tsc never emits. */
|
|
7
|
+
const ENTRY_EXT = import.meta.url.includes("/dist/") ? "js" : "ts";
|
|
8
|
+
const TSX = fileURLToPath(new URL("../node_modules/.bin/tsx", import.meta.url));
|
|
9
|
+
const LAUNCH_ENTRY = fileURLToPath(new URL(`./launch.${ENTRY_EXT}`, import.meta.url));
|
|
10
|
+
/** Provider keys forwarded to the Hermes gateway if present. Hermes is model-agnostic; any one
|
|
11
|
+
* of these unlocks a provider. We forward, never require — the operator's own keys, untouched. */
|
|
12
|
+
const PROVIDER_KEYS = ["OPENROUTER_API_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "NOUS_API_KEY"];
|
|
13
|
+
/**
|
|
14
|
+
* The Hermes (Nous Research) connector. Unlike Claude Code / Codex — where the harness *is* the
|
|
15
|
+
* process and an MCP server rides inside it — Hermes runs as a long-lived **gateway daemon** that
|
|
16
|
+
* spins up a fresh `AIAgent` per inbound message. So the mesh endpoint can't live inside a
|
|
17
|
+
* per-turn MCP server; it must outlive every turn. The connector's command is therefore a small
|
|
18
|
+
* **launcher/supervisor** (`launch.ts`) that owns the {@link MeshAgent} for the gateway's whole
|
|
19
|
+
* life, bridges to an in-gateway Python plugin (platform adapter + hooks + tools) over two local
|
|
20
|
+
* sockets, and spawns `hermes gateway run` as its child. Self-registers on import; the manager
|
|
21
|
+
* resolves it by agent type "hermes".
|
|
22
|
+
*/
|
|
23
|
+
export const hermesConnector = {
|
|
24
|
+
kind: "connector",
|
|
25
|
+
name: "hermes",
|
|
26
|
+
buildLaunch(opts) {
|
|
27
|
+
const env = { COTAL_SPACE: opts.space, COTAL_NAME: opts.name };
|
|
28
|
+
if (opts.role)
|
|
29
|
+
env.COTAL_ROLE = opts.role;
|
|
30
|
+
if (opts.id)
|
|
31
|
+
env.COTAL_ID = opts.id;
|
|
32
|
+
if (opts.creds)
|
|
33
|
+
env.COTAL_CREDS = opts.creds;
|
|
34
|
+
if (opts.servers)
|
|
35
|
+
env.COTAL_SERVERS = opts.servers;
|
|
36
|
+
// An agent file carries identity + persona + model; the launcher applies the persona as
|
|
37
|
+
// Hermes' SOUL.md (system prompt) at gateway startup, the one place it can be set.
|
|
38
|
+
if (opts.configPath)
|
|
39
|
+
env.COTAL_AGENT_FILE = opts.configPath;
|
|
40
|
+
if (process.env.HERMES_MODEL)
|
|
41
|
+
env.HERMES_MODEL = process.env.HERMES_MODEL;
|
|
42
|
+
for (const k of PROVIDER_KEYS)
|
|
43
|
+
if (process.env[k])
|
|
44
|
+
env[k] = process.env[k];
|
|
45
|
+
return { command: TSX, args: [LAUNCH_ENTRY], env };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
registry.register(hermesConnector);
|
|
49
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAoD,MAAM,gBAAgB,CAAC;AAE5F;;;2DAG2D;AAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACnE,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,G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G,OAAO,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC;QAC5E,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC;IACrD,CAAC;CACF,CAAC;AAEF,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hermes lifecycle hooks → Cotal presence.
|
|
3
|
+
*
|
|
4
|
+
* The in-gateway Python plugin registers Hermes hooks (`ctx.register_hook`) and forwards each one
|
|
5
|
+
* to this session's connector over connector-core's control socket — the same relay.ts pattern the
|
|
6
|
+
* Claude Code connector uses, just driven from Python instead of a spawned hook binary. All this
|
|
7
|
+
* handle does is move presence: content delivery rides the adapter (see bridge.ts), so hooks never
|
|
8
|
+
* inject or ack — they only set `idle | working | waiting | offline`.
|
|
9
|
+
*
|
|
10
|
+
* Presence is coarse; only events that cross a state boundary move it. The plugin normalizes its
|
|
11
|
+
* Hermes hook names into the `hook_event_name` values switched on below.
|
|
12
|
+
*/
|
|
13
|
+
import type { HookHandle } from "@cotal-ai/connector-core";
|
|
14
|
+
export declare const hermesHookHandle: HookHandle;
|
|
15
|
+
//# sourceMappingURL=hermes-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hermes-hooks.d.ts","sourceRoot":"","sources":["../src/hermes-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAe3D,eAAO,MAAM,gBAAgB,EAAE,UAkC9B,CAAC"}
|