@ia-ccun/code-agent-cli 0.0.59-beta.5 → 0.0.59-beta.6
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/config/agent/extensions/aicode-provider-scope.ts +388 -0
- package/config/agent/skills/agent-browser/LICENSE +201 -0
- package/config/agent/skills/agent-browser/SKILL.md +55 -0
- package/config/agent/skills/codebase-design/DEEPENING.md +37 -0
- package/config/agent/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/config/agent/skills/{chroma → codebase-design}/LICENSE +1 -1
- package/config/agent/skills/codebase-design/SKILL.md +118 -0
- package/config/agent/skills/codebase-design/agents/openai.yaml +3 -0
- package/config/agent/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/config/agent/skills/domain-modeling/GLOSSARY-FORMAT.md +61 -0
- package/config/agent/skills/{fireworks-tech-graph → domain-modeling}/LICENSE +1 -1
- package/config/agent/skills/domain-modeling/SKILL.md +78 -0
- package/config/agent/skills/domain-modeling/agents/openai.yaml +3 -0
- package/config/agent/skills/frontend-design/SKILL.md +55 -26
- package/config/agent/skills/grill-with-docs/LICENSE +21 -0
- package/config/agent/skills/grill-with-docs/SKILL.md +21 -0
- package/config/agent/skills/grill-with-docs/agents/openai.yaml +5 -0
- package/config/agent/skills/grilling/LICENSE +21 -0
- package/config/agent/skills/grilling/SKILL.md +34 -0
- package/config/agent/skills/grilling/agents/openai.yaml +3 -0
- package/config/agent/skills/tdd/LICENSE +21 -0
- package/config/agent/skills/tdd/SKILL.md +42 -0
- package/config/agent/skills/tdd/agents/openai.yaml +3 -0
- package/config/agent/skills/tdd/mocking.md +59 -0
- package/config/agent/skills/tdd/tests.md +77 -0
- package/config/agent/skills/ui-taste/CHECKSUMS.sha256 +25 -0
- package/config/agent/skills/{milvus-skill → ui-taste}/LICENSE +12 -23
- package/config/agent/skills/ui-taste/MANIFEST.json +256 -0
- package/config/agent/skills/ui-taste/MODIFICATIONS.md +23 -0
- package/config/agent/skills/ui-taste/NOTICE +74 -0
- package/config/agent/skills/ui-taste/SKILL.md +90 -0
- package/config/agent/skills/ui-taste/agents/openai.yaml +4 -0
- package/config/agent/skills/ui-taste/reference/anti-slop-craft.md +138 -0
- package/config/agent/skills/ui-taste/reference/audit.md +71 -0
- package/config/agent/skills/ui-taste/reference/audit.native.md +78 -0
- package/config/agent/skills/ui-taste/reference/craft.md +48 -0
- package/config/agent/skills/ui-taste/reference/distill.md +20 -0
- package/config/agent/skills/ui-taste/reference/image-assets.md +31 -0
- package/config/agent/skills/ui-taste/reference/ios.md +35 -0
- package/config/agent/skills/ui-taste/reference/mobile-controls.md +37 -0
- package/config/agent/skills/ui-taste/reference/mobile-state-performance.md +34 -0
- package/config/agent/skills/ui-taste/reference/native-verification.md +33 -0
- package/config/agent/skills/ui-taste/reference/new-work.md +87 -0
- package/config/agent/skills/ui-taste/reference/operate.md +37 -0
- package/config/agent/skills/ui-taste/reference/overdrive.md +65 -0
- package/config/agent/skills/ui-taste/reference/polish.md +63 -0
- package/config/agent/skills/ui-taste/reference/research.md +45 -0
- package/config/agent/skills/ui-taste/references/uizze-image-to-ui.md +77 -0
- package/config/agent/skills/ui-taste/references/uizze-reference-policy.md +27 -0
- package/config/agent/skills/ui-taste/references/uizze-visual-verification.md +62 -0
- package/config/agent/skills/ui-taste/scripts/verify-visual-evidence.mjs +108 -0
- package/package.json +5 -5
- package/config/agent/skills/chroma/chroma-local/SKILL.md +0 -165
- package/config/agent/skills/chroma/chroma-local/cli.md +0 -48
- package/config/agent/skills/chroma/chroma-local/data-model.md +0 -103
- package/config/agent/skills/chroma/chroma-local/error-handling/python.md +0 -166
- package/config/agent/skills/chroma/chroma-local/error-handling/typescript.md +0 -231
- package/config/agent/skills/chroma/chroma-local/local-chroma/python.md +0 -95
- package/config/agent/skills/chroma/chroma-local/local-chroma/typescript.md +0 -101
- package/config/agent/skills/chroma/chroma-local/metadata/python.md +0 -154
- package/config/agent/skills/chroma/chroma-local/metadata/typescript.md +0 -153
- package/config/agent/skills/chroma/chroma-local/querying/python.md +0 -147
- package/config/agent/skills/chroma/chroma-local/querying/typescript.md +0 -157
- package/config/agent/skills/chroma/chroma-local/regex/python.md +0 -69
- package/config/agent/skills/chroma/chroma-local/regex/typescript.md +0 -71
- package/config/agent/skills/chroma/chroma-local/understanding-a-codebase.md +0 -80
- package/config/agent/skills/chroma/chroma-local/updating-deleting/python.md +0 -159
- package/config/agent/skills/chroma/chroma-local/updating-deleting/typescript.md +0 -228
- package/config/agent/skills/find-skills/SKILL.md +0 -137
- package/config/agent/skills/fireworks-tech-graph/README.md +0 -528
- package/config/agent/skills/fireworks-tech-graph/README.zh.md +0 -499
- package/config/agent/skills/fireworks-tech-graph/SKILL.md +0 -538
- package/config/agent/skills/fireworks-tech-graph/agentloop-core.svg +0 -101
- package/config/agent/skills/fireworks-tech-graph/agents/openai.yaml +0 -4
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style1-flat.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style2-dark.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style3-blueprint.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style4-notion.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style5-glass.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style6-claude.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/assets/samples/sample-style7-openai.png +0 -0
- package/config/agent/skills/fireworks-tech-graph/fixtures/agent-memory-types-style4.json +0 -181
- package/config/agent/skills/fireworks-tech-graph/fixtures/api-flow-style7.json +0 -40
- package/config/agent/skills/fireworks-tech-graph/fixtures/mem0-style1.json +0 -297
- package/config/agent/skills/fireworks-tech-graph/fixtures/microservices-style3.json +0 -64
- package/config/agent/skills/fireworks-tech-graph/fixtures/multi-agent-style5.json +0 -45
- package/config/agent/skills/fireworks-tech-graph/fixtures/system-architecture-style6.json +0 -48
- package/config/agent/skills/fireworks-tech-graph/fixtures/tool-call-style2.json +0 -182
- package/config/agent/skills/fireworks-tech-graph/package.json +0 -42
- package/config/agent/skills/fireworks-tech-graph/references/icons.md +0 -406
- package/config/agent/skills/fireworks-tech-graph/references/style-1-flat-icon.md +0 -108
- package/config/agent/skills/fireworks-tech-graph/references/style-2-dark-terminal.md +0 -107
- package/config/agent/skills/fireworks-tech-graph/references/style-3-blueprint.md +0 -113
- package/config/agent/skills/fireworks-tech-graph/references/style-4-notion-clean.md +0 -94
- package/config/agent/skills/fireworks-tech-graph/references/style-5-glassmorphism.md +0 -125
- package/config/agent/skills/fireworks-tech-graph/references/style-6-claude-official.md +0 -209
- package/config/agent/skills/fireworks-tech-graph/references/style-7-openai.md +0 -215
- package/config/agent/skills/fireworks-tech-graph/references/style-diagram-matrix.md +0 -135
- package/config/agent/skills/fireworks-tech-graph/references/svg-layout-best-practices.md +0 -100
- package/config/agent/skills/fireworks-tech-graph/scripts/README.md +0 -244
- package/config/agent/skills/fireworks-tech-graph/scripts/generate-diagram.sh +0 -157
- package/config/agent/skills/fireworks-tech-graph/scripts/generate-from-template.py +0 -1556
- package/config/agent/skills/fireworks-tech-graph/scripts/test-all-styles.sh +0 -135
- package/config/agent/skills/fireworks-tech-graph/scripts/validate-svg.sh +0 -292
- package/config/agent/skills/fireworks-tech-graph/templates/agent-architecture.svg +0 -28
- package/config/agent/skills/fireworks-tech-graph/templates/architecture.svg +0 -23
- package/config/agent/skills/fireworks-tech-graph/templates/comparison-matrix.svg +0 -14
- package/config/agent/skills/fireworks-tech-graph/templates/data-flow.svg +0 -28
- package/config/agent/skills/fireworks-tech-graph/templates/er-diagram.svg +0 -21
- package/config/agent/skills/fireworks-tech-graph/templates/flowchart.svg +0 -21
- package/config/agent/skills/fireworks-tech-graph/templates/sequence.svg +0 -20
- package/config/agent/skills/fireworks-tech-graph/templates/state-machine.svg +0 -20
- package/config/agent/skills/fireworks-tech-graph/templates/timeline.svg +0 -19
- package/config/agent/skills/fireworks-tech-graph/templates/use-case.svg +0 -21
- package/config/agent/skills/hello/SKILL.md +0 -26
- package/config/agent/skills/librarian/SKILL.md +0 -199
- package/config/agent/skills/milvus-skill/README.md +0 -37
- package/config/agent/skills/milvus-skill/SKILL.md +0 -259
- package/config/agent/skills/milvus-skill/references/collection.md +0 -86
- package/config/agent/skills/milvus-skill/references/database.md +0 -24
- package/config/agent/skills/milvus-skill/references/index.md +0 -69
- package/config/agent/skills/milvus-skill/references/partition.md +0 -29
- package/config/agent/skills/milvus-skill/references/patterns.md +0 -150
- package/config/agent/skills/milvus-skill/references/user-role.md +0 -90
- package/config/agent/skills/milvus-skill/references/vector.md +0 -247
- package/config/agent/skills/pr/SKILL.md +0 -59
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: xujianjiang
|
|
3
|
+
* Provider Scope — 收敛 `/login` 与 `/model` 中可见的 provider(内网环境专用)
|
|
4
|
+
*
|
|
5
|
+
* ## 背景
|
|
6
|
+
*
|
|
7
|
+
* pi 内置 43 个 provider(openai / anthropic / google / openrouter …)。每个内置
|
|
8
|
+
* provider 都带 `envApiKeyAuth`,所以它们**永远**会出现在 `/login` 的 provider
|
|
9
|
+
* 选择器里;只要 `auth.json` 里存了某个 provider 的凭据,它也会连带出现在
|
|
10
|
+
* `/model` 的模型列表里。内网环境下这些外网 provider 根本不可达,留在选择器里
|
|
11
|
+
* 只会误导用户(用户选完才发现连不通)。
|
|
12
|
+
*
|
|
13
|
+
* ## 原理
|
|
14
|
+
*
|
|
15
|
+
* `ExtensionAPI.registerProvider(provider)` 的**原生 Provider 重载**会用传入的对象
|
|
16
|
+
* **整体替换** ModelRuntime 里的 provider(`nativeExtensionProviders` 的优先级高于
|
|
17
|
+
* `builtins`,并且 `refresh()` / `rebuildProviders()` 不会把它还原)。于是为每个
|
|
18
|
+
* 「不该出现的 provider」注册一个空壳:
|
|
19
|
+
*
|
|
20
|
+
* | 空壳字段 | 效果 |
|
|
21
|
+
* | --------------- | ------------------------------------------------------------- |
|
|
22
|
+
* | `auth: {}` | 既没有 `apiKey` 也没有 `oauth` → `/login` 不列出它 |
|
|
23
|
+
* | `getModels: []` | 没有任何模型 → `/model` 与 `pi --list-models` 都不列出它 |
|
|
24
|
+
*
|
|
25
|
+
* 只替换 **pi 内置 provider**;由其它扩展注册的内网 provider(如 `nucc`)不受影响。
|
|
26
|
+
* 若配置了严格白名单 `allow`,会话启动时还会把「其它扩展注册的 provider」
|
|
27
|
+
* (例如 pi 内置 llama.cpp 扩展注册的 `llama.cpp`)一并收敛,只保留白名单里的。
|
|
28
|
+
*
|
|
29
|
+
* ## 配置(优先级从高到低,三者都没配就完全不做任何事)
|
|
30
|
+
*
|
|
31
|
+
* 1. 环境变量 `AICODE_PROVIDER_ALLOWLIST="nucc,aicode"`(逗号 / 空格 / 分号分隔)
|
|
32
|
+
* 2. `<agentDir>/provider-scope.json` → `{ "allow": ["nucc"], "deny": ["openai"] }`
|
|
33
|
+
* 3. `<agentDir>/settings.json` → `{ "providerScope": { "allow": ["nucc"] } }`
|
|
34
|
+
*
|
|
35
|
+
* `<agentDir>` 由 `AICODE_CLI_CODING_AGENT_DIR` / `PI_CODING_AGENT_DIR` 决定,
|
|
36
|
+
* 缺省是 `~/.aicode-cli/agent`。
|
|
37
|
+
*
|
|
38
|
+
* `allow` 是严格白名单(白名单外的内置 provider 全部隐藏),`deny` 是黑名单。
|
|
39
|
+
* 两者都没配 → 本扩展是空操作,普通用户零影响。
|
|
40
|
+
*
|
|
41
|
+
* ## 双重保险(配置写错不会把 CLI 变砖)
|
|
42
|
+
*
|
|
43
|
+
* 1. **加载期自检**:白名单里的 provider 一个都不认识(既不是内置 provider、
|
|
44
|
+
* 不在 `models.json`、也没有 `auth.json` 凭据、扩展源码里也没提到)→ 直接
|
|
45
|
+
* 跳过收敛,保持所有 provider 可见。
|
|
46
|
+
* 2. **会话期自检**:`session_start` 时用真实的 provider 注册表再校验一次;
|
|
47
|
+
* 仍然一个都匹配不上 → 把加载期隐藏的内置 provider 恢复回来
|
|
48
|
+
* (`pi.unregisterProvider`),并给出告警。
|
|
49
|
+
*
|
|
50
|
+
* ## 已知边界
|
|
51
|
+
*
|
|
52
|
+
* - **models.json 里显式定义的 provider 隐藏不掉**:pi 会把它和内置 provider 重新
|
|
53
|
+
* compose,而 compose 出来的 auth 一定带 `apiKey` → 仍会出现在 `/login`。
|
|
54
|
+
* 内网部署请把外网 provider 从 `models.json` 里删掉。
|
|
55
|
+
* - 被隐藏 provider 的凭据仍留在 `auth.json`(只是不再出现在选择器里)。
|
|
56
|
+
* - `settings.json` 的 `defaultProvider` / `defaultModel` 必须指向未被隐藏的
|
|
57
|
+
* provider,否则会话选不到模型(本扩展会在 `session_start` 时告警并尝试自动切换)。
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
61
|
+
import { homedir } from "node:os";
|
|
62
|
+
import { join } from "node:path";
|
|
63
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
64
|
+
import type { Provider } from "@earendil-works/pi-ai";
|
|
65
|
+
import { getBuiltinProviders } from "@earendil-works/pi-ai/providers/all";
|
|
66
|
+
|
|
67
|
+
/** 环境变量名:逗号 / 空格 / 分号分隔的 provider id 白名单 */
|
|
68
|
+
const ENV_ALLOWLIST = "AICODE_PROVIDER_ALLOWLIST";
|
|
69
|
+
|
|
70
|
+
interface ProviderScope {
|
|
71
|
+
/** 严格白名单:只有这些 provider 可见 */
|
|
72
|
+
allow?: string[];
|
|
73
|
+
/** 黑名单:这些 provider 不可见 */
|
|
74
|
+
deny?: string[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface ResolvedScope {
|
|
78
|
+
scope: ProviderScope;
|
|
79
|
+
/** 配置来源,用于 `/provider-scope` 命令展示 */
|
|
80
|
+
source: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 把 "a, b c" / ["a","b"] 统一解析成字符串数组 */
|
|
84
|
+
function parseIdList(value: unknown): string[] {
|
|
85
|
+
if (typeof value === "string") {
|
|
86
|
+
return value
|
|
87
|
+
.split(/[\s,;]+/)
|
|
88
|
+
.map((item) => item.trim())
|
|
89
|
+
.filter((item) => item.length > 0);
|
|
90
|
+
}
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
return value
|
|
93
|
+
.filter((item): item is string => typeof item === "string")
|
|
94
|
+
.map((item) => item.trim())
|
|
95
|
+
.filter((item) => item.length > 0);
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 读取 JSON 文件,任何异常都当作「没有配置」 */
|
|
101
|
+
function readJsonFile(path: string): Record<string, unknown> | undefined {
|
|
102
|
+
try {
|
|
103
|
+
if (!existsSync(path)) return undefined;
|
|
104
|
+
const parsed: unknown = JSON.parse(readFileSync(path, "utf-8"));
|
|
105
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
|
|
106
|
+
return parsed as Record<string, unknown>;
|
|
107
|
+
} catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 解析 agent 目录(aicode 是 ~/.aicode-cli/agent,pi 是 ~/.pi/agent) */
|
|
113
|
+
function resolveAgentDir(): string {
|
|
114
|
+
const fromEnv = [
|
|
115
|
+
process.env.AICODE_CLI_CODING_AGENT_DIR,
|
|
116
|
+
process.env["AICODE-CLI_CODING_AGENT_DIR"],
|
|
117
|
+
process.env.PI_CODING_AGENT_DIR,
|
|
118
|
+
].find((value) => typeof value === "string" && value.trim().length > 0);
|
|
119
|
+
return fromEnv ?? join(homedir(), ".aicode-cli", "agent");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 读取 models.json 里显式定义的 provider id(这些 provider 无法用空壳隐藏) */
|
|
123
|
+
function readModelsConfigProviders(): string[] {
|
|
124
|
+
const modelsPath = join(resolveAgentDir(), "models.json");
|
|
125
|
+
const config = readJsonFile(modelsPath);
|
|
126
|
+
const providers = config?.providers;
|
|
127
|
+
if (!providers || typeof providers !== "object" || Array.isArray(providers)) return [];
|
|
128
|
+
return Object.keys(providers as Record<string, unknown>);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 读取 auth.json 里已有凭据的 provider id */
|
|
132
|
+
function readCredentialProviderIds(): string[] {
|
|
133
|
+
const auth = readJsonFile(join(resolveAgentDir(), "auth.json"));
|
|
134
|
+
return auth ? Object.keys(auth) : [];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 扫描扩展源码目录,看有没有哪个扩展文件里出现了这个 provider id
|
|
139
|
+
* (形如 `"nucc"`)。用于「provider 扩展已经装好、但还没登录(无凭据)」的场景。
|
|
140
|
+
*/
|
|
141
|
+
function extensionSourceMentions(providerId: string): boolean {
|
|
142
|
+
const dirs = [
|
|
143
|
+
join(resolveAgentDir(), "extensions"),
|
|
144
|
+
join(process.cwd(), ".pi", "extensions"),
|
|
145
|
+
];
|
|
146
|
+
const needle = `"${providerId}"`;
|
|
147
|
+
for (const dir of dirs) {
|
|
148
|
+
let entries: string[];
|
|
149
|
+
try {
|
|
150
|
+
entries = readdirSync(dir);
|
|
151
|
+
} catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
if (!/\.(ts|js|mjs)$/.test(entry)) continue;
|
|
156
|
+
try {
|
|
157
|
+
if (readFileSync(join(dir, entry), "utf-8").includes(needle)) return true;
|
|
158
|
+
} catch {
|
|
159
|
+
// 读不到就当没有
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** 从原始配置对象里抽出 allow / deny,两边都空则视为未配置 */
|
|
167
|
+
function normalizeScope(raw: Record<string, unknown>): ProviderScope | undefined {
|
|
168
|
+
const allow = parseIdList(raw.allow ?? raw.allowlist);
|
|
169
|
+
const deny = parseIdList(raw.deny ?? raw.denylist ?? raw.hide);
|
|
170
|
+
if (allow.length === 0 && deny.length === 0) return undefined;
|
|
171
|
+
return {
|
|
172
|
+
allow: allow.length > 0 ? allow : undefined,
|
|
173
|
+
deny: deny.length > 0 ? deny : undefined,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 按优先级解析生效的 provider 范围配置 */
|
|
178
|
+
function resolveScope(): ResolvedScope | undefined {
|
|
179
|
+
const envAllow = parseIdList(process.env[ENV_ALLOWLIST]);
|
|
180
|
+
if (envAllow.length > 0) {
|
|
181
|
+
return { scope: { allow: envAllow }, source: `env ${ENV_ALLOWLIST}` };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const agentDir = resolveAgentDir();
|
|
185
|
+
|
|
186
|
+
const scopeFile = join(agentDir, "provider-scope.json");
|
|
187
|
+
const fileScope = readJsonFile(scopeFile);
|
|
188
|
+
if (fileScope) {
|
|
189
|
+
const scope = normalizeScope(fileScope);
|
|
190
|
+
if (scope) return { scope, source: scopeFile };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const settingsPath = join(agentDir, "settings.json");
|
|
194
|
+
const settings = readJsonFile(settingsPath);
|
|
195
|
+
const settingsScope = settings?.providerScope;
|
|
196
|
+
if (settingsScope && typeof settingsScope === "object" && !Array.isArray(settingsScope)) {
|
|
197
|
+
const scope = normalizeScope(settingsScope as Record<string, unknown>);
|
|
198
|
+
if (scope) return { scope, source: `${settingsPath} (providerScope)` };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 构造一个「空壳 provider」:整体替换掉内置 provider。
|
|
206
|
+
* - `auth: {}` → /login 的 provider 选择器不会列出它
|
|
207
|
+
* - `getModels: () => []` → /model 与 `pi --list-models` 都不会列出它
|
|
208
|
+
*/
|
|
209
|
+
function createHiddenProvider(providerId: string): Provider {
|
|
210
|
+
const disabled = (): never => {
|
|
211
|
+
throw new Error(`Provider "${providerId}" is hidden by the provider-scope extension`);
|
|
212
|
+
};
|
|
213
|
+
return {
|
|
214
|
+
id: providerId,
|
|
215
|
+
name: providerId,
|
|
216
|
+
auth: {},
|
|
217
|
+
getModels: () => [],
|
|
218
|
+
stream: disabled,
|
|
219
|
+
streamSimple: disabled,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default function (pi: ExtensionAPI) {
|
|
224
|
+
const resolved = resolveScope();
|
|
225
|
+
const scope = resolved?.scope ?? {};
|
|
226
|
+
const source = resolved?.source ?? "(未配置)";
|
|
227
|
+
const allow = scope.allow ? new Set(scope.allow) : undefined;
|
|
228
|
+
const deny = new Set(scope.deny ?? []);
|
|
229
|
+
|
|
230
|
+
// 收集内置 provider,计算哪些要隐藏
|
|
231
|
+
const builtinIds = getBuiltinProviders();
|
|
232
|
+
const builtinIdSet = new Set(builtinIds);
|
|
233
|
+
const hiddenIds = new Set<string>();
|
|
234
|
+
|
|
235
|
+
// 加载期自检:白名单里的 provider 一个都不认识 → 放弃收敛(避免配置写错变砖)
|
|
236
|
+
let failOpenReason: string | undefined;
|
|
237
|
+
if (allow) {
|
|
238
|
+
const known = [...allow].filter(
|
|
239
|
+
(id) =>
|
|
240
|
+
builtinIdSet.has(id) ||
|
|
241
|
+
readModelsConfigProviders().includes(id) ||
|
|
242
|
+
readCredentialProviderIds().includes(id) ||
|
|
243
|
+
extensionSourceMentions(id),
|
|
244
|
+
);
|
|
245
|
+
if (known.length === 0) {
|
|
246
|
+
failOpenReason = `白名单里的 provider 都不存在:${[...allow].join(", ")}`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// 没有配置 → 什么都不隐藏(普通用户零影响)
|
|
251
|
+
if (resolved && !failOpenReason) {
|
|
252
|
+
for (const providerId of builtinIds) {
|
|
253
|
+
const visible = allow ? allow.has(providerId) : !deny.has(providerId);
|
|
254
|
+
if (visible) continue;
|
|
255
|
+
// 用空壳整体替换内置 provider(refresh/rebuildProviders 不会还原)
|
|
256
|
+
pi.registerProvider(createHiddenProvider(providerId));
|
|
257
|
+
hiddenIds.add(providerId);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** provider 是否仍然可见(被隐藏的 provider 不可见) */
|
|
262
|
+
const isVisible = (providerId: string): boolean => !hiddenIds.has(providerId);
|
|
263
|
+
|
|
264
|
+
// settings.json 里的默认 provider(用于告警)
|
|
265
|
+
const settings = readJsonFile(join(resolveAgentDir(), "settings.json"));
|
|
266
|
+
const defaultProvider =
|
|
267
|
+
typeof settings?.defaultProvider === "string" ? settings.defaultProvider : undefined;
|
|
268
|
+
|
|
269
|
+
// 会话启动时:默认模型被隐藏 → 告警 + 尝试自动切到允许的模型
|
|
270
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
271
|
+
if (allow && !failOpenReason) {
|
|
272
|
+
// 白名单是严格的:连「其它扩展注册」的 provider 也一并收敛
|
|
273
|
+
// (例如 pi 内置 llama.cpp 扩展注册的 llama.cpp provider)
|
|
274
|
+
// 会话期自检:用真实的 provider 注册表再校验一次
|
|
275
|
+
const known = new Set<string>([
|
|
276
|
+
...builtinIds,
|
|
277
|
+
...ctx.modelRegistry.getRegisteredProviderIds(),
|
|
278
|
+
...readModelsConfigProviders(),
|
|
279
|
+
]);
|
|
280
|
+
const matched = [...allow].filter((id) => known.has(id));
|
|
281
|
+
if (matched.length === 0) {
|
|
282
|
+
// fail-open:恢复加载期隐藏的内置 provider(unregisterProvider 会让内置
|
|
283
|
+
// provider 重新可见),避免白名单写错时把 CLI 变成「一个 provider 都没有」。
|
|
284
|
+
const restored: string[] = [];
|
|
285
|
+
for (const providerId of [...hiddenIds]) {
|
|
286
|
+
if (!builtinIdSet.has(providerId)) continue;
|
|
287
|
+
pi.unregisterProvider(providerId);
|
|
288
|
+
hiddenIds.delete(providerId);
|
|
289
|
+
restored.push(providerId);
|
|
290
|
+
}
|
|
291
|
+
failOpenReason = `白名单里的 provider 都不存在:${[...allow].join(", ")}`;
|
|
292
|
+
const message = [
|
|
293
|
+
`⚠️ provider-scope 白名单里没有任何已知的 provider:${[...allow].join(", ")}`,
|
|
294
|
+
` 配置来源:${source}`,
|
|
295
|
+
` 已回退为「不隐藏任何 provider」${restored.length > 0 ? `(恢复了 ${restored.length} 个内置 provider)` : ""},`,
|
|
296
|
+
" 请检查 provider id 是否写对(内网 provider 是否已安装/加载)。",
|
|
297
|
+
].join("\n");
|
|
298
|
+
if (ctx.hasUI) ctx.ui.notify(message, "warning");
|
|
299
|
+
else console.warn(message);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
for (const providerId of ctx.modelRegistry.getRegisteredProviderIds()) {
|
|
303
|
+
if (allow.has(providerId) || hiddenIds.has(providerId)) continue;
|
|
304
|
+
pi.registerProvider(createHiddenProvider(providerId));
|
|
305
|
+
hiddenIds.add(providerId);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (failOpenReason) return;
|
|
310
|
+
|
|
311
|
+
const current = ctx.model;
|
|
312
|
+
if (!current || isVisible(current.provider)) return;
|
|
313
|
+
|
|
314
|
+
const candidates = ctx.modelRegistry
|
|
315
|
+
.getAvailable()
|
|
316
|
+
.filter((model) => isVisible(model.provider));
|
|
317
|
+
const target = candidates[0];
|
|
318
|
+
const switched = target ? await pi.setModel(target) : false;
|
|
319
|
+
|
|
320
|
+
const message = [
|
|
321
|
+
`⚠️ 当前模型 ${current.provider}/${current.id} 已被 provider-scope 隐藏`,
|
|
322
|
+
` 配置来源:${source}`,
|
|
323
|
+
target
|
|
324
|
+
? switched
|
|
325
|
+
? ` 已自动切换到 ${target.provider}/${target.id}`
|
|
326
|
+
: ` 未能自动切换到 ${target.provider}/${target.id}(凭据未就绪)`
|
|
327
|
+
: " 没有可用的替代模型,请检查 AICODE_API_KEY 等凭据配置",
|
|
328
|
+
].join("\n");
|
|
329
|
+
|
|
330
|
+
if (ctx.hasUI) {
|
|
331
|
+
ctx.ui.notify(message, "warning");
|
|
332
|
+
} else {
|
|
333
|
+
console.warn(message);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// /provider-scope:查看当前收敛配置
|
|
338
|
+
pi.registerCommand("provider-scope", {
|
|
339
|
+
description: "查看 provider 可见范围(内网收敛配置)",
|
|
340
|
+
handler: async (_args, ctx) => {
|
|
341
|
+
const current = ctx.model;
|
|
342
|
+
// models.json 里定义的 provider 无法用空壳隐藏(compose 时一定会生成 apiKey auth)
|
|
343
|
+
const leaky = readModelsConfigProviders().filter((id) =>
|
|
344
|
+
allow ? !allow.has(id) : deny.has(id),
|
|
345
|
+
);
|
|
346
|
+
const lines = [
|
|
347
|
+
"🔍 Provider Scope",
|
|
348
|
+
"",
|
|
349
|
+
` 配置来源:${source}`,
|
|
350
|
+
` 白名单:${allow ? [...allow].join(", ") : "(未设置)"}`,
|
|
351
|
+
` 黑名单:${deny.size > 0 ? [...deny].join(", ") : "(未设置)"}`,
|
|
352
|
+
` 已隐藏内置 provider:${hiddenIds.size} 个`,
|
|
353
|
+
` 当前模型:${current ? `${current.provider}/${current.id}` : "(未选择)"}`,
|
|
354
|
+
` 默认 provider:${defaultProvider ?? "(未设置)"}`,
|
|
355
|
+
];
|
|
356
|
+
if (!resolved) {
|
|
357
|
+
lines.push(
|
|
358
|
+
"",
|
|
359
|
+
" ℹ️ 当前未配置 provider 范围,所有 provider 可见(外网 provider 仍会出现在 /login)。",
|
|
360
|
+
" 内网部署请写 ~/.aicode-cli/agent/provider-scope.json:",
|
|
361
|
+
' { "allow": ["<内网 provider id>"] }',
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
if (failOpenReason) {
|
|
365
|
+
lines.push("", ` ⚠️ 已回退为「不隐藏任何 provider」:${failOpenReason}`);
|
|
366
|
+
}
|
|
367
|
+
if (defaultProvider && !isVisible(defaultProvider)) {
|
|
368
|
+
lines.push(
|
|
369
|
+
"",
|
|
370
|
+
` ⚠️ 默认 provider "${defaultProvider}" 已被隐藏,请把 settings.json 的`,
|
|
371
|
+
` defaultProvider / defaultModel 改成白名单里的 provider。`,
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
if (leaky.length > 0) {
|
|
375
|
+
lines.push(
|
|
376
|
+
"",
|
|
377
|
+
` ⚠️ models.json 里定义的 ${leaky.join(", ")} 无法隐藏,仍会出现在 /login。`,
|
|
378
|
+
` 内网部署请把这些外网 provider 从 models.json 里删掉。`,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
if (ctx.hasUI) {
|
|
382
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
383
|
+
} else {
|
|
384
|
+
console.log(lines.join("\n"));
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Vercel Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agent-browser
|
|
3
|
+
description: Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.
|
|
4
|
+
allowed-tools: Bash(agent-browser:*)
|
|
5
|
+
hidden: true
|
|
6
|
+
license: Apache-2.0
|
|
7
|
+
metadata:
|
|
8
|
+
version: "0.45.0"
|
|
9
|
+
author: "vercel-labs"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# agent-browser
|
|
13
|
+
|
|
14
|
+
Fast browser automation CLI for AI agents. Chrome/Chromium via CDP with accessibility-tree snapshots and compact `@eN` element refs.
|
|
15
|
+
|
|
16
|
+
Install: `npm i -g agent-browser && agent-browser install`
|
|
17
|
+
|
|
18
|
+
## Start here
|
|
19
|
+
|
|
20
|
+
This file is a discovery stub, not the usage guide. Before running any `agent-browser` command, load the actual workflow content from the CLI:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
agent-browser skills get core # start here: the loop, waits, common tasks, troubleshooting
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The core guide ends with a table of references to load for detailed commands and flags. Use `agent-browser skills get core --full` only when you need every reference at once; it is several times larger.
|
|
27
|
+
|
|
28
|
+
The CLI serves skill content that matches the installed version. This stub cannot change between releases, which is why it only points at `skills get core`.
|
|
29
|
+
|
|
30
|
+
## Specialized skills
|
|
31
|
+
|
|
32
|
+
Load a specialized skill when the task falls outside browser web pages:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
agent-browser skills get electron # Electron desktop apps (VS Code, Slack, Discord, Figma, ...)
|
|
36
|
+
agent-browser skills get slack # Slack workspace automation
|
|
37
|
+
agent-browser skills get dogfood # Exploratory testing / QA / bug hunts
|
|
38
|
+
agent-browser skills get derive-client # Record a HAR, derive a standalone API client for a site
|
|
39
|
+
agent-browser skills get webmcp-gen # Build and validate WebMCP tools for a page
|
|
40
|
+
agent-browser skills get modern-web-guidance # Apply Modern Web Guidance, then verify the page
|
|
41
|
+
agent-browser skills get vercel-sandbox # agent-browser inside Vercel Sandbox microVMs
|
|
42
|
+
agent-browser skills get vercel # Protected Vercel deployments and flag overrides
|
|
43
|
+
agent-browser skills get agentcore # AWS Bedrock AgentCore cloud browsers
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Run `agent-browser skills list` to see everything available on the installed version.
|
|
47
|
+
|
|
48
|
+
## Why agent-browser
|
|
49
|
+
|
|
50
|
+
- Fast native Rust CLI, not a Node.js wrapper
|
|
51
|
+
- Works with any AI agent (Cursor, Claude Code, Codex, Continue, Windsurf, etc.)
|
|
52
|
+
- Chrome/Chromium via CDP with no Playwright or Puppeteer dependency
|
|
53
|
+
- Accessibility-tree snapshots with element refs for reliable interaction
|
|
54
|
+
- Sessions, authentication vault, state persistence, video recording
|
|
55
|
+
- Specialized skills for Electron apps, Slack, exploratory testing, cloud providers
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Deepening
|
|
2
|
+
|
|
3
|
+
How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in [SKILL.md](SKILL.md): **module**, **interface**, **seam**, **adapter**.
|
|
4
|
+
|
|
5
|
+
## Dependency categories
|
|
6
|
+
|
|
7
|
+
When assessing a candidate for deepening, classify its dependencies. The category determines how the deepened module is tested across its seam.
|
|
8
|
+
|
|
9
|
+
### 1. In-process
|
|
10
|
+
|
|
11
|
+
Pure computation, in-memory state, no I/O. Always deepenable: merge the modules and test through the new interface directly. No adapter needed.
|
|
12
|
+
|
|
13
|
+
### 2. Local-substitutable
|
|
14
|
+
|
|
15
|
+
Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable if the stand-in exists. The deepened module is tested with the stand-in running in the test suite. The seam is internal; no port at the module's external interface.
|
|
16
|
+
|
|
17
|
+
### 3. Remote but owned (Ports & Adapters)
|
|
18
|
+
|
|
19
|
+
Your own services across a network boundary (microservices, internal APIs). Define a **port** (interface) at the seam. The deep module owns the logic; the transport is injected as an **adapter**. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.
|
|
20
|
+
|
|
21
|
+
Recommendation shape: *"Define a port at the seam, implement an HTTP adapter for production and an in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across a network."*
|
|
22
|
+
|
|
23
|
+
### 4. True external (Mock)
|
|
24
|
+
|
|
25
|
+
Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the external dependency as an injected port; tests provide a mock adapter.
|
|
26
|
+
|
|
27
|
+
## Seam discipline
|
|
28
|
+
|
|
29
|
+
- **One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a port unless at least two adapters are justified (typically production + test). A single-adapter seam is just indirection.
|
|
30
|
+
- **Internal seams vs external seams.** A deep module can have internal seams (private to its implementation, used by its own tests) as well as the external seam at its interface. Don't expose internal seams through the interface just because tests use them.
|
|
31
|
+
|
|
32
|
+
## Testing strategy: replace, don't layer
|
|
33
|
+
|
|
34
|
+
- Old unit tests on shallow modules become waste once tests at the deepened module's interface exist; delete them.
|
|
35
|
+
- Write new tests at the deepened module's interface. The **interface is the test surface**.
|
|
36
|
+
- Tests assert on observable outcomes through the interface, not internal state.
|
|
37
|
+
- Tests should survive internal refactors, since they describe behaviour, not implementation. If a test has to change when the implementation changes, it's testing past the interface.
|