Skip to content

Commit 50730c5

Browse files
docs(core): annotate shared CLI and generator helpers
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 8055553 commit 50730c5

5 files changed

Lines changed: 38 additions & 0 deletions

File tree

internal/annotation/normalizer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func stripBlockDelimiters(text string, language string) string {
8383
return text
8484
}
8585

86+
// stripPythonDocstringDelimiters removes triple-quote wrappers from a Python docstring body.
87+
// @intent expose the raw docstring text by trying both """ and ''' triple-quote forms.
8688
func stripPythonDocstringDelimiters(text string) (string, bool) {
8789
for _, quote := range []string{"\"\"\"", "'''"} {
8890
if stripped, ok := stripPythonQuotedString(text, quote); ok {
@@ -92,6 +94,8 @@ func stripPythonDocstringDelimiters(text string) (string, bool) {
9294
return "", false
9395
}
9496

97+
// stripPythonQuotedString removes a matching opening and closing quote pair while validating any string prefix.
98+
// @intent accept docstrings with optional `r` or `u` prefixes without altering body content.
9599
func stripPythonQuotedString(text string, quote string) (string, bool) {
96100
lower := strings.ToLower(text)
97101
idx := strings.Index(lower, quote)
@@ -110,6 +114,8 @@ func stripPythonQuotedString(text string, quote string) (string, bool) {
110114
return text[idx+len(quote) : len(text)-len(quote)], true
111115
}
112116

117+
// isSupportedPythonDocstringPrefix accepts only the empty prefix and the raw/unicode docstring prefixes.
118+
// @intent avoid stripping byte-string or formatted-string docstrings whose escapes need different handling.
113119
func isSupportedPythonDocstringPrefix(prefix string) bool {
114120
if prefix == "" {
115121
return true

internal/cli/migrate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
// MigrateConfig contains the database and external migration source settings.
14+
// @intent carry the driver, DSN, and migration source needed for one explicit schema migration run.
1415
type MigrateConfig struct {
1516
DBDriver string
1617
DBDSN string
@@ -53,6 +54,7 @@ func newMigrateCmd(deps *Deps) *cobra.Command {
5354
return cmd
5455
}
5556

57+
// @intent resolve migration directory precedence between flag, config, and environment defaults.
5658
func resolveMigrationsDir(cmd *cobra.Command, flagValue string) string {
5759
if cmd.Flags().Changed("migrations-dir") {
5860
return flagValue

internal/cli/serve.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type ServeConfig struct {
4242
WebhookFailOnUnreadable bool
4343
}
4444

45+
// validateServeConfig checks that the serve configuration is self-consistent.
46+
// @intent reject invalid flag combinations before the server starts
47+
// @requires cfg.Transport is set; webhook fields are only validated when Transport == "streamable-http"
4548
func validateServeConfig(cfg ServeConfig) error {
4649
if cfg.Transport != "streamable-http" {
4750
return nil
@@ -92,6 +95,8 @@ func validateServeConfig(cfg ServeConfig) error {
9295
return nil
9396
}
9497

98+
// configuredCloneBaseURLs merges the singular and plural clone base URL flags into a deduplicated list.
99+
// @intent normalize clone base URL inputs from both legacy and current flags into a single ordered slice
95100
func configuredCloneBaseURLs(cfg ServeConfig) []string {
96101
baseURLs := append([]string(nil), cfg.RepoCloneBaseURLs...)
97102
if cfg.RepoCloneBaseURL != "" {
@@ -171,6 +176,8 @@ func newServeCmd(deps *Deps) *cobra.Command {
171176
return cmd
172177
}
173178

179+
// envInt reads an integer from an environment variable, returning fallback if unset or unparseable.
180+
// @intent provide env-based defaults for webhook worker flags without panicking on bad input
174181
func envInt(name string, fallback int) int {
175182
raw := strings.TrimSpace(os.Getenv(name))
176183
if raw == "" {
@@ -183,11 +190,15 @@ func envInt(name string, fallback int) int {
183190
return v
184191
}
185192

193+
// envIsSet reports whether an environment variable is present in the process environment.
194+
// @intent distinguish between an unset variable and one explicitly set to empty string
186195
func envIsSet(name string) bool {
187196
_, ok := os.LookupEnv(name)
188197
return ok
189198
}
190199

200+
// envDuration reads a time.Duration from an environment variable, returning fallback if unset or unparseable.
201+
// @intent provide env-based defaults for webhook timeout and retry delay flags without panicking on bad input
191202
func envDuration(name string, fallback time.Duration) time.Duration {
192203
raw := strings.TrimSpace(os.Getenv(name))
193204
if raw == "" {

internal/ctxns/namespace.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ package ctxns
33

44
import "context"
55

6+
// ctxKey is the unexported type used as the namespace context key to avoid collisions.
7+
// @intent isolate the namespace value in the context map from any other package's keys.
68
type ctxKey struct{}
79

810
const DefaultNamespace = "default"
911

12+
// Normalize replaces an empty namespace with DefaultNamespace, leaving other values unchanged.
13+
// @intent guarantee callers always observe a non-empty namespace string for store and query layers.
1014
func Normalize(ns string) string {
1115
if ns == "" {
1216
return DefaultNamespace

internal/docs/generator.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func (g *Generator) RunIndex() error {
109109
return g.writeIndex(groups)
110110
}
111111

112+
// validateDocGroups checks that every group's output path is safe before writing begins.
113+
// @intent prevent path-traversal writes before any file I/O is attempted
112114
func (g *Generator) validateDocGroups(groups []nodeGroup) error {
113115
for _, grp := range groups {
114116
if _, err := safeDocOutputPath(g.OutDir, grp.FilePath+".md"); err != nil {
@@ -177,6 +179,8 @@ func (g *Generator) loadEdges(nodeIDs []uint) (map[uint][]model.Edge, error) {
177179
return result, nil
178180
}
179181

182+
// generatedFiles builds the list of output paths that this run will produce.
183+
// @intent track expected output files so the manifest and prune step stay consistent
180184
func generatedFiles(groups []nodeGroup) []string {
181185
files := make([]string, 0, len(groups)+1)
182186
for _, grp := range groups {
@@ -186,6 +190,8 @@ func generatedFiles(groups []nodeGroup) []string {
186190
return files
187191
}
188192

193+
// manifestPath returns the namespace-scoped path for the docs manifest file.
194+
// @intent isolate manifest files per namespace so concurrent namespaces do not collide
189195
func (g *Generator) manifestPath() string {
190196
name := ".ccg-docs-manifest.json"
191197
if g.Namespace != "" {
@@ -194,6 +200,8 @@ func (g *Generator) manifestPath() string {
194200
return filepath.Join(g.OutDir, name)
195201
}
196202

203+
// loadManifest reads the previously saved manifest from disk, returning an empty manifest if none exists.
204+
// @intent restore the prior output file list so Run can compute stale files to prune
197205
func (g *Generator) loadManifest() (*manifest, error) {
198206
m := &manifest{Namespace: g.Namespace}
199207
data, err := os.ReadFile(g.manifestPath())
@@ -209,6 +217,9 @@ func (g *Generator) loadManifest() (*manifest, error) {
209217
return m, nil
210218
}
211219

220+
// saveManifest persists the list of generated files to disk for use by the next run's prune step.
221+
// @intent record which files were written so future runs can detect and remove stale docs
222+
// @sideEffect writes .ccg-docs-manifest[.namespace].json to g.OutDir
212223
func (g *Generator) saveManifest(files []string) error {
213224
data, err := json.MarshalIndent(manifest{Namespace: g.Namespace, Files: files}, "", " ")
214225
if err != nil {
@@ -220,6 +231,10 @@ func (g *Generator) saveManifest(files []string) error {
220231
return atomicWriteFile(g.manifestPath(), data, 0644)
221232
}
222233

234+
// pruneManaged deletes previously generated docs that are no longer in the current output set,
235+
// but only if the file starts with the managed marker to avoid removing user-edited files.
236+
// @intent clean up stale generated docs without touching manually created files
237+
// @sideEffect removes markdown files from g.OutDir that are no longer part of the current graph
223238
func (g *Generator) pruneManaged(previous, current []string) error {
224239
keep := map[string]bool{}
225240
for _, p := range current {

0 commit comments

Comments
 (0)