|
| 1 | +Lets implement this feature: |
| 2 | + |
| 3 | +Extendable Project-Level Metadata Architecture for giv |
| 4 | + |
| 5 | +Objective |
| 6 | + |
| 7 | +Augment giv so that rich project metadata is collected once per invocation (early in the run pipeline) from: |
| 8 | + |
| 9 | +1. Known project types via provider scripts (e.g. Node, Python, Rust, Go). |
| 10 | + |
| 11 | +2. User configuration (override or supplement autodetected values) via .giv/config. |
| 12 | + |
| 13 | +3. Custom project type definitions allowing users to specify metadata or files to parse. |
| 14 | + |
| 15 | +The collected metadata—cached under .giv/cache—will be exposed to all prompt-building logic, enabling templates (announcements, release notes, README generation, etc.) to incorporate: |
| 16 | + |
| 17 | +title |
| 18 | + |
| 19 | +url (homepage or documentation) |
| 20 | + |
| 21 | +description |
| 22 | + |
| 23 | +repository\_url |
| 24 | + |
| 25 | +latest\_version |
| 26 | + |
| 27 | +language |
| 28 | + |
| 29 | +license |
| 30 | + |
| 31 | +author / authors |
| 32 | + |
| 33 | +dependencies (list) |
| 34 | + |
| 35 | +dev\_dependencies (list) |
| 36 | + |
| 37 | +scripts (build, test, etc.) |
| 38 | + |
| 39 | +vcs info (default branch, commit SHA, tag count) |
| 40 | + |
| 41 | +This POSIX-compliant design ensures portability across /bin/sh implementations. |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +High-Level Architecture Changes |
| 46 | + |
| 47 | +1. Metadata Phase: Add a metadata\_init call immediately after argument parsing in giv.sh. |
| 48 | + |
| 49 | +2. Provider Registry: Under project/providers/, each provider\_<id>.sh implements detection and collection functions in POSIX shell. |
| 50 | + |
| 51 | +3. Orchestrator: New project/metadata.sh sources providers, detects, prioritizes, collects, merges, caches, and exports metadata. |
| 52 | + |
| 53 | +4. Prompt Integration: Extend llm.sh’s build\_prompt to inject metadata from cache and support \${{meta.<key>}} tokens. |
| 54 | + |
| 55 | +5. Configuration: Add keys in .giv/config: |
| 56 | + |
| 57 | +GIV\_PROJECT\_TYPE to force a provider or set to "auto" for autodetection |
| 58 | + |
| 59 | +GIV\_PROJECT\_METADATA\_FILE for external .env file |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +Provider Interface (POSIX Shell) |
| 64 | + |
| 65 | +Each provider\_<id>.sh must define: |
| 66 | + |
| 67 | +# Detect presence (0 = yes, >0 = no) |
| 68 | + |
| 69 | +provider\_<id>\_detect() { |
| 70 | + |
| 71 | +# e.g. \[ -f "package.json" \] |
| 72 | + |
| 73 | +return 1 |
| 74 | +} |
| 75 | + |
| 76 | +# Collect metadata: output KEY\tVALUE per line |
| 77 | + |
| 78 | +provider\_<id>\_collect() { |
| 79 | + |
| 80 | +# echo "title\tMy Project" |
| 81 | + |
| 82 | +} |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +Directory Layout |
| 87 | + |
| 88 | +project/ |
| 89 | +metadata.sh # orchestrator |
| 90 | +providers/ |
| 91 | +provider\_node\_pkg.sh |
| 92 | +provider\_python\_pep621.sh |
| 93 | +provider\_generic\_git.sh |
| 94 | +.giv/ |
| 95 | +cache/ |
| 96 | +project\_metadata.env |
| 97 | +config # overrides |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +Simplified Orchestration Flow (POSIX Steps) |
| 102 | + |
| 103 | +1. Determine Provider: |
| 104 | + |
| 105 | +if [ "$GIV\_PROJECT\_TYPE" = "custom" ]; then |
| 106 | +[ -f "$GIV\_HOME/project\_provider.sh" ] && . "$GIV\_HOME/project\_provider.sh" |
| 107 | +elif [ "$GIV\_PROJECT\_TYPE" = "auto" ]; then |
| 108 | +for f in "$GIV\_LIB\_DIR/project/providers"/*.sh; do |
| 109 | +. "$f" |
| 110 | +provider\_detect=$(set | awk -F'=' '/^provider\_.\*\_detect=/ { sub("()","",\$1); print \$1 }') |
| 111 | +for fn in \$provider\_detect; do |
| 112 | +\$fn && DETECTED\_PROVIDER="\$fn" && break |
| 113 | +done |
| 114 | +[ -n "$DETECTED_PROVIDER" ] && break |
| 115 | +done |
| 116 | +else |
| 117 | +. "$GIV\_LIB\_DIR/project/providers/provider\_${GIV\_PROJECT\_TYPE}.sh" |
| 118 | +fi |
| 119 | + |
| 120 | +2. Collect Metadata: |
| 121 | + |
| 122 | +if [ -n "$DETECTED\_PROVIDER" ]; then |
| 123 | +coll=${DETECTED\_PROVIDER%_detect}\_collect |
| 124 | +$coll | while IFS="\t" read -r key val; do |
| 125 | +printf '%s=%s\n' "$key" "${val//"/\\"}" >> "$GIV\_CACHE\_DIR/project\_metadata.env" |
| 126 | +done |
| 127 | +fi |
| 128 | + |
| 129 | +3. Apply Overrides: |
| 130 | + |
| 131 | +[ -f "$GIV\_HOME/project\_metadata.env" ] && . "$GIV\_HOME/project\_metadata.env" |
| 132 | + |
| 133 | +4. Export: |
| 134 | + |
| 135 | +# shell export |
| 136 | + |
| 137 | +set -a |
| 138 | +. "$GIV\_CACHE\_DIR/project\_metadata.env" |
| 139 | +set +a |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +Cache Format |
| 144 | + |
| 145 | +project\_metadata.env: simple KEY=value lines |
| 146 | + |
| 147 | +Example project\_metadata.env: |
| 148 | + |
| 149 | +title=My Project |
| 150 | +author=Jane Doe |
| 151 | +latest\_version=1.2.3 |
| 152 | +repository\_url=https://github.com/org/repo.git |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +Prompt Token Usage |
| 157 | + |
| 158 | +Templates can use tokens like: |
| 159 | + |
| 160 | +Project: [title] (v[latest_version]) |
| 161 | +Home: [url] |
| 162 | +Repo: [repository_url] |
| 163 | +Desc: [description] |
| 164 | +License: [license] |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +Configuration (.giv/config) |
| 169 | + |
| 170 | +GIV\_PROJECT\_TYPE=auto |
| 171 | +GIV\_PROJECT\_METADATA\_FILE=metadata.env |
| 172 | +GIV\_PROJECT\_METADATA\_EXTRA<<'EOF' |
| 173 | +owner.team=platform |
| 174 | +tier=gold |
| 175 | +EOF |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +Testing & Validation Checklist |
| 180 | + |
| 181 | +\[ \] Providers detect correctly in mixed-type repos |
| 182 | + |
| 183 | +\[ \] Keys include title, url, description, repository\_url, latest\_version |
| 184 | + |
| 185 | +\[ \] Overrides apply with correct precedence |
| 186 | + |
| 187 | +\[ \] Cache files (.env) generate and load properly |
| 188 | + |
| 189 | +\[ \] Prompt tokens replace as expected |
| 190 | + |
| 191 | +\[ \] POSIX shell lint (shellcheck -s sh) |
| 192 | + |
| 193 | +\[ \] --refresh-metadata flag forces reload |
| 194 | + |
| 195 | +--- |
| 196 | + |
| 197 | +Implementation Checklist |
| 198 | + |
| 199 | +\[ \] Create project/metadata.sh orchestrator (POSIX) |
| 200 | + |
| 201 | +\[ \] Build built-in providers: node\_pkg, python\_pep621, generic\_git |
| 202 | + |
| 203 | +\[ \] Source custom providers from $GIV\_HOME/project\_provider.sh |
| 204 | + |
| 205 | +\[ \] Write metadata to .giv/cache/project\_metadata.env |
| 206 | + |
| 207 | +\[ \] Update giv.sh to call metadata\_init |
| 208 | + |
| 209 | +\[ \] Extend llm.sh build\_prompt for \${{meta.\*}} tokens |
| 210 | + |
| 211 | +\[ \] Add config parsing in args.sh or config.sh |
| 212 | + |
| 213 | +\[ \] Add --refresh-metadata support |
| 214 | + |
| 215 | +\[ \] Write Bats tests for detection, caching, overrides |
| 216 | + |
| 217 | +\[ \] Document usage in README |
0 commit comments