@utilarium/cardigantime 0.0.24-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +65 -0
- package/README.md +398 -0
- package/dist/cardigantime.cjs +2169 -0
- package/dist/cardigantime.cjs.map +1 -0
- package/dist/cardigantime.d.ts +92 -0
- package/dist/cardigantime.js +198 -0
- package/dist/cardigantime.js.map +1 -0
- package/dist/config/executable-security.d.ts +32 -0
- package/dist/config/format-detector.d.ts +59 -0
- package/dist/configure.d.ts +55 -0
- package/dist/configure.js +125 -0
- package/dist/configure.js.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.js +38 -0
- package/dist/constants.js.map +1 -0
- package/dist/discovery/discoverer.d.ts +62 -0
- package/dist/discovery/hierarchical-modes.d.ts +64 -0
- package/dist/discovery/index.d.ts +15 -0
- package/dist/discovery/patterns.d.ts +77 -0
- package/dist/discovery/root-detection.d.ts +100 -0
- package/dist/discovery/traversal-security.d.ts +106 -0
- package/dist/env/errors.d.ts +18 -0
- package/dist/env/index.d.ts +7 -0
- package/dist/env/naming.d.ts +38 -0
- package/dist/env/parser.d.ts +61 -0
- package/dist/env/reader.d.ts +45 -0
- package/dist/env/resolver.d.ts +25 -0
- package/dist/env/schema-utils.d.ts +33 -0
- package/dist/env/types.d.ts +43 -0
- package/dist/error/ArgumentError.d.ts +31 -0
- package/dist/error/ArgumentError.js +48 -0
- package/dist/error/ArgumentError.js.map +1 -0
- package/dist/error/ConfigParseError.d.ts +26 -0
- package/dist/error/ConfigurationError.d.ts +21 -0
- package/dist/error/ConfigurationError.js +46 -0
- package/dist/error/ConfigurationError.js.map +1 -0
- package/dist/error/FileSystemError.d.ts +30 -0
- package/dist/error/FileSystemError.js +58 -0
- package/dist/error/FileSystemError.js.map +1 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/mcp/discovery.d.ts +105 -0
- package/dist/mcp/errors.d.ts +75 -0
- package/dist/mcp/index.d.ts +22 -0
- package/dist/mcp/integration.d.ts +184 -0
- package/dist/mcp/parser.d.ts +141 -0
- package/dist/mcp/resolver.d.ts +165 -0
- package/dist/mcp/tools/check-config-types.d.ts +208 -0
- package/dist/mcp/tools/check-config.d.ts +85 -0
- package/dist/mcp/tools/index.d.ts +12 -0
- package/dist/mcp/types.d.ts +210 -0
- package/dist/parsers/index.d.ts +25 -0
- package/dist/parsers/javascript-parser.d.ts +12 -0
- package/dist/parsers/json-parser.d.ts +6 -0
- package/dist/parsers/typescript-parser.d.ts +15 -0
- package/dist/parsers/yaml-parser.d.ts +6 -0
- package/dist/read.d.ts +56 -0
- package/dist/read.js +653 -0
- package/dist/read.js.map +1 -0
- package/dist/security/audit-logger.d.ts +135 -0
- package/dist/security/cli-validator.d.ts +73 -0
- package/dist/security/config-validator.d.ts +95 -0
- package/dist/security/defaults.d.ts +17 -0
- package/dist/security/index.d.ts +14 -0
- package/dist/security/numeric-guard.d.ts +111 -0
- package/dist/security/path-guard.d.ts +53 -0
- package/dist/security/profiles.d.ts +127 -0
- package/dist/security/security-validator.d.ts +109 -0
- package/dist/security/string-guard.d.ts +92 -0
- package/dist/security/types.d.ts +126 -0
- package/dist/security/zod-secure-enum.d.ts +20 -0
- package/dist/security/zod-secure-number.d.ts +39 -0
- package/dist/security/zod-secure-path.d.ts +24 -0
- package/dist/security/zod-secure-string.d.ts +38 -0
- package/dist/types.d.ts +584 -0
- package/dist/types.js +56 -0
- package/dist/types.js.map +1 -0
- package/dist/util/hierarchical.d.ts +136 -0
- package/dist/util/hierarchical.js +436 -0
- package/dist/util/hierarchical.js.map +1 -0
- package/dist/util/schema-defaults.d.ts +80 -0
- package/dist/util/schema-defaults.js +118 -0
- package/dist/util/schema-defaults.js.map +1 -0
- package/dist/util/storage.d.ts +31 -0
- package/dist/util/storage.js +154 -0
- package/dist/util/storage.js.map +1 -0
- package/dist/validate.d.ts +113 -0
- package/dist/validate.js +260 -0
- package/dist/validate.js.map +1 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Copyright 2025 Tim O'Brien
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
Apache License
|
|
16
|
+
Version 2.0, January 2004
|
|
17
|
+
http://www.apache.org/licenses/
|
|
18
|
+
|
|
19
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
20
|
+
|
|
21
|
+
1. Definitions.
|
|
22
|
+
|
|
23
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
24
|
+
|
|
25
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
26
|
+
|
|
27
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
28
|
+
|
|
29
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
38
|
+
|
|
39
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
40
|
+
|
|
41
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
42
|
+
|
|
43
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
44
|
+
|
|
45
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
46
|
+
|
|
47
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
48
|
+
|
|
49
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
50
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
51
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
52
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
53
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
54
|
+
|
|
55
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
56
|
+
|
|
57
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
58
|
+
|
|
59
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
60
|
+
|
|
61
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
62
|
+
|
|
63
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
64
|
+
|
|
65
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# Cardigantime
|
|
2
|
+
|
|
3
|
+
A robust TypeScript library for configuration management in command-line applications. Cardigantime provides type-safe configuration loading, validation, and CLI integration with Commander.js and Zod schemas.
|
|
4
|
+
|
|
5
|
+
## What is Cardigantime?
|
|
6
|
+
|
|
7
|
+
Cardigantime is a configuration management library designed to solve the common problem of handling configuration in CLI applications. It provides a unified way to:
|
|
8
|
+
|
|
9
|
+
- **Read configuration from multiple formats** (YAML, JSON, JavaScript, TypeScript) with intelligent file discovery
|
|
10
|
+
- **Validate configuration** using Zod schemas for type safety
|
|
11
|
+
- **Integrate with CLI frameworks** like Commander.js seamlessly
|
|
12
|
+
- **Merge configuration sources** (files, CLI args, defaults) with proper precedence
|
|
13
|
+
- **Handle errors gracefully** with comprehensive logging and user-friendly error messages
|
|
14
|
+
|
|
15
|
+
## Why Cardigantime?
|
|
16
|
+
|
|
17
|
+
Building CLI applications with proper configuration management is harder than it should be. **Cardigantime was created specifically to solve the complex problem of supporting sophisticated configuration systems that seamlessly merge command-line arguments, configuration files, and default values.**
|
|
18
|
+
|
|
19
|
+
Without Cardigantime, you need to manually handle:
|
|
20
|
+
- Multi-layered configuration sources with proper precedence
|
|
21
|
+
- Nested configuration objects with deep validation
|
|
22
|
+
- Type safety throughout the configuration pipeline
|
|
23
|
+
- Graceful error handling with actionable messages
|
|
24
|
+
|
|
25
|
+
Cardigantime provides a complete, battle-tested solution for all of this complexity.
|
|
26
|
+
|
|
27
|
+
### One Schema, Multiple Formats
|
|
28
|
+
|
|
29
|
+
Define your configuration schema once with Zod, and Cardigantime automatically supports:
|
|
30
|
+
- **YAML** (`.yaml`, `.yml`) - Human-readable, great for hand-edited configs
|
|
31
|
+
- **JSON** (`.json`) - Strict syntax, ideal for programmatic generation
|
|
32
|
+
- **JavaScript** (`.js`, `.mjs`, `.cjs`) - Dynamic configs with environment logic
|
|
33
|
+
- **TypeScript** (`.ts`, `.mts`, `.cts`) - Type-safe configs with IDE support
|
|
34
|
+
|
|
35
|
+
No additional code or schema definitions needed per format. Your users choose their preferred format, and Cardigantime handles parsing, validation, and merging automatically.
|
|
36
|
+
|
|
37
|
+
## Who Uses Cardigantime?
|
|
38
|
+
|
|
39
|
+
Cardigantime serves two distinct audiences:
|
|
40
|
+
|
|
41
|
+
### Tool Developers
|
|
42
|
+
Developers building CLI applications who want robust configuration management without the boilerplate. You integrate Cardigantime once, define your Zod schema, and get:
|
|
43
|
+
- Multi-format config file support out of the box
|
|
44
|
+
- Automatic CLI option generation
|
|
45
|
+
- Deep merging with proper precedence
|
|
46
|
+
- Hierarchical config discovery (like `.eslintrc` or `.gitignore`)
|
|
47
|
+
- Type safety throughout your codebase
|
|
48
|
+
|
|
49
|
+
### End Users
|
|
50
|
+
Users of tools built with Cardigantime benefit from a consistent, powerful configuration experience without needing to know Cardigantime exists. They get:
|
|
51
|
+
- Freedom to use their preferred config format (YAML, JSON, JS, or TS)
|
|
52
|
+
- Consistent CLI options across tools
|
|
53
|
+
- Clear, actionable error messages
|
|
54
|
+
- Built-in config generation (`--init-config`) and analysis (`--check-config`)
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install @utilarium/cardigantime
|
|
60
|
+
# or
|
|
61
|
+
yarn add @utilarium/cardigantime
|
|
62
|
+
# or
|
|
63
|
+
pnpm add @utilarium/cardigantime
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
Here's a complete example of building a CLI tool with Cardigantime:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { Command } from 'commander';
|
|
72
|
+
import { create } from '@utilarium/cardigantime';
|
|
73
|
+
import { z } from 'zod';
|
|
74
|
+
|
|
75
|
+
// Define your configuration schema using Zod
|
|
76
|
+
const MyConfigSchema = z.object({
|
|
77
|
+
apiKey: z.string().min(1, "API key is required"),
|
|
78
|
+
timeout: z.number().min(1000).default(5000),
|
|
79
|
+
retries: z.number().min(0).max(10).default(3),
|
|
80
|
+
debug: z.boolean().default(false),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Create a Cardigantime instance
|
|
84
|
+
const cardigantime = create({
|
|
85
|
+
defaults: {
|
|
86
|
+
configDirectory: './config', // Required: where to look for config files
|
|
87
|
+
configFile: 'myapp.yaml', // Optional: defaults to 'config.yaml'
|
|
88
|
+
isRequired: false, // Optional: whether config directory must exist
|
|
89
|
+
},
|
|
90
|
+
configShape: MyConfigSchema.shape, // Your Zod schema
|
|
91
|
+
features: ['config'], // Optional: enabled features
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Set up your CLI with Commander.js
|
|
95
|
+
async function main() {
|
|
96
|
+
const program = new Command();
|
|
97
|
+
|
|
98
|
+
program
|
|
99
|
+
.name('myapp')
|
|
100
|
+
.description('My awesome CLI application')
|
|
101
|
+
.version('1.0.0');
|
|
102
|
+
|
|
103
|
+
// Let Cardigantime add its CLI options (like --config-directory)
|
|
104
|
+
await cardigantime.configure(program);
|
|
105
|
+
|
|
106
|
+
// Add your own CLI options
|
|
107
|
+
program
|
|
108
|
+
.option('-k, --api-key <key>', 'API key for authentication')
|
|
109
|
+
.option('-t, --timeout <ms>', 'Request timeout in milliseconds', parseInt)
|
|
110
|
+
.option('--debug', 'Enable debug mode');
|
|
111
|
+
|
|
112
|
+
program.parse();
|
|
113
|
+
const args = program.opts();
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
// Read and validate configuration
|
|
117
|
+
const config = await cardigantime.read(args);
|
|
118
|
+
await cardigantime.validate(config);
|
|
119
|
+
|
|
120
|
+
console.log('Configuration loaded successfully:', config);
|
|
121
|
+
|
|
122
|
+
// Your application logic here
|
|
123
|
+
await runMyApp(config);
|
|
124
|
+
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error('Configuration error:', error.message);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
main().catch(console.error);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Version Information with Git Details
|
|
135
|
+
|
|
136
|
+
Cardigantime exports its own version information including git commit details. You can also set up the same pattern in your own project.
|
|
137
|
+
|
|
138
|
+
#### Using Cardigantime's Version
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { VERSION, PROGRAM_NAME } from '@utilarium/cardigantime';
|
|
142
|
+
|
|
143
|
+
console.log(`Using ${PROGRAM_NAME}: ${VERSION}`);
|
|
144
|
+
// Output: Using cardigantime: 0.0.22-dev.0 (working/a1b2c3d 2026-01-27 11:11:46 -0800) darwin arm64 v24.8.0
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Setting Up Version Info in Your Own Project
|
|
148
|
+
|
|
149
|
+
To add the same detailed version format to your own CLI application, add this to your `vite.config.ts`:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { defineConfig } from 'vite';
|
|
153
|
+
import replace from '@rollup/plugin-replace';
|
|
154
|
+
import { execSync } from 'node:child_process';
|
|
155
|
+
|
|
156
|
+
// Extract git information at build time
|
|
157
|
+
let gitInfo = {
|
|
158
|
+
branch: '',
|
|
159
|
+
commit: '',
|
|
160
|
+
tags: '',
|
|
161
|
+
commitDate: '',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
gitInfo = {
|
|
166
|
+
branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
|
|
167
|
+
commit: execSync('git rev-parse --short HEAD').toString().trim(),
|
|
168
|
+
tags: '',
|
|
169
|
+
commitDate: execSync('git log -1 --format=%cd --date=iso').toString().trim(),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
gitInfo.tags = execSync('git tag --points-at HEAD | paste -sd "," -').toString().trim();
|
|
174
|
+
} catch {
|
|
175
|
+
gitInfo.tags = '';
|
|
176
|
+
}
|
|
177
|
+
} catch {
|
|
178
|
+
console.log('Directory does not have a Git repository, skipping git info');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export default defineConfig({
|
|
182
|
+
plugins: [
|
|
183
|
+
replace({
|
|
184
|
+
'__VERSION__': process.env.npm_package_version,
|
|
185
|
+
'__GIT_BRANCH__': gitInfo.branch,
|
|
186
|
+
'__GIT_COMMIT__': gitInfo.commit,
|
|
187
|
+
'__GIT_TAGS__': gitInfo.tags === '' ? '' : `T:${gitInfo.tags}`,
|
|
188
|
+
'__GIT_COMMIT_DATE__': gitInfo.commitDate,
|
|
189
|
+
'__SYSTEM_INFO__': `${process.platform} ${process.arch} ${process.version}`,
|
|
190
|
+
preventAssignment: true,
|
|
191
|
+
}),
|
|
192
|
+
// ... your other plugins
|
|
193
|
+
],
|
|
194
|
+
// ... rest of your config
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Then in your constants file:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
export const VERSION = '__VERSION__ (__GIT_BRANCH__/__GIT_COMMIT__ __GIT_TAGS__ __GIT_COMMIT_DATE__) __SYSTEM_INFO__';
|
|
202
|
+
export const PROGRAM_NAME = 'myapp';
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The placeholders will be replaced at build time with actual values. This is particularly useful for CLI applications where you need visibility into exactly which build is running.
|
|
206
|
+
|
|
207
|
+
### Configuration File Examples
|
|
208
|
+
|
|
209
|
+
Cardigantime supports multiple configuration formats. Choose the one that best fits your workflow:
|
|
210
|
+
|
|
211
|
+
#### YAML (`config/myapp.yaml`)
|
|
212
|
+
```yaml
|
|
213
|
+
apiKey: "your-secret-api-key"
|
|
214
|
+
timeout: 10000
|
|
215
|
+
retries: 5
|
|
216
|
+
debug: true
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### JSON (`config/myapp.json`)
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"apiKey": "your-secret-api-key",
|
|
223
|
+
"timeout": 10000,
|
|
224
|
+
"retries": 5,
|
|
225
|
+
"debug": true
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### JavaScript (`config/myapp.js`)
|
|
230
|
+
```javascript
|
|
231
|
+
module.exports = {
|
|
232
|
+
apiKey: process.env.API_KEY || "your-secret-api-key",
|
|
233
|
+
timeout: 10000,
|
|
234
|
+
retries: 5,
|
|
235
|
+
debug: process.env.NODE_ENV === 'development'
|
|
236
|
+
};
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### TypeScript (`config/myapp.ts`)
|
|
240
|
+
```typescript
|
|
241
|
+
export default {
|
|
242
|
+
apiKey: process.env.API_KEY || "your-secret-api-key",
|
|
243
|
+
timeout: 10000,
|
|
244
|
+
retries: 5,
|
|
245
|
+
debug: process.env.NODE_ENV === 'development'
|
|
246
|
+
} as const;
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Format Priority:** When multiple config files exist, Cardigantime uses this priority order:
|
|
250
|
+
1. TypeScript (`.ts`, `.mts`, `.cts`) - Highest priority
|
|
251
|
+
2. JavaScript (`.js`, `.mjs`, `.cjs`)
|
|
252
|
+
3. JSON (`.json`)
|
|
253
|
+
4. YAML (`.yaml`, `.yml`) - Lowest priority
|
|
254
|
+
|
|
255
|
+
You can override automatic detection with `--config-format`:
|
|
256
|
+
```bash
|
|
257
|
+
./myapp --config-format yaml # Force YAML even if JSON exists
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Example Usage
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# Use config from file
|
|
264
|
+
./myapp
|
|
265
|
+
|
|
266
|
+
# Override config with CLI arguments
|
|
267
|
+
./myapp --api-key "different-key" --timeout 15000
|
|
268
|
+
|
|
269
|
+
# Use different config directory
|
|
270
|
+
./myapp --config-directory /etc/myapp
|
|
271
|
+
|
|
272
|
+
# Generate initial configuration file
|
|
273
|
+
./myapp --init-config
|
|
274
|
+
|
|
275
|
+
# Analyze configuration with source tracking
|
|
276
|
+
./myapp --check-config
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## Key Features
|
|
280
|
+
|
|
281
|
+
### Configuration Sources & Precedence
|
|
282
|
+
Merges configuration from multiple sources in order of precedence:
|
|
283
|
+
1. **MCP invocation config** (highest priority - for AI assistant tools)
|
|
284
|
+
2. **Configuration file(s)** (medium priority)
|
|
285
|
+
3. **Environment variables** (low priority - system-wide defaults)
|
|
286
|
+
4. **Default values** (lowest priority)
|
|
287
|
+
|
|
288
|
+
### Environment Variable Configuration
|
|
289
|
+
Automatic environment variable support for all configuration fields:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// Define your schema
|
|
293
|
+
const schema = z.object({
|
|
294
|
+
planDirectory: z.string(),
|
|
295
|
+
port: z.number().default(3000),
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// Set environment variables
|
|
299
|
+
process.env.MYAPP_PLAN_DIRECTORY = '/plans';
|
|
300
|
+
process.env.MYAPP_PORT = '8080';
|
|
301
|
+
|
|
302
|
+
// Resolve config - env vars automatically discovered
|
|
303
|
+
const config = await resolveConfig({
|
|
304
|
+
schema,
|
|
305
|
+
appName: 'myapp',
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**Features:**
|
|
310
|
+
- Automatic naming: `planDirectory` → `MYAPP_PLAN_DIRECTORY`
|
|
311
|
+
- Type coercion: Strings parsed to numbers, booleans, arrays
|
|
312
|
+
- Custom names: Map to standard env vars like `OPENAI_API_KEY`
|
|
313
|
+
- Nested fields: `api.key` → `MYAPP_API_KEY`
|
|
314
|
+
|
|
315
|
+
### Multi-Format Configuration
|
|
316
|
+
Supports YAML (`.yaml`, `.yml`), JSON (`.json`), JavaScript (`.js`, `.mjs`, `.cjs`), and TypeScript (`.ts`, `.mts`, `.cts`) configuration files. When multiple formats exist, Cardigantime uses automatic format detection with configurable priority.
|
|
317
|
+
|
|
318
|
+
### Configuration Discovery
|
|
319
|
+
|
|
320
|
+
Cardigantime automatically searches for configuration files using multiple naming conventions, similar to how tools like Vite, ESLint, and TypeScript work:
|
|
321
|
+
|
|
322
|
+
| Priority | Pattern | Example |
|
|
323
|
+
|----------|---------|---------|
|
|
324
|
+
| 1 | `{app}.config.{ext}` | `myapp.config.yaml` |
|
|
325
|
+
| 2 | `{app}.conf.{ext}` | `myapp.conf.yaml` |
|
|
326
|
+
| 3 | `.{app}/config.{ext}` | `.myapp/config.yaml` |
|
|
327
|
+
| 4 | `.{app}rc.{ext}` | `.myapprc.yaml` |
|
|
328
|
+
| 5 | `.{app}rc` | `.myapprc` |
|
|
329
|
+
|
|
330
|
+
Modern visible config files (like `myapp.config.yaml`) are checked first for better discoverability.
|
|
331
|
+
|
|
332
|
+
### Hierarchical Configuration Discovery
|
|
333
|
+
Supports hierarchical configuration discovery, similar to how `.gitignore`, `.eslintrc`, or `package.json` work - searching up the directory tree for configuration directories.
|
|
334
|
+
|
|
335
|
+
**Hierarchical Modes:**
|
|
336
|
+
- `enabled` (default) - Merge configs from parent directories
|
|
337
|
+
- `disabled` - Use only the config in the starting directory
|
|
338
|
+
- `root-only` - Find first config, no merging
|
|
339
|
+
- `explicit` - Only merge explicitly referenced configs
|
|
340
|
+
|
|
341
|
+
```yaml
|
|
342
|
+
# Disable hierarchical for isolated projects
|
|
343
|
+
hierarchical:
|
|
344
|
+
mode: disabled
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### MCP Integration
|
|
348
|
+
First-class support for Model Context Protocol (MCP), enabling AI assistants to configure tools directly through MCP invocations. Includes:
|
|
349
|
+
- **MCP Configuration Priority** - MCP config takes exclusive precedence when provided
|
|
350
|
+
- **File-Based Fallback** - Automatic discovery from target file or working directory
|
|
351
|
+
- **CheckConfig Tool** - Built-in diagnostic tool for all MCP tools
|
|
352
|
+
- **Integration Helpers** - Simple APIs for adding MCP support to your tools
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
import { createMCPIntegration } from '@utilarium/cardigantime/mcp';
|
|
356
|
+
|
|
357
|
+
const integration = createMCPIntegration({
|
|
358
|
+
appName: 'myapp',
|
|
359
|
+
configSchema: myConfigSchema,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// CheckConfig tool is automatically available
|
|
363
|
+
// Config resolution handles MCP and file-based sources
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Type Safety & Validation
|
|
367
|
+
Full TypeScript support with Zod schema validation for robust, type-safe configuration management.
|
|
368
|
+
|
|
369
|
+
### Error Handling
|
|
370
|
+
Comprehensive error handling with detailed, actionable error messages to help users fix configuration issues quickly.
|
|
371
|
+
|
|
372
|
+
## Documentation
|
|
373
|
+
|
|
374
|
+
📚 **[Complete Documentation](https://utilarium.github.io/cardigantime/)** - Full documentation site
|
|
375
|
+
|
|
376
|
+
**Quick Links:**
|
|
377
|
+
- [Getting Started Guide](https://utilarium.github.io/cardigantime/#getting-started) - Detailed setup and basic concepts
|
|
378
|
+
- [Core Concepts](https://utilarium.github.io/cardigantime/#core-concepts) - Configuration sources, hierarchical discovery
|
|
379
|
+
- [MCP Integration](https://utilarium.github.io/cardigantime/#mcp-integration) - Model Context Protocol support for AI assistants
|
|
380
|
+
- [CheckConfig Tool](https://utilarium.github.io/cardigantime/#check-config-tool) - Built-in diagnostic tool
|
|
381
|
+
- [API Reference](https://utilarium.github.io/cardigantime/#api-reference) - Complete API documentation
|
|
382
|
+
- [Configuration Options](https://utilarium.github.io/cardigantime/#configuration-options) - All available options
|
|
383
|
+
- [Debugging & Analysis](https://utilarium.github.io/cardigantime/#debugging-analysis) - Tools for analyzing config
|
|
384
|
+
- [Advanced Usage](https://utilarium.github.io/cardigantime/#advanced-usage) - Complex examples and scenarios
|
|
385
|
+
- [Error Handling](https://utilarium.github.io/cardigantime/#error-handling) - Comprehensive error handling guide
|
|
386
|
+
|
|
387
|
+
## Contributing
|
|
388
|
+
|
|
389
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
390
|
+
|
|
391
|
+
## License
|
|
392
|
+
|
|
393
|
+
Apache-2.0 - see [LICENSE](LICENSE) file for details.
|
|
394
|
+
|
|
395
|
+
## Why "Cardigantime"?
|
|
396
|
+
|
|
397
|
+
Because configuration management should be as comfortable and reliable as your favorite cardigan. Just like a good cardigan keeps you warm and comfortable, Cardigantime keeps your application configuration cozy and well-organized.
|
|
398
|
+
|