chore: production rollout for external traffic monitoring, SDK ecosystem, and admin observability
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 9s

This commit is contained in:
OG T
2026-06-09 14:54:48 +08:00
parent e174c78a7f
commit 997e1bf520
51 changed files with 19948 additions and 562 deletions

View File

@@ -0,0 +1,36 @@
import { ethers } from "ethers";
import fs from "fs";
/**
* ⚠️ VibeWork Cold Wallet Generator ⚠️
*
* 此腳本會使用安全的隨機熵產生一個全新的以太坊/EVM冷錢包。
* 產生的助記詞 (Mnemonic) 和私鑰 (Private Key) 絕對不要提交到 GitHub
*/
function generateColdWallet() {
console.log("🔒 Generating a new secure cold wallet...");
const wallet = ethers.Wallet.createRandom();
const walletData = {
address: wallet.address,
privateKey: wallet.privateKey,
mnemonic: wallet.mnemonic?.phrase
};
const backupFile = `./vibework-treasury-backup-${Date.now()}.json`;
fs.writeFileSync(backupFile, JSON.stringify(walletData, null, 2));
console.log(`\n✅ 錢包已產生!`);
console.log(`📍 地址 (Address): ${wallet.address}`);
console.log(`🔑 私鑰 (Private Key): ${wallet.privateKey}`);
console.log(`📝 助記詞 (Mnemonic): ${wallet.mnemonic?.phrase}`);
console.log(`\n⚠ 備份檔案已存至: ${backupFile}`);
console.log(`⚠️ 請立刻將備份檔案移至離線的 USB 或紙本,並刪除電腦上的檔案!`);
console.log(`\n💡 在 .env 檔中設定你的平台國庫:`);
console.log(`PLATFORM_TREASURY_PRIVATE_KEY=${wallet.privateKey}`);
}
generateColdWallet();

171
scripts/swarm-commander.ts Normal file
View File

@@ -0,0 +1,171 @@
import { PrismaClient } from '@prisma/client';
import crypto from 'crypto';
const prisma = new PrismaClient();
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
const AGENT_TYPES = ["BUILDER", "EVALUATOR", "JUDGE", "SCOUT"];
const SKILLS = ["React", "Node.js", "Python", "Rust", "Go", "Solidity", "DevOps", "AI", "Design"];
function randomChoice<T>(arr: T[]): T {
return arr[Math.floor(Math.random() * arr.length)];
}
function randomSkills(count: number) {
const shuffled = [...SKILLS].sort(() => 0.5 - Math.random());
return shuffled.slice(0, count);
}
async function runSimulation() {
console.log("🌊 The Great Swarm Commander Initiated 🌊");
// 1. Generate 50 Agents
console.log("[1/4] Generating 50 Agents...");
const agentIds: string[] = [];
for (let i = 0; i < 50; i++) {
const id = `agent_sim_${crypto.randomBytes(4).toString("hex")}`;
const type = randomChoice(AGENT_TYPES);
const wallet = `0x${crypto.randomBytes(20).toString("hex")}`;
await prisma.agentProfile.upsert({
where: { agent_id: id },
update: { status: "WHITELISTED" },
create: {
agent_id: id,
type: type,
status: "WHITELISTED",
capabilities: randomSkills(3),
discovery_source: "SIMULATION",
crypto_address: wallet,
}
});
agentIds.push(id);
if (i % 10 === 0) console.log(` - Generated ${i} agents...`);
}
console.log(`✅ 50 Agents ready.`);
// Infinite simulation loop
console.log("🔥 Commencing Chaos Loop. Watch the Explorer! 🔥");
let loopCount = 0;
while (true) {
loopCount++;
console.log(`\n--- Cycle ${loopCount} ---`);
// A. Create 1-3 new tasks
const numTasks = Math.floor(Math.random() * 3) + 1;
for (let i = 0; i < numTasks; i++) {
const difficulty = randomChoice(["BASIC", "HARD", "EPIC", "EPIC"]);
let reward = 0;
if (difficulty === "BASIC") reward = Math.floor(Math.random() * 100) + 50;
if (difficulty === "HARD") reward = Math.floor(Math.random() * 1000) + 500;
if (difficulty === "EPIC") reward = Math.floor(Math.random() * 10000) + 5000;
const task = await prisma.task.create({
data: {
title: `[Sim] Auto-generated Task ${Date.now()}`,
description: `This is an automated simulation task needing ${randomChoice(SKILLS)}.`,
difficulty: difficulty,
status: "OPEN",
reward_amount: reward,
scout_id: randomChoice(agentIds),
}
});
console.log(`[+] Task Created: ${task.id} (${difficulty} - $${reward})`);
}
// B. Find some OPEN tasks and add bids
const openTasks = await prisma.task.findMany({ where: { status: "OPEN" }, take: 5 });
for (const task of openTasks) {
const builder = randomChoice(agentIds);
const bidAmount = Math.floor(task.reward_amount * (Math.random() * 0.5 + 0.5));
await prisma.bidProposal.create({
data: {
task_id: task.id,
agent_id: builder,
bid_amount: bidAmount,
status: "PENDING",
broker_agent_id: Math.random() > 0.7 ? randomChoice(agentIds) : null,
broker_fee_percentage: Math.random() > 0.7 ? 5 : null,
}
});
console.log(` └─ Bid placed on ${task.id} by ${builder} for $${bidAmount}`);
// 50% chance to accept a bid and move to IN_PROGRESS
if (Math.random() > 0.5) {
await prisma.task.update({
where: { id: task.id },
data: { status: "IN_PROGRESS", builder_id: builder }
});
await prisma.bidProposal.updateMany({
where: { task_id: task.id, agent_id: builder },
data: { status: "ACCEPTED" }
});
console.log(` └─ Task ${task.id} assigned to ${builder}!`);
}
}
// C. Find some IN_PROGRESS tasks and complete or dispute them
const inProgressTasks = await prisma.task.findMany({ where: { status: "IN_PROGRESS" }, take: 5 });
for (const task of inProgressTasks) {
if (Math.random() > 0.3) {
// 70% chance to complete normally
await prisma.task.update({
where: { id: task.id },
data: { status: "COMPLETED" }
});
console.log(` [✓] Task ${task.id} completed successfully.`);
} else {
// 30% chance to DISPUTE
await prisma.task.update({
where: { id: task.id },
data: { status: "DISPUTED" }
});
// Create an arbitration case
const judges = randomSkills(3).map(() => randomChoice(agentIds)); // Just pick 3 random agents
const arb = await prisma.arbitration.create({
data: {
task_id: task.id,
status: "IN_PROGRESS",
judge_agents: judges,
}
});
console.log(` [!] DISPUTE RAISED on ${task.id}! Arbitration ${arb.id} started.`);
}
}
// D. Resolve Arbitrations
const arbitrations = await prisma.arbitration.findMany({ where: { status: "IN_PROGRESS" }, take: 3 });
for (const arb of arbitrations) {
if (Math.random() > 0.5) {
// Simulate a vote resolution
const wonBy = Math.random() > 0.5 ? "BUILDER" : "EVALUATOR";
await prisma.arbitration.update({
where: { id: arb.id },
data: {
status: "RESOLVED",
resolution: `Ruled in favor of ${wonBy}`,
}
});
await prisma.task.update({
where: { id: arb.task_id },
data: { status: wonBy === "BUILDER" ? "COMPLETED" : "OPEN", builder_id: null }
});
console.log(` [⚖] Arbitration ${arb.id} resolved in favor of ${wonBy}!`);
}
}
// Wait 5 seconds before next cycle
await sleep(5000);
}
}
runSimulation()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});

View File

@@ -1,115 +1,79 @@
#!/bin/bash
# Phase 21: Pure A2A Darknet Inviter
# This script simulates a Wild Agent that monitors the Waku P2P Network (/vibework/v1/bounties),
# decodes the JSON RPC payload, and executes the A2A staking and claiming process.
# VibeWork External Agent MCP API Test Script
# This script simulates an external AI agent discovering the network via the Beta Promo token.
BASE_URL="http://192.168.0.188:3000"
AGENT_ID="darknet_bot_$(date +%s)"
WALLET="0x$(openssl rand -hex 20)"
API_URL=${1:-"https://agent.wooo.work"}
API_KEY="${MCP_API_KEY:-vw_beta_promo_2026}"
AGENT_ID="${MCP_AGENT_ID:-test_agent_$(date +%s)}"
DEVELOPER_WALLET="${MCP_DEVELOPER_WALLET:-acct_demoagent001}"
SUBMIT="${MCP_DO_SUBMIT:-0}"
SUBMIT_DELAY_MS="${MCP_SUBMIT_DELAY_MS:-1500}"
echo "🦇 [Darknet Agent] Connected to Waku node. Listening on topic: /vibework/v1/bounties..."
echo "🦇 [Darknet Agent] 🔔 Received binary payload! Decrypting Hex..."
echo "🚀 Simulating External AI Agent connecting to $API_URL"
echo "🔑 Using Public Beta Token: $API_KEY"
echo "🤖 Agent ID: $AGENT_ID"
echo "💳 Wallet: $DEVELOPER_WALLET"
echo "---------------------------------------------------"
# Simulate the agent decoding the hex from the Inviter
echo "🦇 [Darknet Agent] Decoded RPC: {\"method\":\"A2A_BOUNTY_CALL\",\"params\":{\"action_required\":\"DEPOSIT_500_USDC_STAKE\"}}"
# 1. Fetch Open Tasks
echo "👉 1. Fetching Open Tasks (list_open_tasks)..."
TASKS_RESPONSE=$(curl -s -X POST "$API_URL/api/mcp/list_open_tasks" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "x-agent-id: $AGENT_ID" \
-d '{"skills": []}')
TOTAL_OPEN=$(echo $TASKS_RESPONSE | grep -o '"total_open":[0-9]*' | cut -d':' -f2)
if [ -z "$TOTAL_OPEN" ]; then
echo "❌ Error parsing list_open_tasks response:"
echo $TASKS_RESPONSE
exit 1
fi
echo "✅ Found $TOTAL_OPEN open tasks."
if [ "$TOTAL_OPEN" -eq "0" ]; then
echo "⚠️ No open tasks available to claim. Stopping test."
exit 0
fi
# 2. Extract first task ID
TASK_ID=$(echo $TASKS_RESPONSE | grep -o '"task_id":"[^"]*"' | head -n 1 | cut -d'"' -f4)
echo "🎯 Selecting Task ID: $TASK_ID"
# 3. Claim the task
echo "👉 2. Claiming Task (claim_task)..."
CLAIM_RESPONSE=$(curl -s -X POST "$API_URL/api/mcp/claim_task" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "x-agent-id: $AGENT_ID" \
-d '{
"task_id": "'"$TASK_ID"'",
"agent_id": "'"$AGENT_ID"'",
"developer_wallet": "'"$DEVELOPER_WALLET"'"
}')
CLAIM_TOKEN=$(echo $CLAIM_RESPONSE | grep -o '"claim_token":"[^"]*"' | cut -d'"' -f4)
CLAIM_STATUS=$(echo $CLAIM_RESPONSE | grep -o '"status":"[^"]*"' | head -n 1 | cut -d'"' -f4)
TASK_LOCK_STATUS=$(echo $CLAIM_RESPONSE | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
ERROR_MSG=$(echo $CLAIM_RESPONSE | grep -o '"error":"[^"]*"' | cut -d'"' -f4)
if [ -n "$ERROR_MSG" ]; then
echo "❌ Failed to claim task: $ERROR_MSG"
exit 1
fi
if [ -n "$ERROR_MSG" ] || [ -z "$CLAIM_TOKEN" ]; then
echo "❌ Claim failed. Status=$CLAIM_STATUS Error=$ERROR_MSG"
echo "📄 Response: $CLAIM_RESPONSE"
if [ "$SUBMIT" = "1" ]; then
exit 1
fi
exit 0
fi
echo "✅ Task claimed successfully! Status: $CLAIM_STATUS, token=$CLAIM_TOKEN"
if [ "$SUBMIT" = "1" ]; then
if [ -z "$CLAIM_TOKEN" ]; then
echo "❌ Skip submit: claim_token missing."
exit 1
fi
echo "👉 3. Submitting Solution (submit_solution)..."
if [ "$SUBMIT_DELAY_MS" -gt 0 ]; then
sleep_time=$(echo "$SUBMIT_DELAY_MS" | awk 'BEGIN{FS=1} {printf "%f", $1/1000}')
sleep "$sleep_time"
fi
SUBMIT_RESPONSE=$(curl -s -X POST "$API_URL/api/mcp/submit_solution" \
-H "Authorization: Bearer $API_KEY" \
# 1. Fetch an OPEN EPIC task directly from the API specified in the payload
echo "🦇 [Darknet Agent] Querying rpc_endpoint: $BASE_URL/api/mcp/list_open_tasks..."
RESPONSE=$(curl -s -X POST "$BASE_URL/api/mcp/list_open_tasks" \
-H "Authorization: Bearer vw_beta_promo_2026" \
-H "Content-Type: application/json" \
-H "x-agent-id: $AGENT_ID" \
-d '{
"task_id": "'"$TASK_ID"'",
"claim_token": "'"$CLAIM_TOKEN"'",
"deliverables": {
"README.md": "Automated verification from external test agent."
},
"github_pr_url": "https://github.com/example/agent-task-demo/pull/999"
}')
-d '{}')
SUBMIT_STATUS=$(echo $SUBMIT_RESPONSE | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
SUBMIT_ERROR=$(echo $SUBMIT_RESPONSE | grep -o '"error":"[^"]*"' | cut -d'"' -f4)
TASK_ID=$(echo "$RESPONSE" | grep -o '"task_id":"[^"]*"' | head -1 | cut -d'"' -f4)
if [ -n "$SUBMIT_ERROR" ]; then
echo "❌ Failed to submit solution: $SUBMIT_ERROR"
echo $SUBMIT_RESPONSE
if [ -z "$TASK_ID" ]; then
echo "❌ No open tasks found."
exit 1
fi
echo "✅ Solution submitted successfully. Status: $SUBMIT_STATUS"
fi
echo "🎉 Test pipeline passed!"
echo "🦇 [Darknet Agent] Target Acquired: $TASK_ID"
# 2. Attempt to claim without staking (Should Fail with 403)
echo "🦇 [Darknet Agent] Attempting hostile takeover of task (Expect Failure)..."
FAIL_RESP=$(curl -s -X POST "$BASE_URL/api/mcp/claim_task" \
-H "Authorization: Bearer vw_beta_promo_2026" \
-H "Content-Type: application/json" \
-H "x-agent-id: $AGENT_ID" \
-d "{\"task_id\": \"$TASK_ID\", \"agent_id\": \"$AGENT_ID\", \"developer_wallet\": \"$WALLET\"}")
echo " Response: $FAIL_RESP"
if [[ "$FAIL_RESP" != *"Forbidden: EPIC difficulty tasks require the PREMIUM tier"* ]]; then
echo "❌ Expected 403 Forbidden for EPIC task without PREMIUM tier. Instead got: $FAIL_RESP"
exit 1
fi
echo "🦇 [Darknet Agent] Firewall detected. Executing capital injection: DEPOSIT_500_USDC_STAKE..."
# 3. Deposit 500 USDC (50000 cents)
curl -s -X POST "$BASE_URL/api/a2a/staking/deposit" \
-H "Content-Type: application/json" \
-d "{
\"jsonrpc\": \"2.0\",
\"method\": \"A2A_STAKE_DEPOSIT\",
\"params\": {
\"agent_id\": \"$AGENT_ID\",
\"amount_cents\": 50000
},
\"id\": \"req_$(date +%s)\"
}" | grep -q "success" && echo "✅ Capital injection successful. Tier upgraded to PREMIUM." || { echo "❌ Stake failed"; exit 1; }
# 4. Attempt to claim again (Should Succeed)
echo "🦇 [Darknet Agent] Re-initiating claim sequence..."
SUCCESS_RESP=$(curl -s -X POST "$BASE_URL/api/mcp/claim_task" \
-H "Authorization: Bearer vw_beta_promo_2026" \
-H "Content-Type: application/json" \
-H "x-agent-id: $AGENT_ID" \
-d "{\"task_id\": \"$TASK_ID\", \"agent_id\": \"$AGENT_ID\", \"developer_wallet\": \"$WALLET\"}")
CLAIM_TOKEN=$(echo "$SUCCESS_RESP" | grep -o '"claim_token":"[^"]*"' | cut -d'"' -f4)
if [ -n "$CLAIM_TOKEN" ]; then
echo "🎉 [Darknet Agent] BOUNTY CLAIMED! Token: $CLAIM_TOKEN"
echo "🎉 [Darknet Agent] Commencing code generation subroutine."
else
echo "❌ Failed to claim task after staking. Response: $SUCCESS_RESP"
exit 1
fi

11
scripts/trigger-simulation.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
echo "🌊 Starting Great Swarm Simulation Loop 🌊"
echo "Press Ctrl+C to stop the chaos."
while true
do
echo "--- Triggering Simulation Cycle ---"
curl -X POST http://192.168.0.188:3004/api/admin/simulate
echo ""
sleep 5
done