@agirails/sdk 2.5.3 → 2.5.4
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/dist/ACTPClient.d.ts +18 -0
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +67 -22
- package/dist/ACTPClient.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +12 -0
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +30 -4
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/StandardAdapter.d.ts +20 -3
- package/dist/adapters/StandardAdapter.d.ts.map +1 -1
- package/dist/adapters/StandardAdapter.js +45 -11
- package/dist/adapters/StandardAdapter.js.map +1 -1
- package/dist/cli/commands/publish.js +16 -4
- package/dist/cli/commands/publish.js.map +1 -1
- package/dist/cli/commands/register.js +16 -4
- package/dist/cli/commands/register.js.map +1 -1
- package/dist/cli/commands/tx.js +31 -3
- package/dist/cli/commands/tx.js.map +1 -1
- package/dist/config/networks.d.ts +2 -2
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +27 -22
- package/dist/config/networks.js.map +1 -1
- package/dist/level0/request.d.ts.map +1 -1
- package/dist/level0/request.js +2 -1
- package/dist/level0/request.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +11 -5
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/utils/IPFSClient.d.ts +3 -1
- package/dist/utils/IPFSClient.d.ts.map +1 -1
- package/dist/utils/IPFSClient.js +27 -7
- package/dist/utils/IPFSClient.js.map +1 -1
- package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
- package/dist/wallet/AutoWalletProvider.js +52 -18
- package/dist/wallet/AutoWalletProvider.js.map +1 -1
- package/dist/wallet/SmartWalletRouter.d.ts +116 -0
- package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
- package/dist/wallet/SmartWalletRouter.js +212 -0
- package/dist/wallet/SmartWalletRouter.js.map +1 -0
- package/dist/wallet/aa/DualNonceManager.d.ts +19 -0
- package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
- package/dist/wallet/aa/DualNonceManager.js +100 -5
- package/dist/wallet/aa/DualNonceManager.js.map +1 -1
- package/package.json +3 -6
- package/src/ACTPClient.ts +0 -1579
- package/src/abi/ACTPKernel.json +0 -1356
- package/src/abi/AgentRegistry.json +0 -915
- package/src/abi/ERC20.json +0 -40
- package/src/abi/EscrowVault.json +0 -134
- package/src/abi/IdentityRegistry.json +0 -316
- package/src/adapters/AdapterRegistry.ts +0 -173
- package/src/adapters/AdapterRouter.ts +0 -416
- package/src/adapters/BaseAdapter.ts +0 -498
- package/src/adapters/BasicAdapter.ts +0 -514
- package/src/adapters/IAdapter.ts +0 -292
- package/src/adapters/StandardAdapter.ts +0 -555
- package/src/adapters/X402Adapter.ts +0 -731
- package/src/adapters/index.ts +0 -60
- package/src/builders/DeliveryProofBuilder.ts +0 -327
- package/src/builders/QuoteBuilder.ts +0 -483
- package/src/builders/index.ts +0 -17
- package/src/cli/commands/balance.ts +0 -110
- package/src/cli/commands/batch.ts +0 -487
- package/src/cli/commands/config.ts +0 -231
- package/src/cli/commands/deploy-check.ts +0 -364
- package/src/cli/commands/deploy-env.ts +0 -120
- package/src/cli/commands/diff.ts +0 -141
- package/src/cli/commands/init.ts +0 -469
- package/src/cli/commands/mint.ts +0 -116
- package/src/cli/commands/pay.ts +0 -113
- package/src/cli/commands/publish.ts +0 -475
- package/src/cli/commands/pull.ts +0 -124
- package/src/cli/commands/register.ts +0 -247
- package/src/cli/commands/simulate.ts +0 -345
- package/src/cli/commands/time.ts +0 -302
- package/src/cli/commands/tx.ts +0 -448
- package/src/cli/commands/watch.ts +0 -211
- package/src/cli/index.ts +0 -134
- package/src/cli/utils/client.ts +0 -252
- package/src/cli/utils/config.ts +0 -389
- package/src/cli/utils/output.ts +0 -465
- package/src/cli/utils/wallet.ts +0 -109
- package/src/config/agirailsmd.ts +0 -262
- package/src/config/networks.ts +0 -275
- package/src/config/pendingPublish.ts +0 -237
- package/src/config/publishPipeline.ts +0 -359
- package/src/config/syncOperations.ts +0 -279
- package/src/erc8004/ERC8004Bridge.ts +0 -462
- package/src/erc8004/ReputationReporter.ts +0 -468
- package/src/erc8004/index.ts +0 -61
- package/src/errors/index.ts +0 -427
- package/src/index.ts +0 -364
- package/src/level0/Provider.ts +0 -117
- package/src/level0/ServiceDirectory.ts +0 -131
- package/src/level0/index.ts +0 -10
- package/src/level0/provide.ts +0 -132
- package/src/level0/request.ts +0 -432
- package/src/level1/Agent.ts +0 -1426
- package/src/level1/index.ts +0 -10
- package/src/level1/pricing/PriceCalculator.ts +0 -255
- package/src/level1/pricing/PricingStrategy.ts +0 -198
- package/src/level1/types/Job.ts +0 -179
- package/src/level1/types/Options.ts +0 -291
- package/src/level1/types/index.ts +0 -8
- package/src/protocol/ACTPKernel.ts +0 -808
- package/src/protocol/AgentRegistry.ts +0 -559
- package/src/protocol/DIDManager.ts +0 -629
- package/src/protocol/DIDResolver.ts +0 -554
- package/src/protocol/EASHelper.ts +0 -378
- package/src/protocol/EscrowVault.ts +0 -255
- package/src/protocol/EventMonitor.ts +0 -204
- package/src/protocol/MessageSigner.ts +0 -510
- package/src/protocol/ProofGenerator.ts +0 -339
- package/src/protocol/QuoteBuilder.ts +0 -15
- package/src/registry/AgentRegistryClient.ts +0 -202
- package/src/runtime/BlockchainRuntime.ts +0 -1015
- package/src/runtime/IACTPRuntime.ts +0 -306
- package/src/runtime/MockRuntime.ts +0 -1298
- package/src/runtime/MockStateManager.ts +0 -577
- package/src/runtime/index.ts +0 -25
- package/src/runtime/types/MockState.ts +0 -237
- package/src/storage/ArchiveBundleBuilder.ts +0 -561
- package/src/storage/ArweaveClient.ts +0 -946
- package/src/storage/FilebaseClient.ts +0 -790
- package/src/storage/index.ts +0 -96
- package/src/storage/types.ts +0 -348
- package/src/types/adapter.ts +0 -310
- package/src/types/agent.ts +0 -79
- package/src/types/did.ts +0 -223
- package/src/types/eip712.ts +0 -175
- package/src/types/erc8004.ts +0 -293
- package/src/types/escrow.ts +0 -27
- package/src/types/index.ts +0 -17
- package/src/types/message.ts +0 -145
- package/src/types/state.ts +0 -87
- package/src/types/transaction.ts +0 -69
- package/src/types/x402.ts +0 -251
- package/src/utils/ErrorRecoveryGuide.ts +0 -676
- package/src/utils/Helpers.ts +0 -688
- package/src/utils/IPFSClient.ts +0 -368
- package/src/utils/Logger.ts +0 -484
- package/src/utils/NonceManager.ts +0 -591
- package/src/utils/RateLimiter.ts +0 -534
- package/src/utils/ReceivedNonceTracker.ts +0 -567
- package/src/utils/SDKLifecycle.ts +0 -416
- package/src/utils/SecureNonce.ts +0 -78
- package/src/utils/Semaphore.ts +0 -276
- package/src/utils/UsedAttestationTracker.ts +0 -385
- package/src/utils/canonicalJson.ts +0 -38
- package/src/utils/circuitBreaker.ts +0 -324
- package/src/utils/computeTypeHash.ts +0 -48
- package/src/utils/fsSafe.ts +0 -80
- package/src/utils/index.ts +0 -80
- package/src/utils/retry.ts +0 -364
- package/src/utils/security.ts +0 -418
- package/src/utils/validation.ts +0 -540
- package/src/wallet/AutoWalletProvider.ts +0 -299
- package/src/wallet/EOAWalletProvider.ts +0 -69
- package/src/wallet/IWalletProvider.ts +0 -135
- package/src/wallet/aa/BundlerClient.ts +0 -274
- package/src/wallet/aa/DualNonceManager.ts +0 -173
- package/src/wallet/aa/PaymasterClient.ts +0 -174
- package/src/wallet/aa/TransactionBatcher.ts +0 -353
- package/src/wallet/aa/UserOpBuilder.ts +0 -246
- package/src/wallet/aa/constants.ts +0 -60
- package/src/wallet/keystore.ts +0 -240
package/src/cli/utils/config.ts
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Configuration Management
|
|
3
|
-
*
|
|
4
|
-
* Handles reading/writing CLI configuration stored in .actp/config.json.
|
|
5
|
-
* Supports mock, testnet, and mainnet modes with mode-specific validation.
|
|
6
|
-
*
|
|
7
|
-
* @module cli/utils/config
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// Types
|
|
15
|
-
// ============================================================================
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* CLI operating mode
|
|
19
|
-
*/
|
|
20
|
-
export type CLIMode = 'mock' | 'testnet' | 'mainnet';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* CLI configuration stored in .actp/config.json
|
|
24
|
-
*/
|
|
25
|
-
export interface CLIConfig {
|
|
26
|
-
/** Operating mode */
|
|
27
|
-
mode: CLIMode;
|
|
28
|
-
|
|
29
|
-
/** User's Ethereum address */
|
|
30
|
-
address: string;
|
|
31
|
-
|
|
32
|
-
/** Optional: Private key for testnet/mainnet mode */
|
|
33
|
-
privateKey?: string;
|
|
34
|
-
|
|
35
|
-
/** Optional: RPC URL override */
|
|
36
|
-
rpcUrl?: string;
|
|
37
|
-
|
|
38
|
-
/** AIP-12: Wallet type — 'auto' (Smart Wallet, gasless) or 'eoa' (traditional) */
|
|
39
|
-
wallet?: 'auto' | 'eoa';
|
|
40
|
-
|
|
41
|
-
/** AIP-12: Smart Wallet address (set when wallet=auto, used by `actp publish`) */
|
|
42
|
-
smartWallet?: string;
|
|
43
|
-
|
|
44
|
-
/** AIP-12: Whether agent is registered on AgentRegistry */
|
|
45
|
-
registered?: boolean;
|
|
46
|
-
|
|
47
|
-
/** Configuration version for migrations */
|
|
48
|
-
version: string;
|
|
49
|
-
|
|
50
|
-
/** Agent name from AGIRAILS.md */
|
|
51
|
-
agentName?: string;
|
|
52
|
-
|
|
53
|
-
/** Agent intent: earn, pay, or both */
|
|
54
|
-
intent?: 'earn' | 'pay' | 'both';
|
|
55
|
-
|
|
56
|
-
/** Service capabilities from AGIRAILS.md */
|
|
57
|
-
capabilities?: string[];
|
|
58
|
-
|
|
59
|
-
/** Base price in USDC */
|
|
60
|
-
price?: number;
|
|
61
|
-
|
|
62
|
-
/** Max concurrent jobs */
|
|
63
|
-
concurrency?: number;
|
|
64
|
-
|
|
65
|
-
/** Payment mode: actp, x402, or both */
|
|
66
|
-
paymentMode?: 'actp' | 'x402' | 'both';
|
|
67
|
-
|
|
68
|
-
/** Budget cap in USDC */
|
|
69
|
-
budget?: number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Default configuration values
|
|
74
|
-
*/
|
|
75
|
-
export const CONFIG_DEFAULTS: CLIConfig = {
|
|
76
|
-
mode: 'mock',
|
|
77
|
-
address: '',
|
|
78
|
-
version: '1.0',
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// ============================================================================
|
|
82
|
-
// Paths
|
|
83
|
-
// ============================================================================
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get the .actp directory path.
|
|
87
|
-
* Respects ACTP_DIR env var override for custom locations.
|
|
88
|
-
*/
|
|
89
|
-
export function getActpDir(projectRoot: string = process.cwd()): string {
|
|
90
|
-
if (process.env.ACTP_DIR) {
|
|
91
|
-
return process.env.ACTP_DIR;
|
|
92
|
-
}
|
|
93
|
-
return path.join(projectRoot, '.actp');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Get the config.json path
|
|
98
|
-
*/
|
|
99
|
-
export function getConfigPath(projectRoot: string = process.cwd()): string {
|
|
100
|
-
return path.join(getActpDir(projectRoot), 'config.json');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ============================================================================
|
|
104
|
-
// Config Operations
|
|
105
|
-
// ============================================================================
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Check if ACTP is initialized in the current directory
|
|
109
|
-
*/
|
|
110
|
-
export function isInitialized(projectRoot: string = process.cwd()): boolean {
|
|
111
|
-
return fs.existsSync(getConfigPath(projectRoot));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Load configuration from disk
|
|
116
|
-
*
|
|
117
|
-
* SECURITY: Warns about private key storage in config file.
|
|
118
|
-
*
|
|
119
|
-
* @throws Error if config doesn't exist or is corrupted
|
|
120
|
-
*/
|
|
121
|
-
export function loadConfig(projectRoot: string = process.cwd()): CLIConfig {
|
|
122
|
-
const configPath = getConfigPath(projectRoot);
|
|
123
|
-
|
|
124
|
-
if (!fs.existsSync(configPath)) {
|
|
125
|
-
throw new Error(
|
|
126
|
-
'ACTP not initialized in this directory.\n' +
|
|
127
|
-
'Run "actp init" to initialize.'
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
133
|
-
const config = JSON.parse(raw) as CLIConfig;
|
|
134
|
-
|
|
135
|
-
// Validate required fields
|
|
136
|
-
if (!config.mode) {
|
|
137
|
-
throw new Error('Config missing required field: mode');
|
|
138
|
-
}
|
|
139
|
-
if (!config.address) {
|
|
140
|
-
throw new Error('Config missing required field: address');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// SECURITY FIX (L-2): Warn about private key storage in config file
|
|
144
|
-
if (config.privateKey) {
|
|
145
|
-
console.warn('\x1b[33m%s\x1b[0m', 'WARNING: Private key stored in config file.');
|
|
146
|
-
console.warn('\x1b[33m%s\x1b[0m', ' Consider using ACTP_PRIVATE_KEY environment variable instead.');
|
|
147
|
-
console.warn('\x1b[33m%s\x1b[0m', ' Run: export ACTP_PRIVATE_KEY=<your-key>');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Config migration: strip deprecated `registered` field (lazy publish)
|
|
151
|
-
if ('registered' in config) {
|
|
152
|
-
delete (config as unknown as Record<string, unknown>).registered;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return config;
|
|
156
|
-
} catch (error) {
|
|
157
|
-
if (error instanceof SyntaxError) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
`Config file corrupted: ${configPath}\n` +
|
|
160
|
-
'Delete it manually or run "actp init --force"'
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Save configuration to disk
|
|
169
|
-
*
|
|
170
|
-
* Creates .actp directory if it doesn't exist.
|
|
171
|
-
* Uses atomic write (temp file + rename).
|
|
172
|
-
*/
|
|
173
|
-
export function saveConfig(
|
|
174
|
-
config: CLIConfig,
|
|
175
|
-
projectRoot: string = process.cwd()
|
|
176
|
-
): void {
|
|
177
|
-
const actpDir = getActpDir(projectRoot);
|
|
178
|
-
const configPath = getConfigPath(projectRoot);
|
|
179
|
-
const tempPath = `${configPath}.tmp`;
|
|
180
|
-
|
|
181
|
-
// Ensure .actp directory exists
|
|
182
|
-
if (!fs.existsSync(actpDir)) {
|
|
183
|
-
fs.mkdirSync(actpDir, { recursive: true, mode: 0o755 });
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
// Atomic write: write to temp, then rename
|
|
188
|
-
const json = JSON.stringify(config, null, 2);
|
|
189
|
-
fs.writeFileSync(tempPath, json, { encoding: 'utf-8', mode: 0o600 }); // Secure permissions
|
|
190
|
-
fs.renameSync(tempPath, configPath);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
// Clean up temp file on error
|
|
193
|
-
if (fs.existsSync(tempPath)) {
|
|
194
|
-
try {
|
|
195
|
-
fs.unlinkSync(tempPath);
|
|
196
|
-
} catch {
|
|
197
|
-
// Ignore cleanup errors
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
throw error;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Update specific config values
|
|
206
|
-
*
|
|
207
|
-
* Loads existing config, merges updates, and saves.
|
|
208
|
-
*/
|
|
209
|
-
export function updateConfig(
|
|
210
|
-
updates: Partial<CLIConfig>,
|
|
211
|
-
projectRoot: string = process.cwd()
|
|
212
|
-
): CLIConfig {
|
|
213
|
-
const config = loadConfig(projectRoot);
|
|
214
|
-
const updated = { ...config, ...updates };
|
|
215
|
-
saveConfig(updated, projectRoot);
|
|
216
|
-
return updated;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Get a specific config value
|
|
221
|
-
*/
|
|
222
|
-
export function getConfigValue<K extends keyof CLIConfig>(
|
|
223
|
-
key: K,
|
|
224
|
-
projectRoot: string = process.cwd()
|
|
225
|
-
): CLIConfig[K] {
|
|
226
|
-
const config = loadConfig(projectRoot);
|
|
227
|
-
return config[key];
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Set a specific config value
|
|
232
|
-
*/
|
|
233
|
-
export function setConfigValue<K extends keyof CLIConfig>(
|
|
234
|
-
key: K,
|
|
235
|
-
value: CLIConfig[K],
|
|
236
|
-
projectRoot: string = process.cwd()
|
|
237
|
-
): void {
|
|
238
|
-
updateConfig({ [key]: value } as Partial<CLIConfig>, projectRoot);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// ============================================================================
|
|
242
|
-
// Validation
|
|
243
|
-
// ============================================================================
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Validate Ethereum address format
|
|
247
|
-
*/
|
|
248
|
-
export function validateAddress(address: string): boolean {
|
|
249
|
-
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Validate private key format (64 hex chars, optionally with 0x prefix)
|
|
254
|
-
*/
|
|
255
|
-
export function validatePrivateKey(key: string): boolean {
|
|
256
|
-
// Remove 0x prefix if present
|
|
257
|
-
const normalized = key.startsWith('0x') ? key.slice(2) : key;
|
|
258
|
-
return /^[a-fA-F0-9]{64}$/.test(normalized);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Validate config for the specified mode
|
|
263
|
-
*
|
|
264
|
-
* @throws Error if config is invalid for the mode
|
|
265
|
-
*/
|
|
266
|
-
export function validateConfigForMode(config: CLIConfig): void {
|
|
267
|
-
// All modes require a valid address
|
|
268
|
-
if (!validateAddress(config.address)) {
|
|
269
|
-
throw new Error(
|
|
270
|
-
`Invalid address: "${config.address}"\n` +
|
|
271
|
-
'Expected 0x-prefixed 40-character hex string.'
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Testnet and mainnet require private key
|
|
276
|
-
if (config.mode !== 'mock') {
|
|
277
|
-
if (!config.privateKey) {
|
|
278
|
-
throw new Error(
|
|
279
|
-
`Private key required for ${config.mode} mode.\n` +
|
|
280
|
-
'Run: actp config set privateKey <your-private-key>'
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (!validatePrivateKey(config.privateKey)) {
|
|
285
|
-
throw new Error(
|
|
286
|
-
'Invalid private key format.\n' +
|
|
287
|
-
'Expected 64-character hex string (with or without 0x prefix).'
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// ============================================================================
|
|
294
|
-
// Gitignore Management
|
|
295
|
-
// ============================================================================
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Add .actp to .gitignore if not already present
|
|
299
|
-
*/
|
|
300
|
-
export function addToGitignore(projectRoot: string = process.cwd()): void {
|
|
301
|
-
const gitignorePath = path.join(projectRoot, '.gitignore');
|
|
302
|
-
|
|
303
|
-
let content = '';
|
|
304
|
-
if (fs.existsSync(gitignorePath)) {
|
|
305
|
-
content = fs.readFileSync(gitignorePath, 'utf-8');
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Check if .actp is already in gitignore
|
|
309
|
-
if (content.includes('.actp')) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Add .actp to gitignore
|
|
314
|
-
const newContent =
|
|
315
|
-
content +
|
|
316
|
-
(content.endsWith('\n') ? '' : '\n') +
|
|
317
|
-
'# ACTP local state (contains mock blockchain state)\n' +
|
|
318
|
-
'.actp/\n';
|
|
319
|
-
|
|
320
|
-
fs.writeFileSync(gitignorePath, newContent, 'utf-8');
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// ============================================================================
|
|
324
|
-
// Ignore File Management (AIP-13)
|
|
325
|
-
// ============================================================================
|
|
326
|
-
|
|
327
|
-
const IGNORE_ENTRIES = ['.actp/', '.env', '.env.*', 'node_modules/'];
|
|
328
|
-
const IGNORE_HEADER = '# ACTP deployment security (AIP-13)';
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Validate that a file path is not a symlink.
|
|
332
|
-
* Throws if the path exists and is a symlink (security: prevents symlink attacks).
|
|
333
|
-
*/
|
|
334
|
-
function assertNotSymlink(filePath: string): void {
|
|
335
|
-
try {
|
|
336
|
-
const stat = fs.lstatSync(filePath);
|
|
337
|
-
if (stat.isSymbolicLink()) {
|
|
338
|
-
throw new Error(
|
|
339
|
-
`Refusing to write ${path.basename(filePath)}: path is a symlink. Remove the symlink and retry.`
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
} catch (err) {
|
|
343
|
-
// Re-throw symlink errors; ENOENT (file doesn't exist) is fine
|
|
344
|
-
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Add standard ignore entries to a file (idempotent).
|
|
350
|
-
* Creates the file if it doesn't exist.
|
|
351
|
-
*/
|
|
352
|
-
function addIgnoreEntries(filePath: string): void {
|
|
353
|
-
assertNotSymlink(filePath);
|
|
354
|
-
|
|
355
|
-
let content = '';
|
|
356
|
-
if (fs.existsSync(filePath)) {
|
|
357
|
-
content = fs.readFileSync(filePath, 'utf-8');
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Only add entries that are missing (check each individually)
|
|
361
|
-
const missingEntries = IGNORE_ENTRIES.filter(entry => !content.includes(entry));
|
|
362
|
-
if (missingEntries.length === 0) return;
|
|
363
|
-
|
|
364
|
-
const newContent =
|
|
365
|
-
content +
|
|
366
|
-
(content.length > 0 && !content.endsWith('\n') ? '\n' : '') +
|
|
367
|
-
IGNORE_HEADER + '\n' +
|
|
368
|
-
missingEntries.join('\n') + '\n';
|
|
369
|
-
|
|
370
|
-
fs.writeFileSync(filePath, newContent, 'utf-8');
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Add .actp/ and related entries to .dockerignore (AIP-13).
|
|
375
|
-
* Creates the file if it doesn't exist. Idempotent.
|
|
376
|
-
* Throws if .dockerignore is a symlink.
|
|
377
|
-
*/
|
|
378
|
-
export function addToDockerignore(projectRoot: string = process.cwd()): void {
|
|
379
|
-
addIgnoreEntries(path.join(projectRoot, '.dockerignore'));
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Add .actp/ and related entries to .railwayignore (AIP-13).
|
|
384
|
-
* Creates the file if it doesn't exist. Idempotent.
|
|
385
|
-
* Throws if .railwayignore is a symlink.
|
|
386
|
-
*/
|
|
387
|
-
export function addToRailwayignore(projectRoot: string = process.cwd()): void {
|
|
388
|
-
addIgnoreEntries(path.join(projectRoot, '.railwayignore'));
|
|
389
|
-
}
|