Skip to content
Back to search

econ-writing-skill

Agent Skill that transforms AI assistants into expert economics paper writers. Synthesizes 50+ guides by Cochrane, McCloskey, Shapiro, Head, Bellemare, Goldin, Kremer. Compatible with Claude Code and OpenAI Codex.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/hanlulong--econ-writing-skill/badge.svg)](/listings/hanlulong--econ-writing-skill)

HTML

<a href="/listings/hanlulong--econ-writing-skill"><img src="/api/listings/hanlulong--econ-writing-skill/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Open Codex or Claude Code in any project and paste this prompt:

Install or update Econ Write as a standalone skill for the client I am using. Read and follow https://github.com/hanlulong/econ-writing-skill/blob/main/INSTALL.md. Handle same-client migration, backups, and verification yourself. Do not install for or change the other client. Do not ask me to run commands. Finish with a concise result.

Use the same prompt for a first installation and rerun it whenever you want to update or safely migrate from a native plugin. It installs only for the client receiving the prompt.

For alternative installation methods, updates, migration, and troubleshooting, see [Installation and updates](INSTALL.md). Use only one installation method per client.

---

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 237 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Econ Writing Skill
  2. **An Agent Skill that transforms AI assistants into expert economics paper writers, synthesizing best practices from 50+ authoritative guides by Nobel laureates, Clark Medal winners, and leading economists.**
  3. [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
  4. [![Agent Skills](https://img.shields.io/badge/Agent%20Skills-Compatible-green.svg)](https://agentskills.io)
  5. [![Claude Code](https://img.shields.io/badge/Claude%20Code-Ready-blueviolet.svg)](https://docs.anthropic.com/en/docs/claude-code)
  6. [![OpenAI Codex](https://img.shields.io/badge/OpenAI%20Codex-Ready-black.svg)](https://openai.com/index/codex/)
  7. ---
  8. ## What Is This?
  9. Econ Writing Skill is an open-source [Agent Skill](https://agentskills.io) that gives AI coding assistants deep knowledge of how to write economics papers. It distills actionable advice from over 50 guides by John Cochrane, Deirdre McCloskey, Jesse Shapiro, Keith Head, Marc Bellemare, Claudia Goldin, Edward Glaeser, Michael Kremer, and many others into a single structured skill file. Compatible with the Agent Skills open standard, it works with Claude Code and OpenAI Codex out of the box.
  10. It is part of a suite covering the rest of the paper's life: [**econ-paper-review-skill**](https://github.com/hanlulong/econ-paper-review-skill) reviews the finished draft like a journal referee — an AI referee report with verified comments and a revision plan — and [**econ-slides-skill**](https://github.com/hanlulong/econ-slides-skill) turns the paper into a professional LaTeX/Beamer talk with a timed speaker script.
  11. ---
  12. ## Key Features
  13. ### Writing & Structure
  14. - **Works for all paper types** -- Applied empirical, pure theory, mixed theory-empirical, structural, and descriptive papers each get tailored structure and guidance
  15. - **Dedicated formulas for every major section** -- Abstract (4-part formula), Introduction (Head's formula), Model Section (Glaeser/Varian), Data Section, Conclusion (3-part formula), Title (with evaluation criteria)
  16. - **Identification strategy guidance** -- Specific writing advice for 13 strategies: RCT, DiD (including staggered), IV, RDD, Synthetic Control, Synthetic DiD, Bunching, Shift-Share/Bartik, Event Studies, ML for Causal Inference, Structural Estimation, Descriptive, plus guidance for papers using multiple strategies
  17. - **Theory paper support** -- Model presentation, proposition writing, and Glaeser's "start with an example" approach
  18. - **Field-specific conventions** -- Macro (calibration tables, IRFs, DSGE), trade (gravity, PPML), development (CONSORT, cost-effectiveness), finance (Fama-MacBeth, winsorization)
  19. ### Style & Quality
  20. - **Style rules from McCloskey and Cochrane** -- Active voice, concrete language, triangular structure, reader-first writing
  21. - **Anti-AI writing patterns** -- Eliminate telltale AI-generated writing (banned words, uniform sentence length, generic phrasing) and write like a real economist
  22. - **Title evaluation framework** -- Score titles on clarity, specificity, length, and memorability with good/bad examples
  23. - **Citation integrity** -- Anti-hallucination guidance for verifying references, distinguishing working paper vs. published versions
  24. - **Economic significance framework** -- Translate coefficients into meaningful units, policy benchmarks, and back-of-envelope calculations
  25. - **Tables and figures best practices** -- Self-contained captions, figure vs. table trade-offs, data visualization from Schwabish (JEP)
  26. ### Review & Assessment
  27. - **Paper review and audit mode** -- Simulated 3-reviewer feedback (Methodologist, Field Expert, Writing Critic) with a 100-point scoring rubric
  28. - **Pre-submission checklist** -- 24-item checklist covering content, style, and modern standards
  29. - **Evaluation test suite** -- 18 test cases for benchmarking skill output quality
  30. ### Academic Workflow
  31. - **Job market paper (JMP) guidance** -- Title, abstract, introduction polish, length, signaling breadth
  32. - **Grant proposal writing** -- NSF, ERC proposal guidance: feasibility, budget justification, timeline, selling a plan vs. presenting findings
  33. - **Referee response guidance** -- Point-by-point response structure for revise-and-resubmit
  34. - **Policy brief and op-ed writing** -- Translate findings for non-academic audiences with plain language and concrete recommendations
  35. - **Working paper to journal conversion** -- Cutting strategy, journal-specific length norms (AER, AER Insights, REStat), appendix organization
  36. - **Dissertation structure** -- Three-essays format, chapter structure, authorship rules
  37. - **Survey and review paper writing** -- JEL, JEP, Handbook chapter conventions
  38. - **Coauthorship conventions** -- Voice consistency, designated "voice editor", signaling individual contributions
  39. ### Modern Standards
  40. - **Modern empirical practices** -- Pre-registration, multiple testing, specification robustness, transparency and reproducibility
  41. - **AEA replication package standards** -- Data Editor requirements: README template, data citation, directory structure, code reproducibility
  42. - **AI use disclosure guidance** -- Journal-specific policies (AEA, Econometric Society) for disclosing AI assistance
  43. - **LaTeX formatting guide** -- Tables (booktabs, threeparttable), figures, bibliography (natbib), journal submission requirements for AER/QJE/Econometrica/REStud/JPE
  44. ---
  45. ## Installation
  46. Open Codex or Claude Code in any project and paste this prompt:
  47. ```text
  48. Install or update Econ Write as a standalone skill for the client I am using. Read and follow https://github.com/hanlulong/econ-writing-skill/blob/main/INSTALL.md. Handle same-client migration, backups, and verification yourself. Do not install for or change the other client. Do not ask me to run commands. Finish with a concise result.
  49. ```
  50. Use the same prompt for a first installation and rerun it whenever you want to
  51. update or safely migrate from a native plugin. It installs only for the client
  52. receiving the prompt.
  53. For alternative installation methods, updates, migration, and troubleshooting,
  54. see [Installation and updates](INSTALL.md). Use only one installation method
  55. per client.
  56. ---
  57. ## Usage
  58. With the recommended standalone installation, natural-language requests can
  59. activate the skill automatically. To invoke it explicitly, use `/econ-write` in
  60. Claude Code or `$econ-write` in Codex (you can also select it from Codex's
  61. `/skills` menu).
  62. Claude Code:
  63. ```
  64. /econ-write write introduction for my paper on the effect of minimum wage on employment
  65. ```
  66. Codex:
  67. ```
  68. $econ-write rewrite this abstract to be more concrete and under 150 words
  69. ```
  70. Either client can also use an ordinary request such as:
  71. ```
  72. Use econ-write to draft a conclusion for my RDD paper on school funding.
  73. ```
  74. ```
  75. Use econ-write to review this paragraph for style violations.
  76. ```
  77. ```
  78. Use econ-write to help me structure the model section for my theory paper.
  79. ```
  80. ```
  81. Use econ-write to audit my full paper and score it.
  82. ```
  83. The skill works in four modes:
  84. - **Drafting**: generates new text following the formulas and rules, marking areas that need your specific results with `[AUTHOR: ...]` placeholders.
  85. - **Rewriting**: identifies violations of the rules (passive voice, vague language, buried leads, throat-clearing) and fixes them while preserving your meaning and contribution.
  86. - **Reviewing**: checks existing text against all rules and provides a detailed report of issues with suggested fixes.
  87. - **Auditing**: scores the full paper from three simulated reviewer perspectives and returns a 100-point rubric with prioritized feedback.
  88. ---
  89. ## Common Use Cases
  90. - **Drafting a new paper section** -- Generate a first draft of any section (abstract, introduction, data, results, conclusion) that follows established formulas from the start.
  91. - **Rewriting existing text for clarity** -- Tighten prose, eliminate passive voice, cut throat-clearing, and make results concrete.
  92. - **Writing an introduction from scratch** -- Follow Head's formula exactly: Hook, Research Question, Main Results, Literature Review & Value Added, Roadmap.
  93. - **Conducting and writing a literature review** -- Build a story-driven review of the 5-10 closest papers, embedded in the introduction, that establishes your paper's niche.
  94. - **Writing up existing empirical results** -- Present results in the correct order (main result first, most parsimonious to least parsimonious) with proper emphasis on economic significance.
  95. - **Writing a theory paper** -- Structure model presentation, write propositions with intuition before proofs, generate testable predictions.
  96. - **Structuring a mixed theory-empirical paper** -- Map empirical tests back to specific model predictions.
  97. - **Preparing a presentation** -- Get advice on slide structure, pacing, and delivery following Shapiro, Cochrane, and others ("Gene Fama usually starts with 'Look at table 1.' That's a good model.").
  98. - **Reviewing a full paper** -- Get a structured audit with 3 simulated reviewer perspectives and a 100-point score.
  99. - **Writing a grant proposal** -- Structure an NSF, ERC, or institutional proposal that sells a research plan, not a finished paper.
  100. - **Writing for policy audiences** -- Translate academic findings into plain-language policy briefs and op-eds.
  101. - **Converting a working paper to journal format** -- Cut strategically, meet journal length norms, organize the online appendix.
  102. - **Preparing a replication package** -- Follow AEA Data Editor standards for data citation, code reproducibility, and README structure.
  103. ---
  104. ## What's Inside
  105. The skill includes five files:
  106. ### `SKILL.md` (main skill file)
  107. 1. **Core Principles** -- Seven foundational rules (Reader First, Triangular Style, One Central Contribution, Concrete Not Abstract, Every Word Counts, Active Voice, Simple over Complex)
  108. 2. **Section Formulas** -- Step-by-step formulas for the Abstract, Introduction (Head's formula), Model Section (Glaeser/Varian), Data Section, Conclusion (3-part formula), and Title (with evaluation criteria)
  109. 3. **Style Rules** -- Detailed guidance on sentence structure, word choice, voice, pronouns, footnotes, numbers, notation, paragraphs, and anti-AI writing patterns
  110. 4. **Tables and Figures** -- Best practices for captions, formatting, figure vs. table trade-offs, and data visualization
  111. 5. **Empirical Work Rules** -- Identification, results presentation, null results, heterogeneity analysis, mechanisms, and common mistakes
  112. 6. **Modern Empirical Practices** -- Pre-registration, multiple testing, specification robustness, transparency
  113. 7. **Paper Structure Templates** -- Templates for applied, theory, mixed theory-empirical, and structural papers, plus appendix organization guidance
  114. 8. **Use Case Instructions** -- Specific instructions for drafting, rewriting, reviewing/auditing, introductions, literature reviews, abstracts, conclusions, results, theory papers, data sections, presentations, and referee responses
  115. 9. **Revision Checklist** -- A 24-item pre-submission checklist covering content, style, and modern standards
  116. 10. **Field-Specific Conventions** -- Adaptations for macro, trade, development, and finance
  117. 11. **AEA Replication Standards** -- Data Editor requirements for replication packages, data citation, and AI disclosure
  118. 12. **Dissertation Structure** -- Three-essays format and JMP positioning
  119. ### `identification-strategies.md`
  120. Detailed writing guidance tailored to each identification strategy: RCT, DiD (including staggered), IV, RDD, Synthetic Control, Synthetic DiD, Structural Estimation, Descriptive/Measurement, Bunching Estimation, Shift-Share/Bartik Instruments, Event Studies, and Machine Learning for Causal Inference, plus guidance for papers combining multiple strategies. Includes an introduction adaptation table showing how to adjust hooks, results paragraphs, and key threats for 13 paper types.
  121. ### `latex-tips.md`
  122. Practical LaTeX guidance for economics papers: document structure, essential packages (booktabs, threeparttable, natbib, siunitx), regression table formatting, figure best practices (PDF vector graphics, subfigures), bibliography management, math formatting, cross-referencing with cleveref, journal submission requirements (AER, QJE, Econometrica, REStud, JPE), Beamer presentations, and common pitfalls.
  123. ### `review-checklist.md`
  124. Structured paper review framework with quick-scan mode (5-minute check), deep-review mode (3 simulated reviewers: Methodologist, Field Expert, Writing Critic), anti-AI detection checklist, 100-point pre-submission scoring rubric, and journal fit assessment for top-5 vs. field journal targeting.
  125. ### `specialized-tasks.md`
  126. Task-specific instructions for lower-frequency writing jobs that build on the core skill: conference and seminar presentations, survey/review papers (JEL, JEP, Handbook chapters), converting a working paper to a journal version, grant proposals (NSF, ERC, institutional), writing for non-academic audiences (policy briefs, op-eds), and referee responses for revise-and-resubmit. Splitting these out of `SKILL.md` keeps the always-loaded core leaner.
  127. ---
  128. ## Sources and Acknowledgements
  129. This skill synthesizes advice from **50+ authoritative sources**. The top 10 sources by authority and impact:
  130. | Rank | Source | Author(s) | Institution |
  131. |------|--------|-----------|-------------|
  132. | 1 | Writing Tips for Ph.D. Students | John H. Cochrane | U Chicago Booth / Hoover |
  133. | 2 | Economical Writing | Deirdre N. McCloskey | UIC / U Chicago |
  134. | 3 | Four Steps to an Applied Micro Paper | Jesse M. Shapiro | Harvard |
  135. | 4 | The Introduction Formula | Keith Head | UBC Sauder |
  136. | 5 | Ten Most Important Rules of Writing Your JMP | Claudia Goldin & Lawrence F. Katz | Harvard |
  137. | 6 | Writing Tips for Economics Research Papers | Plamen Nikolov | Binghamton / Harvard |
  138. | 7 | How to Write Applied Papers in Economics | Marc F. Bellemare | U Minnesota |
  139. | 8 | How to Give an Applied Micro Talk | Jesse M. Shapiro | Harvard |
  140. | 9 | Writing Papers: A Checklist | Michael Kremer | Harvard / UChicago |
  141. | 10 | An Economist's Guide to Visualizing Data | Jonathan A. Schwabish | JEP (AEA) |
  142. Notable authorities include **Nobel laureates** (Goldin 2023, Kremer 2019), **Clark Medal winners** (Gentzkow 2014, Finkelstein 2012), a **MacArthur Fellow** (Shapiro 2021), and editors of leading journals (Bellemare at AJAE, Beatty at AJAE, Shimshack at JEEM).
  143. The full ranked list of all 50+ sources with links, tiers, and notes is available in [`sources/SOURCES_RANKED.md`](sources/SOURCES_RANKED.md).
  144. ---
  145. ## Related Skills
  146. Writing is one stage of the paper's life. The same author maintains companion tools for the other stages:
  147. - [**econ-paper-review-skill**](https://github.com/hanlulong/econ-paper-review-skill) -- An AI referee report on your economics paper before a real referee sees it: verified detailed comments, editing notes, and a revision plan you can hand straight to your agents. Free for noncommercial use, built for round-after-round iteration.
  148. - [**econ-slides-skill**](https://github.com/hanlulong/econ-slides-skill) -- Turn the paper into a professional LaTeX/Beamer talk: conference, seminar, job-market, and discussant decks with timed speaker scripts, every deck compiled and geometry-checked before delivery (MIT).
  149. - [**stata-mcp**](https://github.com/hanlulong/stata-mcp) -- Run Stata from AI agents and IDEs.
  150. - [**awesome-ai-for-economists**](https://github.com/hanlulong/awesome-ai-for-economists) -- The broader curated toolbox of AI resources for economics research.
  151. ---
  152. ## Contributing
  153. Contributions are welcome. If you know of an authoritative economics writing guide that should be included, or if you have suggestions for improving the skill's formulas or rules, please open an issue or submit a pull request.
  154. Areas where contributions are especially useful:
  155. - Additional before/after examples
  156. - Field-specific adaptations (development, trade, labor, macro, finance)
  157. - Translations of the skill for other AI assistant platforms
  158. - Corrections or refinements to existing rules
  159. ---
  160. ## License
  161. This project is licensed under the [MIT License](LICENSE).
  162. ---
  163. *Built by [Lu Han](https://luhan.io). Synthesizes the collective wisdom of the economics profession on how to write well.*
scripts/install.sh · Bundled script · 539 lines · 2 findings marked
  1. #!/bin/bash
  2. # Install Econ Writing Skill for Claude Code and/or Codex
  3. #
  4. # Usage:
  5. # ./scripts/install.sh --claude Install globally for Claude Code
  6. # ./scripts/install.sh --codex Install globally for Codex
  7. # ./scripts/install.sh --all Install globally for both clients
  8. # ./scripts/install.sh --local --claude Install to current project for Claude Code
  9. # ./scripts/install.sh --help Show help
  10. #
  11. # One-line install (no git clone needed):
  12. # curl -fsSL https://raw.githubusercontent.com/hanlulong/econ-writing-skill/main/scripts/install.sh | bash -s -- --global --claude
    • Note: Pipes a downloaded script directly into a shell (curl | sh / wget | bash)
    • Line 12 on GitHub
  13. set -e
  14. RELEASE_TAG="econ-write--v0.1.2"
  15. REPO_ARCHIVE_URL="${ECON_WRITE_ARCHIVE_URL:-https://codeload.github.com/hanlulong/econ-writing-skill/tar.gz/refs/tags/$RELEASE_TAG}"
  16. SKILL_FILES=("SKILL.md" "identification-strategies.md" "latex-tips.md" "review-checklist.md" "specialized-tasks.md")
  17. RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-$$"
  18. BACKUP_ROOT="$HOME/.openeconai/backups/econ-write/$RUN_ID"
  19. BACKUPS_CREATED=0
  20. SOURCE_STAGE_ROOT=""
  21. SOURCE_SKILL_DIR=""
  22. # Parse arguments
  23. MODE="global"
  24. PLATFORM=""
  25. TARGET=""
  26. TARGET_SET=0
  27. print_help() {
  28. echo "Econ Writing Skill Installer"
  29. echo ""
  30. echo "Usage: ./scripts/install.sh [options] [target-directory]"
  31. echo ""
  32. echo "Options:"
  33. echo " --global Install to global skill directories (default)"
  34. echo " --local Install to project directory only"
  35. echo " --claude Install for Claude Code only"
  36. echo " --codex Install for Codex only"
  37. echo " --all Install for both clients explicitly"
  38. echo " --help Show this help message"
  39. echo ""
  40. echo "Examples:"
  41. echo " ./scripts/install.sh --global --claude # Claude Code only"
  42. echo " ./scripts/install.sh --global --codex # Codex only"
  43. echo " ./scripts/install.sh --global --all # Both clients"
  44. echo " ./scripts/install.sh --local --claude . # Current project"
  45. echo " ./scripts/install.sh --local --codex /path/to/repo # Specific project"
  46. echo ""
  47. echo "One-line install (no git clone needed):"
  48. echo " curl -fsSL https://raw.githubusercontent.com/hanlulong/econ-writing-skill/main/scripts/install.sh | bash -s -- --global --claude"
    • Note: Pipes a downloaded script directly into a shell (curl | sh / wget | bash)
    • Line 52 on GitHub
  49. }
  50. select_platform() {
  51. local selected="$1"
  52. if [ -n "$PLATFORM" ] && [ "$PLATFORM" != "$selected" ]; then
  53. echo "Error: Choose exactly one of --claude, --codex, or --all." >&2
  54. exit 2
  55. fi
  56. PLATFORM="$selected"
  57. }
  58. while [[ $# -gt 0 ]]; do
  59. case $1 in
  60. --global) MODE="global"; shift ;;
  61. --local) MODE="local"; shift ;;
  62. --claude) select_platform "claude"; shift ;;
  63. --codex) select_platform "codex"; shift ;;
  64. --all) select_platform "all"; shift ;;
  65. --help) print_help; exit 0 ;;
  66. -*)
  67. echo "Error: Unknown option: $1" >&2
  68. print_help >&2
  69. exit 2
  70. ;;
  71. *)
  72. if [ "$TARGET_SET" -eq 1 ]; then
  73. echo "Error: Only one target directory may be provided." >&2
  74. exit 2
  75. fi
  76. TARGET="$1"
  77. TARGET_SET=1
  78. shift
  79. ;;
  80. esac
  81. done
  82. if [ -z "$PLATFORM" ]; then
  83. echo "Error: Choose exactly one of --claude, --codex, or --all." >&2
  84. print_help >&2
  85. exit 2
  86. fi
  87. if [ "$MODE" != "local" ] && [ "$TARGET_SET" -eq 1 ]; then
  88. echo "Error: A target directory is valid only with --local." >&2
  89. exit 2
  90. fi
  91. if [ "$MODE" = "global" ] && { [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "claude" ]; } &&
  92. [ -n "${CLAUDE_CONFIG_DIR:-}" ] && [[ "$CLAUDE_CONFIG_DIR" != /* ]]; then
  93. echo "Error: CLAUDE_CONFIG_DIR must be an absolute path." >&2
  94. exit 2
  95. fi
  96. SCRIPT_DIR=""
  97. REPO_ROOT=""
  98. LOCAL_SKILL_DIR=""
  99. if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
  100. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || echo "")"
  101. if [ -n "$SCRIPT_DIR" ]; then
  102. REPO_ROOT="$(cd "$SCRIPT_DIR/.." 2>/dev/null && pwd || echo "")"
  103. LOCAL_SKILL_DIR="$REPO_ROOT/skills/econ-write"
  104. fi
  105. fi
  106. # Check if running from local repo or via curl | bash
  107. is_local() {
  108. [ -n "$LOCAL_SKILL_DIR" ] && [ -d "$LOCAL_SKILL_DIR" ]
  109. }
  110. validate_source_dir() {
  111. local source_dir="$1"
  112. local file
  113. for file in "${SKILL_FILES[@]}"; do
  114. if [ ! -f "$source_dir/$file" ] || [ -L "$source_dir/$file" ] || [ ! -s "$source_dir/$file" ]; then
  115. echo "Error: Source is incomplete: skills/econ-write/$file" >&2
  116. return 1
  117. fi
  118. done
  119. }
  120. cleanup_source() {
  121. if [ -n "$SOURCE_STAGE_ROOT" ] && [ -d "$SOURCE_STAGE_ROOT" ]; then
  122. rm -rf "$SOURCE_STAGE_ROOT"
  123. fi
  124. }
  125. trap cleanup_source EXIT
  126. prepare_source() {
  127. local archive
  128. local listing
  129. local extracted
  130. local skill_member
  131. local archive_root
  132. local file
  133. local member
  134. if is_local; then
  135. SOURCE_SKILL_DIR="$LOCAL_SKILL_DIR"
  136. validate_source_dir "$SOURCE_SKILL_DIR"
  137. return
  138. fi
  139. if ! command -v curl >/dev/null 2>&1; then
  140. echo "Error: curl is required for a remote installation." >&2
  141. return 1
  142. fi
  143. if ! command -v tar >/dev/null 2>&1; then
  144. echo "Error: tar is required for a remote installation." >&2
  145. return 1
  146. fi
  147. SOURCE_STAGE_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/econ-write-source.XXXXXX")"
  148. archive="$SOURCE_STAGE_ROOT/source.tar.gz"
  149. listing="$SOURCE_STAGE_ROOT/archive-members.txt"
  150. extracted="$SOURCE_STAGE_ROOT/skill"
  151. mkdir -p "$extracted"
  152. if ! curl -fsSL "$REPO_ARCHIVE_URL" -o "$archive"; then
  153. echo "Error: Failed to download the Econ Write source snapshot; existing installations were not changed." >&2
  154. return 1
  155. fi
  156. if ! tar -tzf "$archive" > "$listing"; then
  157. echo "Error: Failed to inspect the Econ Write source snapshot; existing installations were not changed." >&2
  158. return 1
  159. fi
  160. skill_member="$(grep -E '^[A-Za-z0-9._-]+/skills/econ-write/SKILL\.md$' "$listing" || true)"
  161. if [ -z "$skill_member" ] || [ "$(printf '%s\n' "$skill_member" | wc -l | tr -d ' ')" -ne 1 ]; then
  162. echo "Error: The source snapshot does not contain skills/econ-write; existing installations were not changed." >&2
  163. return 1
  164. fi
  165. archive_root="${skill_member%/skills/econ-write/SKILL.md}"
  166. case "$archive_root" in
  167. ""|.|..|-*|*/*)
  168. echo "Error: The source snapshot has an unsafe archive root; existing installations were not changed." >&2
  169. return 1
  170. ;;
  171. esac
  172. for file in "${SKILL_FILES[@]}"; do
  173. member="$archive_root/skills/econ-write/$file"
  174. if [ "$(grep -Fxc "$member" "$listing" || true)" -ne 1 ]; then
  175. echo "Error: The source snapshot has a missing or duplicate $file; existing installations were not changed." >&2
  176. return 1
  177. fi
  178. done
  179. if ! tar -xzf "$archive" -C "$extracted" --strip-components=3 -- \
  180. "$archive_root/skills/econ-write/SKILL.md" \
  181. "$archive_root/skills/econ-write/identification-strategies.md" \
  182. "$archive_root/skills/econ-write/latex-tips.md" \
  183. "$archive_root/skills/econ-write/review-checklist.md" \
  184. "$archive_root/skills/econ-write/specialized-tasks.md"; then
  185. echo "Error: Failed to extract the Econ Write source snapshot; existing installations were not changed." >&2
  186. return 1
  187. fi
  188. SOURCE_SKILL_DIR="$extracted"
  189. validate_source_dir "$SOURCE_SKILL_DIR"
  190. }
  191. backup_name() {
  192. printf '%s' "$1" | sed 's#[^A-Za-z0-9._-]#_#g' | awk '{ print substr($0, length($0) > 180 ? length($0) - 179 : 1) }'
  193. }
  194. paths_overlap() {
  195. python3 - "$1" "$2" <<'PY'
  196. import os
  197. import sys
  198. from pathlib import Path
  199. try:
  200. if os.path.samefile(sys.argv[1], sys.argv[2]):
  201. raise SystemExit(0)
  202. except OSError:
  203. pass
  204. def forms(raw):
  205. path = Path(raw).expanduser()
  206. return {
  207. os.path.normcase(os.path.normpath(str(path.absolute()))),
  208. os.path.normcase(os.path.normpath(str(path.resolve(strict=False)))),
  209. }
  210. def overlaps(left, right):
  211. try:
  212. common = os.path.commonpath((left, right))
  213. except (OSError, ValueError):
  214. return False
  215. return common in {left, right}
  216. raise SystemExit(
  217. 0
  218. if any(overlaps(left, right) for left in forms(sys.argv[1]) for right in forms(sys.argv[2]))
  219. else 1
  220. )
  221. PY
  222. }
  223. skill_destination_is_safe() {
  224. python3 - "$1" "$HOME" <<'PY'
  225. import os
  226. import stat
  227. import sys
  228. from pathlib import Path
  229. destination = Path(os.path.abspath(os.path.expanduser(sys.argv[1])))
  230. home = Path(os.path.abspath(os.path.expanduser(sys.argv[2])))
  231. try:
  232. boundary = Path(os.path.commonpath((str(home), str(destination.parent))))
  233. except ValueError:
  234. boundary = Path(destination.anchor)
  235. candidate = boundary
  236. for part in destination.parent.relative_to(boundary).parts:
  237. candidate = candidate / part
  238. try:
  239. metadata = candidate.lstat()
  240. except OSError:
  241. continue
  242. attributes = getattr(metadata, "st_file_attributes", 0)
  243. if (
  244. stat.S_ISLNK(metadata.st_mode)
  245. or attributes & getattr(stat, "FILE_ATTRIBUTE_REPARSE_POINT", 0)
  246. or not stat.S_ISDIR(metadata.st_mode)
  247. ):
  248. print(candidate)
  249. raise SystemExit(1)
  250. PY
  251. }
  252. legacy_parent_is_safe() {
  253. python3 - "$1" "$2" <<'PY'
  254. import os
  255. import stat
  256. import sys
  257. from pathlib import Path
  258. legacy = Path(os.path.abspath(os.path.expanduser(sys.argv[1])))
  259. boundary = Path(os.path.abspath(os.path.expanduser(sys.argv[2])))
  260. try:
  261. legacy.parent.relative_to(boundary)
  262. except ValueError:
  263. print(legacy.parent)
  264. raise SystemExit(1)
  265. path = legacy.parent
  266. while True:
  267. try:
  268. metadata = path.lstat()
  269. except OSError:
  270. pass
  271. else:
  272. attributes = getattr(metadata, "st_file_attributes", 0)
  273. if stat.S_ISLNK(metadata.st_mode) or attributes & getattr(stat, "FILE_ATTRIBUTE_REPARSE_POINT", 0):
  274. print(path)
  275. raise SystemExit(1)
  276. if path == boundary:
  277. break
  278. if boundary not in path.parents:
  279. print(path)
  280. raise SystemExit(1)
  281. path = path.parent
  282. PY
  283. }
  284. preserve_copy() {
  285. local source_path="$1"
  286. local original_path="$2"
  287. local name
  288. local path_hash
  289. local original_parent
  290. local client_root
  291. local central_backup
  292. local local_backup
  293. name="$(backup_name "$original_path")"
  294. path_hash="$(python3 - "$original_path" <<'PY'
  295. import hashlib
  296. import sys
  297. print(hashlib.sha256(sys.argv[1].encode("utf-8")).hexdigest()[:12])
  298. PY
  299. )"
  300. name="$name-$path_hash"
  301. central_backup="$BACKUP_ROOT/$name"
  302. if skill_destination_is_safe "$central_backup"; then
  303. if mkdir -p "$BACKUP_ROOT" && mv "$source_path" "$central_backup"; then
  304. BACKUPS_CREATED=1
  305. echo " Preserved previous copy: $central_backup"
  306. return 0
  307. fi
  308. fi
  309. original_parent="$(dirname "$original_path")"
  310. if [ "$(basename "$original_parent")" != "skills" ]; then
  311. return 1
  312. fi
  313. client_root="$(dirname "$original_parent")"
  314. local_backup="$client_root/.openeconai-inactive/econ-write/$RUN_ID/$name"
  315. if ! skill_destination_is_safe "$local_backup"; then
  316. return 1
  317. fi
  318. mkdir -p "$(dirname "$local_backup")" || return 1
  319. if mv "$source_path" "$local_backup"; then
  320. BACKUPS_CREATED=1
  321. echo " Preserved previous copy on its original volume: $local_backup"
  322. return 0
  323. fi
  324. echo " Warning: Could not move the previous copy to $BACKUP_ROOT/$name"
  325. echo " Previous copy remains at: $source_path"
  326. return 1
  327. }
  328. install_skill() {
  329. local dest_dir="$1"
  330. local label="$2"
  331. local parent_dir
  332. local stage_root
  333. local stage_dir
  334. local previous_dir
  335. if ! skill_destination_is_safe "$dest_dir"; then
  336. echo " Error: Refusing an unsafe $label destination ancestor: $dest_dir" >&2
  337. return 1
  338. fi
  339. parent_dir="$(dirname "$dest_dir")"
  340. mkdir -p "$parent_dir"
  341. stage_root="$(mktemp -d "$parent_dir/.econ-write-install.XXXXXX")"
  342. stage_dir="$stage_root/econ-write"
  343. previous_dir="$stage_root/previous"
  344. mkdir -p "$stage_dir"
  345. for file in "${SKILL_FILES[@]}"; do
  346. if ! cp "$SOURCE_SKILL_DIR/$file" "$stage_dir/$file"; then
  347. echo " Error: Failed to stage $file"
  348. rm -rf "$stage_root"
  349. return 1
  350. fi
  351. if [ ! -s "$stage_dir/$file" ]; then
  352. echo " Error: $file is empty; the existing installation was not changed."
  353. rm -rf "$stage_root"
  354. return 1
  355. fi
  356. done
  357. if [ ! -L "$dest_dir" ] && [ -d "$dest_dir" ] && diff -qr "$dest_dir" "$stage_dir" >/dev/null 2>&1; then
  358. rm -rf "$stage_root"
  359. echo " Already current for $label: $dest_dir/"
  360. return 0
  361. fi
  362. if [ -e "$dest_dir" ] || [ -L "$dest_dir" ]; then
  363. if ! mv "$dest_dir" "$previous_dir"; then
  364. echo " Error: Could not stage the previous installation at $dest_dir"
  365. rm -rf "$stage_root"
  366. return 1
  367. fi
  368. fi
  369. if ! mv "$stage_dir" "$dest_dir"; then
  370. echo " Error: Could not activate the staged installation at $dest_dir"
  371. if [ -e "$previous_dir" ] || [ -L "$previous_dir" ]; then
  372. if ! mv "$previous_dir" "$dest_dir"; then
  373. echo " Error: Could not restore the previous installation. It remains available at: $previous_dir" >&2
  374. return 1
  375. fi
  376. fi
  377. rm -rf "$stage_root"
  378. return 1
  379. fi
  380. if [ -e "$previous_dir" ] || [ -L "$previous_dir" ]; then
  381. if ! preserve_copy "$previous_dir" "$dest_dir"; then
  382. echo " Error: The update could not preserve the previous installation; restoring it."
  383. if ! rm -rf "$dest_dir" || ! mv "$previous_dir" "$dest_dir"; then
  384. echo " Error: Automatic restoration failed. The previous installation remains available at: $previous_dir" >&2
  385. return 1
  386. fi
  387. rm -rf "$stage_root"
  388. return 1
  389. fi
  390. fi
  391. rm -rf "$stage_root"
  392. echo " Installed for $label: $dest_dir/"
  393. }
  394. deactivate_legacy_codex_copy() {
  395. local current_dir="$1"
  396. local legacy_dir="$2"
  397. local boundary="$3"
  398. if [ -L "$current_dir" ] || [ ! -d "$current_dir" ] ||
  399. ! diff -qr "$current_dir" "$SOURCE_SKILL_DIR" >/dev/null 2>&1; then
  400. echo " Error: The current Codex skill could not be verified before legacy cleanup: $current_dir" >&2
  401. return 1
  402. fi
  403. if [ ! -e "$legacy_dir" ] && [ ! -L "$legacy_dir" ]; then
  404. return 0
  405. fi
  406. if paths_overlap "$current_dir" "$legacy_dir"; then
  407. echo " Skipped aliased legacy Codex path that resolves to the current skill: $legacy_dir"
  408. return 0
  409. fi
  410. if ! legacy_parent_is_safe "$legacy_dir" "$boundary"; then
  411. echo " Error: Refusing legacy migration through a linked or junction ancestor: $legacy_dir" >&2
  412. return 1
  413. fi
  414. if [ ! -L "$legacy_dir" ] && [ -d "$legacy_dir" ] && diff -qr "$legacy_dir" "$current_dir" >/dev/null 2>&1; then
  415. rm -rf "$legacy_dir"
  416. echo " Removed duplicate legacy Codex copy: $legacy_dir/"
  417. elif ! preserve_copy "$legacy_dir" "$legacy_dir"; then
  418. echo " Error: Could not deactivate the modified legacy Codex copy."
  419. return 1
  420. fi
  421. if [ -L "$current_dir" ] || [ ! -d "$current_dir" ] ||
  422. ! diff -qr "$current_dir" "$SOURCE_SKILL_DIR" >/dev/null 2>&1; then
  423. echo " Error: The current Codex skill changed during legacy cleanup: $current_dir" >&2
  424. return 1
  425. fi
  426. }
  427. prepare_source
  428. echo ""
  429. echo " Econ Writing Skill Installer"
  430. echo " =============================="
  431. echo ""
  432. if [ "$MODE" = "global" ]; then
  433. echo " Mode: Global (available in all projects)"
  434. echo ""
  435. if [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "claude" ]; then
  436. install_skill "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills/econ-write" "Claude Code (global)"
  437. fi
  438. if [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "codex" ]; then
  439. install_skill "$HOME/.agents/skills/econ-write" "Codex (global)"
  440. deactivate_legacy_codex_copy \
  441. "$HOME/.agents/skills/econ-write" \
  442. "$HOME/.codex/skills/econ-write" \
  443. "$HOME"
  444. fi
  445. echo ""
  446. echo " Done! The skill is now available across all your projects."
  447. elif [ "$MODE" = "local" ]; then
  448. TARGET="${TARGET:-.}"
  449. echo " Mode: Local (project: $TARGET)"
  450. echo ""
  451. if [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "claude" ]; then
  452. install_skill "$TARGET/.claude/skills/econ-write" "Claude Code (local)"
  453. fi
  454. if [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "codex" ]; then
  455. install_skill "$TARGET/.agents/skills/econ-write" "Codex (local)"
  456. deactivate_legacy_codex_copy \
  457. "$TARGET/.agents/skills/econ-write" \
  458. "$TARGET/.codex/skills/econ-write" \
  459. "$TARGET"
  460. fi
  461. echo ""
  462. echo " Done! The skill is installed in: $TARGET"
  463. fi
  464. if [ "$BACKUPS_CREATED" -eq 1 ]; then
  465. echo " Previous copies were preserved at the paths reported above."
  466. fi
  467. echo ""
  468. echo " Usage:"
  469. if [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "claude" ]; then
  470. echo " Claude Code: /econ-write rewrite this economics paper introduction"
  471. fi
  472. if [ "$PLATFORM" = "all" ] || [ "$PLATFORM" = "codex" ]; then
  473. echo ' Codex: $econ-write rewrite this economics paper introduction'
  474. fi
  475. echo ""

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.