AI-Powered Git Workspace Documentation Synchronizer CLI Daemon
An intelligent developer workspace utility that monitors repository states, captures structural diffs, and integrates with the Google Gemini API to automatically generate and append codebase change summaries to STRUCTURE.md.
[npx shadow-docs sync] OR [shadow-docs sync]
│
▼
(Git Verification) ➔ ensureCleanTree()
│
┌────┴────────────────────────┐
▼ ▼
[No Lock File] [Has Lock File]
└─► Baseline created. ├─► git diff <lastHash> HEAD
└─► Save current hash. ├─► Read existing STRUCTURE.md (History)
└─► Gather git ls-files (Structure)
│
▼
(Ultimate Context)
│
▼
[AIManager (Gemini)]
│
▼
(Update Docs & Save lock state)
Ensure you are in the project root directory and run:
npm installThis installs the required dependencies including @google/generative-ai for AI calls, commander for CLI structure, and chalk for console coloring.
Create a .env file in the root folder and add your Google Gemini API key:
GOOGLE_GEMINI_API_KEY=your_gemini_api_key_hereCompile the TypeScript files using the local TS compiler config:
npm run buildThis runs the TS compiler (tsc), transpiling TypeScript source files into executable ES modules inside the dist/ directory.
The CLI currently exposes one primary command: sync.
To test or execute the synchronization command directly from the build distribution:
npx shadow-docs syncYou can link the executable binary globally to your local system path:
npm linkAfter linking, you can run the CLI from any target repository workspace on your machine directly:
shadow-docs sync- Validates Git Tree Cleanliness: Checks that your working tree has no uncommitted changes (
ensureCleanTree). If there are dirty files, it aborts execution to maintain a stable commit-based baseline. - Baseline Initialization (First Run): If
.shadow-lockdoes not exist, it saves the current HEAD commit hash in.shadow-lockas a starting baseline. No documentation is written, and it printsBaseline created!. - Diff Comparison (Subsequent Runs): On later runs, it compares the current HEAD commit hash against the
lastHashstored in.shadow-lock. - Generates Context Prompt: If changes exist, it extracts the code diff, maps the project file listing (
git ls-files), and reads the existing documentation history (STRUCTURE.md). - Generates and Appends Summary: Sends the full context to the Google Gemini model and appends the returned bulleted change summary to
STRUCTURE.mdwithout wiping existing records.
shadow-docs/
├── src/
│ ├── commands/
│ │ └── sync.ts # Main sync command orchestrator
│ ├── lib/
│ │ ├── ai.ts # Gemini API prompt builder & content generator
│ │ └── git.ts # Git status, diff, & file listings
│ ├── utils/
│ │ └── store.ts # State management (.shadow-lock & STRUCTURE.md)
│ └── index.ts # Commander CLI entrypoint registration
├── tsconfig.json # TypeScript compiler parameters
└── package.json # Package configuration and script definitions
.shadow-lock: A lightweight state configuration tracking the last synchronized commit hash and date:{ "lastHash": "7083be62ee1e594ff1d81cbce7bed79ace4ee5a4", "updatedAt": "2026-07-12T14:44:56Z" }STRUCTURE.md: The persistent documentation diary. The tool automatically appends updates to this file chronologically:## 🗓️ Update: YYYY-MM-DD * Summary of code modifications generated by the model.
- ❌ No Dirty Trees: The tool will abort execution if uncommitted active changes exist.
- ❌ No Environment Bypass: Requires a valid
GOOGLE_GEMINI_API_KEYto be loaded before generating summaries. - ❌ No Manual Lock Modifications: Modifying
.shadow-lockmanually might cause desynchronized states.