Skip to content

Latest commit

 

History

History
130 lines (93 loc) · 6.13 KB

deepwiki.md

File metadata and controls

130 lines (93 loc) · 6.13 KB

deepwiki.sh

Revision: 2 Last modified: 2026-12-04T16:05:44Z

Overview

Thin shell front end for the DeepWiki "Ask DeepWiki" badge engine. It is the interface callers use — hook steps, schedulers, operators — so nothing outside scripts/deepwiki/ needs to know the implementation is Python.

It deliberately adds nothing: no argument re-parsing, no defaults, no error translation, no exit-code remapping. Every decision, including the measured detection contract, lives in deepwiki.py, and the shell wrapper only locates the sibling module and execs the interpreter. That keeps exactly one place where the oracle logic can be wrong, and one place to test it.

The feature it fronts: if a project's own repository — or one of its declared upstreams — is genuinely indexed on DeepWiki, put this line in the project's README:

[![Ask DeepWiki](https://img.shields.io/badge/Ask-DeepWiki-6E4AFF)](https://deepwiki.com/<owner>/<repo>)

The image is shields.io; only the link points at DeepWiki. That split is not cosmetic — see Edge cases.

Prerequisites

  • bash (4.x or newer) and python3 3.10 or newer, standard library only. PYTHON overrides the interpreter.
  • Outbound HTTPS to mcp.deepwiki.com:443 for a real probe. No token, no account, no authentication.
  • For sync on a real project: a git working tree with at least one remote, or an enabled upstreams/*.sh recipe, or a repo = owner/name declaration in config/deepwiki_badge.conf.

Usage examples

Ask about one repository (the detection contract):

scripts/deepwiki/deepwiki.sh detect HelixDevelopment/constitution
# DEEPWIKI_DETECT state=INDEXED repo=HelixDevelopment/constitution exit=0 http=200 reason="index present"

Exit codes are the contract: 0 INDEXED, 1 NOT_INDEXED, 2 CANNOT_DETERMINE, 3 INVALID_IDENTIFIER, 64 usage. 2 is never a disguised 1: a blind or unreachable instrument withholds the badge instead of claiming absence.

Write the badge into a project, idempotently:

scripts/deepwiki/deepwiki.sh sync --root /path/to/project
# DEEPWIKI_SYNC verdict=PASS repo=acme/widget action=noop source=remote:origin:url probes=1

action is one of noop, inserted-row, appended-to-row, corrected, slot-updated. A second run on an already-correct README is a byte-identical no-op — it does not even touch the file's mtime.

See what the engine thinks your identity is, in probe order, without any network call:

scripts/deepwiki/deepwiki.sh candidates --root /path/to/project

Print the canonical badge line for a repository (no network, no file):

scripts/deepwiki/deepwiki.sh badge acme/widget

Dry run — resolve and plan, write nothing:

scripts/deepwiki/deepwiki.sh sync --root . --dry-run

Edge cases

A NULL is not an absence. The only thing separating "not indexed" from a malformed response is prose from the remote service. So unknown prose, an unparseable frame, a non-200 status, a missing structuredContent, or a response naming a different repository than the one asked for all yield CANNOT_DETERMINE, never NOT_INDEXED. The engine withholds the badge and says so.

A negative needs a control. When no candidate answers INDEXED, the engine probes a known-indexed control repository (facebook/react by default) with the same instrument in the same run. If the control is not seen as indexed, the instrument is blind and the verdict is CANNOT_DETERMINE, not a negative.

A three-segment identifier never reaches the network. The server accepts a/b/c as a host-qualified custom domain and answers the "Repository not found" prose, so it would become a false negative. REPO_RE rejects it locally first (exit 3).

A non-http(s) endpoint is refused. file:, ftp: and friends are rejected before any opener sees them.

A third-party outage never fails the caller. sync exits 0 on every verdict (PASS, SKIP, CANNOT-DETERMINE, DEFERRED). Only --strict (opt-in, never used by the hook wiring) turns a non-PASS into exit 1. An existing badge is never removed on a transient failure.

The badge image must be an actual image endpoint. https://deepwiki.com/badge.svg answers HTTP 429 text/html (a bot-protection page), so GitHub renders a broken picture. That was a real defect in this repository. The emitted image is always shields.io, which is why the output passes scripts/testing/verify_readme_badge_images.sh.

--offline touches no network at all and reports SKIP reason=feature_disabled_by_config. Offline is a deliberate opt-out, not a claim that the repository is unindexed.

Concurrency. A per-root advisory lock serialises runs; a second concurrent run reports verdict=DEFERRED reason=concurrent-run rather than racing the README.

Internal behaviour

  1. Locate deepwiki.py next to itself via BASH_SOURCE, verify python3 exists, and exec it with every argument unchanged.
  2. The interpreter's exit code becomes the wrapper's exit code by virtue of exec — there is no wrapper-level status handling to drift.
  3. If the interpreter is missing, print an actionable diagnostic and exit 64 (usage class), never a "not indexed" verdict and never a crash: a caller that wired this into a hook must see a configuration problem, not a fabricated repository verdict.

Related scripts

  • scripts/deepwiki/deepwiki.py — the engine: oracle, identity resolution, README writer, CLI.
  • scripts/deepwiki/test_deepwiki.sh — the hermetic test suite (62 cases).
  • scripts/deepwiki/mutation_test_deepwiki.sh — the paired §1.1 mutation test (11 mutations).
  • scripts/testing/verify_readme_badge_images.sh — proves a badge image is renderable; the emitted badge must pass it.
  • scripts/sync/verify_upstream_parity.sh — the upstream enumeration and URL normaliser this engine follows.
  • docs/guides/deepwiki_badge.md — the consumer-facing guide.

Last verified

2026-12-05 — bash scripts/deepwiki/test_deepwiki.sh → test_deepwiki: PASS 62/62 cases 0 failed. Live probe against mcp.deepwiki.com returned state=INDEXED for HelixDevelopment/constitution and state=NOT_INDEXED exit=1 for a fabricated repository.