Skip to content

Commit e814e55

Browse files
author
SqlRush
committed
Enforce marketplace policy for plugin loads
1 parent bd00853 commit e814e55

7 files changed

Lines changed: 156 additions & 27 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ M8 补充:headless `/plugin list|status` 现在会按 `enabledPlugins` 的 tru
273273

274274
M8 补充:`enabledPlugins` 的 disabled 状态现在会过滤本地 plugin manifest 产生的 slash command、Skill tool prompt、agent/MCP/output-style/status/stream-init metadata,`/plugin disable <name>` 写入配置后不再只影响展示层;marketplace 下载/安装、版本解析、动态 refresh lifecycle 和完整 UI 管理仍待补齐。
275275

276-
M8 补充:`internal/plugins` 新增 marketplace policy resolver,会根据 `blockedMarketplaces` 优先拒绝来源,并在 `strictKnownMarketplaces` 非空时只允许 strict allowlist 内的 marketplace;`/plugin marketplaces` 现在展示每个 extra/strict/blocked marketplace 的 allow/block decision。真实 marketplace 下载/安装/cache/load enforcement 仍待补齐。
276+
M8 补充:`internal/plugins` 新增 marketplace policy resolver,会根据 `blockedMarketplaces` 优先拒绝来源,并在 `strictKnownMarketplaces` 非空时只允许 strict allowlist 内的 marketplace;`/plugin marketplaces` 现在展示每个 extra/strict/blocked marketplace 的 allow/block decision;本地 plugin manifest 可声明 `marketplace`/`marketplaceName`/`marketplace_name`/`source.name`,带 settings 的 plugin loader 会按 marketplace policy 过滤 command/skill/agent/MCP/output-style/hook 激活路径,`/plugin show/search` 会标注 blocked reason。真实 marketplace 下载/安装/cache lifecycle 仍待补齐。
277277

278278
M8 补充:headless `/config output-style <name>` 现在会校验可用 output style、写入用户 `settings.json``outputStyle`,并同步当前 runner settings;完整 TUI picker 和状态栏附件仍待补齐。
279279

@@ -733,7 +733,7 @@ M7 补充:prompt history `LogEntry` 读取现在接受 `sessionID`/`session`/`
733733
本轮补充:`cmd/claude --help` 现在沿用 Go flag usage 输出并成功退出;`cmd/claude --cwd` 现在会设置 bootstrap working directory,影响 scaffold 输出、project settings、tool cwd 和 transcript path;`cmd/claude --print/-p` 现在接入真实 `conversation.Runner.RunTurn` 单轮 headless 路径,可从参数或 stdin 读取 prompt,读取 `ANTHROPIC_API_KEY`/`ANTHROPIC_BASE_URL`/`ANTHROPIC_MODEL`/`CLAUDE_MODEL`/settings model,解析模型别名,装配 builtin tools、settings-derived permission engine、settings-derived MCP config,并把最终 assistant text 写到 stdout;`--mcp-config`/`--mcpConfig` 现在会把指定 JSON 文件中的 `mcpServers` 合入 headless MCP local settings;`--input-format`/`--inputFormat` text/json/stream-json 现在有基础输入解析,支持 JSON prompt/user message 和 NDJSON user event;`--max-turns`/`--maxTurns` 现在会限制 headless tool-use loop 轮数,`--max-tokens`/`--maxTokens` 和 `--max-turns`/`--maxTurns` 都会拒绝负值;`--output-format`/`--outputFormat` json 现在会输出基础 result envelope,`stream-json` 会先输出基础 `system/init` 事件,再输出 NDJSON event stream 并以 result 行收尾,包含 result text、session id、assistant message、stop reason、model、usage 和 tool results;headless setup/resume/RunTurn 错误现在会在 JSON 模式输出 `subtype:error` result,在 stream-json 模式输出 `type:error` event;`--permission-mode`/`--permissionMode`、`--dangerously-skip-permissions`/`--dangerouslySkipPermissions`、`--system-prompt`/`--systemPrompt` 和 `--append-system-prompt`/`--appendSystemPrompt` 现在也有 CLI 接线或 camelCase alias;`--stream --output-format stream-json` 现在还会透出 raw Anthropic streaming events,包括 text delta;headless `--resume <session-id-or-jsonl>` 和 `--continue` 现在会加载当前项目 transcript chain 作为 history,并把新回合追加回同一个 transcript;`--allowedTools`/`--allowed-tools` 和 `--disallowedTools`/`--disallowed-tools` 现在会作为 CLI permission rules 合入 headless permission engine;`--add-dir`/`--addDir` 现在会作为 CLI additional working directory 合入 headless permission context。
734734
本轮补充:settings 文件读取现在有 path-keyed cache,按 size/mode/mtime 指纹复用内容并提供 cache reset;新增 settings change detector,可对 settings 文件快照区分 created/modified/deleted,并在检测到变化时清空 settings 文件缓存。
735735

736-
当前状态:bootstrap/config/auth/model 基础已完成;settings 已有 merge、managed policy(含本地 file/drop-in、MDM/registry、可选 remote GET source、turn-start remote refresh/app-state propagation 和 daemon heartbeat remote refresh)、settings file cache/change detector、turn-start local settings reload/app-state propagation、JSON Schema generation、marketplace source union 基础 validation、marketplace policy resolver/visibility 和 `strictPluginOnlyCustomization` 基础 enforcement;CLI 已有 `--version`、`--help` 成功退出、`--cwd` working directory override、scaffold settings 校验、基础 `--print` headless 单轮执行路径、基础 `--mcp-config`、基础 input-format text/json/stream-json、`--max-turns` tool loop 限制、基础 JSON result/error 输出、基础 stream-json init/event/error 输出、raw streaming event 透传、headless resume/continue transcript 接线、system prompt flags、dangerously-skip-permissions、常见 camelCase flag aliases、CLI allow/deny tool rules 和 CLI add-dir additional working directory context,但完整参数矩阵、交互 TUI 主循环、resume picker/UI、官方 SDK NDJSON/control protocol、settings background watcher/continuous app-state sync、remote managed 非 daemon 后台 refresh 和官方 stdout/stderr/exit-code parity 仍未完整兼容 CC。
736+
当前状态:bootstrap/config/auth/model 基础已完成;settings 已有 merge、managed policy(含本地 file/drop-in、MDM/registry、可选 remote GET source、turn-start remote refresh/app-state propagation 和 daemon heartbeat remote refresh)、settings file cache/change detector、turn-start local settings reload/app-state propagation、JSON Schema generation、marketplace source union 基础 validation、marketplace policy resolver/visibility/local manifest load enforcement 和 `strictPluginOnlyCustomization` 基础 enforcement;CLI 已有 `--version`、`--help` 成功退出、`--cwd` working directory override、scaffold settings 校验、基础 `--print` headless 单轮执行路径、基础 `--mcp-config`、基础 input-format text/json/stream-json、`--max-turns` tool loop 限制、基础 JSON result/error 输出、基础 stream-json init/event/error 输出、raw streaming event 透传、headless resume/continue transcript 接线、system prompt flags、dangerously-skip-permissions、常见 camelCase flag aliases、CLI allow/deny tool rules 和 CLI add-dir additional working directory context,但完整参数矩阵、交互 TUI 主循环、resume picker/UI、官方 SDK NDJSON/control protocol、settings background watcher/continuous app-state sync、remote managed 非 daemon 后台 refresh 和官方 stdout/stderr/exit-code parity 仍未完整兼容 CC。
737737

738738
### M3: API Client And Conversation Loop
739739

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ test/parity/ # golden tests against TS/official behavior
143143
- 本轮补充:`strictPluginOnlyCustomization` 已开始按 policy settings 生效,当前覆盖已实现的 `skills``mcp``hooks` 和 agent-metadata surfaces:锁定后 user/project/local skills 与 legacy commands 不加载,manual MCP server sources 不加载但 plugin/admin policy 仍保留,settings hooks 只保留 policy hooks 且 plugin hooks 继续运行;`agents` 锁定时非 plugin/bundled/admin prompt command 的 `agent``context: fork``effort` frontmatter metadata 会被清除。完整 forked agent runtime/UI edge cases 仍按缺口追踪。
144144
- 本轮补充:settings 文件读取现在有 path-keyed cache,按 size/mode/mtime 指纹复用内容并提供 `ResetSettingsCache`;新增 settings change detector,可对 settings 文件快照区分 created/modified/deleted,并在检测到变化时清空 settings 文件缓存;Runner turn-start 会在检测到 user/project/local settings 文件变化时重载 merged settings 并同步刷新 plugin MCP server app-state。完整后台 watcher 和 remote managed 非 daemon 后台 refresh 生命周期仍按缺口追踪。
145145
- 本轮补充:新增 settings JSON Schema generation,`SettingsJSONSchema()` 会从 `contracts.Settings` 反射生成 draft 2020-12 schema,补强 `$schema` const、permission mode enum、`strictPluginOnlyCustomization` union 和 login method enum;`/config show schema` 现在可展示 schema ID、draft、字段数和生成大小,完整 Zod message parity 仍按缺口追踪。
146-
- 本轮补充:settings validation 现在覆盖官方 marketplace source union 的基础语义,适用于 `extraKnownMarketplaces[].source``strictKnownMarketplaces[]``blockedMarketplaces[]`:校验 source discriminator、各 source 类型必填字段、URL source 绝对 URL、headers string record、github/git sparsePaths string array、settings-source plugins array、settings-source name 安全/保留名,并继续覆盖 inline marketplace key/name 一致性;`internal/plugins` 新增 marketplace policy resolver,blocked settings 优先、strict allowlist 非空时拒绝未列入来源,`/plugin marketplaces` 会展示 allow/block decision。真实 marketplace install/load/cache enforcement 仍按缺口追踪。
146+
- 本轮补充:settings validation 现在覆盖官方 marketplace source union 的基础语义,适用于 `extraKnownMarketplaces[].source``strictKnownMarketplaces[]``blockedMarketplaces[]`:校验 source discriminator、各 source 类型必填字段、URL source 绝对 URL、headers string record、github/git sparsePaths string array、settings-source plugins array、settings-source name 安全/保留名,并继续覆盖 inline marketplace key/name 一致性;`internal/plugins` 新增 marketplace policy resolver,blocked settings 优先、strict allowlist 非空时拒绝未列入来源,`/plugin marketplaces` 会展示 allow/block decision;本地 plugin manifest 可声明 `marketplace`/`marketplaceName`/`marketplace_name`/`source.name`,带 settings 的 plugin loader 会对这些来源执行 marketplace policy,`/plugin show/search` 会标注 blocked reason。真实 marketplace download/install/cache enforcement 仍按缺口追踪。
147147

148148
### M4: Tool framework、permissions、sandbox
149149

docs/first-second-parity-audit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ The following items remain incomplete and must not be treated as done:
108108
- Full tool execution parity gaps that remain: complete hook runtime policy beyond the current settings command hook path, MCP elicitation, complete SDK control event surface beyond current progress NDJSON, mid-call cancellation for concrete tools, background task behavior, telemetry, schema-not-sent hints, and concrete tool-specific semantics.
109109
- Complete Anthropic API parity gaps that remain: dynamic beta-header latching for any remaining provider-specific feature gates beyond prompt-cache/cache-editing/strict-output/1M-context requests, ant-only dump gating and remote `/issue` submission integration beyond the current local context summary, full official cost tracker/session restore lifecycle beyond current transcript usage restore, post-handshake streaming failure semantics, deeper gateway/proxy auth and routing behavior beyond static custom headers, first-party/Bedrock/Vertex/Foundry client setup, deeper OAuth account/profile lifecycle beyond request-time refresh retry, fast-mode retry/cooldown semantics, persistent unattended retry heartbeats, full prompt-cache editing lifecycle, and provider-specific cache behavior.
110110
- Full conversation/query loop: stop hooks, compact/auto-compact, token budget escalation, resume, SDK JSON/NDJSON control events, status updates, rate-limit handling, model switch breadcrumbs, side questions.
111-
- Full settings parity gaps that remain: complete Zod-equivalent validation messages, full remote managed-settings watcher/non-daemon background refresh lifecycle beyond current turn-start and daemon-heartbeat refresh, remaining forked agent/frontmatter execution and UI edge cases beyond current policy metadata filtering, marketplace install/load enforcement beyond current policy resolver and `/plugin marketplaces` visibility, and background watcher/continuous app-state sync beyond current turn-start local settings reload.
111+
- Full settings parity gaps that remain: complete Zod-equivalent validation messages, full remote managed-settings watcher/non-daemon background refresh lifecycle beyond current turn-start and daemon-heartbeat refresh, remaining forked agent/frontmatter execution and UI edge cases beyond current policy metadata filtering, marketplace download/install/cache enforcement beyond current local manifest load enforcement, and background watcher/continuous app-state sync beyond current turn-start local settings reload.
112112
- Full session/history parity gaps that remain: large-file optimized transcript loading, preserved-segment edge cases beyond current relink/prune support, content-replacement feature-flag/runtime override and inherited subagent gap-fill details, complete async prompt-history lifecycle parity beyond current lock/buffer/undo paths, full pasted-image processing/runtime integration beyond current prompt image-cache/image-block/metadata path, remaining remote-history edge cases, sidechain/subagent transcript layout, and all session metadata entry types.
113113

114114
## Current Verification

internal/conversation/run.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,15 +3327,15 @@ func (r Runner) formatPluginShow(args []string) string {
33273327
if !ok {
33283328
return "Plugin " + name + " was not found in local plugin manifests."
33293329
}
3330-
state := "enabled"
3331-
if !pluginpkg.PluginEnabled(plugin, merged.EnabledPlugins) {
3332-
state = "disabled"
3333-
}
3330+
state := pluginRuntimeState(plugin, merged)
33343331
lines := []string{
33353332
"Plugin " + plugin.Name,
33363333
"State: " + state,
33373334
"Path: " + plugin.Root,
33383335
}
3336+
if strings.TrimSpace(plugin.Marketplace) != "" {
3337+
lines = append(lines, "Marketplace: "+plugin.Marketplace)
3338+
}
33393339
if strings.TrimSpace(plugin.Version) != "" {
33403340
lines = append(lines, "Version: "+plugin.Version)
33413341
}
@@ -3376,7 +3376,7 @@ func (r Runner) formatPluginSearch(query string) string {
33763376
query = strings.TrimSpace(query)
33773377
merged := r.mergedSettings()
33783378
plugins := pluginpkg.LoadPluginDirs(pluginpkg.ProjectPluginDirs(r.WorkingDirectory))
3379-
results := pluginSearchResults(plugins, merged.EnabledPlugins, query)
3379+
results := pluginSearchResults(plugins, merged, query)
33803380
if len(results) == 0 {
33813381
return "No plugins matched " + query + "."
33823382
}
@@ -4155,24 +4155,34 @@ func pluginEnabledValueText(value any) (string, bool) {
41554155
return "", false
41564156
}
41574157

4158+
func pluginRuntimeState(plugin pluginpkg.LoadedPlugin, settings contracts.Settings) string {
4159+
if !pluginpkg.PluginEnabled(plugin, settings.EnabledPlugins) {
4160+
return "disabled"
4161+
}
4162+
if strings.TrimSpace(plugin.Marketplace) != "" {
4163+
decision := pluginpkg.NewMarketplacePolicy(settings).Decision(plugin.Marketplace)
4164+
if !decision.Allowed {
4165+
return "blocked: " + decision.Reason
4166+
}
4167+
}
4168+
return "enabled"
4169+
}
4170+
41584171
type pluginSearchResult struct {
41594172
Plugin string
41604173
Version string
41614174
State string
41624175
Match string
41634176
}
41644177

4165-
func pluginSearchResults(plugins []pluginpkg.LoadedPlugin, enabledPlugins map[string]any, query string) []pluginSearchResult {
4178+
func pluginSearchResults(plugins []pluginpkg.LoadedPlugin, settings contracts.Settings, query string) []pluginSearchResult {
41664179
query = strings.ToLower(strings.TrimSpace(query))
41674180
if query == "" {
41684181
return nil
41694182
}
41704183
var results []pluginSearchResult
41714184
for _, plugin := range plugins {
4172-
state := "enabled"
4173-
if !pluginpkg.PluginEnabled(plugin, enabledPlugins) {
4174-
state = "disabled"
4175-
}
4185+
state := pluginRuntimeState(plugin, settings)
41764186
for _, match := range pluginSearchMatches(plugin, query) {
41774187
results = append(results, pluginSearchResult{
41784188
Plugin: plugin.Name,

internal/conversation/run_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,6 +4751,48 @@ func TestRunnerPluginShowReportsDisabledLocalPlugin(t *testing.T) {
47514751
}
47524752
}
47534753

4754+
func TestRunnerPluginShowReportsMarketplaceBlockedLocalPlugin(t *testing.T) {
4755+
repo := filepath.Join(t.TempDir(), "repo")
4756+
cwd := filepath.Join(repo, "pkg")
4757+
pluginDir := filepath.Join(repo, ".claude", "plugins", "demo")
4758+
if err := os.MkdirAll(filepath.Join(repo, ".git"), 0o755); err != nil {
4759+
t.Fatal(err)
4760+
}
4761+
if err := os.MkdirAll(pluginDir, 0o755); err != nil {
4762+
t.Fatal(err)
4763+
}
4764+
if err := os.MkdirAll(cwd, 0o755); err != nil {
4765+
t.Fatal(err)
4766+
}
4767+
if err := os.WriteFile(filepath.Join(pluginDir, "plugin.json"), []byte(`{"name":"demo","marketplace":"internal","commands":[{"name":"demo:deploy","prompt":"Deploy."}]}`), 0o644); err != nil {
4768+
t.Fatal(err)
4769+
}
4770+
runner := Runner{
4771+
Client: &fakeClient{},
4772+
SessionID: "sess_plugin_show_marketplace_blocked",
4773+
WorkingDirectory: cwd,
4774+
MCP: &MCPConfig{UserSettings: contracts.Settings{
4775+
StrictKnownMarketplaces: []any{"enterprise"},
4776+
}},
4777+
}
4778+
4779+
result, err := runner.RunTurn(context.Background(), nil, messages.UserText("/plugin show demo"))
4780+
if err != nil {
4781+
t.Fatal(err)
4782+
}
4783+
text := result.Messages[1].Content[0].Text
4784+
for _, want := range []string{
4785+
"Plugin demo",
4786+
"State: blocked: not listed in settings strictKnownMarketplaces",
4787+
"Marketplace: internal",
4788+
"- /demo:deploy",
4789+
} {
4790+
if !strings.Contains(text, want) {
4791+
t.Fatalf("plugin show blocked missing %q: %q", want, text)
4792+
}
4793+
}
4794+
}
4795+
47544796
func TestRunnerPluginSearchFindsLocalPluginMetadata(t *testing.T) {
47554797
client := &fakeClient{}
47564798
repo := filepath.Join(t.TempDir(), "repo")

0 commit comments

Comments
 (0)