@alphafox/cli 0.2.0 → 0.3.2
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/README.md +42 -4
- package/dist/catalog/command-tree.d.ts +1 -0
- package/dist/catalog/command-tree.js +5 -3
- package/dist/catalog/validate-body.d.ts +22 -0
- package/dist/catalog/validate-body.js +98 -0
- package/dist/commands/request-body.d.ts +21 -0
- package/dist/commands/request-body.js +92 -0
- package/dist/commands/run.js +113 -10
- package/dist/engine-backtest/errors.d.ts +18 -0
- package/dist/engine-backtest/errors.js +26 -0
- package/dist/engine-backtest/fetch-runtime.d.ts +38 -0
- package/dist/engine-backtest/fetch-runtime.js +170 -0
- package/dist/engine-backtest/native-import.d.ts +1 -0
- package/dist/engine-backtest/native-import.js +10 -0
- package/dist/engine-backtest/parse-args.d.ts +6 -0
- package/dist/engine-backtest/parse-args.js +281 -0
- package/dist/engine-backtest/persist.d.ts +32 -0
- package/dist/engine-backtest/persist.js +94 -0
- package/dist/engine-backtest/replay-timeframe.d.ts +16 -0
- package/dist/engine-backtest/replay-timeframe.js +48 -0
- package/dist/engine-backtest/resolve-packages.d.ts +27 -0
- package/dist/engine-backtest/resolve-packages.js +288 -0
- package/dist/engine-backtest/run-command.d.ts +38 -0
- package/dist/engine-backtest/run-command.js +540 -0
- package/dist/engine-backtest/types.d.ts +249 -0
- package/dist/engine-backtest/types.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +16 -1
- package/dist/install/exec.d.ts +13 -0
- package/dist/install/exec.js +73 -0
- package/dist/install/package-root.d.ts +4 -0
- package/dist/install/package-root.js +59 -0
- package/dist/install/types.d.ts +69 -0
- package/dist/install/types.js +26 -0
- package/dist/install/wizard.d.ts +21 -0
- package/dist/install/wizard.js +332 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/.nojekyll +0 -0
- package/docs/alphafox-cli-installation-guide.md +105 -0
- package/docs/favicon.svg +4 -0
- package/docs/index.html +748 -0
- package/docs/logo/alphafox-mark.svg +4 -0
- package/docs/logo/alphafox-wordmark-black-en.svg +17 -0
- package/docs/logo/alphafox-wordmark-white-en.svg +16 -0
- package/docs/release-supply-chain.md +10 -2
- package/package.json +7 -2
- package/skills/account/SKILL.md +2 -2
- package/skills/admin/SKILL.md +2 -2
- package/skills/alphafox-shared/SKILL.md +22 -1
- package/skills/auth/SKILL.md +1 -1
- package/skills/engine-backtest/SKILL.md +71 -0
- package/skills/exchange/SKILL.md +2 -2
- package/skills/market/SKILL.md +1 -1
- package/skills/notification/SKILL.md +2 -2
- package/skills/strategy/SKILL.md +10 -2
- package/skills/trading/SKILL.md +6 -3
- package/vendor/backtest-runner/NOTICE.md +1 -0
- package/vendor/backtest-runner/README.md +97 -0
- package/vendor/backtest-runner/index.d.ts +423 -0
- package/vendor/backtest-runner/index.mjs +59 -0
- package/vendor/backtest-runner/lib/abortable.mjs +23 -0
- package/vendor/backtest-runner/lib/cache.mjs +159 -0
- package/vendor/backtest-runner/lib/coverage.mjs +238 -0
- package/vendor/backtest-runner/lib/encode.mjs +28 -0
- package/vendor/backtest-runner/lib/exchanges.mjs +143 -0
- package/vendor/backtest-runner/lib/proxy.mjs +78 -0
- package/vendor/backtest-runner/lib/scenario.mjs +66 -0
- package/vendor/backtest-runner/lib/series.mjs +370 -0
- package/vendor/backtest-runner/lib/tape-loader.mjs +614 -0
- package/vendor/backtest-runner/lib/timeframes.mjs +55 -0
- package/vendor/backtest-runner/package.json +13 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
export type SubscriptionTier = "free" | "pro" | "pro_max";
|
|
2
|
+
export type DataQualityMode = "strict" | "basic";
|
|
3
|
+
export type PricePath = "ohlc_path_4" | "close_only";
|
|
4
|
+
export interface ExecutionModel {
|
|
5
|
+
readonly pricePath: PricePath;
|
|
6
|
+
readonly makerFeeRate: number;
|
|
7
|
+
readonly takerFeeRate: number;
|
|
8
|
+
readonly slippageRate: number;
|
|
9
|
+
}
|
|
10
|
+
export interface InclusiveUtcDateRange {
|
|
11
|
+
readonly rangeStart: string;
|
|
12
|
+
readonly rangeEnd: string;
|
|
13
|
+
readonly fromMs: number;
|
|
14
|
+
readonly toMs: number;
|
|
15
|
+
}
|
|
16
|
+
export interface EngineBacktestRunArgs {
|
|
17
|
+
readonly help: boolean;
|
|
18
|
+
readonly experimentId?: string;
|
|
19
|
+
readonly createExperiment: boolean;
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
readonly definitionId?: string;
|
|
22
|
+
readonly definitionLabelZh?: string;
|
|
23
|
+
readonly definitionLabelEn?: string;
|
|
24
|
+
readonly configRaw?: string;
|
|
25
|
+
readonly exchange?: string;
|
|
26
|
+
readonly range?: InclusiveUtcDateRange;
|
|
27
|
+
readonly initialEquity?: number;
|
|
28
|
+
/** Explicit --tier value. Persisted runs otherwise use the account tier. */
|
|
29
|
+
readonly tier?: SubscriptionTier;
|
|
30
|
+
readonly dataQualityMode: DataQualityMode;
|
|
31
|
+
readonly configSchemaVersion?: number;
|
|
32
|
+
readonly executionModelOverride?: Partial<ExecutionModel>;
|
|
33
|
+
readonly persist: boolean;
|
|
34
|
+
/** Replay/download bar. Defaults to 1m; never finer. */
|
|
35
|
+
readonly replayTimeframe: string;
|
|
36
|
+
}
|
|
37
|
+
export interface EngineBacktestSeriesRequirement {
|
|
38
|
+
readonly symbol: string;
|
|
39
|
+
readonly timeframe: string;
|
|
40
|
+
readonly minWarmupCandles: number;
|
|
41
|
+
}
|
|
42
|
+
export interface EngineBacktestTapeSeriesRef {
|
|
43
|
+
readonly symbol: string;
|
|
44
|
+
readonly timeframe: string;
|
|
45
|
+
readonly buffer: string;
|
|
46
|
+
readonly rows: number;
|
|
47
|
+
}
|
|
48
|
+
export interface EngineBacktestTapeInput {
|
|
49
|
+
readonly from: string;
|
|
50
|
+
readonly to: string;
|
|
51
|
+
readonly baseTimeframe: string;
|
|
52
|
+
readonly markets: Readonly<Record<string, unknown>>;
|
|
53
|
+
readonly series: readonly EngineBacktestTapeSeriesRef[];
|
|
54
|
+
readonly fundingRates?: Readonly<Record<string, readonly unknown[]>>;
|
|
55
|
+
readonly lowLiquiditySymbols?: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
export interface EngineBacktestScenario {
|
|
58
|
+
readonly version: 1;
|
|
59
|
+
readonly runId: string;
|
|
60
|
+
readonly trader: {
|
|
61
|
+
readonly id?: string;
|
|
62
|
+
readonly name?: string;
|
|
63
|
+
readonly strategyDefinitionId: string;
|
|
64
|
+
readonly configSchemaVersion: number;
|
|
65
|
+
readonly subscriptionTier: SubscriptionTier;
|
|
66
|
+
readonly config: unknown;
|
|
67
|
+
};
|
|
68
|
+
readonly exchange: {
|
|
69
|
+
readonly positionSideDual: boolean;
|
|
70
|
+
readonly initialEquity: number;
|
|
71
|
+
};
|
|
72
|
+
readonly executionModel: ExecutionModel;
|
|
73
|
+
readonly tape: EngineBacktestTapeInput;
|
|
74
|
+
}
|
|
75
|
+
export interface EngineBacktestMetrics {
|
|
76
|
+
readonly initialEquity: number;
|
|
77
|
+
readonly finalEquity: number;
|
|
78
|
+
readonly netPnl: number;
|
|
79
|
+
readonly returnPct: number;
|
|
80
|
+
readonly maxDrawdownPct: number;
|
|
81
|
+
readonly sharpeRatio: number;
|
|
82
|
+
readonly orderCount: number;
|
|
83
|
+
readonly filledOrderCount: number;
|
|
84
|
+
readonly canceledOrderCount: number;
|
|
85
|
+
readonly tradeCount: number;
|
|
86
|
+
readonly winningTrades: number;
|
|
87
|
+
readonly losingTrades: number;
|
|
88
|
+
readonly winRatePct: number;
|
|
89
|
+
readonly feesPaid: number;
|
|
90
|
+
readonly slippagePaid: number;
|
|
91
|
+
readonly liquidated: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface EngineBacktestResult {
|
|
94
|
+
readonly runId: string;
|
|
95
|
+
readonly status: "completed" | "failed";
|
|
96
|
+
readonly engineVersion?: string;
|
|
97
|
+
readonly metrics: EngineBacktestMetrics;
|
|
98
|
+
readonly equityCurve?: unknown[];
|
|
99
|
+
readonly orders?: unknown[];
|
|
100
|
+
readonly openPositions?: unknown[];
|
|
101
|
+
readonly errors?: Array<{
|
|
102
|
+
code: string;
|
|
103
|
+
message: string;
|
|
104
|
+
path?: string;
|
|
105
|
+
}>;
|
|
106
|
+
readonly warnings?: string[];
|
|
107
|
+
}
|
|
108
|
+
export interface EngineBacktestSupportReason {
|
|
109
|
+
readonly code: string;
|
|
110
|
+
readonly message: string;
|
|
111
|
+
}
|
|
112
|
+
export interface EngineSupportedBacktestPlan {
|
|
113
|
+
readonly definitionId: string;
|
|
114
|
+
readonly configSchemaVersion: number;
|
|
115
|
+
readonly support: {
|
|
116
|
+
readonly status: "supported";
|
|
117
|
+
};
|
|
118
|
+
readonly effectiveConfig: Record<string, unknown>;
|
|
119
|
+
readonly universe: {
|
|
120
|
+
readonly kind: "fixed";
|
|
121
|
+
readonly symbols: string[];
|
|
122
|
+
};
|
|
123
|
+
readonly symbols: string[];
|
|
124
|
+
readonly timeframes: string[];
|
|
125
|
+
readonly seriesRequirements: EngineBacktestSeriesRequirement[];
|
|
126
|
+
readonly needsFunding: boolean;
|
|
127
|
+
readonly auxiliaryDataRequirements: Array<{
|
|
128
|
+
readonly kind: string;
|
|
129
|
+
readonly parameters?: Record<string, unknown>;
|
|
130
|
+
}>;
|
|
131
|
+
readonly configFingerprint: string;
|
|
132
|
+
}
|
|
133
|
+
export interface EngineUnsupportedBacktestPlan {
|
|
134
|
+
readonly definitionId: string;
|
|
135
|
+
readonly configSchemaVersion: number;
|
|
136
|
+
readonly support: {
|
|
137
|
+
readonly status: "unsupported";
|
|
138
|
+
readonly reason: EngineBacktestSupportReason;
|
|
139
|
+
};
|
|
140
|
+
readonly needsFunding: false;
|
|
141
|
+
}
|
|
142
|
+
export interface EngineBacktestFailure {
|
|
143
|
+
readonly status: "failed";
|
|
144
|
+
readonly errors: Array<{
|
|
145
|
+
readonly code: string;
|
|
146
|
+
readonly message: string;
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
149
|
+
export type EngineBacktestPlan = EngineSupportedBacktestPlan | EngineUnsupportedBacktestPlan;
|
|
150
|
+
export interface TapeLoadProgress {
|
|
151
|
+
readonly stage: "markets" | "ohlcv" | "validation" | string;
|
|
152
|
+
readonly detail: string;
|
|
153
|
+
readonly fraction: number;
|
|
154
|
+
}
|
|
155
|
+
export interface TapeExchangeDefinition {
|
|
156
|
+
readonly id: string;
|
|
157
|
+
readonly label: string;
|
|
158
|
+
readonly ccxtId: string;
|
|
159
|
+
readonly marketType: string;
|
|
160
|
+
readonly quoteAsset: string;
|
|
161
|
+
}
|
|
162
|
+
export interface TapeLoadResult {
|
|
163
|
+
readonly tape: EngineBacktestTapeInput;
|
|
164
|
+
readonly buffers: Record<string, ArrayBuffer>;
|
|
165
|
+
readonly coverageWarnings: readonly string[];
|
|
166
|
+
}
|
|
167
|
+
export interface BacktestClientLike {
|
|
168
|
+
init(): Promise<string>;
|
|
169
|
+
version(): Promise<string>;
|
|
170
|
+
strategyDefinitions(): Promise<{
|
|
171
|
+
readonly engineVersion: string;
|
|
172
|
+
readonly definitions: Array<Record<string, unknown> & {
|
|
173
|
+
readonly id: string;
|
|
174
|
+
readonly configSchemaVersion?: number;
|
|
175
|
+
}>;
|
|
176
|
+
}>;
|
|
177
|
+
planBacktest(request: {
|
|
178
|
+
readonly definitionId: string;
|
|
179
|
+
readonly configSchemaVersion: number;
|
|
180
|
+
readonly config: unknown;
|
|
181
|
+
}): Promise<EngineBacktestPlan | EngineBacktestFailure>;
|
|
182
|
+
runBacktest(scenario: EngineBacktestScenario, buffers: Record<string, ArrayBuffer>, onProgress?: (fraction: number) => void): Promise<EngineBacktestResult>;
|
|
183
|
+
terminate(): void;
|
|
184
|
+
}
|
|
185
|
+
export interface BacktestWasmModule {
|
|
186
|
+
createNodeBacktestClient(options?: unknown): BacktestClientLike;
|
|
187
|
+
}
|
|
188
|
+
export interface BacktestRunnerModule {
|
|
189
|
+
loadTape(request: {
|
|
190
|
+
readonly exchangeId?: string;
|
|
191
|
+
readonly exchange?: TapeExchangeDefinition;
|
|
192
|
+
readonly symbols: readonly string[];
|
|
193
|
+
readonly baseTimeframe?: string;
|
|
194
|
+
readonly timeframes: readonly string[];
|
|
195
|
+
readonly seriesRequirements?: readonly EngineBacktestSeriesRequirement[];
|
|
196
|
+
readonly needsFunding?: boolean;
|
|
197
|
+
readonly auxiliaryDataRequirements?: readonly unknown[];
|
|
198
|
+
readonly fromMs: number;
|
|
199
|
+
readonly toMs: number;
|
|
200
|
+
readonly dataQualityMode?: DataQualityMode;
|
|
201
|
+
readonly onProgress?: (progress: TapeLoadProgress) => void;
|
|
202
|
+
}, options?: unknown): Promise<TapeLoadResult>;
|
|
203
|
+
assembleScenario(input: {
|
|
204
|
+
readonly runId: string;
|
|
205
|
+
readonly definitionId: string;
|
|
206
|
+
readonly configSchemaVersion: number;
|
|
207
|
+
readonly config: unknown;
|
|
208
|
+
readonly subscriptionTier: SubscriptionTier;
|
|
209
|
+
readonly initialEquity: number;
|
|
210
|
+
readonly tape?: EngineBacktestTapeInput;
|
|
211
|
+
readonly executionModel?: Partial<ExecutionModel>;
|
|
212
|
+
}): EngineBacktestScenario;
|
|
213
|
+
resolveTapeExchange(exchangeId: string | TapeExchangeDefinition): TapeExchangeDefinition;
|
|
214
|
+
DEFAULT_EXECUTION_MODEL: ExecutionModel;
|
|
215
|
+
}
|
|
216
|
+
export interface PersistedSnapshot {
|
|
217
|
+
readonly snapshotSchemaVersion: 1;
|
|
218
|
+
readonly strategyDefinitionId: string;
|
|
219
|
+
readonly configSchemaVersion: number;
|
|
220
|
+
readonly config: unknown;
|
|
221
|
+
readonly exchangeId: string;
|
|
222
|
+
readonly rangeStart: string;
|
|
223
|
+
readonly rangeEnd: string;
|
|
224
|
+
readonly initialEquity: number;
|
|
225
|
+
readonly subscriptionTier: SubscriptionTier;
|
|
226
|
+
readonly dataQualityMode: DataQualityMode;
|
|
227
|
+
readonly symbols: string[];
|
|
228
|
+
readonly timeframes: string[];
|
|
229
|
+
readonly baseTimeframe: string;
|
|
230
|
+
readonly executionModel: ExecutionModel;
|
|
231
|
+
readonly positionSideDual: boolean;
|
|
232
|
+
readonly engineVersion: string;
|
|
233
|
+
}
|
|
234
|
+
export interface CreateRunRequestBody {
|
|
235
|
+
readonly clientRunId: string;
|
|
236
|
+
readonly snapshot: PersistedSnapshot;
|
|
237
|
+
readonly metrics: EngineBacktestMetrics;
|
|
238
|
+
readonly engineVersion: string;
|
|
239
|
+
readonly configSchemaVersion: number;
|
|
240
|
+
}
|
|
241
|
+
export interface EngineBacktestRunSuccess {
|
|
242
|
+
readonly metrics: EngineBacktestMetrics;
|
|
243
|
+
readonly engineVersion: string;
|
|
244
|
+
readonly experimentId: string;
|
|
245
|
+
readonly runId?: string;
|
|
246
|
+
readonly experimentUrl: string;
|
|
247
|
+
readonly persisted: boolean;
|
|
248
|
+
readonly coverageWarnings: readonly string[];
|
|
249
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,3 +13,7 @@ export { runBrowserPkceLogin } from "./auth/browser-login";
|
|
|
13
13
|
export { startLoopbackCallbackServer } from "./auth/loopback-callback";
|
|
14
14
|
export { CATALOG_OPERATIONS, CATALOG_SOURCE, CATALOG_VERSION, COMPATIBILITY_RANGE, findCatalogOperation, findCatalogOperationByRoute, getOperationSchemaDocument, buildCapabilityManifest, checkGeneratedCatalogCompatibility, } from "./catalog/operations";
|
|
15
15
|
export { CLI_VERSION, CLI_PACKAGE, CLI_CONTRACT_VERSION } from "./version";
|
|
16
|
+
export { validateCatalogWriteBody } from "./catalog/validate-body";
|
|
17
|
+
export { parseRequestBodyFlags, loadJsonArg } from "./commands/request-body";
|
|
18
|
+
export { parseInstallArgs, runInstallWizard, semverLessThan, skillsListHasAlphafox, } from "./install/wizard";
|
|
19
|
+
export { AGENT_INSTALL_GUIDE_BLOB_URL, AGENT_INSTALL_GUIDE_URL, SKILLS_GITHUB_SOURCE, } from "./install/types";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLI_CONTRACT_VERSION = exports.CLI_PACKAGE = exports.CLI_VERSION = exports.checkGeneratedCatalogCompatibility = exports.buildCapabilityManifest = exports.getOperationSchemaDocument = exports.findCatalogOperationByRoute = exports.findCatalogOperation = exports.COMPATIBILITY_RANGE = exports.CATALOG_VERSION = exports.CATALOG_SOURCE = exports.CATALOG_OPERATIONS = exports.startLoopbackCallbackServer = exports.runBrowserPkceLogin = exports.accessTokenNeedsRefresh = exports.refreshStoredTokensOrNull = exports.refreshStoredTokens = exports.requiresHighRiskConfirmation = exports.inferRawApiRisk = exports.assertHighRiskConfirmation = exports.resolveTypedCommand = exports.checkCliCompatibility = exports.pathTemplateMatches = exports.normalizeApiPath = exports.isInternalDisallowedPath = exports.isFacadeAllowlistedPath = exports.WINDOWS_CRED_MAX_BYTES = exports.windowsCredentialTarget = exports.linuxSecretToolBin = exports.linuxSecretServiceArgs = exports.keychainPlatform = exports.probeOsKeychain = exports.getLastTokenSaveResult = exports.tokenFingerprint = exports.deleteTokens = exports.loadTokens = exports.saveTokens = exports.assertNoTokenFields = exports.saveConfigFile = exports.loadConfigFile = exports.resolveProfile = exports.applyJqFilter = exports.writeError = exports.writeSuccess = exports.parseJsonEnvelope = exports.errorEnvelope = exports.successEnvelope = exports.parseGlobalFlags = exports.runCli = void 0;
|
|
3
|
+
exports.validateCatalogWriteBody = exports.CLI_CONTRACT_VERSION = exports.CLI_PACKAGE = exports.CLI_VERSION = exports.checkGeneratedCatalogCompatibility = exports.buildCapabilityManifest = exports.getOperationSchemaDocument = exports.findCatalogOperationByRoute = exports.findCatalogOperation = exports.COMPATIBILITY_RANGE = exports.CATALOG_VERSION = exports.CATALOG_SOURCE = exports.CATALOG_OPERATIONS = exports.startLoopbackCallbackServer = exports.runBrowserPkceLogin = exports.accessTokenNeedsRefresh = exports.refreshStoredTokensOrNull = exports.refreshStoredTokens = exports.requiresHighRiskConfirmation = exports.inferRawApiRisk = exports.assertHighRiskConfirmation = exports.resolveTypedCommand = exports.checkCliCompatibility = exports.pathTemplateMatches = exports.normalizeApiPath = exports.isInternalDisallowedPath = exports.isFacadeAllowlistedPath = exports.WINDOWS_CRED_MAX_BYTES = exports.windowsCredentialTarget = exports.linuxSecretToolBin = exports.linuxSecretServiceArgs = exports.keychainPlatform = exports.probeOsKeychain = exports.getLastTokenSaveResult = exports.tokenFingerprint = exports.deleteTokens = exports.loadTokens = exports.saveTokens = exports.assertNoTokenFields = exports.saveConfigFile = exports.loadConfigFile = exports.resolveProfile = exports.applyJqFilter = exports.writeError = exports.writeSuccess = exports.parseJsonEnvelope = exports.errorEnvelope = exports.successEnvelope = exports.parseGlobalFlags = exports.runCli = void 0;
|
|
4
|
+
exports.SKILLS_GITHUB_SOURCE = exports.AGENT_INSTALL_GUIDE_URL = exports.AGENT_INSTALL_GUIDE_BLOB_URL = exports.skillsListHasAlphafox = exports.semverLessThan = exports.runInstallWizard = exports.parseInstallArgs = exports.loadJsonArg = exports.parseRequestBodyFlags = void 0;
|
|
4
5
|
var run_1 = require("./commands/run");
|
|
5
6
|
Object.defineProperty(exports, "runCli", { enumerable: true, get: function () { return run_1.runCli; } });
|
|
6
7
|
Object.defineProperty(exports, "parseGlobalFlags", { enumerable: true, get: function () { return run_1.parseGlobalFlags; } });
|
|
@@ -65,3 +66,17 @@ var version_1 = require("./version");
|
|
|
65
66
|
Object.defineProperty(exports, "CLI_VERSION", { enumerable: true, get: function () { return version_1.CLI_VERSION; } });
|
|
66
67
|
Object.defineProperty(exports, "CLI_PACKAGE", { enumerable: true, get: function () { return version_1.CLI_PACKAGE; } });
|
|
67
68
|
Object.defineProperty(exports, "CLI_CONTRACT_VERSION", { enumerable: true, get: function () { return version_1.CLI_CONTRACT_VERSION; } });
|
|
69
|
+
var validate_body_1 = require("./catalog/validate-body");
|
|
70
|
+
Object.defineProperty(exports, "validateCatalogWriteBody", { enumerable: true, get: function () { return validate_body_1.validateCatalogWriteBody; } });
|
|
71
|
+
var request_body_1 = require("./commands/request-body");
|
|
72
|
+
Object.defineProperty(exports, "parseRequestBodyFlags", { enumerable: true, get: function () { return request_body_1.parseRequestBodyFlags; } });
|
|
73
|
+
Object.defineProperty(exports, "loadJsonArg", { enumerable: true, get: function () { return request_body_1.loadJsonArg; } });
|
|
74
|
+
var wizard_1 = require("./install/wizard");
|
|
75
|
+
Object.defineProperty(exports, "parseInstallArgs", { enumerable: true, get: function () { return wizard_1.parseInstallArgs; } });
|
|
76
|
+
Object.defineProperty(exports, "runInstallWizard", { enumerable: true, get: function () { return wizard_1.runInstallWizard; } });
|
|
77
|
+
Object.defineProperty(exports, "semverLessThan", { enumerable: true, get: function () { return wizard_1.semverLessThan; } });
|
|
78
|
+
Object.defineProperty(exports, "skillsListHasAlphafox", { enumerable: true, get: function () { return wizard_1.skillsListHasAlphafox; } });
|
|
79
|
+
var types_1 = require("./install/types");
|
|
80
|
+
Object.defineProperty(exports, "AGENT_INSTALL_GUIDE_BLOB_URL", { enumerable: true, get: function () { return types_1.AGENT_INSTALL_GUIDE_BLOB_URL; } });
|
|
81
|
+
Object.defineProperty(exports, "AGENT_INSTALL_GUIDE_URL", { enumerable: true, get: function () { return types_1.AGENT_INSTALL_GUIDE_URL; } });
|
|
82
|
+
Object.defineProperty(exports, "SKILLS_GITHUB_SOURCE", { enumerable: true, get: function () { return types_1.SKILLS_GITHUB_SOURCE; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExecResult, InstallRunner } from "./types";
|
|
2
|
+
export declare function wrapWindowsCommand(command: string, args: readonly string[], platform?: NodeJS.Platform): {
|
|
3
|
+
readonly file: string;
|
|
4
|
+
readonly argv: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function execCommand(command: string, args: readonly string[], options?: {
|
|
7
|
+
readonly timeoutMs?: number;
|
|
8
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
9
|
+
readonly inherit?: boolean;
|
|
10
|
+
readonly platform?: NodeJS.Platform;
|
|
11
|
+
}): Promise<ExecResult>;
|
|
12
|
+
export declare function confirmTty(message: string): Promise<boolean>;
|
|
13
|
+
export declare function createDefaultInstallRunner(env: NodeJS.ProcessEnv, searchDirs: readonly string[]): InstallRunner;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapWindowsCommand = wrapWindowsCommand;
|
|
4
|
+
exports.execCommand = execCommand;
|
|
5
|
+
exports.confirmTty = confirmTty;
|
|
6
|
+
exports.createDefaultInstallRunner = createDefaultInstallRunner;
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
|
+
const promises_1 = require("node:readline/promises");
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
|
+
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
11
|
+
function wrapWindowsCommand(command, args, platform = process.platform) {
|
|
12
|
+
if (platform === "win32") {
|
|
13
|
+
return { file: "cmd.exe", argv: ["/c", command, ...args] };
|
|
14
|
+
}
|
|
15
|
+
return { file: command, argv: [...args] };
|
|
16
|
+
}
|
|
17
|
+
async function execCommand(command, args, options = {}) {
|
|
18
|
+
const { file, argv } = wrapWindowsCommand(command, args, options.platform ?? process.platform);
|
|
19
|
+
const timeout = options.timeoutMs ?? 120_000;
|
|
20
|
+
if (options.inherit) {
|
|
21
|
+
await new Promise((resolve, reject) => {
|
|
22
|
+
const child = (0, node_child_process_1.spawn)(file, argv, {
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
env: options.env,
|
|
25
|
+
timeout,
|
|
26
|
+
});
|
|
27
|
+
child.on("error", reject);
|
|
28
|
+
child.on("exit", (code) => {
|
|
29
|
+
if (code === 0)
|
|
30
|
+
resolve();
|
|
31
|
+
else
|
|
32
|
+
reject(new Error(`${command} exited ${code ?? "null"}`));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return { stdout: "", stderr: "" };
|
|
36
|
+
}
|
|
37
|
+
const { stdout, stderr } = await execFileAsync(file, argv, {
|
|
38
|
+
timeout,
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
env: options.env,
|
|
41
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
42
|
+
});
|
|
43
|
+
return { stdout, stderr };
|
|
44
|
+
}
|
|
45
|
+
async function confirmTty(message) {
|
|
46
|
+
const rl = (0, promises_1.createInterface)({
|
|
47
|
+
input: process.stdin,
|
|
48
|
+
output: process.stderr,
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const answer = await rl.question(`${message} [Y/n] `);
|
|
52
|
+
const token = answer.trim().toLowerCase();
|
|
53
|
+
return token === "" || token === "y" || token === "yes";
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
rl.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function createDefaultInstallRunner(env, searchDirs) {
|
|
60
|
+
return {
|
|
61
|
+
env,
|
|
62
|
+
packageSearchDirs: () => searchDirs,
|
|
63
|
+
isTty: () => Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
64
|
+
log: (message) => {
|
|
65
|
+
process.stderr.write(`${message}\n`);
|
|
66
|
+
},
|
|
67
|
+
confirm: confirmTty,
|
|
68
|
+
exec: (command, args, options) => execCommand(command, args, { ...options, env }),
|
|
69
|
+
execInherit: async (command, args, options) => {
|
|
70
|
+
await execCommand(command, args, { ...options, env, inherit: true });
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function findAlphafoxPackageRoot(startDirs: readonly string[]): string | null;
|
|
2
|
+
export declare function packageHasSkills(packageRoot: string): boolean;
|
|
3
|
+
export declare function globalPackageRoot(npmRootGlobal: string): string;
|
|
4
|
+
export declare function globalBinPath(npmPrefixGlobal: string, platform?: NodeJS.Platform): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findAlphafoxPackageRoot = findAlphafoxPackageRoot;
|
|
4
|
+
exports.packageHasSkills = packageHasSkills;
|
|
5
|
+
exports.globalPackageRoot = globalPackageRoot;
|
|
6
|
+
exports.globalBinPath = globalBinPath;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const version_1 = require("../version");
|
|
10
|
+
function findAlphafoxPackageRoot(startDirs) {
|
|
11
|
+
for (const start of startDirs) {
|
|
12
|
+
const found = walkForPackage(start);
|
|
13
|
+
if (found)
|
|
14
|
+
return found;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function packageHasSkills(packageRoot) {
|
|
19
|
+
const skillsDir = (0, node_path_1.join)(packageRoot, "skills");
|
|
20
|
+
if (!(0, node_fs_1.existsSync)(skillsDir))
|
|
21
|
+
return false;
|
|
22
|
+
try {
|
|
23
|
+
return (0, node_fs_1.readdirSync)(skillsDir, { withFileTypes: true }).some((entry) => entry.isDirectory() &&
|
|
24
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(skillsDir, entry.name, "SKILL.md")));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function globalPackageRoot(npmRootGlobal) {
|
|
31
|
+
return (0, node_path_1.join)(npmRootGlobal, "@alphafox", "cli");
|
|
32
|
+
}
|
|
33
|
+
function globalBinPath(npmPrefixGlobal, platform = process.platform) {
|
|
34
|
+
if (platform === "win32") {
|
|
35
|
+
return (0, node_path_1.join)(npmPrefixGlobal, "alphafox.cmd");
|
|
36
|
+
}
|
|
37
|
+
return (0, node_path_1.join)(npmPrefixGlobal, "bin", "alphafox");
|
|
38
|
+
}
|
|
39
|
+
function walkForPackage(startDir) {
|
|
40
|
+
let dir = startDir;
|
|
41
|
+
for (let i = 0; i < 10; i += 1) {
|
|
42
|
+
const pkgPath = (0, node_path_1.join)(dir, "package.json");
|
|
43
|
+
if ((0, node_fs_1.existsSync)(pkgPath) && packageHasSkills(dir)) {
|
|
44
|
+
try {
|
|
45
|
+
const parsed = JSON.parse((0, node_fs_1.readFileSync)(pkgPath, "utf8"));
|
|
46
|
+
if (parsed.name === version_1.CLI_PACKAGE)
|
|
47
|
+
return dir;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// keep walking
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const parent = (0, node_path_1.dirname)(dir);
|
|
54
|
+
if (parent === dir)
|
|
55
|
+
break;
|
|
56
|
+
dir = parent;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare const SKILLS_GITHUB_SOURCE = "alphafoxai/alphafox-cli";
|
|
2
|
+
export declare const SKILLS_NAME_PREFIX = "alphafox-";
|
|
3
|
+
export declare const AGENT_INSTALL_GUIDE_URL = "https://raw.githubusercontent.com/alphafoxai/alphafox-cli/main/docs/alphafox-cli-installation-guide.md";
|
|
4
|
+
export declare const AGENT_INSTALL_GUIDE_BLOB_URL = "https://github.com/alphafoxai/alphafox-cli/blob/main/docs/alphafox-cli-installation-guide.md";
|
|
5
|
+
export type InstallCliAction = "installed" | "upgraded" | "skipped" | "planned";
|
|
6
|
+
export type InstallSkillsAction = "installed" | "skipped" | "planned" | "failed";
|
|
7
|
+
export type InstallAuthAction = "completed" | "skipped" | "failed" | "planned";
|
|
8
|
+
export interface InstallCliStep {
|
|
9
|
+
readonly action: InstallCliAction;
|
|
10
|
+
readonly version?: string;
|
|
11
|
+
readonly previousVersion?: string;
|
|
12
|
+
readonly latestVersion?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface InstallSkillsStep {
|
|
15
|
+
readonly action: InstallSkillsAction;
|
|
16
|
+
readonly source?: string;
|
|
17
|
+
readonly scope: "global";
|
|
18
|
+
readonly alreadyPresent?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface InstallAuthStep {
|
|
21
|
+
readonly action: InstallAuthAction;
|
|
22
|
+
readonly reason?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface InstallResult {
|
|
25
|
+
readonly cli: InstallCliStep;
|
|
26
|
+
readonly skills: InstallSkillsStep;
|
|
27
|
+
readonly auth: InstallAuthStep;
|
|
28
|
+
readonly next: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
export interface InstallFlags {
|
|
31
|
+
readonly format: "json" | "jsonl" | "text";
|
|
32
|
+
readonly yes: boolean;
|
|
33
|
+
readonly dryRun: boolean;
|
|
34
|
+
readonly noInput: boolean;
|
|
35
|
+
readonly jq?: string;
|
|
36
|
+
readonly noAuth: boolean;
|
|
37
|
+
readonly help: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface ExecResult {
|
|
40
|
+
readonly stdout: string;
|
|
41
|
+
readonly stderr: string;
|
|
42
|
+
}
|
|
43
|
+
export interface InstallRunner {
|
|
44
|
+
readonly exec: (command: string, args: readonly string[], options?: {
|
|
45
|
+
readonly timeoutMs?: number;
|
|
46
|
+
}) => Promise<ExecResult>;
|
|
47
|
+
readonly execInherit: (command: string, args: readonly string[], options?: {
|
|
48
|
+
readonly timeoutMs?: number;
|
|
49
|
+
}) => Promise<void>;
|
|
50
|
+
readonly isTty: () => boolean;
|
|
51
|
+
readonly confirm: (message: string) => Promise<boolean>;
|
|
52
|
+
readonly log: (message: string) => void;
|
|
53
|
+
readonly packageSearchDirs: () => readonly string[];
|
|
54
|
+
readonly env: NodeJS.ProcessEnv;
|
|
55
|
+
}
|
|
56
|
+
export declare class InstallError extends Error {
|
|
57
|
+
readonly type: string;
|
|
58
|
+
readonly subtype?: string;
|
|
59
|
+
readonly hint?: string;
|
|
60
|
+
readonly details?: unknown;
|
|
61
|
+
constructor(input: {
|
|
62
|
+
readonly message: string;
|
|
63
|
+
readonly type?: string;
|
|
64
|
+
readonly subtype?: string;
|
|
65
|
+
readonly hint?: string;
|
|
66
|
+
readonly details?: unknown;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export declare function isInstallError(value: unknown): value is InstallError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstallError = exports.AGENT_INSTALL_GUIDE_BLOB_URL = exports.AGENT_INSTALL_GUIDE_URL = exports.SKILLS_NAME_PREFIX = exports.SKILLS_GITHUB_SOURCE = void 0;
|
|
4
|
+
exports.isInstallError = isInstallError;
|
|
5
|
+
exports.SKILLS_GITHUB_SOURCE = "alphafoxai/alphafox-cli";
|
|
6
|
+
exports.SKILLS_NAME_PREFIX = "alphafox-";
|
|
7
|
+
exports.AGENT_INSTALL_GUIDE_URL = "https://raw.githubusercontent.com/alphafoxai/alphafox-cli/main/docs/alphafox-cli-installation-guide.md";
|
|
8
|
+
exports.AGENT_INSTALL_GUIDE_BLOB_URL = "https://github.com/alphafoxai/alphafox-cli/blob/main/docs/alphafox-cli-installation-guide.md";
|
|
9
|
+
class InstallError extends Error {
|
|
10
|
+
type;
|
|
11
|
+
subtype;
|
|
12
|
+
hint;
|
|
13
|
+
details;
|
|
14
|
+
constructor(input) {
|
|
15
|
+
super(input.message);
|
|
16
|
+
this.name = "InstallError";
|
|
17
|
+
this.type = input.type ?? "runtime";
|
|
18
|
+
this.subtype = input.subtype;
|
|
19
|
+
this.hint = input.hint;
|
|
20
|
+
this.details = input.details;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.InstallError = InstallError;
|
|
24
|
+
function isInstallError(value) {
|
|
25
|
+
return value instanceof InstallError;
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type InstallAuthStep, type InstallFlags, type InstallResult, type InstallRunner } from "./types";
|
|
2
|
+
export declare function parseInstallArgs(args: readonly string[]): {
|
|
3
|
+
readonly noAuth: boolean;
|
|
4
|
+
readonly help: boolean;
|
|
5
|
+
readonly unknown: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function semverLessThan(a: string, b: string): boolean;
|
|
8
|
+
export declare function parseNpmListVersion(output: string): string | null;
|
|
9
|
+
export declare function skillsListHasAlphafox(output: string): boolean;
|
|
10
|
+
export declare function nextSteps(input: {
|
|
11
|
+
readonly auth: InstallAuthStep;
|
|
12
|
+
readonly dryRun: boolean;
|
|
13
|
+
}): string[];
|
|
14
|
+
export declare function runInstallWizard(flags: InstallFlags, env?: NodeJS.ProcessEnv, runner?: InstallRunner): Promise<InstallResult>;
|
|
15
|
+
export declare function installHelpData(): {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly usage: readonly string[];
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly agentGuide: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function resolveLocalSkillsDir(searchDirs: readonly string[]): string | null;
|