7.8 KiB
Global Installation Implementation Summary
Overview
This document summarizes the changes made to enable global installation of gadget-code and gadget-drone with YAML-based configuration.
Key Changes
1. MongoDB/Mongoose Cleanup ✅
Problem: gadget-drone had unnecessary mongoose dependency for type utilities only.
Solution:
- Created
ObjectIdutility in@gadget/api(packages/api/src/lib/objectid.ts) - Exported
Typesfrom@gadget/apifor drone to use - Removed
mongoosefromgadget-drone/package.jsondependencies - Removed Redis configuration from
gadget-drone(was never used)
Files Changed:
packages/api/src/lib/objectid.ts(new)packages/api/src/index.ts(export Types)packages/api/package.json(kept mongoose for database models)gadget-drone/package.json(removed mongoose)gadget-drone/src/config/env.ts(removed redis config)gadget-drone/src/services/agent.ts(import Types from @gadget/api)gadget-drone/src/services/ai.ts(import Types from @gadget/api)
2. Configuration System ✅
Problem: .env files tied to project directories, not suitable for global installation.
Solution: Created @gadget/config package for YAML configuration loading.
New Package: packages/config/
src/types.ts- TypeScript interfaces for config schemassrc/loader.ts- YAML loading with env var substitutionsrc/index.ts- Public API
Features:
- Searches
~/.config/gadget/first, then/etc/gadget/ - Environment variable substitution with
${VAR_NAME}syntax - Path resolution (supports
~for home directory) - Clear error messages with documentation links
3. gadget-code Updates ✅
Changes:
- Removed
dotenvdependency - Added
@gadget/configdependency - Updated
src/config/env.tsto load YAML config - Changed
env.roottoenv.installDir(calculated from__dirname) - Updated all path references to use
installDir:src/web-app.ts(asset paths)src/controllers/api.ts(controller loading)src/controllers/api/v1.ts(child controller loading)
- Added
binentry topackage.jsonfor global commands
Configuration File: ~/.config/gadget/gadget-code.yaml
- All settings from old
.envfile migrated - Organized hierarchically (site, auth, session, mongodb, etc.)
- Sensitive values use environment variable substitution
4. gadget-drone Updates ✅
Changes:
- Removed
dotenvdependency - Added
@gadget/configdependency - Removed
mongoosedependency (now uses Types from @gadget/api) - Added
numeraldependency (was missing but used in logging) - Updated
src/config/env.tsto load YAML config - Changed
env.roottoenv.installDir - Added
binentry topackage.jsonfor global command - Workspace initialization already correctly uses
process.cwd()
Configuration File: ~/.config/gadget/gadget-drone.yaml
- Platform connection settings (baseUrl, apiKey)
- Logging configuration with XDG-compliant default paths
- Environment variable substitution for secrets
5. Documentation ✅
New File: docs/configuration.md
- Complete configuration reference for both applications
- Environment variable substitution guide
- Migration path from
.envfiles - Troubleshooting section
- Security best practices
- XDG Base Directory specification compliance
6. Example Configuration Files ✅
Created:
~/.config/gadget/gadget-code.yaml- Full example with all settings~/.config/gadget/gadget-drone.yaml- Drone configuration example
Both files use environment variable substitution for sensitive values.
Architecture Changes
Path Handling
Before:
const ROOT_DIR = path.resolve(__dirname, "..", "..");
// Used for: assets, controllers, logs, everything
After:
const INSTALL_DIR = path.resolve(__dirname, "..", "..");
// Used for: assets, controllers (where code is installed)
// Workspace operations use process.cwd()
// (where drone is run, separate from installation)
Configuration Loading
Before:
import "dotenv/config";
const value = process.env.DTP_SOME_VALUE;
After:
import { loadGadgetCodeConfig } from "@gadget/config";
const config = loadGadgetCodeConfig();
const value = config.some.value; // with ${ENV_VAR} substitution
Dependency Injection
Before: All values from environment variables After: Hierarchical YAML with env var overrides for secrets only
Testing Results
✅ gadget-drone
- Loads YAML configuration successfully
- Initializes workspace in
process.cwd() - Starts services correctly
- Prompts for credentials (as expected)
✅ gadget-code
- Loads YAML configuration successfully
- Resolves paths from
installDir - Loads controllers correctly
- Starts Express app with proper asset paths
- MongoDB/Redis connection errors expected (services not running)
Migration Guide
For Developers
- Install dependencies:
pnpm install - Build packages:
pnpm -r build - Set environment variables: Export required secrets
- Run with pnpm: Use
pnpm devcommands
For Production Deployment
- Publish packages to npm (or private registry)
- Install globally:
npm install -g gadget-code @gadget/drone - Create config files in
~/.config/gadget/or/etc/gadget/ - Set environment variables for secrets
- Run commands:
gadget-code-web,gadget-drone
Breaking Changes
.envfiles no longer supported - Must use YAML configuration- Configuration location changed - Now in
~/.config/gadget/or/etc/gadget/ - Environment variables - Only for secrets, not general configuration
- Path resolution -
env.rootreplaced withenv.installDir
Benefits
- ✅ True global installation - Run from any directory
- ✅ Centralized configuration - All config in standard locations
- ✅ Better secrets management - Env vars for sensitive data only
- ✅ Multiple drone instances - Each workspace independent
- ✅ Cleaner architecture - Separation of install location vs workspace
- ✅ XDG compliance - Logs in
~/.local/state/ - ✅ No MongoDB/Redis in drone - Pure HTTP + Socket.IO client
Next Steps
- Update AGENTS.md files - Document new development workflow
- Add migration script (optional) - Convert
.envto YAML - Test on clean system - Verify installation from scratch
- Update CI/CD - Adjust for YAML configuration
- Consider publishing - Release to npm for true global installation
Files Summary
New Files
packages/config/package.jsonpackages/config/tsconfig.jsonpackages/config/src/index.tspackages/config/src/types.tspackages/config/src/loader.tspackages/api/src/lib/objectid.tsdocs/configuration.md~/.config/gadget/gadget-code.yaml(example)~/.config/gadget/gadget-drone.yaml(example)
Modified Files
packages/api/src/index.tspackages/api/package.jsongadget-code/package.jsongadget-code/src/config/env.tsgadget-code/src/web-app.tsgadget-code/src/controllers/api.tsgadget-code/src/controllers/api/v1.tsgadget-drone/package.jsongadget-drone/src/config/env.tsgadget-drone/src/services/agent.tsgadget-drone/src/services/ai.tsgadget-drone/src/gadget-drone.ts
Removed Dependencies
gadget-code:dotenvgadget-drone:dotenv,mongoose
Added Dependencies
gadget-code:@gadget/config(workspace)gadget-drone:@gadget/config(workspace),numeralpackages/config:js-yaml,@types/js-yaml
Conclusion
The global installation initiative is complete. Both gadget-code and gadget-drone can now be installed globally and run from any directory, with configuration managed through YAML files in standard locations. The drone process is now properly isolated with no database dependencies, communicating only via HTTP and Socket.IO.