@stoneforge/quarry 0.1.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 +13 -0
- package/README.md +160 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +8 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/quarry-api.d.ts +268 -0
- package/dist/api/quarry-api.d.ts.map +1 -0
- package/dist/api/quarry-api.js +3905 -0
- package/dist/api/quarry-api.js.map +1 -0
- package/dist/api/types.d.ts +1359 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +204 -0
- package/dist/api/types.js.map +1 -0
- package/dist/bin/sf.d.ts +3 -0
- package/dist/bin/sf.d.ts.map +1 -0
- package/dist/bin/sf.js +9 -0
- package/dist/bin/sf.js.map +1 -0
- package/dist/cli/commands/admin.d.ts +11 -0
- package/dist/cli/commands/admin.d.ts.map +1 -0
- package/dist/cli/commands/admin.js +465 -0
- package/dist/cli/commands/admin.js.map +1 -0
- package/dist/cli/commands/alias.d.ts +8 -0
- package/dist/cli/commands/alias.d.ts.map +1 -0
- package/dist/cli/commands/alias.js +70 -0
- package/dist/cli/commands/alias.js.map +1 -0
- package/dist/cli/commands/channel.d.ts +13 -0
- package/dist/cli/commands/channel.d.ts.map +1 -0
- package/dist/cli/commands/channel.js +680 -0
- package/dist/cli/commands/channel.js.map +1 -0
- package/dist/cli/commands/completion.d.ts +8 -0
- package/dist/cli/commands/completion.d.ts.map +1 -0
- package/dist/cli/commands/completion.js +87 -0
- package/dist/cli/commands/completion.js.map +1 -0
- package/dist/cli/commands/config.d.ts +12 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +242 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/crud.d.ts +64 -0
- package/dist/cli/commands/crud.d.ts.map +1 -0
- package/dist/cli/commands/crud.js +805 -0
- package/dist/cli/commands/crud.js.map +1 -0
- package/dist/cli/commands/dep.d.ts +16 -0
- package/dist/cli/commands/dep.d.ts.map +1 -0
- package/dist/cli/commands/dep.js +499 -0
- package/dist/cli/commands/dep.js.map +1 -0
- package/dist/cli/commands/document.d.ts +12 -0
- package/dist/cli/commands/document.d.ts.map +1 -0
- package/dist/cli/commands/document.js +1039 -0
- package/dist/cli/commands/document.js.map +1 -0
- package/dist/cli/commands/embeddings.d.ts +12 -0
- package/dist/cli/commands/embeddings.d.ts.map +1 -0
- package/dist/cli/commands/embeddings.js +273 -0
- package/dist/cli/commands/embeddings.js.map +1 -0
- package/dist/cli/commands/entity.d.ts +16 -0
- package/dist/cli/commands/entity.d.ts.map +1 -0
- package/dist/cli/commands/entity.js +522 -0
- package/dist/cli/commands/entity.js.map +1 -0
- package/dist/cli/commands/gc.d.ts +10 -0
- package/dist/cli/commands/gc.d.ts.map +1 -0
- package/dist/cli/commands/gc.js +257 -0
- package/dist/cli/commands/gc.js.map +1 -0
- package/dist/cli/commands/help.d.ts +11 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +169 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/history.d.ts +9 -0
- package/dist/cli/commands/history.d.ts.map +1 -0
- package/dist/cli/commands/history.js +160 -0
- package/dist/cli/commands/history.js.map +1 -0
- package/dist/cli/commands/identity.d.ts +18 -0
- package/dist/cli/commands/identity.d.ts.map +1 -0
- package/dist/cli/commands/identity.js +698 -0
- package/dist/cli/commands/identity.js.map +1 -0
- package/dist/cli/commands/inbox.d.ts +20 -0
- package/dist/cli/commands/inbox.d.ts.map +1 -0
- package/dist/cli/commands/inbox.js +493 -0
- package/dist/cli/commands/inbox.js.map +1 -0
- package/dist/cli/commands/init.d.ts +20 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +144 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/install.d.ts +9 -0
- package/dist/cli/commands/install.d.ts.map +1 -0
- package/dist/cli/commands/install.js +200 -0
- package/dist/cli/commands/install.js.map +1 -0
- package/dist/cli/commands/library.d.ts +12 -0
- package/dist/cli/commands/library.d.ts.map +1 -0
- package/dist/cli/commands/library.js +665 -0
- package/dist/cli/commands/library.js.map +1 -0
- package/dist/cli/commands/message.d.ts +11 -0
- package/dist/cli/commands/message.d.ts.map +1 -0
- package/dist/cli/commands/message.js +608 -0
- package/dist/cli/commands/message.js.map +1 -0
- package/dist/cli/commands/plan.d.ts +17 -0
- package/dist/cli/commands/plan.d.ts.map +1 -0
- package/dist/cli/commands/plan.js +698 -0
- package/dist/cli/commands/plan.js.map +1 -0
- package/dist/cli/commands/playbook.d.ts +12 -0
- package/dist/cli/commands/playbook.d.ts.map +1 -0
- package/dist/cli/commands/playbook.js +730 -0
- package/dist/cli/commands/playbook.js.map +1 -0
- package/dist/cli/commands/reset.d.ts +12 -0
- package/dist/cli/commands/reset.d.ts.map +1 -0
- package/dist/cli/commands/reset.js +306 -0
- package/dist/cli/commands/reset.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +11 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +106 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/stats.d.ts +8 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +82 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/commands/sync.d.ts +14 -0
- package/dist/cli/commands/sync.d.ts.map +1 -0
- package/dist/cli/commands/sync.js +370 -0
- package/dist/cli/commands/sync.js.map +1 -0
- package/dist/cli/commands/task.d.ts +25 -0
- package/dist/cli/commands/task.d.ts.map +1 -0
- package/dist/cli/commands/task.js +1153 -0
- package/dist/cli/commands/task.js.map +1 -0
- package/dist/cli/commands/team.d.ts +13 -0
- package/dist/cli/commands/team.d.ts.map +1 -0
- package/dist/cli/commands/team.js +471 -0
- package/dist/cli/commands/team.js.map +1 -0
- package/dist/cli/commands/workflow.d.ts +16 -0
- package/dist/cli/commands/workflow.d.ts.map +1 -0
- package/dist/cli/commands/workflow.js +753 -0
- package/dist/cli/commands/workflow.js.map +1 -0
- package/dist/cli/completion.d.ts +28 -0
- package/dist/cli/completion.d.ts.map +1 -0
- package/dist/cli/completion.js +295 -0
- package/dist/cli/completion.js.map +1 -0
- package/dist/cli/db.d.ts +38 -0
- package/dist/cli/db.d.ts.map +1 -0
- package/dist/cli/db.js +90 -0
- package/dist/cli/db.js.map +1 -0
- package/dist/cli/formatter.d.ts +87 -0
- package/dist/cli/formatter.d.ts.map +1 -0
- package/dist/cli/formatter.js +464 -0
- package/dist/cli/formatter.js.map +1 -0
- package/dist/cli/index.d.ts +33 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +38 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/parser.d.ts +45 -0
- package/dist/cli/parser.d.ts.map +1 -0
- package/dist/cli/parser.js +256 -0
- package/dist/cli/parser.js.map +1 -0
- package/dist/cli/plugin-loader.d.ts +39 -0
- package/dist/cli/plugin-loader.d.ts.map +1 -0
- package/dist/cli/plugin-loader.js +165 -0
- package/dist/cli/plugin-loader.js.map +1 -0
- package/dist/cli/plugin-registry.d.ts +50 -0
- package/dist/cli/plugin-registry.d.ts.map +1 -0
- package/dist/cli/plugin-registry.js +206 -0
- package/dist/cli/plugin-registry.js.map +1 -0
- package/dist/cli/plugin-types.d.ts +106 -0
- package/dist/cli/plugin-types.d.ts.map +1 -0
- package/dist/cli/plugin-types.js +103 -0
- package/dist/cli/plugin-types.js.map +1 -0
- package/dist/cli/runner.d.ts +35 -0
- package/dist/cli/runner.d.ts.map +1 -0
- package/dist/cli/runner.js +340 -0
- package/dist/cli/runner.js.map +1 -0
- package/dist/cli/suggest.d.ts +15 -0
- package/dist/cli/suggest.d.ts.map +1 -0
- package/dist/cli/suggest.js +49 -0
- package/dist/cli/suggest.js.map +1 -0
- package/dist/cli/types.d.ts +138 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +63 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config/config.d.ts +86 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +348 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/defaults.d.ts +66 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +114 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/duration.d.ts +75 -0
- package/dist/config/duration.d.ts.map +1 -0
- package/dist/config/duration.js +190 -0
- package/dist/config/duration.js.map +1 -0
- package/dist/config/env.d.ts +67 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +207 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/file.d.ts +97 -0
- package/dist/config/file.d.ts.map +1 -0
- package/dist/config/file.js +365 -0
- package/dist/config/file.js.map +1 -0
- package/dist/config/index.d.ts +35 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +41 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/merge.d.ts +53 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +226 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/config/types.d.ts +257 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +72 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validation.d.ts +55 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +251 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/http/index.d.ts +8 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +12 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/sync-handlers.d.ts +162 -0
- package/dist/http/sync-handlers.d.ts.map +1 -0
- package/dist/http/sync-handlers.js +271 -0
- package/dist/http/sync-handlers.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/server/index.d.ts +34 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3329 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/static.d.ts +18 -0
- package/dist/server/static.d.ts.map +1 -0
- package/dist/server/static.js +71 -0
- package/dist/server/static.js.map +1 -0
- package/dist/server/ws/broadcaster.d.ts +8 -0
- package/dist/server/ws/broadcaster.d.ts.map +1 -0
- package/dist/server/ws/broadcaster.js +7 -0
- package/dist/server/ws/broadcaster.js.map +1 -0
- package/dist/server/ws/handler.d.ts +55 -0
- package/dist/server/ws/handler.d.ts.map +1 -0
- package/dist/server/ws/handler.js +160 -0
- package/dist/server/ws/handler.js.map +1 -0
- package/dist/services/blocked-cache.d.ts +297 -0
- package/dist/services/blocked-cache.d.ts.map +1 -0
- package/dist/services/blocked-cache.js +755 -0
- package/dist/services/blocked-cache.js.map +1 -0
- package/dist/services/dependency.d.ts +205 -0
- package/dist/services/dependency.d.ts.map +1 -0
- package/dist/services/dependency.js +566 -0
- package/dist/services/dependency.js.map +1 -0
- package/dist/services/embeddings/fusion.d.ts +33 -0
- package/dist/services/embeddings/fusion.d.ts.map +1 -0
- package/dist/services/embeddings/fusion.js +34 -0
- package/dist/services/embeddings/fusion.js.map +1 -0
- package/dist/services/embeddings/index.d.ts +12 -0
- package/dist/services/embeddings/index.d.ts.map +1 -0
- package/dist/services/embeddings/index.js +10 -0
- package/dist/services/embeddings/index.js.map +1 -0
- package/dist/services/embeddings/local-provider.d.ts +31 -0
- package/dist/services/embeddings/local-provider.d.ts.map +1 -0
- package/dist/services/embeddings/local-provider.js +80 -0
- package/dist/services/embeddings/local-provider.js.map +1 -0
- package/dist/services/embeddings/service.d.ts +76 -0
- package/dist/services/embeddings/service.d.ts.map +1 -0
- package/dist/services/embeddings/service.js +153 -0
- package/dist/services/embeddings/service.js.map +1 -0
- package/dist/services/embeddings/types.d.ts +70 -0
- package/dist/services/embeddings/types.d.ts.map +1 -0
- package/dist/services/embeddings/types.js +8 -0
- package/dist/services/embeddings/types.js.map +1 -0
- package/dist/services/id-length-cache.d.ts +156 -0
- package/dist/services/id-length-cache.d.ts.map +1 -0
- package/dist/services/id-length-cache.js +197 -0
- package/dist/services/id-length-cache.js.map +1 -0
- package/dist/services/inbox.d.ts +147 -0
- package/dist/services/inbox.d.ts.map +1 -0
- package/dist/services/inbox.js +428 -0
- package/dist/services/inbox.js.map +1 -0
- package/dist/services/index.d.ts +10 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +10 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/priority-service.d.ts +145 -0
- package/dist/services/priority-service.d.ts.map +1 -0
- package/dist/services/priority-service.js +272 -0
- package/dist/services/priority-service.js.map +1 -0
- package/dist/services/search-utils.d.ts +47 -0
- package/dist/services/search-utils.d.ts.map +1 -0
- package/dist/services/search-utils.js +83 -0
- package/dist/services/search-utils.js.map +1 -0
- package/dist/sync/hash.d.ts +48 -0
- package/dist/sync/hash.d.ts.map +1 -0
- package/dist/sync/hash.js +136 -0
- package/dist/sync/hash.js.map +1 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +16 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/merge.d.ts +80 -0
- package/dist/sync/merge.d.ts.map +1 -0
- package/dist/sync/merge.js +310 -0
- package/dist/sync/merge.js.map +1 -0
- package/dist/sync/serialization.d.ts +132 -0
- package/dist/sync/serialization.d.ts.map +1 -0
- package/dist/sync/serialization.js +306 -0
- package/dist/sync/serialization.js.map +1 -0
- package/dist/sync/service.d.ts +102 -0
- package/dist/sync/service.d.ts.map +1 -0
- package/dist/sync/service.js +493 -0
- package/dist/sync/service.js.map +1 -0
- package/dist/sync/types.d.ts +275 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +76 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/systems/identity.d.ts +479 -0
- package/dist/systems/identity.d.ts.map +1 -0
- package/dist/systems/identity.js +817 -0
- package/dist/systems/identity.js.map +1 -0
- package/dist/systems/index.d.ts +8 -0
- package/dist/systems/index.d.ts.map +1 -0
- package/dist/systems/index.js +29 -0
- package/dist/systems/index.js.map +1 -0
- package/package.json +121 -0
- package/web/assets/charts-vendor-D1YcbGux.js +55 -0
- package/web/assets/dnd-vendor-DmxE-_ZH.js +5 -0
- package/web/assets/editor-vendor-BxraAWts.js +279 -0
- package/web/assets/index-B77vv208.js +341 -0
- package/web/assets/index-CF_XnVLh.css +1 -0
- package/web/assets/router-vendor-BCKpRBrB.js +41 -0
- package/web/assets/ui-vendor-DUahGnbT.js +45 -0
- package/web/assets/utils-vendor-CfYKiENT.js +813 -0
- package/web/favicon.ico +0 -0
- package/web/index.html +23 -0
- package/web/logo.png +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duration Parsing and Formatting
|
|
3
|
+
*
|
|
4
|
+
* Handles conversion between duration strings (e.g., '5m', '500ms', '24h')
|
|
5
|
+
* and millisecond values.
|
|
6
|
+
*/
|
|
7
|
+
import type { Duration, DurationString } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Duration unit multipliers (to milliseconds)
|
|
10
|
+
*/
|
|
11
|
+
export declare const DURATION_UNITS: Record<string, number>;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a value is a valid duration string
|
|
14
|
+
*/
|
|
15
|
+
export declare function isDurationString(value: unknown): value is DurationString;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a duration string to milliseconds
|
|
18
|
+
*
|
|
19
|
+
* @param value - Duration string (e.g., '5m', '500ms', '24h', '30d')
|
|
20
|
+
* @returns Duration in milliseconds
|
|
21
|
+
* @throws ValidationError if format is invalid
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* parseDuration('500ms') // 500
|
|
25
|
+
* parseDuration('5s') // 5000
|
|
26
|
+
* parseDuration('5m') // 300000
|
|
27
|
+
* parseDuration('24h') // 86400000
|
|
28
|
+
* parseDuration('30d') // 2592000000
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseDuration(value: string): Duration;
|
|
31
|
+
/**
|
|
32
|
+
* Parses a duration value that may be string or number
|
|
33
|
+
*
|
|
34
|
+
* @param value - Duration string or number (milliseconds)
|
|
35
|
+
* @returns Duration in milliseconds
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseDurationValue(value: string | number): Duration;
|
|
38
|
+
/**
|
|
39
|
+
* Safely parses a duration, returning undefined on failure
|
|
40
|
+
*/
|
|
41
|
+
export declare function tryParseDuration(value: unknown): Duration | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Formats a duration in milliseconds to a human-readable string
|
|
44
|
+
* Uses the largest appropriate unit
|
|
45
|
+
*
|
|
46
|
+
* @param ms - Duration in milliseconds
|
|
47
|
+
* @returns Formatted duration string
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* formatDuration(500) // '500ms'
|
|
51
|
+
* formatDuration(5000) // '5s'
|
|
52
|
+
* formatDuration(300000) // '5m'
|
|
53
|
+
* formatDuration(86400000) // '24h'
|
|
54
|
+
* formatDuration(2592000000) // '30d'
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatDuration(ms: Duration): string;
|
|
57
|
+
/**
|
|
58
|
+
* Formats a duration with appropriate precision for display
|
|
59
|
+
* May produce decimal values for better readability
|
|
60
|
+
*
|
|
61
|
+
* @param ms - Duration in milliseconds
|
|
62
|
+
* @returns Human-readable duration string
|
|
63
|
+
*/
|
|
64
|
+
export declare function formatDurationHuman(ms: Duration): string;
|
|
65
|
+
/**
|
|
66
|
+
* Validates a duration is within an allowed range
|
|
67
|
+
*
|
|
68
|
+
* @param value - Duration in milliseconds
|
|
69
|
+
* @param min - Minimum allowed value
|
|
70
|
+
* @param max - Maximum allowed value
|
|
71
|
+
* @param field - Field name for error messages
|
|
72
|
+
* @returns The validated duration
|
|
73
|
+
*/
|
|
74
|
+
export declare function validateDurationRange(value: Duration, min: Duration, max: Duration, field: string): Duration;
|
|
75
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/config/duration.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAM3D;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMjD,CAAC;AAWF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAiCrD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAYnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAYrE;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAuBnD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CA+BxD;AAMD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,QAAQ,EACf,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,MAAM,GACZ,QAAQ,CAgBV"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duration Parsing and Formatting
|
|
3
|
+
*
|
|
4
|
+
* Handles conversion between duration strings (e.g., '5m', '500ms', '24h')
|
|
5
|
+
* and millisecond values.
|
|
6
|
+
*/
|
|
7
|
+
import { ValidationError, ErrorCode } from '@stoneforge/core';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Duration Units
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Duration unit multipliers (to milliseconds)
|
|
13
|
+
*/
|
|
14
|
+
export const DURATION_UNITS = {
|
|
15
|
+
ms: 1,
|
|
16
|
+
s: 1000,
|
|
17
|
+
m: 60 * 1000,
|
|
18
|
+
h: 60 * 60 * 1000,
|
|
19
|
+
d: 24 * 60 * 60 * 1000,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Duration string pattern: number followed by unit
|
|
23
|
+
*/
|
|
24
|
+
const DURATION_PATTERN = /^(\d+(?:\.\d+)?)(ms|s|m|h|d)$/;
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Parsing Functions
|
|
27
|
+
// ============================================================================
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a value is a valid duration string
|
|
30
|
+
*/
|
|
31
|
+
export function isDurationString(value) {
|
|
32
|
+
if (typeof value !== 'string') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return DURATION_PATTERN.test(value);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parses a duration string to milliseconds
|
|
39
|
+
*
|
|
40
|
+
* @param value - Duration string (e.g., '5m', '500ms', '24h', '30d')
|
|
41
|
+
* @returns Duration in milliseconds
|
|
42
|
+
* @throws ValidationError if format is invalid
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* parseDuration('500ms') // 500
|
|
46
|
+
* parseDuration('5s') // 5000
|
|
47
|
+
* parseDuration('5m') // 300000
|
|
48
|
+
* parseDuration('24h') // 86400000
|
|
49
|
+
* parseDuration('30d') // 2592000000
|
|
50
|
+
*/
|
|
51
|
+
export function parseDuration(value) {
|
|
52
|
+
const match = value.match(DURATION_PATTERN);
|
|
53
|
+
if (!match) {
|
|
54
|
+
throw new ValidationError(`Invalid duration format: '${value}'. Expected format: <number><unit> (e.g., '500ms', '5m', '24h', '30d')`, ErrorCode.INVALID_INPUT, { field: 'duration', value, expected: '<number><unit> where unit is ms, s, m, h, or d' });
|
|
55
|
+
}
|
|
56
|
+
const [, numStr, unit] = match;
|
|
57
|
+
const num = parseFloat(numStr);
|
|
58
|
+
const multiplier = DURATION_UNITS[unit];
|
|
59
|
+
if (multiplier === undefined) {
|
|
60
|
+
throw new ValidationError(`Unknown duration unit: '${unit}'. Valid units: ms, s, m, h, d`, ErrorCode.INVALID_INPUT, { field: 'duration', value, expected: 'ms, s, m, h, or d' });
|
|
61
|
+
}
|
|
62
|
+
const result = num * multiplier;
|
|
63
|
+
if (!Number.isFinite(result)) {
|
|
64
|
+
throw new ValidationError(`Duration overflow: '${value}' produces non-finite value`, ErrorCode.INVALID_INPUT, { field: 'duration', value });
|
|
65
|
+
}
|
|
66
|
+
return Math.round(result);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parses a duration value that may be string or number
|
|
70
|
+
*
|
|
71
|
+
* @param value - Duration string or number (milliseconds)
|
|
72
|
+
* @returns Duration in milliseconds
|
|
73
|
+
*/
|
|
74
|
+
export function parseDurationValue(value) {
|
|
75
|
+
if (typeof value === 'number') {
|
|
76
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
77
|
+
throw new ValidationError(`Invalid duration value: ${value}. Must be a non-negative finite number`, ErrorCode.INVALID_INPUT, { field: 'duration', value, expected: 'non-negative finite number' });
|
|
78
|
+
}
|
|
79
|
+
return Math.round(value);
|
|
80
|
+
}
|
|
81
|
+
return parseDuration(value);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Safely parses a duration, returning undefined on failure
|
|
85
|
+
*/
|
|
86
|
+
export function tryParseDuration(value) {
|
|
87
|
+
if (typeof value === 'number' && Number.isFinite(value) && value >= 0) {
|
|
88
|
+
return Math.round(value);
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === 'string') {
|
|
91
|
+
try {
|
|
92
|
+
return parseDuration(value);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
// ============================================================================
|
|
101
|
+
// Formatting Functions
|
|
102
|
+
// ============================================================================
|
|
103
|
+
/**
|
|
104
|
+
* Formats a duration in milliseconds to a human-readable string
|
|
105
|
+
* Uses the largest appropriate unit
|
|
106
|
+
*
|
|
107
|
+
* @param ms - Duration in milliseconds
|
|
108
|
+
* @returns Formatted duration string
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* formatDuration(500) // '500ms'
|
|
112
|
+
* formatDuration(5000) // '5s'
|
|
113
|
+
* formatDuration(300000) // '5m'
|
|
114
|
+
* formatDuration(86400000) // '24h'
|
|
115
|
+
* formatDuration(2592000000) // '30d'
|
|
116
|
+
*/
|
|
117
|
+
export function formatDuration(ms) {
|
|
118
|
+
if (ms < 0) {
|
|
119
|
+
throw new ValidationError(`Cannot format negative duration: ${ms}`, ErrorCode.INVALID_INPUT, { field: 'duration', value: ms });
|
|
120
|
+
}
|
|
121
|
+
// Try each unit from largest to smallest
|
|
122
|
+
if (ms >= DURATION_UNITS.d && ms % DURATION_UNITS.d === 0) {
|
|
123
|
+
return `${ms / DURATION_UNITS.d}d`;
|
|
124
|
+
}
|
|
125
|
+
if (ms >= DURATION_UNITS.h && ms % DURATION_UNITS.h === 0) {
|
|
126
|
+
return `${ms / DURATION_UNITS.h}h`;
|
|
127
|
+
}
|
|
128
|
+
if (ms >= DURATION_UNITS.m && ms % DURATION_UNITS.m === 0) {
|
|
129
|
+
return `${ms / DURATION_UNITS.m}m`;
|
|
130
|
+
}
|
|
131
|
+
if (ms >= DURATION_UNITS.s && ms % DURATION_UNITS.s === 0) {
|
|
132
|
+
return `${ms / DURATION_UNITS.s}s`;
|
|
133
|
+
}
|
|
134
|
+
return `${ms}ms`;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Formats a duration with appropriate precision for display
|
|
138
|
+
* May produce decimal values for better readability
|
|
139
|
+
*
|
|
140
|
+
* @param ms - Duration in milliseconds
|
|
141
|
+
* @returns Human-readable duration string
|
|
142
|
+
*/
|
|
143
|
+
export function formatDurationHuman(ms) {
|
|
144
|
+
if (ms < 0) {
|
|
145
|
+
throw new ValidationError(`Cannot format negative duration: ${ms}`, ErrorCode.INVALID_INPUT, { field: 'duration', value: ms });
|
|
146
|
+
}
|
|
147
|
+
if (ms === 0) {
|
|
148
|
+
return '0ms';
|
|
149
|
+
}
|
|
150
|
+
// Use the most appropriate unit
|
|
151
|
+
if (ms >= DURATION_UNITS.d) {
|
|
152
|
+
const days = ms / DURATION_UNITS.d;
|
|
153
|
+
return days === Math.floor(days) ? `${days}d` : `${days.toFixed(1)}d`;
|
|
154
|
+
}
|
|
155
|
+
if (ms >= DURATION_UNITS.h) {
|
|
156
|
+
const hours = ms / DURATION_UNITS.h;
|
|
157
|
+
return hours === Math.floor(hours) ? `${hours}h` : `${hours.toFixed(1)}h`;
|
|
158
|
+
}
|
|
159
|
+
if (ms >= DURATION_UNITS.m) {
|
|
160
|
+
const mins = ms / DURATION_UNITS.m;
|
|
161
|
+
return mins === Math.floor(mins) ? `${mins}m` : `${mins.toFixed(1)}m`;
|
|
162
|
+
}
|
|
163
|
+
if (ms >= DURATION_UNITS.s) {
|
|
164
|
+
const secs = ms / DURATION_UNITS.s;
|
|
165
|
+
return secs === Math.floor(secs) ? `${secs}s` : `${secs.toFixed(1)}s`;
|
|
166
|
+
}
|
|
167
|
+
return `${ms}ms`;
|
|
168
|
+
}
|
|
169
|
+
// ============================================================================
|
|
170
|
+
// Validation Functions
|
|
171
|
+
// ============================================================================
|
|
172
|
+
/**
|
|
173
|
+
* Validates a duration is within an allowed range
|
|
174
|
+
*
|
|
175
|
+
* @param value - Duration in milliseconds
|
|
176
|
+
* @param min - Minimum allowed value
|
|
177
|
+
* @param max - Maximum allowed value
|
|
178
|
+
* @param field - Field name for error messages
|
|
179
|
+
* @returns The validated duration
|
|
180
|
+
*/
|
|
181
|
+
export function validateDurationRange(value, min, max, field) {
|
|
182
|
+
if (value < min) {
|
|
183
|
+
throw new ValidationError(`${field} must be at least ${formatDuration(min)}, got ${formatDuration(value)}`, ErrorCode.INVALID_INPUT, { field, value, expected: `>= ${formatDuration(min)}`, actual: formatDuration(value) });
|
|
184
|
+
}
|
|
185
|
+
if (value > max) {
|
|
186
|
+
throw new ValidationError(`${field} must be at most ${formatDuration(max)}, got ${formatDuration(value)}`, ErrorCode.INVALID_INPUT, { field, value, expected: `<= ${formatDuration(max)}`, actual: formatDuration(value) });
|
|
187
|
+
}
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../src/config/duration.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG9D,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAA2B;IACpD,EAAE,EAAE,CAAC;IACL,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,EAAE,GAAG,IAAI;IACZ,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACjB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AAEzD,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CA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AS,cAAc,CAAC,KAAK,CAAC,EAAE,EAChF,SAAS,CAAC,aAAa,EACvB,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CACvF,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QAChB,MAAM,IAAI,eAAe,CACvB,GAAG,KAAK,oBAAoB,cAAc,CAAC,GAAG,CAAC,SAAS,cAAc,CAAC,KAAK,CAAC,EAAE,EAC/E,SAAS,CAAC,aAAa,EACvB,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CACvF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Variable Configuration
|
|
3
|
+
*
|
|
4
|
+
* Handles reading configuration from environment variables.
|
|
5
|
+
*/
|
|
6
|
+
import type { PartialConfiguration, EnvVar } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Parses a boolean from an environment variable value
|
|
9
|
+
*
|
|
10
|
+
* @param value - Environment variable value
|
|
11
|
+
* @returns Parsed boolean, or undefined if not a recognized boolean value
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseEnvBoolean(value: string | undefined): boolean | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a value is a recognized boolean string
|
|
16
|
+
*/
|
|
17
|
+
export declare function isEnvBoolean(value: string | undefined): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Parses a duration from an environment variable value
|
|
20
|
+
*
|
|
21
|
+
* @param value - Environment variable value
|
|
22
|
+
* @returns Parsed duration in ms, or undefined if invalid
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseEnvDuration(value: string | undefined): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Gets a raw environment variable value
|
|
27
|
+
*/
|
|
28
|
+
export declare function getEnvVar(name: EnvVar): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if an environment variable is set (non-empty)
|
|
31
|
+
*/
|
|
32
|
+
export declare function hasEnvVar(name: EnvVar): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Loads configuration from environment variables
|
|
35
|
+
*
|
|
36
|
+
* @returns Partial configuration from environment variables
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadEnvConfig(): PartialConfiguration;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the config file path override from environment
|
|
41
|
+
*/
|
|
42
|
+
export declare function getEnvConfigPath(): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the JSON output mode flag from environment
|
|
45
|
+
*/
|
|
46
|
+
export declare function getEnvJsonMode(): boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the verbose/debug mode flag from environment
|
|
49
|
+
*/
|
|
50
|
+
export declare function getEnvVerboseMode(): boolean | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Gets information about all supported environment variables
|
|
53
|
+
*/
|
|
54
|
+
export declare function getEnvVarInfo(): Array<{
|
|
55
|
+
name: EnvVar;
|
|
56
|
+
configPath: string;
|
|
57
|
+
type: string;
|
|
58
|
+
description: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets currently set environment variables for configuration
|
|
62
|
+
*/
|
|
63
|
+
export declare function getSetEnvVars(): Array<{
|
|
64
|
+
name: EnvVar;
|
|
65
|
+
value: string;
|
|
66
|
+
}>;
|
|
67
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAkB/D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAY9E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAM/D;AAMD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAoB9E;AAMD;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE1D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG/C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,oBAAoB,CA8BpD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAGrD;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,OAAO,GAAG,SAAS,CAEpD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,GAAG,SAAS,CAEvD;AAMD;;GAEG;AACH,wBAAgB,aAAa,IAAI,KAAK,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CA6CD;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAStE"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Variable Configuration
|
|
3
|
+
*
|
|
4
|
+
* Handles reading configuration from environment variables.
|
|
5
|
+
*/
|
|
6
|
+
import { isValidIdentityMode } from '../systems/identity.js';
|
|
7
|
+
import { EnvVars } from './types.js';
|
|
8
|
+
import { tryParseDuration } from './duration.js';
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Boolean Parsing
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Truthy values for environment variables (case-insensitive)
|
|
14
|
+
*/
|
|
15
|
+
const TRUTHY_VALUES = new Set(['1', 'true', 'yes', 'on']);
|
|
16
|
+
/**
|
|
17
|
+
* Falsy values for environment variables (case-insensitive)
|
|
18
|
+
*/
|
|
19
|
+
const FALSY_VALUES = new Set(['0', 'false', 'no', 'off']);
|
|
20
|
+
/**
|
|
21
|
+
* Parses a boolean from an environment variable value
|
|
22
|
+
*
|
|
23
|
+
* @param value - Environment variable value
|
|
24
|
+
* @returns Parsed boolean, or undefined if not a recognized boolean value
|
|
25
|
+
*/
|
|
26
|
+
export function parseEnvBoolean(value) {
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const lower = value.toLowerCase().trim();
|
|
31
|
+
if (TRUTHY_VALUES.has(lower)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (FALSY_VALUES.has(lower)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a value is a recognized boolean string
|
|
41
|
+
*/
|
|
42
|
+
export function isEnvBoolean(value) {
|
|
43
|
+
if (value === undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const lower = value.toLowerCase().trim();
|
|
47
|
+
return TRUTHY_VALUES.has(lower) || FALSY_VALUES.has(lower);
|
|
48
|
+
}
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// Duration Parsing
|
|
51
|
+
// ============================================================================
|
|
52
|
+
/**
|
|
53
|
+
* Parses a duration from an environment variable value
|
|
54
|
+
*
|
|
55
|
+
* @param value - Environment variable value
|
|
56
|
+
* @returns Parsed duration in ms, or undefined if invalid
|
|
57
|
+
*/
|
|
58
|
+
export function parseEnvDuration(value) {
|
|
59
|
+
if (value === undefined) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
// First try as duration string (e.g., '5m', '500ms')
|
|
63
|
+
const asDuration = tryParseDuration(value);
|
|
64
|
+
if (asDuration !== undefined) {
|
|
65
|
+
return asDuration;
|
|
66
|
+
}
|
|
67
|
+
// Try as pure number (milliseconds) - only if it's a pure numeric string
|
|
68
|
+
if (/^\d+(\.\d+)?$/.test(value)) {
|
|
69
|
+
const asNumber = parseFloat(value);
|
|
70
|
+
if (!isNaN(asNumber) && Number.isFinite(asNumber) && asNumber >= 0) {
|
|
71
|
+
return Math.round(asNumber);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
// ============================================================================
|
|
77
|
+
// Environment Configuration Loading
|
|
78
|
+
// ============================================================================
|
|
79
|
+
/**
|
|
80
|
+
* Gets a raw environment variable value
|
|
81
|
+
*/
|
|
82
|
+
export function getEnvVar(name) {
|
|
83
|
+
return process.env[name];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks if an environment variable is set (non-empty)
|
|
87
|
+
*/
|
|
88
|
+
export function hasEnvVar(name) {
|
|
89
|
+
const value = process.env[name];
|
|
90
|
+
return value !== undefined && value !== '';
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Loads configuration from environment variables
|
|
94
|
+
*
|
|
95
|
+
* @returns Partial configuration from environment variables
|
|
96
|
+
*/
|
|
97
|
+
export function loadEnvConfig() {
|
|
98
|
+
const config = {};
|
|
99
|
+
// Actor
|
|
100
|
+
const actor = getEnvVar(EnvVars.ACTOR);
|
|
101
|
+
if (actor !== undefined && actor !== '') {
|
|
102
|
+
config.actor = actor;
|
|
103
|
+
}
|
|
104
|
+
// Database
|
|
105
|
+
const database = getEnvVar(EnvVars.DATABASE);
|
|
106
|
+
if (database !== undefined && database !== '') {
|
|
107
|
+
config.database = database;
|
|
108
|
+
}
|
|
109
|
+
// Sync auto-export
|
|
110
|
+
const autoExport = parseEnvBoolean(getEnvVar(EnvVars.SYNC_AUTO_EXPORT));
|
|
111
|
+
if (autoExport !== undefined) {
|
|
112
|
+
config.sync = config.sync || {};
|
|
113
|
+
config.sync.autoExport = autoExport;
|
|
114
|
+
}
|
|
115
|
+
// Identity mode
|
|
116
|
+
const identityMode = getEnvVar(EnvVars.IDENTITY_MODE);
|
|
117
|
+
if (identityMode !== undefined && isValidIdentityMode(identityMode)) {
|
|
118
|
+
config.identity = config.identity || {};
|
|
119
|
+
config.identity.mode = identityMode;
|
|
120
|
+
}
|
|
121
|
+
return config;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Gets the config file path override from environment
|
|
125
|
+
*/
|
|
126
|
+
export function getEnvConfigPath() {
|
|
127
|
+
const value = getEnvVar(EnvVars.CONFIG);
|
|
128
|
+
return value !== undefined && value !== '' ? value : undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Gets the JSON output mode flag from environment
|
|
132
|
+
*/
|
|
133
|
+
export function getEnvJsonMode() {
|
|
134
|
+
return parseEnvBoolean(getEnvVar(EnvVars.JSON));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Gets the verbose/debug mode flag from environment
|
|
138
|
+
*/
|
|
139
|
+
export function getEnvVerboseMode() {
|
|
140
|
+
return parseEnvBoolean(getEnvVar(EnvVars.VERBOSE));
|
|
141
|
+
}
|
|
142
|
+
// ============================================================================
|
|
143
|
+
// Environment Variable Information
|
|
144
|
+
// ============================================================================
|
|
145
|
+
/**
|
|
146
|
+
* Gets information about all supported environment variables
|
|
147
|
+
*/
|
|
148
|
+
export function getEnvVarInfo() {
|
|
149
|
+
return [
|
|
150
|
+
{
|
|
151
|
+
name: EnvVars.ACTOR,
|
|
152
|
+
configPath: 'actor',
|
|
153
|
+
type: 'string',
|
|
154
|
+
description: 'Default actor name for operations',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: EnvVars.DATABASE,
|
|
158
|
+
configPath: 'database',
|
|
159
|
+
type: 'string',
|
|
160
|
+
description: 'Database filename',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: EnvVars.CONFIG,
|
|
164
|
+
configPath: '(file path)',
|
|
165
|
+
type: 'string',
|
|
166
|
+
description: 'Override config file path',
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: EnvVars.JSON,
|
|
170
|
+
configPath: '(output mode)',
|
|
171
|
+
type: 'boolean',
|
|
172
|
+
description: 'JSON output mode',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: EnvVars.VERBOSE,
|
|
176
|
+
configPath: '(debug mode)',
|
|
177
|
+
type: 'boolean',
|
|
178
|
+
description: 'Verbose/debug mode',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: EnvVars.SYNC_AUTO_EXPORT,
|
|
182
|
+
configPath: 'sync.autoExport',
|
|
183
|
+
type: 'boolean',
|
|
184
|
+
description: 'Auto-export on mutations',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: EnvVars.IDENTITY_MODE,
|
|
188
|
+
configPath: 'identity.mode',
|
|
189
|
+
type: 'string',
|
|
190
|
+
description: 'Identity verification mode (soft, cryptographic, hybrid)',
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Gets currently set environment variables for configuration
|
|
196
|
+
*/
|
|
197
|
+
export function getSetEnvVars() {
|
|
198
|
+
const result = [];
|
|
199
|
+
for (const name of Object.values(EnvVars)) {
|
|
200
|
+
const value = process.env[name];
|
|
201
|
+
if (value !== undefined && value !== '') {
|
|
202
|
+
result.push({ name, value });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
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AAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration File Loading
|
|
3
|
+
*
|
|
4
|
+
* Handles YAML configuration file parsing, discovery, and writing.
|
|
5
|
+
*/
|
|
6
|
+
import type { Configuration, PartialConfiguration, YamlConfigFile, ConfigFileDiscovery } from './types.js';
|
|
7
|
+
/** Default config file name */
|
|
8
|
+
export declare const CONFIG_FILE_NAME = "config.yaml";
|
|
9
|
+
/** Default .stoneforge directory name */
|
|
10
|
+
export declare const STONEFORGE_DIR = ".stoneforge";
|
|
11
|
+
/**
|
|
12
|
+
* Finds the nearest .stoneforge directory by walking up from the given directory.
|
|
13
|
+
*
|
|
14
|
+
* This function first checks the STONEFORGE_ROOT environment variable, which
|
|
15
|
+
* is used to support agents working in git worktrees. When an agent is spawned
|
|
16
|
+
* in a worktree, STONEFORGE_ROOT points to the main workspace root where the
|
|
17
|
+
* SQLite database lives.
|
|
18
|
+
*
|
|
19
|
+
* @param startDir - Directory to start searching from
|
|
20
|
+
* @returns Path to .stoneforge directory, or undefined if not found
|
|
21
|
+
*/
|
|
22
|
+
export declare function findStoneforgeDir(startDir: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the global config directory path
|
|
25
|
+
*/
|
|
26
|
+
export declare function getGlobalConfigDir(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the global config file path
|
|
29
|
+
*/
|
|
30
|
+
export declare function getGlobalConfigPath(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Discovers the configuration file location
|
|
33
|
+
*
|
|
34
|
+
* @param overridePath - Optional override path to use
|
|
35
|
+
* @param startDir - Directory to start searching from (default: cwd)
|
|
36
|
+
* @returns Discovery result with path and existence info
|
|
37
|
+
*/
|
|
38
|
+
export declare function discoverConfigFile(overridePath?: string, startDir?: string): ConfigFileDiscovery;
|
|
39
|
+
/**
|
|
40
|
+
* Parses YAML content into a config file structure
|
|
41
|
+
*
|
|
42
|
+
* @param content - YAML string content
|
|
43
|
+
* @param filePath - Path to file (for error messages)
|
|
44
|
+
* @returns Parsed YAML config object
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseYamlConfig(content: string, filePath?: string): YamlConfigFile;
|
|
47
|
+
/**
|
|
48
|
+
* Converts YAML config (snake_case) to internal format (camelCase)
|
|
49
|
+
*
|
|
50
|
+
* @param yamlConfig - Parsed YAML config
|
|
51
|
+
* @returns Partial configuration in internal format
|
|
52
|
+
*/
|
|
53
|
+
export declare function convertYamlToConfig(yamlConfig: YamlConfigFile): PartialConfiguration;
|
|
54
|
+
/**
|
|
55
|
+
* Reads and parses a configuration file
|
|
56
|
+
*
|
|
57
|
+
* @param filePath - Path to the configuration file
|
|
58
|
+
* @returns Partial configuration from the file
|
|
59
|
+
*/
|
|
60
|
+
export declare function readConfigFile(filePath: string): PartialConfiguration;
|
|
61
|
+
/**
|
|
62
|
+
* Converts internal config (camelCase) to YAML format (snake_case)
|
|
63
|
+
*
|
|
64
|
+
* @param config - Configuration in internal format
|
|
65
|
+
* @returns YAML config object
|
|
66
|
+
*/
|
|
67
|
+
export declare function convertConfigToYaml(config: Configuration | PartialConfiguration): YamlConfigFile;
|
|
68
|
+
/**
|
|
69
|
+
* Serializes configuration to YAML string
|
|
70
|
+
*
|
|
71
|
+
* @param config - Configuration to serialize
|
|
72
|
+
* @returns YAML string
|
|
73
|
+
*/
|
|
74
|
+
export declare function serializeConfigToYaml(config: Configuration | PartialConfiguration): string;
|
|
75
|
+
/**
|
|
76
|
+
* Writes configuration to a file
|
|
77
|
+
*
|
|
78
|
+
* @param filePath - Path to write to
|
|
79
|
+
* @param config - Configuration to write
|
|
80
|
+
*/
|
|
81
|
+
export declare function writeConfigFile(filePath: string, config: Configuration | PartialConfiguration): void;
|
|
82
|
+
/**
|
|
83
|
+
* Updates a configuration file by merging with existing content
|
|
84
|
+
*
|
|
85
|
+
* @param filePath - Path to the configuration file
|
|
86
|
+
* @param updates - Partial configuration to merge
|
|
87
|
+
*/
|
|
88
|
+
export declare function updateConfigFile(filePath: string, updates: PartialConfiguration): void;
|
|
89
|
+
/**
|
|
90
|
+
* Expands ~ to home directory in a path
|
|
91
|
+
*/
|
|
92
|
+
export declare function expandPath(filePath: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Expands ~ in all playbook paths
|
|
95
|
+
*/
|
|
96
|
+
export declare function expandPlaybookPaths(paths: string[]): string[];
|
|
97
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/config/file.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAOpB,+BAA+B;AAC/B,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C,yCAAyC;AACzC,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAM5C;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA+BtE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,CAAC,EAAE,MAAM,EACrB,QAAQ,GAAE,MAAsB,GAC/B,mBAAmB,CA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