@peonai/swarm 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.
Files changed (61) hide show
  1. package/.dockerignore +6 -0
  2. package/Dockerfile +9 -0
  3. package/README.md +29 -0
  4. package/app/api/health/route.ts +2 -0
  5. package/app/api/v1/admin/agents/[id]/route.ts +12 -0
  6. package/app/api/v1/admin/agents/route.ts +31 -0
  7. package/app/api/v1/admin/audit/route.ts +23 -0
  8. package/app/api/v1/admin/cleanup/route.ts +21 -0
  9. package/app/api/v1/admin/export/route.ts +15 -0
  10. package/app/api/v1/admin/history/route.ts +23 -0
  11. package/app/api/v1/admin/profile/route.ts +23 -0
  12. package/app/api/v1/admin/settings/route.ts +44 -0
  13. package/app/api/v1/auth/route.ts +5 -0
  14. package/app/api/v1/memory/route.ts +105 -0
  15. package/app/api/v1/persona/[agentId]/route.ts +13 -0
  16. package/app/api/v1/persona/me/route.ts +12 -0
  17. package/app/api/v1/profile/observe/route.ts +34 -0
  18. package/app/api/v1/profile/route.ts +72 -0
  19. package/app/api/v1/reflect/route.ts +96 -0
  20. package/app/globals.css +190 -0
  21. package/app/i18n.ts +161 -0
  22. package/app/layout.tsx +12 -0
  23. package/app/page.tsx +561 -0
  24. package/docker-compose.yml +34 -0
  25. package/docs/DEBATE-ROUND1.md +244 -0
  26. package/docs/DEBATE-ROUND2.md +158 -0
  27. package/docs/REQUIREMENTS.md +162 -0
  28. package/docs/docs.html +272 -0
  29. package/docs/index.html +228 -0
  30. package/docs/script.js +103 -0
  31. package/docs/style.css +418 -0
  32. package/lib/auth.ts +63 -0
  33. package/lib/db.ts +63 -0
  34. package/lib/embedding.ts +29 -0
  35. package/lib/schema.ts +134 -0
  36. package/mcp-server.ts +56 -0
  37. package/next-env.d.ts +6 -0
  38. package/next.config.ts +5 -0
  39. package/package.json +34 -0
  40. package/packages/cli/README.md +33 -0
  41. package/packages/cli/bin/swarm.mjs +274 -0
  42. package/packages/cli/package.json +10 -0
  43. package/postcss.config.mjs +2 -0
  44. package/skill/CLAUDE.md +40 -0
  45. package/skill/CODEX.md +43 -0
  46. package/skill/GEMINI.md +38 -0
  47. package/skill/IFLOW.md +38 -0
  48. package/skill/OPENCODE.md +38 -0
  49. package/skill/swarm-ai-skill/SKILL.md +74 -0
  50. package/skill/swarm-ai-skill/env.sh +4 -0
  51. package/skill/swarm-ai-skill/scripts/bootstrap.sh +21 -0
  52. package/skill/swarm-ai-skill/scripts/env.sh +4 -0
  53. package/skill/swarm-ai-skill/scripts/env.sh.example +3 -0
  54. package/skill/swarm-ai-skill/scripts/memory-read.sh +8 -0
  55. package/skill/swarm-ai-skill/scripts/memory-write.sh +10 -0
  56. package/skill/swarm-ai-skill/scripts/observe.sh +9 -0
  57. package/skill/swarm-ai-skill/scripts/profile-read.sh +9 -0
  58. package/skill/swarm-ai-skill/scripts/profile-update.sh +9 -0
  59. package/skill/swarm-ai-skill/scripts/session-start.sh +19 -0
  60. package/tsconfig.json +21 -0
  61. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,38 @@
1
+ # Swarm AI Integration
2
+
3
+ You have access to a shared user profile API at `http://localhost:3777`. Use it to personalize responses and record what you learn.
4
+
5
+ ## Session Start
6
+
7
+ Read the user profile and use it as context:
8
+
9
+ ```bash
10
+ curl -s http://localhost:3777/api/v1/profile \
11
+ -H "Authorization: Bearer $SWARM_API_KEY"
12
+ ```
13
+
14
+ ## During Interaction
15
+
16
+ When you learn something new about the user, record it:
17
+
18
+ ```bash
19
+ curl -s -X POST http://localhost:3777/api/v1/profile/observe \
20
+ -H "Content-Type: application/json" \
21
+ -H "Authorization: Bearer $SWARM_API_KEY" \
22
+ -d '{"observations":[{"layer":"LAYER","key":"KEY","value":"VALUE","confidence":0.8}]}'
23
+ ```
24
+
25
+ Layers: `identity`, `work`, `preferences`, `context` (24h TTL).
26
+
27
+ ## Memory
28
+
29
+ ```bash
30
+ # Search
31
+ curl -s "http://localhost:3777/api/v1/memory?q=QUERY" -H "Authorization: Bearer $SWARM_API_KEY"
32
+
33
+ # Write
34
+ curl -s -X POST http://localhost:3777/api/v1/memory \
35
+ -H "Content-Type: application/json" \
36
+ -H "Authorization: Bearer $SWARM_API_KEY" \
37
+ -d '{"content":"CONTENT","tags":["tag1"]}'
38
+ ```
package/skill/IFLOW.md ADDED
@@ -0,0 +1,38 @@
1
+ # Swarm AI Integration
2
+
3
+ You have access to a shared user profile API at `http://localhost:3777`. Use it to personalize responses and record what you learn.
4
+
5
+ ## Session Start
6
+
7
+ Read the user profile and use it as context:
8
+
9
+ ```bash
10
+ curl -s http://localhost:3777/api/v1/profile \
11
+ -H "Authorization: Bearer $SWARM_API_KEY"
12
+ ```
13
+
14
+ ## During Interaction
15
+
16
+ When you learn something new about the user, record it:
17
+
18
+ ```bash
19
+ curl -s -X POST http://localhost:3777/api/v1/profile/observe \
20
+ -H "Content-Type: application/json" \
21
+ -H "Authorization: Bearer $SWARM_API_KEY" \
22
+ -d '{"observations":[{"layer":"LAYER","key":"KEY","value":"VALUE","confidence":0.8}]}'
23
+ ```
24
+
25
+ Layers: `identity`, `work`, `preferences`, `context` (24h TTL).
26
+
27
+ ## Memory
28
+
29
+ ```bash
30
+ # Search
31
+ curl -s "http://localhost:3777/api/v1/memory?q=QUERY" -H "Authorization: Bearer $SWARM_API_KEY"
32
+
33
+ # Write
34
+ curl -s -X POST http://localhost:3777/api/v1/memory \
35
+ -H "Content-Type: application/json" \
36
+ -H "Authorization: Bearer $SWARM_API_KEY" \
37
+ -d '{"content":"CONTENT","tags":["tag1"]}'
38
+ ```
@@ -0,0 +1,38 @@
1
+ # Swarm AI Integration
2
+
3
+ You have access to a shared user profile API at `http://localhost:3777`. Use it to personalize responses and record what you learn.
4
+
5
+ ## Session Start
6
+
7
+ Read the user profile and use it as context:
8
+
9
+ ```bash
10
+ curl -s http://localhost:3777/api/v1/profile \
11
+ -H "Authorization: Bearer $SWARM_API_KEY"
12
+ ```
13
+
14
+ ## During Interaction
15
+
16
+ When you learn something new about the user, record it:
17
+
18
+ ```bash
19
+ curl -s -X POST http://localhost:3777/api/v1/profile/observe \
20
+ -H "Content-Type: application/json" \
21
+ -H "Authorization: Bearer $SWARM_API_KEY" \
22
+ -d '{"observations":[{"layer":"LAYER","key":"KEY","value":"VALUE","confidence":0.8}]}'
23
+ ```
24
+
25
+ Layers: `identity`, `work`, `preferences`, `context` (24h TTL).
26
+
27
+ ## Memory
28
+
29
+ ```bash
30
+ # Search
31
+ curl -s "http://localhost:3777/api/v1/memory?q=QUERY" -H "Authorization: Bearer $SWARM_API_KEY"
32
+
33
+ # Write
34
+ curl -s -X POST http://localhost:3777/api/v1/memory \
35
+ -H "Content-Type: application/json" \
36
+ -H "Authorization: Bearer $SWARM_API_KEY" \
37
+ -d '{"content":"CONTENT","tags":["tag1"]}'
38
+ ```
@@ -0,0 +1,74 @@
1
+ # Swarm AI — Agent Skill
2
+
3
+ 跨 Agent 用户画像共享。让每个 agent 都了解用户,不用反复教育。
4
+
5
+ ## 安装
6
+
7
+ ### 1. 配置 API Key
8
+
9
+ 编辑 `scripts/env.sh`:
10
+ ```bash
11
+ export SWARM_API_URL="http://localhost:3777"
12
+ export SWARM_API_KEY="your_api_key_here"
13
+ ```
14
+
15
+ ### 2. 接入你的 Agent 平台
16
+
17
+ #### OpenClaw
18
+ 在 `AGENTS.md` 的「Every Session」部分加一行:
19
+ ```
20
+ - Run `bash ~/.openclaw/workspace/skills/swarm-ai-skill/scripts/bootstrap.sh` to load user profile context
21
+ ```
22
+
23
+ #### Claude Code
24
+ 在项目根目录 `CLAUDE.md` 加:
25
+ ```
26
+ At the start of every task, run: bash /path/to/skills/swarm-ai-skill/scripts/bootstrap.sh
27
+ When you learn something new about the user, run: bash /path/to/skills/swarm-ai-skill/scripts/observe.sh '[{"key":"...","value":"..."}]'
28
+ ```
29
+
30
+ #### Cursor
31
+ 在 `.cursorrules` 加:
32
+ ```
33
+ At session start, execute: bash /path/to/skills/swarm-ai-skill/scripts/bootstrap.sh
34
+ Use the output as user context for personalization.
35
+ ```
36
+
37
+ #### 其他平台
38
+ 任何能执行 shell 的 agent,在 system prompt 里加:
39
+ ```
40
+ Before responding, run `scripts/bootstrap.sh` and use the output as user context.
41
+ ```
42
+
43
+ ## 脚本
44
+
45
+ `scripts/` 目录下,全部 bash,零依赖(只需 curl):
46
+
47
+ | 脚本 | 用途 | 调用时机 |
48
+ |------|------|----------|
49
+ | `bootstrap.sh` | 读画像,输出上下文文本 | 会话开始 |
50
+ | `profile-read.sh [layer] [tag]` | 读画像 JSON | 需要查具体字段 |
51
+ | `profile-update.sh <layer> <json>` | 更新画像 | 确认了新的用户信息 |
52
+ | `observe.sh <json_array>` | 提交观察 | 发现用户偏好/习惯 |
53
+ | `memory-read.sh [query]` | 搜索记忆 | 需要历史上下文 |
54
+ | `memory-write.sh <content> [tags]` | 写入记忆 | 记录重要事件 |
55
+
56
+ ## 什么时候该写入
57
+
58
+ Agent 应该在以下场景调用 `observe.sh`:
59
+ - 用户明确表达偏好(「我喜欢用 TypeScript」)
60
+ - 用户纠正了你的假设(「不是 Vue,是 React」)
61
+ - 发现用户的工作习惯(沟通风格、时区、角色)
62
+ - 项目上下文变化(新项目、技术栈变更)
63
+
64
+ **不要**记录:敏感信息、临时情绪、一次性指令。
65
+
66
+ ## 画像结构
67
+
68
+ 按 layer 组织,名称自由定义:
69
+ - `identity` — 姓名、语言、时区
70
+ - `work` — 技术栈、角色、项目
71
+ - `communication` — 沟通风格
72
+ - `context` — 当前状态(默认 24h 过期)
73
+
74
+ 每条有 `confidence`(0-1),observe 时高 confidence 覆盖低的,不同 agent 的观察互不干扰。
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ # Swarm AI Skill - env config
3
+ export SWARM_API_URL="http://localhost:3777"
4
+ export SWARM_API_KEY="${SWARM_API_KEY:-}"
@@ -0,0 +1,21 @@
1
+ #!/bin/bash
2
+ # swarm-ai bootstrap — 会话开始时调用,输出用户画像上下文
3
+ # 输出纯文本,直接注入 system prompt / 上下文
4
+ set -euo pipefail
5
+ source "$(dirname "$0")/env.sh"
6
+
7
+ PROFILE=$(curl -sf "${SWARM_API_URL}/api/v1/profile" \
8
+ -H "Authorization: Bearer ${SWARM_API_KEY}" 2>/dev/null || echo '{}')
9
+
10
+ # 空画像不输出
11
+ [ "$PROFILE" = "{}" ] && exit 0
12
+
13
+ cat <<EOF
14
+ [Swarm AI — User Profile Context]
15
+ The following is known about the user from cross-agent shared memory.
16
+ Use this to personalize your responses. When you learn new information
17
+ about the user, call the observe script to record it.
18
+
19
+ $PROFILE
20
+ [End Profile Context]
21
+ EOF
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ # Swarm AI env config — edit these values for your agent
3
+ export SWARM_API_URL="${SWARM_API_URL:-http://localhost:3777}"
4
+ export SWARM_API_KEY="${SWARM_API_KEY:-REPLACE_ME}"
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ export SWARM_API_URL="${SWARM_API_URL:-http://localhost:3777}"
3
+ export SWARM_API_KEY="${SWARM_API_KEY:-REPLACE_ME}"
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ # swarm-ai memory search/list
3
+ # Usage: ./memory-read.sh [search_query]
4
+ set -euo pipefail
5
+ source "$(dirname "$0")/env.sh"
6
+ Q="${1:-}"
7
+ [ "$Q" ] && P="?q=$Q" || P=""
8
+ curl -sf "${SWARM_API_URL}/api/v1/memory${P}" -H "Authorization: Bearer ${SWARM_API_KEY}"
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ # swarm-ai memory write
3
+ # Usage: ./memory-write.sh <content> [tags_comma_separated]
4
+ set -euo pipefail
5
+ source "$(dirname "$0")/env.sh"
6
+ TAGS="[]"
7
+ [ "${2:-}" ] && TAGS="[$(echo "$2" | sed 's/[^,]*/\"&\"/g')]"
8
+ curl -sf -X POST "${SWARM_API_URL}/api/v1/memory" \
9
+ -H "Content-Type: application/json" -H "Authorization: Bearer ${SWARM_API_KEY}" \
10
+ -d "{\"content\":$(echo "$1" | python3 -c 'import json,sys;print(json.dumps(sys.stdin.read().strip()))'),\"tags\":$TAGS}"
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ # swarm-ai observe
3
+ # Usage: ./observe.sh <json_observations>
4
+ # Example: ./observe.sh '[{"key":"mood","value":"focused","confidence":0.8}]'
5
+ set -euo pipefail
6
+ source "$(dirname "$0")/env.sh"
7
+ curl -sf -X POST "${SWARM_API_URL}/api/v1/profile/observe" \
8
+ -H "Content-Type: application/json" -H "Authorization: Bearer ${SWARM_API_KEY}" \
9
+ -d "{\"observations\":$1}"
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ # swarm-ai profile read
3
+ # Usage: ./profile-read.sh [layer] [tag]
4
+ set -euo pipefail
5
+ source "$(dirname "$0")/env.sh"
6
+ PARAMS=""
7
+ [ "${1:-}" ] && PARAMS="?layer=$1"
8
+ [ "${2:-}" ] && PARAMS="${PARAMS:+$PARAMS&}${PARAMS:+}${PARAMS:-?}tag=$2"
9
+ curl -sf "${SWARM_API_URL}/api/v1/profile${PARAMS}" -H "Authorization: Bearer ${SWARM_API_KEY}"
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ # swarm-ai profile update
3
+ # Usage: ./profile-update.sh <layer> <json_entries>
4
+ # Example: ./profile-update.sh work '{"tech_stack":{"value":["TS","React"],"tags":["dev"]}}'
5
+ set -euo pipefail
6
+ source "$(dirname "$0")/env.sh"
7
+ curl -sf -X PATCH "${SWARM_API_URL}/api/v1/profile" \
8
+ -H "Content-Type: application/json" -H "Authorization: Bearer ${SWARM_API_KEY}" \
9
+ -d "{\"layer\":\"$1\",\"entries\":$2}"
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+ # swarm-ai session-start — 会话开始时调用
3
+ # 记录会话启动时间,用于后续 reflect 计算"本次会话"的记忆范围
4
+ set -euo pipefail
5
+ source "$(dirname "$0")/env.sh"
6
+
7
+ SESSION_FILE="${SWARM_SESSION_FILE:-/tmp/swarm-session-${SWARM_AGENT_ID:-unknown}.json}"
8
+
9
+ # 写入会话起始标记
10
+ cat > "$SESSION_FILE" <<EOF
11
+ {
12
+ "agent_id": "${SWARM_AGENT_ID:-unknown}",
13
+ "started_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
14
+ "pid": $$
15
+ }
16
+ EOF
17
+
18
+ # 同时输出画像上下文(保持 bootstrap 的原有功能)
19
+ "$(dirname "$0")/bootstrap.sh"
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "preserve",
15
+ "incremental": true,
16
+ "plugins": [{ "name": "next" }],
17
+ "paths": { "@/*": ["./*"] }
18
+ },
19
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
20
+ "exclude": ["node_modules"]
21
+ }