update-source-map
Skill54 starsChanged 5 months agoMITView on GitHub
Create or update a structured source map (Markdown + JSON) for any project directory. Use when Codex needs to (1) index an unfamiliar workspace before doing work in it, (2) refresh a stale source map after files are added, removed, or renamed, (3) prepare quick navigation context for a multi-turn task that touches many files, or (4) preserve a reusable structured inventory of the project. Auto-detects whether to create a new map or update an existing one based on the presence of `x_temp/SOURCE_MAP.md` or `SOURCE_MAP.md` at the workspace root. Outputs are human-readable Markdown for navigation and structured JSON for programmatic queries. Curated file summaries in a separate JSON file persist across regenerations.
In this repository27 other files it gives its agents.
- alphaxivSkill
- arxivSkill
- doc-coauthoringSkill
- docxSkill
- drawio-diagramSkill
- figure-descriptionSkill
- formula-derivationSkill
- grant-proposalSkill
- mmx-cliSkill
- mock-reviewSkill
- novelty-checkSkill
- paper-readingSkill
- pdfSkill
- phd-benchmark-paper-templateSkill
- phd-figure-designerSkill
- phd-idea-evaluatorSkill
- phd-intro-drafterSkill
- phd-pre-submission-reviewerSkill
- phd-tech-paper-templateSkill
- phd-vibe-research-workflowSkill
- pptxSkill
- proof-writerSkill
- research-litSkill
- research-survey-loopSkill
- research-wikiSkill
- theme-factorySkill
- xlsxSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Do not trigger for: code refactoring, single-file edits, paper reading, or tasks unrelated to project navigation.
- Very specific: line 22
Run scripts/detect_existing.py <workspace_root> to decide between create and update mode.
- Very specific: line 31
If detection returns partial: true (only one of the two files exists), warn the user before proceeding.
- Distinctive: line 35
Before any execution, report the plan:
- Distinctive: line 43
If the user explicitly asked you to build or update the source map, proceed after stating the plan.
- Distinctive: line 47
Create the output directory if it doesn't exist:
- Distinctive: line 91
After building, always check the following.
- Very specific: line 97
Curated summaries not lost: if update mode, curated_summaries.json count should be ≥ previous count minus deleted files
- Very specific: line 101
If any check fails, fix the source (build_source_map.py) and re-run.
- Very specific: line 156
Lost curated knowledge: if curated summaries were stored in the build script, they were lost on every regeneration — fixed by extracting to …
- Very specific: line 157
PDF binary read attempts: avoid read_text() on PDFs.
- Distinctive: line 159
When you add new scripts, check the verify checklist in Step 5 for additional bugs to add.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Update Source Map
Overview
Build (or refresh) a structured index of a project directory. The skill always produces a Markdown SOURCE_MAP.md (primary, human-readable) and a JSON source_map.json (programmatic). A hand-curated curated_summaries.json is preserved across regenerations so curated per-file knowledge compounds over time.
When this skill runs
Trigger on requests like: - "build a source map for this project" - "update the source map" - "create a project index" - any task where Codex is about to do work in a workspace it doesn't already know well
Do not trigger for: code refactoring, single-file edits, paper reading, or tasks unrelated to project navigation.
Workflow
Step 1 — Decide mode (auto-detect)
Run scripts/detect_existing.py <workspace_root> to decide between create and update mode. Detection priority:
<workspace>/x_temp/SOURCE_MAP.md+x_temp/source_map.json→ update<workspace>/SOURCE_MAP.md+source_map.json→ update<workspace>/.codex/source_map.json→ update- Otherwise → create
The detection JSON has fields: mode, md_path, json_path, found_at. Pass --force-mode create|update to override.
If detection returns partial: true (only one of the two files exists), warn the user before proceeding.
Step 2 — Confirm the Run Plan
Before any execution, report the plan:
- Which mode (create / update) and why
- Which workspace to scan
- Where the outputs will go (default:
<workspace>/x_temp/) - Any custom exclusions or extensions
- Estimated file count from a quick
find(to set expectations)
If the user explicitly asked you to build or update the source map, proceed after stating the plan. If the user only asked what would happen, stop after the plan.
Step 3 — Setup
Create the output directory if it doesn't exist:
mkdir -p <workspace>/x_tempFor update mode with diff support, also keep the previous inventory:
mv <workspace>/x_temp/file_inventory.jsonl <workspace>/x_temp/file_inventory.prev.jsonl(only if regeneration would otherwise lose it)
Step 4 — Run the pipeline
Two equivalent options:
Option A — one-shot CLI (recommended for simple cases):
python3 scripts/regenerate.py <workspace_root> \
[--output-dir x_temp] \
[--force-mode create|update] \
[--exclude "extra_dir1,extra_dir2"] \
[--keep-prev-inventory]Option B — modular (use when intermediate inspection is useful):
# 1. Scan
python3 scripts/scan_workspace.py <workspace_root> \
--output <workspace>/x_temp/file_inventory.jsonl \
[--exclude "..."]
# 2. Build
python3 scripts/build_source_map.py \
--inventory <workspace>/x_temp/file_inventory.jsonl \
--md-out <workspace>/x_temp/SOURCE_MAP.md \
--json-out <workspace>/x_temp/source_map.json \
--curated-out <workspace>/x_temp/curated_summaries.json \
--mode create|update \
[--existing-curated <workspace>/x_temp/curated_summaries.json] \
[--prev-inventory <workspace>/x_temp/file_inventory.prev.jsonl]Step 5 — Verify (do not skip)
After building, always check the following. Each check has a known failure mode from real past runs:
- JSON validity:
python3 -c "import json; json.load(open('<json_path>'))"— must succeed - File count consistency: MD + PDF count in
source_map.json["totals"]must equallen(files)— catches partial writes - No type-mismatch in tables: spot-check 1 row of the Markdown —
r["type"]should appear in the type column (known bug: hardcoded "PDF" leaked into MD rows in earlier versions) - No root-file-as-folder bug: top-level rollup table should only contain real folders, not files at workspace root
- Curated summaries not lost: if update mode,
curated_summaries.jsoncount should be ≥ previous count minus deleted files - No
notes.assets/leakage:find <workspace>/x_temp -name "*.png" -o -name "*.jpg"should return nothing - Original files untouched:
find <workspace> -newer <workspace>/x_temp/SOURCE_MAP.md -type fshould not return anything (or only items insidex_temp/)
If any check fails, fix the source (build_source_map.py) and re-run. Do not patch the output Markdown by hand.
Step 6 — Hand off
Tell the user: - Mode used (create / update) - Number of files indexed - Where the artifacts live - Any diff highlights (in update mode) - Whether the curated_summaries.json was preserved / extended
Append the standard completion audit block (see "Completion audit" below).
Quick reference — script purposes
| Script | Purpose | Standalone? |
detect_existing.py | Decide create vs update by looking for existing artifacts | Yes (CLI) |
scan_workspace.py | Walk the workspace, emit per-file metadata + H2/H3 for .md | Yes (CLI) |
extract_headings.py | Extract H2/H3 from a single .md file (quick one-off) | Yes (CLI) |
build_source_map.py | Take inventory, build Markdown + JSON + curated | Yes (CLI) |
regenerate.py | One-shot orchestrator: detect → scan → build | Yes (CLI) |
Reference docs (load on demand)
references/format-spec.md— exact schema ofSOURCE_MAP.md,source_map.json,curated_summaries.json. Read when you need to know the output structure precisely.references/create-vs-update.md— the auto-detection rules, when to force-mode, and how curated summaries survive updates. Read when mode decision is unclear.references/exclusions-default.md— what's filtered out by default, how to add custom exclusions, and the "no modify" file boundary. Read before scanning an unfamiliar project.
Boundaries (non-negotiable)
- ❌ Never modify files outside the output directory (default:
<workspace>/x_temp/) - ❌ Never read PDF contents — metadata only
- ❌ Never index image assets (
*.assets/,*.images/, etc.) - ❌ Never touch files with names containing
no modify,no-edit,readonly,do not touch - ❌ Never overwrite
curated_summaries.jsonentries that were curated by hand - ❌ Never reformat a regeneration silently — if file count changes, surface the diff to the user
Completion audit
At the end of every run, append:
Completion audit:
- Mode: create | update
- Files indexed: <N> (MD: <M>, PDF: <P>)
- Outputs: <md_path>, <json_path>, <curated_path>
- Curated summaries preserved: yes (N entries) | no (create mode)
- Diff: <N> added, <M> removed (update mode only)
- Original files touched: no
- All 7 verify checks passed: yes | <failed checks>Lessons embedded in this skill
The skill encodes mistakes from a prior real-world run on a 43-file / 66MB personal knowledge base:
- Type-mismatch bug: hardcoding "PDF" in a loop over a folder that contains a README.md — fixed by using
r["type"]everywhere - Root-file-as-folder bug: top-level rollup loop treated root-level files as if they were subdirectories — fixed by skipping
len(parts) == 1incompute_top_rollups - Double-slash in tree root: render_tree passed both name and a trailing slash — fixed by single source of truth in
tree_root - Lost curated knowledge: if curated summaries were stored in the build script, they were lost on every regeneration — fixed by extracting to
curated_summaries.json - PDF binary read attempts: avoid
read_text()on PDFs; only inspect metadata
When you add new scripts, check the verify checklist in Step 5 for additional bugs to add.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

