From 26ac62fbb7c92836f9c4dbf3c65f49e5b13967d7 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Fri, 20 Nov 2026 03:35:49 +0000 Subject: [PATCH] Establish native CommandKit command composition --- docs/oss/attribution.md | 86 ++++++++++++++++++++++++ docs/oss/licenses/pflag-BSD-3-Clause.txt | 28 ++++++++ docs/roadmap/implementation.md | 14 ++++ go.mod | 6 ++ go.sum | 17 +++++ internal/adapter/cli/app.go | 55 +++++++++++++++ internal/adapter/cli/app_test.go | 31 +++++++++ internal/adapter/cli/run.go | 23 +------ 8 files changed, 239 insertions(+), 21 deletions(-) create mode 100644 docs/oss/licenses/pflag-BSD-3-Clause.txt create mode 100644 internal/adapter/cli/app.go create mode 100644 internal/adapter/cli/app_test.go diff --git a/docs/oss/attribution.md b/docs/oss/attribution.md index 6e8e8cc..d3c2c85 100644 --- a/docs/oss/attribution.md +++ b/docs/oss/attribution.md @@ -48,6 +48,92 @@ License and notices: [LGPL 3.0](licenses/LGPL-3.0.txt) | [Source](https://forge.maximumdirect.net/base-layer/configkit/src/commit/51ef3144158db1a09fabdbd1c7ae59908c84923b). +## CommandKit + +Selected module: `go.maximumdirect.net/commandkit` at `v0.7.0`. + +Copyright (C) 2026 Eric Rakestraw + +SPDX-License-Identifier: LGPL-3.0-or-later + +License and notices: [LGPL 3.0](licenses/LGPL-3.0.txt) | +[GPL 3.0](licenses/GPL-3.0.txt) | +[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/b57bfe176cff05a892e6cb07ebb5f350239e55d4/COPYRIGHT) | +[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/b57bfe176cff05a892e6cb07ebb5f350239e55d4/LICENSE). + +[Source](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/b57bfe176cff05a892e6cb07ebb5f350239e55d4). + +## CommandKit ckconfig + +Selected module: `go.maximumdirect.net/ckconfig` at `v0.9.0`. + +Copyright (C) 2026 Eric Rakestraw + +SPDX-License-Identifier: LGPL-3.0-or-later + +License and notices: [LGPL 3.0](licenses/LGPL-3.0.txt) | +[GPL 3.0](licenses/GPL-3.0.txt) | +[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/9962368f0c1ea1f6ad010638e94621091105d745/integrations/ckconfig/COPYRIGHT) | +[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/9962368f0c1ea1f6ad010638e94621091105d745/integrations/ckconfig/LICENSE). + +[Source](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/9962368f0c1ea1f6ad010638e94621091105d745/integrations/ckconfig). + +## CommandKit ckprompt + +Selected module: `go.maximumdirect.net/ckprompt` at `v0.10.0`. + +Copyright (C) 2026 Eric Rakestraw + +SPDX-License-Identifier: LGPL-3.0-or-later + +License and notices: [LGPL 3.0](licenses/LGPL-3.0.txt) | +[GPL 3.0](licenses/GPL-3.0.txt) | +[COPYRIGHT](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/c9a56e1b15f2169881a91fca4e1f4a1c475e057a/integrations/ckprompt/COPYRIGHT) | +[LICENSE](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/c9a56e1b15f2169881a91fca4e1f4a1c475e057a/integrations/ckprompt/LICENSE). + +[Source](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/c9a56e1b15f2169881a91fca4e1f4a1c475e057a/integrations/ckprompt). + +## Cobra + +Selected module: `github.com/spf13/cobra` at `v1.10.2` (transitive dependency). + +Copyright 2013-2023 The Cobra Authors + +SPDX-License-Identifier: Apache-2.0 + +License and notices: [Apache 2.0](licenses/Apache-2.0.txt) | +[LICENSE.txt](https://github.com/spf13/cobra/blob/88b30ab89da2d0d0abb153818746c5a2d30eccec/LICENSE.txt). + +[Source](https://github.com/spf13/cobra/tree/88b30ab89da2d0d0abb153818746c5a2d30eccec). + +## pflag + +Selected module: `github.com/spf13/pflag` at `v1.1.0` (transitive dependency). + +Copyright (c) 2012 Alex Ogier. All rights reserved. + +Copyright (c) 2012 The Go Authors. All rights reserved. + +SPDX-License-Identifier: BSD-3-Clause + +License and notices: [BSD 3-Clause](licenses/pflag-BSD-3-Clause.txt) | +[LICENSE](https://github.com/spf13/pflag/blob/f8a990678a6d44385313e9b19e40737f889f9b14/LICENSE). + +[Source](https://github.com/spf13/pflag/tree/f8a990678a6d44385313e9b19e40737f889f9b14). + +## mousetrap + +Selected module: `github.com/inconshreveable/mousetrap` at `v1.1.0` (Windows transitive dependency). + +Copyright 2022 Alan Shreve (@inconshreveable) + +SPDX-License-Identifier: Apache-2.0 + +License and notices: [Apache 2.0](licenses/Apache-2.0.txt) | +[LICENSE](https://github.com/inconshreveable/mousetrap/blob/4e8053ee7ef85a6bd26368364a6d27f1641c1d21/LICENSE). + +[Source](https://github.com/inconshreveable/mousetrap/tree/4e8053ee7ef85a6bd26368364a6d27f1641c1d21). + ## jsonschema/v6 Selected module: `github.com/santhosh-tekuri/jsonschema/v6` at `v6.0.3`. diff --git a/docs/oss/licenses/pflag-BSD-3-Clause.txt b/docs/oss/licenses/pflag-BSD-3-Clause.txt new file mode 100644 index 0000000..63ed1cf --- /dev/null +++ b/docs/oss/licenses/pflag-BSD-3-Clause.txt @@ -0,0 +1,28 @@ +Copyright (c) 2012 Alex Ogier. All rights reserved. +Copyright (c) 2012 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index a70f191..1c8e888 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -152,6 +152,20 @@ filesystem hardening is requested. ## Stage 1: Select Released Dependencies And Establish Command Composition +**Status: Complete.** Selected CommandKit v0.7.0 +(`b57bfe176cff05a892e6cb07ebb5f350239e55d4`), ckconfig v0.9.0 +(`9962368f0c1ea1f6ad010638e94621091105d745`), and ckprompt v0.10.0 +(`c9a56e1b15f2169881a91fca4e1f4a1c475e057a`); retained ConfigKit v1.2.1, +PromptKit v0.23.3, Go minimum 1.27.0, and validation toolchain 1.27.4. +Native composition now owns dispatch and finalization; application acquisition +and command effects remain explicit unfinished callbacks for subsequent work. +Verified configuration-free help/version/scope discovery and Bash/Zsh/Fish +completion, all-package test compilation, tidy module metadata, linked dependency +selection (including Windows-only mousetrap), and release notice paths. +Full behavioral checks remain deferred to Stage 9: the old CLI integration tests +still describe the retired interface, and the new application handlers are not +yet implemented. No compatibility dispatch was retained. + **Primary files:** `go.mod`, `go.sum`, `internal/adapter/cli` composition, `docs/oss/attribution.md`, and applicable `docs/oss/licenses/` texts. diff --git a/go.mod b/go.mod index 606dc08..4ba7b11 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,18 @@ module gitea.maximumdirect.net/eric/scriptorium go 1.27.0 require ( + go.maximumdirect.net/ckconfig v0.9.0 + go.maximumdirect.net/ckprompt v0.10.0 + go.maximumdirect.net/commandkit v0.7.0 go.maximumdirect.net/configkit v1.2.1 go.maximumdirect.net/promptkit v0.23.3 ) require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect + github.com/spf13/cobra v1.10.2 // indirect + github.com/spf13/pflag v1.1.0 // indirect go.yaml.in/yaml/v4 v4.0.0 // indirect golang.org/x/text v0.44.0 // indirect ) diff --git a/go.sum b/go.sum index f94e6d1..ac60f42 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,29 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28= github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.1.0 h1:6W6MbVUrnMb8PEhjkqwsVLY7ryuzRfFHF4mQd7L94ag= +github.com/spf13/pflag v1.1.0/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +go.maximumdirect.net/ckconfig v0.9.0 h1:s9Ikga4wt4K1NpLCX9bLhm5vbcm1Fgqy9yk2lmO4Sss= +go.maximumdirect.net/ckconfig v0.9.0/go.mod h1:yGjFVr2UzjJjiwDdMwsKehuQfvvtv7rTEOIk5NQOY00= +go.maximumdirect.net/ckprompt v0.10.0 h1:t2UyWSke+bWH9aTDrw5/bteD+TO0y5LD0NWw0y2KniQ= +go.maximumdirect.net/ckprompt v0.10.0/go.mod h1:vx8lZnelASctQtyxY2yV4PuTZfLpE9EqDa+LPj3+SHM= +go.maximumdirect.net/commandkit v0.7.0 h1:toLDGhHoVe6gBX5HWuzQ/Joz0cBqEhJXolW21m3axBk= +go.maximumdirect.net/commandkit v0.7.0/go.mod h1:sVp3JXKpm2YrP4Ie8Q3nWmQgwBdPN8uO+wQU72erDns= go.maximumdirect.net/configkit v1.2.1 h1:f+/6WjNl6CULbMr6ZSVwi4aty9rmuDfJlvpeU7I+HZM= go.maximumdirect.net/configkit v1.2.1/go.mod h1:ewu6blSokUDCMovy8JBXAdXRikGmlHXAQpFghnPWRfs= go.maximumdirect.net/promptkit v0.23.3 h1:bKbrkluwfgXUsm0e/mxz/TpV9b60yUtJLVUROLsM3VU= go.maximumdirect.net/promptkit v0.23.3/go.mod h1:vPFg76VXcffP0JBFMS2WADCHwV5FYvO2O4bvIoiDlwc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v4 v4.0.0 h1:/LG1pNO84Z4l603j/xMn69CcS5OYhMQ/f7l2LoQUGuw= go.yaml.in/yaml/v4 v4.0.0/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/adapter/cli/app.go b/internal/adapter/cli/app.go new file mode 100644 index 0000000..b4dba74 --- /dev/null +++ b/internal/adapter/cli/app.go @@ -0,0 +1,55 @@ +package cli + +import ( + "context" + "errors" + "io" + + appconfig "gitea.maximumdirect.net/eric/scriptorium/internal/config" + "go.maximumdirect.net/ckconfig" + "go.maximumdirect.net/ckprompt" + "go.maximumdirect.net/commandkit" + "go.maximumdirect.net/configkit" + "go.maximumdirect.net/promptkit" +) + +// Execute composes the native CLI and returns its finalized outcome. The caller +// owns the context, streams, and process exit. +func Execute(ctx context.Context, identity commandkit.Identity, args []string, stdout, stderr io.Writer) commandkit.Outcome { + app, err := newApp(identity) + if err != nil { + return commandkit.Failure("Could not compose application commands.").WithCause(err) + } + return app.Execute(ctx, args, commandkit.Streams{Out: stdout, Err: stderr}) +} + +func newApp(identity commandkit.Identity) (*commandkit.App, error) { + application := ckconfig.FromConfigKit("app", "Scriptorium application configuration.", loadApplication) + framework := ckprompt.ConfigScope(loadEngine) + configuration := ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{ + Scopes: []ckconfig.Scope[struct{}, struct{}]{application, framework}, + }) + definitions := ckprompt.FromEngine(loadEngine) + declarations := []commandkit.Declaration{ + commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "run", Summary: "Run a stored prompt.", Run: commandNotImplemented}), + commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "serve", Summary: "Serve the HTTP API.", Run: commandNotImplemented}), + configuration, + commandkit.Completion("scriptorium"), + } + declarations = append(declarations, ckprompt.Declarations(definitions)...) + return commandkit.New(identity, declarations...) +} + +// Application acquisition and effects are filled in independently of command +// declaration construction; metadata operations must never reach these callbacks. +func loadApplication(context.Context, ckconfig.Selection, struct{}, struct{}) (*configkit.Result[appconfig.Document], error) { + return nil, errors.New("application configuration acquisition is not implemented") +} + +func loadEngine(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) { + return nil, errors.New("engine acquisition is not implemented") +} + +func commandNotImplemented(commandkit.Invocation, struct{}) commandkit.Outcome { + return commandkit.Failure("Application command is not implemented.") +} diff --git a/internal/adapter/cli/app_test.go b/internal/adapter/cli/app_test.go new file mode 100644 index 0000000..3c667e1 --- /dev/null +++ b/internal/adapter/cli/app_test.go @@ -0,0 +1,31 @@ +package cli + +import ( + "bytes" + "context" + "strings" + "testing" + + "go.maximumdirect.net/commandkit" +) + +func TestNativeMetadataWithoutConfiguration(t *testing.T) { + t.Chdir(t.TempDir()) + for _, args := range [][]string{ + {"--help"}, {"version"}, {"run", "--help"}, {"serve", "--help"}, + {"config", "scopes"}, {"config", "show", "--help"}, + {"promptkit", "--help"}, {"promptkit", "list", "prompts", "--help"}, + {"completion", "bash"}, {"completion", "zsh"}, {"completion", "fish"}, + } { + t.Run(strings.Join(args, " "), func(t *testing.T) { + var out, diagnostics bytes.Buffer + outcome := Execute(context.Background(), commandkit.Identity{Name: "scriptorium", Version: "test-version", Revision: "test-revision"}, args, &out, &diagnostics) + if outcome.Status != 0 || out.Len() == 0 { + t.Fatalf("outcome=%#v stdout=%q stderr=%q", outcome, out.String(), diagnostics.String()) + } + if args[0] == "version" && !strings.Contains(out.String(), "test-version") { + t.Fatalf("version identity missing: %q", out.String()) + } + }) + } +} diff --git a/internal/adapter/cli/run.go b/internal/adapter/cli/run.go index 749b18e..b3ee022 100644 --- a/internal/adapter/cli/run.go +++ b/internal/adapter/cli/run.go @@ -18,6 +18,7 @@ import ( "gitea.maximumdirect.net/eric/scriptorium/internal/defaults" renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format" executionreport "gitea.maximumdirect.net/eric/scriptorium/internal/report" + "go.maximumdirect.net/commandkit" "go.maximumdirect.net/configkit" "go.maximumdirect.net/promptkit" ) @@ -112,27 +113,7 @@ func (l *listFlag) Set(v string) error { } func Run(args []string, stdout, stderr io.Writer) int { - if len(args) == 0 { - printUsage(stderr) - return ExitRuntimeError - } - - switch args[0] { - case "run": - return runCommand(args[1:], stdout, stderr) - case "render": - return renderCommand(args[1:], stdout, stderr) - case "serve": - return serveCommand(args[1:], stderr) - case "inspect": - return inspectCommand(args[1:], stdout, stderr) - case "config": - return configCommand(args[1:], stdout, stderr) - default: - fmt.Fprintf(stderr, "unknown command %q\n", args[0]) - printUsage(stderr) - return ExitRuntimeError - } + return Execute(context.Background(), commandkit.Identity{Name: "scriptorium", Version: "dev"}, args, stdout, stderr).Status } func runCommand(args []string, stdout, stderr io.Writer) int {