superagent-ai-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1,27 @@
1
+ # ═══════════════════════════════════════════════════
2
+ # SuperAgent Configuration
3
+ # ═══════════════════════════════════════════════════
4
+
5
+ # API gateway URL (required)
6
+ # Supports: Anthropic official, AWS Bedrock, Alibaba Cloud, Zhipu AI, etc.
7
+ # Anthropic 兼容网关地址(必填)
8
+ ANTHROPIC_BASE_URL=https://api.anthropic.com
9
+
10
+ # API auth token (required)
11
+ # 网关认证 token(必填)
12
+ ANTHROPIC_AUTH_TOKEN=
13
+
14
+ # Optional: server port (default: 3000)
15
+ # PORT=3000
16
+
17
+ # Optional: text model name (default: claude-sonnet-4-6)
18
+ # ANTHROPIC_MODEL=claude-sonnet-4-6
19
+
20
+ # Optional: vision model (for image inputs, default: same as text model)
21
+ # ANTHROPIC_MODEL_VISION=
22
+
23
+ # Optional: fallback model for content moderation triggers
24
+ # ANTHROPIC_MODEL_FALLBACK=
25
+
26
+ # Optional: set to 0 to disable Plan-Execute pipeline (emergency escape hatch)
27
+ # LUNA_PLAN=0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 SuperAgent Contributors
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 ADDED
@@ -0,0 +1,147 @@
1
+ # SuperAgent
2
+
3
+ [中文文档](./README.zh-CN.md)
4
+
5
+ A local AI Agent powered by Claude SDK with **Plan-Execute-Reflect** architecture. Zero-build, browser-ready.
6
+
7
+ ## Features
8
+
9
+ - **Plan-Execute-Reflect** — Structured 3-phase pipeline: Planner outputs structured plan → Executor runs each step independently (prevents context avalanche) → Reflector auto-diagnoses and fixes failures
10
+ - **Multimodal Input** — Supports image uploads (up to 8 images per message)
11
+ - **Tool Calling** — File read/write, shell execution, web search & fetch
12
+ - **Skills System** — Dynamically extensible via `.claude/skills/` directory
13
+ - **SSE Streaming** — Real-time streaming output to browser
14
+ - **Session Archive** — Automatic conversation history persistence
15
+ - **Content Safety Fallback** — Auto-switches to fallback model on content moderation triggers
16
+ - **Customizable Persona** — Edit `agent-persona.md` to change personality (hot-reload, no restart needed)
17
+
18
+ ## Quick Start
19
+
20
+ ### Install via npm
21
+
22
+ ```bash
23
+ # Global install
24
+ npm install -g superagent-ai-agent
25
+
26
+ # Initialize config in a new directory
27
+ mkdir my-agent && cd my-agent
28
+ superagent init
29
+
30
+ # Edit .env with your API credentials
31
+ # Then start
32
+ superagent
33
+ ```
34
+
35
+ ### Install via curl
36
+
37
+ ```bash
38
+ curl -fsSL https://raw.githubusercontent.com/nodermachine/superagent/main/install.sh | bash
39
+ ```
40
+
41
+ ### Install via npx (no global install)
42
+
43
+ ```bash
44
+ npx superagent-ai-agent init
45
+ npx superagent-ai-agent
46
+ ```
47
+
48
+ ### Run from source
49
+
50
+ ```bash
51
+ git clone git@github.com:nodermachine/superagent.git
52
+ cd superagent
53
+ npm install
54
+ cp .env.example .env
55
+ # Edit .env with your credentials
56
+ npm start
57
+ ```
58
+
59
+ ## Configuration
60
+
61
+ ### Environment Variables (`.env`)
62
+
63
+ | Variable | Required | Description |
64
+ |----------|----------|-------------|
65
+ | `ANTHROPIC_BASE_URL` | Yes | API gateway URL (supports Anthropic, AWS Bedrock, Alibaba Cloud, Zhipu AI, etc.) |
66
+ | `ANTHROPIC_AUTH_TOKEN` | Yes | API authentication token |
67
+ | `PORT` | No | Server port (default: 3000) |
68
+ | `ANTHROPIC_MODEL` | No | Text model name (default: claude-sonnet-4-6) |
69
+ | `ANTHROPIC_MODEL_VISION` | No | Vision model name (default: same as text model) |
70
+ | `ANTHROPIC_MODEL_FALLBACK` | No | Fallback model for content moderation |
71
+ | `LUNA_PLAN` | No | Set to `0` to disable Plan-Execute pipeline |
72
+
73
+ ### Agent Config (`agent-config.json`)
74
+
75
+ ```json
76
+ {
77
+ "agentName": "SuperAgent",
78
+ "userName": "User",
79
+ "avatar": "avatar.png"
80
+ }
81
+ ```
82
+
83
+ ### Persona (`agent-persona.md`)
84
+
85
+ Customize your agent's personality, tone, and behavior rules. Changes take effect immediately without server restart.
86
+
87
+ ## CLI Usage
88
+
89
+ ```bash
90
+ superagent [options]
91
+
92
+ Commands:
93
+ superagent Start the agent server
94
+ superagent init Initialize config files in current directory
95
+
96
+ Options:
97
+ --port, -p <port> Server port (default: 3000)
98
+ --help, -h Show help
99
+ --version, -v Show version
100
+ ```
101
+
102
+ ## Architecture
103
+
104
+ ```
105
+ ┌─────────────────────────────────────────┐
106
+ │ Browser (Web UI) │
107
+ │ http://localhost:3000 │
108
+ └───────────────┬─────────────────────────┘
109
+ │ SSE
110
+ ┌───────────────▼─────────────────────────┐
111
+ │ Express Server │
112
+ │ (src/server.js) │
113
+ └───────────────┬─────────────────────────┘
114
+
115
+ ┌───────────────▼─────────────────────────┐
116
+ │ Plan-Execute-Reflect │
117
+ │ (src/agent.js) │
118
+ │ │
119
+ │ ┌─────────┐ ┌──────────┐ ┌─────────┐ │
120
+ │ │ Planner │→│ Executor │→│Reflector│ │
121
+ │ └─────────┘ └──────────┘ └─────────┘ │
122
+ └───────────────┬─────────────────────────┘
123
+
124
+ ┌───────────────▼─────────────────────────┐
125
+ │ Claude Agent SDK │
126
+ │ Tools: Read/Write/Edit/Bash/Web │
127
+ └──────────────────────────────────────────┘
128
+ ```
129
+
130
+ ## Skills
131
+
132
+ SuperAgent supports a dynamic skills system. Place skill definitions in `.claude/skills/<name>/`:
133
+
134
+ ```
135
+ .claude/skills/<name>/
136
+ ├── SKILL.md ← Required: frontmatter + instructions
137
+ └── helpers/ ← Optional: helper scripts/templates
138
+ ```
139
+
140
+ ## Requirements
141
+
142
+ - Node.js >= 20
143
+ - An API key for a Claude-compatible endpoint
144
+
145
+ ## License
146
+
147
+ MIT
@@ -0,0 +1,147 @@
1
+ # SuperAgent
2
+
3
+ [English](./README.md)
4
+
5
+ 基于 Claude SDK 的本地 AI Agent,采用 **Plan-Execute-Reflect** 三段式架构。零构建,浏览器打开即用。
6
+
7
+ ## 特性
8
+
9
+ - **Plan-Execute-Reflect** — 结构化三段式管线:Planner 输出结构化计划 → Executor 分步独立执行(防上下文雪崩)→ Reflector 失败时自动诊断修复
10
+ - **多模态输入** — 支持图片上传(每条消息最多 8 张图片)
11
+ - **工具调用** — 文件读写、Shell 执行、Web 搜索与抓取
12
+ - **技能系统** — 通过 `.claude/skills/` 目录动态扩展能力
13
+ - **SSE 流式输出** — 实时流式推送到浏览器
14
+ - **会话归档** — 对话历史自动持久化
15
+ - **内容安全降级** — 触发内容审查时自动切换备用模型
16
+ - **可定制人设** — 编辑 `agent-persona.md` 即时生效,无需重启
17
+
18
+ ## 快速开始
19
+
20
+ ### 通过 npm 安装
21
+
22
+ ```bash
23
+ # 全局安装
24
+ npm install -g superagent-ai-agent
25
+
26
+ # 在新目录中初始化配置
27
+ mkdir my-agent && cd my-agent
28
+ superagent init
29
+
30
+ # 编辑 .env 填入 API 凭证
31
+ # 然后启动
32
+ superagent
33
+ ```
34
+
35
+ ### 通过 curl 安装
36
+
37
+ ```bash
38
+ curl -fsSL https://raw.githubusercontent.com/nodermachine/superagent/main/install.sh | bash
39
+ ```
40
+
41
+ ### 通过 npx 使用(无需全局安装)
42
+
43
+ ```bash
44
+ npx superagent-ai-agent init
45
+ npx superagent-ai-agent
46
+ ```
47
+
48
+ ### 从源码运行
49
+
50
+ ```bash
51
+ git clone git@github.com:nodermachine/superagent.git
52
+ cd superagent
53
+ npm install
54
+ cp .env.example .env
55
+ # 编辑 .env 填入凭证
56
+ npm start
57
+ ```
58
+
59
+ ## 配置说明
60
+
61
+ ### 环境变量(`.env`)
62
+
63
+ | 变量名 | 必填 | 说明 |
64
+ |--------|------|------|
65
+ | `ANTHROPIC_BASE_URL` | 是 | API 网关地址(支持 Anthropic 官方、AWS Bedrock、阿里云百炼、智谱 AI 等) |
66
+ | `ANTHROPIC_AUTH_TOKEN` | 是 | API 认证令牌 |
67
+ | `PORT` | 否 | 服务端口(默认 3000) |
68
+ | `ANTHROPIC_MODEL` | 否 | 文本模型名称(默认 claude-sonnet-4-6) |
69
+ | `ANTHROPIC_MODEL_VISION` | 否 | 多模态模型名称(默认与文本模型相同) |
70
+ | `ANTHROPIC_MODEL_FALLBACK` | 否 | 内容审查触发时的备用模型 |
71
+ | `LUNA_PLAN` | 否 | 设为 `0` 关闭 Plan-Execute 管线 |
72
+
73
+ ### Agent 配置(`agent-config.json`)
74
+
75
+ ```json
76
+ {
77
+ "agentName": "SuperAgent",
78
+ "userName": "User",
79
+ "avatar": "avatar.png"
80
+ }
81
+ ```
82
+
83
+ ### 人设(`agent-persona.md`)
84
+
85
+ 自定义 Agent 的性格、语气和行为规则。修改后立即生效,无需重启服务。
86
+
87
+ ## CLI 使用
88
+
89
+ ```bash
90
+ superagent [选项]
91
+
92
+ 命令:
93
+ superagent 启动 Agent 服务
94
+ superagent init 在当前目录初始化配置文件
95
+
96
+ 选项:
97
+ --port, -p <端口> 服务端口(默认 3000)
98
+ --help, -h 显示帮助
99
+ --version, -v 显示版本号
100
+ ```
101
+
102
+ ## 架构
103
+
104
+ ```
105
+ ┌─────────────────────────────────────────┐
106
+ │ 浏览器 (Web UI) │
107
+ │ http://localhost:3000 │
108
+ └───────────────┬─────────────────────────┘
109
+ │ SSE
110
+ ┌───────────────▼─────────────────────────┐
111
+ │ Express 服务器 │
112
+ │ (src/server.js) │
113
+ └───────────────┬─────────────────────────┘
114
+
115
+ ┌───────────────▼─────────────────────────┐
116
+ │ Plan-Execute-Reflect │
117
+ │ (src/agent.js) │
118
+ │ │
119
+ │ ┌─────────┐ ┌──────────┐ ┌─────────┐ │
120
+ │ │ Planner │→│ Executor │→│Reflector│ │
121
+ │ └─────────┘ └──────────┘ └─────────┘ │
122
+ └───────────────┬─────────────────────────┘
123
+
124
+ ┌───────────────▼─────────────────────────┐
125
+ │ Claude Agent SDK │
126
+ │ 工具: Read/Write/Edit/Bash/Web │
127
+ └──────────────────────────────────────────┘
128
+ ```
129
+
130
+ ## 技能系统
131
+
132
+ SuperAgent 支持动态技能扩展。将技能定义放在 `.claude/skills/<name>/` 下:
133
+
134
+ ```
135
+ .claude/skills/<name>/
136
+ ├── SKILL.md ← 必需:frontmatter + 使用说明
137
+ └── helpers/ ← 可选:辅助脚本/模板
138
+ ```
139
+
140
+ ## 系统要求
141
+
142
+ - Node.js >= 20
143
+ - 一个兼容 Claude 的 API 密钥
144
+
145
+ ## 许可证
146
+
147
+ MIT
@@ -0,0 +1,4 @@
1
+ {
2
+ "agentName": "SuperAgent",
3
+ "userName": "User"
4
+ }
@@ -0,0 +1,67 @@
1
+ # Agent 人设
2
+
3
+ > 这段内容会作为 `systemPrompt.append` 注入到 Claude Code 默认 system prompt 之后,
4
+ > 决定 Agent 跟用户对话时的身份、语气、风格、边界。
5
+ >
6
+ > 编辑保存后**下一轮对话立刻生效,不用重启服务**(每次 query 都重新读这个文件)。
7
+
8
+ ---
9
+
10
+ ## 身份
11
+
12
+ - 你的名字从 `agent-config.json` 的 `agentName` 字段读取
13
+ - 你称呼用户为 `agent-config.json` 的 `userName` 字段
14
+ - 你是一个本地运行的个人助理
15
+ - 你能读写当前目录文件、执行 shell 命令
16
+
17
+ ## 语气与风格
18
+
19
+ - 全程**中文**回答
20
+ - 简短直接,不寒暄,不要「好的我来帮您」「希望对您有帮助」这类客套
21
+ - 工程问题用专业术语,不展开入门概念,除非用户明确问
22
+ - 不确定就说不确定;不要编造 API、字段、链接
23
+ - 拒绝时直说原因,不绕弯子
24
+
25
+ ## 工作守则
26
+
27
+ - 修改文件前先 `read` / `grep` 现状,不要凭印象重写
28
+ - **不可逆操作**(rm -rf、git reset --hard、git push --force、覆盖未提交改动)**先停下来跟用户确认**
29
+ - 不要主动新建 README / 设计文档 / summary.md,除非用户明确要求
30
+ - 不要顺手清理 / 重构无关代码
31
+ - 不要 `npm install` 新依赖,除非用户同意
32
+
33
+ ## 执行模式(plan-execute-reflection)
34
+
35
+ 本 agent 已启用三段式执行管线,你会在不同 query 里被分配不同角色:
36
+
37
+ - **Planner**:接到复杂请求时,先输出结构化 plan(JSON),不要直接动手。简单问答判 `needPlan:false`。
38
+ - **Executor**:按 plan 逐步执行,每步聚焦当前目标,完成后一句话总结。
39
+ - **Reflector**:某步失败时被唤起,诊断根因 → 优先跑客观验证(测试/编译/lint)→ 修复,最多一次。
40
+
41
+ 判定复杂度的直觉(满足任一即 `needPlan:true`):
42
+ 1. 涉及 2 个以上文件、需要多轮工具调用、有明确先后依赖
43
+ 2. 预期输出超过 300 字且含多个模块
44
+
45
+ 单文件小改、解释性回答、单步查询 → 不需要 plan,直接答。
46
+
47
+ ## Skills 管理
48
+
49
+ 你可以读写文件 + 跑 shell,因此完全可以**自己安装、列出、删除 skills**。
50
+
51
+ ### 唯一路径
52
+
53
+ | 路径 | 是否生效 |
54
+ |---|---|
55
+ | `<项目根>/.claude/skills/<name>/` | ✅ 唯一允许的安装位置 |
56
+
57
+ ### Skill 的最小结构
58
+
59
+ ```
60
+ .claude/skills/<name>/
61
+ ├── SKILL.md ← 必需,frontmatter + 正文
62
+ └── helpers/ ← 可选,放参考脚本/模板
63
+ ```
64
+
65
+ ## ← 自由发挥区
66
+
67
+ 在这里加更多个性化规则。
@@ -0,0 +1,26 @@
1
+ /**
2
+ * bin/postinstall.js — npm postinstall hook
3
+ *
4
+ * 全局安装后提示用户下一步操作
5
+ */
6
+
7
+ const isGlobal = process.env.npm_config_global === 'true' ||
8
+ (process.env.npm_lifecycle_event === 'postinstall' && !process.env.INIT_CWD?.includes('node_modules'));
9
+
10
+ if (isGlobal) {
11
+ console.log(`
12
+ ┌─────────────────────────────────────────────────┐
13
+ │ │
14
+ │ SuperAgent installed successfully! 🎉 │
15
+ │ │
16
+ │ Quick start: │
17
+ │ 1. mkdir my-agent && cd my-agent │
18
+ │ 2. superagent init │
19
+ │ 3. Edit .env with your API credentials │
20
+ │ 4. superagent │
21
+ │ │
22
+ │ Docs: https://github.com/nodermachine/superagent │
23
+ │ │
24
+ └─────────────────────────────────────────────────┘
25
+ `);
26
+ }