Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

ci(research): extract reusable LDR-research workflow + add issue-trigger caller (#3987)

LearningCircuit9755a900ebf4
diff --git a/.github/labels.yml b/.github/labels.yml
index 44a3edda47..5f1adb7215 100644
--- a/.github/labels.yml
+++ b/.github/labels.yml
@@ -23,3 +23,12 @@
- name: awaiting-codeowner
color: 'fef2c0'
description: Author has responded; needs codeowner re-review
+# LDR research trigger labels (used by .github/workflows/e2e-research-test.yml
+# and .github/workflows/issue-research.yml — applied manually by maintainers,
+# auto-removed by the workflow after the run completes):
+- name: ldr_research
+ color: '7057ff'
+ description: Trigger LDR research on this PR or issue
+- name: ldr_research_static
+ color: '7057ff'
+ description: Trigger LDR static-query regression run on this PR
diff --git a/.github/workflows/e2e-research-test.yml b/.github/workflows/e2e-research-test.yml
index bf11ae5745..0bd9f0b81c 100644
--- a/.github/workflows/e2e-research-test.yml
+++ b/.github/workflows/e2e-research-test.yml
@@ -13,17 +13,20 @@ on:
permissions: {} # Minimal top-level for OSSF Scorecard
jobs:
- research:
- name: LDR Research
- runs-on: ubuntu-latest
- environment: ci
+ build-query:
+ name: Assemble query
if: github.event.label.name == 'ldr_research' || github.event.label.name == 'ldr_research_static'
+ runs-on: ubuntu-latest
permissions:
contents: read
- pull-requests: write
- issues: write
+ outputs:
+ query: ${{ steps.assemble.outputs.query }}
+ header: ${{ steps.headers.outputs.header }}
+ subheader: ${{ steps.headers.outputs.subheader }}
env:
LABEL_NAME: ${{ github.event.label.name }}
+ MAX_DIFF_SIZE: ${{ vars.MAX_DIFF_SIZE || '8000' }}
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
@@ -36,140 +39,116 @@ jobs:
persist-credentials: false
fetch-depth: 0
- - name: Install dependencies
- run: sudo apt-get update && sudo apt-get install -y jq
-
- - name: Select model
- id: set-model
- env:
- LABEL: ${{ github.event.label.name }}
- MAIN_MODEL: ${{ vars.LDR_RESEARCH_MODEL || 'google/gemini-2.0-flash-001' }}
- CHEAP_MODEL: ${{ vars.LDR_RESEARCH_CHEAP_MODEL || 'google/gemini-2.0-flash-001' }}
+ - name: Build PR-research query
+ id: assemble
run: |
- # ldr_research_static = regression test → cheap model
- # ldr_research = deep PR analysis → main (configurable) model
- if [ "$LABEL" = "ldr_research_static" ]; then
- echo "model=$CHEAP_MODEL" >> "$GITHUB_OUTPUT"
+ if [ "$LABEL_NAME" = "ldr_research_static" ]; then
+ cat > query.txt <<'STATIC_EOF'
+ What is Local Deep Research and how does it work?
+ STATIC_EOF
else
- echo "model=$MAIN_MODEL" >> "$GITHUB_OUTPUT"
- fi
-
- - name: Get PR diff
- if: github.event.label.name == 'ldr_research'
- env:
- BASE_REF: ${{ github.event.pull_request.base.ref }}
- run: |
- git fetch origin "$BASE_REF"
- git diff "origin/$BASE_REF...HEAD" --no-color > diff.txt
- echo "Diff size: $(wc -c < diff.txt) bytes"
-
- - name: Set up PDM
- uses: pdm-project/setup-pdm@973541a5febeafcfdadf8a51211435be6ecfd90f # v4.5
- with:
- python-version: '3.12'
- cache: true
-
- - name: Install LDR
- run: pdm install
-
- - name: Run LDR Research
- env:
- OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
- SERPER_API_KEY: ${{ secrets.SERPER_API_KEY }}
- LDR_PROVIDER: ${{ vars.LDR_PROVIDER || 'openrouter' }}
- LDR_SEARCH_TOOL: ${{ vars.LDR_SEARCH_TOOL || 'serper' }}
- LDR_RESEARCH_MODEL: ${{ steps.set-model.outputs.model }}
- LDR_STRATEGY: ${{ vars.LDR_STRATEGY || 'langgraph-agent' }}
- MAX_DIFF_SIZE: ${{ vars.MAX_DIFF_SIZE || '8000' }}
- LDR_MODE: ${{ github.event.label.name == 'ldr_research_static' && 'static' || 'diff' }}
- run: |
- set +e
-
- # Run in appropriate mode
- if [ "$LDR_MODE" = "static" ]; then
- echo "Running in STATIC mode (fixed query for regression testing)"
- RESPONSE=$(pdm run python scripts/ldr-diff-research.py --mode static)
- else
- echo "Running in DIFF mode (researching PR changes)"
- RESPONSE=$(pdm run python scripts/ldr-diff-research.py --mode diff < diff.txt)
- fi
-
- EXIT_CODE=$?
- set -e
-
- echo "=== Script exit code: $EXIT_CODE ==="
- echo "=== Response (first 2000 chars): ==="
- echo "$RESPONSE" | head -c 2000
- echo ""
- echo "=== End response ==="
-
- # Check if it's valid JSON
- if ! echo "$RESPONSE" | jq . > /dev/null 2>&1; then
- echo "❌ Response is not valid JSON"
- exit 1
- fi
+ git fetch origin "$BASE_REF"
+ git diff "origin/$BASE_REF...HEAD" --no-color > diff.txt
+ DIFF_BYTES=$(wc -c < diff.txt)
+ echo "Diff size: $DIFF_BYTES bytes (cap: $MAX_DIFF_SIZE)"
+
+ head -c "$MAX_DIFF_SIZE" diff.txt > diff-trunc.txt
+ if [ "$DIFF_BYTES" -gt "$MAX_DIFF_SIZE" ]; then
+ printf '\n... (truncated)\n' >> diff-trunc.txt
+ fi
- # Check for errors in JSON
- ERROR=$(echo "$RESPONSE" | jq -r '.error // empty')
- if [ -n "$ERROR" ]; then
- echo "❌ Error: $ERROR"
- exit 1
+ {
+ cat <<'PROMPT_HEAD_EOF'
+ Based on these code changes, research relevant documentation,
+ best practices, and potential issues. Focus on any libraries, APIs, or patterns used.
+
+ Code changes:
+ PROMPT_HEAD_EOF
+ cat diff-trunc.txt
+ cat <<'PROMPT_TAIL_EOF'
+
+ Research topics to cover:
+ 1. Documentation for any libraries or APIs being used/modified
+ 2. Best practices for the patterns shown
+ 3. Known issues or gotchas related to these changes
+ 4. Security considerations if applicable
+ PROMPT_TAIL_EOF
+ } > query.txt
fi
- # Save full response for later steps
- echo "$RESPONSE" > response.json
-
- # Extract research summary
- echo "$RESPONSE" | jq -r '.research' > result.md
- echo "✅ Research completed"
+ # Multi-line GH Actions output via heredoc-style delimiter.
+ # Use a randomized delimiter so a query containing the literal
+ # delimiter on its own line cannot prematurely terminate the
+ # heredoc.
+ DELIM="LDR_QUERY_EOF_$$_${RANDOM}_$(date +%N)"
+ {
+ echo "query<<$DELIM"
+ cat query.txt
+ echo "$DELIM"
+ } >> "$GITHUB_OUTPUT"
- - name: Post Research Results
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ - name: Compute headers
+ id: headers
run: |
- # Get mode from response
- MODE=$(jq -r '.mode // "diff"' response.json)
-
- # Build comment header based on mode
- if [ "$MODE" = "static" ]; then
- HEADER="## 🧪 LDR Static Query Test Results"
- QUERY=$(jq -r '.query // empty' response.json)
- SUBHEADER="**Query:** $QUERY"
+ if [ "$LABEL_NAME" = "ldr_research_static" ]; then
+ echo "header=## 🧪 LDR Static Query Test Results" >> "$GITHUB_OUTPUT"
+ echo "subheader=**Query:** What is Local Deep Research and how does it work?" >> "$GITHUB_OUTPUT"
else
- HEADER="## 🔬 LDR Research Results"
- SUBHEADER="_Analysis of PR code changes_"
+ echo "header=## 🔬 LDR Research Results" >> "$GITHUB_OUTPUT"
+ echo "subheader=_Analysis of PR code changes_" >> "$GITHUB_OUTPUT"
fi
- # Extract sources and format them (API returns 'link' not 'url')
- SOURCES=$(jq -r '.sources[:10][] | "- [\(.title // "Source")](\(.link // .url // ""))"' response.json 2>/dev/null || echo "")
+ research:
+ name: Run LDR research
+ needs: build-query
+ uses: ./.github/workflows/ldr-research-reusable.yml
+ with:
+ query: ${{ needs.build-query.outputs.query }}
+ model: ${{ github.event.label.name == 'ldr_research_static' && (vars.LDR_RESEARCH_CHEAP_MODEL || 'google/gemini-2.0-flash-001') || (vars.LDR_RESEARCH_MODEL || 'google/gemini-2.0-flash-001') }}
+ provider: ${{ vars.LDR_PROVIDER || 'openrouter' }}
+ search-tool: ${{ vars.LDR_SEARCH_TOOL || 'serper' }}
+ strategy: ${{ vars.LDR_STRATEGY || 'langgraph-agent' }}
+ comment-header: ${{ needs.build-query.outputs.header }}
+ comment-subheader: ${{ needs.build-query.outputs.subheader }}
+ secrets:
+ OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
+ SERPER_API_KEY: ${{ secrets.SERPER_API_KEY }}
+
+ post-comment:
+ name: Post PR comment
+ needs: research
+ # always() so the label-removal step runs even if research was skipped
+ # (e.g. build-query failed). The download/post steps are guarded by
+ # needs.research.outputs.success == 'true' so they self-skip in that
+ # case.
+ if: always()
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ pull-requests: write
+ issues: write
+ env:
+ LABEL_NAME: ${{ github.event.label.name }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ steps:
+ - name: Harden the runner (Audit all outbound calls)
+ uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
+ with:
+ egress-policy: audit
- # Build comment
- {
- echo "$HEADER"
- echo ""
- echo "$SUBHEADER"
- echo ""
- cat result.md
- echo ""
- if [ -n "$SOURCES" ]; then
- echo "### 🔍 Search Sources"
- echo ""
- echo "$SOURCES"
- echo ""
- fi
- echo "---"
- echo "_Generated by [Local Deep Research](https://github.com/LearningCircuit/local-deep-research) E2E test_"
- } > comment.md
+ - name: Download research artifact
+ if: needs.research.outputs.success == 'true'
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ name: ${{ needs.research.outputs.comment-artifact-name }}
- gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} -F comment.md
+ - name: Post comment
+ if: needs.research.outputs.success == 'true'
+ run: |
+ gh pr comment "$PR_NUMBER" --repo "${{ github.repository }}" -F comment.md
- name: Remove label for re-triggering
if: always()
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- gh issue edit ${{ github.event.pull_request.number }} --remove-label "$LABEL_NAME" 2>/dev/null || true
-
- - name: Cleanup
- if: always()
- run: rm -f diff.txt result.md comment.md response.json
+ gh issue edit "$PR_NUMBER" --remove-label "$LABEL_NAME" 2>/dev/null || true
diff --git a/.github/workflows/issue-research.yml b/.github/workflows/issue-research.yml
new file mode 100644
index 0000000000..ef4317af8e
--- /dev/null
+++ b/.github/workflows/issue-research.yml
@@ -0,0 +1,130 @@
+name: Issue Research
+
+# When a maintainer applies the `ldr_research` label to an issue,
+# run LDR research on the issue title + body and post a comment
+# with two sections: a brief, cautious response for the reporter,
+# and adjacent context for maintainer triage.
+#
+# The same `ldr_research` label is reused from the PR workflow.
+# GitHub gates by event type (`on: issues:` here vs
+# `on: pull_request:` in e2e-research-test.yml), so they don't
+# conflict.
+
+on:
+ issues:
+ types: [labeled]
+
+permissions: {} # Minimal top-level for OSSF Scorecard
+
+jobs:
+ build-query:
+ name: Assemble query
+ if: github.event.label.name == 'ldr_research'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ outputs:
+ query: ${{ steps.assemble.outputs.query }}
+ env:
+ ISSUE_TITLE: ${{ github.event.issue.title }}
+ ISSUE_BODY: ${{ github.event.issue.body }}
+ steps:
+ - name: Harden the runner (Audit all outbound calls)
+ uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
+ with:
+ egress-policy: audit
+
+ - name: Sanitize and assemble query
+ id: assemble
+ run: |
+ # Strip control chars (defence-in-depth against weird issue
+ # bodies) and truncate to 4000 chars before embedding in the
+ # prompt. The issue body is semi-trusted user input — never
+ # eval'd, never shelled out, only passed to the LLM as text.
+ SAFE_TITLE=$(printf '%s' "$ISSUE_TITLE" | tr -d '\000-\010\013-\037\177' | head -c 500)
+ SAFE_BODY=$(printf '%s' "$ISSUE_BODY" | tr -d '\000-\010\013-\037\177' | head -c 4000)
+
+ {
+ cat <<'PROMPT_HEAD_EOF'
+ A user filed a GitHub issue against the Local Deep Research project. Produce a comment with two distinct sections:
+
+ (1) "**For the reporter**" — a brief, cautious, 2-4 sentence summary of likely diagnostic directions, framed as suggestions and not authoritative diagnosis. If you don't have enough context to be useful, say so plainly.
+
+ (2) "**For maintainers**" — adjacent external context: similar reports in other projects, relevant upstream library documentation, known issues with the components mentioned, and related discussions. Treat the maintainer as the primary audience for the substantive research.
+
+ Issue title:
+ PROMPT_HEAD_EOF
+ printf '%s\n' "$SAFE_TITLE"
+ cat <<'PROMPT_MID_EOF'
+
+ Issue body:
+ <<<ISSUE_BODY
+ PROMPT_MID_EOF
+ printf '%s\n' "$SAFE_BODY"
+ cat <<'PROMPT_TAIL_EOF'
+ ISSUE_BODY>>>
+ PROMPT_TAIL_EOF
+ } > query.txt
+
+ # Randomized delimiter so a query containing the literal delimiter
+ # on its own line cannot prematurely terminate the heredoc.
+ DELIM="LDR_QUERY_EOF_$$_${RANDOM}_$(date +%N)"
+ {
+ echo "query<<$DELIM"
+ cat query.txt
+ echo "$DELIM"
+ } >> "$GITHUB_OUTPUT"
+
+ research:
+ name: Run LDR research
+ needs: build-query
+ uses: ./.github/workflows/ldr-research-reusable.yml
+ with:
+ query: ${{ needs.build-query.outputs.query }}
+ model: ${{ vars.LDR_RESEARCH_MODEL || 'google/gemini-2.0-flash-001' }}
+ provider: ${{ vars.LDR_PROVIDER || 'openrouter' }}
+ search-tool: ${{ vars.LDR_SEARCH_TOOL || 'serper' }}
+ strategy: ${{ vars.LDR_STRATEGY || 'langgraph-agent' }}
+ comment-header: '## 🤖 LDR Research'
+ comment-subheader: '_Auto-generated context for maintainer triage and the reporter — see disclaimer below._'
+ secrets:
+ OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
+ SERPER_API_KEY: ${{ secrets.SERPER_API_KEY }}
+
+ post-comment:
+ name: Post issue comment
+ needs: research
+ # always() so the label-removal step runs even if research was skipped
+ # (e.g. build-query failed). The download/post steps are guarded by
+ # needs.research.outputs.success == 'true' so they self-skip in that
+ # case.
+ if: always()
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ issues: write
+ env:
+ ISSUE_NUMBER: ${{ github.event.issue.number }}
+ LABEL_NAME: ${{ github.event.label.name }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ steps:
+ - name: Harden the runner (Audit all outbound calls)
+ uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
+ with:
+ egress-policy: audit
+
+ - name: Download research artifact
+ if: needs.research.outputs.success == 'true'
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ name: ${{ needs.research.outputs.comment-artifact-name }}
+
+ - name: Post comment
+ if: needs.research.outputs.success == 'true'
+ run: |
+ gh issue comment "$ISSUE_NUMBER" --repo "${{ github.repository }}" -F comment.md
+
+ - name: Remove label for re-triggering
+ if: always()
+ run: |
+ gh issue edit "$ISSUE_NUMBER" --remove-label "$LABEL_NAME" 2>/dev/null || true
diff --git a/.github/workflows/ldr-research-reusable.yml b/.github/workflows/ldr-research-reusable.yml
new file mode 100644
index 0000000000..9ab5af92f4
--- /dev/null
+++ b/.github/workflows/ldr-research-reusable.yml
@@ -0,0 +1,273 @@
+name: LDR Research (reusable)
+
+# Reusable workflow that runs the LDR research script on a caller-supplied
+# query and produces a comment-ready markdown blob (uploaded as an
+# artifact). Callers download the artifact and post it to their target
+# (PR comment, issue comment, Reddit, etc.). This workflow does NOT post
+# anywhere — that's caller-specific.
+
+on:
+ workflow_call:
+ inputs:
+ query:
+ description: 'Fully-assembled research prompt. The caller does all prompt engineering.'
+ type: string
+ required: true
+ model:
+ description: 'OpenRouter model slug. Empty falls back to vars.LDR_RESEARCH_MODEL then a hard default.'
+ type: string
+ default: ''
+ provider:
+ description: 'LLM provider.'
+ type: string
+ default: 'openrouter'
+ search-tool:
+ description: 'Search tool.'
+ type: string
+ default: 'serper'
+ strategy:
+ description: 'LDR search strategy.'
+ type: string
+ default: 'langgraph-agent'
+ iterations:
+ description: 'Override the strategy iteration cap. 0 keeps the strategy default.'
+ type: number
+ default: 0
+ max-query-length:
+ description: 'Backstop truncation on the query string before invoking the script.'
+ type: number
+ default: 12000
+ max-sources:
+ description: 'Cap sources rendered in the markdown.'
+ type: number
+ default: 10
+ comment-header:
+ description: 'Top header line of the formatted markdown.'
+ type: string
+ default: '## LDR Research Results'
+ comment-subheader:
+ description: 'Optional second-line subheader.'
+ type: string
+ default: ''
+ comment-footer:
+ description: 'Footer line. Reddit will swap in a bot disclaimer.'
+ type: string
+ default: '_Generated by [Local Deep Research](https://github.com/LearningCircuit/local-deep-research) E2E test_'
+ include-sources-section:
+ description: 'Render a dedicated sources section. Reddit will set false to fit length caps.'
+ type: boolean
+ default: true
+ output-truncate-chars:
+ description: 'Truncate the rendered markdown to this many chars. 0 disables truncation.'
+ type: number
+ default: 0
+ runner:
+ description: 'Runner label.'
+ type: string
+ default: 'ubuntu-latest'
+ artifact-suffix:
+ description: 'Optional disambiguator appended to the artifact name. Use a unique value per matrix entry when calling this workflow multiple times in one caller run.'
+ type: string
+ default: ''
+ secrets:
+ OPENROUTER_API_KEY:
+ required: true
+ SERPER_API_KEY:
+ required: true
+ outputs:
+ comment-artifact-name:
+ description: 'Name of the artifact containing comment.md and response.json.'
+ value: ${{ jobs.research.outputs.comment-artifact-name }}
+ success:
+ description: "'true' if LDR returned valid non-error JSON."
+ value: ${{ jobs.research.outputs.success }}
+
+permissions: {}
+
+jobs:
+ research:
+ name: Run LDR research
+ runs-on: ${{ inputs.runner }}
+ environment: ci
+ permissions:
+ contents: read
+ outputs:
+ comment-artifact-name: ${{ steps.artifact-name.outputs.name }}
+ success: ${{ steps.run-script.outputs.success }}
+ env:
+ QUERY: ${{ inputs.query }}
+ MAX_QUERY_LENGTH: ${{ inputs.max-query-length }}
+ MAX_SOURCES: ${{ inputs.max-sources }}
+ COMMENT_HEADER: ${{ inputs.comment-header }}
+ COMMENT_SUBHEADER: ${{ inputs.comment-subheader }}
+ COMMENT_FOOTER: ${{ inputs.comment-footer }}
+ INCLUDE_SOURCES: ${{ inputs.include-sources-section }}
+ OUTPUT_TRUNCATE_CHARS: ${{ inputs.output-truncate-chars }}
+ steps:
+ - name: Harden the runner (Audit all outbound calls)
+ uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
+ with:
+ egress-policy: audit
+
+ - name: Checkout repository
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+ fetch-depth: 1
+
+ - name: Install jq
+ run: sudo apt-get update && sudo apt-get install -y jq
+
+ - name: Compute artifact name
+ id: artifact-name
+ env:
+ SUFFIX: ${{ inputs.artifact-suffix }}
+ run: |
+ NAME="ldr-research-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}"
+ if [ -n "$SUFFIX" ]; then
+ # Sanitize: artifact names allow [A-Za-z0-9._-] only.
+ SAFE_SUFFIX=$(printf '%s' "$SUFFIX" | tr -c 'A-Za-z0-9._-' '_')
+ NAME="${NAME}-${SAFE_SUFFIX}"
+ fi
+ echo "name=$NAME" >> "$GITHUB_OUTPUT"
+
+ - name: Resolve model
+ id: resolve-model
+ env:
+ INPUT_MODEL: ${{ inputs.model }}
+ REPO_VAR_MODEL: ${{ vars.LDR_RESEARCH_MODEL }}
+ run: |
+ if [ -n "$INPUT_MODEL" ]; then
+ echo "model=$INPUT_MODEL" >> "$GITHUB_OUTPUT"
+ elif [ -n "$REPO_VAR_MODEL" ]; then
+ echo "model=$REPO_VAR_MODEL" >> "$GITHUB_OUTPUT"
+ else
+ echo "model=google/gemini-2.0-flash-001" >> "$GITHUB_OUTPUT"
+ fi
+
+ - name: Set up PDM
+ uses: pdm-project/setup-pdm@973541a5febeafcfdadf8a51211435be6ecfd90f # v4.5
+ with:
+ python-version: '3.12'
+ cache: true
+
+ - name: Install LDR
+ run: pdm install
+
+ - name: Write query to file (with backstop truncation)
+ run: |
+ # Truncate by total byte count, not per-line. Avoids putting the
+ # entire query on the command line where it could exceed ARG_MAX.
+ QUERY_BYTES=$(printf '%s' "$QUERY" | wc -c)
+ if [ "$QUERY_BYTES" -gt "$MAX_QUERY_LENGTH" ]; then
+ printf '%s' "$QUERY" | head -c "$MAX_QUERY_LENGTH" > query.txt
+ printf '\n... (truncated)\n' >> query.txt
+ echo "Query truncated: $QUERY_BYTES -> $MAX_QUERY_LENGTH bytes"
+ else
+ printf '%s' "$QUERY" > query.txt
+ fi
+ echo "Final query size: $(wc -c < query.txt) bytes"
+
+ - name: Run LDR Research
+ id: run-script
+ env:
+ OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
+ SERPER_API_KEY: ${{ secrets.SERPER_API_KEY }}
+ LDR_PROVIDER: ${{ inputs.provider }}
+ LDR_SEARCH_TOOL: ${{ inputs.search-tool }}
+ LDR_RESEARCH_MODEL: ${{ steps.resolve-model.outputs.model }}
+ LDR_STRATEGY: ${{ inputs.strategy }}
+ ITERATIONS: ${{ inputs.iterations }}
+ run: |
+ set +e
+ if [ "$ITERATIONS" -gt 0 ] 2>/dev/null; then
+ pdm run python scripts/ldr-research.py --iterations "$ITERATIONS" \
+ < query.txt > response.json
+ else
+ pdm run python scripts/ldr-research.py < query.txt > response.json
+ fi
+ set -e
+
+ echo "=== Response (first 2000 chars): ==="
+ head -c 2000 response.json
+ echo ""
+ echo "=== End response ==="
+
+ # Validate JSON shape
+ if ! jq . response.json > /dev/null 2>&1; then
+ echo "::error::Response is not valid JSON"
+ echo "success=false" >> "$GITHUB_OUTPUT"
+ exit 1
+ fi
+
+ ERROR=$(jq -r '.error // empty' response.json)
+ if [ -n "$ERROR" ]; then
+ echo "::error::LDR error: $ERROR"
+ echo "success=false" >> "$GITHUB_OUTPUT"
+ exit 1
+ fi
+
+ echo "success=true" >> "$GITHUB_OUTPUT"
+ echo "✅ Research completed"
+
+ - name: Build comment markdown
+ run: |
+ jq -r '.research' response.json > result.md
+
+ # Optional sources section
+ if [ "$INCLUDE_SOURCES" = "true" ]; then
+ SOURCES=$(jq -r --argjson cap "$MAX_SOURCES" \
+ '.sources[:$cap][] | "- [\(.title // "Source")](\(.link // .url // ""))"' \
+ response.json 2>/dev/null || echo "")
+ else
+ SOURCES=""
+ fi
+
+ {
+ echo "$COMMENT_HEADER"
+ echo ""
+ if [ -n "$COMMENT_SUBHEADER" ]; then
+ echo "$COMMENT_SUBHEADER"
+ echo ""
+ fi
+ cat result.md
+ echo ""
+ if [ -n "$SOURCES" ]; then
+ echo "### 🔍 Search Sources"
+ echo ""
+ echo "$SOURCES"
+ echo ""
+ fi
+ echo "---"
+ echo "$COMMENT_FOOTER"
+ } > comment.md
+
+ # Optional truncation (Reddit will use this)
+ if [ "$OUTPUT_TRUNCATE_CHARS" -gt 0 ] 2>/dev/null; then
+ CURRENT=$(wc -c < comment.md)
+ if [ "$CURRENT" -gt "$OUTPUT_TRUNCATE_CHARS" ]; then
+ # Truncate at last paragraph break before the limit, with a budget
+ # for the trailing marker.
+ MARKER='…[truncated]'
+ BUDGET=$((OUTPUT_TRUNCATE_CHARS - ${#MARKER} - 1))
+ head -c "$BUDGET" comment.md > comment.md.tmp
+ # Trim trailing partial line so we end on a clean paragraph
+ awk 'BEGIN{RS=""} {gsub(/[[:space:]]+$/,""); print}' \
+ comment.md.tmp > comment.md
+ echo "" >> comment.md
+ echo "$MARKER" >> comment.md
+ rm -f comment.md.tmp
+ echo "Truncated comment.md to $OUTPUT_TRUNCATE_CHARS chars."
+ fi
+ fi
+
+ echo "Final comment.md size: $(wc -c < comment.md) bytes"
+
+ - name: Upload research artifact
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: ${{ steps.artifact-name.outputs.name }}
+ path: |
+ comment.md
+ response.json
+ retention-days: 7
diff --git a/docs/ci/workflow-status.md b/docs/ci/workflow-status.md
index 97a5689034..6fe328d804 100644
--- a/docs/ci/workflow-status.md
+++ b/docs/ci/workflow-status.md
@@ -25,7 +25,7 @@
<!-- BEGIN GENERATED -->
-**63 workflows:** 1 disabled · 1 stale · 2 manual-only · 59 active
+**65 workflows:** 1 disabled · 2 stale · 2 manual-only · 60 active
## ⚠ Disabled workflows
@@ -37,6 +37,7 @@
| Workflow | Cron | Last successful run |
|---|---|---|
+| `osv-scanner.yml` | `39 12 * * 1` | never |
| `update-precommit-hooks.yml` | `0 8 * * 5` | never |
## ℹ Manual-only by design
@@ -83,7 +84,7 @@
| `playwright-webkit-tests.yml` | ✅ | this week | workflow_call, manual, schedule(0 2 * * *) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/playwright-webkit-tests.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/playwright-webkit-tests.yml) |
| `pre-commit.yml` | ⊘ | this week | PR, workflow_call, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/pre-commit.yml) |
| `puppeteer-e2e-tests.yml` | ✅ | this week | PR, workflow_call, manual, schedule(0 2 * * 0) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/puppeteer-e2e-tests.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/puppeteer-e2e-tests.yml) |
-| `responsive-ui-tests-enhanced.yml` | ✅ | this week | workflow_call, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/responsive-ui-tests-enhanced.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/responsive-ui-tests-enhanced.yml) |
+| `responsive-ui-tests-enhanced.yml` | ❌ | this week | workflow_call, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/responsive-ui-tests-enhanced.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/responsive-ui-tests-enhanced.yml) |
| `security-file-write-check.yml` | ⊘ | this week | PR, workflow_call, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/security-file-write-check.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/security-file-write-check.yml) |
| `validate-image-pinning.yml` | ⊘ | this week | PR, workflow_call, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/validate-image-pinning.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/validate-image-pinning.yml) |
| `vulture-dead-code.yml` | ✅ | this week | workflow_call, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/vulture-dead-code.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/vulture-dead-code.yml) |
@@ -94,10 +95,9 @@
|---|---|---|---|---|
| `compose-published-smoke.yml` | — | never | manual, schedule(0 5 * * 1) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/compose-published-smoke.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/compose-published-smoke.yml?query=event%3Aschedule) |
| `fuzz.yml` | ✅ | this week | schedule(0 0 * * 0), manual, PR | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/fuzz.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/fuzz.yml?query=event%3Aschedule) |
-| `gitleaks.yml` | ✅ | this week | PR, manual, schedule(0 3 * * *) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/gitleaks.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/gitleaks.yml?query=event%3Aschedule) |
-| `ossf-scorecard.yml` | ✅ | this week | branch_protection_rule, schedule(0 8 * * 1), manual, push:main | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ossf-scorecard.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ossf-scorecard.yml?query=event%3Aschedule) |
-| `osv-scanner-scheduled.yml` | ✅ | this week | push:main, schedule(41 21 * * 1), manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/osv-scanner-scheduled.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/osv-scanner-scheduled.yml?query=event%3Aschedule) |
-| `osv-scanner.yml` | ✅ | this week | PR, merge_group, schedule(39 12 * * 1), manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/osv-scanner.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/osv-scanner.yml?query=event%3Aschedule) |
+| `gitleaks.yml` | ⏳ | this week | PR, manual, schedule(0 3 * * *) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/gitleaks.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/gitleaks.yml?query=event%3Aschedule) |
+| `ossf-scorecard.yml` | ⏳ | this week | branch_protection_rule, schedule(0 8 * * 1), manual, push:main | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ossf-scorecard.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ossf-scorecard.yml?query=event%3Aschedule) |
+| `osv-scanner-scheduled.yml` | ⏳ | this week | push:main, schedule(41 21 * * 1), manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/osv-scanner-scheduled.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/osv-scanner-scheduled.yml?query=event%3Aschedule) |
| `release-gate.yml` | ✅ | this week | workflow_call, manual, schedule(0 2 * * *) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/release-gate.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/release-gate.yml?query=event%3Aschedule) |
| `sbom.yml` | ✅ | this week | manual, schedule(0 10 * * 3), release | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/sbom.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/sbom.yml?query=event%3Aschedule) |
| `update-dependencies.yml` | ✅ | this week | workflow_call, manual, schedule(0 8 * * 3) | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/update-dependencies.yml/badge.svg?event=schedule)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/update-dependencies.yml?query=event%3Aschedule) |
@@ -109,7 +109,7 @@
|---|---|---|---|---|
| `advanced-search-reminder.yml` | ✅ | this week | PR | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/advanced-search-reminder.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/advanced-search-reminder.yml) |
| `ai-code-reviewer.yml` | ✅ | this week | PR | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ai-code-reviewer.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ai-code-reviewer.yml) |
-| `check-workflow-status.yml` | ✅ | this week | PR, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/check-workflow-status.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/check-workflow-status.yml) |
+| `check-workflow-status.yml` | ❌ | this week | PR, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/check-workflow-status.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/check-workflow-status.yml) |
| `claude-code-review.yml` | · | this week | PR | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/claude-code-review.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/claude-code-review.yml) |
| `danger-zone-alert.yml` | ✅ | this week | PR | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/danger-zone-alert.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/danger-zone-alert.yml) |
| `dependency-review.yml` | ✅ | this week | PR, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/dependency-review.yml) |
@@ -118,7 +118,7 @@
| `labels-sync.yml` | ✅ | this week | push:main, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/labels-sync.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/labels-sync.yml) |
| `mcp-tests.yml` | ✅ | this week | push:main,dev, PR, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/mcp-tests.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/mcp-tests.yml) |
| `pr-triage.yml` | ✅ | this week | PR, pull_request_review | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/pr-triage.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/pr-triage.yml) |
-| `release.yml` | ⏳ | this week | push:main, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/release.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/release.yml) |
+| `release.yml` | — | this week | push:main, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/release.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/release.yml) |
| `version_check.yml` | ✅ | this week | push:main, manual | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/version_check.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/version_check.yml) |
| `welcome-first-time.yml` | ✅ | this week | PR-target | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/welcome-first-time.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/welcome-first-time.yml) |
@@ -132,6 +132,9 @@
## Other
-_None._
+| Workflow | Status | Last activity | Trigger | Live badge |
+|---|---|---|---|---|
+| `issue-research.yml` | — | never | issues | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/issue-research.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/issue-research.yml) |
+| `ldr-research-reusable.yml` | — | never | workflow_call | [![status](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ldr-research-reusable.yml/badge.svg)](https://github.com/LearningCircuit/local-deep-research/actions/workflows/ldr-research-reusable.yml) |
<!-- END GENERATED -->
diff --git a/scripts/ldr-diff-research.py b/scripts/ldr-research.py
similarity index 66%
rename from scripts/ldr-diff-research.py
rename to scripts/ldr-research.py
index 0dc537dcc5..a25759c72e 100755
--- a/scripts/ldr-diff-research.py
+++ b/scripts/ldr-research.py
@@ -1,20 +1,20 @@
#!/usr/bin/env python3
"""
-LDR Diff Research Script
+LDR Research Script
-Reads a code diff from stdin and uses Local Deep Research to find
-relevant documentation, best practices, and known issues.
+Reads a research query from stdin and uses Local Deep Research to find
+relevant documentation, sources, and context. Returns JSON with the
+research output.
Usage:
- # Diff mode (default) - research a code diff
- cat diff.txt | python scripts/ldr-diff-research.py
- git diff HEAD~1 | python scripts/ldr-diff-research.py
+ # Pipe a query from stdin
+ echo "What is RAG?" | python scripts/ldr-research.py
- # Static mode - run a fixed query for regression testing
- python scripts/ldr-diff-research.py --mode static
+ # Or pass a file
+ python scripts/ldr-research.py < query.txt
# With CLI arguments (easier local testing)
- python scripts/ldr-diff-research.py --provider openrouter --model gpt-4o < diff.txt
+ python scripts/ldr-research.py --provider openrouter --model gpt-4o < query.txt
Output: JSON with research results, sources, and findings.
@@ -25,7 +25,6 @@ Environment variables (can be overridden by CLI args):
LDR_SEARCH_TOOL - Search tool (default: serper)
LDR_RESEARCH_MODEL - Model name (default: google/gemini-2.0-flash-001 for openrouter)
LDR_STRATEGY - Search strategy (default: langgraph-agent)
- MAX_DIFF_SIZE - Max diff size in bytes (default: 8000)
Note: This uses the programmatic API and does NOT require a running LDR server.
"""
@@ -35,9 +34,6 @@ import json
import os
import sys
-# Default static query for regression testing
-DEFAULT_STATIC_QUERY = "What is Local Deep Research and how does it work?"
-
def make_serializable(obj):
"""Convert objects to JSON-serializable format."""
@@ -64,13 +60,7 @@ def make_serializable(obj):
def parse_args():
parser = argparse.ArgumentParser(
- description="Run LDR research on code diffs or static queries"
- )
- parser.add_argument(
- "--mode",
- choices=["diff", "static"],
- default=os.environ.get("LDR_MODE", "diff"),
- help="Research mode: 'diff' for PR diffs, 'static' for fixed query",
+ description="Run LDR research on a query read from stdin"
)
parser.add_argument(
"--provider",
@@ -97,60 +87,22 @@ def parse_args():
"langgraph_agent.max_iterations from settings)."
),
)
- parser.add_argument(
- "--max-diff-size",
- type=int,
- default=int(os.environ.get("MAX_DIFF_SIZE", "8000")),
- help="Max diff size in bytes (default: 8000)",
- )
parser.add_argument(
"--strategy",
default=os.environ.get("LDR_STRATEGY", "langgraph-agent"),
help="Search strategy name (default: langgraph-agent)",
)
- parser.add_argument(
- "--static-query",
- default=os.environ.get("LDR_STATIC_QUERY", DEFAULT_STATIC_QUERY),
- help=f"Query for static mode (default: '{DEFAULT_STATIC_QUERY}')",
- )
return parser.parse_args()
def main():
args = parse_args()
- # Determine query based on mode
- if args.mode == "static":
- query = args.static_query
- diff = None
- else:
- # Read diff from stdin
- diff = sys.stdin.read()
- if not diff.strip():
- print(
- json.dumps(
- {
- "error": "No diff provided (use --mode static for fixed query)"
- }
- )
- )
- sys.exit(1)
-
- # Truncate if too large
- if len(diff) > args.max_diff_size:
- diff = diff[: args.max_diff_size] + "\n... (truncated)"
-
- query = f"""Based on these code changes, research relevant documentation,
-best practices, and potential issues. Focus on any libraries, APIs, or patterns used.
-
-Code changes:
-{diff}
-
-Research topics to cover:
-1. Documentation for any libraries or APIs being used/modified
-2. Best practices for the patterns shown
-3. Known issues or gotchas related to these changes
-4. Security considerations if applicable"""
+ # Read query from stdin
+ query = sys.stdin.read().strip()
+ if not query:
+ print(json.dumps({"error": "No query provided on stdin"}))
+ sys.exit(1)
# Default model for OpenRouter if not specified
model_name = args.model
@@ -198,7 +150,7 @@ Research topics to cover:
kwargs = {
"query": query,
"provider": args.provider,
- "search_tool": args.search_tool, # Explicitly pass search_tool
+ "search_tool": args.search_tool,
"settings_snapshot": settings,
"programmatic_mode": True,
"search_strategy": args.strategy,
@@ -218,17 +170,12 @@ Research topics to cover:
# Build output - make sure everything is JSON serializable
output = {
- "mode": args.mode,
"research": research_output,
"sources": make_serializable(result.get("sources", [])),
"findings": make_serializable(result.get("findings", [])),
"iterations": result.get("iterations"),
}
- # Include query for static mode (for verification)
- if args.mode == "static":
- output["query"] = query
-
print(json.dumps(output))
except Exception as e: