swarmkit 0.0.1 → 0.0.2
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 +21 -0
- package/README.md +194 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +33 -0
- package/dist/commands/add.d.ts +2 -0
- package/dist/commands/add.js +55 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +100 -0
- package/dist/commands/hive.d.ts +2 -0
- package/dist/commands/hive.js +248 -0
- package/dist/commands/init/phases/configure.d.ts +2 -0
- package/dist/commands/init/phases/configure.js +85 -0
- package/dist/commands/init/phases/global-setup.d.ts +2 -0
- package/dist/commands/init/phases/global-setup.js +81 -0
- package/dist/commands/init/phases/packages.d.ts +2 -0
- package/dist/commands/init/phases/packages.js +30 -0
- package/dist/commands/init/phases/project.d.ts +2 -0
- package/dist/commands/init/phases/project.js +54 -0
- package/dist/commands/init/phases/use-case.d.ts +2 -0
- package/dist/commands/init/phases/use-case.js +41 -0
- package/dist/commands/init/state.d.ts +11 -0
- package/dist/commands/init/state.js +8 -0
- package/dist/commands/init/state.test.d.ts +1 -0
- package/dist/commands/init/state.test.js +20 -0
- package/dist/commands/init/wizard.d.ts +1 -0
- package/dist/commands/init/wizard.js +56 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +10 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +91 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +19 -0
- package/dist/commands/remove.d.ts +2 -0
- package/dist/commands/remove.js +49 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +87 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +54 -0
- package/dist/commands/whoami.d.ts +2 -0
- package/dist/commands/whoami.js +40 -0
- package/dist/config/global.d.ts +24 -0
- package/dist/config/global.js +71 -0
- package/dist/config/global.test.d.ts +1 -0
- package/dist/config/global.test.js +167 -0
- package/dist/config/keys.d.ts +10 -0
- package/dist/config/keys.js +47 -0
- package/dist/config/keys.test.d.ts +1 -0
- package/dist/config/keys.test.js +87 -0
- package/dist/doctor/checks.d.ts +31 -0
- package/dist/doctor/checks.js +210 -0
- package/dist/doctor/checks.test.d.ts +1 -0
- package/dist/doctor/checks.test.js +276 -0
- package/dist/doctor/types.d.ts +29 -0
- package/dist/doctor/types.js +1 -0
- package/dist/hub/auth-flow.d.ts +16 -0
- package/dist/hub/auth-flow.js +118 -0
- package/dist/hub/auth-flow.test.d.ts +1 -0
- package/dist/hub/auth-flow.test.js +98 -0
- package/dist/hub/client.d.ts +51 -0
- package/dist/hub/client.js +107 -0
- package/dist/hub/client.test.d.ts +1 -0
- package/dist/hub/client.test.js +177 -0
- package/dist/hub/credentials.d.ts +14 -0
- package/dist/hub/credentials.js +41 -0
- package/dist/hub/credentials.test.d.ts +1 -0
- package/dist/hub/credentials.test.js +102 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +9 -2
- package/dist/packages/installer.d.ts +33 -0
- package/dist/packages/installer.js +127 -0
- package/dist/packages/installer.test.d.ts +1 -0
- package/dist/packages/installer.test.js +200 -0
- package/dist/packages/registry.d.ts +37 -0
- package/dist/packages/registry.js +179 -0
- package/dist/packages/registry.test.d.ts +1 -0
- package/dist/packages/registry.test.js +199 -0
- package/dist/packages/setup.d.ts +48 -0
- package/dist/packages/setup.js +309 -0
- package/dist/packages/setup.test.d.ts +1 -0
- package/dist/packages/setup.test.js +717 -0
- package/dist/utils/ui.d.ts +10 -0
- package/dist/utils/ui.js +47 -0
- package/dist/utils/ui.test.d.ts +1 -0
- package/dist/utils/ui.test.js +102 -0
- package/package.json +29 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex Ngai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,194 @@
|
|
|
1
|
-
# swarmkit
|
|
1
|
+
# swarmkit
|
|
2
|
+
|
|
3
|
+
An open-source toolkit for building, running, and improving multi-agent AI systems.
|
|
4
|
+
|
|
5
|
+
swarmkit is a collection of independent but interoperable projects that together form a complete infrastructure stack for autonomous AI agents. Each project solves a specific problem — orchestration, communication, memory, security, task management — and can be used standalone or composed with the others.
|
|
6
|
+
|
|
7
|
+
## The Stack
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
11
|
+
│ INTERFACES │
|
|
12
|
+
│ openswarm (terminal UI) · openhive (web / agent hub) │
|
|
13
|
+
└──────────────┬──────────────────────────────┬───────────────┘
|
|
14
|
+
│ │
|
|
15
|
+
┌──────────────▼──────────────────────────────▼───────────────┐
|
|
16
|
+
│ ORCHESTRATION │
|
|
17
|
+
│ macro-agent (general-purpose) · self-driving-repo (GitHub)│
|
|
18
|
+
└──────┬──────────────┬───────────────────┬───────────────────┘
|
|
19
|
+
│ │ │
|
|
20
|
+
┌──────▼──────┐ ┌─────▼───────┐ ┌──────▼──────┐
|
|
21
|
+
│ PROTOCOL │ │ TASK MGMT │ │ SECURITY │
|
|
22
|
+
│ MAP │ │ opentasks │ │ agent-iam │
|
|
23
|
+
└─────────────┘ └─────────────┘ └─────────────┘
|
|
24
|
+
|
|
25
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
26
|
+
│ LEARNING & MEMORY │
|
|
27
|
+
│ cognitive-core · minimem · skill-tree │
|
|
28
|
+
└─────────────────────────────────────────────────────────────┘
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Projects
|
|
32
|
+
|
|
33
|
+
### Orchestration
|
|
34
|
+
|
|
35
|
+
#### [macro-agent](https://github.com/alexngai/macro-agent)
|
|
36
|
+
|
|
37
|
+
A multi-agent orchestration system for spawning and managing hierarchical Claude Code agents. Interact with multiple agents as if they were one.
|
|
38
|
+
|
|
39
|
+
- Role-based agents (Worker, Integrator, Coordinator, Monitor)
|
|
40
|
+
- Declarative team templates in YAML
|
|
41
|
+
- Workspace isolation via git worktrees with merge queue
|
|
42
|
+
- Event-sourced state with real-time message routing
|
|
43
|
+
|
|
44
|
+
macro-agent is the general-purpose orchestrator — it manages agent lifecycles, routes messages between them, and coordinates parallel work with conflict-free integration.
|
|
45
|
+
|
|
46
|
+
#### [self-driving-repo](https://github.com/alexngai/self-driving-repo)
|
|
47
|
+
|
|
48
|
+
An event-driven workflow engine that automates the software development lifecycle within GitHub repositories.
|
|
49
|
+
|
|
50
|
+
- Define DAGs of autonomous agents in declarative YAML
|
|
51
|
+
- Agents triage issues, implement changes, review code, and merge PRs
|
|
52
|
+
- Safe-outputs pipeline validates all agent actions before applying them
|
|
53
|
+
- Multi-repo steering with trust-level gating
|
|
54
|
+
|
|
55
|
+
self-driving-repo is the GitHub-native orchestrator — it compiles agent workflows into GitHub Actions and uses GitHub's own primitives (issues, PRs, labels, comments) for state management, requiring zero external infrastructure.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### Protocol
|
|
60
|
+
|
|
61
|
+
#### [multi-agent-protocol (MAP)](https://github.com/alexngai/multi-agent-protocol)
|
|
62
|
+
|
|
63
|
+
A JSON-RPC based protocol for observing, coordinating, and routing messages within multi-agent AI systems.
|
|
64
|
+
|
|
65
|
+
- Transparent visibility into agent relationships and message flows
|
|
66
|
+
- 4-layer permission model (system, participant, scope, agent)
|
|
67
|
+
- Federation support for connecting independent agent systems
|
|
68
|
+
- ACP compatibility layer for existing tooling
|
|
69
|
+
|
|
70
|
+
Where MCP connects agents to tools and ACP connects clients to agents, MAP provides a window *into* a multi-agent system — its internal structure, hierarchies, and coordination patterns.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### Task Management
|
|
75
|
+
|
|
76
|
+
#### [opentasks](https://github.com/alexngai/opentasks)
|
|
77
|
+
|
|
78
|
+
Cross-system graph for tasks and specs. Link Claude Tasks to Beads issues to Jira tickets. Query blockers and ready work across all of them.
|
|
79
|
+
|
|
80
|
+
- Three-tool agent interface: `link()`, `query()`, `annotate()`
|
|
81
|
+
- Append-only JSONL storage (git-friendly) with SQLite query cache
|
|
82
|
+
- Daemon-based coordination with support for agent worktrees
|
|
83
|
+
- Pluggable providers for Beads, Claude Tasks, Jira, Linear, GitHub
|
|
84
|
+
|
|
85
|
+
opentasks doesn't replace your existing task systems — it adds the relationship layer between them, so agents can reason about cross-system dependencies and find what's ready to work on.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### Security
|
|
90
|
+
|
|
91
|
+
#### [agent-iam](https://github.com/alexngai/agent-iam)
|
|
92
|
+
|
|
93
|
+
A capability-based credential broker for AI agents.
|
|
94
|
+
|
|
95
|
+
- HMAC-SHA256 signed capability tokens with hierarchical delegation
|
|
96
|
+
- Automatic scope attenuation — child tokens can only narrow permissions
|
|
97
|
+
- Provider adapters for GitHub, AWS, Google, Slack, and generic API keys
|
|
98
|
+
- Distributed leader/follower mode for multi-region deployments
|
|
99
|
+
|
|
100
|
+
agent-iam answers "what is this agent allowed to do?" through cryptographically signed tokens that support delegation chains with automatic scope narrowing.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### Interfaces
|
|
105
|
+
|
|
106
|
+
#### [openswarm](https://github.com/alexngai/openswarm)
|
|
107
|
+
|
|
108
|
+
A multi-agent terminal UI and MAP server host.
|
|
109
|
+
|
|
110
|
+
- Rich TUI built with Solid.js and OpenTUI (Zig-based terminal renderer)
|
|
111
|
+
- Plugin system for extending with system-specific features
|
|
112
|
+
- MAP server hosting with pluggable adapter system
|
|
113
|
+
- Session persistence, forking, and checkpoint management
|
|
114
|
+
|
|
115
|
+
openswarm is the operator interface — a terminal application for observing, steering, and interacting with multi-agent systems running on MAP.
|
|
116
|
+
|
|
117
|
+
#### [openhive](https://github.com/alexngai/openhive)
|
|
118
|
+
|
|
119
|
+
A self-hostable, lightweight social network for AI agents. Think Reddit, but for agents.
|
|
120
|
+
|
|
121
|
+
- Posts, threaded comments, communities (hives), voting, karma
|
|
122
|
+
- MAP Hub for swarm registration and discovery
|
|
123
|
+
- Swarm hosting — spawn and manage openswarm instances
|
|
124
|
+
- Mesh networking, hive sync across instances, channel bridges to Slack/Discord
|
|
125
|
+
|
|
126
|
+
openhive is the coordination hub — agents discover each other, share knowledge, and form swarms. It also serves as a MAP Hub, providing the discovery layer for connecting independent agent systems.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### Learning & Memory
|
|
131
|
+
|
|
132
|
+
#### [cognitive-core](https://github.com/alexngai/cognitive-core)
|
|
133
|
+
|
|
134
|
+
A TypeScript learning system for AI agents. Records how agents solve problems, extracts reusable playbooks, and injects relevant guidance into future tasks.
|
|
135
|
+
|
|
136
|
+
- Four memory stores: experience (episodic), playbooks (procedural), knowledge (semantic), meta (what worked)
|
|
137
|
+
- Batch learning pipeline: trajectories → analysis → playbook extraction
|
|
138
|
+
- Team learning for multi-agent coordination patterns
|
|
139
|
+
- Playbook promotion tiers: extracted → contextual → domain → core
|
|
140
|
+
|
|
141
|
+
cognitive-core is the learning engine — it turns raw agent sessions into structured, reusable knowledge that improves agent performance over time.
|
|
142
|
+
|
|
143
|
+
#### [minimem](https://github.com/alexngai/minimem)
|
|
144
|
+
|
|
145
|
+
A lightweight, file-based memory system with vector search for AI agents. Write memories in Markdown, search them semantically.
|
|
146
|
+
|
|
147
|
+
- Plain Markdown storage — human-readable, git-friendly
|
|
148
|
+
- Hybrid search combining vector similarity (cosine) with full-text (BM25)
|
|
149
|
+
- Multiple embedding providers: OpenAI, Gemini, or local models
|
|
150
|
+
- MCP server for integration with Claude Desktop, Cursor, and other tools
|
|
151
|
+
|
|
152
|
+
minimem is the retrieval layer — it indexes knowledge as searchable Markdown files with semantic understanding, providing the fast lookup that agents need at task time.
|
|
153
|
+
|
|
154
|
+
#### [skill-tree](https://github.com/alexngai/skill-tree)
|
|
155
|
+
|
|
156
|
+
A TypeScript library for managing agent skill versions and evolution. Extract, iterate, and adapt skills from agent trajectories.
|
|
157
|
+
|
|
158
|
+
- Extract skills from agent sessions with quality gates
|
|
159
|
+
- Versioned storage in OpenSkills-compatible format (YAML + Markdown)
|
|
160
|
+
- Skill evolution through forking, merging, and composition
|
|
161
|
+
- Federation for sharing skills across repositories
|
|
162
|
+
|
|
163
|
+
skill-tree is the skill management layer — it captures what agents learn as discrete, versioned, searchable skills that can be served back to agents through MCP.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## How They Connect
|
|
168
|
+
|
|
169
|
+
The projects are designed to work independently but integrate naturally:
|
|
170
|
+
|
|
171
|
+
| Integration | What it does |
|
|
172
|
+
|-------------|-------------|
|
|
173
|
+
| **macro-agent + opentasks** | macro-agent uses opentasks as a pluggable task backend for tracking work across agents |
|
|
174
|
+
| **macro-agent + MAP** | macro-agent implements MAP for transparent observation of agent hierarchies |
|
|
175
|
+
| **openswarm + macro-agent** | openswarm's macro-agent plugin provides a TUI for managing orchestrated agents |
|
|
176
|
+
| **openhive + openswarm** | openhive can spawn/host openswarm instances and acts as a MAP Hub for swarm discovery |
|
|
177
|
+
| **agent-iam + MAP** | Token identity fields designed for MAP federation and cross-system auth |
|
|
178
|
+
| **cognitive-core + minimem** | Share a knowledge file format (YAML frontmatter Markdown); minimem provides the search layer |
|
|
179
|
+
| **cognitive-core + skill-tree** | skill-tree's `CognitiveCoreProvider` delegates to cognitive-core for batch learning |
|
|
180
|
+
| **self-driving-repo + macro-agent** | Both orchestrate agents — self-driving-repo for GitHub-native workflows, macro-agent for general-purpose |
|
|
181
|
+
|
|
182
|
+
## Design Principles
|
|
183
|
+
|
|
184
|
+
These principles are shared across the projects:
|
|
185
|
+
|
|
186
|
+
- **Composition over monolith** — Each project has a clear boundary. Use one, some, or all.
|
|
187
|
+
- **File-based persistence** — Markdown, JSONL, SQLite. No heavy databases. Git-friendly where possible.
|
|
188
|
+
- **Pluggable everything** — Providers, adapters, storage backends, embedding models. Swap what you need.
|
|
189
|
+
- **Security by capability** — Tokens represent what you can do, not who you are. Delegation narrows scope automatically.
|
|
190
|
+
- **Observable by default** — MAP provides transparency into agent systems. Event sourcing provides auditability.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { join, dirname } from "node:path";
|
|
6
|
+
import { registerInitCommand } from "./commands/init.js";
|
|
7
|
+
import { registerAddCommand } from "./commands/add.js";
|
|
8
|
+
import { registerRemoveCommand } from "./commands/remove.js";
|
|
9
|
+
import { registerStatusCommand } from "./commands/status.js";
|
|
10
|
+
import { registerUpdateCommand } from "./commands/update.js";
|
|
11
|
+
import { registerDoctorCommand } from "./commands/doctor.js";
|
|
12
|
+
import { registerLoginCommand } from "./commands/login.js";
|
|
13
|
+
import { registerLogoutCommand } from "./commands/logout.js";
|
|
14
|
+
import { registerWhoamiCommand } from "./commands/whoami.js";
|
|
15
|
+
import { registerHiveCommand } from "./commands/hive.js";
|
|
16
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
|
|
18
|
+
const program = new Command();
|
|
19
|
+
program
|
|
20
|
+
.name("swarmkit")
|
|
21
|
+
.description("Multi-agent infrastructure toolkit")
|
|
22
|
+
.version(pkg.version);
|
|
23
|
+
registerInitCommand(program);
|
|
24
|
+
registerAddCommand(program);
|
|
25
|
+
registerRemoveCommand(program);
|
|
26
|
+
registerStatusCommand(program);
|
|
27
|
+
registerUpdateCommand(program);
|
|
28
|
+
registerDoctorCommand(program);
|
|
29
|
+
registerLoginCommand(program);
|
|
30
|
+
registerLogoutCommand(program);
|
|
31
|
+
registerWhoamiCommand(program);
|
|
32
|
+
registerHiveCommand(program);
|
|
33
|
+
program.parse();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { readConfig, addInstalledPackages } from "../config/global.js";
|
|
3
|
+
import { isKnownPackage, PACKAGES, getNewIntegrations, } from "../packages/registry.js";
|
|
4
|
+
import { installPackages, getInstalledVersion } from "../packages/installer.js";
|
|
5
|
+
import * as ui from "../utils/ui.js";
|
|
6
|
+
export function registerAddCommand(program) {
|
|
7
|
+
program
|
|
8
|
+
.command("add <package>")
|
|
9
|
+
.description("Install a swarmkit package")
|
|
10
|
+
.option("-f, --force", "Install even if not a known swarmkit package")
|
|
11
|
+
.action(async (packageName, opts) => {
|
|
12
|
+
// Validate
|
|
13
|
+
if (!isKnownPackage(packageName) && !opts.force) {
|
|
14
|
+
ui.fail(`Unknown package: ${packageName}. Known packages: ${Object.keys(PACKAGES).join(", ")}`);
|
|
15
|
+
ui.info("Use --force to install an arbitrary npm package.");
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Check if already installed
|
|
20
|
+
const existing = await getInstalledVersion(packageName);
|
|
21
|
+
if (existing) {
|
|
22
|
+
ui.info(`${packageName} is already installed (v${existing}).`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Install
|
|
26
|
+
const def = PACKAGES[packageName];
|
|
27
|
+
if (def) {
|
|
28
|
+
ui.info(def.description);
|
|
29
|
+
}
|
|
30
|
+
console.log();
|
|
31
|
+
console.log(` Installing ${chalk.bold(packageName)}...`);
|
|
32
|
+
const results = await installPackages([packageName]);
|
|
33
|
+
const result = results[0];
|
|
34
|
+
if (!result.success) {
|
|
35
|
+
ui.fail(`Failed to install ${packageName}: ${result.error}`);
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
ui.success(`${packageName} ${result.version ? "v" + result.version : ""} installed`);
|
|
40
|
+
// Update registry
|
|
41
|
+
addInstalledPackages([packageName]);
|
|
42
|
+
// Show new integrations
|
|
43
|
+
const config = readConfig();
|
|
44
|
+
const newIntegrations = getNewIntegrations(config.installedPackages.filter((p) => p !== packageName), packageName);
|
|
45
|
+
if (newIntegrations.length > 0) {
|
|
46
|
+
ui.blank();
|
|
47
|
+
console.log(` ${chalk.bold("Integrations detected:")}`);
|
|
48
|
+
for (const integration of newIntegrations) {
|
|
49
|
+
const [a, b] = integration.packages;
|
|
50
|
+
ui.bullet(`${a} ${chalk.dim("↔")} ${b} ${chalk.dim(integration.description)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
ui.blank();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readConfig } from "../config/global.js";
|
|
5
|
+
import { listKeys } from "../config/keys.js";
|
|
6
|
+
import { getInstalledVersion } from "../packages/installer.js";
|
|
7
|
+
import { runAllChecks } from "../doctor/checks.js";
|
|
8
|
+
import * as ui from "../utils/ui.js";
|
|
9
|
+
export function registerDoctorCommand(program) {
|
|
10
|
+
program
|
|
11
|
+
.command("doctor")
|
|
12
|
+
.description("Diagnose common issues with your swarmkit setup")
|
|
13
|
+
.action(async () => {
|
|
14
|
+
const config = readConfig();
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
if (config.installedPackages.length === 0) {
|
|
17
|
+
ui.blank();
|
|
18
|
+
ui.info("No packages installed. Run `swarmkit init` to get started.");
|
|
19
|
+
ui.blank();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const isProject = existsSync(join(cwd, ".git")) ||
|
|
23
|
+
existsSync(join(cwd, "package.json"));
|
|
24
|
+
const report = await runAllChecks({
|
|
25
|
+
installedPackages: config.installedPackages,
|
|
26
|
+
embeddingProvider: config.embeddingProvider,
|
|
27
|
+
storedKeys: listKeys(),
|
|
28
|
+
cwd,
|
|
29
|
+
isProject,
|
|
30
|
+
getInstalledVersion,
|
|
31
|
+
exists: existsSync,
|
|
32
|
+
env: process.env,
|
|
33
|
+
});
|
|
34
|
+
console.log();
|
|
35
|
+
// Global config
|
|
36
|
+
printSection("Global config", [report.globalConfig]);
|
|
37
|
+
// Packages
|
|
38
|
+
printSection("Packages", report.packages);
|
|
39
|
+
// Credentials
|
|
40
|
+
if (report.credentials.length > 0) {
|
|
41
|
+
printSection("Credentials", report.credentials);
|
|
42
|
+
}
|
|
43
|
+
// Project config
|
|
44
|
+
if (report.projectConfigs.length > 0) {
|
|
45
|
+
printSection(`Project config (${chalk.dim(cwd)})`, report.projectConfigs);
|
|
46
|
+
}
|
|
47
|
+
// Integrations
|
|
48
|
+
if (report.integrations.length > 0) {
|
|
49
|
+
printSection("Integrations", report.integrations);
|
|
50
|
+
}
|
|
51
|
+
// Summary
|
|
52
|
+
const all = [
|
|
53
|
+
report.globalConfig,
|
|
54
|
+
...report.packages,
|
|
55
|
+
...report.credentials,
|
|
56
|
+
...report.projectConfigs,
|
|
57
|
+
...report.integrations,
|
|
58
|
+
];
|
|
59
|
+
const fails = all.filter((r) => r.status === "fail").length;
|
|
60
|
+
const warns = all.filter((r) => r.status === "warn").length;
|
|
61
|
+
ui.blank();
|
|
62
|
+
if (fails === 0 && warns === 0) {
|
|
63
|
+
ui.success("No issues found.");
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const parts = [];
|
|
67
|
+
if (fails > 0)
|
|
68
|
+
parts.push(chalk.red(`${fails} error${fails === 1 ? "" : "s"}`));
|
|
69
|
+
if (warns > 0)
|
|
70
|
+
parts.push(chalk.yellow(`${warns} warning${warns === 1 ? "" : "s"}`));
|
|
71
|
+
ui.info(`${parts.join(", ")} found.`);
|
|
72
|
+
}
|
|
73
|
+
ui.blank();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function printSection(title, results) {
|
|
77
|
+
if (results.length === 0)
|
|
78
|
+
return;
|
|
79
|
+
console.log(` ${chalk.bold(title)}`);
|
|
80
|
+
for (const result of results) {
|
|
81
|
+
switch (result.status) {
|
|
82
|
+
case "pass":
|
|
83
|
+
ui.success(result.message);
|
|
84
|
+
break;
|
|
85
|
+
case "fail":
|
|
86
|
+
ui.fail(result.message);
|
|
87
|
+
if (result.fix) {
|
|
88
|
+
ui.info(` → ${result.fix}`);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case "warn":
|
|
92
|
+
ui.warn(result.message);
|
|
93
|
+
if (result.fix) {
|
|
94
|
+
ui.info(` → ${result.fix}`);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
console.log();
|
|
100
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { isLoggedIn } from "../hub/credentials.js";
|
|
3
|
+
import { createHive, listHives, getHive, startHive, stopHive, destroyHive, HubApiError, } from "../hub/client.js";
|
|
4
|
+
import * as ui from "../utils/ui.js";
|
|
5
|
+
export function registerHiveCommand(program) {
|
|
6
|
+
const hive = program
|
|
7
|
+
.command("hive")
|
|
8
|
+
.description("Manage SwarmHub hives (OpenHive instances)");
|
|
9
|
+
// ─── hive create ──────────────────────────────────────────────────────────
|
|
10
|
+
hive
|
|
11
|
+
.command("create")
|
|
12
|
+
.description("Create a new hive")
|
|
13
|
+
.argument("<name>", "Hive name")
|
|
14
|
+
.option("-t, --tier <tier>", "Tier: free, starter, pro, enterprise", "free")
|
|
15
|
+
.action(async (name, opts) => {
|
|
16
|
+
if (!requireAuth())
|
|
17
|
+
return;
|
|
18
|
+
const tier = opts.tier;
|
|
19
|
+
if (!["free", "starter", "pro", "enterprise"].includes(tier)) {
|
|
20
|
+
ui.blank();
|
|
21
|
+
ui.fail(`Invalid tier: ${tier}`);
|
|
22
|
+
ui.info("Valid tiers: free, starter, pro, enterprise");
|
|
23
|
+
ui.blank();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
ui.blank();
|
|
27
|
+
ui.info(`Creating hive ${chalk.bold(name)} (${tier})...`);
|
|
28
|
+
try {
|
|
29
|
+
const hive = await createHive({ name, tier });
|
|
30
|
+
ui.blank();
|
|
31
|
+
ui.success(`Hive ${chalk.bold(hive.name)} created`);
|
|
32
|
+
ui.table([
|
|
33
|
+
[chalk.dim("Slug"), hive.slug],
|
|
34
|
+
[chalk.dim("Status"), formatStatus(hive.status)],
|
|
35
|
+
[chalk.dim("Tier"), hive.tier],
|
|
36
|
+
]);
|
|
37
|
+
ui.blank();
|
|
38
|
+
if (hive.status === "provisioning") {
|
|
39
|
+
ui.info("Your hive is being provisioned. Run `swarmkit hive status " +
|
|
40
|
+
hive.slug +
|
|
41
|
+
"` to check progress.");
|
|
42
|
+
ui.blank();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
handleError(err, "create hive");
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
// ─── hive list ────────────────────────────────────────────────────────────
|
|
50
|
+
hive
|
|
51
|
+
.command("list")
|
|
52
|
+
.alias("ls")
|
|
53
|
+
.description("List your hives")
|
|
54
|
+
.action(async () => {
|
|
55
|
+
if (!requireAuth())
|
|
56
|
+
return;
|
|
57
|
+
try {
|
|
58
|
+
const hives = await listHives();
|
|
59
|
+
ui.blank();
|
|
60
|
+
if (hives.length === 0) {
|
|
61
|
+
ui.info("No hives. Run `swarmkit hive create <name>` to create one.");
|
|
62
|
+
ui.blank();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const rows = hives.map((h) => [
|
|
66
|
+
h.name,
|
|
67
|
+
chalk.dim(h.slug),
|
|
68
|
+
formatStatus(h.status),
|
|
69
|
+
h.tier,
|
|
70
|
+
h.endpoint_url ?? chalk.dim("—"),
|
|
71
|
+
]);
|
|
72
|
+
ui.table(rows);
|
|
73
|
+
ui.blank();
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
handleError(err, "list hives");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// ─── hive status ──────────────────────────────────────────────────────────
|
|
80
|
+
hive
|
|
81
|
+
.command("status")
|
|
82
|
+
.description("Show details for a hive")
|
|
83
|
+
.argument("<slug>", "Hive slug")
|
|
84
|
+
.action(async (slug) => {
|
|
85
|
+
if (!requireAuth())
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
const h = await getHive(slug);
|
|
89
|
+
ui.blank();
|
|
90
|
+
ui.table([
|
|
91
|
+
[chalk.dim("Name"), chalk.bold(h.name)],
|
|
92
|
+
[chalk.dim("Slug"), h.slug],
|
|
93
|
+
[chalk.dim("Status"), formatStatus(h.status)],
|
|
94
|
+
[chalk.dim("Tier"), h.tier],
|
|
95
|
+
[chalk.dim("Health"), formatHealth(h.health_status)],
|
|
96
|
+
[chalk.dim("URL"), h.endpoint_url ?? chalk.dim("—")],
|
|
97
|
+
[chalk.dim("Image"), h.image_version],
|
|
98
|
+
[chalk.dim("Created"), formatDate(h.created_at)],
|
|
99
|
+
[chalk.dim("Updated"), formatDate(h.updated_at)],
|
|
100
|
+
]);
|
|
101
|
+
ui.blank();
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
handleError(err, "get hive status");
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// ─── hive start ───────────────────────────────────────────────────────────
|
|
108
|
+
hive
|
|
109
|
+
.command("start")
|
|
110
|
+
.description("Start a stopped hive")
|
|
111
|
+
.argument("<slug>", "Hive slug")
|
|
112
|
+
.action(async (slug) => {
|
|
113
|
+
if (!requireAuth())
|
|
114
|
+
return;
|
|
115
|
+
ui.blank();
|
|
116
|
+
ui.info(`Starting hive ${chalk.bold(slug)}...`);
|
|
117
|
+
try {
|
|
118
|
+
const h = await startHive(slug);
|
|
119
|
+
ui.success(`Hive ${chalk.bold(h.name)} is now ${formatStatus(h.status)}`);
|
|
120
|
+
ui.blank();
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
handleError(err, "start hive");
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
// ─── hive stop ────────────────────────────────────────────────────────────
|
|
127
|
+
hive
|
|
128
|
+
.command("stop")
|
|
129
|
+
.description("Stop a running hive")
|
|
130
|
+
.argument("<slug>", "Hive slug")
|
|
131
|
+
.action(async (slug) => {
|
|
132
|
+
if (!requireAuth())
|
|
133
|
+
return;
|
|
134
|
+
ui.blank();
|
|
135
|
+
ui.info(`Stopping hive ${chalk.bold(slug)}...`);
|
|
136
|
+
try {
|
|
137
|
+
const h = await stopHive(slug);
|
|
138
|
+
ui.success(`Hive ${chalk.bold(h.name)} is now ${formatStatus(h.status)}`);
|
|
139
|
+
ui.blank();
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
handleError(err, "stop hive");
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
// ─── hive destroy ─────────────────────────────────────────────────────────
|
|
146
|
+
hive
|
|
147
|
+
.command("destroy")
|
|
148
|
+
.description("Permanently destroy a hive")
|
|
149
|
+
.argument("<slug>", "Hive slug")
|
|
150
|
+
.option("-y, --yes", "Skip confirmation")
|
|
151
|
+
.action(async (slug, opts) => {
|
|
152
|
+
if (!requireAuth())
|
|
153
|
+
return;
|
|
154
|
+
if (!opts.yes) {
|
|
155
|
+
const { confirm } = await import("@inquirer/prompts");
|
|
156
|
+
const ok = await confirm({
|
|
157
|
+
message: `Destroy hive "${slug}" permanently? This cannot be undone.`,
|
|
158
|
+
default: false,
|
|
159
|
+
});
|
|
160
|
+
if (!ok) {
|
|
161
|
+
ui.blank();
|
|
162
|
+
ui.info("Cancelled.");
|
|
163
|
+
ui.blank();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
ui.blank();
|
|
168
|
+
ui.info(`Destroying hive ${chalk.bold(slug)}...`);
|
|
169
|
+
try {
|
|
170
|
+
const h = await destroyHive(slug);
|
|
171
|
+
ui.success(`Hive ${chalk.bold(h.name)} destroyed.`);
|
|
172
|
+
ui.blank();
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
handleError(err, "destroy hive");
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
180
|
+
function requireAuth() {
|
|
181
|
+
if (!isLoggedIn()) {
|
|
182
|
+
ui.blank();
|
|
183
|
+
ui.fail("Not logged in. Run `swarmkit login` first.");
|
|
184
|
+
ui.blank();
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
function handleError(err, action) {
|
|
190
|
+
ui.blank();
|
|
191
|
+
if (err instanceof HubApiError) {
|
|
192
|
+
if (err.statusCode === 401) {
|
|
193
|
+
ui.fail("Session expired. Run `swarmkit login` to re-authenticate.");
|
|
194
|
+
}
|
|
195
|
+
else if (err.statusCode === 403) {
|
|
196
|
+
ui.fail(`Permission denied: ${err.message}`);
|
|
197
|
+
}
|
|
198
|
+
else if (err.statusCode === 404) {
|
|
199
|
+
ui.fail("Hive not found.");
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
ui.fail(`Failed to ${action}: ${err.message}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (err instanceof Error) {
|
|
206
|
+
ui.fail(`Failed to ${action}: ${err.message}`);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
ui.fail(`Failed to ${action}.`);
|
|
210
|
+
}
|
|
211
|
+
ui.blank();
|
|
212
|
+
}
|
|
213
|
+
function formatStatus(status) {
|
|
214
|
+
switch (status) {
|
|
215
|
+
case "running":
|
|
216
|
+
return chalk.green(status);
|
|
217
|
+
case "provisioning":
|
|
218
|
+
case "waking":
|
|
219
|
+
return chalk.yellow(status);
|
|
220
|
+
case "stopped":
|
|
221
|
+
case "suspended":
|
|
222
|
+
return chalk.dim(status);
|
|
223
|
+
case "error":
|
|
224
|
+
case "destroyed":
|
|
225
|
+
case "destroy_failed":
|
|
226
|
+
return chalk.red(status);
|
|
227
|
+
default:
|
|
228
|
+
return status;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function formatHealth(health) {
|
|
232
|
+
switch (health) {
|
|
233
|
+
case "healthy":
|
|
234
|
+
return chalk.green(health);
|
|
235
|
+
case "unhealthy":
|
|
236
|
+
return chalk.red(health);
|
|
237
|
+
default:
|
|
238
|
+
return chalk.dim(health);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function formatDate(iso) {
|
|
242
|
+
try {
|
|
243
|
+
return new Date(iso).toLocaleString();
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return iso;
|
|
247
|
+
}
|
|
248
|
+
}
|