Shared : command system (core/lib/cmd + ui + lua) #5
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
residual/.agent#5
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Plan: Shared
:command system incore/lib/cmd+ propagation to res-edit, res-code, res-console, res-sheetsStatus: design (decisions locked) → phased implementation plan
Locked decisions (from user)
Alt+:only, hardcoded, non-configurable. Sits in the console'sAltdomain. Never a configurable key.modeGoto/modeFindinto the:line, but keepCtrl+F/Ctrl+Gshortcuts — they pre-fill the:line.core/lib/cmdis a builder-type system. Provides interface + standards (parser,Registry,Handler,Context,Result, arg tokenizer with quotes) but ships no app command lists. Each app implements its own registry. res-edit owns its set; res-code composes res-edit's set."a b"→ one arg).core/lib/cmdand delete its localrunCommand.command.register(verb, fn)so Lua scripts build their own:verbcommands. Reusable glue ships ascore/lib/cmd/lua.core/lib/cmd/uiships a premade, position-agnostic bubbletea widget (input line + dropdown + live-filter autocomplete). Apps include it in the appropriate position (bottom for edit/console, top for code).Three opt-in layers
Apps compose only the layers they need:
cmd+cmd/uicmd+cmd/ui(+ latercmd/lua)cmd+cmd/ui+cmd/luacmd+cmd/ui(later phase)Builder API (
core/lib/cmd)Context{ Verb, Args, Raw, App },Result{ Status, Quit },Handler func(ctx Context) ResultSpec{ Verb, Aliases, Usage, Desc, Handler }Registry:NewRegistry,Register(idempotent; later wins),Merge(res-code composes res-edit),Run(line, app),Complete(prefix),Specs()parse.go): strip one leading:; quote-aware tokenize ("..."/'...'); resolve aliases; unknown verb → status message;Raw= everything after verb.cmd/luabridgeLuaToHandler(fn, eng),Register(r, eng, verb, fn, opts),BindCommandTable(L, r, eng)— registers acommandLua global so addon scripts docommand.register("hello", function(args) return "hi " .. (args[1] or "") end).cmd/uipalettePalettewithPosition(PosBottom / PosTop / PosOverlay), live-filter autocomplete, Tab-accept, Enter-run, Esc-cancel, mouse support. All styles fromcore/lib/tui/theme(amber palette, AGENTS.md §7). Position-agnostic: app decides placement.Propagation
core/lib/edit):modeCommand+:entry;editCommands()registry (:w :write :save :q :quit :wq :x :e :edit :goto :g :find :f); adoptui.Palette(PosBottom);Ctrl+F/Ctrl+Gpre-fill; remove oldmodeFind/modeGoto.extra/internal/code):modeCommand+:;codeCommands() = Merge(edit.EditCommands(), codeOnly)(:tabnew :tabn :tabp :b :sidebar :term);ui.Palette(PosTop).core/internal/libs/console):psCommandstate;Alt+:trigger;consoleCommands()calling existing Lua surface (:menu :widget :reload :set :q); includecmdlua.BindCommandTable; updatedocs/console/scripting.md.runCommandwithsheetsCommands(); adoptui.Palette(PosBottom); delete hardcoded switch.Implementation phases
core/lib/cmdbuilder +cmd/ui+cmd/lua+ unit tests.Alt+:+ Lua bridge).docs/design/command-registry.md, updatedocs/keymap.md, per-app docs, AGENTS.md §4 package table.Verification
cd core && go build ./... && go test ./...cd extra && go build ./... && go test ./...core/lib/cmd,cmd/ui,cmd/lua,core/lib/edit,extra/internal/code,extra/lib/sheets/tui.Risks
:must never intercept shell input → gated behindAlt+:only (hardcoded).core/lib/cmdbase Lua-free & UI-free;cmd/lua+cmd/uiare opt-in subpkgs.Alt+*console-owned;Ctrl+*editors;:bare-rune safe).tui/themeonly.PosTopin code must not overlap tab bar.