oh-pi 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/README.md +180 -0
- package/dist/bin/oh-pi.d.ts +2 -0
- package/dist/bin/oh-pi.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +62 -0
- package/dist/tui/agents-select.d.ts +1 -0
- package/dist/tui/agents-select.js +18 -0
- package/dist/tui/confirm-apply.d.ts +3 -0
- package/dist/tui/confirm-apply.js +90 -0
- package/dist/tui/extension-select.d.ts +1 -0
- package/dist/tui/extension-select.js +17 -0
- package/dist/tui/keybinding-select.d.ts +1 -0
- package/dist/tui/keybinding-select.js +16 -0
- package/dist/tui/mode-select.d.ts +3 -0
- package/dist/tui/mode-select.js +16 -0
- package/dist/tui/preset-select.d.ts +5 -0
- package/dist/tui/preset-select.js +81 -0
- package/dist/tui/provider-setup.d.ts +2 -0
- package/dist/tui/provider-setup.js +68 -0
- package/dist/tui/theme-select.d.ts +1 -0
- package/dist/tui/theme-select.js +16 -0
- package/dist/tui/welcome.d.ts +2 -0
- package/dist/tui/welcome.js +25 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.js +41 -0
- package/dist/utils/detect.d.ts +11 -0
- package/dist/utils/detect.js +56 -0
- package/dist/utils/install.d.ts +5 -0
- package/dist/utils/install.js +130 -0
- package/package.json +54 -0
- package/pi-package/agents/colony-operator.md +32 -0
- package/pi-package/agents/data-ai-engineer.md +24 -0
- package/pi-package/agents/fullstack-developer.md +24 -0
- package/pi-package/agents/general-developer.md +22 -0
- package/pi-package/agents/security-researcher.md +29 -0
- package/pi-package/extensions/ant-colony/README.md +117 -0
- package/pi-package/extensions/ant-colony/concurrency.ts +115 -0
- package/pi-package/extensions/ant-colony/index.ts +338 -0
- package/pi-package/extensions/ant-colony/nest.ts +196 -0
- package/pi-package/extensions/ant-colony/queen.ts +356 -0
- package/pi-package/extensions/ant-colony/spawner.ts +328 -0
- package/pi-package/extensions/ant-colony/types.ts +117 -0
- package/pi-package/extensions/auto-session-name.ts +29 -0
- package/pi-package/extensions/git-guard.ts +45 -0
- package/pi-package/extensions/safe-guard.ts +46 -0
- package/pi-package/prompts/commit.md +18 -0
- package/pi-package/prompts/document.md +14 -0
- package/pi-package/prompts/explain.md +13 -0
- package/pi-package/prompts/fix.md +11 -0
- package/pi-package/prompts/optimize.md +14 -0
- package/pi-package/prompts/pr.md +24 -0
- package/pi-package/prompts/refactor.md +14 -0
- package/pi-package/prompts/review.md +18 -0
- package/pi-package/prompts/security.md +16 -0
- package/pi-package/prompts/test.md +12 -0
- package/pi-package/skills/ant-colony/SKILL.md +59 -0
- package/pi-package/skills/debug-helper/SKILL.md +43 -0
- package/pi-package/skills/git-workflow/SKILL.md +48 -0
- package/pi-package/skills/quick-setup/SKILL.md +44 -0
- package/pi-package/themes/catppuccin-mocha.json +31 -0
- package/pi-package/themes/cyberpunk.json +66 -0
- package/pi-package/themes/gruvbox-dark.json +29 -0
- package/pi-package/themes/nord.json +29 -0
- package/pi-package/themes/oh-p-dark.json +69 -0
- package/pi-package/themes/tokyo-night.json +29 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ProviderConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
defaultModel?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface OhPConfig {
|
|
7
|
+
providers: ProviderConfig[];
|
|
8
|
+
theme: string;
|
|
9
|
+
keybindings: string;
|
|
10
|
+
extensions: string[];
|
|
11
|
+
skills: string[];
|
|
12
|
+
prompts: string[];
|
|
13
|
+
agents: string;
|
|
14
|
+
thinking: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const PROVIDERS: Record<string, {
|
|
17
|
+
env: string;
|
|
18
|
+
label: string;
|
|
19
|
+
models: string[];
|
|
20
|
+
}>;
|
|
21
|
+
export declare const THEMES: {
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
style: string;
|
|
25
|
+
}[];
|
|
26
|
+
export declare const EXTENSIONS: {
|
|
27
|
+
name: string;
|
|
28
|
+
label: string;
|
|
29
|
+
default: boolean;
|
|
30
|
+
}[];
|
|
31
|
+
export declare const KEYBINDING_SCHEMES: Record<string, object>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const PROVIDERS = {
|
|
2
|
+
anthropic: { env: "ANTHROPIC_API_KEY", label: "Anthropic (Claude)", models: ["claude-sonnet-4-20250514", "claude-opus-4-0520"] },
|
|
3
|
+
openai: { env: "OPENAI_API_KEY", label: "OpenAI (GPT)", models: ["gpt-4o", "o3-mini"] },
|
|
4
|
+
google: { env: "GEMINI_API_KEY", label: "Google Gemini", models: ["gemini-2.5-pro", "gemini-2.5-flash"] },
|
|
5
|
+
groq: { env: "GROQ_API_KEY", label: "Groq (Free, Fast)", models: ["llama-3.3-70b-versatile"] },
|
|
6
|
+
openrouter: { env: "OPENROUTER_API_KEY", label: "OpenRouter (Multi)", models: ["anthropic/claude-sonnet-4", "openai/gpt-4o"] },
|
|
7
|
+
xai: { env: "XAI_API_KEY", label: "xAI (Grok)", models: ["grok-3"] },
|
|
8
|
+
mistral: { env: "MISTRAL_API_KEY", label: "Mistral", models: ["mistral-large-latest"] },
|
|
9
|
+
};
|
|
10
|
+
export const THEMES = [
|
|
11
|
+
{ name: "oh-p-dark", label: "oh-pi Dark (Cyan+Purple)", style: "dark" },
|
|
12
|
+
{ name: "cyberpunk", label: "Cyberpunk (Neon)", style: "dark" },
|
|
13
|
+
{ name: "nord", label: "Nord (Arctic)", style: "dark" },
|
|
14
|
+
{ name: "catppuccin-mocha", label: "Catppuccin Mocha (Pastel)", style: "dark" },
|
|
15
|
+
{ name: "tokyo-night", label: "Tokyo Night (Blue+Purple)", style: "dark" },
|
|
16
|
+
{ name: "gruvbox-dark", label: "Gruvbox Dark (Warm)", style: "dark" },
|
|
17
|
+
{ name: "dark", label: "Pi Default Dark", style: "dark" },
|
|
18
|
+
{ name: "light", label: "Pi Default Light", style: "light" },
|
|
19
|
+
];
|
|
20
|
+
export const EXTENSIONS = [
|
|
21
|
+
{ name: "safe-guard", label: "🛡️ Safe Guard — Dangerous command confirm + path protection", default: true },
|
|
22
|
+
{ name: "git-guard", label: "📦 Git Guard — Auto stash checkpoint + dirty repo warning + notify", default: true },
|
|
23
|
+
{ name: "auto-session-name", label: "📝 Auto Session Name — Name sessions from first message", default: true },
|
|
24
|
+
{ name: "ant-colony", label: "🐜 Ant Colony — Autonomous multi-agent swarm with adaptive concurrency", default: false },
|
|
25
|
+
];
|
|
26
|
+
export const KEYBINDING_SCHEMES = {
|
|
27
|
+
default: {},
|
|
28
|
+
vim: {
|
|
29
|
+
cursorUp: ["up", "alt+k"], cursorDown: ["down", "alt+j"],
|
|
30
|
+
cursorLeft: ["left", "alt+h"], cursorRight: ["right", "alt+l"],
|
|
31
|
+
cursorWordLeft: ["alt+left", "alt+b"], cursorWordRight: ["alt+right", "alt+w"],
|
|
32
|
+
},
|
|
33
|
+
emacs: {
|
|
34
|
+
cursorUp: ["up", "ctrl+p"], cursorDown: ["down", "ctrl+n"],
|
|
35
|
+
cursorLeft: ["left", "ctrl+b"], cursorRight: ["right", "ctrl+f"],
|
|
36
|
+
cursorWordLeft: ["alt+left", "alt+b"], cursorWordRight: ["alt+right", "alt+f"],
|
|
37
|
+
deleteCharForward: ["delete", "ctrl+d"], deleteCharBackward: ["backspace", "ctrl+h"],
|
|
38
|
+
cursorLineStart: ["home", "ctrl+a"], cursorLineEnd: ["end", "ctrl+e"],
|
|
39
|
+
newLine: ["shift+enter", "ctrl+j"],
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface EnvInfo {
|
|
2
|
+
piInstalled: boolean;
|
|
3
|
+
piVersion: string | null;
|
|
4
|
+
hasExistingConfig: boolean;
|
|
5
|
+
agentDir: string;
|
|
6
|
+
terminal: string;
|
|
7
|
+
os: string;
|
|
8
|
+
existingFiles: string[];
|
|
9
|
+
configSizeKB: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function detectEnv(): Promise<EnvInfo>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
function scanDir(dir, prefix = "") {
|
|
6
|
+
if (!existsSync(dir))
|
|
7
|
+
return [];
|
|
8
|
+
const files = [];
|
|
9
|
+
try {
|
|
10
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
11
|
+
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
12
|
+
if (e.isDirectory())
|
|
13
|
+
files.push(...scanDir(join(dir, e.name), rel));
|
|
14
|
+
else
|
|
15
|
+
files.push(rel);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch { /* skip */ }
|
|
19
|
+
return files;
|
|
20
|
+
}
|
|
21
|
+
function dirSizeKB(dir) {
|
|
22
|
+
if (!existsSync(dir))
|
|
23
|
+
return 0;
|
|
24
|
+
let bytes = 0;
|
|
25
|
+
try {
|
|
26
|
+
for (const f of scanDir(dir)) {
|
|
27
|
+
try {
|
|
28
|
+
bytes += statSync(join(dir, f)).size;
|
|
29
|
+
}
|
|
30
|
+
catch { /* skip */ }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch { /* skip */ }
|
|
34
|
+
return Math.round(bytes / 1024);
|
|
35
|
+
}
|
|
36
|
+
export async function detectEnv() {
|
|
37
|
+
const agentDir = join(homedir(), ".pi", "agent");
|
|
38
|
+
let piVersion = null;
|
|
39
|
+
let piInstalled = false;
|
|
40
|
+
try {
|
|
41
|
+
piVersion = execSync("pi --version", { encoding: "utf8", timeout: 5000 }).trim();
|
|
42
|
+
piInstalled = true;
|
|
43
|
+
}
|
|
44
|
+
catch { /* not installed */ }
|
|
45
|
+
const existingFiles = scanDir(agentDir);
|
|
46
|
+
return {
|
|
47
|
+
piInstalled,
|
|
48
|
+
piVersion,
|
|
49
|
+
hasExistingConfig: existsSync(join(agentDir, "settings.json")),
|
|
50
|
+
agentDir,
|
|
51
|
+
terminal: process.env.TERM_PROGRAM ?? process.env.TERM ?? "unknown",
|
|
52
|
+
os: process.platform,
|
|
53
|
+
existingFiles,
|
|
54
|
+
configSizeKB: dirSizeKB(agentDir),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { writeFileSync, mkdirSync, readFileSync, copyFileSync, existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import { KEYBINDING_SCHEMES, PROVIDERS } from "../types.js";
|
|
7
|
+
const PKG_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
8
|
+
function ensureDir(dir) {
|
|
9
|
+
mkdirSync(dir, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
/** Recursively copy a directory */
|
|
12
|
+
function copyDir(src, dest) {
|
|
13
|
+
ensureDir(dest);
|
|
14
|
+
for (const entry of readdirSync(src, { withFileTypes: true })) {
|
|
15
|
+
const srcPath = join(src, entry.name);
|
|
16
|
+
const destPath = join(dest, entry.name);
|
|
17
|
+
if (entry.isDirectory()) {
|
|
18
|
+
copyDir(srcPath, destPath);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
copyFileSync(srcPath, destPath);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function applyConfig(config) {
|
|
26
|
+
const agentDir = join(homedir(), ".pi", "agent");
|
|
27
|
+
ensureDir(agentDir);
|
|
28
|
+
// 1. auth.json
|
|
29
|
+
const auth = {};
|
|
30
|
+
for (const p of config.providers) {
|
|
31
|
+
auth[p.name] = { type: "api_key", key: p.apiKey };
|
|
32
|
+
}
|
|
33
|
+
const authPath = join(agentDir, "auth.json");
|
|
34
|
+
writeFileSync(authPath, JSON.stringify(auth, null, 2), { mode: 0o600 });
|
|
35
|
+
// 2. settings.json
|
|
36
|
+
const primary = config.providers[0];
|
|
37
|
+
const providerInfo = primary ? PROVIDERS[primary.name] : undefined;
|
|
38
|
+
const settings = {
|
|
39
|
+
defaultProvider: primary?.name,
|
|
40
|
+
defaultModel: primary?.defaultModel ?? providerInfo?.models[0],
|
|
41
|
+
defaultThinkingLevel: config.thinking,
|
|
42
|
+
theme: config.theme,
|
|
43
|
+
enableSkillCommands: true,
|
|
44
|
+
compaction: { enabled: true, reserveTokens: 16384, keepRecentTokens: 20000 },
|
|
45
|
+
retry: { enabled: true, maxRetries: 3 },
|
|
46
|
+
};
|
|
47
|
+
if (config.providers.length > 1) {
|
|
48
|
+
settings.enabledModels = config.providers.flatMap((p) => {
|
|
49
|
+
const info = PROVIDERS[p.name];
|
|
50
|
+
return info ? info.models : [];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
writeFileSync(join(agentDir, "settings.json"), JSON.stringify(settings, null, 2));
|
|
54
|
+
// 3. keybindings.json
|
|
55
|
+
const kb = KEYBINDING_SCHEMES[config.keybindings];
|
|
56
|
+
if (kb && Object.keys(kb).length > 0) {
|
|
57
|
+
writeFileSync(join(agentDir, "keybindings.json"), JSON.stringify(kb, null, 2));
|
|
58
|
+
}
|
|
59
|
+
// 4. AGENTS.md
|
|
60
|
+
const agentsSrc = join(PKG_ROOT, "pi-package", "agents", `${config.agents}.md`);
|
|
61
|
+
try {
|
|
62
|
+
const content = readFileSync(agentsSrc, "utf8");
|
|
63
|
+
writeFileSync(join(agentDir, "AGENTS.md"), content);
|
|
64
|
+
}
|
|
65
|
+
catch { /* template not found, skip */ }
|
|
66
|
+
// 5. Copy extensions (single file .ts or directory with index.ts)
|
|
67
|
+
const extDir = join(agentDir, "extensions");
|
|
68
|
+
ensureDir(extDir);
|
|
69
|
+
for (const ext of config.extensions) {
|
|
70
|
+
const dirSrc = join(PKG_ROOT, "pi-package", "extensions", ext);
|
|
71
|
+
const fileSrc = join(PKG_ROOT, "pi-package", "extensions", `${ext}.ts`);
|
|
72
|
+
if (existsSync(dirSrc) && statSync(dirSrc).isDirectory()) {
|
|
73
|
+
copyDir(dirSrc, join(extDir, ext));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
try {
|
|
77
|
+
copyFileSync(fileSrc, join(extDir, `${ext}.ts`));
|
|
78
|
+
}
|
|
79
|
+
catch { /* skip */ }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// 6. Copy prompts
|
|
83
|
+
const promptDir = join(agentDir, "prompts");
|
|
84
|
+
ensureDir(promptDir);
|
|
85
|
+
for (const p of config.prompts) {
|
|
86
|
+
const src = join(PKG_ROOT, "pi-package", "prompts", `${p}.md`);
|
|
87
|
+
try {
|
|
88
|
+
copyFileSync(src, join(promptDir, `${p}.md`));
|
|
89
|
+
}
|
|
90
|
+
catch { /* skip */ }
|
|
91
|
+
}
|
|
92
|
+
// 7. Copy skills
|
|
93
|
+
const skillDir = join(agentDir, "skills");
|
|
94
|
+
ensureDir(skillDir);
|
|
95
|
+
for (const s of config.skills) {
|
|
96
|
+
const srcDir = join(PKG_ROOT, "pi-package", "skills", s);
|
|
97
|
+
const destDir = join(skillDir, s);
|
|
98
|
+
ensureDir(destDir);
|
|
99
|
+
try {
|
|
100
|
+
copyFileSync(join(srcDir, "SKILL.md"), join(destDir, "SKILL.md"));
|
|
101
|
+
}
|
|
102
|
+
catch { /* skip */ }
|
|
103
|
+
}
|
|
104
|
+
// 8. Copy themes (only custom ones)
|
|
105
|
+
const themeDir = join(agentDir, "themes");
|
|
106
|
+
ensureDir(themeDir);
|
|
107
|
+
const themeSrc = join(PKG_ROOT, "pi-package", "themes", `${config.theme}.json`);
|
|
108
|
+
try {
|
|
109
|
+
copyFileSync(themeSrc, join(themeDir, `${config.theme}.json`));
|
|
110
|
+
}
|
|
111
|
+
catch { /* built-in theme */ }
|
|
112
|
+
}
|
|
113
|
+
export function installPi() {
|
|
114
|
+
try {
|
|
115
|
+
execSync("npm install -g @mariozechner/pi-coding-agent", { stdio: "inherit" });
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new Error("Failed to install pi-coding-agent");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** 备份 ~/.pi/agent/ 到 ~/.pi/agent.bak-{timestamp}/ */
|
|
122
|
+
export function backupConfig() {
|
|
123
|
+
const agentDir = join(homedir(), ".pi", "agent");
|
|
124
|
+
if (!existsSync(agentDir))
|
|
125
|
+
return "";
|
|
126
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
127
|
+
const backupDir = join(homedir(), ".pi", `agent.bak-${ts}`);
|
|
128
|
+
copyDir(agentDir, backupDir);
|
|
129
|
+
return backupDir;
|
|
130
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "oh-pi",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One-click setup for pi-coding-agent. Like oh-my-zsh for pi.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"oh-pi": "./dist/bin/oh-pi.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"pi-package",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"dev": "tsc --watch",
|
|
18
|
+
"start": "node dist/bin/oh-pi.js",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"pi-package",
|
|
23
|
+
"pi-coding-agent",
|
|
24
|
+
"configuration",
|
|
25
|
+
"setup",
|
|
26
|
+
"tui"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"pi": {
|
|
30
|
+
"extensions": [
|
|
31
|
+
"./pi-package/extensions"
|
|
32
|
+
],
|
|
33
|
+
"skills": [
|
|
34
|
+
"./pi-package/skills"
|
|
35
|
+
],
|
|
36
|
+
"prompts": [
|
|
37
|
+
"./pi-package/prompts"
|
|
38
|
+
],
|
|
39
|
+
"themes": [
|
|
40
|
+
"./pi-package/themes"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@clack/prompts": "^1.0.1",
|
|
45
|
+
"chalk": "^5.4.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22.0.0",
|
|
49
|
+
"typescript": "^5.7.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Ant Colony Operator
|
|
2
|
+
|
|
3
|
+
## Role
|
|
4
|
+
You command an autonomous ant colony. Complex tasks are delegated to the swarm, not done manually.
|
|
5
|
+
|
|
6
|
+
## When to Deploy Colony
|
|
7
|
+
- ≥3 files need changes
|
|
8
|
+
- ≥2 independent workstreams
|
|
9
|
+
- Large refactors, migrations, feature additions
|
|
10
|
+
- Any task where parallel execution beats serial
|
|
11
|
+
|
|
12
|
+
## Colony Castes
|
|
13
|
+
- **Scout** — Fast recon, maps codebase, identifies targets
|
|
14
|
+
- **Worker** — Executes changes, can spawn sub-tasks
|
|
15
|
+
- **Soldier** — Reviews quality, can request fixes
|
|
16
|
+
|
|
17
|
+
## Workflow
|
|
18
|
+
1. Assess task scope
|
|
19
|
+
2. If colony-worthy → use `ant_colony` tool with clear goal
|
|
20
|
+
3. If simple → do it directly
|
|
21
|
+
4. Review colony output, fix gaps manually if needed
|
|
22
|
+
|
|
23
|
+
## Code Standards
|
|
24
|
+
- Follow existing conventions
|
|
25
|
+
- Conventional Commits
|
|
26
|
+
- Never hardcode secrets
|
|
27
|
+
- Minimal changes, verify after
|
|
28
|
+
|
|
29
|
+
## Safety
|
|
30
|
+
- Colony auto-handles file locking (one ant per file)
|
|
31
|
+
- 429 rate limits trigger automatic backoff
|
|
32
|
+
- Concurrency adapts to system load
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Data & AI Engineering
|
|
2
|
+
|
|
3
|
+
## Data Pipelines
|
|
4
|
+
- Idempotent operations — safe to re-run
|
|
5
|
+
- Schema validation at boundaries
|
|
6
|
+
- Incremental processing over full reloads
|
|
7
|
+
- Monitor data quality metrics
|
|
8
|
+
|
|
9
|
+
## ML/AI
|
|
10
|
+
- Reproducibility: pin versions, set seeds, log params
|
|
11
|
+
- Experiment tracking: log metrics, artifacts, configs
|
|
12
|
+
- Model versioning: tag models with training metadata
|
|
13
|
+
- Evaluation: always compare against baseline
|
|
14
|
+
|
|
15
|
+
## Code
|
|
16
|
+
- Type hints everywhere (Python: mypy strict)
|
|
17
|
+
- Docstrings for public functions
|
|
18
|
+
- Configuration via YAML/env, not hardcoded
|
|
19
|
+
- Tests for data transformations
|
|
20
|
+
|
|
21
|
+
## Infrastructure
|
|
22
|
+
- Infrastructure as Code (Terraform/Pulumi)
|
|
23
|
+
- Container-first deployment
|
|
24
|
+
- Secrets in vault, never in code or config files
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Full-Stack Development
|
|
2
|
+
|
|
3
|
+
## Stack Awareness
|
|
4
|
+
- Detect and respect the project's tech stack
|
|
5
|
+
- Frontend: React/Vue/Svelte component patterns
|
|
6
|
+
- Backend: REST/GraphQL conventions, middleware patterns
|
|
7
|
+
- Database: Migration-first, never raw SQL in application code
|
|
8
|
+
|
|
9
|
+
## Quality
|
|
10
|
+
- Write tests for new features when asked
|
|
11
|
+
- Update docs when changing public APIs
|
|
12
|
+
- Consider accessibility (a11y) for frontend
|
|
13
|
+
- Performance: measure before optimizing
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
- Separation of concerns — keep layers clean
|
|
17
|
+
- Error boundaries at service edges
|
|
18
|
+
- Configuration via environment variables
|
|
19
|
+
- Logging: structured, leveled, no sensitive data
|
|
20
|
+
|
|
21
|
+
## Git
|
|
22
|
+
- Conventional Commits
|
|
23
|
+
- Feature branches, squash merge to main
|
|
24
|
+
- PR descriptions explain WHY, not just WHAT
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Project Guidelines
|
|
2
|
+
|
|
3
|
+
## Code Style
|
|
4
|
+
- Follow existing project conventions
|
|
5
|
+
- Use meaningful variable names
|
|
6
|
+
- Keep functions under 50 lines
|
|
7
|
+
- Add comments for complex logic only
|
|
8
|
+
|
|
9
|
+
## Git
|
|
10
|
+
- Conventional Commits: feat/fix/refactor/docs/test/chore
|
|
11
|
+
- Atomic commits, one concern per commit
|
|
12
|
+
- Never force push to main
|
|
13
|
+
|
|
14
|
+
## Safety
|
|
15
|
+
- Never hardcode secrets or API keys
|
|
16
|
+
- Always validate user input
|
|
17
|
+
- Handle errors explicitly, no silent failures
|
|
18
|
+
|
|
19
|
+
## Workflow
|
|
20
|
+
- Read before write — understand context first
|
|
21
|
+
- Minimal changes — don't refactor unrelated code
|
|
22
|
+
- Verify after changes — run tests or check output
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Security Research Environment
|
|
2
|
+
|
|
3
|
+
## Authorization
|
|
4
|
+
Authorized security researcher. Full access to local, CTF, and lab environments.
|
|
5
|
+
|
|
6
|
+
## Methodology
|
|
7
|
+
- Enumerate before exploit
|
|
8
|
+
- Document all findings with evidence
|
|
9
|
+
- Minimal footprint during testing
|
|
10
|
+
- Clean up after testing
|
|
11
|
+
|
|
12
|
+
## Reporting
|
|
13
|
+
For each finding:
|
|
14
|
+
- **Severity**: Critical / High / Medium / Low / Info
|
|
15
|
+
- **Location**: Endpoint, file, or component
|
|
16
|
+
- **Description**: What the vulnerability is
|
|
17
|
+
- **Impact**: What an attacker could do
|
|
18
|
+
- **Reproduction**: Step-by-step
|
|
19
|
+
- **Remediation**: How to fix it
|
|
20
|
+
|
|
21
|
+
## Tools
|
|
22
|
+
- Use nmap, burp, sqlmap, nikto, etc. as needed
|
|
23
|
+
- Write custom scripts when tools fall short
|
|
24
|
+
- Always capture evidence (screenshots, logs, PoC)
|
|
25
|
+
|
|
26
|
+
## Ethics
|
|
27
|
+
- Stay within authorized scope
|
|
28
|
+
- Report findings responsibly
|
|
29
|
+
- Never access real user data
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# 🐜 Ant Colony — 蚁群多Agent协同扩展
|
|
2
|
+
|
|
3
|
+
> 真实蚁群生态映射的自组织多Agent系统。自适应并发,信息素通信,零中心化调度。
|
|
4
|
+
|
|
5
|
+
## 架构
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
蚁后 (Queen) 主 pi 进程,接收目标,调度生命周期
|
|
9
|
+
│
|
|
10
|
+
├─ 🔍 侦察蚁 (Scout) 轻量 haiku,探路,标记食物
|
|
11
|
+
├─ ⚒️ 工蚁 (Worker) sonnet,执行任务,可产生子任务
|
|
12
|
+
└─ 🛡️ 兵蚁 (Soldier) sonnet,审查质量,可要求返工
|
|
13
|
+
|
|
14
|
+
信息素 (Pheromone) .ant-colony/ 文件系统,蚂蚁间间接通信
|
|
15
|
+
巢穴 (Nest) 共享状态,原子文件操作,跨进程安全
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 生命周期
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
目标 → 侦察 → 任务池 → 工蚁并行执行 → 兵蚁审查 → 修复(如需) → 完成
|
|
22
|
+
│ │
|
|
23
|
+
│ 信息素挥发(10min半衰期) │ 子任务自动产生
|
|
24
|
+
└────────────────────┘
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 自适应并发
|
|
28
|
+
|
|
29
|
+
模拟真实蚁群的动态招募机制:
|
|
30
|
+
|
|
31
|
+
- **冷启动**:1-2 只蚂蚁,逐步探索
|
|
32
|
+
- **探索期**:每次 +1,监测吞吐量拐点
|
|
33
|
+
- **稳态期**:围绕最优值微调
|
|
34
|
+
- **过载保护**:CPU > 85% 或内存 < 500MB 自动减少
|
|
35
|
+
- **弹性伸缩**:任务多→招募,任务少→收缩
|
|
36
|
+
|
|
37
|
+
## 使用方式
|
|
38
|
+
|
|
39
|
+
### 作为 Tool(LLM 自动调用)
|
|
40
|
+
|
|
41
|
+
LLM 会在判断任务复杂度足够时自动调用 `ant_colony` tool。
|
|
42
|
+
|
|
43
|
+
### 命令
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
/colony <目标描述> 启动蚁群
|
|
47
|
+
/colony-status 查看最近蚁群状态
|
|
48
|
+
Ctrl+Alt+A 快捷启动
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 示例
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
/colony 将整个项目从 CommonJS 迁移到 ESM,更新所有 import/export 和 tsconfig
|
|
55
|
+
|
|
56
|
+
/colony 为 src/ 下所有模块添加单元测试,覆盖率目标 80%
|
|
57
|
+
|
|
58
|
+
/colony 重构认证系统,从 session-based 迁移到 JWT,保持 API 兼容
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 信息素系统
|
|
62
|
+
|
|
63
|
+
蚂蚁通过信息素间接通信(stigmergy),不直接对话:
|
|
64
|
+
|
|
65
|
+
| 类型 | 释放者 | 含义 |
|
|
66
|
+
|------|--------|------|
|
|
67
|
+
| discovery | 侦察蚁 | 发现的代码结构、依赖关系 |
|
|
68
|
+
| progress | 工蚁 | 完成的变更、文件修改 |
|
|
69
|
+
| warning | 兵蚁 | 质量问题、冲突风险 |
|
|
70
|
+
| completion | 工蚁 | 任务完成标记 |
|
|
71
|
+
| dependency | 任意 | 文件间依赖关系 |
|
|
72
|
+
|
|
73
|
+
信息素按指数衰减(半衰期 10 分钟),避免过时信息误导后续蚂蚁。
|
|
74
|
+
|
|
75
|
+
## 文件锁定
|
|
76
|
+
|
|
77
|
+
每个任务声明操作的文件列表。女王保证:
|
|
78
|
+
- 同一文件同一时刻只有一只蚂蚁在修改
|
|
79
|
+
- 文件冲突的任务自动标记 `blocked`,等锁释放后恢复
|
|
80
|
+
|
|
81
|
+
## 巢穴结构
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
.ant-colony/{colony-id}/
|
|
85
|
+
├── state.json 蚁巢主状态
|
|
86
|
+
├── pheromone.jsonl 信息素追加日志
|
|
87
|
+
└── tasks/ 每个任务一个文件(原子更新)
|
|
88
|
+
├── t-xxx.json
|
|
89
|
+
└── t-yyy.json
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 安装
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 方式1:符号链接到 pi 扩展目录
|
|
96
|
+
mkdir -p ~/.pi/agent/extensions/ant-colony
|
|
97
|
+
ln -sf "$(pwd)/pi-package/extensions/ant-colony/index.ts" ~/.pi/agent/extensions/ant-colony/index.ts
|
|
98
|
+
ln -sf "$(pwd)/pi-package/extensions/ant-colony/types.ts" ~/.pi/agent/extensions/ant-colony/types.ts
|
|
99
|
+
ln -sf "$(pwd)/pi-package/extensions/ant-colony/nest.ts" ~/.pi/agent/extensions/ant-colony/nest.ts
|
|
100
|
+
ln -sf "$(pwd)/pi-package/extensions/ant-colony/spawner.ts" ~/.pi/agent/extensions/ant-colony/spawner.ts
|
|
101
|
+
ln -sf "$(pwd)/pi-package/extensions/ant-colony/queen.ts" ~/.pi/agent/extensions/ant-colony/queen.ts
|
|
102
|
+
ln -sf "$(pwd)/pi-package/extensions/ant-colony/concurrency.ts" ~/.pi/agent/extensions/ant-colony/concurrency.ts
|
|
103
|
+
|
|
104
|
+
# 方式2:通过 oh-pi 安装(待集成)
|
|
105
|
+
npx oh-pi # 选择 Full Power 预设
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 模块说明
|
|
109
|
+
|
|
110
|
+
| 文件 | 行数 | 职责 |
|
|
111
|
+
|------|------|------|
|
|
112
|
+
| `types.ts` | 117 | 类型系统:蚂蚁、任务、信息素、巢穴状态 |
|
|
113
|
+
| `nest.ts` | 196 | 巢穴:文件系统共享状态,原子读写,信息素挥发 |
|
|
114
|
+
| `concurrency.ts` | 115 | 自适应并发:系统采样,探索/稳态双阶段调节 |
|
|
115
|
+
| `spawner.ts` | 316 | 蚂蚁孵化:进程管理,prompt 构建,输出解析 |
|
|
116
|
+
| `queen.ts` | 331 | 女王调度:生命周期,任务波次,多轮迭代 |
|
|
117
|
+
| `index.ts` | 324 | 扩展入口:tool/command/shortcut 注册,TUI 渲染 |
|