@mnemom/smoltbot 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +119 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.js +235 -0
- package/dist/commands/integrity.d.ts +1 -0
- package/dist/commands/integrity.js +63 -0
- package/dist/commands/logs.d.ts +4 -0
- package/dist/commands/logs.js +86 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +299 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +63 -0
- package/dist/lib/api.d.ts +34 -0
- package/dist/lib/api.js +22 -0
- package/dist/lib/config.d.ts +18 -0
- package/dist/lib/config.js +40 -0
- package/dist/lib/models.d.ts +32 -0
- package/dist/lib/models.js +189 -0
- package/dist/lib/openclaw.d.ts +131 -0
- package/dist/lib/openclaw.js +219 -0
- package/dist/lib/prompt.d.ts +11 -0
- package/dist/lib/prompt.js +40 -0
- package/package.json +38 -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,119 @@
|
|
|
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
|
+
|
|
9
|
+
Transparent AI agent tracing. [AAP](https://github.com/mnemom/aap)-compliant.
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g smoltbot
|
|
17
|
+
smoltbot init
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
That's it. `smoltbot init` configures your local environment to route API calls through the Mnemom gateway, where they're traced and verified. Your API key never leaves your machine — only a SHA-256 hash is used for agent identification.
|
|
21
|
+
|
|
22
|
+
## CLI Commands
|
|
23
|
+
|
|
24
|
+
| Command | Description |
|
|
25
|
+
|---------|-------------|
|
|
26
|
+
| `smoltbot init` | Configure tracing for your AI agent |
|
|
27
|
+
| `smoltbot status` | Show agent status and connection info |
|
|
28
|
+
| `smoltbot integrity` | Display integrity score and verification stats |
|
|
29
|
+
| `smoltbot logs [-l N]` | Show recent traces and actions |
|
|
30
|
+
|
|
31
|
+
## How It Works
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Your App → smoltbot gateway → AI Provider (Anthropic, etc.)
|
|
35
|
+
↓
|
|
36
|
+
CF AI Gateway
|
|
37
|
+
↓
|
|
38
|
+
Observer Worker
|
|
39
|
+
↓
|
|
40
|
+
AP-Trace + Verify → Supabase
|
|
41
|
+
↓
|
|
42
|
+
Dashboard (mnemom.ai)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
1. **Gateway** — A Cloudflare Worker that intercepts API requests. It identifies your agent via API key hash (zero-config), attaches tracing metadata, and forwards requests transparently. Your prompts and responses pass through unchanged.
|
|
46
|
+
|
|
47
|
+
2. **Observer** — A scheduled Cloudflare Worker that processes AI Gateway logs. It extracts thinking blocks and tool calls from responses, analyzes decisions with Claude Haiku, builds [AP-Traces](https://github.com/mnemom/aap), and verifies them against your agent's alignment card using the AAP SDK.
|
|
48
|
+
|
|
49
|
+
3. **API** — Serves agent data, traces, integrity scores, drift alerts, and blog posts. Powers both the CLI and the web dashboard.
|
|
50
|
+
|
|
51
|
+
4. **CLI** — The `smoltbot` command. Configures your local environment and queries your agent's transparency data.
|
|
52
|
+
|
|
53
|
+
5. **Dashboard** — Web UI at [mnemom.ai](https://mnemom.ai) where you can view traces, claim your agent, and monitor alignment.
|
|
54
|
+
|
|
55
|
+
## Architecture
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
smoltbot/
|
|
59
|
+
├── cli/ # CLI tool (npm package)
|
|
60
|
+
├── gateway/ # Cloudflare Worker — API proxy + tracing
|
|
61
|
+
├── observer/ # Cloudflare Worker — trace builder + AAP verification
|
|
62
|
+
├── api/ # Cloudflare Worker — REST API
|
|
63
|
+
├── dashboard/ # React frontend (legacy, see mnemom-website)
|
|
64
|
+
└── database/ # Supabase schema (Postgres)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Claiming Your Agent
|
|
68
|
+
|
|
69
|
+
After `smoltbot init`, your agent is registered automatically. To link it to your Mnemom account:
|
|
70
|
+
|
|
71
|
+
1. Run `smoltbot status` to get your agent ID
|
|
72
|
+
2. Go to [mnemom.ai/claim](https://mnemom.ai/claim)
|
|
73
|
+
3. Paste your agent ID and prove ownership with your API key hash
|
|
74
|
+
|
|
75
|
+
Claiming gives you a private dashboard with full trace history, integrity scores, and drift detection.
|
|
76
|
+
|
|
77
|
+
## What Gets Traced
|
|
78
|
+
|
|
79
|
+
Smoltbot builds [AP-Traces](https://github.com/mnemom/aap) that record:
|
|
80
|
+
|
|
81
|
+
- **Action** — What the agent did (type, name, category)
|
|
82
|
+
- **Decision** — What alternatives were considered and why one was selected
|
|
83
|
+
- **Escalation** — Whether the agent escalated to a human and why
|
|
84
|
+
- **Verification** — Whether the trace is consistent with the agent's declared alignment card
|
|
85
|
+
|
|
86
|
+
What is **not** stored: your prompts, responses, or API key.
|
|
87
|
+
|
|
88
|
+
## Current Limitations
|
|
89
|
+
|
|
90
|
+
- **Anthropic only** — Smoltbot currently supports the Anthropic API (Claude) only. Other providers are not yet supported.
|
|
91
|
+
- **API key auth only** — Agent identification uses Anthropic API key hashing. OAuth and other auth methods are not supported.
|
|
92
|
+
- **Hosted gateway** — The default gateway runs on Mnemom infrastructure. Self-hosting is possible but requires manual setup.
|
|
93
|
+
|
|
94
|
+
## Dependencies
|
|
95
|
+
|
|
96
|
+
- [Agent Alignment Protocol (AAP)](https://github.com/mnemom/aap) — `@mnemom/agent-alignment-protocol` on npm
|
|
97
|
+
- [Cloudflare Workers](https://workers.cloudflare.com/) — Gateway, observer, and API hosting
|
|
98
|
+
- [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/) — Request logging and analytics
|
|
99
|
+
- [Supabase](https://supabase.com/) — Postgres database with row-level security
|
|
100
|
+
|
|
101
|
+
## Self-Hosting
|
|
102
|
+
|
|
103
|
+
Smoltbot is designed to run on Cloudflare Workers + Supabase. To self-host:
|
|
104
|
+
|
|
105
|
+
1. Create a Supabase project and run `database/schema.sql`
|
|
106
|
+
2. Deploy workers: `cd gateway && wrangler deploy`, `cd api && wrangler deploy`, `cd observer && wrangler deploy`
|
|
107
|
+
3. Set secrets on each worker via `wrangler secret put`
|
|
108
|
+
4. Configure a Cloudflare AI Gateway and point the gateway worker to it
|
|
109
|
+
5. Update the CLI's gateway URL: `smoltbot init --gateway=https://your-domain.com`
|
|
110
|
+
|
|
111
|
+
## Contributing
|
|
112
|
+
|
|
113
|
+
Contributions welcome. Please open an issue first to discuss what you'd like to change.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
[Apache-2.0](LICENSE)
|
|
118
|
+
|
|
119
|
+
Copyright 2026 Mnemom LLC
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { configExists, loadConfig, saveConfig, generateAgentId, deriveAgentId, } from "../lib/config.js";
|
|
2
|
+
import { detectOpenClaw, configureSmoltbotProvider, setDefaultModel, } from "../lib/openclaw.js";
|
|
3
|
+
import { getModelDefinition, isAnthropicModel, formatModelName, } from "../lib/models.js";
|
|
4
|
+
import { askYesNo, isInteractive } from "../lib/prompt.js";
|
|
5
|
+
const GATEWAY_URL = "https://gateway.mnemom.ai";
|
|
6
|
+
const DASHBOARD_URL = "https://mnemom.ai";
|
|
7
|
+
export async function initCommand(options = {}) {
|
|
8
|
+
console.log("\n" + "=".repeat(60));
|
|
9
|
+
console.log(" smoltbot init - Transparent AI Agent Tracing");
|
|
10
|
+
console.log("=".repeat(60) + "\n");
|
|
11
|
+
// Step 1: Check for existing smoltbot config
|
|
12
|
+
const existingConfig = await handleExistingConfig(options);
|
|
13
|
+
if (existingConfig === "abort") {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// Step 2: Detect OpenClaw installation
|
|
17
|
+
console.log("Detecting OpenClaw installation...\n");
|
|
18
|
+
const detection = detectOpenClaw();
|
|
19
|
+
if (!detection.installed) {
|
|
20
|
+
console.log("✗ OpenClaw not found\n");
|
|
21
|
+
console.log(detection.error || "OpenClaw is not installed.");
|
|
22
|
+
console.log("\nInstall OpenClaw first: https://openclaw.ai\n");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
console.log("✓ OpenClaw installation detected\n");
|
|
26
|
+
// Step 3: Check auth method
|
|
27
|
+
if (detection.isOAuth) {
|
|
28
|
+
console.log("✗ OAuth authentication detected\n");
|
|
29
|
+
console.log("smoltbot only supports API key authentication (not OAuth).\n");
|
|
30
|
+
console.log("To use smoltbot:");
|
|
31
|
+
console.log(" 1. Get an API key from https://console.anthropic.com");
|
|
32
|
+
console.log(" 2. Run `openclaw auth` and add your API key\n");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
if (!detection.hasApiKey || !detection.apiKey) {
|
|
36
|
+
console.log("✗ No Anthropic API key found\n");
|
|
37
|
+
console.log(detection.error || "No API key in auth-profiles.json.");
|
|
38
|
+
console.log("\nTo configure your API key:");
|
|
39
|
+
console.log(" Run `openclaw auth`\n");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
console.log("✓ Anthropic API key found in auth-profiles.json\n");
|
|
43
|
+
console.log(" Note: Only API key auth is supported (not OAuth)\n");
|
|
44
|
+
// Step 4: Detect current model
|
|
45
|
+
const { modelId, provider } = parseCurrentModel(detection);
|
|
46
|
+
if (!modelId) {
|
|
47
|
+
console.log("✗ No default model configured in OpenClaw\n");
|
|
48
|
+
console.log("Configure a default model first:");
|
|
49
|
+
console.log(" openclaw models set anthropic/claude-opus-4-5-20251101\n");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
console.log(`✓ Current model: ${provider}/${modelId}`);
|
|
53
|
+
console.log(` (${formatModelName(modelId)})\n`);
|
|
54
|
+
// Step 5: Determine models to configure
|
|
55
|
+
const modelsToAdd = determineModelsToAdd(modelId, detection);
|
|
56
|
+
console.log("Models to configure for smoltbot provider:");
|
|
57
|
+
for (const model of modelsToAdd) {
|
|
58
|
+
console.log(` - smoltbot/${model.id} (${model.name})`);
|
|
59
|
+
}
|
|
60
|
+
console.log();
|
|
61
|
+
// Step 6: Configure smoltbot provider
|
|
62
|
+
if (detection.smoltbotAlreadyConfigured && !options.force) {
|
|
63
|
+
console.log("⚠ smoltbot provider already exists in OpenClaw config\n");
|
|
64
|
+
if (isInteractive() && !options.yes) {
|
|
65
|
+
const reconfigure = await askYesNo("Reconfigure smoltbot provider?", true);
|
|
66
|
+
if (!reconfigure) {
|
|
67
|
+
console.log("\nKeeping existing configuration.\n");
|
|
68
|
+
// Still create/update smoltbot config
|
|
69
|
+
const agentId = await createSmoltbotConfig(existingConfig, detection.apiKey);
|
|
70
|
+
showSuccessMessage(agentId, modelId);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
console.log("Reconfiguring smoltbot provider...\n");
|
|
75
|
+
}
|
|
76
|
+
console.log("Configuring smoltbot provider in OpenClaw...");
|
|
77
|
+
configureSmoltbotProvider(detection.apiKey, modelsToAdd);
|
|
78
|
+
console.log("✓ smoltbot provider configured\n");
|
|
79
|
+
// Step 7: Offer to switch default model
|
|
80
|
+
const smoltbotModelPath = `smoltbot/${modelId}`;
|
|
81
|
+
const alreadyUsingSmoltbot = provider === "smoltbot";
|
|
82
|
+
let shouldSwitch = false;
|
|
83
|
+
if (!alreadyUsingSmoltbot) {
|
|
84
|
+
shouldSwitch = await promptModelSwitch(modelId, provider, options);
|
|
85
|
+
if (shouldSwitch) {
|
|
86
|
+
console.log(`Setting default model to ${smoltbotModelPath}...`);
|
|
87
|
+
setDefaultModel(smoltbotModelPath);
|
|
88
|
+
console.log(`✓ Default model set to ${smoltbotModelPath}\n`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(`Default model unchanged (${provider}/${modelId})\n`);
|
|
92
|
+
console.log("To enable traced mode later:");
|
|
93
|
+
console.log(` openclaw models set ${smoltbotModelPath}\n`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Step 8: Create smoltbot config
|
|
97
|
+
const agentId = await createSmoltbotConfig(existingConfig, detection.apiKey);
|
|
98
|
+
// Step 9: Show success
|
|
99
|
+
// Traced mode is active if we just switched OR if already using smoltbot
|
|
100
|
+
const tracedModeActive = shouldSwitch || alreadyUsingSmoltbot;
|
|
101
|
+
showSuccessMessage(agentId, modelId, tracedModeActive);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Handle existing smoltbot config
|
|
105
|
+
* Returns "abort" if user doesn't want to reconfigure, or the existing config
|
|
106
|
+
*/
|
|
107
|
+
async function handleExistingConfig(options) {
|
|
108
|
+
if (!configExists()) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const existingConfig = loadConfig();
|
|
112
|
+
if (!existingConfig) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
console.log("⚠ smoltbot is already initialized\n");
|
|
116
|
+
console.log(` Agent ID: ${existingConfig.agentId}`);
|
|
117
|
+
console.log(` Gateway: ${existingConfig.gateway || GATEWAY_URL}\n`);
|
|
118
|
+
if (options.force) {
|
|
119
|
+
console.log("Reconfiguring (--force)...\n");
|
|
120
|
+
return existingConfig;
|
|
121
|
+
}
|
|
122
|
+
if (isInteractive() && !options.yes) {
|
|
123
|
+
const reconfigure = await askYesNo("Reconfigure smoltbot?", true);
|
|
124
|
+
if (!reconfigure) {
|
|
125
|
+
console.log("\nNo changes made.\n");
|
|
126
|
+
return "abort";
|
|
127
|
+
}
|
|
128
|
+
console.log();
|
|
129
|
+
}
|
|
130
|
+
return existingConfig;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Parse the current model from detection results
|
|
134
|
+
*/
|
|
135
|
+
function parseCurrentModel(detection) {
|
|
136
|
+
let modelId = detection.currentModelId || null;
|
|
137
|
+
let provider = detection.currentProvider || null;
|
|
138
|
+
// If current model is already smoltbot, get the underlying model
|
|
139
|
+
if (provider === "smoltbot") {
|
|
140
|
+
// The model is already using smoltbot, that's fine
|
|
141
|
+
// modelId should be the actual model ID
|
|
142
|
+
}
|
|
143
|
+
else if (!provider && modelId) {
|
|
144
|
+
// No provider prefix, assume anthropic
|
|
145
|
+
provider = "anthropic";
|
|
146
|
+
}
|
|
147
|
+
return { modelId, provider };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Determine which models to add to the smoltbot provider
|
|
151
|
+
*/
|
|
152
|
+
function determineModelsToAdd(currentModelId, detection) {
|
|
153
|
+
const models = [];
|
|
154
|
+
const addedIds = new Set();
|
|
155
|
+
// Always add the current model
|
|
156
|
+
if (currentModelId && isAnthropicModel(currentModelId)) {
|
|
157
|
+
const modelDef = getModelDefinition(currentModelId);
|
|
158
|
+
models.push(modelDef);
|
|
159
|
+
addedIds.add(currentModelId);
|
|
160
|
+
}
|
|
161
|
+
// If smoltbot was already configured, preserve any additional models
|
|
162
|
+
if (detection.smoltbotAlreadyConfigured) {
|
|
163
|
+
const existingProvider = detection.smoltbotAlreadyConfigured;
|
|
164
|
+
// We'd need to read the existing config here, but for simplicity
|
|
165
|
+
// we just focus on the current model
|
|
166
|
+
}
|
|
167
|
+
return models;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Prompt user to switch default model
|
|
171
|
+
*/
|
|
172
|
+
async function promptModelSwitch(modelId, currentProvider, options) {
|
|
173
|
+
// If --yes flag, default to switching
|
|
174
|
+
if (options.yes) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
// If non-interactive, default to switching
|
|
178
|
+
if (!isInteractive()) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
console.log("─".repeat(50));
|
|
182
|
+
console.log("\nSwitch to traced mode now?");
|
|
183
|
+
console.log(` Current: ${currentProvider}/${modelId}`);
|
|
184
|
+
console.log(` Traced: smoltbot/${modelId}\n`);
|
|
185
|
+
console.log("When using smoltbot models, all API calls are logged for");
|
|
186
|
+
console.log("transparency and alignment verification.\n");
|
|
187
|
+
return askYesNo("Switch to traced model?", true);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Create or update smoltbot config
|
|
191
|
+
*/
|
|
192
|
+
async function createSmoltbotConfig(existingConfig, apiKey) {
|
|
193
|
+
const agentId = apiKey
|
|
194
|
+
? deriveAgentId(apiKey)
|
|
195
|
+
: existingConfig?.agentId || generateAgentId();
|
|
196
|
+
const config = {
|
|
197
|
+
agentId,
|
|
198
|
+
gateway: GATEWAY_URL,
|
|
199
|
+
openclawConfigured: true,
|
|
200
|
+
configuredAt: new Date().toISOString(),
|
|
201
|
+
};
|
|
202
|
+
saveConfig(config);
|
|
203
|
+
console.log("✓ Created ~/.smoltbot/config.json\n");
|
|
204
|
+
return agentId;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Show success message
|
|
208
|
+
*/
|
|
209
|
+
function showSuccessMessage(agentId, modelId, switched = true) {
|
|
210
|
+
console.log("=".repeat(60));
|
|
211
|
+
console.log(" smoltbot initialized successfully!");
|
|
212
|
+
console.log("=".repeat(60) + "\n");
|
|
213
|
+
console.log(`Agent ID: ${agentId}\n`);
|
|
214
|
+
if (switched) {
|
|
215
|
+
console.log("✓ Traced mode is now active\n");
|
|
216
|
+
console.log("All OpenClaw API calls will be traced. Your traces will");
|
|
217
|
+
console.log("appear at:\n");
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
console.log("Traced mode is ready but not active.\n");
|
|
221
|
+
console.log("To enable traced mode, run:");
|
|
222
|
+
console.log(` openclaw models set smoltbot/${modelId}\n`);
|
|
223
|
+
console.log("Once enabled, your traces will appear at:\n");
|
|
224
|
+
}
|
|
225
|
+
console.log(` ${DASHBOARD_URL}/agents/${agentId}\n`);
|
|
226
|
+
console.log("─".repeat(50));
|
|
227
|
+
console.log("\nUseful commands:\n");
|
|
228
|
+
console.log(" smoltbot status - Check configuration and connectivity");
|
|
229
|
+
console.log(" smoltbot logs - View recent traces");
|
|
230
|
+
console.log(" smoltbot integrity - View integrity score\n");
|
|
231
|
+
console.log("─".repeat(50));
|
|
232
|
+
console.log("\nTo switch between traced and untraced mode:\n");
|
|
233
|
+
console.log(` Traced: openclaw models set smoltbot/${modelId}`);
|
|
234
|
+
console.log(` Untraced: openclaw models set anthropic/${modelId}\n`);
|
|
235
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function integrityCommand(): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { configExists, loadConfig } from "../lib/config.js";
|
|
2
|
+
import { getIntegrity } from "../lib/api.js";
|
|
3
|
+
export async function integrityCommand() {
|
|
4
|
+
if (!configExists()) {
|
|
5
|
+
console.log("\n✗ smoltbot is not initialized\n");
|
|
6
|
+
console.log("Run `smoltbot init` to get started.\n");
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
const config = loadConfig();
|
|
10
|
+
if (!config) {
|
|
11
|
+
console.log("\n✗ Failed to load configuration\n");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
console.log("\n🔍 Fetching integrity score...\n");
|
|
15
|
+
try {
|
|
16
|
+
const integrity = await getIntegrity(config.agentId);
|
|
17
|
+
const scorePercent = (integrity.score * 100).toFixed(1);
|
|
18
|
+
const scoreBar = generateScoreBar(integrity.score);
|
|
19
|
+
console.log("━".repeat(50));
|
|
20
|
+
console.log("Integrity Score");
|
|
21
|
+
console.log("━".repeat(50));
|
|
22
|
+
console.log(` Score: ${scorePercent}% ${scoreBar}`);
|
|
23
|
+
console.log(` Total: ${integrity.total_traces} traces`);
|
|
24
|
+
console.log(` Verified: ${integrity.verified} ✓`);
|
|
25
|
+
console.log(` Violations: ${integrity.violations} ✗`);
|
|
26
|
+
console.log(` Updated: ${integrity.last_updated}`);
|
|
27
|
+
console.log("━".repeat(50));
|
|
28
|
+
if (integrity.violations > 0) {
|
|
29
|
+
console.log("\n⚠️ You have integrity violations. Run `smoltbot logs` to investigate.\n");
|
|
30
|
+
}
|
|
31
|
+
else if (integrity.total_traces === 0) {
|
|
32
|
+
console.log("\n💡 No traces recorded yet. Start using Claude to build your integrity score.\n");
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log("\n✓ Your agent has a clean integrity record!\n");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
40
|
+
if (message.includes("404") || message.includes("not found")) {
|
|
41
|
+
console.log("━".repeat(50));
|
|
42
|
+
console.log("Integrity Score");
|
|
43
|
+
console.log("━".repeat(50));
|
|
44
|
+
console.log(" Score: N/A");
|
|
45
|
+
console.log(" Total: 0 traces");
|
|
46
|
+
console.log(" Verified: 0 ✓");
|
|
47
|
+
console.log(" Violations: 0 ✗");
|
|
48
|
+
console.log("━".repeat(50));
|
|
49
|
+
console.log("\n💡 No traces recorded yet. Start using Claude to build your integrity score.\n");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(`\n✗ Failed to fetch integrity score: ${message}\n`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function generateScoreBar(score) {
|
|
58
|
+
const filled = Math.round(score * 10);
|
|
59
|
+
const empty = 10 - filled;
|
|
60
|
+
const filledChar = "█";
|
|
61
|
+
const emptyChar = "░";
|
|
62
|
+
return `[${filledChar.repeat(filled)}${emptyChar.repeat(empty)}]`;
|
|
63
|
+
}
|