-
Notifications
You must be signed in to change notification settings - Fork 724
feat(extension): Plugin / Hook framework with command pruning #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sang-neo03
wants to merge
25
commits into
main
Choose a base branch
from
feat/extension-platform
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6f2ba48
feat(extension): introduce Plugin / Hook framework with command pruning
sang-neo03 f34d051
fix(pruning): deny stub must override Args + PersistentPreRunE
sang-neo03 b3a6a35
Merge branch 'main' into feat/extension-platform
sang-neo03 2bedf8c
fix(config): policy subcommand bypasses parent's credential check
sang-neo03 b0e2d4d
feat(shortcuts): tag service groups with cmdmeta.Domain
sang-neo03 203ef32
feat(diagnostic): add unconditionally allowed command paths for intro…
sang-neo03 c046ed4
feat(plugins): add diagnostic command to inspect installed plugins an…
sang-neo03 aa9760e
Merge branch 'main' into feat/extension-platform
sang-neo03 9429c52
fix(cli): surface unknown_subcommand error instead of silent help fal…
sang-neo03 adfe1f8
refactor(envelope): rename error.type pruning/strict_mode to command_…
sang-neo03 bb20e40
feat(platform): fail closed on unannotated/invalid risk when a Rule i…
sang-neo03 27efb9d
chore(config): hide diagnostic policy/plugins commands from --help
sang-neo03 7d28188
Merge branch 'main' into feat/extension-platform
sang-neo03 cbfa752
style: gofmt
sang-neo03 a2dff61
Merge branch 'main' into feat/extension-platform
sang-neo03 2a6f0f4
fix(platform): nil Selector honours None contract; reject multi-doc p…
sang-neo03 06b06ed
chore: go mod tidy
sang-neo03 461e3c6
feat(extension/platform): plugin SDK with policy engine, hooks, and B…
liangshuo-1 4ff5ad2
feat(extension/platform): plugin SDK with policy engine, hooks, and B…
liangshuo-1 b78df3d
Merge remote-tracking branch 'origin/feat/extension-platform' into fe…
sang-neo03 aacb5d7
refactor(policy): remove validate command and update diagnostics
sang-neo03 0efee93
fix(extension/platform): address PR review must-fix items
sang-neo03 baa8878
Merge branch 'main' into feat/extension-platform
sang-neo03 eba0d75
fix(extension/platform): address CodeRabbit review comments + CI gofmt
sang-neo03 1f9f75a
fix(cmdpolicy): replace filepath.Abs with filepath.Clean for lint policy
sang-neo03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/larksuite/cli/internal/cmdutil" | ||
| "github.com/larksuite/cli/internal/output" | ||
| internalplatform "github.com/larksuite/cli/internal/platform" | ||
| ) | ||
|
|
||
| // NewCmdConfigPlugins exposes the plugin inventory diagnostic command. | ||
| // | ||
| // `config policy show` is intentionally focused on the user-layer Rule | ||
| // (Restrict). Plugins also contribute hooks (Observe / Wrap / Lifecycle) | ||
| // that are not policy gates but still mutate the CLI's runtime behaviour. | ||
| // This command surfaces both halves so an operator can answer "what is | ||
| // this binary doing differently from stock lark-cli?" in one place. | ||
| // | ||
| // Like config policy show, the dispatch path is exempt from policy | ||
| // enforcement (see internal/cmdpolicy/diagnostic.go) so it remains | ||
| // usable under any Rule. | ||
| func NewCmdConfigPlugins(f *cmdutil.Factory) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "plugins", | ||
| Hidden: true, // diagnostic-only; kept callable, omitted from --help so it stays out of AI-agent context | ||
| Short: "Inspect installed plugins and their hook contributions", | ||
| // Same leaf-level no-op as config policy: the parent `config` | ||
| // group's PersistentPreRunE requires builtin credential, but | ||
| // this is a read-only diagnostic that must work everywhere. | ||
| PersistentPreRunE: func(c *cobra.Command, _ []string) error { | ||
| c.SilenceUsage = true | ||
| return nil | ||
| }, | ||
| } | ||
| cmd.AddCommand(newCmdConfigPluginsShow(f)) | ||
| return cmd | ||
| } | ||
|
|
||
| func newCmdConfigPluginsShow(f *cmdutil.Factory) *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "show", | ||
| Short: "List successfully installed plugins, their rules, and registered hooks", | ||
| Long: `Print every plugin that committed during bootstrap, including: | ||
|
|
||
| - name / version / capabilities (FailurePolicy, Restricts, RequiredCLIVersion) | ||
| - rule (when the plugin called r.Restrict) | ||
| - hooks: observers (Before / After), wrappers, lifecycle handlers | ||
|
|
||
| Hooks are attributed by their namespaced name -- the framework prepends | ||
| the plugin name as the prefix at registration time, so an entry | ||
| "secaudit.audit-pre" belongs to plugin "secaudit".`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runConfigPluginsShow(f) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func runConfigPluginsShow(f *cmdutil.Factory) error { | ||
| inv := internalplatform.GetActiveInventory() | ||
| if inv == nil { | ||
| // Always emit the same field set as the populated branch so | ||
| // AI agents and CI scripts don't have to branch on whether | ||
| // `total` is present. `note` makes the unusual state explicit | ||
| // for human readers. | ||
| output.PrintJson(f.IOStreams.Out, map[string]any{ | ||
| "plugins": []any{}, | ||
| "total": 0, | ||
| "note": "no inventory recorded; bootstrap did not finish", | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return nil | ||
| } | ||
|
|
||
| plugins := make([]map[string]any, 0, len(inv.Plugins)) | ||
| for _, p := range inv.Plugins { | ||
| entry := map[string]any{ | ||
| "name": p.Name, | ||
| "version": p.Version, | ||
| "capabilities": p.Capabilities, | ||
| } | ||
| if p.Rule != nil { | ||
| entry["rule"] = p.Rule | ||
| } | ||
| entry["hooks"] = map[string]any{ | ||
| "observers": p.Observers, | ||
| "wrappers": p.Wrappers, | ||
| "lifecycle": p.Lifecycles, | ||
| "count": len(p.Observers) + len(p.Wrappers) + len(p.Lifecycles), | ||
| } | ||
| plugins = append(plugins, entry) | ||
| } | ||
| output.PrintJson(f.IOStreams.Out, map[string]any{ | ||
| "plugins": plugins, | ||
| "total": len(plugins), | ||
| }) | ||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.