Last updated: 2026-02-17
CLI tool (datacore) for installing, configuring, and managing Datacore installations. Published as @datacore-one/cli on npm. The init flow is the core value: it provisions ~/Data/, clones modules, imports data sources (ChatGPT exports, etc.), and kicks off background ingest.
Think of it as a guided installer with ongoing management commands. init is stateful (saves progress to a lock file so it can resume), while other commands (sync, module, space, config) are stateless utilities.
| Component | Responsibility |
|---|---|
src/index.ts |
Entry point, arg dispatch, command routing |
src/routing.ts |
Parses args into resource/action pairs |
src/lib/init.ts |
Multi-step init wizard with resume support |
src/lib/background.ts |
Spawns detached background processes (ingest) |
src/lib/dependency.ts |
Doctor checks (git, bun, claude, etc.) |
src/lib/module.ts |
Module install/update/remove |
src/lib/space.ts |
Space listing and creation |
src/lib/sync.ts |
Pull/push/status across all spaces |
src/lib/snapshot.ts |
State snapshots for rollback |
src/state.ts |
OperationState type and lock file I/O |
src/config.ts |
datacore config read/write |
src/format.ts |
Output formatting (human vs JSON) |
CLI invocation
→ routing.ts parses args (resource + action + flags)
→ index.ts dispatches to handler
→ lib/* executes
→ format.ts outputs result
Init flow specifically:
datacore init
→ Steps 1-8 with resume support (lock file at ~/Data/.datacore/state/init.lock)
→ Step 8: spawn background `datacore ingest` per import source (detached)
→ Background ingest runs after terminal closes
| Decision | Rationale |
|---|---|
| Background ingest via detached spawn | Init completes quickly; heavy ingest runs post-terminal |
| Lock file for init resume | Multi-step init can fail mid-way; resume from last step |
| Version in two places | Compiled binary can't read package.json at runtime; hardcode in src/index.ts |
| Bun runtime | Fast startup, native TS, compatible with Node >=18 for distribution |
JSON output mode (--format json) |
Enables machine-readable output for agentic callers |
- Version drift:
package.jsonandVERSIONconst insrc/index.tsmust be bumped together. Easy to forget one. - Confidence check gaps: After adding behavior to the happy path, always verify error/fallback branches also get the change. The ChatGPT parse-failure branch was a real gap caught this way.
- npm login masking:
npm loginweb-OTP masks the URL with***. Use a Granular Access Token from npmjs.com instead for any non-interactive publish flow. - Background process visibility: Detached spawns are fire-and-forget. Errors from background ingest are silent to the user. Add logging to
~/Data/.datacore/state/ingest-*.logfor debugging.
datacore-cli/
├── src/
│ ├── index.ts # Entry point and command dispatch
│ ├── routing.ts # Arg parsing
│ ├── state.ts # OperationState type, lock file
│ ├── config.ts # Config read/write
│ ├── format.ts # Output formatting
│ ├── errors.ts # CLIError type
│ ├── help.ts # Help text
│ └── lib/
│ ├── init.ts # Init wizard (8 steps)
│ ├── background.ts # spawnBackground() helper
│ ├── dependency.ts # Doctor checks
│ ├── module.ts # Module management
│ ├── space.ts # Space management
│ ├── sync.ts # Sync operations
│ ├── snapshot.ts # State snapshots
│ └── ...
├── tests/ # Bun test suite
├── dist/ # Built output (published to npm)
├── package.json # npm metadata (version must match src/index.ts)
├── INSTALL-SIMULATION.md # Reference for init UX flow
└── OVERVIEW.md # This file
Entry points:
src/index.ts- Start here for any feature worksrc/lib/init.ts- For anything touching the install flowINSTALL-SIMULATION.md- Reference for expected UX; keep in sync with code
bun installin project rootbun run dev -- init --helpto test without buildingbun run buildto compile todist/bun testto run test suite- For publish: bump version in
package.jsonANDsrc/index.ts, thennpm publish