Skip to content

Commit a41f728

Browse files
committed
feat: enhance auto generate llms workflow
1 parent 2096030 commit a41f728

File tree

3 files changed

+58
-26
lines changed

3 files changed

+58
-26
lines changed

.github/workflows/generate-llms.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Generate CLIX Flutter LLMS
1+
name: Generate llms.txt
22

33
on:
44
workflow_dispatch:
55
inputs:
66
llm_mode:
77
description: 'Generation mode'
88
type: choice
9-
options: [changed, all]
9+
options: [ changed, all ]
1010
default: changed
1111
base:
1212
description: 'Base ref/tag/sha for compare (optional)'
@@ -16,16 +16,33 @@ on:
1616
description: 'Head ref/tag/sha for compare (optional)'
1717
type: string
1818
required: false
19+
workflow_call:
20+
inputs:
21+
llm_mode:
22+
description: 'Generation mode'
23+
type: string
24+
default: changed
25+
base:
26+
description: 'Base ref/tag/sha for compare (optional)'
27+
type: string
28+
required: false
29+
head:
30+
description: 'Head ref/tag/sha for compare (optional)'
31+
type: string
32+
required: false
33+
secrets:
34+
OPENAI_API_KEY:
35+
required: true
1936
release:
20-
types: [published]
37+
types: [ published ]
2138

2239
permissions:
2340
contents: write
2441
pull-requests: write
2542

2643
jobs:
2744
generate:
28-
name: Generate LLMS
45+
name: Generate llms.txt
2946
runs-on: ubuntu-latest
3047
env:
3148
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
@@ -140,9 +157,9 @@ jobs:
140157
script: |
141158
const defaultBranch = context.payload.repository.default_branch;
142159
const head = process.env.BRANCH;
143-
const title = 'chore: update CLIX Flutter LLMS index';
160+
const title = 'chore: update Clix Flutter llms.txt index';
144161
const body = [
145-
'This PR updates the generated CLIX Flutter SDK LLMS index.',
162+
'This PR updates the generated Clix Flutter SDK llms.txt index.',
146163
'',
147164
`- Triggered by: ${context.eventName}`,
148165
`- Range: ${process.env.COMPARE || '(none / full)'}`

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ jobs:
7272
7373
- name: Release to pub.dev
7474
run: dart pub publish --force
75+
76+
generate-llms:
77+
needs: release
78+
uses: ./.github/workflows/generate-llms.yml
79+
with:
80+
llm_mode: changed
81+
secrets: inherit

scripts/generate_llms.sh

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# CLIX Flutter LLMS generator (outputs llms.txt)
4+
# Clix Flutter llms.txt generator
55
# Usage:
66
# ./scripts/generate_llms.sh --llm-all
77
# ./scripts/generate_llms.sh --base <old> --head <new> [--llm]
@@ -484,10 +484,29 @@ if [[ -n "${BASE_REF:-}" && -n "${HEAD_REF:-}" ]]; then
484484
' 2>/dev/null | sed '/^$/d; s#^./##' | sort -u >> "$CHANGED_SET"
485485
else
486486
git fetch --no-tags --depth=1 origin "${BASE_REF}" "${HEAD_REF}" >/dev/null 2>&1 || true
487-
git diff --name-only "${BASE_REF}...${HEAD_REF}" 2>/dev/null | sed 's#^./##' | sort -u >> "$CHANGED_SET" || true
487+
# First try the standard symmetric diff (needs a merge base).
488+
echo "git diff --name-only ${BASE_REF}...${HEAD_REF} (local):" >&2
489+
DIFF_TMP="${SECTION_TMP_DIR}/git_diff_paths.txt"
490+
if git diff --name-only "${BASE_REF}...${HEAD_REF}" >"$DIFF_TMP" 2>/dev/null; then
491+
:
492+
else
493+
# If histories are unrelated (no merge base), fall back to two-dot diff.
494+
echo "git diff with '...' failed (likely no merge base); falling back to 'git diff ${BASE_REF} ${HEAD_REF}'" >&2
495+
git diff --name-only "${BASE_REF}" "${HEAD_REF}" >"$DIFF_TMP" 2>/dev/null || true
496+
fi
497+
sed 's#^./##' "$DIFF_TMP" | sort -u >> "$CHANGED_SET"
488498
fi
489499
fi
490500

501+
# Debug: print the raw CHANGED_SET to stderr (before any filtering) so we can
502+
# verify which paths will be considered for surgical updates.
503+
if [[ -s "$CHANGED_SET" ]]; then
504+
echo "Changed paths from compare range (${BASE_REF:-?}...${HEAD_REF:-?}):" >&2
505+
cat "$CHANGED_SET" >&2
506+
else
507+
echo "Changed paths set is empty for compare range (${BASE_REF:-?}...${HEAD_REF:-?})" >&2
508+
fi
509+
491510
# If we have an existing LLMS and a changed set, do TEXT-MODE update (surgical)
492511
if [[ -f "$EXISTING_LLMS_PATH" && -s "$CHANGED_SET" ]]; then
493512
OUTFILE="$STAGING_PATH"
@@ -501,26 +520,15 @@ if [[ -f "$EXISTING_LLMS_PATH" && -s "$CHANGED_SET" ]]; then
501520
abs_file="${REPO_ROOT}/${rel}"
502521
raw_url="$(rel_to_url "$rel")"
503522
dir_rel="$(dirname "$rel")"; dir_rel="${dir_rel:-.}"
504-
# If the line already exists and LLM is not requested, keep it verbatim
505-
if grep -F -q "](${raw_url}):" "$OUTFILE" >/dev/null 2>&1; then
506-
if [[ "$USE_LLM" != "true" ]]; then
507-
continue
508-
fi
509-
fi
510523
if [[ -f "$abs_file" ]]; then
511524
title="$(titleize "$(basename "$abs_file")")"
512-
# Default to existing description if present
513-
existing_line="$(awk -F '\t' -v u="$raw_url" '$1==u{print $0; exit}' "$EXISTING_MAP" 2>/dev/null || true)"
514-
desc="$(printf "%s" "$existing_line" | cut -f2- || true)"
515-
if [[ -z "$desc" ]]; then
516-
# Generate quickly (may call LLM if enabled)
517-
f_desc="$(first_comment_line "$abs_file" || true)"
518-
[[ -z "$f_desc" ]] && f_desc="Source file for ${title}"
519-
if [[ "$USE_LLM" == "true" ]]; then
520-
llm_desc="$(llm_describe_file "$rel" "$abs_file" "$raw_url" "$dir_rel" "$REPO_SLUG" || true)"
521-
[[ -n "$llm_desc" ]] && f_desc="$llm_desc"
522-
fi
523-
desc="$f_desc"
525+
# For changed files, always recompute the description from current source
526+
# and optionally enrich it via LLM, instead of reusing any previous text.
527+
desc="$(first_comment_line "$abs_file" || true)"
528+
[[ -z "$desc" ]] && desc="Source file for ${title}"
529+
if [[ "$USE_LLM" == "true" ]]; then
530+
llm_desc="$(llm_describe_file "$rel" "$abs_file" "$raw_url" "$dir_rel" "$REPO_SLUG" || true)"
531+
[[ -n "$llm_desc" ]] && desc="$llm_desc"
524532
fi
525533
newline="- [${title}](${raw_url}): ${desc}"
526534
replace_or_append_line "$rel" "$raw_url" "$newline" "$dir_rel"

0 commit comments

Comments
 (0)