@cotal-ai/cli 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.
Files changed (46) hide show
  1. package/LICENSE +202 -0
  2. package/dist/command.d.ts +5 -0
  3. package/dist/command.d.ts.map +1 -0
  4. package/dist/command.js +34 -0
  5. package/dist/command.js.map +1 -0
  6. package/dist/commands/console.d.ts +2 -0
  7. package/dist/commands/console.d.ts.map +1 -0
  8. package/dist/commands/console.js +45 -0
  9. package/dist/commands/console.js.map +1 -0
  10. package/dist/commands/join.d.ts +2 -0
  11. package/dist/commands/join.d.ts.map +1 -0
  12. package/dist/commands/join.js +201 -0
  13. package/dist/commands/join.js.map +1 -0
  14. package/dist/commands/mint.d.ts +4 -0
  15. package/dist/commands/mint.d.ts.map +1 -0
  16. package/dist/commands/mint.js +52 -0
  17. package/dist/commands/mint.js.map +1 -0
  18. package/dist/commands/spawn.d.ts +15 -0
  19. package/dist/commands/spawn.d.ts.map +1 -0
  20. package/dist/commands/spawn.js +112 -0
  21. package/dist/commands/spawn.js.map +1 -0
  22. package/dist/commands/up.d.ts +2 -0
  23. package/dist/commands/up.d.ts.map +1 -0
  24. package/dist/commands/up.js +75 -0
  25. package/dist/commands/up.js.map +1 -0
  26. package/dist/commands/watch.d.ts +2 -0
  27. package/dist/commands/watch.d.ts.map +1 -0
  28. package/dist/commands/watch.js +63 -0
  29. package/dist/commands/watch.js.map +1 -0
  30. package/dist/commands/web.d.ts +5 -0
  31. package/dist/commands/web.d.ts.map +1 -0
  32. package/dist/commands/web.js +187 -0
  33. package/dist/commands/web.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +67 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/render.d.ts +32 -0
  39. package/dist/render.d.ts.map +1 -0
  40. package/dist/render.js +0 -0
  41. package/dist/render.js.map +1 -0
  42. package/dist/ui.d.ts +15 -0
  43. package/dist/ui.d.ts.map +1 -0
  44. package/dist/ui.js +25 -0
  45. package/dist/ui.js.map +1 -0
  46. package/package.json +27 -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.
@@ -0,0 +1,5 @@
1
+ import type { Registry } from "@cotal-ai/core";
2
+ /** Dispatch `argv` against the commands self-registered in a {@link Registry}.
3
+ * The single entry point a composition root calls — no hardcoded command list. */
4
+ export declare function runCli(registry: Registry, argv: string[]): Promise<void>;
5
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAkBxD;mFACmF;AACnF,wBAAsB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAc9E"}
@@ -0,0 +1,34 @@
1
+ import { c } from "./ui.js";
2
+ function help(commands) {
3
+ const groups = new Map();
4
+ for (const cmd of commands) {
5
+ const g = cmd.group ?? "Commands";
6
+ (groups.get(g) ?? groups.set(g, []).get(g)).push(cmd);
7
+ }
8
+ const pad = Math.max(...commands.map((c) => c.name.length));
9
+ let out = `${c.bold("cotal")} — lateral agent coordination over NATS\n`;
10
+ for (const [group, cmds] of groups) {
11
+ out += `\n${c.bold(group)}\n`;
12
+ for (const cmd of cmds)
13
+ out += ` ${cmd.name.padEnd(pad)} ${c.dim(cmd.summary)}\n`;
14
+ }
15
+ console.log(out);
16
+ }
17
+ /** Dispatch `argv` against the commands self-registered in a {@link Registry}.
18
+ * The single entry point a composition root calls — no hardcoded command list. */
19
+ export async function runCli(registry, argv) {
20
+ const commands = registry.all("command");
21
+ const [name, ...rest] = argv;
22
+ if (name === undefined || name === "help" || name === "-h" || name === "--help") {
23
+ help(commands);
24
+ return;
25
+ }
26
+ const cmd = commands.find((c) => c.name === name);
27
+ if (!cmd) {
28
+ console.error(c.red(`unknown command: ${name}`));
29
+ help(commands);
30
+ process.exit(1);
31
+ }
32
+ await cmd.run(rest);
33
+ }
34
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,SAAS,CAAC;AAE5B,SAAS,IAAI,CAAC,QAAmB;IAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC5C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,IAAI,UAAU,CAAC;QAClC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,2CAA2C,CAAC;IACxE,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,EAAE,CAAC;QACnC,GAAG,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAC9B,KAAK,MAAM,GAAG,IAAI,IAAI;YAAE,GAAG,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IACtF,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC;AAED;mFACmF;AACnF,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,QAAkB,EAAE,IAAc;IAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAU,SAAS,CAAC,CAAC;IAClD,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QAChF,IAAI,CAAC,QAAQ,CAAC,CAAC;QACf,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function console_(argv: string[]): Promise<void>;
2
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/commands/console.ts"],"names":[],"mappings":"AAMA,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsC5D"}
@@ -0,0 +1,45 @@
1
+ import { parseArgs } from "node:util";
2
+ import { readFileSync } from "node:fs";
3
+ import { CotalEndpoint, isReachable, DEFAULT_SERVER, chatWildcard } from "@cotal-ai/core";
4
+ import { c } from "../ui.js";
5
+ import { runLog, runDashboard } from "../render.js";
6
+ export async function console_(argv) {
7
+ const { values } = parseArgs({
8
+ args: argv,
9
+ allowPositionals: true,
10
+ options: {
11
+ space: { type: "string" },
12
+ server: { type: "string" },
13
+ plain: { type: "boolean" },
14
+ creds: { type: "string" },
15
+ },
16
+ });
17
+ const space = values.space ?? "demo";
18
+ const server = values.server ?? DEFAULT_SERVER;
19
+ const creds = values.creds ? readFileSync(values.creds, "utf8") : undefined;
20
+ if (!(await isReachable(server, { creds }))) {
21
+ console.error(c.red(`Can't reach NATS at ${server}. Run: pnpm cotal up`));
22
+ process.exit(1);
23
+ }
24
+ // Observer: never registers presence, never consumes an inbox — invisible to peers.
25
+ const ep = new CotalEndpoint({
26
+ space,
27
+ servers: server,
28
+ creds,
29
+ channels: [],
30
+ consume: false, // observer: reads via dashboard render + presence-watch, binds no durables
31
+ registerPresence: false,
32
+ watchPresence: true,
33
+ card: { name: "console", kind: "endpoint" },
34
+ });
35
+ ep.on("error", (e) => console.error(c.red("! " + e.message)));
36
+ // Under auth the observer may only sub chat.> (DM/anycast stay confidential), so narrow
37
+ // the tap; open mode taps the whole space.
38
+ const tapSubject = creds ? chatWildcard(space) : undefined;
39
+ // Dashboard needs a real terminal; piped/--plain falls back to the classic log.
40
+ if (values.plain || process.stdout.isTTY !== true)
41
+ await runLog(ep, space, tapSubject);
42
+ else
43
+ await runDashboard(ep, space, tapSubject);
44
+ }
45
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/commands/console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAA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EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE;KAC5C,CAAC,CAAC;IACH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAErE,wFAAwF;IACxF,2CAA2C;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,gFAAgF;IAChF,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI;QAAE,MAAM,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;;QAClF,MAAM,YAAY,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function join(argv: string[]): Promise<void>;
2
+ //# sourceMappingURL=join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../src/commands/join.ts"],"names":[],"mappings":"AAgBA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuNxD"}
@@ -0,0 +1,201 @@
1
+ import { parseArgs } from "node:util";
2
+ import { userInfo } from "node:os";
3
+ import { readFileSync } from "node:fs";
4
+ import * as readline from "node:readline";
5
+ import { CotalEndpoint, isReachable, parseJoinLink, DEFAULT_SERVER, } from "@cotal-ai/core";
6
+ import { c, statusBadge } from "../ui.js";
7
+ export async function join(argv) {
8
+ const { values } = parseArgs({
9
+ args: argv,
10
+ allowPositionals: true,
11
+ options: {
12
+ space: { type: "string" },
13
+ name: { type: "string" },
14
+ role: { type: "string" },
15
+ channel: { type: "string" },
16
+ server: { type: "string" },
17
+ kind: { type: "string" },
18
+ link: { type: "string" },
19
+ token: { type: "string" },
20
+ creds: { type: "string" },
21
+ tls: { type: "boolean" },
22
+ },
23
+ });
24
+ // A join link carries server + auth + space; explicit flags still override it.
25
+ const link = values.link ? parseJoinLink(values.link) : undefined;
26
+ const space = values.space ?? link?.space ?? "demo";
27
+ const name = values.name ?? userInfo().username;
28
+ const server = values.server ?? link?.servers ?? DEFAULT_SERVER;
29
+ const channel = values.channel ?? link?.channels?.[0] ?? "general";
30
+ const auth = {
31
+ token: values.token ?? link?.token,
32
+ user: link?.user,
33
+ pass: link?.pass,
34
+ creds: values.creds ? readFileSync(values.creds, "utf8") : undefined,
35
+ tls: values.tls ?? link?.tls ?? false,
36
+ };
37
+ if (!(await isReachable(server, auth))) {
38
+ console.error(c.red(`Can't reach NATS at ${server}.`));
39
+ console.error(c.dim(link ? "Check the join link and that the host is up." : "Start it in another terminal: pnpm cotal up"));
40
+ process.exit(1);
41
+ }
42
+ const ep = new CotalEndpoint({
43
+ space,
44
+ servers: server,
45
+ ...auth,
46
+ channels: [channel],
47
+ card: {
48
+ name,
49
+ role: values.role,
50
+ kind: values.kind ?? "agent",
51
+ },
52
+ });
53
+ const me = ep.card.id;
54
+ // Interactive only when attached to a real terminal; headless when spawned
55
+ // detached (manager) — then we just hold presence and log mesh events.
56
+ const interactive = process.stdin.isTTY === true;
57
+ let rlClosed = false;
58
+ const rl = interactive
59
+ ? readline.createInterface({
60
+ input: process.stdin,
61
+ output: process.stdout,
62
+ prompt: c.dim(`${name}> `),
63
+ })
64
+ : undefined;
65
+ rl?.on("close", () => {
66
+ rlClosed = true;
67
+ });
68
+ const print = (line) => {
69
+ if (rl && !rlClosed) {
70
+ readline.cursorTo(process.stdout, 0);
71
+ readline.clearLine(process.stdout, 0);
72
+ console.log(line);
73
+ rl.prompt(true);
74
+ }
75
+ else {
76
+ console.log(line);
77
+ }
78
+ };
79
+ const who = (card) => `${c.bold(card.name)}${card.role ? c.dim("/" + card.role) : ""}`;
80
+ ep.on("message", (m, d) => {
81
+ const text = m.parts
82
+ .map((p) => (p.kind === "text" ? p.text : JSON.stringify(p.data)))
83
+ .join(" ");
84
+ if (m.to === me)
85
+ print(`${c.magenta("(DM)")} ${who(m.from)} ${c.dim("→ you:")} ${text}`);
86
+ else if (m.toService)
87
+ print(`${c.yellow("(@" + m.toService + ")")} ${who(m.from)}: ${text}`);
88
+ else
89
+ print(`${c.cyan("#" + (m.channel ?? "?"))} ${who(m.from)}: ${text}`);
90
+ d.ack(); // printed = surfaced
91
+ });
92
+ ep.on("presence", (ev) => {
93
+ if (ev.presence.card.id === me)
94
+ return; // ignore self
95
+ if (ev.type === "join")
96
+ print(c.green(`→ ${who(ev.presence.card)} joined `) + statusBadge(ev.presence.status));
97
+ else if (ev.type === "offline")
98
+ print(c.dim(`← ${who(ev.presence.card)} went offline`));
99
+ else
100
+ print(`${c.dim("•")} ${who(ev.presence.card)} ${statusBadge(ev.presence.status)}${ev.presence.activity ? c.dim(" — " + ev.presence.activity) : ""}`);
101
+ });
102
+ ep.on("error", (e) => print(c.red(`! ${e.message}`)));
103
+ await ep.start();
104
+ const shutdown = async () => {
105
+ print(c.dim("leaving…"));
106
+ rl?.close();
107
+ await ep.stop();
108
+ process.exit(0);
109
+ };
110
+ process.on("SIGINT", () => void shutdown());
111
+ process.on("SIGTERM", () => void shutdown());
112
+ if (!interactive || !rl) {
113
+ console.log(c.dim(`${name} (${values.role ?? "no role"}) holding presence in ${space} — headless`));
114
+ await new Promise(() => { }); // park; event handlers do the work
115
+ return;
116
+ }
117
+ console.log(c.dim(`Joined ${c.bold(space)} as ${who({ name, role: values.role })} on #${channel}.`));
118
+ console.log(c.dim("Type to broadcast. Commands: /who /dm <name> <msg> /anycast <role> <msg> /working [x] /waiting [x] /idle /me <x> /quit\n"));
119
+ setTimeout(() => {
120
+ const others = ep.getRoster().filter((p) => p.card.id !== me);
121
+ if (others.length)
122
+ print(c.dim("Present: ") +
123
+ others.map((p) => who(p.card) + " " + statusBadge(p.status)).join(c.dim(", ")));
124
+ }, 400);
125
+ rl.prompt();
126
+ const setStatus = async (status, activity) => {
127
+ if (activity)
128
+ await ep.setActivity(activity);
129
+ await ep.setStatus(status);
130
+ print(c.dim(`(you are now ${status}${activity ? ": " + activity : ""})`));
131
+ };
132
+ rl.on("line", async (raw) => {
133
+ const line = raw.trim();
134
+ if (!line) {
135
+ rl.prompt();
136
+ return;
137
+ }
138
+ try {
139
+ if (line === "/quit" || line === "/exit")
140
+ return void (await shutdown());
141
+ else if (line === "/who") {
142
+ print(c.dim("Roster:"));
143
+ for (const p of ep.getRoster())
144
+ print(" " +
145
+ who(p.card) +
146
+ " " +
147
+ statusBadge(p.status) +
148
+ (p.activity ? c.dim(" — " + p.activity) : "") +
149
+ (p.card.id === me ? c.dim(" (you)") : ""));
150
+ }
151
+ else if (line === "/idle")
152
+ await setStatus("idle");
153
+ else if (line.startsWith("/working"))
154
+ await setStatus("working", line.slice(8).trim() || undefined);
155
+ else if (line.startsWith("/waiting"))
156
+ await setStatus("waiting", line.slice(8).trim() || undefined);
157
+ else if (line.startsWith("/me "))
158
+ await ep.setActivity(line.slice(4).trim()).then(() => print(c.dim("(activity updated)")));
159
+ else if (line.startsWith("/dm ")) {
160
+ const rest = line.slice(4).trim();
161
+ const sp = rest.indexOf(" ");
162
+ if (sp < 1)
163
+ print(c.red("usage: /dm <name> <message>"));
164
+ else {
165
+ const target = rest.slice(0, sp);
166
+ const text = rest.slice(sp + 1);
167
+ const peer = ep
168
+ .getRoster()
169
+ .find((p) => p.card.name.toLowerCase() === target.toLowerCase() && p.card.id !== me);
170
+ if (!peer)
171
+ print(c.red(`no peer named "${target}" present`));
172
+ else {
173
+ await ep.unicast(peer.card.id, text);
174
+ print(`${c.magenta("(DM)")} ${c.dim("you →")} ${c.bold(peer.card.name)}: ${text}`);
175
+ }
176
+ }
177
+ }
178
+ else if (line.startsWith("/anycast ")) {
179
+ const rest = line.slice(9).trim();
180
+ const sp = rest.indexOf(" ");
181
+ if (sp < 1)
182
+ print(c.red("usage: /anycast <role> <message>"));
183
+ else {
184
+ const service = rest.slice(0, sp);
185
+ const text = rest.slice(sp + 1);
186
+ await ep.anycast(service, text);
187
+ print(`${c.yellow("(@" + service + ")")} ${c.dim("you →")} ${text}`);
188
+ }
189
+ }
190
+ else {
191
+ await ep.multicast(line, { channel });
192
+ print(`${c.cyan("#" + channel)} ${c.dim("you:")} ${line}`);
193
+ }
194
+ }
195
+ catch (e) {
196
+ print(c.red(`! ${e.message}`));
197
+ }
198
+ rl.prompt();
199
+ });
200
+ }
201
+ //# sourceMappingURL=join.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.js","sourceRoot":"","sources":["../../src/commands/join.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,GAKf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAc;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;QAC3B,IAAI,EAAE,IAAI;QACV,gBAAgB,EAAE,IAAI;QACtB,OAAO,EAAE;YACP,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC3B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B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L,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Out-of-band cred minting: generate an identity, sign a profile-scoped user JWT with the
2
+ * space's account signing key, and write a creds file the agent/observer loads to join. */
3
+ export declare function mint(argv: string[]): Promise<void>;
4
+ //# sourceMappingURL=mint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mint.d.ts","sourceRoot":"","sources":["../../src/commands/mint.ts"],"names":[],"mappings":"AAcA;4FAC4F;AAC5F,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CxD"}
@@ -0,0 +1,52 @@
1
+ import { mkdirSync, writeFileSync, existsSync } from "node:fs";
2
+ import { resolve, join, dirname } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { authDir, agentFilePath, loadAgentFile, loadSpaceAuth, mintCreds, newIdentity, } from "@cotal-ai/core";
5
+ import { c } from "../ui.js";
6
+ /** Out-of-band cred minting: generate an identity, sign a profile-scoped user JWT with the
7
+ * space's account signing key, and write a creds file the agent/observer loads to join. */
8
+ export async function mint(argv) {
9
+ const { values, positionals } = parseArgs({
10
+ args: argv,
11
+ allowPositionals: true,
12
+ options: { profile: { type: "string" }, out: { type: "string" } },
13
+ });
14
+ const name = positionals[0];
15
+ if (!name) {
16
+ console.error(c.red("usage: cotal mint <name> --profile <agent|observer|admin> [--out <path>]"));
17
+ process.exit(1);
18
+ }
19
+ const profile = (values.profile ?? "agent");
20
+ if (profile !== "agent" && profile !== "observer" && profile !== "admin") {
21
+ console.error(c.red(`unknown profile "${profile}" — expected agent, observer, or admin`));
22
+ process.exit(1);
23
+ }
24
+ const dir = authDir(process.cwd());
25
+ const auth = loadSpaceAuth(dir);
26
+ if (!auth) {
27
+ console.error(c.red("no space auth found here — run `cotal up` first"));
28
+ process.exit(1);
29
+ }
30
+ // For agents, derive the publish allow-list AND role from the agent file if one exists
31
+ // (publish: ?? channels: for channels; role scopes the TASK-queue consumer to svc_<role>).
32
+ // observers/managers ignore both.
33
+ let channels;
34
+ let role;
35
+ if (profile === "agent") {
36
+ const f = agentFilePath(process.cwd(), name);
37
+ if (existsSync(f)) {
38
+ const def = loadAgentFile(f);
39
+ channels = def.publish ?? def.channels;
40
+ role = def.role;
41
+ }
42
+ }
43
+ const identity = newIdentity();
44
+ const creds = await mintCreds(auth, identity, profile, { channels, role });
45
+ const out = resolve(values.out ?? join(dir, "creds", `${name}.creds`));
46
+ mkdirSync(dirname(out), { recursive: true });
47
+ writeFileSync(out, creds, { mode: 0o600 });
48
+ console.log(c.green(`✓ minted ${profile} creds for "${name}"`));
49
+ console.log(c.dim(` id: ${identity.id}`));
50
+ console.log(c.dim(` creds: ${out}`));
51
+ }
52
+ //# sourceMappingURL=mint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mint.js","sourceRoot":"","sources":["../../src/commands/mint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,OAAO,EACP,aAAa,EACb,aAAa,EACb,aAAa,EACb,SAAS,EACT,WAAW,GAEZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,CAAC,EAAE,MAAM,UAAU,CAAC;AAE7B;4FAC4F;AAC5F,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAc;IACvC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;QACxC,IAAI,EAAE,IAAI;QACV,gBAAgB,EAAE,IAAI;QACtB,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;KAClE,CAAC,CAAC;IACH,MAAM,IAAI,G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AAI,GAAG,GAAG,CAAC,IAAI,CAAC;QAClB,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC;IACvE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,OAAO,eAAe,IAAI,GAAG,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `cotal spawn <name-or-path>` — launch an agent in the FOREGROUND of this
3
+ * terminal from a local agent file, joined to the mesh with its persona.
4
+ *
5
+ * Unlike `cotal start` (the manager spawns into a detached PTY you attach to),
6
+ * `cotal spawn` hands the terminal straight to the agent: run it in your shell,
7
+ * or inside a cmux/tmux pane, and the real Claude TUI takes over.
8
+ *
9
+ * The launch recipe is the connector's `buildLaunch` (the single source of truth,
10
+ * shared with the manager); only *how the spec runs* differs — foreground exec
11
+ * here vs. a supervised runtime in the manager. The connector is resolved from
12
+ * the registry by agent type, composed at the root.
13
+ */
14
+ export declare function spawn(argv: string[]): Promise<void>;
15
+ //# sourceMappingURL=spawn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/commands/spawn.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAqGzD"}