From 866742921d2f604db732a97a1e367177952a638b Mon Sep 17 00:00:00 2001 From: GitHub Copilot CLI Date: Mon, 13 Apr 2026 09:38:09 +0900 Subject: [PATCH] Handle directory inputs in to-markdown workflow Add explicit directory guidance and recursive conversion support so directory paths are not treated as single files and the workflow no longer stalls on folder inputs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../opencode-seed/commands/to-markdown.md | 9 ++-- .../instructions/markitdown-converter.md | 1 + .../skills/markitdown-converter/SKILL.md | 1 + .../markitdown-converter/scripts/convert.sh | 42 ++++++++++++++++++- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/.devcontainer/opencode-seed/commands/to-markdown.md b/.devcontainer/opencode-seed/commands/to-markdown.md index 0af9880..8ba74eb 100644 --- a/.devcontainer/opencode-seed/commands/to-markdown.md +++ b/.devcontainer/opencode-seed/commands/to-markdown.md @@ -9,18 +9,21 @@ Convert source content into Markdown using MarkItDown. ## Usage -`/to-markdown [output.md]` +`/to-markdown [output]` ## Execution 1. Parse `$ARGUMENTS` as: - first token: input path or URL - - optional second token: output file path + - optional second token: output path +2. If input is a directory: + - do not call `Read File` on the directory path + - require output to be a directory path and convert supported files recursively 2. Run: ```bash bash /home/vscode/.opencode/skills/markitdown-converter/scripts/convert.sh [output] ``` -3. If output path is provided, report the saved path. +3. If output path is provided, report the saved path(s). 4. If output path is omitted, return the generated Markdown in the response. diff --git a/.devcontainer/opencode-seed/instructions/markitdown-converter.md b/.devcontainer/opencode-seed/instructions/markitdown-converter.md index e05c279..4bc784a 100644 --- a/.devcontainer/opencode-seed/instructions/markitdown-converter.md +++ b/.devcontainer/opencode-seed/instructions/markitdown-converter.md @@ -2,5 +2,6 @@ When users ask to read, summarize, or analyze non-Markdown sources (PDF, DOCX, P Guidelines: - Prefer `/to-markdown ` for large inputs. +- If `` is a directory, never use `Read File` on that directory path; run `/to-markdown ` instead. - For small inputs, `/to-markdown ` and return inline Markdown is acceptable. - After conversion, continue analysis using the Markdown output only. diff --git a/.devcontainer/opencode-seed/skills/markitdown-converter/SKILL.md b/.devcontainer/opencode-seed/skills/markitdown-converter/SKILL.md index 1fa65d9..507e650 100644 --- a/.devcontainer/opencode-seed/skills/markitdown-converter/SKILL.md +++ b/.devcontainer/opencode-seed/skills/markitdown-converter/SKILL.md @@ -25,3 +25,4 @@ Use this skill when you need to transform non-Markdown sources (PDF, Office docs - If output is large, prefer writing to a file and then summarizing key sections. - Preserve the generated Markdown as an artifact when reproducibility is needed. +- When the input is a directory, pass an output directory and convert files in bulk instead of reading the directory as a file. diff --git a/.devcontainer/opencode-seed/skills/markitdown-converter/scripts/convert.sh b/.devcontainer/opencode-seed/skills/markitdown-converter/scripts/convert.sh index d18d081..696fdc7 100644 --- a/.devcontainer/opencode-seed/skills/markitdown-converter/scripts/convert.sh +++ b/.devcontainer/opencode-seed/skills/markitdown-converter/scripts/convert.sh @@ -10,11 +10,49 @@ INPUT="$1" OUTPUT="${2:-}" if ! command -v markitdown >/dev/null 2>&1; then - echo "markitdown is not installed. Install with: uv tool install markitdown" >&2 + echo "markitdown is not installed. Install with: uv tool install 'markitdown[all]'" >&2 exit 2 fi -if [ -n "$OUTPUT" ]; then +is_supported_file() { + local path="$1" + case "${path,,}" in + *.pdf|*.doc|*.docx|*.ppt|*.pptx|*.xls|*.xlsx|*.html|*.htm|*.txt|*.csv|*.json|*.xml) + return 0 + ;; + *) + return 1 + ;; + esac +} + +if [ -d "$INPUT" ]; then + if [ -z "$OUTPUT" ]; then + echo "Input is a directory. Provide an output directory as the second argument." >&2 + exit 3 + fi + + mkdir -p "$OUTPUT" + converted=0 + + while IFS= read -r -d '' source_file; do + if ! is_supported_file "$source_file"; then + continue + fi + + rel_path="${source_file#$INPUT/}" + target_path="$OUTPUT/${rel_path%.*}.md" + mkdir -p "$(dirname "$target_path")" + markitdown "$source_file" > "$target_path" + converted=$((converted + 1)) + echo "Saved Markdown: $target_path" + done < <(find "$INPUT" -type f -print0 | sort -z) + + if [ "$converted" -eq 0 ]; then + echo "No supported files found in: $INPUT" >&2 + exit 4 + fi +elif [ -n "$OUTPUT" ]; then markitdown "$INPUT" > "$OUTPUT" echo "Saved Markdown: $OUTPUT" else