|
| 1 | +name: 'TreeMapper' |
| 2 | +description: 'Export codebase structure and contents for AI/LLM context' |
| 3 | +author: 'nikolay-e' |
| 4 | + |
| 5 | +branding: |
| 6 | + icon: 'folder' |
| 7 | + color: 'blue' |
| 8 | + |
| 9 | +inputs: |
| 10 | + path: |
| 11 | + description: 'Directory to analyze' |
| 12 | + required: false |
| 13 | + default: '.' |
| 14 | + format: |
| 15 | + description: 'Output format (yaml, json, txt, md)' |
| 16 | + required: false |
| 17 | + default: 'yaml' |
| 18 | + output: |
| 19 | + description: 'Output file path' |
| 20 | + required: false |
| 21 | + default: 'tree.yaml' |
| 22 | + max-depth: |
| 23 | + description: 'Maximum traversal depth' |
| 24 | + required: false |
| 25 | + no-content: |
| 26 | + description: 'Skip file contents (structure only)' |
| 27 | + required: false |
| 28 | + default: 'false' |
| 29 | + max-file-bytes: |
| 30 | + description: 'Skip files larger than N bytes (0 for unlimited)' |
| 31 | + required: false |
| 32 | + ignore-file: |
| 33 | + description: 'Path to custom ignore file' |
| 34 | + required: false |
| 35 | + no-default-ignores: |
| 36 | + description: 'Disable default ignores' |
| 37 | + required: false |
| 38 | + default: 'false' |
| 39 | + python-version: |
| 40 | + description: 'Python version to use' |
| 41 | + required: false |
| 42 | + default: '3.11' |
| 43 | + |
| 44 | +outputs: |
| 45 | + output-file: |
| 46 | + description: 'Path to generated output file' |
| 47 | + value: ${{ steps.run.outputs.output-file }} |
| 48 | + token-count: |
| 49 | + description: 'Approximate token count' |
| 50 | + value: ${{ steps.run.outputs.token-count }} |
| 51 | + |
| 52 | +runs: |
| 53 | + using: 'composite' |
| 54 | + steps: |
| 55 | + - name: Set up Python |
| 56 | + uses: actions/setup-python@v5 |
| 57 | + with: |
| 58 | + python-version: ${{ inputs.python-version }} |
| 59 | + |
| 60 | + - name: Install treemapper |
| 61 | + shell: bash |
| 62 | + run: pip install treemapper |
| 63 | + |
| 64 | + - name: Run treemapper |
| 65 | + id: run |
| 66 | + shell: bash |
| 67 | + run: | |
| 68 | + ARGS="${{ inputs.path }}" |
| 69 | + ARGS="$ARGS -f ${{ inputs.format }}" |
| 70 | + ARGS="$ARGS -o ${{ inputs.output }}" |
| 71 | +
|
| 72 | + if [ -n "${{ inputs.max-depth }}" ]; then |
| 73 | + ARGS="$ARGS --max-depth ${{ inputs.max-depth }}" |
| 74 | + fi |
| 75 | +
|
| 76 | + if [ "${{ inputs.no-content }}" = "true" ]; then |
| 77 | + ARGS="$ARGS --no-content" |
| 78 | + fi |
| 79 | +
|
| 80 | + if [ -n "${{ inputs.max-file-bytes }}" ]; then |
| 81 | + ARGS="$ARGS --max-file-bytes ${{ inputs.max-file-bytes }}" |
| 82 | + fi |
| 83 | +
|
| 84 | + if [ -n "${{ inputs.ignore-file }}" ]; then |
| 85 | + ARGS="$ARGS -i ${{ inputs.ignore-file }}" |
| 86 | + fi |
| 87 | +
|
| 88 | + if [ "${{ inputs.no-default-ignores }}" = "true" ]; then |
| 89 | + ARGS="$ARGS --no-default-ignores" |
| 90 | + fi |
| 91 | +
|
| 92 | + # Capture stderr for token count |
| 93 | + OUTPUT=$(treemapper $ARGS 2>&1 >/dev/null) || true |
| 94 | + TOKEN_COUNT=$(echo "$OUTPUT" | grep -oE '^~?[0-9,]+ tokens' | head -1 || echo "unknown") |
| 95 | +
|
| 96 | + echo "output-file=${{ inputs.output }}" >> $GITHUB_OUTPUT |
| 97 | + echo "token-count=$TOKEN_COUNT" >> $GITHUB_OUTPUT |
| 98 | +
|
| 99 | + # Actually run it |
| 100 | + treemapper $ARGS |
0 commit comments