@galinum/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.
- package/LICENSE +202 -0
- package/README.md +148 -0
- package/bin/galinum.js +7 -0
- package/package.json +45 -0
- package/src/agent.js +49 -0
- package/src/api.js +34 -0
- package/src/args.js +35 -0
- package/src/cli.js +59 -0
- package/src/commands/fetch.js +25 -0
- package/src/commands/identify.js +30 -0
- package/src/commands/listen.js +37 -0
- package/src/commands/subscribe.js +47 -0
- package/src/commands/subscriptions.js +12 -0
- package/src/commands/unsubscribe.js +17 -0
- package/src/config.js +46 -0
- package/src/constants.js +7 -0
- package/src/messages.js +40 -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 2026 Galinum
|
|
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/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# galinum-cli
|
|
2
|
+
|
|
3
|
+
> Universal agent inbox. Any product can send messages through the Galinum SDK; any agent can read them through this CLI.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@galinum/cli)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://github.com/Galinum/galinum-cli/actions/workflows/ci.yml)
|
|
8
|
+
|
|
9
|
+
Agents typically have no inbox. They run, they exit, and any message that arrives in between is lost.
|
|
10
|
+
|
|
11
|
+
`galinum` gives every agent a durable inbox. Products publish messages through the Galinum SDK, the CLI polls or listens, and the agent reads them on the next turn. Works in any harness — Claude Code, Codex, your own runtime.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @galinum/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Node.js 20 or later. Zero runtime dependencies.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# 1. Create an identity for this agent (stored in ~/.galinum/config.json)
|
|
25
|
+
galinum identify --name "my-agent" --harness codex
|
|
26
|
+
|
|
27
|
+
# 2. Subscribe using an invite code from a product
|
|
28
|
+
galinum subscribe inv_xxxxxxxxxxxxxxxx
|
|
29
|
+
|
|
30
|
+
# 3. Read pending messages
|
|
31
|
+
galinum fetch
|
|
32
|
+
|
|
33
|
+
# Or keep listening
|
|
34
|
+
galinum listen
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Commands
|
|
38
|
+
|
|
39
|
+
### `identify`
|
|
40
|
+
|
|
41
|
+
Create and store this agent's Galinum identity.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
galinum identify --name <name> [--harness <value>] [--email <email>] [--reset]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
| Flag | Meaning |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `--name` | Human-readable agent name. |
|
|
50
|
+
| `--harness` | The runtime this agent runs in (`claude-code`, `codex`, `custom`, …). |
|
|
51
|
+
| `--email` | Optional contact email. |
|
|
52
|
+
| `--reset` | Replace an existing stored identity. |
|
|
53
|
+
|
|
54
|
+
### `subscribe`
|
|
55
|
+
|
|
56
|
+
Subscribe to an organization's inbox using an invite code.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
galinum subscribe <invite-code>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Invite codes follow the format `inv_<16-128 url-safe chars>`.
|
|
63
|
+
|
|
64
|
+
### `subscriptions`
|
|
65
|
+
|
|
66
|
+
List local subscriptions.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
galinum subscriptions
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `unsubscribe`
|
|
73
|
+
|
|
74
|
+
Remove a local subscription.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
galinum unsubscribe <organization-slug>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `fetch`
|
|
81
|
+
|
|
82
|
+
Fetch pending messages once. Messages are acknowledged after they are printed.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
galinum fetch [organization-slug]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `listen`
|
|
89
|
+
|
|
90
|
+
Continuously poll for new messages.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
galinum listen [organization-slug] [--interval-seconds 30]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`Ctrl+C` stops cleanly.
|
|
97
|
+
|
|
98
|
+
## Global flags
|
|
99
|
+
|
|
100
|
+
| Flag | Purpose |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `--config <path>` | Override config location (default: `~/.galinum/config.json`). |
|
|
103
|
+
| `--base-url <url>` | Override the Galinum API base URL (useful for staging). |
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
The CLI stores state in `~/.galinum/config.json` (file mode `0600`, directory mode `0700`):
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"agent": {
|
|
112
|
+
"id": "agt_…",
|
|
113
|
+
"name": "my-agent",
|
|
114
|
+
"harness": "codex",
|
|
115
|
+
"contact_email": null,
|
|
116
|
+
"key": "<bearer key>"
|
|
117
|
+
},
|
|
118
|
+
"subscriptions": [
|
|
119
|
+
{
|
|
120
|
+
"org": "acme",
|
|
121
|
+
"baseUrl": "https://galinum.com",
|
|
122
|
+
"inboxId": "ibx_…",
|
|
123
|
+
"key": "<bearer key>"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The `key` fields are bearer tokens — treat the file like an SSH key.
|
|
130
|
+
|
|
131
|
+
## Integrating with agent harnesses
|
|
132
|
+
|
|
133
|
+
`galinum fetch` exits cleanly when there are no pending messages, so it's safe to call frequently from a session-start or pre-task hook. Example:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# In your agent's startup hook
|
|
137
|
+
galinum fetch --quiet || true
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Long-running agents can run `galinum listen` in the background and pipe its output into the conversation.
|
|
141
|
+
|
|
142
|
+
## Contributing
|
|
143
|
+
|
|
144
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Bug reports and small PRs welcome.
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
[Apache-2.0](LICENSE) © Galinum
|
package/bin/galinum.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@galinum/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Universal agent inbox CLI — receive durable messages from any product that integrates with the Galinum SDK, in any agent harness.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agents",
|
|
7
|
+
"ai-agents",
|
|
8
|
+
"inbox",
|
|
9
|
+
"cli",
|
|
10
|
+
"galinum",
|
|
11
|
+
"claude-code",
|
|
12
|
+
"codex",
|
|
13
|
+
"messaging"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"author": "Galinum",
|
|
17
|
+
"homepage": "https://github.com/Galinum/galinum-cli#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/Galinum/galinum-cli/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Galinum/galinum-cli.git"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": {
|
|
27
|
+
"galinum": "./bin/galinum.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"src",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "node --test test/*.test.js",
|
|
40
|
+
"start": "node bin/galinum.js"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/agent.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { normalizeBaseUrl, requestJson } from "./api.js";
|
|
2
|
+
import { saveConfig } from "./config.js";
|
|
3
|
+
|
|
4
|
+
export function agentPayload(args) {
|
|
5
|
+
return {
|
|
6
|
+
name: args.name || "agent",
|
|
7
|
+
harness: args.harness || null,
|
|
8
|
+
contact_email: args.email || null,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function sameAgentMetadata(agent, payload) {
|
|
13
|
+
return (
|
|
14
|
+
agent.name === payload.name &&
|
|
15
|
+
(agent.harness ?? null) === payload.harness &&
|
|
16
|
+
(agent.contact_email ?? null) === payload.contact_email
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function createAgent(args, payload) {
|
|
21
|
+
const baseUrl = normalizeBaseUrl(args["base-url"]);
|
|
22
|
+
const data = await requestJson(`${baseUrl}/api/agents/identify`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
body: JSON.stringify(payload),
|
|
25
|
+
});
|
|
26
|
+
if (!data?.id || !data?.name || !data?.key) {
|
|
27
|
+
throw new Error("Server response missing agent identity");
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
id: data.id,
|
|
31
|
+
name: data.name,
|
|
32
|
+
harness: data.harness ?? null,
|
|
33
|
+
contact_email: data.contact_email ?? null,
|
|
34
|
+
key: data.key,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function ensureIdentified(args, config) {
|
|
39
|
+
if (config.agent?.key) return config.agent;
|
|
40
|
+
if (config.agent) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Stored identity ${config.agent.id} has no agent key. Re-run \`galinum identify --reset\` to create a new identity.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
config.agent = await createAgent(args, agentPayload({ ...args, name: "agent" }));
|
|
46
|
+
await saveConfig(args, config);
|
|
47
|
+
console.log(`Identified as ${config.agent.id}.`);
|
|
48
|
+
return config.agent;
|
|
49
|
+
}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DEFAULT_BASE_URL } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
export class GalinumRequestError extends Error {
|
|
4
|
+
constructor(status, data) {
|
|
5
|
+
const detail = data?.error ? `: ${data.error}` : "";
|
|
6
|
+
super(`Galinum request failed (${status})${detail}`);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.data = data;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function normalizeBaseUrl(value) {
|
|
13
|
+
const url = new URL(value || DEFAULT_BASE_URL);
|
|
14
|
+
url.pathname = "";
|
|
15
|
+
url.search = "";
|
|
16
|
+
url.hash = "";
|
|
17
|
+
return url.toString().replace(/\/$/, "");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function requestJson(url, options = {}) {
|
|
21
|
+
const res = await fetch(url, {
|
|
22
|
+
...options,
|
|
23
|
+
headers: {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
...(options.headers ?? {}),
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const data = await res.json().catch(() => null);
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new GalinumRequestError(res.status, data);
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
}
|
package/src/args.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { DEFAULT_CONFIG_PATH } from "./constants.js";
|
|
3
|
+
|
|
4
|
+
export function parseArgs(argv) {
|
|
5
|
+
const args = { _: [] };
|
|
6
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
7
|
+
const arg = argv[i];
|
|
8
|
+
if (!arg.startsWith("--")) {
|
|
9
|
+
args._.push(arg);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const key = arg.slice(2);
|
|
14
|
+
const next = argv[i + 1];
|
|
15
|
+
if (!next || next.startsWith("--")) {
|
|
16
|
+
args[key] = true;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
args[key] = next;
|
|
21
|
+
i += 1;
|
|
22
|
+
}
|
|
23
|
+
return args;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function invocationName() {
|
|
27
|
+
const argv1 = process.argv[1] ?? "";
|
|
28
|
+
const base = path.basename(argv1);
|
|
29
|
+
if (base === "galinum" || base === "galinum-cli") return base;
|
|
30
|
+
return `node ${argv1}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function configPath(args) {
|
|
34
|
+
return typeof args.config === "string" ? args.config : DEFAULT_CONFIG_PATH;
|
|
35
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { invocationName, parseArgs } from "./args.js";
|
|
2
|
+
import { identify } from "./commands/identify.js";
|
|
3
|
+
import { subscribe } from "./commands/subscribe.js";
|
|
4
|
+
import { listSubscriptions } from "./commands/subscriptions.js";
|
|
5
|
+
import { unsubscribe } from "./commands/unsubscribe.js";
|
|
6
|
+
import { fetchMessages } from "./commands/fetch.js";
|
|
7
|
+
import { listen } from "./commands/listen.js";
|
|
8
|
+
|
|
9
|
+
function usage() {
|
|
10
|
+
const bin = invocationName();
|
|
11
|
+
console.log(`Usage:
|
|
12
|
+
${bin} identify --name name [--harness value] [--email email] [--reset]
|
|
13
|
+
${bin} subscribe <invite-code>
|
|
14
|
+
${bin} subscriptions
|
|
15
|
+
${bin} unsubscribe <organization-slug>
|
|
16
|
+
${bin} fetch [organization-slug]
|
|
17
|
+
${bin} listen [organization-slug] [--interval-seconds 30]
|
|
18
|
+
|
|
19
|
+
Commands:
|
|
20
|
+
identify Create and store this agent's Galinum identity.
|
|
21
|
+
subscribe Subscribe to an organization using an invite code.
|
|
22
|
+
subscriptions List local subscriptions.
|
|
23
|
+
unsubscribe Remove a local subscription.
|
|
24
|
+
fetch Fetch pending messages once (all subscriptions, or one).
|
|
25
|
+
listen Repeatedly fetch new messages on an interval.
|
|
26
|
+
|
|
27
|
+
Global flags:
|
|
28
|
+
--config <path> Override config location (default: ~/.galinum/config.json).
|
|
29
|
+
--base-url <url> Override Galinum API base URL.
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const COMMANDS = {
|
|
34
|
+
identify,
|
|
35
|
+
subscribe,
|
|
36
|
+
subscriptions: listSubscriptions,
|
|
37
|
+
unsubscribe,
|
|
38
|
+
fetch: fetchMessages,
|
|
39
|
+
listen,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export async function run(argv) {
|
|
43
|
+
const args = parseArgs(argv);
|
|
44
|
+
const command = args._[0];
|
|
45
|
+
|
|
46
|
+
if (!command || command === "help" || args.help) {
|
|
47
|
+
usage();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const handler = COMMANDS[command];
|
|
52
|
+
if (!handler) {
|
|
53
|
+
usage();
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await handler(args);
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { loadConfig } from "../config.js";
|
|
2
|
+
import { fetchSubscription } from "../messages.js";
|
|
3
|
+
|
|
4
|
+
export async function fetchMessages(args) {
|
|
5
|
+
const orgSlug = args._[1];
|
|
6
|
+
const config = await loadConfig(args);
|
|
7
|
+
if (config.subscriptions.length === 0) {
|
|
8
|
+
if (!args.quiet) {
|
|
9
|
+
console.log("No subscriptions. Use `galinum subscribe <invite-code>` first.");
|
|
10
|
+
}
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
const targets = orgSlug
|
|
14
|
+
? config.subscriptions.filter((s) => s.org === orgSlug)
|
|
15
|
+
: config.subscriptions;
|
|
16
|
+
if (targets.length === 0) {
|
|
17
|
+
if (!args.quiet) console.log(`Not subscribed to "${orgSlug}".`);
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
let total = 0;
|
|
21
|
+
for (const sub of targets) {
|
|
22
|
+
total += await fetchSubscription(sub, args.quiet);
|
|
23
|
+
}
|
|
24
|
+
return total;
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { configPath } from "../args.js";
|
|
2
|
+
import { loadConfig, saveConfig } from "../config.js";
|
|
3
|
+
import { agentPayload, createAgent, sameAgentMetadata } from "../agent.js";
|
|
4
|
+
|
|
5
|
+
export async function identify(args) {
|
|
6
|
+
const config = await loadConfig(args);
|
|
7
|
+
const payload = agentPayload(args);
|
|
8
|
+
|
|
9
|
+
if (config.agent && !args.reset) {
|
|
10
|
+
if (!config.agent.key) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Stored identity ${config.agent.id} predates agent auth and has no key. Re-run with --reset to create a new identity.`,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (sameAgentMetadata(config.agent, payload)) {
|
|
16
|
+
console.log(`Already identified as ${config.agent.id}.`);
|
|
17
|
+
return config.agent;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Already identified as ${config.agent.id}. To update metadata, edit ${configPath(args)} or re-run with --reset.`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
config.agent = await createAgent(args, payload);
|
|
25
|
+
const file = await saveConfig(args, config);
|
|
26
|
+
|
|
27
|
+
console.log(`Identified as ${config.agent.id}.`);
|
|
28
|
+
console.log(`Config: ${file}`);
|
|
29
|
+
return config.agent;
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DEFAULT_POLL_INTERVAL_MS } from "../constants.js";
|
|
2
|
+
import { fetchMessages } from "./fetch.js";
|
|
3
|
+
|
|
4
|
+
function sleep(ms, signal) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
const timer = setTimeout(resolve, ms);
|
|
7
|
+
if (signal) {
|
|
8
|
+
const onAbort = () => {
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
resolve();
|
|
11
|
+
};
|
|
12
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function listen(args) {
|
|
18
|
+
const intervalSeconds = Number(args["interval-seconds"] ?? "30");
|
|
19
|
+
const intervalMs = Number.isFinite(intervalSeconds)
|
|
20
|
+
? Math.max(5, intervalSeconds) * 1000
|
|
21
|
+
: DEFAULT_POLL_INTERVAL_MS;
|
|
22
|
+
|
|
23
|
+
console.log("Listening for Galinum messages.");
|
|
24
|
+
console.log("Press Ctrl+C to stop.");
|
|
25
|
+
|
|
26
|
+
const controller = new AbortController();
|
|
27
|
+
const stop = () => controller.abort();
|
|
28
|
+
process.once("SIGINT", stop);
|
|
29
|
+
process.once("SIGTERM", stop);
|
|
30
|
+
|
|
31
|
+
const innerArgs = { ...args, _: ["fetch", ...(args._[1] ? [args._[1]] : [])], quiet: true };
|
|
32
|
+
while (!controller.signal.aborted) {
|
|
33
|
+
await fetchMessages(innerArgs);
|
|
34
|
+
if (controller.signal.aborted) break;
|
|
35
|
+
await sleep(intervalMs, controller.signal);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { INVITE_CODE_REGEX } from "../constants.js";
|
|
2
|
+
import { normalizeBaseUrl, requestJson } from "../api.js";
|
|
3
|
+
import { loadConfig, saveConfig } from "../config.js";
|
|
4
|
+
import { ensureIdentified } from "../agent.js";
|
|
5
|
+
|
|
6
|
+
export async function subscribe(args) {
|
|
7
|
+
const inviteCode = args._[1];
|
|
8
|
+
if (!inviteCode) {
|
|
9
|
+
throw new Error("Invite code is required. Usage: galinum subscribe <invite-code>");
|
|
10
|
+
}
|
|
11
|
+
if (!INVITE_CODE_REGEX.test(inviteCode)) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Invalid invite code "${inviteCode}". Expected format: inv_<16-128 url-safe chars>.`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const baseUrl = normalizeBaseUrl(args["base-url"]);
|
|
18
|
+
const config = await loadConfig(args);
|
|
19
|
+
const agent = await ensureIdentified(args, config);
|
|
20
|
+
|
|
21
|
+
const data = await requestJson(`${baseUrl}/api/agent-inboxes`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: { Authorization: `Bearer ${agent.key}` },
|
|
24
|
+
body: JSON.stringify({ invite_code: inviteCode }),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const org = data.organization?.id;
|
|
28
|
+
if (!org || !data.id || !data.key) {
|
|
29
|
+
throw new Error("Server response missing inbox credentials");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const existing = config.subscriptions.findIndex((s) => s.org === org);
|
|
33
|
+
if (existing !== -1) config.subscriptions.splice(existing, 1);
|
|
34
|
+
|
|
35
|
+
config.subscriptions.push({
|
|
36
|
+
org,
|
|
37
|
+
baseUrl,
|
|
38
|
+
inboxId: data.id,
|
|
39
|
+
key: data.key,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const file = await saveConfig(args, config);
|
|
43
|
+
|
|
44
|
+
console.log(`Subscribed to ${org}.`);
|
|
45
|
+
console.log(`Inbox ID: ${data.id}`);
|
|
46
|
+
console.log(`Config: ${file}`);
|
|
47
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { loadConfig } from "../config.js";
|
|
2
|
+
|
|
3
|
+
export async function listSubscriptions(args) {
|
|
4
|
+
const config = await loadConfig(args);
|
|
5
|
+
if (config.subscriptions.length === 0) {
|
|
6
|
+
console.log("No subscriptions. Use `galinum subscribe <invite-code>` to add one.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
for (const sub of config.subscriptions) {
|
|
10
|
+
console.log(`${sub.org}\t${sub.inboxId}\t${sub.baseUrl}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { loadConfig, saveConfig } from "../config.js";
|
|
2
|
+
|
|
3
|
+
export async function unsubscribe(args) {
|
|
4
|
+
const orgSlug = args._[1];
|
|
5
|
+
if (!orgSlug) {
|
|
6
|
+
throw new Error("Organization slug is required. Usage: galinum unsubscribe <slug>");
|
|
7
|
+
}
|
|
8
|
+
const config = await loadConfig(args);
|
|
9
|
+
const idx = config.subscriptions.findIndex((s) => s.org === orgSlug);
|
|
10
|
+
if (idx === -1) {
|
|
11
|
+
console.log(`Not subscribed to "${orgSlug}".`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
config.subscriptions.splice(idx, 1);
|
|
15
|
+
await saveConfig(args, config);
|
|
16
|
+
console.log(`Unsubscribed from ${orgSlug}.`);
|
|
17
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { configPath } from "./args.js";
|
|
4
|
+
|
|
5
|
+
function emptyConfig() {
|
|
6
|
+
return { subscriptions: [] };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function normalizeAgent(agent) {
|
|
10
|
+
if (!agent || typeof agent !== "object") return null;
|
|
11
|
+
if (typeof agent.id !== "string" || typeof agent.name !== "string") return null;
|
|
12
|
+
return {
|
|
13
|
+
id: agent.id,
|
|
14
|
+
name: agent.name,
|
|
15
|
+
harness: typeof agent.harness === "string" ? agent.harness : null,
|
|
16
|
+
contact_email: typeof agent.contact_email === "string" ? agent.contact_email : null,
|
|
17
|
+
key: typeof agent.key === "string" ? agent.key : null,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizeConfig(parsed) {
|
|
22
|
+
const config = {
|
|
23
|
+
subscriptions: Array.isArray(parsed?.subscriptions) ? parsed.subscriptions : [],
|
|
24
|
+
};
|
|
25
|
+
const agent = normalizeAgent(parsed?.agent);
|
|
26
|
+
if (agent) config.agent = agent;
|
|
27
|
+
return config;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function loadConfig(args) {
|
|
31
|
+
const file = configPath(args);
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
34
|
+
return normalizeConfig(parsed);
|
|
35
|
+
} catch {
|
|
36
|
+
return emptyConfig();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function saveConfig(args, config) {
|
|
41
|
+
const file = configPath(args);
|
|
42
|
+
// Restrict permissions — config holds bearer tokens.
|
|
43
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
44
|
+
await writeFile(file, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
45
|
+
return file;
|
|
46
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_BASE_URL = "https://galinum.com";
|
|
5
|
+
export const DEFAULT_CONFIG_PATH = path.join(os.homedir(), ".galinum", "config.json");
|
|
6
|
+
export const DEFAULT_POLL_INTERVAL_MS = 30_000;
|
|
7
|
+
export const INVITE_CODE_REGEX = /^inv_[A-Za-z0-9_-]{16,128}$/;
|
package/src/messages.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { requestJson } from "./api.js";
|
|
2
|
+
|
|
3
|
+
export function printMessage(orgSlug, message) {
|
|
4
|
+
console.log("");
|
|
5
|
+
console.log(`[${orgSlug}] [${message.created_at}] ${message.title}`);
|
|
6
|
+
console.log(`Type: ${message.type}`);
|
|
7
|
+
console.log(message.body);
|
|
8
|
+
if (message.payload !== null && message.payload !== undefined) {
|
|
9
|
+
console.log("Payload:");
|
|
10
|
+
console.log(JSON.stringify(message.payload, null, 2));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function ackMessages(subscription, messageIds) {
|
|
15
|
+
if (messageIds.length === 0) return;
|
|
16
|
+
const url = `${subscription.baseUrl}/api/agent-inbox/messages?inbox_id=${encodeURIComponent(subscription.inboxId)}`;
|
|
17
|
+
await requestJson(url, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: { Authorization: `Bearer ${subscription.key}` },
|
|
20
|
+
body: JSON.stringify({ message_ids: messageIds }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function fetchSubscription(subscription, quiet) {
|
|
25
|
+
const url = `${subscription.baseUrl}/api/agent-inbox/messages?inbox_id=${encodeURIComponent(subscription.inboxId)}`;
|
|
26
|
+
const data = await requestJson(url, {
|
|
27
|
+
headers: { Authorization: `Bearer ${subscription.key}` },
|
|
28
|
+
});
|
|
29
|
+
const messages = Array.isArray(data.messages) ? data.messages : [];
|
|
30
|
+
if (messages.length === 0) {
|
|
31
|
+
if (!quiet) console.log(`[${subscription.org}] No pending messages.`);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
for (const message of messages) printMessage(subscription.org, message);
|
|
35
|
+
await ackMessages(
|
|
36
|
+
subscription,
|
|
37
|
+
messages.map((m) => m.id),
|
|
38
|
+
);
|
|
39
|
+
return messages.length;
|
|
40
|
+
}
|