Skip to content

Fix -local mode: don't pass project name as repo#2

Open
ha1t wants to merge 1 commit into
tomohiro-owada:mainfrom
ha1t:fix/local-mode-repos
Open

Fix -local mode: don't pass project name as repo#2
ha1t wants to merge 1 commit into
tomohiro-owada:mainfrom
ha1t:fix/local-mode-repos

Conversation

@ha1t
Copy link
Copy Markdown

@ha1t ha1t commented May 22, 2026

概要

-local モードでローカルディレクトリを指定して実行する際、tasksrepos フィールドに projectName を疑似的なリポジトリ名として詰めていた部分を修正します。

main.go:1012

- tasks = append(tasks, task{name: projectName, repos: []string{projectName}})
+ tasks = append(tasks, task{name: projectName, repos: nil})

背景・なぜ修正が必要か

-local モードでは localDir でローカルパスを直接指定するため、repos 配列にリポジトリを入れる必要はありません。にもかかわらず projectName(例: myproject)を repos
の要素として詰めていたため、以下の副作用が発生していました。

  1. generateWiki 内の repo ループでの誤動作
    for _, repo := range repos (main.go:513) が projectName を処理対象にしてしまう。isLocalPath(projectName) の判定で、たまたまカレントに同名ディレクトリがあれば誤って repoDir
    として追加され、無ければ "owner/repo" 形式エラーになりかけていました(先行修正 2dd3794 で validation はスキップ済みだが、根本原因は残存)。
  2. WikiResult.Repos に偽のリポジトリ名が混入
    JSON 出力に "repos": ["myproject"] のような実体のない名前が入っていました。
  3. LLM プロンプトの汚染
    structurePrompt / pagePrompt / writeHomeAndSidebar に渡される repos がそのまま Repositories: myproject のように LLM へのコンテキストに含まれ、生成内容のノイズになっていました。

generateWiki 側は localDir != "" の場合にすでに repoDirs を localDir から組み立てるロジックを持っている(main.go:504-512)ため、repos は nil で問題ありません。

動作確認

  • wikigen -local . ← OK
  • wikigen -local /path/to/repo myproject ← OK
  • 生成された wiki の Home/Sidebar、JSON 出力に projectName が repo として混入しないことを確認

関連コミット

  • 1fed195 Add -local flag: skip clone, use local directory
  • d5e09fb Fix -local flag: handle project name from positional arg
  • 2dd3794 Skip repo validation in -local mode(symptom の一部だけ抑え込んでいた)
  • 本PR: 根本原因を修正

In -local mode, the project name was being added as a repo entry,
which is incorrect. Set repos to nil so downstream handling treats
it as a pure local-directory task.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Fix -local mode: don't pass project name as repo

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix -local mode to not pass project name as fake repo entry
• Set repos to nil for local directory tasks
• Prevents downstream issues in repo loop processing
• Eliminates spurious repo names from JSON output and LLM prompts
Diagram
flowchart LR
  A["Local mode task creation"] -->|Before| B["repos: projectName"]
  A -->|After| C["repos: nil"]
  B -->|Causes| D["Repo loop errors"]
  B -->|Causes| E["Fake repos in output"]
  B -->|Causes| F["LLM prompt pollution"]
  C -->|Prevents| D
  C -->|Prevents| E
  C -->|Prevents| F

Loading

File Changes

1. main.go 🐞 Bug fix +1/-1

Remove project name from local mode repos

• Changed task creation in -local mode to set repos field to nil instead of
 []string{projectName}
• Fixes incorrect repo entry that was causing downstream processing errors
• Prevents fake repository names from appearing in JSON output and LLM prompts
• Aligns with existing logic that builds repoDirs from localDir when in local mode

main.go


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented May 22, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0)

Grey Divider


Remediation recommended

1. JSON repos becomes null 🐞 Bug ≡ Correctness
Description
In -local mode, tasks now pass repos=nil into generateWiki, and WikiResult.Repos is set to that nil
slice and encoded to JSON as null rather than an array. This is a breaking output contract for any
scripting that expects .repos to be an array.
Code

main.go[1012]

Evidence
The -local task now sets repos to nil, which is then copied into WikiResult and JSON-encoded in
-json mode; a nil slice encodes as null, changing the JSON output type for the repos field.

main.go[1006-1013]
main.go[117-126]
main.go[495-500]
main.go[1102-1106]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
In `-local` mode, `repos` is set to `nil`, which propagates into `WikiResult.Repos` and gets JSON-encoded as `null`. This changes the JSON shape for the `repos` field from an array to null.

### Issue Context
- `WikiResult.Repos` is a `[]string` with JSON tag `"repos"` and is emitted in `-json` output.
- `generateWiki` assigns `Repos: repos` directly.
- `encoding/json` encodes a nil slice as `null`.

### Fix
Initialize `repos` to an empty (non-nil) slice in `-local` mode (e.g., `[]string{}` or `make([]string, 0)`), so JSON output remains an array (`[]`).

### Fix Focus Areas
- main.go[1006-1013]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant