-
Notifications
You must be signed in to change notification settings - Fork 0
[sync] go-scm: 14 commits from Forge #1
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9806bbe
feat(manifest): add compile step and marketplace index builder
Snider 631ddd4
feat(manifest): add compile step and marketplace index builder
Snider 5799bd4
refactor(marketplace): replace raw os calls with go-io Medium in Inst…
Snider cc4b78d
Merge remote-tracking branch 'origin/agent/implement-manifest-compile…
Snider c666c2d
Merge remote-tracking branch 'origin/agent/replace-raw-filepath-join-…
Snider 871f558
docs: add manifest core.json implementation plan
Snider d752da4
chore: bump forge deps (core/go v0.3.1, go-io v0.1.2, config v0.1.2)
Snider caaece7
chore: sync go.mod dependencies
Snider c2c54f1
refactor(marketplace,jobrunner): replace os.ReadFile/WriteFile/MkdirA…
Snider e9fc690
refactor: replace fmt.Errorf/errors.New with coreerr.E()
Snider 8a65670
chore: sync dependencies for v0.3.4
Snider 223c41d
feat: add en-GB locale file for CLI commands
Snider 8367a53
feat: embed and load locale translations on init
Snider 9de597a
refactor: pass locales via RegisterCommands, remove direct i18n import
Snider 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,102 @@ | ||
| package scm | ||
|
|
||
| import ( | ||
| "crypto/ed25519" | ||
| "encoding/hex" | ||
| "os/exec" | ||
| "strings" | ||
|
|
||
| "forge.lthn.ai/core/cli/pkg/cli" | ||
| "forge.lthn.ai/core/go-io" | ||
| "forge.lthn.ai/core/go-scm/manifest" | ||
| ) | ||
|
|
||
| func addCompileCommand(parent *cli.Command) { | ||
| var ( | ||
| dir string | ||
| signKey string | ||
| builtBy string | ||
| ) | ||
|
|
||
| cmd := &cli.Command{ | ||
| Use: "compile", | ||
| Short: "Compile manifest.yaml into core.json", | ||
| Long: "Read .core/manifest.yaml, attach build metadata (commit, tag), and write core.json to the project root.", | ||
| RunE: func(cmd *cli.Command, args []string) error { | ||
| return runCompile(dir, signKey, builtBy) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVarP(&dir, "dir", "d", ".", "Project root directory") | ||
| cmd.Flags().StringVar(&signKey, "sign-key", "", "Hex-encoded ed25519 private key for signing") | ||
| cmd.Flags().StringVar(&builtBy, "built-by", "core scm compile", "Builder identity") | ||
|
|
||
| parent.AddCommand(cmd) | ||
| } | ||
|
|
||
| func runCompile(dir, signKeyHex, builtBy string) error { | ||
| medium, err := io.NewSandboxed(dir) | ||
| if err != nil { | ||
| return cli.WrapVerb(err, "open", dir) | ||
| } | ||
|
|
||
| m, err := manifest.Load(medium, ".") | ||
| if err != nil { | ||
| return cli.WrapVerb(err, "load", "manifest") | ||
| } | ||
|
|
||
| opts := manifest.CompileOptions{ | ||
| Commit: gitCommit(dir), | ||
| Tag: gitTag(dir), | ||
| BuiltBy: builtBy, | ||
| } | ||
|
|
||
| if signKeyHex != "" { | ||
| keyBytes, err := hex.DecodeString(signKeyHex) | ||
| if err != nil { | ||
| return cli.WrapVerb(err, "decode", "sign key") | ||
| } | ||
| opts.SignKey = ed25519.PrivateKey(keyBytes) | ||
| } | ||
|
|
||
| cm, err := manifest.Compile(m, opts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := manifest.WriteCompiled(medium, ".", cm); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cli.Blank() | ||
| cli.Print(" %s %s\n", successStyle.Render("compiled"), valueStyle.Render(m.Code)) | ||
| cli.Print(" %s %s\n", dimStyle.Render("version:"), valueStyle.Render(m.Version)) | ||
| if opts.Commit != "" { | ||
| cli.Print(" %s %s\n", dimStyle.Render("commit:"), valueStyle.Render(opts.Commit)) | ||
| } | ||
| if opts.Tag != "" { | ||
| cli.Print(" %s %s\n", dimStyle.Render("tag:"), valueStyle.Render(opts.Tag)) | ||
| } | ||
| cli.Print(" %s %s\n", dimStyle.Render("output:"), valueStyle.Render("core.json")) | ||
| cli.Blank() | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // gitCommit returns the current HEAD commit hash, or empty on error. | ||
| func gitCommit(dir string) string { | ||
| out, err := exec.Command("git", "-C", dir, "rev-parse", "HEAD").Output() | ||
| if err != nil { | ||
| return "" | ||
| } | ||
| return strings.TrimSpace(string(out)) | ||
| } | ||
|
|
||
| // gitTag returns the tag pointing at HEAD, or empty if none. | ||
| func gitTag(dir string) string { | ||
| out, err := exec.Command("git", "-C", dir, "describe", "--tags", "--exact-match", "HEAD").Output() | ||
| if err != nil { | ||
| return "" | ||
| } | ||
| return strings.TrimSpace(string(out)) | ||
| } | ||
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,59 @@ | ||
| package scm | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "forge.lthn.ai/core/cli/pkg/cli" | ||
| "forge.lthn.ai/core/go-io" | ||
| "forge.lthn.ai/core/go-scm/manifest" | ||
| ) | ||
|
|
||
| func addExportCommand(parent *cli.Command) { | ||
| var dir string | ||
|
|
||
| cmd := &cli.Command{ | ||
| Use: "export", | ||
| Short: "Export compiled manifest as JSON", | ||
| Long: "Read core.json from the project root and print it to stdout. Falls back to compiling .core/manifest.yaml if core.json is not found.", | ||
| RunE: func(cmd *cli.Command, args []string) error { | ||
| return runExport(dir) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVarP(&dir, "dir", "d", ".", "Project root directory") | ||
|
|
||
| parent.AddCommand(cmd) | ||
| } | ||
|
|
||
| func runExport(dir string) error { | ||
| medium, err := io.NewSandboxed(dir) | ||
| if err != nil { | ||
| return cli.WrapVerb(err, "open", dir) | ||
| } | ||
|
|
||
| // Try core.json first. | ||
| cm, err := manifest.LoadCompiled(medium, ".") | ||
| if err != nil { | ||
| // Fall back to compiling from source. | ||
| m, loadErr := manifest.Load(medium, ".") | ||
| if loadErr != nil { | ||
| return cli.WrapVerb(loadErr, "load", "manifest") | ||
| } | ||
| cm, err = manifest.Compile(m, manifest.CompileOptions{ | ||
| Commit: gitCommit(dir), | ||
| Tag: gitTag(dir), | ||
| BuiltBy: "core scm export", | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| data, err := manifest.MarshalJSON(cm) | ||
| if err != nil { | ||
| return cli.WrapVerb(err, "marshal", "manifest") | ||
| } | ||
|
|
||
| fmt.Println(string(data)) | ||
| return nil | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing key length validation before cast.
The hex-decoded bytes are cast directly to
ed25519.PrivateKeywithout validating the length. An ed25519 private key should be 64 bytes (or 32 bytes for seed-only). Invalid lengths will cause cryptographic operations to fail or behave unexpectedly.🛡️ Proposed fix to add validation
if signKeyHex != "" { keyBytes, err := hex.DecodeString(signKeyHex) if err != nil { return cli.WrapVerb(err, "decode", "sign key") } + if len(keyBytes) != ed25519.PrivateKeySize { + return cli.WrapVerb(fmt.Errorf("expected %d bytes, got %d", ed25519.PrivateKeySize, len(keyBytes)), "validate", "sign key") + } opts.SignKey = ed25519.PrivateKey(keyBytes) }Note: This requires adding
"fmt"to the imports.🤖 Prompt for AI Agents