mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 10:08:02 +08:00
Give each AI Agent (OpenClaw, Hermes) its own lark-cli workspace so
its Feishu calls don't overwrite the developer's local config or
collide with other Agents.
lark-cli config bind [--source openclaw|hermes] [--app-id <id>]
[--identity bot-only|user-default] [--force]
Key capabilities:
- Source auto-detected from OPENCLAW_* / HERMES_* env signals; config
written to ~/.lark-cli/<agent>/, isolated per Agent.
- Two identity presets: 'bot-only' (flag-mode default) and
'user-default'. Flag mode rejects silent bot→user escalation
without --force; TUI prompts are exempt.
- Agent-friendly stdout JSON with 'identity' + 'message' for
next-step branching.
- 'config show' and 'doctor' expose the bound 'workspace'.
- OpenClaw SecretRef resolution: plain / ${VAR} / file:+JSON Pointer
/ exec:.
93 lines
2.7 KiB
Go
93 lines
2.7 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
"github.com/larksuite/cli/internal/output"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// ConfigShowOptions holds all inputs for config show.
|
|
type ConfigShowOptions struct {
|
|
Factory *cmdutil.Factory
|
|
}
|
|
|
|
// NewCmdConfigShow creates the config show subcommand.
|
|
func NewCmdConfigShow(f *cmdutil.Factory, runF func(*ConfigShowOptions) error) *cobra.Command {
|
|
opts := &ConfigShowOptions{Factory: f}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "show",
|
|
Short: "Show current configuration",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if runF != nil {
|
|
return runF(opts)
|
|
}
|
|
return configShowRun(opts)
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func configShowRun(opts *ConfigShowOptions) error {
|
|
f := opts.Factory
|
|
|
|
config, err := core.LoadMultiAppConfig()
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return notConfiguredError()
|
|
}
|
|
return output.Errorf(output.ExitValidation, "config", "failed to load config: %v", err)
|
|
}
|
|
if config == nil || len(config.Apps) == 0 {
|
|
return output.ErrWithHint(output.ExitValidation, "config", "not configured", "run: lark-cli config init")
|
|
}
|
|
app := config.CurrentAppConfig(f.Invocation.Profile)
|
|
if app == nil {
|
|
return output.ErrWithHint(output.ExitValidation, "config", "no active profile", "run: lark-cli profile list")
|
|
}
|
|
users := "(no logged-in users)"
|
|
if len(app.Users) > 0 {
|
|
var userStrs []string
|
|
for _, u := range app.Users {
|
|
userStrs = append(userStrs, fmt.Sprintf("%s (%s)", u.UserName, u.UserOpenId))
|
|
}
|
|
users = strings.Join(userStrs, ", ")
|
|
}
|
|
output.PrintJson(f.IOStreams.Out, map[string]interface{}{
|
|
"workspace": core.CurrentWorkspace().Display(),
|
|
"profile": app.ProfileName(),
|
|
"appId": app.AppId,
|
|
"appSecret": "****",
|
|
"brand": app.Brand,
|
|
"lang": app.Lang,
|
|
"users": users,
|
|
})
|
|
fmt.Fprintf(f.IOStreams.ErrOut, "\nConfig file path: %s\n", core.GetConfigPath())
|
|
return nil
|
|
}
|
|
|
|
// notConfiguredError returns the "not configured" error with a hint that
|
|
// points the user to the right next step: config init for the default local
|
|
// workspace, config bind for an Agent workspace that has not been bound yet.
|
|
func notConfiguredError() error {
|
|
ws := core.CurrentWorkspace()
|
|
if ws.IsLocal() {
|
|
return output.ErrWithHint(output.ExitValidation, "config",
|
|
"not configured",
|
|
"run: lark-cli config init")
|
|
}
|
|
return output.ErrWithHint(output.ExitValidation, ws.Display(),
|
|
fmt.Sprintf("%s context detected but lark-cli not bound to %s workspace", ws.Display(), ws.Display()),
|
|
fmt.Sprintf("run: lark-cli config bind --source %s", ws.Display()))
|
|
}
|