@mnemom/mnemom 0.7.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 +191 -0
- package/README.md +123 -0
- package/dist/commands/agents.d.ts +15 -0
- package/dist/commands/agents.js +303 -0
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +60 -0
- package/dist/commands/card.d.ts +23 -0
- package/dist/commands/card.js +460 -0
- package/dist/commands/claim.d.ts +1 -0
- package/dist/commands/claim.js +72 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +763 -0
- package/dist/commands/integrity.d.ts +1 -0
- package/dist/commands/integrity.js +49 -0
- package/dist/commands/license.d.ts +3 -0
- package/dist/commands/license.js +163 -0
- package/dist/commands/logs.d.ts +5 -0
- package/dist/commands/logs.js +73 -0
- package/dist/commands/migrate-config.d.ts +2 -0
- package/dist/commands/migrate-config.js +72 -0
- package/dist/commands/policy.d.ts +31 -0
- package/dist/commands/policy.js +543 -0
- package/dist/commands/register.d.ts +6 -0
- package/dist/commands/register.js +362 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +383 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +381 -0
- package/dist/lib/api.d.ts +133 -0
- package/dist/lib/api.js +207 -0
- package/dist/lib/auth.d.ts +60 -0
- package/dist/lib/auth.js +281 -0
- package/dist/lib/config.d.ts +105 -0
- package/dist/lib/config.js +253 -0
- package/dist/lib/format.d.ts +35 -0
- package/dist/lib/format.js +60 -0
- package/dist/lib/model-cache.d.ts +16 -0
- package/dist/lib/model-cache.js +138 -0
- package/dist/lib/models.d.ts +41 -0
- package/dist/lib/models.js +357 -0
- package/dist/lib/openclaw.d.ts +221 -0
- package/dist/lib/openclaw.js +474 -0
- package/dist/lib/prompt.d.ts +26 -0
- package/dist/lib/prompt.js +150 -0
- package/dist/smoltbot-shim.d.ts +2 -0
- package/dist/smoltbot-shim.js +7 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
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 the 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 the 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 any 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
|
+
Copyright 2026 Mnemom LLC
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# smoltbot
|
|
2
|
+
|
|
3
|
+
[](https://github.com/mnemom/smoltbot/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/mnemom/smoltbot/actions/workflows/codeql.yml)
|
|
5
|
+
[](https://www.npmjs.com/package/smoltbot)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://github.com/mnemom/aap)
|
|
8
|
+
[](https://github.com/mnemom/aip)
|
|
9
|
+
|
|
10
|
+
Transparent AI agent tracing. [AAP](https://github.com/mnemom/aap)-compliant.
|
|
11
|
+
|
|
12
|
+
Smoltbot observes your AI agent's API calls and builds verifiable alignment traces — what decisions were made, what alternatives were considered, and whether behavior matches declared values. Your prompts and responses are never stored.
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
|
|
16
|
+
Full documentation is at **[docs.mnemom.ai/smoltbot/overview](https://docs.mnemom.ai/smoltbot/overview)**.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g smoltbot
|
|
22
|
+
smoltbot init
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That's it. `smoltbot init` detects your configured AI provider API keys (Anthropic, OpenAI, Gemini) and configures your local environment to route API calls through the Mnemom gateway, where they're traced and verified. Your API keys never leave your machine — only SHA-256 hashes are used for agent identification.
|
|
26
|
+
|
|
27
|
+
## Supported Providers
|
|
28
|
+
|
|
29
|
+
| Provider | Models | Thinking/AIP | Auth |
|
|
30
|
+
|----------|--------|-------------|------|
|
|
31
|
+
| Anthropic | Claude Opus 4.6, Opus 4.5, Sonnet 4.5 | Full (thinking blocks) | `x-api-key` |
|
|
32
|
+
| OpenAI | GPT-5.2, GPT-5.2 Pro, GPT-5 | Via reasoning summaries | `Authorization: Bearer` |
|
|
33
|
+
| Gemini | Gemini 2.5 Pro, Gemini 3 Pro | Full (thought parts) | `x-goog-api-key` |
|
|
34
|
+
|
|
35
|
+
## CLI Commands
|
|
36
|
+
|
|
37
|
+
| Command | Description |
|
|
38
|
+
|---------|-------------|
|
|
39
|
+
| `smoltbot init` | Configure tracing for your AI agent (multi-provider) |
|
|
40
|
+
| `smoltbot status` | Show agent status, providers, and connection info |
|
|
41
|
+
| `smoltbot integrity` | Display integrity score and verification stats |
|
|
42
|
+
| `smoltbot logs [-l N]` | Show recent traces and actions |
|
|
43
|
+
| `smoltbot card show` | Display active alignment card |
|
|
44
|
+
| `smoltbot card publish <file>` | Publish alignment card from JSON file |
|
|
45
|
+
| `smoltbot card validate <file>` | Validate card JSON locally |
|
|
46
|
+
|
|
47
|
+
## How It Works
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
┌─── /anthropic/* ──→ Anthropic (Claude)
|
|
51
|
+
Your App → smoltbot ├─── /openai/* ──→ OpenAI (GPT-5)
|
|
52
|
+
gateway └─── /gemini/* ──→ Google (Gemini)
|
|
53
|
+
↓
|
|
54
|
+
CF AI Gateway
|
|
55
|
+
↓
|
|
56
|
+
Observer Worker
|
|
57
|
+
↓
|
|
58
|
+
AP-Trace + Verify → Supabase
|
|
59
|
+
↓
|
|
60
|
+
Dashboard (mnemom.ai)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
1. **Gateway** — A Cloudflare Worker that intercepts API requests to Anthropic, OpenAI, and Gemini. It identifies your agent via API key hash (zero-config), attaches tracing metadata, injects thinking/reasoning per provider, performs real-time integrity checking, injects conscience nudges, and delivers webhooks. Your prompts and responses pass through unchanged.
|
|
64
|
+
|
|
65
|
+
2. **Observer** — A scheduled Cloudflare Worker that processes AI Gateway logs. It extracts thinking blocks (Anthropic/Gemini) or reasoning summaries (OpenAI) from responses, analyzes decisions with Claude Haiku, builds [AP-Traces](https://github.com/mnemom/aap), verifies them against your agent's alignment card using the AAP SDK, and runs [AIP](https://github.com/mnemom/aip) integrity checks. Creates enforcement nudges when violations are detected.
|
|
66
|
+
|
|
67
|
+
3. **API** — Serves agent data, traces, integrity scores, drift alerts, enforcement status, and a unified conscience timeline. Powers both the CLI and the web dashboard.
|
|
68
|
+
|
|
69
|
+
4. **CLI** — The `smoltbot` command. Configures your local environment and queries your agent's transparency data.
|
|
70
|
+
|
|
71
|
+
5. **Dashboard** — Web UI at [mnemom.ai](https://mnemom.ai) where you can view the conscience timeline, claim your agent, and monitor alignment.
|
|
72
|
+
|
|
73
|
+
## What Gets Traced
|
|
74
|
+
|
|
75
|
+
Smoltbot builds [AP-Traces](https://github.com/mnemom/aap) that record:
|
|
76
|
+
|
|
77
|
+
- **Action** — What the agent did (type, name, category)
|
|
78
|
+
- **Decision** — What alternatives were considered and why one was selected
|
|
79
|
+
- **Escalation** — Whether the agent escalated to a human and why
|
|
80
|
+
- **Verification** — Whether the trace is consistent with the agent's declared alignment card
|
|
81
|
+
- **Integrity** — Real-time [AIP](https://github.com/mnemom/aip) analysis of thinking blocks, with verdict (clear/review_needed/boundary_violation)
|
|
82
|
+
|
|
83
|
+
What is **not** stored: your prompts, responses, or API key.
|
|
84
|
+
|
|
85
|
+
### AIP Compatibility Matrix
|
|
86
|
+
|
|
87
|
+
| Provider/Model | AIP Support | Method |
|
|
88
|
+
|----------------|-------------|--------|
|
|
89
|
+
| Anthropic reasoning models (Opus, Sonnet) | Full | Thinking blocks analyzed directly |
|
|
90
|
+
| OpenAI GPT-5 Thinking series | Partial | Reasoning summaries (reduced confidence) |
|
|
91
|
+
| Gemini 2.5/3 with thinking | Full | Thought parts analyzed directly |
|
|
92
|
+
| Non-reasoning models | Tracing only | Synthetic clear verdict |
|
|
93
|
+
|
|
94
|
+
## Enforcement Modes
|
|
95
|
+
|
|
96
|
+
| Mode | Behavior |
|
|
97
|
+
|------|----------|
|
|
98
|
+
| `observe` | Detect violations, record them, take no action (default) |
|
|
99
|
+
| `nudge` | Detect violations, inject feedback into the agent's next request via system prompt — the agent sees it and can self-correct |
|
|
100
|
+
| `enforce` | Hard block with 403 for non-streaming; falls back to nudge for streaming |
|
|
101
|
+
|
|
102
|
+
Enforcement works across all providers where AIP is supported.
|
|
103
|
+
|
|
104
|
+
## Current Limitations
|
|
105
|
+
|
|
106
|
+
- **API key auth only** — Agent identification uses API key hashing (SHA-256, works identically across all providers). OAuth and other auth methods are not supported.
|
|
107
|
+
- **AIP requires reasoning models** — AIP integrity checking requires models with exposed thinking. Models without thinking get synthetic clear verdicts.
|
|
108
|
+
- **Hosted gateway** — The default gateway runs on Mnemom infrastructure. Self-hosting is possible but requires manual setup.
|
|
109
|
+
|
|
110
|
+
## Dependencies
|
|
111
|
+
|
|
112
|
+
- [Agent Alignment Protocol (AAP)](https://github.com/mnemom/aap) — `@mnemom/agent-alignment-protocol@0.1.8` on npm
|
|
113
|
+
- [Agent Integrity Protocol (AIP)](https://github.com/mnemom/aip) — `@mnemom/agent-integrity-protocol@0.1.4` on npm
|
|
114
|
+
- [Cloudflare Workers](https://workers.cloudflare.com/) — Gateway, observer, and API hosting
|
|
115
|
+
- [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) — Request logging and analytics
|
|
116
|
+
- [Supabase](https://supabase.com/) — Postgres database with row-level security
|
|
117
|
+
- API keys: Anthropic (required for AIP analysis), OpenAI and Gemini (optional, for multi-provider tracing)
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[Apache-2.0](LICENSE)
|
|
122
|
+
|
|
123
|
+
Copyright 2026 Mnemom LLC
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function agentsListCommand(): Promise<void>;
|
|
2
|
+
export declare function agentsDefaultCommand(name: string): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* smoltbot agents add <name-or-id> [--alias <alias>]
|
|
5
|
+
* Register an existing API agent in the local config.
|
|
6
|
+
*/
|
|
7
|
+
export declare function agentsAddCommand(nameOrId: string, alias?: string): Promise<void>;
|
|
8
|
+
export declare function agentsRemoveCommand(name: string): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* smoltbot agents rekey [agent-name]
|
|
11
|
+
* Re-bind a claimed agent to a new provider API key.
|
|
12
|
+
* The raw key is hashed locally (SHA-256) and never transmitted.
|
|
13
|
+
*/
|
|
14
|
+
export declare function agentsRekeyCommand(name?: string): Promise<void>;
|
|
15
|
+
export declare function agentsCheckBindingCommand(name?: string): Promise<void>;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { loadConfig, saveConfig, computeAgentHash } from "../lib/config.js";
|
|
2
|
+
import { listAgents, getAgent, getAgentByName, postApi, verifyBinding } from "../lib/api.js";
|
|
3
|
+
import { fmt } from "../lib/format.js";
|
|
4
|
+
import { askInput } from "../lib/prompt.js";
|
|
5
|
+
export async function agentsListCommand() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
if (!config) {
|
|
8
|
+
console.log("\n" + fmt.error("smoltbot is not initialized") + "\n");
|
|
9
|
+
console.log("Run `smoltbot init` to get started.\n");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
console.log(fmt.header("Registered Agents"));
|
|
13
|
+
console.log();
|
|
14
|
+
// Build reverse map: agentId → local alias name
|
|
15
|
+
const localAliases = new Map();
|
|
16
|
+
for (const [name, agent] of Object.entries(config.agents)) {
|
|
17
|
+
localAliases.set(agent.agentId, name);
|
|
18
|
+
}
|
|
19
|
+
// Fetch ALL agents from API for the authenticated user
|
|
20
|
+
let apiAgents = [];
|
|
21
|
+
try {
|
|
22
|
+
apiAgents = await listAgents();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
console.log(fmt.warn("Could not reach API — showing local agents only") + "\n");
|
|
26
|
+
}
|
|
27
|
+
const shown = new Set();
|
|
28
|
+
if (apiAgents.length > 0) {
|
|
29
|
+
for (const agent of apiAgents) {
|
|
30
|
+
shown.add(agent.id);
|
|
31
|
+
const localName = localAliases.get(agent.id);
|
|
32
|
+
const isDefault = localName === config.defaultAgent;
|
|
33
|
+
const displayName = localName ?? agent.name ?? agent.email ?? agent.id;
|
|
34
|
+
const defaultMarker = isDefault ? " (default)" : "";
|
|
35
|
+
console.log(` ${fmt.label(displayName + defaultMarker, "")}`);
|
|
36
|
+
console.log(` ${fmt.label("Agent ID: ", agent.id)}`);
|
|
37
|
+
if (agent.key_prefix) {
|
|
38
|
+
console.log(` ${fmt.label("Key: ", ` ${agent.key_prefix}…`)}`);
|
|
39
|
+
}
|
|
40
|
+
if (localName && localName !== displayName) {
|
|
41
|
+
console.log(` ${fmt.label("Local alias:", " " + localName)}`);
|
|
42
|
+
}
|
|
43
|
+
if (agent.last_seen) {
|
|
44
|
+
console.log(` ${fmt.label("Last seen:", " " + new Date(agent.last_seen).toLocaleDateString())}`);
|
|
45
|
+
}
|
|
46
|
+
if (agent.created_at) {
|
|
47
|
+
console.log(` ${fmt.label("Created: ", new Date(agent.created_at).toLocaleDateString())}`);
|
|
48
|
+
}
|
|
49
|
+
console.log();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Show locally-registered agents not in the API response
|
|
53
|
+
for (const [name, agent] of Object.entries(config.agents)) {
|
|
54
|
+
if (!shown.has(agent.agentId)) {
|
|
55
|
+
const isDefault = name === config.defaultAgent;
|
|
56
|
+
const defaultMarker = isDefault ? " (default)" : "";
|
|
57
|
+
const providerInfo = agent.providers?.join(", ") ?? (agent.openclawConfigured ? "openclaw" : "unknown");
|
|
58
|
+
console.log(` ${fmt.label(name + defaultMarker, "")} ${fmt.warn("(local only — not found in account)")}`);
|
|
59
|
+
console.log(` ${fmt.label("Agent ID: ", agent.agentId)}`);
|
|
60
|
+
console.log(` ${fmt.label("Provider: ", providerInfo)}`);
|
|
61
|
+
console.log();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const total = apiAgents.length > 0 ? apiAgents.length : Object.keys(config.agents).length;
|
|
65
|
+
console.log(` Total: ${total} agent(s)\n`);
|
|
66
|
+
}
|
|
67
|
+
export async function agentsDefaultCommand(name) {
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
if (!config) {
|
|
70
|
+
console.log("\n" + fmt.error("smoltbot is not initialized") + "\n");
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
if (!config.agents[name]) {
|
|
74
|
+
console.log(fmt.error(`Agent "${name}" is not registered locally.`) + "\n");
|
|
75
|
+
console.log(`Run \`smoltbot agents add ${name}\` to register it first.\n`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
config.defaultAgent = name;
|
|
79
|
+
saveConfig(config);
|
|
80
|
+
console.log(fmt.success(`Default agent set to "${name}"`) + "\n");
|
|
81
|
+
console.log(fmt.label("Agent ID:", ` ${config.agents[name].agentId}`) + "\n");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* smoltbot agents add <name-or-id> [--alias <alias>]
|
|
85
|
+
* Register an existing API agent in the local config.
|
|
86
|
+
*/
|
|
87
|
+
export async function agentsAddCommand(nameOrId, alias) {
|
|
88
|
+
const config = loadConfig();
|
|
89
|
+
if (!config) {
|
|
90
|
+
console.log("\n" + fmt.error("smoltbot is not initialized") + "\n");
|
|
91
|
+
console.log("Run `smoltbot init` to get started.\n");
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
// Fetch the agent from the API
|
|
95
|
+
let agentId;
|
|
96
|
+
let apiName = null;
|
|
97
|
+
let createdAt;
|
|
98
|
+
try {
|
|
99
|
+
if (/^smolt-[0-9a-f]{8}$/.test(nameOrId)) {
|
|
100
|
+
const a = await getAgent(nameOrId);
|
|
101
|
+
agentId = a.id;
|
|
102
|
+
createdAt = a.created_at;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const a = await getAgentByName(nameOrId);
|
|
106
|
+
if (!a) {
|
|
107
|
+
console.log(fmt.error(`Agent not found: ${nameOrId}`) + "\n");
|
|
108
|
+
console.log("Run `smoltbot agents` to see agents in your account.\n");
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
agentId = a.id;
|
|
112
|
+
apiName = a.name;
|
|
113
|
+
createdAt = a.created_at;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
118
|
+
console.log("\n" + fmt.error(msg) + "\n");
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
const localAlias = alias ?? apiName ?? nameOrId;
|
|
122
|
+
// Check for conflicts
|
|
123
|
+
const existing = config.agents[localAlias];
|
|
124
|
+
if (existing) {
|
|
125
|
+
if (existing.agentId === agentId) {
|
|
126
|
+
console.log(fmt.success(`Agent "${localAlias}" is already registered (${agentId})`) + "\n");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
console.log(fmt.error(`Alias "${localAlias}" is already in use by agent ${existing.agentId}.`) + "\n");
|
|
130
|
+
console.log(`Use --alias <name> to choose a different local name.\n`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
config.agents[localAlias] = { agentId, configuredAt: createdAt };
|
|
134
|
+
saveConfig(config);
|
|
135
|
+
console.log(fmt.success(`Agent registered as "${localAlias}"`) + "\n");
|
|
136
|
+
console.log(fmt.label("Agent ID:", ` ${agentId}`) + "\n");
|
|
137
|
+
console.log(`Use --agent ${localAlias} to target this agent.\n`);
|
|
138
|
+
}
|
|
139
|
+
export async function agentsRemoveCommand(name) {
|
|
140
|
+
const config = loadConfig();
|
|
141
|
+
if (!config) {
|
|
142
|
+
console.log("\n" + fmt.error("smoltbot is not initialized") + "\n");
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
if (!config.agents[name]) {
|
|
146
|
+
console.log(fmt.error(`Agent "${name}" not found`) + "\n");
|
|
147
|
+
console.log("Available agents: " + Object.keys(config.agents).join(", ") + "\n");
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
if (name === "default" && Object.keys(config.agents).length === 1) {
|
|
151
|
+
console.log(fmt.error("Cannot remove the only agent") + "\n");
|
|
152
|
+
console.log("Register another agent first with `smoltbot register <name>`.\n");
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
const removedId = config.agents[name].agentId;
|
|
156
|
+
delete config.agents[name];
|
|
157
|
+
// If we removed the default, switch to first remaining agent
|
|
158
|
+
if (config.defaultAgent === name) {
|
|
159
|
+
const remaining = Object.keys(config.agents);
|
|
160
|
+
config.defaultAgent = remaining[0] || "default";
|
|
161
|
+
console.log(fmt.warn(`Default agent switched to "${config.defaultAgent}"`) + "\n");
|
|
162
|
+
}
|
|
163
|
+
saveConfig(config);
|
|
164
|
+
console.log(fmt.success(`Agent "${name}" removed (${removedId})`) + "\n");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* smoltbot agents rekey [agent-name]
|
|
168
|
+
* Re-bind a claimed agent to a new provider API key.
|
|
169
|
+
* The raw key is hashed locally (SHA-256) and never transmitted.
|
|
170
|
+
*/
|
|
171
|
+
export async function agentsRekeyCommand(name) {
|
|
172
|
+
const config = loadConfig();
|
|
173
|
+
if (!config) {
|
|
174
|
+
console.log("\n" + fmt.error("smoltbot is not initialized") + "\n");
|
|
175
|
+
console.log("Run `smoltbot init` to get started.\n");
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
// Resolve which agent to rekey
|
|
179
|
+
const agentName = name ?? config.defaultAgent;
|
|
180
|
+
const agentEntry = config.agents[agentName];
|
|
181
|
+
if (!agentEntry) {
|
|
182
|
+
console.log(fmt.error(`Agent "${agentName}" not found`) + "\n");
|
|
183
|
+
console.log("Available agents: " + Object.keys(config.agents).join(", ") + "\n");
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
const { agentId } = agentEntry;
|
|
187
|
+
// Fetch canonical name from API — required for named-agent hash computation
|
|
188
|
+
// (named agents: hash = SHA256(key + '|' + name), unnamed: SHA256(key))
|
|
189
|
+
let agentApiName = null;
|
|
190
|
+
try {
|
|
191
|
+
const agent = await getAgent(agentId);
|
|
192
|
+
agentApiName = agent.name ?? null;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
console.log(fmt.warn("Could not fetch agent details from API — proceeding without name confirmation"));
|
|
196
|
+
}
|
|
197
|
+
console.log("\n" + fmt.header("Rekey Agent"));
|
|
198
|
+
console.log();
|
|
199
|
+
console.log(` Agent: ${agentName} (${agentId})`);
|
|
200
|
+
if (agentApiName) {
|
|
201
|
+
console.log(` Name: ${agentApiName}`);
|
|
202
|
+
}
|
|
203
|
+
console.log();
|
|
204
|
+
console.log(fmt.warn("Your new provider key will be hashed locally. The raw key never leaves your machine."));
|
|
205
|
+
console.log();
|
|
206
|
+
// Read new key — prefer env var for CI, otherwise prompt interactively
|
|
207
|
+
let newKey = (process.env.SMOLTBOT_NEW_KEY ?? "").trim();
|
|
208
|
+
if (!newKey) {
|
|
209
|
+
newKey = (await askInput("Enter your new provider API key:", true)).trim();
|
|
210
|
+
}
|
|
211
|
+
if (!newKey) {
|
|
212
|
+
console.log(fmt.error("No key provided") + "\n");
|
|
213
|
+
process.exit(1);
|
|
214
|
+
}
|
|
215
|
+
// Compute hash client-side — raw key never sent to API
|
|
216
|
+
const newKeyHash = computeAgentHash(newKey, agentApiName);
|
|
217
|
+
console.log(" Computing hash and calling API...\n");
|
|
218
|
+
// Call API
|
|
219
|
+
let result;
|
|
220
|
+
try {
|
|
221
|
+
result = await postApi(`/v1/agents/${agentId}/rekey`, { new_key_hash: newKeyHash });
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
225
|
+
if (msg.startsWith("409") || msg.includes("conflict")) {
|
|
226
|
+
// Extract conflict agent ID if present
|
|
227
|
+
const match = msg.match(/conflict: ((?:smolt-[0-9a-f]{8}|mnm-[0-9a-f-]{36}))/);
|
|
228
|
+
const shadowId = match ? match[1] : "(unknown)";
|
|
229
|
+
console.log(fmt.error("Key conflict: a different agent was already auto-created for this key.\n"));
|
|
230
|
+
console.log(` Shadow agent ID: ${shadowId}`);
|
|
231
|
+
console.log(" Steps to resolve:");
|
|
232
|
+
console.log(" 1. Open the Mnemom dashboard and deactivate the shadow agent.");
|
|
233
|
+
console.log(" 2. Run `smoltbot agents rekey` again.\n");
|
|
234
|
+
console.log(" Or visit: https://www.mnemom.ai/docs/guides/agent-key-rotation\n");
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
console.log(fmt.error(msg) + "\n");
|
|
238
|
+
}
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
// Agent ID is stable — no config changes needed
|
|
242
|
+
console.log(fmt.success("Agent rekeyed successfully") + "\n");
|
|
243
|
+
console.log(fmt.label("Agent ID: ", ` ${result.agent_id}`));
|
|
244
|
+
console.log(fmt.label("Rekeyed at:", ` ${new Date(result.rekeyed_at).toLocaleString()}`));
|
|
245
|
+
console.log();
|
|
246
|
+
console.log("Your agent history, alignment card, and integrity score are preserved.");
|
|
247
|
+
console.log("Update your ANTHROPIC_API_KEY (or equivalent) to the new key.\n");
|
|
248
|
+
}
|
|
249
|
+
export async function agentsCheckBindingCommand(name) {
|
|
250
|
+
const config = loadConfig();
|
|
251
|
+
if (!config) {
|
|
252
|
+
console.log('\n' + fmt.error('smoltbot is not initialized') + '\n');
|
|
253
|
+
console.log('Run `smoltbot init` to get started.\n');
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
const agentName = name ?? config.defaultAgent;
|
|
257
|
+
const agentEntry = config.agents[agentName];
|
|
258
|
+
if (!agentEntry) {
|
|
259
|
+
console.log(fmt.error(`Agent "${agentName}" not found`) + '\n');
|
|
260
|
+
console.log('Available agents: ' + Object.keys(config.agents).join(', ') + '\n');
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
const { agentId } = agentEntry;
|
|
264
|
+
// Fetch canonical name from API (needed for named-agent hash)
|
|
265
|
+
let agentApiName = null;
|
|
266
|
+
try {
|
|
267
|
+
const agent = await getAgent(agentId);
|
|
268
|
+
agentApiName = agent.name ?? null;
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
console.log(fmt.warn('Could not fetch agent details — proceeding without name confirmation'));
|
|
272
|
+
}
|
|
273
|
+
console.log('\n' + fmt.header('Check Key Binding'));
|
|
274
|
+
console.log(` Agent: ${agentName} (${agentId})`);
|
|
275
|
+
console.log();
|
|
276
|
+
let key = (process.env.SMOLTBOT_CHECK_KEY ?? '').trim();
|
|
277
|
+
if (!key) {
|
|
278
|
+
key = (await askInput('Enter the API key to check:', true)).trim();
|
|
279
|
+
}
|
|
280
|
+
if (!key) {
|
|
281
|
+
console.log(fmt.error('No key provided') + '\n');
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
const keyHash = computeAgentHash(key, agentApiName);
|
|
285
|
+
let result;
|
|
286
|
+
try {
|
|
287
|
+
result = await verifyBinding(agentId, keyHash);
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
console.log(fmt.error(err instanceof Error ? err.message : String(err)) + '\n');
|
|
291
|
+
process.exit(1);
|
|
292
|
+
}
|
|
293
|
+
if (result.bound) {
|
|
294
|
+
console.log(fmt.success('Key is bound to this agent') + '\n');
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
console.log(fmt.error('Key is NOT bound to this agent') + '\n');
|
|
298
|
+
}
|
|
299
|
+
if (result.key_prefix) {
|
|
300
|
+
const label = result.bound ? 'Key prefix: ' : 'Current prefix:';
|
|
301
|
+
console.log(fmt.label(label, ` ${result.key_prefix}…`) + '\n');
|
|
302
|
+
}
|
|
303
|
+
}
|